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

Fits the background and signal in each analysis bin independently. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CAFAna/XSec/FitInAnaBinsBkgdEstimator.h"

Inheritance diagram for ana::FitInAnaBinsBkgdEstimator:
ana::IBkgdEstimator

Public Member Functions

 FitInAnaBinsBkgdEstimator (SpectrumLoaderBase &lMC, SpectrumLoaderBase &lDA, const HistAxis axisana, const HistAxis axisfit, const Cut sel, std::vector< Cut > kinsel, std::vector< std::pair< Cut, bool > > bkgdtypes, Cut isSig, const SystShifts &shiftmc=kNoShift, const SystShifts &shiftda=kNoShift, const Var &weimc=kUnweighted, const Var &weida=kUnweighted)
 
Spectrum Background () const override
 
void SaveTo (TDirectory *dir, const std::string &name) const override
 

Static Public Member Functions

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

Private Member Functions

 FitInAnaBinsBkgdEstimator (std::vector< PredictionScaleComp * > compfits, std::vector< Spectrum * > datas, Spectrum data)
 

Private Attributes

std::vector< PredictionScaleComp * > fCompPreds
 
std::vector< Spectrum * > fDatas
 
Spectrum fData
 

Detailed Description

Fits the background and signal in each analysis bin independently.

Definition at line 11 of file FitInAnaBinsBkgdEstimator.h.

Constructor & Destructor Documentation

ana::FitInAnaBinsBkgdEstimator::FitInAnaBinsBkgdEstimator ( SpectrumLoaderBase lMC,
SpectrumLoaderBase lDA,
const HistAxis  axisana,
const HistAxis  axisfit,
const Cut  sel,
std::vector< Cut kinsel,
std::vector< std::pair< Cut, bool > >  bkgdtypes,
Cut  isSig,
const SystShifts shiftmc = kNoShift,
const SystShifts shiftda = kNoShift,
const Var weimc = kUnweighted,
const Var weida = kUnweighted 
)
inline

Definition at line 14 of file FitInAnaBinsBkgdEstimator.h.

References Background(), cut, dir, fCompPreds, fDatas, LoadFrom(), SaveTo(), and string.

Referenced by LoadFrom().

28  : fData(lDA,axisana,sel,shiftda,weida)
29  {
30  std::vector< std::pair<Cut,bool> > inttypes = bkgdtypes;
31  // Always include signal as last entry, and always float in fit
32  inttypes.push_back(std::pair<Cut,bool>(isSig,true));
33  for (Cut cut : kinsel){
34  fCompPreds.push_back(new PredictionScaleComp(lMC, axisfit, sel&&cut,
35  inttypes, shiftmc, weimc));
36  fDatas.push_back(new Spectrum(lDA, axisfit, sel&&cut, shiftda, weida));
37  }
38  }
std::vector< PredictionScaleComp * > fCompPreds
_Cut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
std::vector< float > Spectrum
Definition: Constants.h:610
const Cut cut
Definition: exporter_fd.C:30
ana::FitInAnaBinsBkgdEstimator::FitInAnaBinsBkgdEstimator ( std::vector< PredictionScaleComp * >  compfits,
std::vector< Spectrum * >  datas,
Spectrum  data 
)
inlineprivate

Definition at line 46 of file FitInAnaBinsBkgdEstimator.h.

49  : fCompPreds(compfits),
50  fDatas(datas),
51  fData(data)
52  {}
std::vector< PredictionScaleComp * > fCompPreds
const XML_Char const XML_Char * data
Definition: expat.h:268

Member Function Documentation

Spectrum ana::FitInAnaBinsBkgdEstimator::Background ( ) const
overridevirtual

Implements ana::IBkgdEstimator.

Definition at line 12 of file FitInAnaBinsBkgdEstimator.cxx.

References ana::assert(), demo5::expt, fCompPreds, fData, fDatas, ana::Spectrum::GetBinnings(), ana::Spectrum::GetEigen(), ana::Spectrum::GetLabels(), makeTrainCVSamples::int, ana::IFitter::kQuiet, ana::Spectrum::Livetime(), pot, seed, and systs.

Referenced by FitInAnaBinsBkgdEstimator().

