SystMaker.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 // SystMaker.C
3 // Mike Wallbank <wallbank@fnal.gov> (University of Cincinnati), June 2018
4 // Jeremy Hewes <jhewes15@fnal.gov> (University of Cincinnati), Dec 2018
5 //
6 // Framework for handling the creation, manipulation and interface of
7 // systematics for the long-baseline NC-disappearance analyses.
8 // Refer to docdb-34085 for more information and user manual.
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #pragma once
12 
13 // Framework includes
14 
15 // #include "OscLib/func/OscCalcSterile.h"
16 
17 #include "CAFAna/Core/HistAxis.h"
18 #include "CAFAna/Core/Cut.h"
19 #include "CAFAna/Core/ISyst.h"
20 #include "CAFAna/Core/Sample.h"
22 #include "CAFAna/Analysis/Calcs.h"
24 
25 #include "TVector.h"
26 
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 #include <vector>
31 #include <algorithm>
32 
33 class TFile;
34 class TH1;
35 class TCanvas;
36 
37 namespace ana {
38 
39  enum class SystPredType {
40  kExtrap,
41  kFD,
42  kND,
43  kUnknown
44  };
45 
50 
51  // Forward declarations
52  class Loaders;
53  class IPrediction;
54  class SystShifts;
55  class NuISyst;
56 
58  const HistAxis* axis, const HistAxis* numuAxis,
59  const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut,
60  const SystShifts* shift_data, const SystShifts* shift_mc,
61  const Var* weight,
62  Loaders* loaders, Loaders* loaders_nd = nullptr);
63 
64  TH1* GetSpectrum(IPrediction* pred, bool signal, covmx::Sample sample,
66 
68 
69  // --------------------------------------------------------------------------
71 
72  public:
73 
77 
79  int fSigma;
81  std::pair<TH1*, TH1*> fShiftedSpectrum;
82  std::pair<TH1*, TH1*> fShiftedRatio;
83  std::pair<double, double> fShift;
84 
85  void PrintSigma(std::ostream& os = std::cout);
86 
87  void SaveTo(TDirectory* dir) const;
88  static SystMakerShiftSigma* LoadFrom(TDirectory* dir);
89 
90  };
91 
92  // --------------------------------------------------------------------------
94 
95  public:
96 
98  virtual ~SystMakerShift();
99 
100  std::string GetName() { return fName; }
101  std::string GetLabel() { return fLabel; }
102  std::vector<int> GetSigmas();
103 
104  void PrintShift(std::ostream& os = std::cout);
105 
106  bool CheckShifts();
107  TCanvas* DrawSig(TH1* nominal);
108  TCanvas* DrawBkg(TH1* nominal);
109  void DrawShift(TDirectory* outDir, std::pair<TH1*, TH1*>& nominal);
110  std::string WriteTable(std::pair<TH1*, TH1*> nominal,
111  std::string name);
112 
113  std::pair<TH1*, TH1*> GetShiftedSpectrum(int sigma);
114  void ProcessShift(std::pair<TH1*, TH1*>& nominal_spectrum,
115  const covmx::Sample sample, osc::IOscCalc* calc);
116  virtual void MakePredictions(SystPredType predType,
117  const HistAxis* axis, const HistAxis* numuAxis,
118  const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut,
119  const Var* weight, Loaders* loaders);
120 
121  void SaveTo(TDirectory* dir) const;
122  static std::unique_ptr<SystMakerShift> LoadFrom(TDirectory* dir);
123 
124  protected:
125 
128 
129  std::map<int, SystMakerShiftSigma*> fSigmas;
130 
131  };
132 
133  // --------------------------------------------------------------------------
135 
136  public:
137 
139  void AddSigma(Loaders* loaders, int sigma);
140  void AddSigma(Loaders* loaders_nd, Loaders* loaders_fd, int sigma);
141  void AddOnOff(Loaders* loaders);
142  void AddOnOff(Loaders* loaders_nd, Loaders* loaders_fd);
143  virtual void MakePredictions(SystPredType predType,
144  const HistAxis* axis, const HistAxis* numuAxis,
145  const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut,
146  const Var* weight, Loaders* loaders) override;
147 
148  void CheckLoaders();
149 
150  private:
151 
152  std::map<int, std::pair<Loaders*, Loaders*> > fLoaders;
153 
154  };
155 
156  // --------------------------------------------------------------------------
158 
159  public:
160 
163 
164  void AddSigma(const Var* weight, int sigma);
165  void AddOnOff(const Var* weight);
166  virtual void MakePredictions(SystPredType predType,
167  const HistAxis* axis, const HistAxis* numuAxis,
168  const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut,
169  const Var* weight, Loaders* loaders) override;
170 
171  private:
172 
173  std::map<int, const Var*> fWeights;
174 
175  };
176 
177  // --------------------------------------------------------------------------
179 
180  public:
181 
183  void AddSigma(SystShifts* syst, int sigma);
184  virtual void MakePredictions(SystPredType predType,
185  const HistAxis* axis, const HistAxis* numuAxis,
186  const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut,
187  const Var* weight, Loaders* loaders) override;
188 
189  private:
190 
191  std::map<int, SystShifts*> fSysts;
192 
193  };
194 
195  // --------------------------------------------------------------------------
196  class SystMaker {
197 
198  public:
199 
201  std::string sample_name = "");
202  ~SystMaker();
203 
204  std::string GetName() { return fName; }
205  std::string GetLabel() { return fLabel; }
206 
207  SystMakerShift* GetShift(std::string shift_name);
208  std::map<std::string, SystMakerShift*> GetShifts() { return fShifts; };
209  std::map<int, std::pair<double, double> > GetTotalShift();
210  std::pair<double, double> GetTotalShift(int sigma);
211  double GetTotalShift(int sigma, bool signal);
212  std::vector<int> GetSigmas();
213  std::map<int, std::pair<TH1*, TH1*> > GetSpectra() { return fSpectra; };
214  IPrediction* GetNominal() { return fNominalPred; };
215 
216  void AddShift(SystMakerShift* shift);
217  void PrintSyst(std::ostream& os = std::cout);
218  TCanvas* DrawSig();
219  TCanvas* DrawBkg();
220  void DrawSyst(TDirectory* outDir);
222  void MakePredictions(SystPredType predType);
223  void ProcessSyst(const covmx::Sample sample, osc::IOscCalc* calc);
224 
225  NuISyst* MakeISyst(covmx::Sample sample);
226 
227  void SetAxes(const HistAxis* axis, const HistAxis* numuAxis = nullptr);
228  void SetCuts(const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut = nullptr);
229  void SetNominalLoaders(Loaders* loaders);
230  void SetNominalWeight(const Var* weight);
231 
232  void SaveTo(TDirectory* dir) const;
233  static std::unique_ptr<SystMaker> LoadFrom(TDirectory* dir);
234 
235  private:
236 
240 
241  std::map<std::string, SystMakerShift*> fShifts;
242  std::map<int, std::pair<TH1*, TH1*> > fSpectra;
243  std::map<int, std::pair<double, double> > fTotalShifts;
244 
245  const HistAxis *fAxis, *fNuMuAxis;
246  const Cut *fNDCut, *fFDCut, *fNuMuCut;
248  const Var* fWeight;
249 
251 
252  };
253 
254  // --------------------------------------------------------------------------
256 
257  public:
258 
260  ~SystematicsMaker();
261 
262  std::string Name() { return fName; }
263 
264  void AddSystematic(SystMaker* syst);
265  std::map<std::string, SystMaker*> GetSystMakers()
266  { return fSystMakers; };
267 
268  void Go(const covmx::Sample sample, osc::IOscCalc* calc);
269 
270  void SetAxes(const HistAxis* axis, const HistAxis* numuAxis = nullptr);
271  void SetCuts(const Cut* fd_cut, const Cut* nd_cut, const Cut* numu_cut = nullptr);
272  void SetNominalLoaders(Loaders* loader, Loaders* loader_light = nullptr);
273  void SetNominalWeight(const Var* weight);
274 
275  std::vector<std::string> GetSystematicsNames();
276  std::vector<NuISyst*> MakeISysts();
277 
278  void DrawSysts(TDirectory* outDir);
279  void PrintSysts(std::ostream& os = std::cout);
280 
281  void Add(SystematicsMaker* systMaker, bool overwrite);
282  void SaveTo(TDirectory* dir, bool separate = false) const;
283  static std::unique_ptr<SystematicsMaker> LoadFrom(TDirectory* dir);
284 
285  private:
286 
289 
290  std::map<std::string, SystMaker*> fSystMakers;
291 
292  const HistAxis *fAxis, *fNuMuAxis;
293  const Cut *fNDCut, *fFDCut, *fNuMuCut;
296  const Var* fWeight;
298 
299  };
300 
301 } // namespace ana
const XML_Char * name
Definition: expat.h:151
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::map< int, std::pair< double, double > > fTotalShifts
Definition: SystMaker.h:243
void SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
std::map< int, const Var * > fWeights
Definition: SystMaker.h:173
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
const HistAxis * fNuMuAxis
Definition: SystMaker.h:245
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
IPrediction * fNominalPred
Definition: SystMaker.h:250
std::string GetLabel()
Definition: SystMaker.h:205
std::pair< TH1 *, TH1 * > fShiftedRatio
Definition: SystMaker.h:82
const covmx::Sample NCSample(covmx::Selection::kNC, covmx::Polarity::kNoPol, covmx::Detector::kNoDet)
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
Adapt the PMNS_Sterile calculator to standard interface.
void WriteTable(double CosRejCosmInt, double CosRejMontInt, std::pair< TH1D *, TH1D * > Data, std::pair< TH1D *, TH1D * > Mont, std::string Name)
std::string fSampleName
Definition: SystMaker.h:239
osc::OscCalcDumb calc
TH1 * GetSpectrum(IPrediction *pred, bool signal, const Sample sample, IOscCalc *calc)
Definition: SystMaker.cxx:78
std::unique_ptr< T > LoadFrom(TDirectory *dir, const std::string &label)
Definition: LoadFromFile.h:17
std::string outDir
const Var * fWeight
Definition: SystMaker.h:296
const char * label
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
std::string GetName()
Definition: SystMaker.h:100
std::string fName
Definition: SystMaker.h:287
std::map< int, std::pair< Loaders *, Loaders * > > fLoaders
Definition: SystMaker.h:152
Loaders * fLightLoaders
Definition: SystMaker.h:295
IPrediction * GetNominal()
Definition: SystMaker.h:214
SystPredType fPredType
Definition: SystMaker.h:288
SystShifts GetShift(TString systName, double sigma)
covmx::Sample fSample
Definition: SystMaker.h:297
std::string GetName()
Definition: SystMaker.h:204
std::string GetLabel()
Definition: SystMaker.h:101
IPrediction * fPrediction
Definition: SystMaker.h:80
const HistAxis * fNuMuAxis
Definition: SystMaker.h:292
loader
Definition: demo0.py:10
std::string fName
Definition: SystMaker.h:126
std::pair< double, double > fShift
Definition: SystMaker.h:83
std::string fLabel
Definition: SystMaker.h:127
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
std::map< int, std::pair< TH1 *, TH1 * > > GetSpectra()
Definition: SystMaker.h:213
void MakeISysts(std::string nd_path="/nova/data/users/jhewes15/nus19/systmakers/neardet", std::string nd_file="systsmaker_nc_fhc_2019.root", std::string fd_path="/nova/data/users/jhewes15/nus19/systmakers/fardet", std::string fd_file="systsmaker_nc_fhc_2019.root")
Definition: MakeISysts.C:14
std::map< std::string, SystMaker * > fSystMakers
Definition: SystMaker.h:290
std::string fName
Definition: SystMaker.h:237
TString MakeLatexCommandName(TString mystring)
std::pair< TH1 *, TH1 * > fShiftedSpectrum
Definition: SystMaker.h:81
const Var * fWeight
Definition: SystMaker.h:248
TDirectory * dir
Definition: macro.C:5
std::map< std::string, SystMaker * > GetSystMakers()
Definition: SystMaker.h:265
std::vector< Loaders * > loaders
Definition: syst_header.h:386
std::map< std::string, SystMakerShift * > GetShifts()
Definition: SystMaker.h:208
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
const Cut * fNuMuCut
Definition: SystMaker.h:246
IPrediction * GetPrediction(SystPredType predType, const HistAxis *axis, const HistAxis *numuAxis, const Cut *FDCut, const Cut *NDCut, const Cut *numuCut, const SystShifts *shiftData, const SystShifts *shiftMC, const Var *weight, Loaders *loaders, Loaders *loadersND)
Definition: SystMaker.cxx:44
Loaders * fLoaders
Definition: SystMaker.h:247
void AddShift(TH1D *hUniv, double &shift, TH1D *hIncv, TH1D *hSystIn)
std::string Name()
Definition: SystMaker.h:262
std::string fLabel
Definition: SystMaker.h:238
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
void SetCuts(std::vector< covmx::Sample > &samples)
Definition: Utilities.h:309
const Cut * fNuMuCut
Definition: SystMaker.h:293
SystPredType
Definition: SystMaker.h:39
std::map< int, SystShifts * > fSysts
Definition: SystMaker.h:191
const covmx::Sample NullSample(covmx::Selection::kNoSel, covmx::Polarity::kNoPol, covmx::Detector::kNoDet)
enum BeamMode string