MakePredictionNoOsc_RHC_ND.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 MakePredictionNoOsc_RHC_ND(TString opt, string systFile="default", double res=0)
44 {
45  //Load systs in memory
47  //vector<const ISyst*> systsfile = LoadSystsFromFile("/nova/app/users/mrajaoal/my_new_release/CAFAna/nus/Nus20/Systs/isysts.root", "isysts_numusel_rhc_fardet");
48  vector<const ISyst*> systsfile = LoadSystsFromFile(InputPath() + "/systs/isysts.root", "isysts_numusel_rhc_neardet");
49 
50  try {
51  DontAddDirectory guard;
52 
53  Sample sample = GetSampleFromOptString(opt);
54  SetAxis(sample, res);
55  SetCut(sample);
56 
57  // What type of file to run over
58  vector<pair<string, bool>> loaderOpts
59  = { {"fullcaf",false}, {"concat",true} };
60  bool concat = ParseOption<bool>(loaderOpts, opt, true);
61 
62  // Systematic option
63  vector<pair<string, string>> systOpts
64  = { {"nosysts","nosysts"}, {"filesysts","file"}, {"xsecsysts","xsec"},
65  {"allsysts","all"} };
66 
67  string systType = ParseOption<string>(systOpts, opt, "nosysts");
68 
69  // Important variables
70  const Var kReweight = kPPFXFluxCVWgt;
72 
73  // Set up systematics
74  vector<const ISyst*> systs;
75  if (systType == "file" || systType == "all") {
76  vector<const ISyst*> fileSysts = systFile == "default" ?
77  //LoadSysts(sample, kUseCVMFS) : LoadSystsFromFile(pnfs2xrootd(systFile), "isysts_"+sample.GetTag());
78  LoadSysts(sample) : LoadSystsFromFile(pnfs2xrootd(systFile), "isysts_"+sample.GetTag());
79  systs.insert(end(systs), begin(fileSysts), end(fileSysts));
80  }
81  if (systType == "xsec" || systType == "all") {
82  vector<const ISyst*> xsecSysts = getAllXsecSysts_2020();
83  systs.insert(end(systs), begin(xsecSysts), end(xsecSysts));
84  }
85  // Add in neutron here eventually
86 
87  // Set CAF type
89  if (concat) {
90  if (sample.selection == covmx::kCCNue) CAFType = ECAFType::kNueConcat;
91  else if (sample.selection == covmx::kCCNumu) CAFType = ECAFType::kNumuConcat;
92  else if (sample.selection == covmx::kNC) CAFType = ECAFType::kNusConcat;
93  }
94 
95  // Define the loader
96  Prod5NomLoaders loaders(CAFType,
98  if (sample.detector == covmx::kNearDet) {
99  loaders.SetND(true);
100  }
102 
103  // Create the prediction
104  IPredictionGenerator* gen = nullptr;
105  if (sample.detector == covmx::kNearDet) gen = new NDPredictionNoOscGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
106  else gen = new FDPredictionGenerator(*sample.GetAxis(), *sample.GetCut(), kNoShift, kReweight);
107  IPrediction* pred = gen->Generate(loaders).release();
108  PredictionInterp* predInterp = nullptr;
109  if (systs.size() > 0) {
110  predInterp = new PredictionInterp(systs, calc, *gen, loaders);
111  }
112  loaders.Go();
113 
114  // Initialise output file
115  ostringstream outFileName;
116  outFileName << "pred_" << sample.GetTag();
117  if (res!=0) outFileName << "_res" << (int)res;
118  outFileName << ".root";
119  TFile* outFile = TFile::Open(outFileName.str().c_str(), "recreate");
120 
121  // Save prediction to file
122  ostringstream dirname;
123  dirname << "pred_" << sample.GetTag();
124  pred->SaveTo(outFile->mkdir(dirname.str().c_str()));
125 
126  if (predInterp) {
127  dirname.str("");
128  dirname << "pred_interp_" << sample.GetTag();;
129  predInterp->SaveTo(outFile->mkdir(dirname.str().c_str()));
130  }
131  } catch(const exception& e) {
132  cout << endl << "Exception occurred! " << e.what() << endl;
133  }
134 
135 } // macro MakePrediction
136 
Implements systematic errors by interpolation between shifted templates.
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
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)
void MakePredictionNoOsc_RHC_ND(TString opt, string systFile="default", double res=0)
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:21
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
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
string InputPath()
Definition: Utilities.h:183
ECAFType
Definition: Loaders.h:19
enum BeamMode string