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

Class to handle ND predictions. More...

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

Inheritance diagram for NDPredictionHandler:
PredictionHandler

Public Member Functions

 NDPredictionHandler (Loaders *loaders, std::string predOpt, bool data)
 
 ~NDPredictionHandler ()
 
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)
 
 NDPredictionHandler (std::string predOpt, bool isData=false, Loaders *loaders=nullptr)
 
 ~NDPredictionHandler ()
 
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 AddLoaders (Loaders *loaders)
 
void AddData (SpectrumLoader *loadersData)
 

Protected Attributes

SpectrumLoaderfLoadersData
 
SpectrumLoaderfLoadersCos
 
std::map< std::string, Spectrum * > fCosSpec
 
bool fCosmics
 

Private Attributes

LoadersfLoaders
 
std::vector< const ISyst * > fSysts
 
osc::OscCalcSterilefOscCalc
 
std::map< std::string, CheatDecomp * > fDecompositions
 
std::map< std::string, IPrediction * > fPredictions
 
std::map< std::string, Spectrum * > fSpectra
 
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
 
std::string fPredOpt
 
bool fData
 
bool fRunSysts
 

Detailed Description

Class to handle ND predictions.

Definition at line 208 of file Nus18PredictionHandlers.h.

Constructor & Destructor Documentation

NDPredictionHandler::NDPredictionHandler ( Loaders loaders,
std::string  predOpt,
bool  data 
)

Definition at line 241 of file Nus18PredictionHandlers.h.

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

241  :
242  fLoaders(loaders),
243  fPredOpt(predOpt),
244  fData(data),
245  fRunSysts(false) {
246 
247  // Make sure the Prediction Handler is set up to handle the prediction option
248  if (fPredOpt != "Decomp" and fPredOpt != "NDExtrap") {
249  std::cout << "The Prediction Handler is not set up to handle " << fPredOpt << " predictions." << std::endl;
250  std::cout << "Currently options are Decomp (CheatDecomp), or NDExtrap (NDPredictionSterile)." << std::endl;
251  abort();
252  }
253 }
const XML_Char const XML_Char * data
Definition: expat.h:268
OStream cout
Definition: OStream.cxx:6
NDPredictionHandler::~NDPredictionHandler ( )

Definition at line 255 of file Nus18PredictionHandlers.h.

References plot_validation_datamc_2018::decomp, fDecompositions, fShiftedSpectra, and fSpectra.

255  {
256  for (const auto& decomp : fDecompositions)
257  delete decomp.second;
258  for (const auto& shift : fShiftedSpectra) {
259  for (const auto& syst : shift.second) {
260  delete syst.second.first;
261  delete syst.second.second;
262  }
263  }
264  for (const auto& spectum : fSpectra)
265  delete spectum.second;
266 }
std::map< std::string, Spectrum * > fSpectra
std::map< std::string, CheatDecomp * > fDecompositions
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
NDPredictionHandler::NDPredictionHandler ( std::string  predOpt,
bool  isData = false,
Loaders loaders = nullptr 
)
inline

Definition at line 157 of file PredictionHandler.h.

158  : PredictionHandler(predOpt, isData, loaders)
159  {
160  }
PredictionHandler(std::string predOpt, bool isData=false, Loaders *loaders=nullptr)
NDPredictionHandler::~NDPredictionHandler ( )
inline

Member Function Documentation

void PredictionHandler::AddData ( SpectrumLoader loadersData)
inherited

Definition at line 140 of file PredictionHandler.h.

References PredictionHandler::fData, and PredictionHandler::fLoadersData.

Referenced by ExampleCode(), and MakeUnoscPlots().

140  {
141  fData = true;
142  fLoadersData = loadersData;
143 }
SpectrumLoader * fLoadersData
void PredictionHandler::AddLoaders ( Loaders loaders)
inherited

Definition at line 136 of file PredictionHandler.h.

References PredictionHandler::fLoaders, and loaders.

Referenced by ExampleCode(), and MakeUnoscPlots().

