Nus18SystsXSecOnOffLoad.C
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////
2 // Cross-section on/off systematics for Nus18
3 //
4 // Author: Sijith Edayath
5 // Modified by Mike Wallbank (wallbank@fnal.gov)
6 /////////////////////////////////////////////////////////////////////
7 
9 #include "CAFAna/Core/Loaders.h"
10 #include "CAFAna/Core/SystShifts.h"
11 #include "CAFAna/Core/Utilities.h"
12 #include "CAFAna/Cuts/Cuts.h"
13 #include "NuXAna/Cuts/NusCuts18.h"
15 #include "CAFAna/Cuts/SpillCuts.h"
23 #include "CAFAna/Systs/BeamSysts.h"
24 #include "CAFAna/Systs/Systs.h"
26 #include "CAFAna/Vars/HistAxes.h"
27 #include "NuXAna/Vars/HistAxes.h"
29 
32 
33 using namespace ana;
34 
35 /// Run systematics for cross-section on/off
37 
38  TH1::AddDirectory(0);
39  const Var kReweight = kXSecCVWgt2018*kPPFXFluxCVWgt;
40 
41  // Get options
42  ECAFType cafType;
43  Loaders::FluxType fluxType;
44  bool extrap = false;
45  if (opt.Contains("caf", TString::kIgnoreCase))
46  cafType = ECAFType::kFullCAF;
47  else if (opt.Contains("concat", TString::kIgnoreCase))
48  cafType = ECAFType::kNusConcat;
49  else {
50  std::cout << "ECAFType required: caf or concat" << std::endl;
51  abort();
52  }
53  if (opt.Contains("fhc", TString::kIgnoreCase))
54  fluxType = Loaders::FluxType::kFHC;
55  else if (opt.Contains("rhc", TString::kIgnoreCase))
56  fluxType = Loaders::FluxType::kRHC;
57  else {
58  std::cout << "FluxType required: fhc or rhc" << std::endl;
59  abort();
60  }
61  if (opt.Contains("extrap", TString::kIgnoreCase))
62  extrap = true;
63 
64  // Set up the loaders
65  Loaders* loaders = new Prod4NomLoaders(cafType, fluxType);
67 
68  // Get the labels for cross-section on/off systematics
69  std::map<std::string, const Var*> systematics;
70  const Var kXSecWeightOff = kPPFXFluxCVWgt;
71  systematics["NoXSec"] = &kXSecWeightOff;
72 
73  // Define a map of samples and cuts/axes to set them up
74  // Each sample, essentially, is a way to set up the analysis
75  HistAxis AxisRecoE = kNus18AxisE;
76  std::map<std::string, std::pair<HistAxis*, std::pair<Cut*, Cut*> > > cut_samples;
77  cut_samples["Nus18"] = std::make_pair(&AxisRecoE, std::make_pair(new Cut(kNus18ND), new Cut(kNus18FD)));
78 
79  // Set up maps to the decompositions/predictions (each flavor component)
80  // Nominal maps are indexed purely by sample label
81  // Shifted maps are indexed by sample label, systematic label, then sigma of the shift
82  std::map<std::string, NDPredictionSterile*> predsND_nominal;
83  std::map<std::string, FDPredictionSterile*> predsFD_nominal;
84  std::map<std::string, PredictionSterile*> predsExtrap_nominal;
85  std::map<std::string, std::map<std::string, std::map<int, NDPredictionSterile*> > > predsND_shifted;
86  std::map<std::string, std::map<std::string, std::map<int, FDPredictionSterile*> > > predsFD_shifted;
87  std::map<std::string, std::map<std::string, std::map<int, PredictionSterile*> > > predsExtrap_shifted;
88 
89  // Set up the actual decompositions/predictions
90  // sample.first = the sample label
91  // shiftLabel.first = the systematic shift label
92  // sample.second.first = the sample HistAxis
93  // sample.second.second = the sample Cut
94  // syst.first = the integer number of sigmas for the shift
95  // syst.second = the systematic being shifted
96  for (const auto& sample : cut_samples) {
97 
98  const NDPredictionGenerator gennd(*sample.second.first, *sample.second.second.first, kNoShift, kReweight);
99  const FDPredictionGenerator genfd(*sample.second.first, *sample.second.second.second, kNoShift, kReweight);
100  SterileGenerator* genExtrap;
101  if (extrap)
102  genExtrap = new SterileGenerator(*sample.second.first, kNus18BinsNumuCCAxis,
103  *sample.second.second.second, *sample.second.second.first,
104  kNumuCutND2018, kNoShift, kReweight);
105 
106  // Set up the nominal decompositions
107  // Only one is needed per sample
108  predsND_nominal[sample.first] = (NDPredictionSterile*)gennd.Generate(*loaders).release();
109  predsFD_nominal[sample.first] = (FDPredictionSterile*)genfd.Generate(*loaders).release();
110  if (extrap)
111  predsExtrap_nominal[sample.first] = (PredictionSterile*)genExtrap->Generate(*loaders).release();
112 
113  if (extrap)
114  delete genExtrap;
115 
116  // Set up the shifted decompositions
117  // One is needed for every sample and systematic
118  for (const auto& syst : systematics) {
119 
120  // Create new prediction generators with correct reweights
121  const NDPredictionGenerator gennd_xsecoff
122  (*sample.second.first, *sample.second.second.first, kNoShift, *syst.second);
123  const FDPredictionGenerator genfd_xsecoff
124  (*sample.second.first, *sample.second.second.second, kNoShift, *syst.second);
125  SterileGenerator* genExtrap_xsecoff;
126  if (extrap)
127  genExtrap_xsecoff = new SterileGenerator(*sample.second.first, kNus18BinsNumuCCAxis,
128  *sample.second.second.second, *sample.second.second.first,
129  kNumuCutND2018, kNoShift, *syst.second);
130 
131  // Shift the spectra
132  predsND_shifted[sample.first][syst.first][1]
133  = (NDPredictionSterile*)gennd_xsecoff.Generate(*loaders).release();
134  predsFD_shifted[sample.first][syst.first][1]
135  = (FDPredictionSterile*)genfd_xsecoff.Generate(*loaders).release();
136  if (extrap)
137  predsExtrap_shifted[sample.first][syst.first][1]
138  = (PredictionSterile*)genExtrap_xsecoff->Generate(*loaders).release();
139 
140  if (extrap)
141  delete genExtrap_xsecoff;
142 
143  }
144 
145  }
146 
147  loaders->Go();
148 
149  std::string folder = "./";
150  std::string filenm = "SystsXSecOnOff18";
151 
152  std::string fullLocation = folder + filenm + ".root";
153  TFile* rootF = new TFile(fullLocation.c_str(), "RECREATE");
154  SaveMaps(rootF, predsND_nominal, predsND_shifted);
155  SaveMaps(rootF, predsFD_nominal, predsFD_shifted);
156  if (extrap)
157  SaveMaps(rootF, predsExtrap_nominal, predsExtrap_shifted);
158  rootF->Close();
159 
160  // delete loaders;
161 
162  return;
163 
164 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const override
std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const override
const Cut kNumuCutND2018
Definition: NumuCuts2018.h:41
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
void SaveMaps(TDirectory *out, std::map< std::string, IDecomp * > decomps_nominal, std::map< std::string, std::map< std::string, std::map< int, IDecomp * > > > decomps_shifted, std::map< std::string, PredictionNoExtrap * > predsNE_nominal, std::map< std::string, std::map< std::string, std::map< int, PredictionNoExtrap * > > > predsNE_shifted, std::map< std::string, PredictionSterile * > predsSt_nominal, std::map< std::string, std::map< std::string, std::map< int, PredictionSterile * > > > predsSt_shifted)
Save all of the objects in the input maps to the out directory/file.
Definition: PPFXHelper.h:1077
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Generates extrapolated NC predictions using ProportionalDecomp.
const Cut kNus18FD
Definition: NusCuts18.h:100
const HistAxis kNus18AxisE("Energy Deposited in Scintillator (GeV)", kNus18EnergyBinning, kNus18Energy)
Axes used in Nus18 analysis by nus group.
Definition: HistAxes.h:16
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
_Cut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
const Cut kNus18ND
Full Nus18 ND analysis selection.
Definition: NusCuts18.h:137
Take the output of an extrapolation and oscillate it as required.
const SystShifts kNoShift
Definition: SystShifts.cxx:21
OStream cout
Definition: OStream.cxx:6
const Var kXSecCVWgt2018
Definition: XsecTunes.h:49
std::vector< Loaders * > loaders
Definition: syst_header.h:386
bool systematics
Definition: fnexvscaf.C:31
A prediction object compatible with sterile oscillations.
const HistAxis kNus18BinsNumuCCAxis("Reconstructed Neutrino Energy (GeV)", kNus18EnergyBinning, kCCE)
Definition: HistAxes.h:17
std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const override
Take the output of an extrapolation and oscillate it as required.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
For nominal spectra and reweighting systs (xsec/flux)
Definition: Prod4Loaders.h:96
Generates Near Detector predictions.
void Nus18SystsXSecOnOffLoad(TString opt)
Run systematics for cross-section on/off.
ECAFType
Definition: Loaders.h:19
enum BeamMode string