SystsPPFXAna17.C
Go to the documentation of this file.
4 
5 using namespace ana;
6 
7 void PlotSysts(TH1* nom, TH1* hup, TH1* hdn, TH1* hsx,
8  TDirectory* rootOUT, FILE* textOFS,
9  strings strs);
10 
12  {
13  char pot[3];
14  sprintf(pot, "%d", i);
15  std::string potStr = std::string(pot);
16 
17  return potStr;
18  }
19 
20 
22 {
23  TH1::AddDirectory(0);
24  double NCSCALE =8.85e20;
25 
26  // A map of systematic labels
27 /* std::map<std::string, std::string> shiftlabels;
28  shiftlabels["CalFlat095"] = "Flat Miscalibration Down";
29  shiftlabels["CalFlat105"] = "Flat Miscalibration Up";
30  shiftlabels["CalShape"] = "Calibration shape";
31 */
32  std::string labelRecoE = "Energy Deposited in Scintillator (GeV)";
33  std::vector<std::string> cut_samples;
34  cut_samples.push_back("Ana01");
35 
36 
37  // Set up maps to the decompositions/predictions (each flavor component)
38  // Nominal maps are indexed purely by sample label
39  // Shifted maps are indexed by sample label, systematic label, then sigma of the shift
40  std::map<std::string, IDecomp*> decomps_nominal;
41  std::map<std::string, std::map<std::string, std::map<int, IDecomp*> > > decomps_shifted;
42  std::map<std::string, PredictionNoExtrap*> predsNE_nominal;
43  std::map<std::string, std::map<std::string, std::map<int, PredictionNoExtrap*> > > predsNE_shifted;
44  std::map<std::string, PredictionSterile*> predsSt_nominal;
45  std::map<std::string, std::map<std::string, std::map<int, PredictionSterile*> > > predsSt_shifted;
46 
47  std::vector<IDecomp*> decomps_shifted_Idx;
48  std::vector<PredictionNoExtrap*> predsNE_shifted_Idx;
49  std::vector<PredictionSterile*> predsSt_shifted_Idx;
50 
51 
52  std::string folder1="./";
53  std::string folder = "/nova/ana/users/sedayath/CAFAna_work_place/job/NUS17/Syst/Test/";
54  std::string filenm = "ppfx_ndtest";
55 
56  std::string loadLocation = folder + filenm + ".root";
57  std::string saveLocation = folder1 + filenm + "1Ana.root";
58  std::string textLocation = folder1 + filenm + "1Ana.txt";
59 
60  TFile* rootL = new TFile(loadLocation.c_str(), "READ");
61  // std::cout << "Before loading maps"<<std::endl;
62 
63  LoadMaps(rootL, &decomps_nominal, &decomps_shifted);
64  LoadMaps(rootL, &predsNE_nominal, &predsNE_shifted);
65 // std::cout << "Before loading maps 1"<<std::endl;
66 
67  LoadMaps(rootL, &predsSt_nominal, &predsSt_shifted);
68  std::cout << "Before loading maps 2"<<std::endl;
69 
70  rootL->Close();
71 
72  std::cout << "Opened file "<<std::endl;
73 
74  TFile* rootF = new TFile(saveLocation.c_str(), "RECREATE");
75  FILE* textF;
76  textF = fopen(textLocation.c_str(), "w");
77 
78  for(const auto& sample : cut_samples) {
79  strings strs;
80  strs.fComponent = "NC";
81  strs.fDet = "ND";
82  strs.fPOT = StringFromDouble(NCSCALE);
83  strs.fSample = sample;
84  strs.fSystType = "PPFX";
85  strs.fXLabel = labelRecoE;
86  //double NCSCALE =9e20;
87  InitializeSystText(textF, strs);
88 
89  std::cout << "DECOMP NOMINAL "<<decomps_nominal[sample] <<std::endl;
90 
91  TH1* hNomNC_decomp = GetNC(decomps_nominal[sample], NCSCALE);
92  TH1* hNomBG_decomp = GetBG(decomps_nominal[sample], NCSCALE);
93 
94  TH1* hNomNC_predNE = GetNC(predsNE_nominal[sample], NCSCALE);
95  TH1* hNomBG_predNE = GetBG(predsNE_nominal[sample], NCSCALE);
96 
97  TH1* hNomNC_predSt = GetNC(predsSt_nominal[sample], NCSCALE);
98  TH1* hNomBG_predSt = GetBG(predsSt_nominal[sample], NCSCALE);
99 
100  std::cout << "Opened file 2"<<std::endl;
101 
102 
103  for(int Idx=0; Idx<100 ;++Idx) {
105  decomps_shifted_Idx.push_back(decomps_shifted[sample][index][1]);
106  predsNE_shifted_Idx.push_back(predsNE_shifted[sample][index][1]);
107  predsSt_shifted_Idx.push_back(predsSt_shifted[sample][index][1]);
108 }
109  // std::cout << shifts.first << std::endl;
110  strs.fSystS = "PPFXWGT";
111  strs.fSystL = "PPFX";
112 
113  // Flat systematics MUST be first,
114  // as they are handled with use_max boolean
115  std::cout << "Here 1 "<<std::endl;
116 
117  strs.fComponent = "NC";
118  strs.fDet = "ND";
119  PlotMultiSyst(hNomNC_decomp,
120  decomps_shifted_Idx,
121  rootF, textF, strs, NCSCALE, true, true);
122 
123  strs.fComponent = "BG";
124  PlotMultiSyst(hNomBG_decomp,
125  decomps_shifted_Idx,
126  rootF, textF, strs, NCSCALE, false, true);
127 
128 
129  strs.fComponent = "NC";
130  strs.fDet = "FD";
131  PlotMultiSyst(hNomNC_predNE,
132  predsNE_shifted_Idx,
133  rootF, textF, strs, NCSCALE, true, true);
134 
135  strs.fComponent = "BG";
136  PlotMultiSyst(hNomBG_predNE,
137  predsNE_shifted_Idx,
138  rootF, textF, strs, NCSCALE, false, true);
139 
140 
141  strs.fComponent = "NC";
142  strs.fDet = "EX";
143  PlotMultiSyst(hNomNC_predSt,
144  predsSt_shifted_Idx,
145  rootF, textF, strs, NCSCALE, true, true);
146 
147 
148  strs.fComponent = "BG";
149  PlotMultiSyst(hNomBG_predSt,
150  predsSt_shifted_Idx,
151  rootF, textF, strs, NCSCALE, false, true);
152  }
153 
154 
155  fclose(textF);
156  rootF->Close();
157 
158  std::cout << "Finished. Ctrl+Z should be safe if the macro didn't quit." << std::endl;
159 }
std::string fDet
Definition: PPFXHelper.h:104
void SystsPPFXAna17()
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void PlotMultiSyst(TH1 *h, std::vector< TH1 * > hp, TDirectory *out, FILE *text, strings strs)
Plot multiple systematics.
Definition: PPFXHelper.h:464
std::string fComponent
Definition: PPFXHelper.h:103
void PlotSysts(TH1 *nom, TH1 *hup, TH1 *hdn, TH1 *hsx, TDirectory *rootOUT, FILE *textOFS, strings strs)
TH1 * GetNC(IDecomp *specs, double POT)
Definition: PPFXHelper.h:211
fclose(fg1)
std::string StringFromInt1(int i)
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
#define pot
std::string fPOT
Definition: PPFXHelper.h:105
OStream cout
Definition: OStream.cxx:6
std::string fXLabel
Definition: PPFXHelper.h:110
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