CountingExperiment.cxx
Go to the documentation of this file.
2 
4 
7 
9 
10 #include "TDirectory.h"
11 #include "TObjString.h"
12 #include "TH1.h"
13 
14 namespace ana
15 {
16  //----------------------------------------------------------------------
18  const Spectrum& d,
19  const Spectrum& cosmic)
20  : fMC(p), fData(d),
21  fCosmic(cosmic.ToTH1(d.Livetime(), kLivetime))
22  {
23  }
24 
25  //----------------------------------------------------------------------
27  {
28  delete fCosmic;
29  }
30 
31  //----------------------------------------------------------------------
33  const SystShifts& syst) const
34  {
35  double exp = fMC->PredictSyst(osc, syst).Integral(fData.POT());
36  if (fCosmic) exp += fCosmic->Integral(0,-1);
37  double obs = fData.Integral(fData.POT());
38 
39  return LogLikelihood(exp, obs);
40  }
41 
42  //----------------------------------------------------------------------
43  void CountingExperiment::SaveTo(TDirectory* dir) const
44  {
45  TDirectory* tmp = dir;
46 
47  dir->cd();
48  TObjString("CountingExperiment").Write("type");
49 
50  fMC->SaveTo(dir->mkdir("mc"));
51  fData.SaveTo(dir->mkdir("data"));
52 
53  if(fCosmic) fCosmic->Write("cosmic");
54 
55  tmp->cd();
56  }
57 
58  //----------------------------------------------------------------------
59  std::unique_ptr<CountingExperiment> CountingExperiment::LoadFrom(TDirectory* dir)
60  {
61  TObjString* ptag = (TObjString*)dir->Get("type");
62  assert(ptag);
63  assert(ptag->GetString() == "CountingExperiment");
64 
65  assert(dir->GetDirectory("mc"));
66  assert(dir->GetDirectory("data"));
67 
68 
69  const IPrediction* mc = ana::LoadFrom<IPrediction>(dir->GetDirectory("mc")).release();
70  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir->GetDirectory("data"));
71 
72  TH1* cosmic = 0;
73  if(dir->Get("cosmic")) cosmic = (TH1*)dir->Get("cosmic");
74 
75  auto ret = std::make_unique<CountingExperiment>(mc, *data);
76  if(cosmic) ret->fCosmic = cosmic;
77  return ret;
78  }
79 }
Oscillation analysis framework, runs over CAF files outside of ART.
virtual void SaveTo(TDirectory *dir) const
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
CountingExperiment(const IPrediction *p, const Spectrum &d, const Spectrum &cosmic)
const char * p
Definition: xmltok.h:285
virtual double ChiSq(osc::IOscCalculatorAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
Float_t tmp
Definition: plot.C:36
stan::math::var LogLikelihood(const std::vector< stan::math::var > &exp, const TH1 *obs)
Variant that handles the prediction in the form of Stan vars.
Definition: StanUtils.cxx:11
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
Definition: Spectrum.cxx:742
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:37
virtual Spectrum PredictSyst(osc::IOscCalculator *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:98
const XML_Char const XML_Char * data
Definition: expat.h:268
General interface to any calculator that lets you set the parameters.
Sum up livetimes from individual cosmic triggers.
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Float_t d
Definition: plot.C:236
virtual void SaveTo(TDirectory *dir) const override
double POT() const
Definition: Spectrum.h:263
Oscillation probability calculators.
Definition: Calcs.h:5
const IPrediction * fMC
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:38
TDirectory * dir
Definition: macro.C:5
string syst
Definition: plotSysts.py:176
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir)
Definition: Spectrum.cxx:1055
static std::unique_ptr< CountingExperiment > LoadFrom(TDirectory *dir)
void SaveTo(TDirectory *dir) const
Definition: Spectrum.cxx:1029