MakePrediction.C
Go to the documentation of this file.
1 /// MakePrediction.C by J. Hewes <jhewes15@fnal.gov>
2 
5 
8 
10 
12 #include "CAFAna/Vars/HistAxes.h"
14 
16 
17 #include "CAFAna/Analysis/Calcs.h"
19 #include "CAFAna/Core/Sample.h"
20 
21 #include "NuXAna/Vars/NusVars.h"
26 
27 #include "OscLib/OscCalcSterile.h"
28 
29 using namespace ana;
30 
31 using std::begin;
32 using std::cout;
33 using std::end;
34 using std::endl;
35 using std::exception;
36 using std::ostringstream;
37 using std::pair;
38 using std::string;
39 using std::vector;
40 
41 using covmx::Sample;
42 
43 void MakePrediction(TString opt, string systFile="default", double res=0)
44 {
45  try {
46  DontAddDirectory guard;
47 
48  Sample sample = GetSampleFromOptString(opt);
49  SetAxis(sample, res);
50  SetCut(sample);
51 
52  // What type of file to run over
53  vector<pair<string, bool>> loaderOpts
54  = { {"fullcaf",false}, {"concat",true} };
55  bool concat = ParseOption<bool>(loaderOpts, opt, true);
56 
57  // Systematic option
58  vector<pair<string, string>> systOpts
59  = { {"nosysts","nosysts"}, {"filesysts","file"}, {"xsecsysts","xsec"},
60  {"allsysts","all"} };
61 
62  string systType = ParseOption<string>(systOpts, opt, "nosysts");
63 
64  // Important variables
65  const Var kReweight = kPPFXFluxCVWgt;
67 
68  // Set up systematics
69  vector<const ISyst*> systs;
70  if (systType == "file" || systType == "all") {
71  vector<const ISyst*> fileSysts = systFile == "default" ?
72  LoadSysts(sample) : LoadSystsFromFile(pnfs2xrootd(systFile), "isysts_"+sample.GetTag());
73  systs.insert(end(systs), begin(fileSysts), end(fileSysts));
74  }
75  if (systType == "xsec" || systType == "all") {
76  vector<const ISyst*> xsecSysts = getAllXsecSysts_2020();
77  systs.insert(end(systs), begin(xsecSysts), end(xsecSysts));
78  }
79  // Add in neutron here eventually
80 
81  // Set CAF type
83  if (concat) {
84  if (sample.selection == covmx::kCCNue) CAFType = ECAFType::kNueConcat;
85  else if (sample.selection == covmx::kCCNumu) CAFType = ECAFType::kNumuConcat;
86  else if (sample.selection == covmx::kNC) CAFType = ECAFType::kNusConcat;
87  }
88 
89  // Define the loader
90  Prod5NomLoaders loaders(CAFType,
92  if (sample.detector == covmx::kNearDet) {
93  loaders.SetND(true);
94  }
96 
97  // Create the prediction
98  IPredictionGenerator* gen = nullptr;
99  if (sample.detector == covmx::kNearDet) gen = new NDPredictionGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
100  else gen = new FDPredictionGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
101  IPrediction* pred = gen->Generate(loaders).release();
102  PredictionInterp* predInterp = nullptr;
103  if (systs.size() > 0) {
104  predInterp = new PredictionInterp(systs, calc, *gen, loaders);
105  }
106  loaders.Go();
107 
108  // Initialise output file
109  ostringstream outFileName;
110  outFileName << "pred_" << sample.GetTag();
111  if (res!=0) outFileName << "_res" << (int)res;
112  outFileName << ".root";
113  TFile* outFile = TFile::Open(outFileName.str().c_str(), "recreate");
114 
115  // Save prediction to file
116  ostringstream dirname;
117  dirname << "pred_" << sample.GetTag();
118  pred->SaveTo(outFile->mkdir(dirname.str().c_str()));
119 
120  if (predInterp) {
121  dirname.str("");
122  dirname << "pred_interp_" << sample.GetTag();;
123  predInterp->SaveTo(outFile->mkdir(dirname.str().c_str()));
124  }
125  } catch(const exception& e) {
126  cout << endl << "Exception occurred! " << e.what() << endl;
127  }
128 
129 } // macro MakePrediction
130 
Implements systematic errors by interpolation between shifted templates.
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void MakePrediction(TString opt, string systFile="default", double res=0)
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
std::vector< const ISyst * > LoadSystsFromFile(std::string filePath, std::string dirName)
Load systematics from file.
Definition: Utilities.h:483
Adapt the PMNS_Sterile calculator to standard interface.
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void SetCut(covmx::Sample &sample)
Definition: Utilities.h:274
std::string pnfs2xrootd(std::string loc, bool unauth)
Definition: UtilsExt.cxx:237
osc::OscCalcDumb calc
covmx::Sample GetSampleFromOptString(TString optString)
Function to take an option TString and return a single associated covmx::Sample.
Definition: Utilities.h:355
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
void SetAxis(TH1 *h, bool visible, int color, int style=1, bool scale=true)
std::vector< const ISyst * > getAllXsecSysts_2020()
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
virtual void SaveTo(TDirectory *dir, const std::string &name) const override
osc::OscCalcSterile * DefaultSterileCalc(int nflavors)
Create a sterile calculator with default assumptions for all parameters.
Definition: Calcs.cxx:97
TFile * outFile
Definition: PlotXSec.C:135
For nominal spectra and reweighting systs (xsec/flux)
Definition: Prod5Loaders.h:101
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
std::vector< Loaders * > loaders
Definition: syst_header.h:386
void SetND(bool nd)
Definition: Loaders.h:65
std::vector< const ISyst * > LoadSysts(covmx::Sample sample)
Get systematics for a given sample.
Definition: Utilities.h:524
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const override
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Given loaders and an MC shift, Generate() generates an IPrediction.
Prevent histograms being added to the current directory.
Definition: UtilsExt.h:46
Float_t e
Definition: plot.C:35
Generates Near Detector predictions.
ECAFType
Definition: Loaders.h:19
enum BeamMode string