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<Cut, Var>;
12  template class GenericSystematicDef<NuTruthCut, NuTruthVar>;
13 
14  template<class CutType, class VarType>
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 CutType, class VarType>
25  void
27  {
28  TDirectory * tmp = gDirectory;
29 
30  dir->mkdir(name.c_str());
31  dir = dir->GetDirectory(name.c_str()); // switch to subdir
32  dir->cd();
33 
34 
35  TObjString("SystematicDef").Write("type");
36  TObjString(fName.c_str()).Write("label");
37 
38  const char * type = fType == kOneSided ? "kOneSided" : "kTwoSided";
39  TObjString(type).Write("syst_type");
40 
41  dir->Write();
42  delete dir;
43 
44  tmp->cd();
45  }
46 
47  template<class CutType, class VarType>
48  std::unique_ptr<GenericSystematicDef<CutType, VarType>>
50  {
51  dir = dir->GetDirectory(name.c_str()); // switch to subdir
52  assert(dir);
53 
54  TObjString * ptag = (TObjString*) dir->Get("type");
55  assert(ptag->GetString() == "SystematicDef" && "Type does not match SystematicDef");
56  delete ptag;
57 
58  std::string type = ((TObjString*) dir->Get("syst_type"))->GetString().Data();
59  Type_t type_t = type == "kOneSided" ? kOneSided : kTwoSided;
60 
61  delete dir;
62 
63  std::string label = ((TObjString*) dir->Get("label"))->GetString().Data();
64 
65  delete dir;
66  return std::make_unique<GenericSystematicDef<CutType, VarType>>(label, type_t);
67  }
68 
69 
70 
71  template<class CutType, class VarType>
73  std::vector<SpectrumLoaderBase*> loaders_up,
74  std::vector<SpectrumLoaderBase*> loaders_down,
75  const _HistAxis<VarType> * hist_axis,
77  const UpDownPair<const SystShifts> shifts,
78  Type_t type)
79  : fLoadersUp(loaders_up),
80  fLoadersDown(loaders_down),
81  fHistAxis(hist_axis),
82  fWeight(weights),
83  fSystShifts(shifts),
84  fName(name),
85  fType(type)
86  {}
87 
88  template<class CutType, class VarType>
90  {
91  Spectrum * ret = new Spectrum(*fLoadersUp[0],
92  *fHistAxis,
93  cut,
94  *fSystShifts.up,
95  *fWeight.up);
96  for(auto iload = 1u; iload < fLoadersUp.size(); iload++) {
97  fLoadersUp[iload]->AddSpectrum(*ret,
99  cut,
100  *fSystShifts.up,
101  *fWeight.up);
102 
103  }
104  return ret;
105  }
106 
107  template<class CutType, class VarType>
109  {
110 
111  // for two sided systematics, make sure we're using the right loaders
112  // If two sides originate from shifts or weights,
113  // there will only be one set of loaders, which fLoadersUp will point to.
114  // Loaders are too complicated for redundancy unlike systs and weights
115  Spectrum * ret;
116  if(fLoadersDown.size() > 0) {
117  ret= new Spectrum(*fLoadersDown[0],
118  *fHistAxis,
119  cut,
120  *fSystShifts.down,
121  *fWeight.down);
122  for(auto iload = 1u; iload < fLoadersDown.size(); iload++) {
123  fLoadersDown[iload]->AddSpectrum(*ret,
124  fHistAxis->GetVar1D(),
125  cut,
126  *fSystShifts.down,
127  *fWeight.down);
128 
129  }
130  }
131  else {
132  ret= new Spectrum(*fLoadersUp[0],
133  *fHistAxis,
134  cut,
135  *fSystShifts.down,
136  *fWeight.down);
137  for(auto iload = 1u; iload < fLoadersUp.size(); iload++) {
138  fLoadersUp[iload]->AddSpectrum(*ret,
139  fHistAxis->GetVar1D(),
140  cut,
141  *fSystShifts.down,
142  *fWeight.down);
143 
144  }
145  }
146  return ret;
147  }
148 
149  template<class CutType, class VarType>
151  {
152  return BuildSpectrumUp(cut);
153  }
154 
155  template<class CutType, class VarType>
157  : fHistAxis( new _HistAxis<VarType>(*rhs.fHistAxis)),
158  fWeight({new VarType(*rhs.fWeight.up),new VarType(*rhs.fWeight.down)}),
159  fSystShifts({new SystShifts(*rhs.fSystShifts.up),new SystShifts(*rhs.fSystShifts.down)}),
160  fName(rhs.fName),
161  fType(rhs.fType)
162  {
163  // note loaders can't be copied
164  }
165 
166  template<class CutType, class VarType>
168  : fHistAxis(std::move(rhs.fHistAxis)),
169  fWeight({std::move(rhs.fWeight.up), std::move(rhs.fWeight.down)}),
170  fSystShifts({std::move(rhs.fSystShifts.up), std::move(rhs.fSystShifts.down)}),
171  fName(rhs.fName),
172  fType(rhs.fType)
173  {}
174 
175 }
GenericSystematicDef(std::string name, Type_t type)
Definition: SystematicDef.h:30
const XML_Char * name
Definition: expat.h:151
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const std::string fName
const UpDownPair< const VarType > fWeight
std::vector< double > Spectrum
Definition: Constants.h:746
Float_t tmp
Definition: plot.C:36
void SaveTo(TDirectory *dir, const std::string &name) const
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:39
const char * label
static std::unique_ptr< GenericSystematicDef< CutType, VarType > > LoadFrom(TDirectory *dir, const std::string &name)
Spectrum * BuildSpectrum(const CutType cut)
Var weights
std::vector< SpectrumLoaderBase * > fLoadersUp
Spectrum * BuildSpectrumUp(const CutType cut)
const _HistAxis< VarType > * fHistAxis
const Cut cut
Definition: exporter_fd.C:30
string GetString(xmlDocPtr xml_doc, string node_path)
TDirectory * dir
Definition: macro.C:5
std::vector< SpectrumLoaderBase * > fLoadersDown
assert(nhit_max >=nhit_nbins)
const UpDownPair< const SystShifts > fSystShifts
Spectrum * BuildSpectrumDown(const CutType cut)
T GetVar1D() const
Definition: HistAxis.h:110
gm Write()
enum BeamMode string