All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::PredictionLinFit Class Reference

Parameterize a collection of universes as a function of the syst knobs. More...

#include <PredictionLinFit.h>

Inheritance diagram for ana::PredictionLinFit:
ana::IPrediction

Public Member Functions

 PredictionLinFit (const std::vector< const ISyst * > &systs, const IPrediction *pnom, const std::vector< std::pair< SystShifts, const IPrediction * >> &univs)
 Direct creation from an ensemble of universes. More...
 
 PredictionLinFit (const std::vector< const ISyst * > &systs, const IPredictionGenerator &predGen, Loaders &loaders, int nUniv)
 Constructor in the PredictionInterp style. More...
 
 ~PredictionLinFit ()
 
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
 
void DebugPlot (const ISyst *syst, osc::IOscCalc *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void DebugPlots (osc::IOscCalc *calc, const std::string &savePattern="", Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void DebugPlotColz (const ISyst *syst, osc::IOscCalc *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void DebugPlotsColz (osc::IOscCalc *calc, const std::string &savePattern="", Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void SaveTo (TDirectory *dir) const override
 
- Public Member Functions inherited from ana::IPrediction
virtual ~IPrediction ()
 
virtual Spectrum PredictUnoscillated () const
 
virtual OscillatableSpectrum ComponentCC (int from, int to) const
 

Static Public Member Functions

static std::unique_ptr
< PredictionLinFit
LoadFrom (TDirectory *dir)
 

Protected Member Functions

void InitFits () const
 
std::vector< double > InitFitsBin (const std::vector< std::vector< double >> &M, const std::vector< double > &ds, const std::vector< std::vector< double >> &coords) const
 Helper for InitFits() More...
 
std::vector< double > GetCoords (const SystShifts &shift) const
 
Ratio GetRatio (const SystShifts &shift) const
 

Protected Attributes

const std::vector< const ISyst * > fSysts
 
const IPredictionfNom
 
std::vector< std::pair
< SystShifts, const
IPrediction * > > 
fUnivs
 
std::vector< std::vector
< double > > 
fCoeffs
 

Detailed Description

Parameterize a collection of universes as a function of the syst knobs.

Definition at line 11 of file PredictionLinFit.h.

Constructor & Destructor Documentation

ana::PredictionLinFit::PredictionLinFit ( const std::vector< const ISyst * > &  systs,
const IPrediction pnom,
const std::vector< std::pair< SystShifts, const IPrediction * >> &  univs 
)

Direct creation from an ensemble of universes.

Definition at line 28 of file PredictionLinFit.cxx.

31  : fSysts(systs), fNom(pnom), fUnivs(univs)
32  {
33  }
const IPrediction * fNom
const std::vector< const ISyst * > fSysts
std::vector< std::pair< SystShifts, const IPrediction * > > fUnivs
ana::PredictionLinFit::PredictionLinFit ( const std::vector< const ISyst * > &  systs,
const IPredictionGenerator predGen,
Loaders loaders,
int  nUniv 
)

Constructor in the PredictionInterp style.

Definition at line 36 of file PredictionLinFit.cxx.

40  : fSysts(systs)
41  {
42  fNom = predGen.Generate(loaders, SystShifts::Nominal()).release();
43 
44  /*
45  // TODO rework PredictionLinFit to work with the new-style systematic
46  // universe weights.
47 
48  // We really want to apply a weight - but PredictionGenerator is set up to
49  // take a SystShifts, so...
50  class DummyUnivWeightSyst: public ISyst
51  {
52  public:
53  DummyUnivWeightSyst(const std::vector<const ISyst*> systs, int univIdx)
54  : ISyst(UniqueName(), UniqueName()),
55  fVar(GetUniverseWeight(systs, univIdx))
56  {
57  }
58 
59  void Shift(double sigma, caf::SRSliceProxy* sr, double& weight) const override
60  {
61  weight *= fVar(sr);
62  }
63  protected:
64  Var fVar;
65  };
66 
67  for(int univIdx = 0; univIdx < nUniv; ++univIdx){
68  // This one is an accurate label for what the shift is
69  const SystShifts s1 = UniverseOracle::Instance().ShiftsForSysts(systs, nUniv)[univIdx];
70  // But this is the sane way to compute its effect
71  const SystShifts s2(new DummyUnivWeightSyst(systs, univIdx), 1);
72  fUnivs.emplace_back(s1, predGen.Generate(loaders, s2).release());
73  }
74  */
75  }
const IPrediction * fNom
const std::vector< const ISyst * > fSysts
static SystShifts Nominal()
Definition: SystShifts.h:23
ana::PredictionLinFit::~PredictionLinFit ( )

Definition at line 78 of file PredictionLinFit.cxx.

79  {
80  }

Member Function Documentation

void ana::PredictionLinFit::DebugPlot ( const ISyst syst,
osc::IOscCalc calc,
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const

Definition at line 358 of file PredictionLinFit.cxx.

363  {
364  DontAddDirectory guard;
365 
366  if(fCoeffs.empty()) InitFits();
367 
368  std::unique_ptr<TH1> nom(fNom->PredictComponent(calc, flav, curr, sign).ToTH1(18e20));
369  const int nbins = nom->GetNbinsX();
370 
371  std::vector<TGraph*> curves(nbins);
372  for(int bin = 0; bin < nbins; ++bin) curves[bin] = new TGraph;
373 
374  for(int i = 0; i <= 80; ++i){
375  const double x = .1*i-4;
376  const SystShifts ss(syst, x);
377  std::unique_ptr<TH1> h(PredictComponentSyst(calc, ss, flav, curr, sign).ToTH1(18e20));
378 
379  for(int bin = 0; bin < nbins; ++bin){
380  const double ratio = h->GetBinContent(bin+1)/nom->GetBinContent(bin+1);
381 
382  if(!std::isnan(ratio)) curves[bin]->SetPoint(curves[bin]->GetN(), x, ratio);
383  else curves[bin]->SetPoint(curves[bin]->GetN(), x, 1);
384  } // end for bin
385  } // end for i (x)
386 
387  int nx = int(sqrt(nbins));
388  int ny = int(sqrt(nbins));
389  if(nx*ny < nbins) ++nx;
390  if(nx*ny < nbins) ++ny;
391 
392  TCanvas* c = new TCanvas;
393  c->Divide(nx, ny);
394 
395  for(int bin = 0; bin < nbins; ++bin){
396  c->cd(bin+1);
397  (new TH2F(UniqueName().c_str(),
398  TString::Format("%s %g < %s < %g;Shift;Ratio",
399  syst->ShortName().c_str(),
400  nom->GetXaxis()->GetBinLowEdge(bin+1),
401  nom->GetXaxis()->GetTitle(),
402  nom->GetXaxis()->GetBinUpEdge(bin+1)),
403  100, -4, +4, 100, .5, 1.5))->Draw();
404  curves[bin]->Draw("l same");
405  } // end for bin
406 
407  c->cd(0);
408  }
Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
process_name opflash particleana ie x
const IPrediction * fNom
std::vector< std::vector< double > > fCoeffs
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
while getopts h
int sign(double val)
Definition: UtilFunc.cxx:104
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const =0
std::string UniqueName()
Return a different string each time, for creating histograms.
void ana::PredictionLinFit::DebugPlotColz ( const ISyst syst,
osc::IOscCalc calc,
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const

Definition at line 444 of file PredictionLinFit.cxx.

449  {
450  InitFits();
451 
452  std::unique_ptr<TH1> nom(fNom->PredictComponent(calc, flav, curr, sign).ToTH1(18e20));
453  const int nbins = nom->GetNbinsX();
454 
455  TH2* h2 = new TH2F("", (syst->LatexName()+";;#sigma").c_str(),
456  nbins, nom->GetXaxis()->GetXmin(), nom->GetXaxis()->GetXmax(),
457  80, -4, +4);
458  h2->GetXaxis()->SetTitle(nom->GetXaxis()->GetTitle());
459 
460  for(int i = 1; i <= 80; ++i){
461  const double y = h2->GetYaxis()->GetBinCenter(i);
462  const SystShifts ss(syst, y);
463  std::unique_ptr<TH1> h(PredictComponentSyst(calc, ss, flav, curr, sign).ToTH1(18e20));
464 
465  for(int bin = 0; bin < nbins; ++bin){
466  const double ratio = h->GetBinContent(bin+1)/nom->GetBinContent(bin+1);
467 
468  if(!isnan(ratio) && !isinf(ratio))
469  h2->Fill(h2->GetXaxis()->GetBinCenter(bin), y, ratio);
470  } // end for bin
471  } // end for i (x)
472 
473  h2->Draw("colz");
474  h2->SetMinimum(0.5);
475  h2->SetMaximum(1.5);
476  }
Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
const IPrediction * fNom
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
while getopts h
process_name opflash particleana ie ie y
int sign(double val)
Definition: UtilFunc.cxx:104
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const =0
void ana::PredictionLinFit::DebugPlots ( osc::IOscCalc calc,
const std::string &  savePattern = "",
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const

Definition at line 411 of file PredictionLinFit.cxx.

416  {
417  const bool save = !savePattern.empty();
418  const bool multiFile = savePattern.find("%s") != std::string::npos;
419 
420  if(save && !multiFile){
421  new TCanvas;
422  gPad->Print((savePattern+"[").c_str());
423  }
424 
425  for(const ISyst* s: fSysts){
426  DebugPlot(s, calc, flav, curr, sign);
427 
428  if(save){
429  if(multiFile){
430  gPad->Print(TString::Format(savePattern.c_str(), s->ShortName().c_str()).Data());
431  }
432  else{
433  gPad->Print(savePattern.c_str());
434  }
435  }
436  } // end for s
437 
438  if(save && !multiFile){
439  gPad->Print((savePattern+"]").c_str());
440  }
441  }
const std::vector< const ISyst * > fSysts
void DebugPlot(const ISyst *syst, osc::IOscCalc *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
int sign(double val)
Definition: UtilFunc.cxx:104
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
void ana::PredictionLinFit::DebugPlotsColz ( osc::IOscCalc calc,
const std::string &  savePattern = "",
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const

Definition at line 479 of file PredictionLinFit.cxx.

484  {
485  const bool save = !savePattern.empty();
486  const bool multiFile = savePattern.find("%s") != std::string::npos;
487 
488  if(save && !multiFile){
489  new TCanvas;
490  gPad->Print((savePattern+"[").c_str());
491  }
492 
493  for(const ISyst* s: fSysts){
494  new TCanvas;
495  DebugPlotColz(s, calc, flav, curr, sign);
496 
497  if(save){
498  if(multiFile){
499  gPad->Print(TString::Format(savePattern.c_str(), s->ShortName().c_str()).Data());
500  }
501  else{
502  gPad->Print(savePattern.c_str());
503  }
504  }
505  } // end for it
506 
507  if(save && !multiFile){
508  gPad->Print((savePattern+"]").c_str());
509  }
510  }
const std::vector< const ISyst * > fSysts
void DebugPlotColz(const ISyst *syst, osc::IOscCalc *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
int sign(double val)
Definition: UtilFunc.cxx:104
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::vector< double > ana::PredictionLinFit::GetCoords ( const SystShifts shift) const
protected

Definition at line 285 of file PredictionLinFit.cxx.

286  {
287  const unsigned int N = fSysts.size();
288 
289  std::vector<double> coords;
290  coords.reserve(N + (N*(N+1))/2);
291 
292  // Add all the linear terms
293  for(const ISyst* s: fSysts) coords.push_back(shift.GetShift(s));
294 
295  // Now add all the quadratic and cross terms
296  for(unsigned int i = 0; i < N; ++i){
297  for(unsigned int j = i; j < N; ++j){
298  coords.push_back(coords[i] * coords[j]);
299  }
300  }
301 
302  return coords;
303  }
const std::vector< const ISyst * > fSysts
shift
Definition: fcl_checks.sh:26
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
process_name largeant stream1 can override from command line with o or output physics producers generator N
Ratio ana::PredictionLinFit::GetRatio ( const SystShifts shift) const
protected

Definition at line 306 of file PredictionLinFit.cxx.

307  {
308  if(fCoeffs.empty()) InitFits();
309 
310  // To get correct binning
311  TH1D* hret = fNom->PredictUnoscillated().ToTH1(1);
312  hret->Reset();
313 
314  const std::vector<double> coords = GetCoords(shift);
315  const unsigned int N = coords.size();
316 
317  for(unsigned int binIdx = 0; binIdx < fCoeffs.size(); ++binIdx){
318  double factor = 0;
319  for(unsigned int i = 0; i < N; ++i) factor += fCoeffs[binIdx][i] * coords[i];
320 
321  hret->SetBinContent(binIdx, exp(factor));
322  }
323 
324  const Ratio ret(hret);
325  HistCache::Delete(hret);
326  return ret;
327  }
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
const IPrediction * fNom
std::vector< double > GetCoords(const SystShifts &shift) const
std::vector< std::vector< double > > fCoeffs
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:54
shift
Definition: fcl_checks.sh:26
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
process_name largeant stream1 can override from command line with o or output physics producers generator N
void ana::PredictionLinFit::InitFits ( ) const
protected

Definition at line 83 of file PredictionLinFit.cxx.

84  {
85  if(!fCoeffs.empty()) return;
86 
87  std::vector<std::vector<double>> coords; // [varIdx][univIdx]
88 
89  for(const auto& it: fUnivs){
90  const std::vector<double> c = GetCoords(it.first);
91  if(coords.empty()) coords.resize(c.size());
92  for(unsigned int varIdx = 0; varIdx < c.size(); ++varIdx){
93  coords[varIdx].push_back(c[varIdx]);
94  }
95  }
96 
97  const unsigned int N = coords.size();
98 
99  std::vector<std::vector<double>> M(N, std::vector<double>(N));
100 
101  for(unsigned int i = 0; i < N; ++i){
102  const std::vector<double>& ci = coords[i];
103  for(unsigned int j = 0; j < N; ++j){
104  const std::vector<double>& cj = coords[j];
105  for(unsigned int univIdx = 0; univIdx < fUnivs.size(); ++univIdx){
106  M[i][j] += ci[univIdx] * cj[univIdx];
107  }
108  }
109  }
110 
111  osc::NoOscillations calc; // TODO class member?
112 
113  const Spectrum snom = fNom->Predict(&calc);
114 
115  TH1D* hnom = snom.ToTH1(1); // only need this to count the bins :(
116  const int Nbins = hnom->GetNbinsX();
117  HistCache::Delete(hnom);
118 
119  // The data (ratios) that we're trying to fit
120  std::vector<std::vector<double>> ds(Nbins+2, std::vector<double>(fUnivs.size()));
121 
122  for(unsigned int univIdx = 0; univIdx < fUnivs.size(); ++univIdx){
123  const Ratio r(fUnivs[univIdx].second->Predict(&calc), snom);
124  TH1D* hr = r.ToTH1();
125 
126  for(int binIdx = 0; binIdx < Nbins+2; ++binIdx){
127  ds[binIdx][univIdx] = log(hr->GetBinContent(binIdx));
128  }
129 
130  HistCache::Delete(hr);
131  }
132 
133  Progress prog("Initializing PredictionLinFit");
134  for(int binIdx = 0; binIdx < Nbins+2; ++binIdx){
135  fCoeffs.push_back(InitFitsBin(M, ds[binIdx], coords));
136  prog.SetProgress(binIdx/double(Nbins+1));
137  }
138  }
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
const IPrediction * fNom
std::vector< double > GetCoords(const SystShifts &shift) const
std::vector< std::vector< double > > fCoeffs
virtual Spectrum Predict(osc::IOscCalc *calc) const =0
std::vector< std::pair< SystShifts, const IPrediction * > > fUnivs
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
std::vector< double > InitFitsBin(const std::vector< std::vector< double >> &M, const std::vector< double > &ds, const std::vector< std::vector< double >> &coords) const
Helper for InitFits()
process_name largeant stream1 can override from command line with o or output physics producers generator N
prog
Definition: just_cmake.sh:3
esac echo uname r
std::vector< double > ana::PredictionLinFit::InitFitsBin ( const std::vector< std::vector< double >> &  M,
const std::vector< double > &  ds,
const std::vector< std::vector< double >> &  coords 
) const
protected

Helper for InitFits()

Definition at line 142 of file PredictionLinFit.cxx.

145  {
146  const unsigned int N = M.size();
147  const unsigned int Nuniv = fUnivs.size();
148 
149  std::vector<double> v(N);
150 
151  for(unsigned int i = 0; i < N; ++i){
152  const std::vector<double>& c = coords[i];
153  for(unsigned int univIdx = 0; univIdx < Nuniv; ++univIdx){
154  v[i] += c[univIdx]* ds[univIdx];
155  }
156  }
157 
158  // std::cout << "-----" << std::endl;
159 
160  // Don't try to re-add an already used variable
161  std::vector<bool> already(N);
162 
163  IncrementalCholeskyDecomp icd;
164 
165  std::vector<double> vsub;
166 
167  std::vector<int> vars;
168 
169  std::vector<double> residual = ds;
170 
171  std::vector<std::vector<double>> coords_sub(Nuniv);
172 
173  for(unsigned int matSize = 1; matSize <= 500/*std::min(N, Nuniv)*/; ++matSize){
174  // Try adding each potential variable while holding the coefficients of
175  // the rest fixed. This is a fast way to estimate which variable will be
176  // the best when added to the full fit.
177  int bestVarIdx = -1;
178  double bestSqErr = std::numeric_limits<double>::infinity();
179 
180  for(unsigned int varIdx = 0; varIdx < N; ++varIdx){
181  if(already[varIdx]) continue;
182 
183  const std::vector<double>& c = coords[varIdx];
184 
185  double num = 0, denom = 0;
186 
187  for(unsigned int univIdx = 0; univIdx < Nuniv; ++univIdx){
188  num += residual[univIdx]*c[univIdx];
189  denom += util::sqr(c[univIdx]);
190  }
191 
192  // Best coefficient for this variable
193  const double x = num/denom;
194 
195  // Evaluate this solution
196  double sqErr = 0;
197  for(unsigned int univIdx = 0; univIdx < Nuniv; ++univIdx){
198  sqErr += util::sqr(residual[univIdx] - c[univIdx] * x);
199  }
200 
201  if(sqErr < bestSqErr){
202  bestSqErr = sqErr;
203  bestVarIdx = varIdx;
204  }
205  } // end for varIdx
206 
207  // std::cout << matSize << ": chose to add var " << bestVarIdx << " predicting MSE = " << sqrt(bestSqErr/Nuniv) << std::endl;
208 
209  // Now that it's certain, we can shorten the variable name
210  const int varIdx = bestVarIdx;
211  const std::vector<double>& c = coords[varIdx];
212 
213  // Make sure not to use it again
214  already[varIdx] = true;
215 
216  // Expand the problem with the new variable
217  vsub.push_back(v[varIdx]);
218  vars.push_back(varIdx);
219  icd.AddRow(M[varIdx], vars);
220 
221  // And solve it exactly
222  const std::vector<double> a = icd.Solve(vsub);
223 
224  double sqErr = 0;
225  for(unsigned int univIdx = 0; univIdx < Nuniv; ++univIdx){
226  std::vector<double>& cs = coords_sub[univIdx];
227  cs.push_back(c[univIdx]);
228 
229  // Update the residuals for the new solution
230  residual[univIdx] = ds[univIdx];
231  for(unsigned int i = 0; i < matSize; ++i){
232  residual[univIdx] -= a[i] * cs[i];
233  }
234 
235  // As a side effect, it's easy to compute the new squared error
236  sqErr += util::sqr(residual[univIdx]);
237  }
238 
239  // Can remove sqErr if we don't want this printout
240  // std::cout << " optimized by matrix to " << sqrt(sqErr/Nuniv) << std::endl;
241  } // end for matSize
242 
243  // Solve one last time, reuse vsub to store output
244  vsub = icd.Solve(vsub);
245 
246  // Package up results
247  std::vector<double> ret(N);
248  for(unsigned int i = 0; i < vars.size(); ++i) ret[vars[i]] = vsub[i];
249  return ret;
250  }
process_name opflash particleana ie x
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
process_name gaushit a
std::vector< std::pair< SystShifts, const IPrediction * > > fUnivs
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::unique_ptr< PredictionLinFit > ana::PredictionLinFit::LoadFrom ( TDirectory *  dir)
static

Definition at line 513 of file PredictionLinFit.cxx.

514  {
515  TObjString* tag = (TObjString*)dir->Get("type");
516  assert(tag);
517  assert(tag->GetString() == "PredictionLinFit");
518 
519  std::unique_ptr<IPrediction> nom = ana::LoadFrom<IPrediction>(dir->GetDirectory("nom"));
520 
521  std::vector<const ISyst*> systs;
522  TH1* hSystNames = (TH1*)dir->Get("syst_names");
523  if(hSystNames){
524  for(int systIdx = 0; systIdx < hSystNames->GetNbinsX(); ++systIdx){
525  systs.push_back(SystRegistry::ShortNameToSyst(hSystNames->GetXaxis()->GetBinLabel(systIdx+1)));
526  }
527  }
528 
529  std::vector<std::pair<SystShifts, const IPrediction*>> univs;
530 
531  for(int univIdx = 0; ; ++univIdx){
532  TDirectory* ud = dir->GetDirectory(TString::Format("univ_%d", univIdx).Data());
533  if(!ud) break; // out of universes
534 
535  univs.emplace_back(*ana::LoadFrom<SystShifts>(ud->GetDirectory("shift")),
536  ana::LoadFrom<IPrediction>(ud->GetDirectory("pred")).release());
537  }
538 
539  // TODO think about memory management
540  return std::make_unique<PredictionLinFit>(systs, nom.release(), univs);
541  }
tuple dir
Definition: dropbox.py:28
static const ISyst * ShortNameToSyst(const std::string &s, bool allowFail=false)
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:26
Spectrum ana::PredictionLinFit::Predict ( osc::IOscCalc calc) const
overridevirtual

Implements ana::IPrediction.

Definition at line 253 of file PredictionLinFit.cxx.

254  {
255  return fNom->Predict(calc);
256  }
const IPrediction * fNom
virtual Spectrum Predict(osc::IOscCalc *calc) const =0
Spectrum ana::PredictionLinFit::PredictComponent ( osc::IOscCalc calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtual

Implements ana::IPrediction.

Definition at line 266 of file PredictionLinFit.cxx.

270  {
271  return fNom->PredictComponent(calc, flav, curr, sign);
272  }
const IPrediction * fNom
int sign(double val)
Definition: UtilFunc.cxx:104
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const =0
Spectrum ana::PredictionLinFit::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 275 of file PredictionLinFit.cxx.

280  {
281  return GetRatio(syst) * PredictComponent(calc, flav, curr, sign);
282  }
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
int sign(double val)
Definition: UtilFunc.cxx:104
Ratio GetRatio(const SystShifts &shift) const
Spectrum ana::PredictionLinFit::PredictSyst ( osc::IOscCalc calc,
const SystShifts syst 
) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 259 of file PredictionLinFit.cxx.

261  {
262  return GetRatio(syst) * Predict(calc);
263  }
Spectrum Predict(osc::IOscCalc *calc) const override
Ratio GetRatio(const SystShifts &shift) const
void ana::PredictionLinFit::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 330 of file PredictionLinFit.cxx.

331  {
332  TDirectory* tmp = gDirectory;
333 
334  dir->cd();
335  TObjString("PredictionLinFit").Write("type");
336 
337  fNom->SaveTo(dir->mkdir("nom"));
338 
339  for(unsigned int univIdx = 0; univIdx < fUnivs.size(); ++univIdx){
340  TDirectory* ud = dir->mkdir(TString::Format("univ_%d", univIdx).Data());
341  fUnivs[univIdx].first.SaveTo(ud->mkdir("shift"));
342  fUnivs[univIdx].second->SaveTo(ud->mkdir("pred"));
343  } // end for it
344 
345  if(!fSysts.empty()){
346  TH1F hSystNames("syst_names", ";Syst names", fSysts.size(), 0, fSysts.size());
347  int binIdx = 1;
348  for(auto it: fSysts){
349  hSystNames.GetXaxis()->SetBinLabel(binIdx++, it->ShortName().c_str());
350  }
351  hSystNames.Write("syst_names");
352  }
353 
354  tmp->cd();
355  }
const IPrediction * fNom
virtual void SaveTo(TDirectory *dir) const
Definition: IPrediction.cxx:85
const std::vector< const ISyst * > fSysts
std::vector< std::pair< SystShifts, const IPrediction * > > fUnivs
tuple dir
Definition: dropbox.py:28

Member Data Documentation

std::vector<std::vector<double> > ana::PredictionLinFit::fCoeffs
mutableprotected

Definition at line 86 of file PredictionLinFit.h.

const IPrediction* ana::PredictionLinFit::fNom
protected

Definition at line 83 of file PredictionLinFit.h.

const std::vector<const ISyst*> ana::PredictionLinFit::fSysts
protected

Definition at line 82 of file PredictionLinFit.h.

std::vector<std::pair<SystShifts, const IPrediction*> > ana::PredictionLinFit::fUnivs
protected

Definition at line 84 of file PredictionLinFit.h.


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