CountingExperiment.cxx
Go to the documentation of this file.
2 
4 
7 
8 #include "OscLib/IOscCalc.h"
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  // use namespace to disabiguate from method inherited from IExperiment
40  return ana::LogLikelihood(exp, obs);
41  }
42 
43  //----------------------------------------------------------------------
44  void CountingExperiment::SaveTo(TDirectory* dir, const std::string& name) const
45  {
46  TDirectory* tmp = dir;
47 
48  dir = dir->mkdir(name.c_str()); // switch to subdir
49  dir->cd();
50 
51  TObjString("CountingExperiment").Write("type");
52 
53  fMC->SaveTo(dir, "mc");
54  fData.SaveTo(dir, "data");
55 
56  if(fCosmic) fCosmic->Write("cosmic");
57 
58  dir->Write();
59  delete dir;
60 
61  tmp->cd();
62  }
63 
64  //----------------------------------------------------------------------
65  std::unique_ptr<CountingExperiment> CountingExperiment::LoadFrom(TDirectory* dir, const std::string& name)
66  {
67  dir = dir->GetDirectory(name.c_str()); // switch to subdir
68  assert(dir);
69 
70  TObjString* ptag = (TObjString*)dir->Get("type");
71  assert(ptag);
72  assert(ptag->GetString() == "CountingExperiment");
73  delete ptag;
74 
75  assert(dir->GetDirectory("mc"));
76  assert(dir->GetDirectory("data"));
77 
78 
80  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir, "data");
81 
82  TH1* cosmic = 0;
83  if(dir->Get("cosmic")) cosmic = (TH1*)dir->Get("cosmic");
84 
85  delete dir;
86 
87  auto ret = std::make_unique<CountingExperiment>(mc, *data);
88  if(cosmic) ret->fCosmic = cosmic;
89  return ret;
90  }
91 }
const XML_Char * name
Definition: expat.h:151
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
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
Float_t tmp
Definition: plot.C:36
virtual void SaveTo(TDirectory *dir, const std::string &name) const
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
Definition: Spectrum.cxx:333
double LogLikelihood(const Eigen::ArrayXd &ea, const Eigen::ArrayXd &oa, bool useOverflow)
The log-likelihood formula from the PDG.
Definition: EigenUtils.cxx:36
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
const XML_Char const XML_Char * data
Definition: expat.h:268
Sum up livetimes from individual cosmic triggers.
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:607
virtual double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
static std::unique_ptr< CountingExperiment > LoadFrom(TDirectory *dir, const std::string &name)
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Float_t d
Definition: plot.C:236
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:72
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:578
virtual void SaveTo(TDirectory *dir, const std::string &name) const override
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir, const std::string &label)
Definition: IPrediction.cxx:28
double POT() const
Definition: Spectrum.h:231
Oscillation probability calculators.
Definition: Calcs.h:5
const IPrediction * fMC
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
Standard interface to all prediction techniques.
Definition: IPrediction.h:57