Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ana::NumuCC2p2hBkgdEstimator Class Referenceabstract

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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/NDAna/numucc_2p2h/NumuCC2p2hBkgdEstimator.h"

Inheritance diagram for ana::NumuCC2p2hBkgdEstimator:
ana::IBkgdEstimator

Public Member Functions

 NumuCC2p2hBkgdEstimator (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)
 
 ~NumuCC2p2hBkgdEstimator ()
 
Spectrum Background () const override
 
void SaveTo (TDirectory *dir) const override
 
virtual void SaveTo (TDirectory *dir, const std::string &name) const =0
 

Static Public Member Functions

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

Private Member Functions

 NumuCC2p2hBkgdEstimator (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 NumuCC2p2hBkgdEstimator.h.

Constructor & Destructor Documentation

ana::NumuCC2p2hBkgdEstimator::NumuCC2p2hBkgdEstimator ( 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 NumuCC2p2hBkgdEstimator.h.

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

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
std::vector< Spectrum * > fDatas
ana::NumuCC2p2hBkgdEstimator::~NumuCC2p2hBkgdEstimator ( )

Definition at line 51 of file NumuCC2p2hBkgdEstimator.cxx.

Referenced by NumuCC2p2hBkgdEstimator().

52  {}
ana::NumuCC2p2hBkgdEstimator::NumuCC2p2hBkgdEstimator ( std::vector< PredictionScaleComp * >  compfits,
std::vector< Spectrum * >  datas,
Spectrum  data 
)
inlineprivate

Definition at line 47 of file NumuCC2p2hBkgdEstimator.h.

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

Member Function Documentation

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

Implements ana::IBkgdEstimator.

Definition at line 12 of file NumuCC2p2hBkgdEstimator.cxx.

References ana::assert(), demo5::expt, fCompPreds, fData, fDatas, ana::Spectrum::GetBinnings(), ana::Spectrum::GetLabels(), GetSpectra(), MECModelEnuComparisons::i, makeTrainCVSamples::int, ana::IFitter::kQuiet, ana::Spectrum::Livetime(), pot, seed, gen_flatrecord::size, systs, and ana::Spectrum::ToTH1().

Referenced by NumuCC2p2hBkgdEstimator().

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 sum up the background templates
21  // Grab the TH1* from fData to get a hist with the right binning
22  TH1 *hbkgd = fData.ToTH1(pot);
23  for (int i = 0; i <= hbkgd->GetNbinsX(); i++) hbkgd->SetBinContent(i,0);
24  assert(hbkgd->GetNbinsX()==int(fCompPreds.size())
25  && "Number of kinematic bins given to NumuCC2p2hBkgdEstimator"
26  " does not match number of reconstructed bins in analysis");
27 
28  // Loop over Preds and fit, get the scale for background, and store in hbkgd
29  for (int kinIdx = 0; kinIdx < int(fCompPreds.size()); kinIdx++){
30  SingleSampleExperiment expt(fCompPreds[kinIdx],*fDatas[kinIdx]);
31  std::vector<const ISyst*> systs = fCompPreds[kinIdx]->GetSysts();
32  // Now we can make a fitter with the vector of systs
33  MinuitFitter fit(&expt, {}, systs);
34  SystShifts seed;
35  // Do a fit
36  fit.Fit(seed,MinuitFitter::kQuiet);
37  double bkgdsum=0;
38  for(int i=0; i<int(fCompPreds[kinIdx]->GetSpectra().size()-1);i++)//loop over non signal preds signal is last
39  {
40  double bkgdscale = seed.GetShift(systs[i]);
41  double bkgdnom = fCompPreds[kinIdx]->GetSpectra()[i]->Integral(pot);
42  bkgdsum+=(1+bkgdscale)*bkgdnom;
43  }
44  hbkgd->SetBinContent(kinIdx+1, bkgdsum);
45  }
46  Spectrum bkgdest(hbkgd, fData.GetLabels(), fData.GetBinnings(), pot, fData.Livetime());
47  delete hbkgd; // ret copies hbkgd, prevent memory leak here
48  return bkgdest;
49  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
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:148
std::vector< PredictionScaleComp * > fCompPreds
expt
Definition: demo5.py:34
unsigned int seed
Definition: runWimpSim.h:102
#define pot
std::vector< float > Spectrum
Definition: Constants.h:610
void GetSpectra(IPrediction *pred, osc::IOscCalc *calc, TH1 *&hSig, TH1 *&hNC, TH1 *&hCC, TH1 *&hBeam, TH1 *&hTotBkg)
Definition: nue_pid_effs.C:427
std::vector< Spectrum * > fDatas
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< NumuCC2p2hBkgdEstimator > ana::NumuCC2p2hBkgdEstimator::LoadFrom ( TDirectory *  dir)
static

Definition at line 77 of file NumuCC2p2hBkgdEstimator.cxx.

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

Referenced by NumuCC2p2hBkgdEstimator().

78  {
79  Spectrum* data = ana::LoadFrom<Spectrum>
80  (dir->GetDirectory("fData")).release();
81 
82  TVectorD* nanabins = (TVectorD*)dir->Get("nanabins");
83  assert(nanabins->GetNoElements()==1 && "N MCBkgds is not 1.");
84  std::vector<Spectrum*> datas;
85  std::vector<PredictionScaleComp*> ps;
86  dir->cd();
87  for (int i = 0; i < (*nanabins)[0]; i++){
88  std::string idxstr = std::to_string(i);
89  dir->cd(("fCompPreds_"+idxstr).c_str());
90  ps.push_back(ana::LoadFrom<PredictionScaleComp>(gDirectory).release());
91  dir->cd(("fDatas_"+idxstr).c_str());
92  datas.push_back(ana::LoadFrom<Spectrum>(gDirectory).release());
93  }
94  return std::unique_ptr<NumuCC2p2hBkgdEstimator>(
95  new NumuCC2p2hBkgdEstimator(ps, datas, *data));
96  }
const XML_Char const XML_Char * data
Definition: expat.h:268
NumuCC2p2hBkgdEstimator(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)
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
virtual void ana::IBkgdEstimator::SaveTo ( TDirectory *  dir,
const std::string name 
) const
pure virtualinherited
void ana::NumuCC2p2hBkgdEstimator::SaveTo ( TDirectory *  dir) const
override

Definition at line 54 of file NumuCC2p2hBkgdEstimator.cxx.

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

Referenced by NumuCC2p2hBkgdEstimator().

55  {
56  TDirectory *tmp = gDirectory;
57  dir->cd();
58 
59  TObjString("NumuCC2p2hBkgdEstimator").Write("type");
60 
61  assert(fCompPreds.size()==fDatas.size());
62  // Save number of analysis bins as a TVectorD for when we load this
63  TVectorD nanabins(1);
64  nanabins[0] = fCompPreds.size();
65  nanabins.Write("nanabins");
66  for (int i = 0; i < int(fCompPreds.size()); i++){
67  std::string idxstr = std::to_string(i);
68  fCompPreds[i]->SaveTo(dir->mkdir(("fCompPreds_"+idxstr).c_str()));
69  fDatas[i] ->SaveTo(dir->mkdir(("fDatas_" +idxstr).c_str()));
70  }
71  fData.SaveTo(dir->mkdir("fData"));
72 
73  tmp->cd();
74  }
std::vector< PredictionScaleComp * > fCompPreds
Float_t tmp
Definition: plot.C:36
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
std::vector< Spectrum * > fDatas
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::NumuCC2p2hBkgdEstimator::fCompPreds
private

Definition at line 55 of file NumuCC2p2hBkgdEstimator.h.

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

Spectrum ana::NumuCC2p2hBkgdEstimator::fData
private

Definition at line 57 of file NumuCC2p2hBkgdEstimator.h.

Referenced by Background(), and SaveTo().

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

Definition at line 56 of file NumuCC2p2hBkgdEstimator.h.

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


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