All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PredictionScaleComp.cxx
Go to the documentation of this file.
2 
8 
9 #include "TDirectory.h"
10 #include "TObjString.h"
11 #include "TH1.h"
12 #include "TVectorD.h"
13 
14 #include <cassert>
15 
16 namespace ana
17 {
18  //----------------------------------------------------------------------
21  const HistAxis& axis,
22  SpillCut spillcut,
23  Cut cut,
24  const std::vector<const SystComponentScale*>& systs,
25  const SystShifts& shift,
26  const Var& wei)
27  : fSysts(systs)
28  {
29  Cut complementCut = kNoCut;
30 
31  assert(!systs.empty() && "Please give at least one systematic.");
32  for(const SystComponentScale* syst: systs){
33  fPreds.push_back(new PredictionNoOsc(loader, axis,
34  spillcut, cut && syst->GetCut(), shift, wei));
35  }
36 
37  fTotal = new PredictionNoOsc(loader, axis, spillcut, cut, shift, wei);
38  }
39 
40  //----------------------------------------------------------------------
43  SpectrumLoaderBase& loaderNue,
44  SpectrumLoaderBase& loaderNuTau,
45  SpectrumLoaderBase& loaderIntrinsic,
46  const HistAxis& axis,
47  SpillCut spillcut,
48  Cut cut,
49  const std::vector<const SystComponentScale*>& systs,
50  const SystShifts& shift,
51  const Var& wei)
52  : fSysts(systs)
53  {
54  assert(!systs.empty() && "Please give at least one systematic.");
55  for(const SystComponentScale* syst: systs){
56  fPreds.push_back(new PredictionNoExtrap(loaderNonswap, loaderNue, loaderNuTau, loaderIntrinsic,
57  axis, spillcut, cut && syst->GetCut(), shift, wei));
58  }
59 
60  fTotal = new PredictionNoExtrap(loaderNonswap, loaderNue, loaderNuTau, loaderIntrinsic,
61  axis, spillcut, cut, shift, wei);
62  }
63 
64  //----------------------------------------------------------------------
67  const HistAxis& axis1,
68  const HistAxis& axis2,
69  SpillCut spillcut,
70  Cut cut,
71  const std::vector<const SystComponentScale*>& systs,
72  const SystShifts& shift,
73  const Var& wei)
74  {
75  assert(0 && "unimplemented");
76 
77  // TODO TODO TODO
78  /*
79  assert(truthcuts.size()>0 && "Please give at least one truth selection.");
80  for(unsigned int i = 0; i < truthcuts.size(); ++i){
81  fPreds.push_back(new PredictionNoOsc(loader, axis1, axis2,
82  cut && truthcuts[i], shift, wei));
83  fSysts.push_back(new DummyScaleCompSyst(i));
84  fComplementCut = fComplementCut && !truthcuts[i];
85  }
86 
87  // The idea is that if truthcuts are exhaustive, this Spectrum should wind
88  // up empty
89  fComplement = new Spectrum(loader, axis1, axis2,
90  cut && fComplementCut, shift, wei);
91  */
92  }
93 
94  //----------------------------------------------------------------------
97  const std::vector<const IPrediction*>& preds,
98  const std::vector<const SystComponentScale*>& systs)
99  : fSysts(systs),
100  fPreds(preds),
101  fTotal(total)
102  {
103  }
104 
105  //----------------------------------------------------------------------
107  {
108  for(const IPrediction* p: fPreds) delete p;
109  delete fTotal;
110  }
111 
112  //----------------------------------------------------------------------
114  const SystShifts& shift,
115  Flavors::Flavors_t flav,
116  Current::Current_t curr,
117  Sign::Sign_t sign) const
118  {
119  SystShifts shiftClean = shift;
120  for(const ISyst* s: fSysts) shiftClean.SetShift(s, 0);
121 
122  // Starting with the total and adding in the differences for components
123  // that need to change is faster if most of the knobs are set to zero.
124  Spectrum ret = fTotal->PredictSyst(calc, shiftClean);
125 
126  for(unsigned int i = 0; i < fPreds.size(); ++i){
127  const double x = shift.GetShift(fSysts[i]);
128  if(x == 0) continue; // Nominal, can skip
129 
130  Spectrum si = fPreds[i]->PredictComponentSyst(calc, shiftClean,
131  flav, curr, sign);
132 
133  si.Scale(pow(1+fSysts[i]->OneSigmaScale(), x) - 1);
134 
135  ret += si;
136  }
137 
138  return ret;
139  }
140 
141  //----------------------------------------------------------------------
144  const SystComponentScale* syst) const
145  {
146  for(unsigned int i = 0; i < fSysts.size(); ++i){
147  if(fSysts[i] == syst) return fPreds[i]->Predict(osc);
148  }
149 
150  std::cout << "PredictionScaleComp::PredictCategory(): Unknown systematic " << syst->ShortName() << std::endl;
151  abort();
152  }
153 
154  //----------------------------------------------------------------------
155  void PredictionScaleComp::SaveTo(TDirectory* dir) const
156  {
157  TDirectory* tmp = gDirectory;
158  dir->cd();
159 
160  TObjString("PredictionScaleComp").Write("type");
161 
162  fTotal->SaveTo(dir->mkdir("total"));
163 
164  for(unsigned int i = 0; i < fPreds.size(); ++i){
165  fPreds[i]->SaveTo(dir->mkdir(("pred"+std::to_string(i)).c_str()));
166  }
167 
168  for(unsigned int i = 0; i < fSysts.size(); ++i){
169  fSysts[i]->SaveTo(dir->mkdir(("syst"+std::to_string(i)).c_str()));
170  }
171 
172  tmp->cd();
173  }
174 
175  //----------------------------------------------------------------------
176  std::unique_ptr<PredictionScaleComp> PredictionScaleComp::LoadFrom(TDirectory* dir)
177  {
178  IPrediction* total = ana::LoadFrom<IPrediction>(dir->GetDirectory("total")).release();
179 
180  std::vector<const IPrediction*> preds;
181  for(unsigned int i = 0; ; ++i){
182  TDirectory* di = dir->GetDirectory(("pred"+std::to_string(i)).c_str());
183  if(!di) break; // We got all the predictions
184 
185  preds.push_back(ana::LoadFrom<IPrediction>(di).release());
186  }
187 
188  std::vector<const SystComponentScale*> systs;
189  for(unsigned int i = 0; ; ++i){
190  TDirectory* si = dir->GetDirectory(("syst"+std::to_string(i)).c_str());
191  if(!si) break; // We got all the predictions
192 
193  systs.push_back(ana::LoadFrom<SystComponentScale>(si).release());
194  }
195 
196  return std::unique_ptr<PredictionScaleComp>(new PredictionScaleComp(total, preds, systs));
197  }
198 
199 }
const Cut kNoCut([](const caf::SRSliceProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
Spectrum PredictCategory(osc::IOscCalc *osc, const SystComponentScale *syst) const
static std::unique_ptr< PredictionScaleComp > LoadFrom(TDirectory *dir)
virtual Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
void SetShift(const ISyst *syst, double shift)
Shifts are 0=nominal, -1,+1 = 1 sigma shifts.
Definition: SystShifts.cxx:47
process_name opflash particleana ie x
Uncertainty in the scale of a single component of the spectrum.
virtual void SaveTo(TDirectory *dir) const
Definition: IPrediction.cxx:85
tuple loader
Definition: demo.py:7
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:16
pdgs p
Definition: selectors.fcl:22
PredictionScaleComp(SpectrumLoaderBase &loader, const HistAxis &axis, SpillCut spillcut, Cut cut, const std::vector< const SystComponentScale * > &systs, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
process_name opflashCryoW ana
shift
Definition: fcl_checks.sh:26
Encapsulate code to systematically shift a caf::StandardRecord.
Definition: ISyst.h:14
void Scale(double c)
Multiply this spectrum by a constant c.
virtual std::string ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:30
virtual void SaveTo(TDirectory *dir) const override
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:30
std::vector< const SystComponentScale * > fSysts
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:62
double GetShift(const ISyst *syst) const
Definition: SystShifts.cxx:56
tuple dir
Definition: dropbox.py:28
Base class for the various types of spectrum loader.
int sign(double val)
Definition: UtilFunc.cxx:104
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:26
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
Standard interface to all prediction techniques.
Definition: IPrediction.h:58
Prediction that just uses one detector&#39;s MC, with no extrapolation.
const IPrediction * fTotal
std::vector< const IPrediction * > fPreds
BEGIN_PROLOG could also be cout
Prediction that wraps a simple Spectrum.