nuCrystalBall.C
Go to the documentation of this file.
1 #ifdef __CINT__
2 void nuCrystalBall(const TString filename, const TString opt)
3 {
4  std::cout << "Sorry, you must run in compiled mode" << std::endl;
5 }
6 #else
7 
11 #include "CAFAna/Cuts/Cuts.h"
12 #include "CAFAna/Cuts/SpillCuts.h"
14 
15 #include "TString.h"
16 #include "TFile.h"
17 
18 #include <iostream>
19 #include <vector>
20 
21 #include "Utilities/func/MathUtil.h"
22 
24 
25 using namespace ana;
26 
27 void nuCrystalBall(const TString filename, const TString opt)
28 {
29  // Create loaders
30  // Set miniprod file definitions
31  std::vector<SpectrumLoader> loaders;
32  loaders.push_back(SpectrumLoader("prod_caf_R17-09-05-prod4recopreview.f_fd_genie_nonswap_fhc_nova_v08_full_v1_addShortSimpleCVN"));
33  loaders.push_back(SpectrumLoader("prod_caf_R17-09-05-prod4recopreview.f_fd_genie_nonswap_rhc_nova_v08_full_v1_addShortSimpleCVN"));
34  std::vector<SpectrumLoader> loadersSwap;
35  loadersSwap.push_back(SpectrumLoader("prod_caf_R17-09-05-prod4recopreview.f_fd_genie_fluxswap_fhc_nova_v08_full_v1_addShortSimpleCVN"));
36  loadersSwap.push_back(SpectrumLoader("prod_caf_R17-09-05-prod4recopreview.f_fd_genie_fluxswap_rhc_nova_v08_full_v1_addShortSimpleCVN"));
37 
38  // Define weight
40 
41  // Get vectors of vars, cuts, cut names, pid cuts and pid cut names
42  std::vector<VarDef> vars = GetVars(opt);
43  std::vector<CutDef> cuts = GetCuts(opt);
44  std::vector<std::vector<PIDCutDef> > pidCuts = GetPIDCuts(opt);
45 
46  // Create vector to fill with predictions
47  std::vector<PredDef> preds;
48 
49  // Loop over FHC and RHC
50  for(auto rhc = 0; rhc < 2; ++rhc)
51  {
52  loaders[rhc].SetSpillCut(kStandardSpillCuts);
53  loadersSwap[rhc].SetSpillCut(kStandardSpillCuts);
54 
55  TString fhcName = "fhc";
56  if(rhc)
57  fhcName = "rhc";
58 
59  // Make predictions for var distributions to do the fom optimisation
60  // PIDS:
61  // 1. short Simple
62  // 2. ELU
63  // 3. 2017
64  // Loop over vars
65  for(const auto var:vars)
66  {
67  // Loop over cuts
68  for(auto cut:cuts)
69  {
70  // Add No PID cut prediction
71  preds.push_back({
72  new PredictionNoExtrap(loaders[rhc], loadersSwap[rhc],
73  var.name.Data(), var.binning, var.var,
74  cut.cut, kNoShift, weight),
75  cut.name.Data(), "noPIDCut", var.name.Data(), fhcName});
76  std::cout << "Making prediction: "
77  << var.name.Data() << " "
78  << "noPIDCut" << " "
79  << cut.name.Data() << " "
80  << fhcName << std::endl;
81 
82  // Now lets make a PID cut
83  // Loop over PID cuts
84  for(auto pidCut:pidCuts[rhc])
85  {
86  // Select if we want to create a prediction for combo
87  if(var.type.Contains("pid", TString::kIgnoreCase))
88  // only apply cut if relevant for PID
89  {
90  if(!((pidCut.name.Contains(var.name.Data())) ||
91  (pidCut.name.Contains("allPIDs"))))
92  continue; // Don't apply PID cut
93  }
94  // Add prediciton
95  preds.push_back({
96  new PredictionNoExtrap(loaders[rhc], loadersSwap[rhc],
97  var.name.Data(), var.binning, var.var,
98  cut.cut && pidCut.cut, kNoShift, weight),
99  cut.name.Data(), pidCut.name.Data(), var.name.Data(), fhcName});
100  std::cout << "Making prediction: "
101  << var.name.Data() << " "
102  << pidCut.name.Data() << " "
103  << cut.name.Data() << " "
104  << fhcName << std::endl;
105  }// loop over PID cuts
106  }// loop over cuts
107  }// loop over vars
108  }// loop over FHC/RHC
109 
110  // Loop over FHC and RHC
111  for(auto rhc = 0; rhc < 1; ++rhc)
112  {
113  std::cout << "Loaders Go!" << std::endl;
114  loaders[rhc].Go();
115  loadersSwap[rhc].Go();
116  }
117 
118  // Write predictions to file
119  auto outFile = new TFile(filename, "recreate");
120  std::cout << "writing predictions..." << std::endl;
121  for(auto pred:preds)
122  {
123  std::cout << "pred_nxp_"
124  << pred.cutName << "_"
125  << pred.pidCutName << "_"
126  << pred.varName << "_"
127  << pred.fhcName << std::endl;
128  pred.prediction->SaveTo(outFile->mkdir(
129  "pred_nxp_" + pred.cutName + "_" +
130  pred.pidCutName + "_" + pred.varName + "_" + pred.fhcName));
131  }
132 std::cout << "Ending script..." << std::endl;
133 }// end of nuCrystalBall
134 #endif
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Var weight
string filename
Definition: shutoffs.py:106
TFile * outFile
Definition: PlotXSec.C:135
std::vector< CutDef > GetCuts(TString opt, bool pastCuts=false, bool noCut=true)
const std::map< std::pair< std::string, std::string >, Variable > vars
std::vector< std::vector< PIDCutDef > > GetPIDCuts(TString opt, bool noCut=true)
const SystShifts kNoShift
Definition: SystShifts.cxx:21
OStream cout
Definition: OStream.cxx:6
const Cut cut
Definition: exporter_fd.C:30
const std::vector< VarDef > GetVars(TString opt, TString type="all")
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::vector< Loaders * > loaders
Definition: syst_header.h:386
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Prediction that just uses FD MC, with no extrapolation.
const Var kXSecCVWgt2017
Definition: XsecTunes.h:37
void nuCrystalBall(const TString filename, const TString opt)
Definition: nuCrystalBall.C:27