136  {
137  fLoaders = loaders;
138 }
std::vector< Loaders * > loaders
Definition: syst_header.h:386
void NDPredictionHandler::AddSystematics ( std::vector< const ISyst * >  systs,
osc::OscCalcSterile calc 
)

Definition at line 268 of file Nus18PredictionHandlers.h.

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

268  {
269  fRunSysts = true;
270  fSysts = systs;
271  fOscCalc = calc;
272 }
std::vector< const ISyst * > fSysts
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
osc::OscCalcDumb calc
osc::OscCalcSterile * fOscCalc
void NDPredictionHandler::AddVar ( std::string  name,
HistAxis  axis,
Cut  cuts,
SystShifts  shift,
Var  weight,
bool  cutdata = true 
)
virtual

Implements PredictionHandler.

Definition at line 229 of file PredictionHandler.h.

References allInOneTrainingPlots::axis, om::cout, update_sam_good_runs_metadata::cuts, plot_validation_datamc_2018::decomp, allTimeWatchdog::endl, PredictionHandler::fData, PredictionHandler::fDecompositions, PredictionHandler::fLoaders, PredictionHandler::fLoadersData, PredictionHandler::fPredictions, PredictionHandler::fPredOpt, PredictionHandler::fRunSysts, PredictionHandler::fShiftedSpectra, PredictionHandler::fSpectra, PredictionHandler::fSysts, ana::NDPredictionGenerator::Generate(), ana::Loaders::GetLoader(), kMC, caf::kNEARDET, make_pair(), outFile, plot_validation_datamc::pred, Save(), string, cvnie::subdir, and ana::weight.

235 {
236 
237  CheatDecomp* decomp = nullptr;
238  IPrediction* pred = nullptr;
239  Spectrum* spec = nullptr;
240 
241  // Decomposition
242  if (fPredOpt == "Decomp")
244  axis, cuts, shift, weight);
245 
246  // Predictions
247  if (fPredOpt == "NDExtrap") {
248  const NDPredictionGenerator genND(axis, cuts, shift, weight);
249  pred = genND.Generate(*fLoaders).release();
250  }
251 
252  // Systematics
253  std::map<std::string, std::pair<Spectrum*, Spectrum*> > shifts;
254  if (fRunSysts) {
255  for (const auto& shift : fSysts) {
257  axis, cuts, SystShifts(shift, +1), weight);
259  axis, cuts, SystShifts(shift, -1), weight);
260  shifts[shift->ShortName()] = std::make_pair(shiftUp, shiftDown);
261  }
262  }
263 
264  // Make data spectrum
265  if (fData && cutdata)
266  spec = new Spectrum(*fLoadersData, axis, cuts);
267 
268  if (decomp)
270  if (pred)
272  if (shifts.size())
273  fShiftedSpectra[name] = shifts;
274  if (spec)
275  fSpectra[name] = spec;
276 
277  return;
278 
279 }
Near Detector underground.
Definition: SREnums.h:10
std::vector< const ISyst * > fSysts
const XML_Char * name
Definition: expat.h:151
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const Color_t kMC
std::vector< double > Spectrum
Definition: Constants.h:743
std::map< std::string, Spectrum * > fSpectra
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
std::map< std::string, CheatDecomp * > fDecompositions
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
SpectrumLoaderBase & GetLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:129
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
SpectrumLoader * fLoadersData
std::map< std::string, IPrediction * > fPredictions
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Generates Near Detector predictions.
Just return the ND truth spectra as the decomposition.
Definition: CheatDecomp.h:10
void NDPredictionHandler::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 183 of file PredictionHandler.h.

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

191 {
192 
193  const HistAxis axis(label, binning, var);
194 
195  return AddVar(name, axis, cuts, shift, weight, cutdata);
196 
197 }
const XML_Char * name
Definition: expat.h:151
const char * label
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void NDPredictionHandler::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 199 of file PredictionHandler.h.

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

210 {
211 
212  const HistAxis axis(labelx, binningx, varx, labely, binningy, vary);
213 
214  return AddVar(name, axis, cuts, shift, weight, cutdata);
215 
216 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void NDPredictionHandler::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 218 of file PredictionHandler.h.

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

223 {
224  const HistAxis axis ({labelx, labely, labelz}, {binningx, binningy, binningz}, {varx, vary, varz});
225 
226  return AddVar(name, axis, cuts, shift, weight, cutdata);
227 }
const XML_Char * name
Definition: expat.h:151
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void NDPredictionHandler::AddVar ( std::string  name,
HistAxis  axis,
Cut  cuts,
SystShifts  shift,
Var  weight 
)

Definition at line 282 of file Nus18PredictionHandlers.h.

References allInOneTrainingPlots::axis, update_sam_good_runs_metadata::cuts, plot_validation_datamc_2018::decomp, fData, fDecompositions, fLoaders, fPredictions, fPredOpt, fRunSysts, fShiftedSpectra, fSpectra, fSysts, ana::NDPredictionGenerator::Generate(), ana::Loaders::GetLoader(), cmf::kData, kMC, caf::kNEARDET, make_pair(), plot_validation_datamc::pred, and ana::weight.

Referenced by AddVar().

282  {
283 
284  CheatDecomp* decomp = nullptr;
285  IPrediction* pred = nullptr;
286  Spectrum* spec = nullptr;
287 
288  // Decomposition
289  if (fPredOpt == "Decomp")
291  axis, cuts, shift, weight);
292 
293  // Predictions
294  if (fPredOpt == "NDExtrap") {
295  const NDPredictionGenerator genND(axis, cuts, shift, weight);
296  pred = genND.Generate(*fLoaders).release();
297  }
298 
299  // Systematics
300  std::map<std::string, std::pair<Spectrum*, Spectrum*> > shifts;
301  if (fRunSysts) {
302  for (const auto& shift : fSysts) {
304  axis, cuts, SystShifts(shift, +1), weight);
306  axis, cuts, SystShifts(shift, -1), weight);
307  shifts[shift->ShortName()] = std::make_pair(shiftUp, shiftDown);
308  }
309  }
310 
311  // Data
312  if (fData)
314  axis, cuts);
315 
316  if (decomp)
318  if (pred)
320  if (shifts.size())
321  fShiftedSpectra[name] = shifts;
322  if (spec)
323  fSpectra[name] = spec;
324 
325  return;
326 
327 }
Near Detector underground.
Definition: SREnums.h:10
std::vector< const ISyst * > fSysts
const XML_Char * name
Definition: expat.h:151
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const Color_t kMC
std::vector< double > Spectrum
Definition: Constants.h:743
std::map< std::string, Spectrum * > fSpectra
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
std::map< std::string, CheatDecomp * > fDecompositions
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
SpectrumLoaderBase & GetLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:129
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
std::map< std::string, IPrediction * > fPredictions
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Generates Near Detector predictions.
Just return the ND truth spectra as the decomposition.
Definition: CheatDecomp.h:10
void NDPredictionHandler::AddVar ( std::string  name,
std::string  label,
Var  var,
Binning  binning,
Cut  cuts,
SystShifts  shift,
Var  weight 
)

Definition at line 274 of file Nus18PredictionHandlers.h.

References AddVar(), and allInOneTrainingPlots::axis.

274  {
275 
276  const HistAxis axis(label, binning, var);
277 
278  return AddVar(name, axis, cuts, shift, weight);
279 
280 }
const XML_Char * name
Definition: expat.h:151
const char * label
void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight)
void NDPredictionHandler::Save ( TFile *  outFile)
virtual

Implements PredictionHandler.

void NDPredictionHandler::Save ( TFile *  outFile)
virtual

Implements PredictionHandler.

Definition at line 329 of file Nus18PredictionHandlers.h.

References fData, fDecompositions, fShiftedSpectra, fSpectra, string, and cvnie::subdir.

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

