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-11-28/CAFAna/xsec_tuning/Ana2020/tuning/MECTuningUtils.h"

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

Public Member Functions

 BigChi2SingleSampleExperiment (const IPrediction *pred, const Spectrum &data, double scaleFactor=1)
 
double ChiSq (osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
 
const IPredictionGetPrediction () const
 
virtual stan::math::var LogLikelihood (osc::IOscCalcAdjustableStan *osc, const SystShifts &syst=kNoShift) const override
 
virtual void SaveTo (TDirectory *dir, const std::string &name) const override
 

Static Public Member Functions

static std::unique_ptr< SingleSampleExperimentLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

template<typename T >
Eigen::Array< T, Eigen::Dynamic, 1 > PredHistIncCosmics (osc::_IOscCalc< T > *calc, const SystShifts &syst) const
 

Protected Attributes

const IPredictionfMC
 
Spectrum fData
 
std::optional< SpectrumfCosmic
 
double fCosmicScaleError
 
bool fPoissonError
 
std::vector< std::pair< double, double > > fBinErrors
 

Private Attributes

double fScaleFactor
 

Detailed Description

Definition at line 147 of file MECTuningUtils.h.

Constructor & Destructor Documentation

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

Definition at line 150 of file MECTuningUtils.h.

153  : SingleSampleExperiment(pred, data), fScaleFactor(scaleFactor)
154  {}
SingleSampleExperiment(const IPrediction *pred, const Spectrum &data, const Spectrum &cosmic, double cosmicScaleError=0, bool PoissonError=false)
const XML_Char const XML_Char * data
Definition: expat.h:268

Member Function Documentation

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

Reimplemented from ana::SingleSampleExperiment.

Definition at line 156 of file MECTuningUtils.h.

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

158  {
160  return fScaleFactor * expt.ChiSq(osc, syst);
161  }
SingleSampleExperiment(const IPrediction *pred, const Spectrum &data, const Spectrum &cosmic, double cosmicScaleError=0, bool PoissonError=false)
expt
Definition: demo5.py:34
const IPrediction* ana::SingleSampleExperiment::GetPrediction ( ) const
inlineinherited
std::unique_ptr< SingleSampleExperiment > ana::SingleSampleExperiment::LoadFrom ( TDirectory *  dir,
const std::string name 
)
staticinherited

Definition at line 154 of file SingleSampleExperiment.cxx.

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

155  {
156  dir = dir->GetDirectory(name.c_str()); // switch to subdir
157  assert(dir);
158 
159  TObjString* ptag = (TObjString*)dir->Get("type");
160  assert(ptag);
161  assert(ptag->GetString() == "SingleSampleExperiment");
162  delete ptag;
163 
164  const IPrediction* mc = ana::LoadFrom<IPrediction>(dir, "mc").release();
165  const std::unique_ptr<Spectrum> data = Spectrum::LoadFrom(dir, "data");
166 
167  auto ret = std::make_unique<SingleSampleExperiment>(mc, *data);
168 
169  if(dir->Get("cosmic")){
170  ret->fCosmic = *ana::LoadFrom<Spectrum>(dir, "cosmic");
171  }
172 
173  delete dir;
174 
175  return ret;
176  }
const XML_Char * name
Definition: expat.h:151
const XML_Char const XML_Char * data
Definition: expat.h:268
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir, const std::string &label)
Definition: IPrediction.cxx:18
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
stan::math::var ana::SingleSampleExperiment::LogLikelihood ( osc::IOscCalcAdjustableStan osc,
const SystShifts syst = kNoShift 
) const
overridevirtualinherited

Reimplemented from ana::IExperiment.

Definition at line 122 of file SingleSampleExperiment.cxx.

References ana::SingleSampleExperiment::fData, ana::Spectrum::GetEigen(), ana::LogLikelihood(), ana::Spectrum::POT(), plot_validation_datamc::pred, and ana::SingleSampleExperiment::PredHistIncCosmics().

Referenced by test_stanfit_systpulls().

124  {
126  Eigen::ArrayXd data = fData.GetEigen(fData.POT());
127 
128  // fully-qualified so that we get the one in StanUtils.h
129  return ana::LogLikelihood(pred, data) / -2.; // LogLikelihood(), confusingly, returns chi2=-2*LL
130  }
const Eigen::ArrayXd & GetEigen() const
NB these don&#39;t have POT scaling. For expert high performance ops only!
Definition: Spectrum.h:189
double LogLikelihood(const Eigen::ArrayXd &ea, const Eigen::ArrayXd &oa, bool useOverflow)
The log-likelihood formula from the PDG.
Definition: EigenUtils.cxx:36
const XML_Char const XML_Char * data
Definition: expat.h:268
double POT() const
Definition: Spectrum.h:227
Eigen::Array< stan::math::var, Eigen::Dynamic, 1 > ArrayXstan
Definition: StanUtils.h:7
Eigen::Array< T, Eigen::Dynamic, 1 > PredHistIncCosmics(osc::_IOscCalc< T > *calc, const SystShifts &syst) const
template<typename T >
template Eigen::ArrayXstan ana::SingleSampleExperiment::PredHistIncCosmics ( osc::_IOscCalc< T > *  calc,
const SystShifts syst 
) const
protectedinherited

