Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ana::BigChi2SingleSampleExperiment Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-01-22/CAFAna/xsec_tuning/Ana2020/tuning/MECTuningUtils.h"

Inheritance diagram for ana::BigChi2SingleSampleExperiment:
ana::SingleSampleExperiment ana::IChiSqExperiment

Public Member Functions

 BigChi2SingleSampleExperiment (const IPrediction *pred, const Spectrum &data, double scaleFactor=1)
 
double ChiSq (osc::IOscCalculatorAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
 
virtual void Derivative (osc::IOscCalculator *calc, const SystShifts &shift, std::unordered_map< const ISyst *, double > &dch) const override
 
virtual void SaveTo (TDirectory *dir) const override
 

Static Public Member Functions

static std::unique_ptr< SingleSampleExperimentLoadFrom (TDirectory *dir)
 

Protected Member Functions

TH1D * PredHistIncCosmics (osc::IOscCalculator *calc, const SystShifts &syst) const
 

Protected Attributes

const IPredictionfMC
 
Spectrum fData
 
TH1D * fCosmic
 
double fCosmicScaleError
 

Private Attributes

double fScaleFactor
 

Detailed Description

Definition at line 127 of file MECTuningUtils.h.

Constructor & Destructor Documentation

ana::BigChi2SingleSampleExperiment::BigChi2SingleSampleExperiment ( const IPrediction pred,
const Spectrum data,
double  scaleFactor = 1 
)
inline

Definition at line 130 of file MECTuningUtils.h.

133  : SingleSampleExperiment(pred, data), fScaleFactor(scaleFactor)
134  {}
SingleSampleExperiment(const IPrediction *pred, const Spectrum &data, const Spectrum &cosmic, double cosmicScaleError=0)
const XML_Char const XML_Char * data
Definition: expat.h:268

Member Function Documentation

double ana::BigChi2SingleSampleExperiment::ChiSq ( osc::IOscCalculatorAdjustable osc,
const SystShifts syst = SystShifts::Nominal() 
) const
inlineoverridevirtual

Reimplemented from ana::SingleSampleExperiment.

Definition at line 136 of file MECTuningUtils.h.

References ana::SingleSampleExperiment::ChiSq(), demo5::expt, and plotSysts::syst.

138  {
140  return fScaleFactor * expt.ChiSq(osc, syst);
141  }
SingleSampleExperiment(const IPrediction *pred, const Spectrum &data, const Spectrum &cosmic, double cosmicScaleError=0)
expt
Definition: demo5.py:34
string syst
Definition: plotSysts.py:176
void ana::SingleSampleExperiment::Derivative ( osc::IOscCalculator calc,
const SystShifts shift,
std::unordered_map< const ISyst *, double > &  dch 
) const
overridevirtualinherited

Reimplemented from ana::IChiSqExperiment.

Definition at line 108 of file SingleSampleExperiment.cxx.

References ana::HistCache::Delete(), ana::IPrediction::Derivative(), ana::SingleSampleExperiment::fCosmic, ana::SingleSampleExperiment::fCosmicScaleError, ana::SingleSampleExperiment::fData, ana::SingleSampleExperiment::fMC, chisquared::hpred, MECModelEnuComparisons::i, it, ana::LogLikelihoodDerivative(), pot, ana::Spectrum::POT(), ana::SingleSampleExperiment::PredHistIncCosmics(), and ana::Spectrum::ToTH1().

Referenced by ana::SingleSampleExperiment::ChiSq().

111  {
112  const double pot = fData.POT();
113 
114  std::unordered_map<const ISyst*, std::vector<double>> dp;
115  for(auto it: dchi) dp[it.first] = {};
116  fMC->Derivative(calc, shift, pot, dp);
117 
118  if(dp.empty()){ // prediction doesn't implement derivatives
119  dchi.clear(); // pass on that info to our caller
120  return;
121  }
122 
123  TH1D* hpred = PredHistIncCosmics(calc, shift);
124  TH1D* hdata = fData.ToTH1(pot);
125 
126  for(auto& it: dchi){
127  if(it.first != &kCosmicBkgScaleSyst){
128  it.second += LogLikelihoodDerivative(hpred, hdata, dp[it.first]);
129  }
130  else{
131  const unsigned int N = fCosmic->GetNbinsX()+2;
132  const double* ca = fCosmic->GetArray();
133  std::vector<double> cosErr(N);
134  for(unsigned int i = 0; i < N; ++i) cosErr[i] = ca[i]*fCosmicScaleError;
135  it.second += LogLikelihoodDerivative(hpred, hdata, cosErr);
136  }
137  }
138 
139  HistCache::Delete(hpred);
140  HistCache::Delete(hdata);
141  }
set< int >::iterator it
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.
Definition: Spectrum.cxx:553
virtual void Derivative(osc::IOscCalculator *calc, const SystShifts &shift, double pot, std::unordered_map< const ISyst *, std::vector< double >> &dchi) const
Definition: IPrediction.h:92
const CosmicBkgScaleSyst kCosmicBkgScaleSyst
double LogLikelihoodDerivative(double e, double o, double dedx)
Definition: Utilities.cxx:154
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
#define pot
double POT() const
Definition: Spectrum.h:263
TH1D * PredHistIncCosmics(osc::IOscCalculator *calc, const SystShifts &syst) const
std::unique_ptr< SingleSampleExperiment > ana::SingleSampleExperiment::LoadFrom ( TDirectory *  dir)
staticinherited

Definition at line 160 of file SingleSampleExperiment.cxx.

References ana::Spectrum::LoadFrom(), ana::LoadFrom< IPrediction >(), mc, runNovaSAM::release, and runNovaSAM::ret.

Referenced by getHists_FNEX(), and ana::LoadFrom< IChiSqExperiment >().

161  {
162  TObjString* ptag = (TObjString*)dir->Get("type");
163  assert(ptag);
164  assert(ptag->GetString() == "SingleSampleExperiment");
165 
166  assert(dir->GetDirectory("mc"));
167  assert(dir->GetDirectory("data"));
168 
169 
170  const IPrediction* mc = ana::LoadFrom<IPrediction>(dir->GetDirectory("mc")).release();
171  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir->GetDirectory("data"));
172 
173  TH1D* cosmic = 0;
174  if(dir->Get("cosmic")) cosmic = (TH1D*)dir->Get("cosmic");
175 
176  auto ret = std::make_unique<SingleSampleExperiment>(mc, *data);
177  if(cosmic) ret->fCosmic = cosmic;
178  return ret;
179  }
const XML_Char const XML_Char * data
Definition: expat.h:268
Sum up livetimes from individual cosmic triggers.
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:38
TDirectory * dir
Definition: macro.C:5
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir)
Definition: Spectrum.cxx:1055
TH1D * ana::SingleSampleExperiment::PredHistIncCosmics ( osc::IOscCalculator calc,
const SystShifts syst 
) const
protectedinherited

