Public Member Functions | Protected Attributes | Private Attributes | List of all members
FDPredictionHandler Class Reference

Class to handle FD predictions. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-04-11/NuXAna/macros/Nus18/Nus18PredictionHandlers.h"

Inheritance diagram for FDPredictionHandler:
PredictionHandler

Public Member Functions

 FDPredictionHandler (std::string predOpt)
 
 ~FDPredictionHandler ()
 
void AddCosmics (SpectrumLoader *loaders_cosmics)
 
void AddData (SpectrumLoader *loaders_data)
 
void AddLoaders (Loaders *loaders)
 
void AddSystematics (std::vector< const ISyst * > systs, osc::OscCalcSterile *calc)
 
void AddVar (std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
 
void AddVar (std::string name, std::string label, Var var, Binning binning, Cut cuts, SystShifts shift, Var weight)
 
void Save (TFile *outFile)
 
 FDPredictionHandler (std::string predOpt, bool isData=false, Loaders *loaders=nullptr)
 
 ~FDPredictionHandler ()
 
void AddVar (std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight, bool cutdata=true)
 
void AddVar (std::string name, std::string label, Var var, Binning binning, Cut cuts, SystShifts shift, Var weight, bool cutdata=true)
 
void AddVar (std::string name, std::string labelx, std::string labely, Var varx, Var vary, Binning binningx, Binning binningy, Cut cuts, SystShifts shift, Var weight, bool cutdata=true)
 
void AddVar (std::string name, std::string labelx, std::string labely, std::string labelz, Var varx, Var vary, Var varz, Binning binningx, Binning binningy, Binning binningz, Cut cuts, SystShifts shift, Var weight, bool cutdata=true)
 
void Save (TFile *outFile)
 
void AddCosmics (SpectrumLoader *loadersCosmic)
 

Protected Attributes

std::map< std::string, CheatDecomp * > fDecompositions
 
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
 

Private Attributes

LoadersfLoaders
 
SpectrumLoaderfLoadersData
 
SpectrumLoaderfLoadersCos
 
std::vector< const ISyst * > fSysts
 
osc::OscCalcSterilefOscCalc
 
std::map< std::string, IPrediction * > fPredictions
 
std::map< std::string, Spectrum * > fSpectra
 
std::map< std::string, Spectrum * > fCosSpec
 
std::string fPredOpt
 
bool fData
 
bool fRunSysts
 
bool fCosmics
 

Detailed Description

Class to handle FD predictions.

Definition at line 37 of file Nus18PredictionHandlers.h.

Constructor & Destructor Documentation

FDPredictionHandler::FDPredictionHandler ( std::string  predOpt)

Definition at line 75 of file Nus18PredictionHandlers.h.

References om::cout, allTimeWatchdog::endl, and fPredOpt.

75  :
76  fPredOpt(predOpt),
77  fLoaders(nullptr),
78  fData(false),
79  fRunSysts(false),
80  fCosmics(false) {
81 
82  // Make sure the Prediction Handler is set up to handle the prediction option
83  if (fPredOpt != "Extrap" and fPredOpt != "FDExtrap" and fPredOpt != "NoExtrap") {
84  std::cout << "The Prediction Handler is not set up to handle " << fPredOpt << " predictions." << std::endl
85  << "Currently options are Extrap (PredictionSterile), "
86  << "FDExtrap (FDPredictionSterile) or NoExtrap (PredictionNoExtrap)." << std::endl;
87  abort();
88  }
89 }
OStream cout
Definition: OStream.cxx:6
FDPredictionHandler::~FDPredictionHandler ( )

Definition at line 91 of file Nus18PredictionHandlers.h.

References std::cos(), fCosSpec, fPredictions, fSpectra, and plot_validation_datamc::pred.

91  {
92  for (const auto& pred : fPredictions)
93  delete pred.second;
94  for (const auto& spectrum : fSpectra)
95  delete spectrum.second;
96  for (const auto& cos : fCosSpec)
97  delete cos.second;
98 }
std::map< std::string, Spectrum * > fCosSpec
std::map< std::string, IPrediction * > fPredictions
std::map< std::string, Spectrum * > fSpectra
T cos(T number)
Definition: d0nt_math.hpp:78
FDPredictionHandler::FDPredictionHandler ( std::string  predOpt,
bool  isData = false,
Loaders loaders = nullptr 
)
inline

Definition at line 323 of file PredictionHandler.h.

324  : PredictionHandler(predOpt, isData, loaders)
325  {
326  }
PredictionHandler(std::string predOpt, bool isData=false, Loaders *loaders=nullptr)
FDPredictionHandler::~FDPredictionHandler ( )
inline

Member Function Documentation

void FDPredictionHandler::AddCosmics ( SpectrumLoader loaders_cosmics)

Definition at line 100 of file Nus18PredictionHandlers.h.

References fCosmics, and fLoadersCos.

Referenced by AddVar(), ExampleCode(), MakeNus18ExtrapPred(), and MakeUnoscPlots().

100  {
101  fCosmics = true;
102  fLoadersCos = loaders_cosmics;
103 }
SpectrumLoader * fLoadersCos
void FDPredictionHandler::AddCosmics ( SpectrumLoader loadersCosmic)
void FDPredictionHandler::AddData ( SpectrumLoader loaders_data)

Definition at line 105 of file Nus18PredictionHandlers.h.

References fData, and fLoadersData.

Referenced by ExampleCode(), and MakeUnoscPlots().

105  {
106  fData = true;
107  fLoadersData = loaders_data;
108 }
SpectrumLoader * fLoadersData
void FDPredictionHandler::AddLoaders ( Loaders loaders)

Definition at line 110 of file Nus18PredictionHandlers.h.

References fLoaders, and loaders.

Referenced by ExampleCode(), MakeNus18ExtrapPred(), and MakeUnoscPlots().

110  {
111  fLoaders = loaders;
112 }
std::vector< Loaders * > loaders
Definition: syst_header.h:386
void FDPredictionHandler::AddSystematics ( std::vector< const ISyst * >  systs,
osc::OscCalcSterile calc 
)

Definition at line 114 of file Nus18PredictionHandlers.h.

References calc, fOscCalc, fRunSysts, fSysts, and systs.

Referenced by MakeNus18ExtrapPred().

114  {
115  fRunSysts = true;
116  fSysts = systs;
117  fOscCalc = calc;
118 }
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
osc::OscCalcDumb calc
osc::OscCalcSterile * fOscCalc
std::vector< const ISyst * > fSysts
void FDPredictionHandler::AddVar ( std::string  name,
HistAxis  axis,
Cut  cuts,
SystShifts  shift,
Var  weight 
)

Definition at line 128 of file Nus18PredictionHandlers.h.

References std::cos(), om::cout, allTimeWatchdog::endl, fCosmics, fCosSpec, fData, fLoaders, fLoadersCos, fLoadersData, fOscCalc, fPredictions, fPredOpt, fRunSysts, fSpectra, fSysts, ana::IPredictionGenerator::Generate(), ana::kInBeamSpill, ana::kInCosmicTimingWindow, ana::kNumuCutND2018, ana::kNus18BinsNumuCCAxis, ana::kNus18ND, and plot_validation_datamc::pred.

Referenced by AddVar(), and MakeNus18ExtrapPred().

128  {
129 
130  if (!fLoaders) {
131  std::cout << "Error: Loaders must be set before variables can be added." << std::endl;
132  abort();
133  }
134 
135  Spectrum* spec = nullptr;
136  Spectrum* cos = nullptr;
137  IPrediction* pred = nullptr;
138 
139  // Make the prediction generator
140  IPredictionGenerator* pred_gen = nullptr;
141  if (fPredOpt == "Extrap") {
143  cuts, kNus18ND,
144  kNumuCutND2018, shift, weight);
145  pred_gen = genExtrap;
146  }
147  else if (fPredOpt == "FDExtrap") {
148  FDPredictionGenerator* genFD = new FDPredictionGenerator(axis, cuts, shift, weight);
149  pred_gen = genFD;
150  }
151  else if (fPredOpt == "NoExtrap") {
152  NoExtrapGenerator* genNoExtrap = new NoExtrapGenerator(axis, cuts, weight);
153  pred_gen = genNoExtrap;
154  }
155 
156  // Get the prediction
157  if (fRunSysts) {
158  PredictionInterp* pred_interp = new PredictionInterp(fSysts, fOscCalc, *pred_gen, *fLoaders);
159  pred = pred_interp;
160  }
161  else
162  pred = pred_gen->Generate(*fLoaders).release();
163 
164  // Make data spectrum
165  if (fData)
166  spec = new Spectrum(*fLoadersData, axis, cuts && kInBeamSpill);
167 
168  // Make cosmic spectrum
169  if (fCosmics)
170  cos = new Spectrum(*fLoadersCos, axis, cuts && kInCosmicTimingWindow);
171 
172  // Save the data products
173  if (pred)
175  if (spec)
176  fSpectra[name] = spec;
177  if (cos)
178  fCosSpec[name] = cos;
179 
180  return;
181 
182 }
SpectrumLoader * fLoadersData
std::map< std::string, Spectrum * > fCosSpec
const XML_Char * name
Definition: expat.h:151
Implements systematic errors by interpolation between shifted templates.
const Cut kNumuCutND2018
Definition: NumuCuts2018.h:41
std::map< std::string, IPrediction * > fPredictions
std::vector< double > Spectrum
Definition: Constants.h:743
Generates extrapolated NC predictions using ProportionalDecomp.
Generates FD-only predictions (no extrapolation)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
std::map< std::string, Spectrum * > fSpectra
osc::OscCalcSterile * fOscCalc
const Cut kInCosmicTimingWindow
Is the event far from the start and ends of the spill ? For FD cosmic selection.
Definition: TimingCuts.cxx:165
const Cut kNus18ND
Full Nus18 ND analysis selection.
Definition: NusCuts18.h:137
OStream cout
Definition: OStream.cxx:6
std::vector< const ISyst * > fSysts
virtual std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const =0
SpectrumLoader * fLoadersCos
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
T cos(T number)
Definition: d0nt_math.hpp:78
const HistAxis kNus18BinsNumuCCAxis("Reconstructed Neutrino Energy (GeV)", kNus18EnergyBinning, kCCE)
Definition: HistAxes.h:17
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Given loaders and an MC shift, Generate() generates an IPrediction.
void FDPredictionHandler::AddVar ( std::string  name,
std::string  label,
Var  var,
Binning  binning,
Cut  cuts,
SystShifts  shift,
Var  weight 
)