Definition at line 64 of file SingleSampleExperiment.cxx.

References calc, ana::SingleSampleExperiment::fBinErrors, ana::SingleSampleExperiment::fCosmic, ana::SingleSampleExperiment::fCosmicScaleError, ana::SingleSampleExperiment::fData, ana::SingleSampleExperiment::fMC, ana::SingleSampleExperiment::fPoissonError, ana::Spectrum::GetEigen(), ana::Spectrum::GetEigenStan(), ana::SystShifts::GetShift(), ana::Spectrum::HasStan(), MECModelEnuComparisons::i, ana::kLivetime, ana::Spectrum::Livetime(), ana::Spectrum::POT(), ana::IPrediction::PredictSyst(), ana::SystShifts::RemoveShift(), scale, sigma(), and T.

Referenced by ana::SingleSampleExperiment::ChiSq(), and ana::SingleSampleExperiment::LogLikelihood().

66  {
67  using EigenArray = Eigen::Array<T, Eigen::Dynamic, 1>;
68 
69  SystShifts systNoCosmic = syst;
70  systNoCosmic.RemoveShift(&kCosmicBkgScaleSyst);
71 
72  Spectrum specPred = fMC->PredictSyst(calc, systNoCosmic);
73  EigenArray apred;
74  if (specPred.HasStan())
75  {
76  if constexpr (std::is_same_v<T, stan::math::var>)
77  apred = specPred.GetEigenStan(fData.POT());
78  }
79  else
80  apred = specPred.GetEigen(fData.POT());
81 
82  if(fCosmic.has_value()){
83  // note the conversion here from double to stan::math::var if T is stan::math::var
84  EigenArray acosm = fCosmic->GetEigen(fData.Livetime(), kLivetime);
85  if(fCosmicScaleError != 0 && !fPoissonError){
86  const T scale = 1 + syst.GetShift(&kCosmicBkgScaleSyst) * fCosmicScaleError;
87  acosm *= scale;
88  }
89  if(fPoissonError){
90  T sigma = syst.GetShift(&kCosmicBkgScaleSyst);
91  for(int i = 1; i<= acosm.size()-2; i++){
92  if (sigma>0) acosm[i] *= (1+sigma*fBinErrors[i-1].first);
93  if (sigma<0) acosm[i] *= (1+sigma*fBinErrors[i-1].second);
94  }
95  }
96 
97  apred += acosm;
98  }
99 
100  return apred;
101  }
std::optional< Spectrum > fCosmic
const CosmicBkgScaleSyst kCosmicBkgScaleSyst
Double_t scale
Definition: plot.C:25
if(dump)
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const
Definition: IPrediction.cxx:49
std::vector< std::pair< double, double > > fBinErrors
std::vector< float > Spectrum
Definition: Constants.h:610
double sigma(TH1F *hist, double percentile)
std::vector< double > POT
double T
Definition: Xdiff_gwt.C:5
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:230
void ana::SingleSampleExperiment::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtualinherited

Reimplemented from ana::IExperiment.

Definition at line 133 of file SingleSampleExperiment.cxx.

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

134  {
135  TDirectory* tmp = dir;
136 
137  dir = dir->mkdir(name.c_str()); // switch to subdir
138  dir->cd();
139 
140  TObjString("SingleSampleExperiment").Write("type");
141 
142  fMC->SaveTo(dir, "mc");
143  fData.SaveTo(dir, "data");
144 
145  if(fCosmic.has_value()) fCosmic->SaveTo(dir, "cosmic");
146 
147  dir->Write();
148  delete dir;
149 
150  tmp->cd();
151  }
const XML_Char * name
Definition: expat.h:151
std::optional< Spectrum > fCosmic
Float_t tmp
Definition: plot.C:36
virtual void SaveTo(TDirectory *dir, const std::string &name) const
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
TDirectory * dir
Definition: macro.C:5

Member Data Documentation

std::vector< std::pair <double, double> > ana::SingleSampleExperiment::fBinErrors
protectedinherited
std::optional<Spectrum> ana::SingleSampleExperiment::fCosmic
protectedinherited
double ana::SingleSampleExperiment::fCosmicScaleError
protectedinherited
Spectrum ana::SingleSampleExperiment::fData
protectedinherited
const IPrediction* ana::SingleSampleExperiment::fMC
protectedinherited
bool ana::SingleSampleExperiment::fPoissonError
protectedinherited
double ana::BigChi2SingleSampleExperiment::fScaleFactor
private

Definition at line 164 of file MECTuningUtils.h.


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