Definition at line 68 of file SingleSampleExperiment.cxx.

References ana::SingleSampleExperiment::fCosmic, ana::SingleSampleExperiment::fCosmicScaleError, ana::SingleSampleExperiment::fData, ana::SingleSampleExperiment::fMC, ana::SystShifts::GetShift(), chisquared::hpred, ana::Spectrum::POT(), plot_validation_datamc::pred, ana::IPrediction::PredictSyst(), scale, ana::SystShifts::SetShift(), plotSysts::syst, and ana::Spectrum::ToTH1().

Referenced by ana::SingleSampleExperiment::ChiSq(), ana::SingleSampleExperiment::Derivative(), and ana::SingleSampleExperiment::~SingleSampleExperiment().

70  {
71  SystShifts systNoCosmic = syst;
72  systNoCosmic.SetShift(&kCosmicBkgScaleSyst, 0);
73 
74  const Spectrum pred = fMC->PredictSyst(calc, systNoCosmic);
75 
76  TH1D* hpred = pred.ToTH1(fData.POT());
77 
78  if(fCosmic){
79  if(fCosmicScaleError != 0){
80  const double scale = 1 + syst.GetShift(&kCosmicBkgScaleSyst) * fCosmicScaleError;
81  hpred->Add(fCosmic, scale);
82  }
83  else{
84  hpred->Add(fCosmic);
85  }
86  }
87 
88  return hpred;
89  }
const CosmicBkgScaleSyst kCosmicBkgScaleSyst
virtual Spectrum PredictSyst(osc::IOscCalculator *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:98
Double_t scale
Definition: plot.C:25
double POT() const
Definition: Spectrum.h:263
string syst
Definition: plotSysts.py:176
void ana::SingleSampleExperiment::SaveTo ( TDirectory *  dir) const
overridevirtualinherited

Reimplemented from ana::IChiSqExperiment.

Definition at line 144 of file SingleSampleExperiment.cxx.

References dir, ana::SingleSampleExperiment::fCosmic, ana::SingleSampleExperiment::fData, ana::SingleSampleExperiment::fMC, ana::IPrediction::SaveTo(), ana::Spectrum::SaveTo(), and tmp.

Referenced by joint_fit_make_experiments().

145  {
146  TDirectory* tmp = dir;
147 
148  dir->cd();
149  TObjString("SingleSampleExperiment").Write("type");
150 
151  fMC->SaveTo(dir->mkdir("mc"));
152  fData.SaveTo(dir->mkdir("data"));
153 
154  if(fCosmic) fCosmic->Write("cosmic");
155 
156  tmp->cd();
157  }
virtual void SaveTo(TDirectory *dir) const
Float_t tmp
Definition: plot.C:36
TDirectory * dir
Definition: macro.C:5
void SaveTo(TDirectory *dir) const
Definition: Spectrum.cxx:1029

Member Data Documentation

TH1D* ana::SingleSampleExperiment::fCosmic
protectedinherited
double ana::SingleSampleExperiment::fCosmicScaleError
protectedinherited
Spectrum ana::SingleSampleExperiment::fData
protectedinherited
const IPrediction* ana::SingleSampleExperiment::fMC
protectedinherited
double ana::BigChi2SingleSampleExperiment::fScaleFactor
private

Definition at line 144 of file MECTuningUtils.h.


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