Definition at line 120 of file Nus18PredictionHandlers.h.

References AddVar(), and allInOneTrainingPlots::axis.

120  {
121 
122  const HistAxis axis(label, binning, var);
123 
124  return AddVar(name, axis, cuts, shift, weight);
125 
126 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
const char * label
void FDPredictionHandler::AddVar ( std::string  name,
HistAxis  axis,
Cut  cuts,
SystShifts  shift,
Var  weight,
bool  cutdata = true 
)
virtual

Implements PredictionHandler.

Definition at line 388 of file PredictionHandler.h.

References AddCosmics(), std::cos(), om::cout, allTimeWatchdog::endl, PredictionHandler::fCosmics, PredictionHandler::fCosSpec, PredictionHandler::fData, PredictionHandler::fLoaders, PredictionHandler::fLoadersCos, PredictionHandler::fLoadersData, PredictionHandler::fOscCalc, PredictionHandler::fPredictions, PredictionHandler::fPredOpt, PredictionHandler::fRunSysts, PredictionHandler::fSpectra, PredictionHandler::fSysts, ana::IPredictionGenerator::Generate(), ana::kInBeamSpill, ana::kInCosmicTimingWindow, ana::kNumu2020ND, ana::kNus18BinsNumuCCAxis, ana::kNus18ND, outFile, plot_validation_datamc::pred, and Save().

388  {
389 
390  if (!fLoaders) {
391  std::cout << "Error: Loaders must be set before variables can be added." << std::endl;
392  abort();
393  }
394 
395  Spectrum* spec = nullptr;
396  Spectrum* cos = nullptr;
397  IPrediction* pred = nullptr;
398 
399  // Make the prediction generator
400  IPredictionGenerator* pred_gen = nullptr;
401  if (fPredOpt == "Extrap") {
403  cuts,
405  shift, weight);
406  pred_gen = genExtrap;
407  }
408  else if (fPredOpt == "FDExtrap") {
409  FDPredictionGenerator* genFD = new FDPredictionGenerator(axis, cuts, shift, weight);
410  pred_gen = genFD;
411  }
412  else if (fPredOpt == "NoExtrap") {
413  NoExtrapGenerator* genNoExtrap = new NoExtrapGenerator(axis, cuts, weight);
414  pred_gen = genNoExtrap;
415  }
416 
417  // Get the prediction
418  if (fRunSysts) {
419  PredictionInterp* pred_interp = new PredictionInterp(fSysts, fOscCalc, *pred_gen, *fLoaders);
420  pred = pred_interp;
421  }
422  else
423  pred = pred_gen->Generate(*fLoaders).release();
424 
425  // Make data spectrum
426  if (fData && cutdata)
427  spec = new Spectrum(*fLoadersData, axis, cuts && kInBeamSpill);
428 
429  // Make cosmic spectrum
430  if (fCosmics && cutdata)
431  cos = new Spectrum(*fLoadersCos, axis, cuts && kInCosmicTimingWindow);
432 
433  // Save the data products
434  if (pred)
436  if (spec)
437  fSpectra[name] = spec;
438  if (cos)
439  fCosSpec[name] = cos;
440 
441  return;
442 
443 }
SpectrumLoader * fLoadersData
std::map< std::string, Spectrum * > fCosSpec
const XML_Char * name
Definition: expat.h:151
Implements systematic errors by interpolation between shifted templates.
const Cut kNumu2020ND
Definition: NumuCuts2020.h:57
std::map< std::string, IPrediction * > fPredictions
std::vector< double > Spectrum
Definition: Constants.h:743
Generates extrapolated NC predictions using ProportionalDecomp.
Generates FD-only predictions (no extrapolation)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
std::map< std::string, Spectrum * > fSpectra
osc::OscCalcSterile * fOscCalc
const Cut kInCosmicTimingWindow
Is the event far from the start and ends of the spill ? For FD cosmic selection.
Definition: TimingCuts.cxx:165
const Cut kNus18ND
Full Nus18 ND analysis selection.
Definition: NusCuts18.h:137
OStream cout
Definition: OStream.cxx:6
std::vector< const ISyst * > fSysts
virtual std::unique_ptr< IPrediction > Generate(Loaders &loaders, const SystShifts &shiftMC=kNoShift) const =0
SpectrumLoader * fLoadersCos
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
T cos(T number)
Definition: d0nt_math.hpp:78
const HistAxis kNus18BinsNumuCCAxis("Reconstructed Neutrino Energy (GeV)", kNus18EnergyBinning, kCCE)
Definition: HistAxes.h:17
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Given loaders and an MC shift, Generate() generates an IPrediction.
void FDPredictionHandler::AddVar ( std::string  name,
std::string  label,
Var  var,
Binning  binning,
Cut  cuts,
SystShifts  shift,
Var  weight,
bool  cutdata = true 
)
virtual

