CountingExperiment.cxx
Go to the documentation of this file.
2 
4 
8 
9 #include "OscLib/IOscCalc.h"
10 
11 #include "TDirectory.h"
12 #include "TObjString.h"
13 #include "TH1.h"
14 
15 namespace ana
16 {
17  REGISTER_LOADFROM("CountingExperiment", IExperiment, CountingExperiment);
18 
19  //----------------------------------------------------------------------
21  const Spectrum& d,
22  const Spectrum& cosmic)
23  : fMC(p), fData(d),
24  fCosmic(cosmic.ToTH1(d.Livetime(), kLivetime))
25  {
26  }
27 
28  //----------------------------------------------------------------------
30  {
31  delete fCosmic;
32  }
33 
34  //----------------------------------------------------------------------
36  const SystShifts& syst) const
37  {
38  double exp = fMC->PredictSyst(osc, syst).Integral(fData.POT());
39  if (fCosmic) exp += fCosmic->Integral(0,-1);
40  double obs = fData.Integral(fData.POT());
41 
42  // use namespace to disabiguate from method inherited from IExperiment
43  return ana::LogLikelihood(exp, obs);
44  }
45 
46  //----------------------------------------------------------------------
47  void CountingExperiment::SaveTo(TDirectory* dir, const std::string& name) const
48  {
49  TDirectory* tmp = dir;
50 
51  dir = dir->mkdir(name.c_str()); // switch to subdir
52  dir->cd();
53 
54  TObjString("CountingExperiment").Write("type");
55 
56  fMC->SaveTo(dir, "mc");
57  fData.SaveTo(dir, "data");
58 
59  if(fCosmic) fCosmic->Write("cosmic");
60 
61  dir->Write();
62  delete dir;
63 
64  tmp->cd();
65  }
66 
67  //----------------------------------------------------------------------
68  std::unique_ptr<CountingExperiment> CountingExperiment::LoadFrom(TDirectory* dir, const std::string& name)
69  {
70  dir = dir->GetDirectory(name.c_str()); // switch to subdir
71  assert(dir);
72 
73  TObjString* ptag = (TObjString*)dir->Get("type");
74  assert(ptag);
75  assert(ptag->GetString() == "CountingExperiment");
76  delete ptag;
77 
78  assert(dir->GetDirectory("mc"));
79  assert(dir->GetDirectory("data"));
80 
81 
83  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir, "data");
84 
85  TH1* cosmic = 0;
86  if(dir->Get("cosmic")) cosmic = (TH1*)dir->Get("cosmic");
87 
88  delete dir;
89 
90  auto ret = std::make_unique<CountingExperiment>(mc, *data);
91  if(cosmic) ret->fCosmic = cosmic;
92  return ret;
93  }
94 }
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:272
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:40
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:546
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:49
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
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:18
double POT() const
Definition: Spectrum.h:219
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
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
assert(nhit_max >=nhit_nbins)
Standard interface to all prediction techniques.
Definition: IPrediction.h:57