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

Compare a single data spectrum to the MC + cosmics expectation. More...

#include <SingleSampleExperiment.h>

Inheritance diagram for ana::SingleSampleExperiment:
ana::IExperiment

Public Member Functions

 SingleSampleExperiment (const IPrediction *pred, const Spectrum &data, const Spectrum &cosmicInTime, const Spectrum &cosmicOutOfTime)
 
 SingleSampleExperiment (const IPrediction *pred, const Spectrum &data)
 In MC studies you might not want to bother with cosmics. More...
 
 fCosmicOutOfTime (0,{},{}, 0, 0)
 
 fMask (0)
 
virtual ~SingleSampleExperiment ()
 
virtual double ChiSq (osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
 
virtual void SaveTo (TDirectory *dir) const override
 
 SingleSampleExperiment (const SingleSampleExperiment &)=delete
 
SingleSampleExperimentoperator= (const SingleSampleExperiment &)=delete
 
 SingleSampleExperiment (SingleSampleExperiment &&s)
 
void SetMaskHist (double xmin=0, double xmax=-1, double ymin=0, double ymax=-1)
 
- Public Member Functions inherited from ana::IExperiment
virtual ~IExperiment ()
 

Static Public Member Functions

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

Protected Attributes

const IPredictionfMC
 
Spectrum fData
 
Spectrum fCosmicInTime
 
Spectrum fCosmicOutOfTime
 
TH1 * fMask
 

Detailed Description

Compare a single data spectrum to the MC + cosmics expectation.

Definition at line 10 of file SingleSampleExperiment.h.

Constructor & Destructor Documentation

ana::SingleSampleExperiment::SingleSampleExperiment ( const IPrediction pred,
const Spectrum data,
const Spectrum cosmicInTime,
const Spectrum cosmicOutOfTime 
)
Parameters
predSource of oscillated MC beam predictions
dataData spectrum to compare to
cosmicInTimeIn-time cosmic ray background component
cosmicOutOfTimeOut-of-time cosmic ray background component

Definition at line 16 of file SingleSampleExperiment.cxx.

20  : fMC(pred), fData(data), fCosmicInTime(cosmicInTime), fCosmicOutOfTime(cosmicOutOfTime), fMask(0)
21  {
22  if(cosmicInTime.POT() > 0){
23  std::cout << "SingleSampleExperiment: in-time cosmics have nonzero POT. "
24  << "Did you confuse the two cosmics arguments?"
25  << std::endl;
26  abort();
27  }
28  }
BEGIN_PROLOG could also be cout
ana::SingleSampleExperiment::SingleSampleExperiment ( const IPrediction pred,
const Spectrum data 
)
inline

In MC studies you might not want to bother with cosmics.

Definition at line 23 of file SingleSampleExperiment.h.

ana::SingleSampleExperiment::~SingleSampleExperiment ( )
virtual

Definition at line 31 of file SingleSampleExperiment.cxx.

32  {
33  delete fMask;
34  }
ana::SingleSampleExperiment::SingleSampleExperiment ( const SingleSampleExperiment )
delete
ana::SingleSampleExperiment::SingleSampleExperiment ( SingleSampleExperiment &&  s)
inline

Definition at line 42 of file SingleSampleExperiment.h.

43  : fMC(s.fMC),
44  fData(std::move(s.fData)),
45  fCosmicInTime(std::move(s.fCosmicInTime)),
46  fCosmicOutOfTime(std::move(s.fCosmicOutOfTime))
47  {
48  s.fMC = nullptr;
49  };
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60

Member Function Documentation

double ana::SingleSampleExperiment::ChiSq ( osc::IOscCalcAdjustable osc,
const SystShifts syst = SystShifts::Nominal() 
) const
overridevirtual

Implements ana::IExperiment.

Definition at line 37 of file SingleSampleExperiment.cxx.

39  {
40  Spectrum p = fMC->PredictSyst(calc, syst);
41 
42  if(fCosmicOutOfTime.POT() > 0){ // if out-of-time cosmics supplied
43  p += fCosmicOutOfTime;
44  }
45 
46  TH1D* hpred = p.ToTH1(fData.POT());
47 
48  // "Livetime" here means number of readout windows.
49  if(fCosmicInTime.Livetime() > 0){ // if in-cosmics supplied
50  // This many are already included in the beam MC
51  const double beamLivetime = p.Livetime() * fData.POT()/p.POT();
52  // So we need to take this many from the cosmics-only to match the data
53  const double intimeLivetime = fData.Livetime() - beamLivetime;
54 
55  TH1D* hcosmic = fCosmicInTime.ToTH1(intimeLivetime, kLivetime);
56  hpred->Add(hcosmic);
57  HistCache::Delete(hcosmic);
58  }
59 
60  TH1D* hdata = fData.ToTH1(fData.POT());
61 
62  // If a valid mask has been set, zero out the offending bins
63  if (fMask){
64  assert(hpred->GetNbinsX() == fMask->GetNbinsX());
65  assert(hdata->GetNbinsX() == fMask->GetNbinsX());
66 
67  for(int i = 0; i < fMask->GetNbinsX()+2; ++i){
68  if (fMask->GetBinContent(i+1) == 1) continue;
69  hpred->SetBinContent(i+1, 0);
70  hdata->SetBinContent(i+1, 0);
71  }
72  }
73 
74  const double ll = LogLikelihood(hpred, hdata);
75 
76  HistCache::Delete(hpred);
77  HistCache::Delete(hdata);
78 
79  return ll;
80  }
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.
double LogLikelihood(double e, double o)
The log-likelihood formula for a single bin.
pdgs p
Definition: selectors.fcl:22
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:62
double POT() const
Definition: Spectrum.h:289
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:292
ana::SingleSampleExperiment::fCosmicOutOfTime ( ,
{}  ,
{}  ,
,
 
)
ana::SingleSampleExperiment::fMask ( )
inline

Definition at line 25 of file SingleSampleExperiment.h.

std::unique_ptr< SingleSampleExperiment > ana::SingleSampleExperiment::LoadFrom ( TDirectory *  dir)
static

Definition at line 99 of file SingleSampleExperiment.cxx.

100  {
101  TObjString* ptag = (TObjString*)dir->Get("type");
102  assert(ptag);
103  assert(ptag->GetString() == "SingleSampleExperiment");
104 
105  assert(dir->GetDirectory("mc"));
106  assert(dir->GetDirectory("data"));
107 
108 
109  const IPrediction* mc = ana::LoadFrom<IPrediction>(dir->GetDirectory("mc")).release();
110  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir->GetDirectory("data"));
111 
112  // Legacy format. This is the in-time cosmics
113  if(dir->GetDirectory("cosmic")){
114  const std::unique_ptr<Spectrum> cosmicInTime = Spectrum::LoadFrom(dir->GetDirectory("cosmic"));
115  return std::make_unique<SingleSampleExperiment>(mc, *data, *cosmicInTime, Spectrum(0, {}, {}, 0, 0));
116  }
117 
118  const std::unique_ptr<Spectrum> cosmicInTime = Spectrum::LoadFrom(dir->GetDirectory("cosmicInTime"));
119  const std::unique_ptr<Spectrum> cosmicOutOfTime = Spectrum::LoadFrom(dir->GetDirectory("cosmicOutOfTime"));
120 
121  return std::make_unique<SingleSampleExperiment>(mc, *data, *cosmicInTime, *cosmicOutOfTime);
122  }
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir)
tuple dir
Definition: dropbox.py:28
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:26
SingleSampleExperiment& ana::SingleSampleExperiment::operator= ( const SingleSampleExperiment )
delete
void ana::SingleSampleExperiment::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 83 of file SingleSampleExperiment.cxx.

