Nus18SystsCalibAbsLoad.C
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////
2 // Absolute Calibration systematics for Nus18
3 //
4 // Author: Sijith Edayath
5 // Modified by Mike Wallbank (wallbank@fnal.gov)
6 /////////////////////////////////////////////////////////////////////
7 
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"
18 #include "CAFAna/Extrap/ExtrapSterile.h"
19 #include "CAFAna/Extrap/FDExtrap.h"
20 #include "CAFAna/Extrap/NDExtrap.h"
25 #include "CAFAna/Systs/Systs.h"
27 #include "NuXAna/Vars/HistAxes.h"
29 
32 
33 using namespace ana;
34 
35 void Nus18SystsCalibAbsLoad(TString opt) {
36 
37  TH1::AddDirectory(0);
38  const Var kReweight = kXSecCVWgt2018*kPPFXFluxCVWgt;
39 
40  // Get options
41  ECAFType cafType;
42  Loaders::FluxType fluxType;
43  bool extrap = false;
44  if (opt.Contains("caf", TString::kIgnoreCase))
45  cafType = ECAFType::kFullCAF;
46  else if (opt.Contains("concat", TString::kIgnoreCase))
47  cafType = ECAFType::kNusConcat;
48  else {
49  std::cout << "ECAFType required: caf or concat" << std::endl;
50  abort();
51  }
52  if (opt.Contains("fhc", TString::kIgnoreCase))
53  fluxType = Loaders::FluxType::kFHC;
54  else if (opt.Contains("rhc", TString::kIgnoreCase))
55  fluxType = Loaders::FluxType::kRHC;
56  else {
57  std::cout << "FluxType required: fhc or rhc" << std::endl;
58  abort();
59  }
60  if (opt.Contains("extrap", TString::kIgnoreCase))
61  extrap = true;
62 
63  // Set up the loaders
64  Loaders* loaders_nom = new Prod4NomLoaders(cafType, fluxType);
65  Loaders* loaders_up = new Prod4AbsCalibLoaders(cafType, fluxType, +1);
66  Loaders* loaders_down = new Prod4AbsCalibLoaders(cafType, fluxType, -1);
67  Loaders* loaders_shape = new Prod4CalibShapeLoaders(cafType, fluxType);
68  loaders_nom ->SetSpillCut(kStandardSpillCuts);
69  loaders_up ->SetSpillCut(kStandardSpillCuts);
70  loaders_down ->SetSpillCut(kStandardSpillCuts);
71  loaders_shape->SetSpillCut(kStandardSpillCuts);
72 
73  // Get all Absolute Calibration systematics
74  std::map<std::string, Loaders*> systematics;
75  systematics["CalFlatUp"] = loaders_up;
76  systematics["CalFlatDown"] = loaders_down;
77  systematics["CalShape"] = loaders_shape;
78 
79  // Define a map of samples and cuts/axes to set them up
80  // Each sample, essentially, is a way to set up the analysis
81  HistAxis AxisRecoE = kNus18AxisE;
82  std::map<std::string, std::pair<HistAxis*, std::pair<Cut*, Cut*> > > cut_samples;
83  cut_samples["Nus18"] = std::make_pair(&AxisRecoE, std::make_pair(new Cut(kNus18ND), new Cut(kNus18FD)));
84 
85  // Set up maps to the decompositions/predictions (each flavor component)
86  // Nominal maps are indexed purely by sample label
87  // Shifted maps are indexed by sample label, systematic label, then sigma of the shift
88  std::map<std::string, NDPredictionSterile*> predsND_nominal;
89  std::map<std::string, FDPredictionSterile*> predsFD_nominal;
90  std::map<std::string, PredictionSterile*> predsExtrap_nominal;
91  std::map<std::string, std::map<std::string, std::map<int, NDPredictionSterile*> > > predsND_shifted;
92  std::map<std::string, std::map<std::string, std::map<int, FDPredictionSterile*> > > predsFD_shifted;
93  std::map<std::string, std::map<std::string, std::map<int, PredictionSterile*> > > predsExtrap_shifted;
94 
95  // Set up the actual decompositions/predictions
96  // sample.first = the sample label
97  // shiftLabel.first = the systematic shift label
98  // sample.second.first = the sample HistAxis
99  // sample.second.second = the sample Cut
100  for(const auto& sample : cut_samples) {
101 
102  // Get prediction generators
103  const NDPredictionGenerator gennd(*sample.second.first, *sample.second.second.first, kNoShift, kReweight);
104  const FDPredictionGenerator genfd(*sample.second.first, *sample.second.second.second, kNoShift, kReweight);
105  SterileGenerator* genExtrap;
106  if (extrap)
107  genExtrap = new SterileGenerator(*sample.second.first, kNus18BinsNumuCCAxis,
108  *sample.second.second.second, *sample.second.second.first,
109  kNumuCutND2018, kNoShift, kReweight);
110 
111  // Set up the nominal decompositions
112  // Only one is needed per sample
113  predsND_nominal[sample.first] = (NDPredictionSterile*)gennd.Generate(*loaders_nom).release();
114  predsFD_nominal[sample.first] = (FDPredictionSterile*)genfd.Generate(*loaders_nom).release();
115  if (extrap)
116  predsExtrap_nominal[sample.first] = (PredictionSterile*)genExtrap->Generate(*loaders_nom).release();
117 
118  // Set up the shifted decompositions
119  // One is needed for every sample, systematic, and sigma level
120  for (const auto& syst : systematics) {
121  predsND_shifted[sample.first][syst.first][1]
122  = (NDPredictionSterile*)gennd.Generate(*syst.second).release();
123  predsFD_shifted[sample.first][syst.first][1]
124  = (FDPredictionSterile*)genfd.Generate(*syst.second).release();
125  if (extrap)
126  predsExtrap_shifted[sample.first][syst.first][1]
127  = (PredictionSterile*)genExtrap->Generate(*syst.second).release();
128  }
129 
130  if (extrap)
131  delete genExtrap;
132 
133  }
134 
135  loaders_nom ->Go();
136  loaders_up ->Go();
137  loaders_down ->Go();
138  loaders_shape->Go();
139 
140  std::string folder = "./";
141  std::string filenm = "SystsCalibAbs18";
142 
143  std::string fullLocation = folder + filenm + ".root";
144  TFile* rootF = new TFile(fullLocation.c_str(), "RECREATE");
145  SaveMaps(rootF, predsND_nominal, predsND_shifted);
146  SaveMaps(rootF, predsFD_nominal, predsFD_shifted);
147  if (extrap)
148  SaveMaps(rootF, predsExtrap_nominal, predsExtrap_shifted);
149  rootF->Close();
150 
151  // delete loaders_nom;
152  // delete loaders_up;
153  // delete loaders_down;
154  // delete loaders_shape;
155 
156  return;
157 
158 }
void Nus18SystsCalibAbsLoad(TString opt)
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
Loaders for calibration shape paths/definitions.
Definition: Prod4Loaders.h:196
Loaders for absolute calibration paths/definitions.
Definition: Prod4Loaders.h:119
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:22
OStream cout
Definition: OStream.cxx:6
const Var kXSecCVWgt2018
Definition: XsecTunes.h:49
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.
ECAFType
Definition: Loaders.h:19
enum BeamMode string