SystsMCStatsAna.C
Go to the documentation of this file.
4 
5 using namespace ana;
6 
7 void DivideErrorByN(TH1* h, int n_samples);
8 
10 {
11  TH1::AddDirectory(0);
12 
13  // A map of systematic labels
14  std::map<std::string, std::string> shiftlabels;
15  shiftlabels["Set1"] = "Set 1";
16  shiftlabels["Set2"] = "Set 2";
17  shiftlabels["Set3"] = "Set 3";
18  shiftlabels["Set4"] = "Set 4";
19 
20  std::string labelRecoE = "Calorimetric Energy (GeV)";
21  std::vector<std::string> cut_samples;
22  cut_samples.push_back("Ana01");
23 
24  // Set up maps to the decompositions/predictions (each flavor component)
25  // Nominal maps are indexed purely by sample label
26  // Shifted maps are indexed by sample label, systematic label, then sigma of the shift
27  std::map<std::string, IDecomp*> decomps_nominal;
28  std::map<std::string, std::map<std::string, std::map<int, IDecomp*> > > decomps_shifted;
29  std::map<std::string, PredictionNoExtrap*> predsNE_nominal;
30  std::map<std::string, std::map<std::string, std::map<int, PredictionNoExtrap*> > > predsNE_shifted;
31  std::map<std::string, PredictionSterile*> predsSt_nominal;
32  std::map<std::string, std::map<std::string, std::map<int, PredictionSterile*> > > predsSt_shifted;
33 
34  std::string folder = "/nova/ana/steriles/Ana01/Systematics/";
35  std::string filenm = "SystsMCStats";
36 
37  std::string loadLocation = folder + filenm + ".root";
38  std::string saveLocation = folder + filenm + "Ana.root";
39  std::string textLocation = folder + filenm + "Ana.txt";
40 
41  TFile* rootL = new TFile(loadLocation.c_str(), "READ");
42  LoadMaps(rootL, &decomps_nominal, &decomps_shifted);
43  LoadMaps(rootL, &predsNE_nominal, &predsNE_shifted);
44  LoadMaps(rootL, &predsSt_nominal, &predsSt_shifted);
45  rootL->Close();
46 
47  TFile* rootF = new TFile(saveLocation.c_str(), "RECREATE");
48  FILE* textF;
49  textF = fopen(textLocation.c_str(), "w");
50 
51  for(const auto& sample : cut_samples) {
52  strings strs;
53  strs.fComponent = "NC";
54  strs.fDet = "ND";
56  strs.fSample = sample;
57  strs.fSystType = "MCStats";
58  strs.fXLabel = labelRecoE;
59 
60  InitializeSystText(textF, strs);
61 
62  TH1* hNomNC_decomp = GetNC(decomps_nominal[sample], NCSCALE);
63  TH1* hNomBG_decomp = GetBG(decomps_nominal[sample], NCSCALE);
64 
65  TH1* hNomNC_predNE = GetNC(predsNE_nominal[sample], NCSCALE);
66  TH1* hNomBG_predNE = GetBG(predsNE_nominal[sample], NCSCALE);
67 
68  TH1* hNomNC_predSt = GetNC(predsSt_nominal[sample], NCSCALE);
69  TH1* hNomBG_predSt = GetBG(predsSt_nominal[sample], NCSCALE);
70 
71  for(const auto& shifts : shiftlabels) {
72  strs.fSystS = shifts.first;
73  strs.fSystL = shifts.second;
74 
75  strs.fComponent = "NC";
76  strs.fDet = "ND";
77  PlotSyst(hNomNC_decomp,
78  decomps_shifted[sample][shifts.first][1],
79  rootF, textF, strs, NCSCALE, true, false);
80 
81  strs.fComponent = "BG";
82  PlotSyst(hNomBG_decomp,
83  decomps_shifted[sample][shifts.first][1],
84  rootF, textF, strs, NCSCALE, false, false);
85 
86  strs.fComponent = "NC";
87  strs.fDet = "FD";
88  PlotSyst(hNomNC_predNE,
89  predsNE_shifted[sample][shifts.first][1],
90  rootF, textF, strs, NCSCALE, true, false);
91 
92  strs.fComponent = "BG";
93  PlotSyst(hNomBG_predNE,
94  predsNE_shifted[sample][shifts.first][1],
95  rootF, textF, strs, NCSCALE, false, false);
96 
97  strs.fComponent = "NC";
98  strs.fDet = "EX";
99  PlotSyst(hNomNC_predSt,
100  predsSt_shifted[sample][shifts.first][1],
101  rootF, textF, strs, NCSCALE, true, false);
102 
103  strs.fComponent = "BG";
104  PlotSyst(hNomBG_predSt,
105  predsSt_shifted[sample][shifts.first][1],
106  rootF, textF, strs, NCSCALE, false, false);
107  }
108 
109  int n_samples = shiftlabels.size();
110  std::cout << n_samples << std::endl;
111 
112  strs.fComponent = "NC";
113  strs.fDet = "ND";
114  DivideErrorByN(hNomNC_decomp, n_samples);
115  PlotSystBand(hNomNC_decomp, rootF, textF, strs);
116 
117  strs.fComponent = "BG";
118  DivideErrorByN(hNomBG_decomp, n_samples);
119  PlotSystBand(hNomBG_decomp, rootF, textF, strs);
120 
121  strs.fComponent = "NC";
122  strs.fDet = "FD";
123  DivideErrorByN(hNomNC_predNE, n_samples);
124  PlotSystBand(hNomNC_predNE, rootF, textF, strs);
125 
126  strs.fComponent = "BG";
127  DivideErrorByN(hNomBG_predNE, n_samples);
128  PlotSystBand(hNomBG_predNE, rootF, textF, strs);
129 
130  strs.fComponent = "NC";
131  strs.fDet = "EX";
132  DivideErrorByN(hNomNC_predSt, n_samples);
133  PlotSystBand(hNomNC_predSt, rootF, textF, strs);
134 
135  strs.fComponent = "BG";
136  DivideErrorByN(hNomBG_predSt, n_samples);
137  PlotSystBand(hNomBG_predSt, rootF, textF, strs);
138  }
139 
140  fclose(textF);
141  rootF->Close();
142 
143  std::cout << "Finished. Ctrl+Z should be safe if the macro didn't quit." << std::endl;
144 }
145 
146 void DivideErrorByN(TH1* h, int n_samples)
147 {
148  double div = (double)n_samples;
149  for(int i=0, n=h->GetNbinsX(); i <= n+1; ++i) {
150  h->SetBinError(i, h->GetBinError(i)/div);
151  }
152 }
std::string fDet
Definition: PPFXHelper.h:104
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::string fComponent
Definition: PPFXHelper.h:103
void DivideErrorByN(TH1 *h, int n_samples)
void PlotSyst(TH1 *h, TH1 *hp1, TH1 *hm1, TH1 *hp2, TH1 *hm2, TDirectory *out, FILE *text, strings strs)
Definition: PPFXHelper.h:662
TH1 * GetNC(IDecomp *specs, double POT)
Definition: PPFXHelper.h:211
fclose(fg1)
void InitializeSystText(FILE *text, strings strs)
Print some initial text about a systematic – the systematic type and sample.
Definition: PPFXHelper.h:263
std::string fSystL
Definition: PPFXHelper.h:109
std::string fPOT
Definition: PPFXHelper.h:105
OStream cout
Definition: OStream.cxx:6
void PlotSystBand(TH1 *h, TDirectory *out, FILE *text, strings strs)
Definition: PPFXHelper.h:968
std::string fXLabel
Definition: PPFXHelper.h:110
void SystsMCStatsAna()
std::string fSystType
Definition: PPFXHelper.h:107
std::string fSystS
Definition: PPFXHelper.h:108
void LoadMaps(TDirectory *dir, std::map< std::string, IDecomp * > *nominal, std::map< std::string, std::map< std::string, std::map< int, IDecomp * > > > *shifted)
Definition: PPFXHelper.h:273
static double NCSCALE
TH1 * GetBG(IDecomp *specs, double POT)
Definition: PPFXHelper.h:236
std::string StringFromDouble(double pot)
Definition: PPFXHelper.h:128
A helper structure to contain a group of string for plotting.
Definition: PPFXHelper.h:101
std::string fSample
Definition: PPFXHelper.h:106
enum BeamMode string