TrivialSignalEstimator.cxx
Go to the documentation of this file.
4 
5 #include "TObjString.h"
6 #include "TVectorD.h"
7 
8 namespace ana
9 {
10  ///////////////////////////////////////////////////////////////////////
11  int
13  {
14  return fBkgdEst->GetNComponents();
15  }
16 
17  ///////////////////////////////////////////////////////////////////////
18  const Spectrum *
20  {
21  return fBkgdEst->GetComponent(n);
22  }
23 
24  ///////////////////////////////////////////////////////////////////////
26  const HistAxis * axis,
27  const Cut & selection,
28  std::vector<Cut> trueBkgds,
29  const SystShifts & shift,
30  const Var & weight)
31  : fBkgdEst(new TrivialBkgdEstimator(*loader_mc,
32  *axis,
33  selection,
34  trueBkgds,
35  shift,
36  weight))
37  {}
38 
39  ///////////////////////////////////////////////////////////////////////
40  const Spectrum *
41  TrivialSignalEstimator::Signal(const Spectrum * sel_data) const
42  {
43  return new Spectrum(*sel_data - fBkgdEst->Background());
44  }
45 
46  ///////////////////////////////////////////////////////////////////////
47  const Spectrum *
49  {
50  return new Spectrum(fBkgdEst->Background());
51  }
52 
53  ///////////////////////////////////////////////////////////////////////
54  void TrivialSignalEstimator::SaveTo(TDirectory *dir, const std::string& name) const
55  {
56  TDirectory * tmp = gDirectory;
57 
58  dir = dir->mkdir(name.c_str()); // switch to subdir
59  dir->cd();
60 
61  TObjString("TrivialSignalEstimator").Write("type");
62 
63  fBkgdEst->SaveTo(dir, "fBkgdEst");
64 
65  dir->Write();
66  delete dir;
67 
68  tmp->cd();
69  }
70 
71  ///////////////////////////////////////////////////////////////////////
74  {
75  return new TrivialSignalEstimator(*this);
76  }
77 
78  ///////////////////////////////////////////////////////////////////////
79  std::unique_ptr<TrivialSignalEstimator>
81  {
82  dir = dir->GetDirectory(name.c_str()); // switch to subdir
83  assert(dir);
84 
85  TObjString * tag = (TObjString*) dir->Get("type");
86  assert(tag);
87  assert(tag->GetString() == "TrivialSignalEstimator" && "Type does not match TrivialSignalEstimator");
88  delete tag;
89 
90  TrivialBkgdEstimator* bkgd = TrivialBkgdEstimator::LoadFrom(dir, "fBkgdEst").release();
91 
92  delete dir;
93 
94  return std::unique_ptr<TrivialSignalEstimator>
95  ( new TrivialSignalEstimator(bkgd) );
96  }
97 
98  ///////////////////////////////////////////////////////////////////////
100  : fBkgdEst(bkgd)
101  {}
102 
103  ///////////////////////////////////////////////////////////////////////
106  {
107  this->fBkgdEst = new TrivialBkgdEstimator(*rhs.fBkgdEst);
108  }
109 
110  ///////////////////////////////////////////////////////////////////////
113  {
114  this->fBkgdEst = rhs.fBkgdEst;
115  rhs.fBkgdEst = NULL;
116  }
117 
118  ///////////////////////////////////////////////////////////////////////
121  {
122  if ( this == &rhs )
123  return *this;
124  this->fBkgdEst = new TrivialBkgdEstimator(*rhs.fBkgdEst);
125  return *this;
126  }
127 
128  ///////////////////////////////////////////////////////////////////////
131  {
132  if ( this == &rhs )
133  return *this;
134  this->fBkgdEst = rhs.fBkgdEst;
135  rhs.fBkgdEst = NULL;
136  return *this;
137  }
138 
139  ///////////////////////////////////////////////////////////////////////
141  {
142  delete fBkgdEst;
143  }
144 
145 }
const XML_Char * name
Definition: expat.h:151
static std::unique_ptr< TrivialSignalEstimator > LoadFrom(TDirectory *, const std::string &name)
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
static std::unique_ptr< TrivialBkgdEstimator > LoadFrom(TDirectory *dir, const std::string &name)
const Spectrum * Background() const override
Float_t tmp
Definition: plot.C:36
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Spectrum * GetComponent(int) const
const Spectrum * BackgroundComponent(int) const override
const Spectrum * Signal(const Spectrum *) const override
Spectrum Background() const override
int GetNBkgdComponents() const override
TrivialBkgdEstimator * fBkgdEst
std::vector< float > Spectrum
Definition: Constants.h:570
ISignalEstimator * Clone() override
Base class for the various types of spectrum loader.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TrivialSignalEstimator & operator=(const TrivialSignalEstimator &)
TrivialSignalEstimator(SpectrumLoaderBase *loader_mc, const HistAxis *axis, const Cut &sel, std::vector< Cut > trueBkgds, const SystShifts &shift=kNoShift, const Var &weight=kUnweighted)
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void SaveTo(TDirectory *, const std::string &name) const override
Just return the MC prediction for the background.
void SaveTo(TDirectory *dir, const std::string &name) const override