Implements PredictionHandler.

Definition at line 350 of file PredictionHandler.h.

References PredictionHandler::AddVar(), and allInOneTrainingPlots::axis.

350  {
351 
352  const HistAxis axis(label, binning, var);
353 
354  return AddVar(name, axis, cuts, shift, weight, cutdata);
355 
356 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
const char * label
void FDPredictionHandler::AddVar ( std::string  name,
std::string  labelx,
std::string  labely,
Var  varx,
Var  vary,
Binning  binningx,
Binning  binningy,
Cut  cuts,
SystShifts  shift,
Var  weight,
bool  cutdata = true 
)
virtual

Implements PredictionHandler.

Definition at line 358 of file PredictionHandler.h.

References PredictionHandler::AddVar(), and allInOneTrainingPlots::axis.

369 {
370 
371  const HistAxis axis(labelx, binningx, varx, labely, binningy, vary);
372 
373  return AddVar(name, axis, cuts, shift, weight, cutdata);
374 
375 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void FDPredictionHandler::AddVar ( std::string  name,
std::string  labelx,
std::string  labely,
std::string  labelz,
Var  varx,
Var  vary,
Var  varz,
Binning  binningx,
Binning  binningy,
Binning  binningz,
Cut  cuts,
SystShifts  shift,
Var  weight,
bool  cutdata = true 
)
virtual

Implements PredictionHandler.

Definition at line 377 of file PredictionHandler.h.

References PredictionHandler::AddVar(), and allInOneTrainingPlots::axis.

382 {
383  const HistAxis axis ({labelx, labely, labelz}, {binningx, binningy, binningz}, {varx, vary, varz});
384 
385  return AddVar(name, axis, cuts, shift, weight, cutdata);
386 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void FDPredictionHandler::Save ( TFile *  outFile)
virtual

Implements PredictionHandler.

Definition at line 184 of file Nus18PredictionHandlers.h.

References fCosmics, fCosSpec, fData, fPredictions, and fSpectra.

Referenced by AddVar(), ExampleCode(), MakeNus18ExtrapPred(), and MakeUnoscPlots().

184  {
185 
186  // Save MC predictions to file
187  for (std::map<std::string, IPrediction*>::const_iterator predIt = fPredictions.begin();
188  predIt != fPredictions.end(); ++predIt)
189  predIt->second->SaveTo(outFile, Form("FD%sPred", predIt->first.c_str()));
190 
191  // Save data spectra to file
192  if (fData)
193  for (std::map<std::string, Spectrum*>::const_iterator specIt = fSpectra.begin();
194  specIt != fSpectra.end(); ++specIt)
195  specIt->second->SaveTo(outFile, Form("FD%sSpec", specIt->first.c_str()));
196 
197  // Save cosmics to file
198  if (fCosmics)
199  for (std::map<std::string, Spectrum*>::const_iterator cosIt = fCosSpec.begin();
200  cosIt != fCosSpec.end(); ++cosIt)
201  cosIt->second->SaveTo(outFile, Form("FD%sCosSpec", cosIt->first.c_str()));
202 
203  return;
204 
205 }
std::map< std::string, Spectrum * > fCosSpec
std::map< std::string, IPrediction * > fPredictions
std::map< std::string, Spectrum * > fSpectra
TFile * outFile
Definition: PlotXSec.C:135
void FDPredictionHandler::Save ( TFile *  outFile)
virtual

Implements PredictionHandler.

Member Data Documentation

bool FDPredictionHandler::fCosmics
private

Definition at line 71 of file Nus18PredictionHandlers.h.

Referenced by AddCosmics(), AddVar(), and Save().

std::map<std::string, Spectrum*> FDPredictionHandler::fCosSpec
private

Definition at line 65 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), Save(), and ~FDPredictionHandler().

bool FDPredictionHandler::fData
private

Definition at line 69 of file Nus18PredictionHandlers.h.

Referenced by AddData(), AddVar(), and Save().

std::map<std::string, CheatDecomp*> PredictionHandler::fDecompositions
protectedinherited
Loaders* FDPredictionHandler::fLoaders
private

Definition at line 54 of file Nus18PredictionHandlers.h.

Referenced by AddLoaders(), and AddVar().

SpectrumLoader* FDPredictionHandler::fLoadersCos
private

Definition at line 56 of file Nus18PredictionHandlers.h.

Referenced by AddCosmics(), and AddVar().

SpectrumLoader* FDPredictionHandler::fLoadersData
private

Definition at line 55 of file Nus18PredictionHandlers.h.

Referenced by AddData(), and AddVar().

osc::OscCalcSterile* FDPredictionHandler::fOscCalc
private

Definition at line 60 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics(), and AddVar().

std::map<std::string, IPrediction*> FDPredictionHandler::fPredictions
private

Definition at line 63 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), Save(), and ~FDPredictionHandler().

std::string FDPredictionHandler::fPredOpt
private

Definition at line 68 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), and FDPredictionHandler().

bool FDPredictionHandler::fRunSysts
private

Definition at line 70 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics(), and AddVar().

std::map<std::string, std::map<std::string, std::pair<Spectrum*, Spectrum*> > > PredictionHandler::fShiftedSpectra
protectedinherited
std::map<std::string, Spectrum*> FDPredictionHandler::fSpectra
private

Definition at line 64 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), Save(), and ~FDPredictionHandler().

std::vector<const ISyst*> FDPredictionHandler::fSysts
private

Definition at line 59 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics(), and AddVar().


The documentation for this class was generated from the following files: