Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ana::PredictionCombinePeriods Class Reference

Sum MC predictions from different periods scaled according to data POT targets. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CAFAna/Prediction/PredictionCombinePeriods.h"

Inheritance diagram for ana::PredictionCombinePeriods:
ana::IPrediction

Public Member Functions

 PredictionCombinePeriods (const std::vector< std::pair< const IPrediction *, double >> &preds)
 
 ~PredictionCombinePeriods ()
 
Spectrum Predict (osc::IOscCalc *calc) const override
 
Spectrum PredictSyst (osc::IOscCalc *calc, const SystShifts &syst) const override
 
Spectrum PredictComponent (osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
Spectrum PredictComponentSyst (osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
OscillatableSpectrum ComponentCC (int from, int to) const override
 
Spectrum ComponentNCTotal () const override
 
Spectrum ComponentNC () const override
 
Spectrum ComponentNCAnti () const override
 
void SaveTo (TDirectory *dir, const std::string &name) const override
 
unsigned int NPredictions () const
 
const IPredictionGetPrediction (int i) const
 
double GetPOT (int i) const
 
virtual Spectrum PredictUnoscillated () const
 
virtual Spectrum Predict (osc::IOscCalcStan *calc) const
 
virtual Spectrum PredictSyst (osc::IOscCalcStan *calc, const SystShifts &syst) const
 
virtual Spectrum PredictComponent (osc::IOscCalcStan *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
 
virtual Spectrum PredictComponentSyst (osc::IOscCalcStan *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
 

Static Public Member Functions

static std::unique_ptr< PredictionCombinePeriodsLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Attributes

std::vector< std::pair< const IPrediction *, double > > fPreds
 

Detailed Description

Sum MC predictions from different periods scaled according to data POT targets.

Be sure you understand how putting one of these in a SingleSampleExperiment differs from putting regular predictions for the different periods into a MultiExperiment. This calculates chisq(data1+data2|mc1+mc2), whereas the MultiExperiment is chisq(data1|mc1)+chisq(data2+mc2).

Definition at line 14 of file PredictionCombinePeriods.h.

Constructor & Destructor Documentation

ana::PredictionCombinePeriods::PredictionCombinePeriods ( const std::vector< std::pair< const IPrediction *, double >> &  preds)
Parameters
predsList of predictions to combine, along with the POT target for that period. Should be like: {{pred1, data1.POT()}, {pred2, data2.POT()}}

Definition at line 18 of file PredictionCombinePeriods.cxx.

References ana::assert(), and fPreds.

Referenced by LoadFrom().

19  : fPreds(preds)
20  {
21  assert(!fPreds.empty());
22  }
std::vector< std::pair< const IPrediction *, double > > fPreds
assert(nhit_max >=nhit_nbins)
ana::PredictionCombinePeriods::~PredictionCombinePeriods ( )

Definition at line 25 of file PredictionCombinePeriods.cxx.

26  {
27  // It's pretty normal for the elements of fPred to have come from the stack
28  // for(auto it: fPreds) delete it.first;
29  }

Member Function Documentation

OscillatableSpectrum ana::PredictionCombinePeriods::ComponentCC ( int  from,
int  to 
) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 105 of file PredictionCombinePeriods.cxx.

References ana::bins, ana::IPrediction::ComponentCC(), fPreds, ana::ReweightableSpectrum::GetBinnings(), ana::ReweightableSpectrum::GetEigen(), ana::ReweightableSpectrum::GetLabels(), make_syst_table_plots::h, it, PandAna.Demos.pi0_spectra::labels, and plot_validation_datamc::pred.

106  {
107  // TODO this is a total copy-paste job from the above.
108 
109  Eigen::MatrixXd asum;
110 
111  std::vector<std::string> labels;
112  std::vector<Binning> bins;
113 
114  double potsum = 0;
115  double livesum = 0;
116  for(auto it: fPreds){
117  const IPrediction* pred = it.first;
118  const double targetPOT = it.second;
119  const OscillatableSpectrum s = pred->ComponentCC(from, to);
120 
121  Eigen::MatrixXd h = s.GetEigen(targetPOT);
122  potsum += targetPOT;
123  // No. FD MC is going to have zero (unknown) livetime anyway. If someone
124  // needs this livetime accounting, they can come and think hard about it
125  // and then reinstate it.
126  // livesum += s.Livetime()*targetPOT/s.POT();
127 
128  if(asum.size() > 0){
129  asum += h;
130  }
131  else{
132  asum = h;
133  labels = s.GetLabels();
134  bins = s.GetBinnings();
135  }
136  }
137 
138  return OscillatableSpectrum(std::move(asum),
139  HistAxis(labels, bins),
140  potsum, livesum);
141  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
set< int >::iterator it
std::vector< std::pair< const IPrediction *, double > > fPreds
const XML_Char * s
Definition: expat.h:262
const Binning bins
Definition: NumuCC_CPiBin.h:8
Spectrum ana::PredictionCombinePeriods::ComponentNC ( ) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 150 of file PredictionCombinePeriods.cxx.

References ana::Flavors::kAll, ana::Current::kNC, ana::Sign::kNu, noosc, and PredictComponent().

151  {
154  }
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Neutrinos-only.
Definition: IPrediction.h:49
Neutral-current interactions.
Definition: IPrediction.h:40
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum ana::PredictionCombinePeriods::ComponentNCAnti ( ) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 155 of file PredictionCombinePeriods.cxx.

References ana::Flavors::kAll, ana::Sign::kAntiNu, ana::Current::kNC, noosc, and PredictComponent().

156  {
159  }
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
Antineutrinos-only.
Definition: IPrediction.h:50
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Neutral-current interactions.
Definition: IPrediction.h:40
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum ana::PredictionCombinePeriods::ComponentNCTotal ( ) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 145 of file PredictionCombinePeriods.cxx.

References ana::Flavors::kAll, ana::Sign::kBoth, ana::Current::kNC, noosc, and PredictComponent().

146  {
149  }
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Neutral-current interactions.
Definition: IPrediction.h:40
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
All neutrinos, any flavor.
Definition: IPrediction.h:26
double ana::PredictionCombinePeriods::GetPOT ( int  i) const
inline

Definition at line 57 of file PredictionCombinePeriods.h.

References fPreds, and MECModelEnuComparisons::i.

57 {return fPreds[i].second;}
std::vector< std::pair< const IPrediction *, double > > fPreds
const IPrediction* ana::PredictionCombinePeriods::GetPrediction ( int  i) const
inline

Definition at line 56 of file PredictionCombinePeriods.h.

References fPreds, and MECModelEnuComparisons::i.

Referenced by PlotSysts().

56 {return fPreds[i].first;}
std::vector< std::pair< const IPrediction *, double > > fPreds
std::unique_ptr< PredictionCombinePeriods > ana::PredictionCombinePeriods::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 191 of file PredictionCombinePeriods.cxx.

References ana::assert(), dir, genie::utils::style::Format(), MECModelEnuComparisons::i, ana::LoadFrom< IPrediction >(), pots, plot_validation_datamc::pred, PredictionCombinePeriods(), runNovaSAM::release, and getGoodRuns4SAM::tag.

Referenced by BlessedPlotsAnaByPeriod(), CalcRWithSysts(), FDDataMCSystBandAna(), FitParamEffectsAna(), FitSystEffectsAna(), LoadMaps(), SaveTo(), SpectrumParamEffectsAna(), and SystsOscParamAna().

192  {
193  dir = dir->GetDirectory(name.c_str()); // switch to subdir
194  assert(dir);
195 
196  TObjString* tag = (TObjString*)dir->Get("type");
197  assert(tag);
198  assert(tag->GetString() == "PredictionCombinePeriods");
199  delete tag;
200 
201  TVectorD* pots = (TVectorD*)dir->Get("pots");
202  assert(pots);
203 
204  std::vector<std::pair<const IPrediction*, double>> preds;
205 
206  for(int i = 0; i < pots->GetNrows(); ++i){
207  const IPrediction* pred = ana::LoadFrom<IPrediction>(dir, TString::Format("pred%d", i).Data()).release();
208  assert(pred);
209  preds.emplace_back(pred, (*pots)[i]);
210  }
211 
212  delete dir;
213 
214  return std::unique_ptr<PredictionCombinePeriods>(new PredictionCombinePeriods(preds));
215  }
const XML_Char * name
Definition: expat.h:151
int pots
PredictionCombinePeriods(const std::vector< std::pair< const IPrediction *, double >> &preds)
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir, const std::string &label)
Definition: IPrediction.cxx:18
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
unsigned int ana::PredictionCombinePeriods::NPredictions ( ) const
inline

Definition at line 55 of file PredictionCombinePeriods.h.

References fPreds.

55 {return fPreds.size();}
std::vector< std::pair< const IPrediction *, double > > fPreds
Spectrum ana::PredictionCombinePeriods::Predict ( osc::IOscCalc calc) const
overridevirtual

Implements ana::IPrediction.

Definition at line 32 of file PredictionCombinePeriods.cxx.

References ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, and PredictComponent().

Referenced by drawSystsShiftingNDdata(), futureSig_reach_singlePOTcombo_syst(), MakeNusPrediction(), PlotStack(), PlotSysts(), saveContours_complete(), and SpectrumParamEffectsAna().

33  {
34  return PredictComponent(calc,
37  Sign::kBoth);
38  }
Interactions of both types.
Definition: IPrediction.h:42
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum ana::IPrediction::Predict ( osc::IOscCalcStan calc) const
virtualinherited

Reimplemented in ana::PredictionInterp, ana::PredictionExtendToPeripheral, ana::PredictionNoOsc, ana::PredictionExtrapSum, ana::PredictionExtrap, and ana::PredictionAddRock.

Definition at line 43 of file IPrediction.cxx.

References ana::assert().

44  {
45  assert(0 && "This Prediction hasn't implemented a Stan-aware Predict()!");
46  }
assert(nhit_max >=nhit_nbins)
Spectrum ana::PredictionCombinePeriods::PredictComponent ( osc::IOscCalc calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtual

Implements ana::IPrediction.

Definition at line 52 of file PredictionCombinePeriods.cxx.

References ana::SystShifts::Nominal(), and PredictComponentSyst().

Referenced by CalcRWithSysts(), ComponentNC(), ComponentNCAnti(), ComponentNCTotal(), PlotStack(), PlotSysts(), Predict(), and PredictSyst().

56  {
58  flav, curr, sign);
59  }
static SystShifts Nominal()
Definition: SystShifts.h:34
Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
def sign(x)
Definition: canMan.py:197
Spectrum ana::IPrediction::PredictComponent ( osc::IOscCalcStan calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
virtualinherited

Reimplemented in ana::PredictionInterp, ana::PredictionNoOsc, ana::PredictionExtendToPeripheral, ana::PredictionExtrapSum, ana::PredictionAddRock, and ana::PredictionExtrap.

Definition at line 70 of file IPrediction.cxx.

References ana::assert().

74  {
75  assert(0 && "This Prediction hasn't implemented a Stan-aware PredictComponent()!");
76  }
assert(nhit_max >=nhit_nbins)
Spectrum ana::PredictionCombinePeriods::PredictComponentSyst ( osc::IOscCalc calc,
const SystShifts syst,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 63 of file PredictionCombinePeriods.cxx.

References ana::bins, fPreds, ana::Spectrum::GetBinnings(), ana::Spectrum::GetEigen(), ana::Spectrum::GetLabels(), make_syst_table_plots::h, it, PandAna.Demos.pi0_spectra::labels, plot_validation_datamc::pred, and ana::IPrediction::PredictComponentSyst().

Referenced by CalcRWithSysts(), PredictComponent(), and PredictSyst().

68  {
69  Eigen::ArrayXd asum;
70 
71  std::vector<std::string> labels;
72  std::vector<Binning> bins;
73 
74  double potsum = 0;
75  double livesum = 0;
76  for(auto it: fPreds){
77  const IPrediction* pred = it.first;
78  const double targetPOT = it.second;
79  const Spectrum s = pred->PredictComponentSyst(calc, syst,
80  flav, curr, sign);
81 
82  Eigen::ArrayXd h = s.GetEigen(targetPOT);
83  potsum += targetPOT;
84  // No. FD MC is going to have zero (unknown) livetime anyway. If someone
85  // needs this livetime accounting, they can come and think hard about it
86  // and then reinstate it.
87  // livesum += s.Livetime()*targetPOT/s.POT();
88 
89  if(asum.size() > 0){
90  asum += h;
91  }
92  else{
93  asum = h;
94  labels = s.GetLabels();
95  bins = s.GetBinnings();
96  }
97  }
98 
99  return Spectrum(std::move(asum),
100  HistAxis(labels, bins),
101  potsum, livesum);
102  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
set< int >::iterator it
std::vector< std::pair< const IPrediction *, double > > fPreds
const XML_Char * s
Definition: expat.h:262
std::vector< float > Spectrum
Definition: Constants.h:610
const Binning bins
Definition: NumuCC_CPiBin.h:8
def sign(x)
Definition: canMan.py:197
Spectrum ana::IPrediction::PredictComponentSyst ( osc::IOscCalcStan calc,
const SystShifts syst,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
virtualinherited

Reimplemented in ana::PredictionInterp, and ana::PredictionAddRock.

Definition at line 93 of file IPrediction.cxx.

References ana::assert(), ana::SystShifts::IsNominal(), and ana::IPrediction::PredictComponent().

98  {
99  assert(syst.IsNominal() && "This Prediction doesn't support PredictSyst(). Did you just mean Predict()?");
100 
101  // Default implementation: no treatment of systematics
102  return PredictComponent(calc, flav, curr, sign);
103  }
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const =0
assert(nhit_max >=nhit_nbins)
def sign(x)
Definition: canMan.py:197
Spectrum ana::PredictionCombinePeriods::PredictSyst ( osc::IOscCalc calc,
const SystShifts syst 
) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 41 of file PredictionCombinePeriods.cxx.

References ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, PredictComponent(), and PredictComponentSyst().

Referenced by PlotSysts().

43  {
44  return PredictComponentSyst(calc, syst,
47  Sign::kBoth);
48  }
Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Interactions of both types.
Definition: IPrediction.h:42
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum ana::IPrediction::PredictSyst ( osc::IOscCalcStan calc,
const SystShifts syst 
) const
virtualinherited

Reimplemented in ana::PredictionInterp, and ana::PredictionAddRock.

Definition at line 59 of file IPrediction.cxx.

References ana::assert(), ana::SystShifts::IsNominal(), and ana::IPrediction::Predict().

61  {
62  assert(syst.IsNominal() && "This Prediction doesn't support PredictSyst(). Did you just mean Predict()?");
63 
64  // Default implementation: no treatment of systematics
65  return Predict(calc);
66  }
virtual Spectrum Predict(osc::IOscCalc *calc) const =0
assert(nhit_max >=nhit_nbins)
Spectrum ana::IPrediction::PredictUnoscillated ( ) const
virtualinherited

Reimplemented in ana::PredictionSterile.

Definition at line 33 of file IPrediction.cxx.

References noosc, and ana::IPrediction::Predict().

Referenced by cc(), demo5(), demo::DrawUpDownRatioCanvas(), efficiency(), efficiencySA(), plot_nd_data_mc(), template_basic(), and test_ana().

34  {
35  // Default implementation
37  return Predict(&noosc);
38  }
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
virtual Spectrum Predict(osc::IOscCalc *calc) const =0
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
void ana::PredictionCombinePeriods::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 164 of file PredictionCombinePeriods.cxx.

References dir, genie::utils::style::Format(), fPreds, MECModelEnuComparisons::i, compare_h5_caf::idx, it, LoadFrom(), pots, moon_position_table_new3::second, and tmp.

Referenced by MakeNusPrediction().

165  {
166  TDirectory* tmp = gDirectory;
167 
168  dir = dir->mkdir(name.c_str()); // switch to subdir
169  dir->cd();
170 
171  TObjString("PredictionCombinePeriods").Write("type");
172 
173  int idx = 0;
174  for(auto it: fPreds)
175  it.first->SaveTo(dir, TString::Format("pred%d", idx++).Data());
176 
177  TVectorD pots(fPreds.size());
178  for(unsigned int i = 0; i < fPreds.size(); ++i)
179  pots[i] = fPreds[i].second;
180 
181  pots.Write("pots");
182 
183  dir->Write();
184  delete dir;
185 
186  tmp->cd();
187  }
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
int pots
Float_t tmp
Definition: plot.C:36
std::vector< std::pair< const IPrediction *, double > > fPreds
TDirectory * dir
Definition: macro.C:5
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154

Member Data Documentation

std::vector<std::pair<const IPrediction*, double> > ana::PredictionCombinePeriods::fPreds
protected

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