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"
27 
28 #include "OscLib/OscCalcSterile.h"
29 
30 using namespace ana;
31 
32 using std::begin;
33 using std::cout;
34 using std::end;
35 using std::endl;
36 using std::exception;
37 using std::ostringstream;
38 using std::pair;
39 using std::string;
40 using std::vector;
41 
42 using covmx::Sample;
43 
44 void MakePrediction(TString opt, string systFile="default", double res=0)
45 {
46  try {
47  DontAddDirectory guard;
48 
49  Sample sample = GetSampleFromOptString(opt);
50  SetAxis(sample, res);
51  SetCut(sample);
52 
53  // Important variables
54  const Var kReweight = kPPFXFluxCVWgt;
56 
57  vector<const ISyst*> systs = getNusAna2020AllSysts(sample);
58 
59  // Set CAF type
60  enum ECAFType CAFType;
61  if (sample.selection == covmx::kCCNue) CAFType = ECAFType::kNueConcat;
62  else if (sample.selection == covmx::kCCNumu) CAFType = ECAFType::kNumuConcat;
63  else if (sample.selection == covmx::kNC) CAFType = ECAFType::kNusConcat;
64 
65  // Define the loader
66  Prod5NomLoaders loaders(CAFType,
68  if (sample.detector == covmx::kNearDet) loaders.SetND(true);
70 
71  // Create the prediction
72  IPredictionGenerator* gen = nullptr;
73  if (sample.detector == covmx::kNearDet) gen = new NDPredictionGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
74  else gen = new FDPredictionGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
75  IPrediction* pred = gen->Generate(loaders).release();
76  PredictionInterp* predInterp = nullptr;
77  if (systs.size() > 0) predInterp = new PredictionInterp(systs, calc, *gen, loaders);
78  loaders.Go();
79 
80  // Initialise output file
81  ostringstream outFileName;
82  outFileName << "pred_" << sample.GetTag();
83  if (res!=0) outFileName << "_res" << (int)res;
84  outFileName << ".root";
85  TFile* outFile = TFile::Open(outFileName.str().c_str(), "recreate");
86  TDirectory* predDir = outFile->mkdir(sample.GetTag().c_str());
87 
88  // Save prediction to file
89  pred->SaveTo(predDir, "pred");
90  if (predInterp) predInterp->SaveTo(predDir, "pred_interp");
91 
92  } catch(const exception& e) {
93  cout << endl << "Exception occurred! " << e.what() << endl;
94  }
95 
96 } // macro MakePrediction
97 
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
vector< const ISyst * > getNusAna2020AllSysts(covmx::Sample &s)
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:261
osc::OscCalcDumb calc
covmx::Sample GetSampleFromOptString(TString optString)
Function to take an option TString and return a single associated covmx::Sample.
Definition: Utilities.h:342
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)
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
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