13  {
14  assert(fCompPreds.size()>0 && "Must give at least one MC int type");
15  assert(fCompPreds.size()==fDatas.size());
16 
17  // Set pot = 1 so that if there's a POT accounting error, it super obvious
18  double pot = 1;
19 
20  // We're going to subtract off the signal prediction from the data
21  // Grab the TH1* from fData to get a hist with the right binning
22  Eigen::ArrayXd asig = fData.GetEigen(pot);
23  asig.setZero();
24 
25  assert(asig.size()-2==int(fCompPreds.size())
26  && "Number of kinematic bins given to FitInAnaBinsBkgdEstimator"
27  " does not match number of reconstructed bins in analysis");
28 
29  // Loop over Preds and fit, get the scale for signal, and store in hsig
30  for (int kinIdx = 0; kinIdx < int(fCompPreds.size()); kinIdx++){
31  SingleSampleExperiment expt(fCompPreds[kinIdx],*fDatas[kinIdx]);
32  std::vector<const ISyst*> systs = fCompPreds[kinIdx]->GetSysts();
33  // Now we can make a fitter with the vector of systs
34  MinuitFitter fit(&expt, {}, systs);
35  SystShifts seed;
36  // Do a fit
37  fit.Fit(seed,MinuitFitter::kQuiet);
38  double sigscale = seed.GetShift(systs.back()); // Signal scale is last
39  double signom = fCompPreds[kinIdx]->GetSpectra().back()->Integral(pot);
40  asig[kinIdx+1] = (1+sigscale)*signom;
41  }
42  Spectrum sigest(std::move(asig),
44  pot, fData.Livetime());
45  return fData - sigest;
46  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
std::vector< PredictionScaleComp * > fCompPreds
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
const Eigen::ArrayXd & GetEigen() const
NB these don&#39;t have POT scaling. For expert high performance ops only!
Definition: Spectrum.h:189
expt
Definition: demo5.py:34
unsigned int seed
Definition: runWimpSim.h:102
#define pot
std::vector< float > Spectrum
Definition: Constants.h:610
assert(nhit_max >=nhit_nbins)
const std::vector< std::string > & GetLabels() const
Definition: Spectrum.h:263
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:230
std::unique_ptr< FitInAnaBinsBkgdEstimator > ana::FitInAnaBinsBkgdEstimator::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 76 of file FitInAnaBinsBkgdEstimator.cxx.

References ana::assert(), dir, FitInAnaBinsBkgdEstimator(), MECModelEnuComparisons::i, nd_projection_maker::ps, runNovaSAM::release, string, and art::to_string().

Referenced by FitInAnaBinsBkgdEstimator(), and ana::LoadFrom< IBkgdEstimator >().

77  {
78  dir = dir->GetDirectory(name.c_str()); // switch to subdir
79  assert(dir);
80 
81  Spectrum* data = ana::LoadFrom<Spectrum>(dir, "fData").release();
82 
83  TVectorD* nanabins = (TVectorD*)dir->Get("nanabins");
84  assert(nanabins->GetNoElements()==1 && "N MCBkgds is not 1.");
85  std::vector<Spectrum*> datas;
86  std::vector<PredictionScaleComp*> ps;
87  for (int i = 0; i < (*nanabins)[0]; i++){
88  std::string idxstr = std::to_string(i);
89  ps.push_back(ana::LoadFrom<PredictionScaleComp>(dir, "fCompPreds_"+idxstr).release());
90  datas.push_back(ana::LoadFrom<Spectrum>(dir, "fDatas_"+idxstr).release());
91  }
92 
93  delete dir;
94 
95  return std::unique_ptr<FitInAnaBinsBkgdEstimator>(
96  new FitInAnaBinsBkgdEstimator(ps, datas, *data));
97  }
const XML_Char * name
Definition: expat.h:151
FitInAnaBinsBkgdEstimator(SpectrumLoaderBase &lMC, SpectrumLoaderBase &lDA, const HistAxis axisana, const HistAxis axisfit, const Cut sel, std::vector< Cut > kinsel, std::vector< std::pair< Cut, bool > > bkgdtypes, Cut isSig, const SystShifts &shiftmc=kNoShift, const SystShifts &shiftda=kNoShift, const Var &weimc=kUnweighted, const Var &weida=kUnweighted)
const XML_Char const XML_Char * data
Definition: expat.h:268
std::vector< float > Spectrum
Definition: Constants.h:610
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string
void ana::FitInAnaBinsBkgdEstimator::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Implements ana::IBkgdEstimator.

Definition at line 48 of file FitInAnaBinsBkgdEstimator.cxx.

References ana::assert(), dir, fCompPreds, fData, fDatas, MECModelEnuComparisons::i, makeTrainCVSamples::int, ana::Spectrum::SaveTo(), string, tmp, and art::to_string().

Referenced by FitInAnaBinsBkgdEstimator().

49  {
50  TDirectory *tmp = gDirectory;
51 
52  dir = dir->mkdir(name.c_str()); // switch to subdir
53  dir->cd();
54 
55  TObjString("FitInAnaBinsBkgdEstimator").Write("type");
56 
57  assert(fCompPreds.size()==fDatas.size());
58  // Save number of analysis bins as a TVectorD for when we load this
59  TVectorD nanabins(1);
60  nanabins[0] = fCompPreds.size();
61  nanabins.Write("nanabins");
62  for (int i = 0; i < int(fCompPreds.size()); i++){
63  std::string idxstr = std::to_string(i);
64  fCompPreds[i]->SaveTo(dir, "fCompPreds_"+idxstr);
65  fDatas[i] ->SaveTo(dir, "fDatas_" +idxstr);
66  }
67  fData.SaveTo(dir, "fData");
68 
69  dir->Write();
70  delete dir;
71 
72  tmp->cd();
73  }
const XML_Char * name
Definition: expat.h:151
std::vector< PredictionScaleComp * > fCompPreds
Float_t tmp
Definition: plot.C:36
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string

Member Data Documentation

std::vector<PredictionScaleComp*> ana::FitInAnaBinsBkgdEstimator::fCompPreds
private

Definition at line 54 of file FitInAnaBinsBkgdEstimator.h.

Referenced by Background(), FitInAnaBinsBkgdEstimator(), and SaveTo().

Spectrum ana::FitInAnaBinsBkgdEstimator::fData
private

Definition at line 56 of file FitInAnaBinsBkgdEstimator.h.

Referenced by Background(), and SaveTo().

std::vector<Spectrum*> ana::FitInAnaBinsBkgdEstimator::fDatas
private

Definition at line 55 of file FitInAnaBinsBkgdEstimator.h.

Referenced by Background(), FitInAnaBinsBkgdEstimator(), and SaveTo().


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