All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  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 }
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir)
virtual void SaveTo(TDirectory *dir) const
Definition: IPrediction.cxx:85
double LogLikelihood(double e, double o)
The log-likelihood formula for a single bin.
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:16
CountingExperiment(const IPrediction *p, const Spectrum &d, const Spectrum &cosmic)
pdgs p
Definition: selectors.fcl:22
virtual double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
process_name opflashCryoW ana
virtual void SaveTo(TDirectory *dir) const override
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:30
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:62
double POT() const
Definition: Spectrum.h:289
tuple dir
Definition: dropbox.py:28
const IPrediction * fMC
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:26
BEGIN_PROLOG cosmic
Standard interface to all prediction techniques.
Definition: IPrediction.h:58
static std::unique_ptr< CountingExperiment > LoadFrom(TDirectory *dir)
void SaveTo(TDirectory *dir) const