329  {
330 
331  // Save MC decompositions to file
332  for (std::map<std::string, CheatDecomp*>::const_iterator decompIt = fDecompositions.begin();
333  decompIt != fDecompositions.end(); ++decompIt)
334  decompIt->second->SaveTo(outFile, Form("ND%sDecomp", decompIt->first.c_str()));
335 
336  // Save systematics to file
337  for (std::map<std::string, std::map<std::string, std::pair<Spectrum*, Spectrum*> > >::const_iterator shiftIt = fShiftedSpectra.begin();
338  shiftIt != fShiftedSpectra.end(); ++shiftIt) {
339  TString subdir = Form("ND%sDecompSysts", shiftIt->first.c_str());
340  outFile->cd();
341  outFile->mkdir(subdir);
342  for (std::map<std::string, std::pair<Spectrum*, Spectrum*> >::const_iterator systIt = shiftIt->second.begin();
343  systIt != shiftIt->second.end(); ++systIt) {
344  TString subsubdir = systIt->first.c_str();
345  outFile->cd(subdir);
346  gDirectory->mkdir(subsubdir);
347  gDirectory->cd(subsubdir);
348  systIt->second.first->SaveTo(gDirectory, "ShiftUp");
349  systIt->second.second->SaveTo(gDirectory, "ShiftDown");
350  }
351  }
352 
353  // Save data spectra to file
354  if (fData)
355  for (std::map<std::string, Spectrum*>::const_iterator specIt = fSpectra.begin();
356  specIt != fSpectra.end(); ++specIt)
357  specIt->second->SaveTo(outFile, Form("ND%sSpec", specIt->first.c_str()));
358 
359  return;
360 
361 }
subdir
Definition: cvnie.py:7
std::map< std::string, Spectrum * > fSpectra
std::map< std::string, CheatDecomp * > fDecompositions
TFile * outFile
Definition: PlotXSec.C:135
std::map< std::string, std::map< std::string, std::pair< Spectrum *, Spectrum * > > > fShiftedSpectra
enum BeamMode string

Member Data Documentation

bool PredictionHandler::fCosmics
protectedinherited

Definition at line 89 of file PredictionHandler.h.

Referenced by FDPredictionHandler::AddVar().

std::map<std::string, Spectrum*> PredictionHandler::fCosSpec
protectedinherited
bool NDPredictionHandler::fData
private

Definition at line 236 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), and Save().

std::map<std::string, CheatDecomp*> NDPredictionHandler::fDecompositions
private

Definition at line 229 of file Nus18PredictionHandlers.h.

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

Loaders* NDPredictionHandler::fLoaders
private

Definition at line 222 of file Nus18PredictionHandlers.h.

Referenced by AddVar().

SpectrumLoader* PredictionHandler::fLoadersCos
protectedinherited

Definition at line 72 of file PredictionHandler.h.

Referenced by FDPredictionHandler::AddVar().

SpectrumLoader* PredictionHandler::fLoadersData
protectedinherited
osc::OscCalcSterile* NDPredictionHandler::fOscCalc
private

Definition at line 226 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics().

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

Definition at line 230 of file Nus18PredictionHandlers.h.

Referenced by AddVar().

std::string NDPredictionHandler::fPredOpt
private

Definition at line 235 of file Nus18PredictionHandlers.h.

Referenced by AddVar(), and NDPredictionHandler().

bool NDPredictionHandler::fRunSysts
private

Definition at line 237 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics(), and AddVar().

std::map<std::string, std::map<std::string, std::pair<Spectrum*, Spectrum*> > > NDPredictionHandler::fShiftedSpectra
private

Definition at line 232 of file Nus18PredictionHandlers.h.

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

std::map<std::string, Spectrum*> NDPredictionHandler::fSpectra
private

Definition at line 231 of file Nus18PredictionHandlers.h.

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

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

Definition at line 225 of file Nus18PredictionHandlers.h.

Referenced by AddSystematics(), and AddVar().


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