SystematicDef.cxx
Go to the documentation of this file.
2 
3 #include "CAFAna/Core/Spectrum.h"
4 
5 #include "TString.h"
6 #include "TDirectory.h"
7 #include "TObjString.h"
8 
9 namespace ana {
10 
11  template class GenericSystematicDef<caf::SRProxy>;
12  template class GenericSystematicDef<caf::SRNeutrinoProxy>;
13 
14  template<class SRType>
15  void
17  {
18  for(auto iload = 0u; iload < fLoadersUp.size(); iload++)
19  if(!fLoadersUp[iload]->Gone()) fLoadersUp[iload]->Go();
20  for(auto iload = 0u; iload < fLoadersDown.size(); iload++)
21  if(!fLoadersDown[iload]->Gone()) fLoadersDown[iload]->Go();
22  }
23 
24  template<class SRType>
25  void
27  {
28  TDirectory * tmp = gDirectory;
29 
30  dir = dir->mkdir(name.c_str()); // switch to subdir
31  dir->cd();
32 
33  TObjString("SystematicDef").Write("type");
34  TObjString(fName.c_str()).Write("label");
35 
36  const char * type = fType == kOneSided ? "kOneSided" : "kTwoSided";
37  TObjString(type).Write("syst_type");
38 
39  dir->Write();
40  delete dir;
41 
42  tmp->cd();
43  }
44 
45  template<class SRType>
46  std::unique_ptr<GenericSystematicDef<SRType> >
48  {
49  dir = dir->GetDirectory(name.c_str()); // switch to subdir
50  assert(dir);
51 
52  TObjString * ptag = (TObjString*) dir->Get("type");
53  assert(ptag->GetString() == "SystematicDef" && "Type does not match SystematicDef");
54  delete ptag;
55 
56  std::string type = ((TObjString*) dir->Get("syst_type"))->GetString().Data();
57  Type_t type_t = type == "kOneSided" ? kOneSided : kTwoSided;
58 
59  delete dir;
60 
61  std::string label = ((TObjString*) dir->Get("label"))->GetString().Data();
62  return std::make_unique<GenericSystematicDef<SRType> >(label, type_t);
63  }
64 
65 
66 
67  template<class SRType>
69  std::vector<SpectrumLoaderBase*> loaders_up,
70  std::vector<SpectrumLoaderBase*> loaders_down,
71  const _HistAxis<_Var<SRType> > * hist_axis,
72  const UpDownPair<const _Var<SRType> > weights,
73  const UpDownPair<const SystShifts> shifts,
74  Type_t type)
75  : fLoadersUp(loaders_up),
76  fLoadersDown(loaders_down),
77  fHistAxis(hist_axis),
78  fWeight(weights),
79  fSystShifts(shifts),
80  fName(name),
81  fType(type)
82  {}
83 
84  template<class SRType>
86  {
87  Spectrum * ret = new Spectrum(*fLoadersUp[0],
88  *fHistAxis,
89  cut,
90  *fSystShifts.up,
91  *fWeight.up);
92  for(auto iload = 1u; iload < fLoadersUp.size(); iload++) {
93  fLoadersUp[iload]->AddSpectrum(*ret,
94  fHistAxis->GetVar1D(),
95  cut,
96  *fSystShifts.up,
97  *fWeight.up);
98 
99  }
100  return ret;
101  }
102 
103  template<class SRType>
105  {
106 
107  // for two sided systematics, make sure we're using the right loaders
108  // If two sides originate from shifts or weights,
109  // there will only be one set of loaders, which fLoadersUp will point to.
110  // Loaders are too complicated for redundancy unlike systs and weights
111  Spectrum * ret;
112  if(fLoadersDown.size() > 0) {
113  ret= new Spectrum(*fLoadersDown[0],
114  *fHistAxis,
115  cut,
116  *fSystShifts.down,
117  *fWeight.down);
118  for(auto iload = 1u; iload < fLoadersDown.size(); iload++) {
119  fLoadersDown[iload]->AddSpectrum(*ret,
120  fHistAxis->GetVar1D(),
121  cut,
122  *fSystShifts.down,
123  *fWeight.down);
124 
125  }
126  }
127  else {
128  ret= new Spectrum(*fLoadersUp[0],
129  *fHistAxis,
130  cut,
131  *fSystShifts.down,
132  *fWeight.down);
133  for(auto iload = 1u; iload < fLoadersUp.size(); iload++) {
134  fLoadersUp[iload]->AddSpectrum(*ret,
135  fHistAxis->GetVar1D(),
136  cut,
137  *fSystShifts.down,
138  *fWeight.down);
139 
140  }
141  }
142  return ret;
143  }
144 
145  template<class SRType>
147  {
148  return BuildSpectrumUp(cut);
149  }
150 
151  template<class SRType>
153  : fHistAxis( new _HistAxis<_Var<SRType> >(*rhs.fHistAxis)),
154  fWeight({new _Var<SRType>(*rhs.fWeight.up),new _Var<SRType>(*rhs.fWeight.down)}),
155  fSystShifts({new SystShifts(*rhs.fSystShifts.up),new SystShifts(*rhs.fSystShifts.down)}),
156  fName(rhs.fName),
157  fType(rhs.fType)
158  {
159  // note loaders can't be copied
160  }
161 
162  template<class SRType>
164  : fHistAxis(std::move(rhs.fHistAxis)),
165  fWeight({std::move(rhs.fWeight.up), std::move(rhs.fWeight.down)}),
166  fSystShifts({std::move(rhs.fSystShifts.up), std::move(rhs.fSystShifts.down)}),
167  fName(rhs.fName),
168  fType(rhs.fType)
169  {}
170 
171 }
const XML_Char * name
Definition: expat.h:151
void SaveTo(TDirectory *dir, const std::string &name) const
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
static std::unique_ptr< GenericSystematicDef< SRType > > LoadFrom(TDirectory *dir, const std::string &name)
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Spectrum * BuildSpectrumDown(const _Cut< SRType > cut)
std::vector< SpectrumLoaderBase * > fLoadersUp
Float_t tmp
Definition: plot.C:36
const std::string fName
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
Spectrum * BuildSpectrumUp(const _Cut< SRType > cut)
std::vector< SpectrumLoaderBase * > fLoadersDown
Var weights
std::vector< float > Spectrum
Definition: Constants.h:570
const UpDownPair< const SystShifts > fSystShifts
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
string GetString(xmlDocPtr xml_doc, string node_path)
Collect information describing the x-axis of an analysis histogram.
Definition: HistAxis.h:18
TDirectory * dir
Definition: macro.C:5
const _HistAxis< _Var< SRType > > * fHistAxis
assert(nhit_max >=nhit_nbins)
GenericSystematicDef(std::string name, Type_t type)
Definition: SystematicDef.h:30
Spectrum * BuildSpectrum(const _Cut< SRType > cut)
Template for Cut and SpillCut.
Definition: Cut.h:15
const UpDownPair< const _Var< SRType > > fWeight
gm Write()