84  {
85  TDirectory* tmp = dir;
86 
87  dir->cd();
88  TObjString("SingleSampleExperiment").Write("type");
89 
90  fMC->SaveTo(dir->mkdir("mc"));
91  fData.SaveTo(dir->mkdir("data"));
92  fCosmicInTime.SaveTo(dir->mkdir("cosmicInTime"));
93  fCosmicOutOfTime.SaveTo(dir->mkdir("cosmicOutOfTime"));
94 
95  tmp->cd();
96  }
virtual void SaveTo(TDirectory *dir) const
Definition: IPrediction.cxx:85
tuple dir
Definition: dropbox.py:28
void SaveTo(TDirectory *dir) const
void ana::SingleSampleExperiment::SetMaskHist ( double  xmin = 0,
double  xmax = -1,
double  ymin = 0,
double  ymax = -1 
)

Definition at line 125 of file SingleSampleExperiment.cxx.

126  {
127  fMask = GetMaskHist(fData, xmin, xmax, ymin, ymax);
128  }
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
TH1 * GetMaskHist(const Spectrum &s, double xmin, double xmax, double ymin, double ymax)

Member Data Documentation

Spectrum ana::SingleSampleExperiment::fCosmicInTime
protected

Definition at line 57 of file SingleSampleExperiment.h.

Spectrum ana::SingleSampleExperiment::fCosmicOutOfTime
protected

Definition at line 57 of file SingleSampleExperiment.h.

Spectrum ana::SingleSampleExperiment::fData
protected

Definition at line 56 of file SingleSampleExperiment.h.

TH1* ana::SingleSampleExperiment::fMask
protected

Definition at line 58 of file SingleSampleExperiment.h.

const IPrediction* ana::SingleSampleExperiment::fMC
protected

Definition at line 55 of file SingleSampleExperiment.h.


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