-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplotall.cxx
285 lines (265 loc) · 10.6 KB
/
plotall.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// TODO:: Change title name to be like e.g ev Jet pt -> v , greek nu
// TODO:: legend should be only ds
// TODO:: change the mass unit \\text{W m_{T} (GeV/}c^{2}) doesn't work!
// TODO:: add more histograms for filtred mass and angles.
#include <ROOT/RDataFrame.hxx>// big guns
#include <TCanvas.h>
#include <TLegend.h>
#include <THStack.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TF1.h>
#include <iterator>// just for std::size
#include "src/tdrstyle.C"
//#include "src/calchisto.hpp"
enum channel {elnu,munu};
constexpr channel
channelAll[]={elnu,munu};
enum dataSource {tzq,ttz,met,wj,/*ww,wz,zz*/vv,st,tw,dy,ttbar,npl,cms};//,wjt,met,st,stb,stw,stbw,ttl,ttj,ttb,cms};
constexpr dataSource
dataSourceAll[]={tzq,ttz,met,wj,/*ww,wz,zz*/vv,st,tw,dy,ttbar,npl,cms};//,wjt,met,st,stb,stw,stbw,ttl,ttj,ttb,cms};
int debug = 1;
std::string allNamesArray[][3] = {// histogram id, histogram title, x axis string
// {"cmet_sEt_", "Corrected MET " "sum E_{T} ","Sum E_{T} (GeV)"}
{ "met_sEt_","Un-corrected MET " "sum E_{T} ","Sum E_{T} (GeV)"}
// ,{"cmet__pt_", "Corrected MET " "p_{T} ","p_{T} (GeV/c)"}
// ,{"cmet_dpx_", "Corrected MET #Delta p_{x} ","p_{x} (GeV/c)"}
// ,{"cmet_dpy_", "Corrected MET #Delta p_{y} ","p_{y} (GeV/c)"}
,{ "met__pt_","Un-corrected MET " "p_{T} ","p_{T} (GeV/c)"}
,{"W_invariant_mass_","W invariant mass ","W\\ m_{ }\\ (\\text{GeV/}c^{2})"}
,{ "tWm_","Transverse W mass ","W\\ m_{T}\\ (\\text{GeV/}c^{2})"}
,{ "tTm_","Transverse T mass ","T\\ m_{T}\\ (\\text{GeV/}c^{2})"}
//,{ "ttop_pt_","Transverse T p_{t}","T\\ p_{T}\\ (Gev)"}
,{ "zmas_", "Recon. Z mass ","Z\\ m_{ }\\ (\\text{GeV/}c^{2})"}
,{ "Z_W_Delta_Phi_", "Z W #Delta#phi ", "Z & W #Delta#phi (rad)"}
,{ "Z_MET_Delta_Phi_", "Z MET #Delta#phi ", "Z & MET #Delta#phi (rad)"}
,{"Z_pair_jets_Delta_Phi_","Z pair jets #Delta#phi ","Z pair jets #Delta#phi (rad)"}
,{"ev_w_", "Event Weight ","Weight"}
,{"nbjet_","Events","Number of bjets"}
};
int plotall(){
gROOT->SetBatch(kTRUE);// no open canvas window
//setTDRStyle();
TFile cf("plots/plotall.root","RECREATE");
TCanvas canv("name to reset","title to reset",10,10,900,900);
TH1D *hobj;
// now we open ALL the files
std::map<std::pair<channel,dataSource>,TFile*> hFd;
for(channel ch:channelAll){
//for(channel ch:channelAll){
std::string chN;
switch (ch){
case elnu: {chN ="elnu_";break;}
case munu: {chN ="munu_";break;}
}
for(dataSource ds:dataSourceAll){
std::string opener = chN ;
switch (ds){
case tzq:{opener += "tzq";break;}
case vv:{opener += "_vv";break;}
// case ww:{opener += "_ww";break;}
// case wz:{opener += "_wz";break;}
// case zz:{opener += "_zz";break;}
case st:{opener += "_ST";break;}
case ttz:{opener += "ttz";break;}
case ttbar:{opener +="ttbar";break;}
case wj:{opener += "_Wj";break;}
case dy:{opener += "_DY";break;}
case met:{opener += "met";break;}
case cms:{opener += "cms";break;}
case tw:{opener += "_tW";break;}
case npl:{opener ="NPL_run_" + chN;break;}
}
if(debug > 0) std::cout<<ds<<std::endl;
// if(ds != cms){
hFd[std::make_pair(ch,ds)]
= new TFile(("histo/BDT_" + opener + ".root").c_str());
// }else{
// hFd[std::make_pair(ch,ds)]
// = new TFile(("histo/" + opener + ".root").c_str());
// }// if
}}// now we have a histogram file dictionary of all the files miahahaha
for(size_t i=0; i < std::size(allNamesArray) ;++i){
for(channel ch:channelAll){
std::string chN,chF,lgN; // chf : channel title
switch (ch){
case elnu: {chN ="elnu";chF = "e#nu"; break;}
case munu: {chN ="munu";chF ="#mu#nu"; break;}
}// switch
double max = -1;
std::string title = allNamesArray[i][1] + chF;
std::string stname = allNamesArray[i][0] + chN;
canv.SetName(stname.c_str());canv.SetTitle(stname.c_str());
THStack stac(stname.c_str(),title.c_str());
// THStack stad(stname.c_str(),title.c_str());//testing stack for data
TLegend legS = TLegend(0.8,0.6,0.95,0.9);
// legS.SetFillStyle(1001);
// legS.SetBorderSize(1);
// legS.SetFillColor(0);
// legS.SetLineColor(0);
// legS.SetShadowColor(0);
// legS.SetFillColor(kWhite);
// legS.SetTextSize(0.02);
gStyle->SetOptStat(0);
int W = 800, H = 600, H_ref = 600, W_ref = 800;
// references for T, B, L, R
float T = 0.08 * H_ref, B = 0.12 * H_ref,
L = 0.12 * W_ref, R = 0.04 * W_ref;
TPad *pads = new TPad("pad","pad",0.01, 0.315, 0.99, 0.99);//pads = pad stack
pads->SetTopMargin(0);
pads->SetFillColor(0);
pads->SetBorderMode(0);
pads->SetFrameFillStyle(0);
pads->SetFrameBorderMode(0);
pads->SetLeftMargin(L / W);
pads->SetRightMargin(R / W);
pads->SetTopMargin(T / H);
pads->SetBottomMargin(B / H * 0.3);
pads->SetTickx(0);
pads->SetTicky(0);
pads->Draw();
pads->cd();
/* TPad *pad = new TPad("pad", "pad", 0.01, 0.01, 0.99, 0.3275);
pad->SetTopMargin(0);
pad->SetFillColor(0);
pad->SetBorderMode(0);
pad->SetFrameFillStyle(0);
pad->SetFrameBorderMode(0);
pad->SetLeftMargin(L / W);
pad->SetRightMargin(R / W);
pad->SetTopMargin(T / H);
pad->SetBottomMargin(B / H * 2.1);
pad->SetTickx(0);
pad->SetTicky(0);
pad->SetGridy(1);
pad->Draw();
pad->cd();*/
TH1D * rp;
for(dataSource ds:dataSourceAll){
if(met == ds) continue;
std::string opener = chN + "_";
int colour;
switch (ds){
case tzq:{opener += "tzq" ;lgN = "tZq" ;colour = 6 ;break;}// magenta
case vv:{opener += "_vv" ;lgN = "VV " ;colour = 2 ;break;}// red
// case ww:{opener +="_ww" ;lgN = "ww " ;colour = 30 ;break;}
// case wz:{opener +="_wz" ;lgN = "wz " ;colour = 28 ;break;}
// case zz:{opener +="_zz" ;lgN = "zz " ;colour = 46 ;break;}
case st:{opener += "_ST" ;lgN = "Single t" ;colour = 95;break;}//
case ttz:{opener += "ttz" ;lgN = "t#bar{t}Z" ;colour = 5 ;break;}// yellow
case ttbar:{opener += "ttb" ;lgN = "t#bar{t}" ;colour = 7 ;break;}// cyan
case wj:{opener += "_Wj" ;lgN = "W+Jets" ;colour = 55;break;}//
case dy:{opener += "_DY" ;lgN = "Z/#gamma+Jets" ;colour = 79;break;}//
case met:{opener += "met" ;lgN = "MET" ;colour = 9 ;break;}// violet
case cms:{opener += "cms" ;lgN = "data" ;colour = 1 ;break;}// black
case tw:{opener += "_tW" ;lgN = "tW" ;colour = 75;break;}//
case npl:{opener += "NPL";lgN = "NPL" ;colour = 40;break;}
}
std::string hobjN = allNamesArray[i][0] + opener;
hFd[std::make_pair(ch,ds)]->GetObject(hobjN.c_str(), hobj);
//std::cout<< "ds and ch "<<ds<< " "<<ch<<std::endl;
if(debug > 0)std::cout<<"passed make pair "<<hobjN<<std::endl;
hobj->SetDirectory(nullptr);
if(debug > 0)std::cout<<"passed setDir"<<std::endl;
//if(hobj->GetMaximum() > max) max = hobj->GetMaximum( );
if(debug > 0)std::cout<<"passed get max"<<std::endl;
// note that MET is already skipped above
// WARNING: We require CMS to be the last thing in dataSourceAll !
if( cms != ds ){
//hobj->Scale(1./(9*hobj->Integral()));
hobj->Scale(2.0);
hobj->SetFillColor(colour);
stac .Add(hobj);
legS .AddEntry(hobj,lgN.c_str(),"f");
}else{// CMS is last, so we plot at this time!
// canv .cd();// pick me to draw?
TH1F *lsh = new TH1F(*((TH1F *)(stac.GetStack()->Last())));
max = lsh ->GetMaximum();
stac .Draw("HIST");// TODO: histe
stac .GetXaxis()->SetTitle(allNamesArray[i][2].c_str());
stac .GetYaxis()->SetTitle("Event");
stac .SetMaximum(max*1.2);// now plot is set, plot CMS on it
hobj->SetLineColor( colour);
hobj->SetMarkerColor(colour);
hobj->SetMarkerStyle(20);
hobj->SetMarkerSize(1.0);
legS .AddEntry(hobj,lgN.c_str(),"lep");
//hobj->Scale(1./hobj->Integral());
hobj->Draw("E0 SAME");
legS .Draw();
rp = (TH1D*)(hobj->Clone());
}}// else & dataSource
rp->Divide((TH1D*)stac.GetStack()->Last());
TPad *padr = new TPad("pad", "pad", 0.01, 0.01, 0.99, 0.2800);// padr = pad ratio
padr->SetTopMargin(0);
padr->SetFillColor(0);
padr->SetBorderMode(0);
padr->SetFrameFillStyle(0);
padr->SetFrameBorderMode(0);
padr->SetLeftMargin(L / W);
padr->SetRightMargin(R / W);
padr->SetTopMargin(T / H);
padr->SetBottomMargin(B / H * 2.1);
padr->SetTickx(0);
padr->SetTicky(0);
padr->SetGridy(1);
canv.cd();
padr->Draw();
padr->cd();
rp->Draw();
// canv .BuildLegend();
canv .Update();
cf .WriteTObject(&canv);
// canv .SaveAs(("plots/" + stname + ".root").c_str());// slow
// canv .SaveAs(("plots/" + stname + ".pdf" ).c_str());
legS .Clear();
canv .Clear();// clear rather than delete, reusable!
// stac will auto clean up since it is not new-ed
}}// channel, i
for(auto &x : hFd){
x.second->Close(); x.second = nullptr;
}
hobj = nullptr;
// file cf will automatically close
gROOT->SetBatch(kFALSE);// re-enable TBrowser
return 0;
}
/*
Working legend
TLegend legend_= TLegend(0.8,0.6,0.95,0.9);
legend_.SetFillStyle(1001);
legend_.SetBorderSize(1);
legend_.SetFillColor(0);
legend_.SetLineColor(0);
legend_.SetShadowColor(0);
legend_.SetFillColor(kWhite);
legend_.SetTextSize(0.02);
gStyle->SetOptStat(0);
std :: map<string,string> IdLegend;
IdLegend["BNumHist"]="b quark";
IdLegend["BBarNumHist"]="b bar quark";
for (const auto histId : HistPerCanvas){
TCanvas *tempcanvas = new TCanvas(histId.first.c_str(),histId.first.c_str(),200,10,700,500);
tempcanvas->cd();
int colour = 2;
float max = -1;
for (auto histo : HistPerCanvas[histId.first.c_str()]){
legend_.AddEntry(&IdHist[histo.c_str()],IdLegend[histo.c_str()].c_str(),"l");
if(colour == 10)
{// to get rid of the white colour graph in the plots
colour++;
}// to get rid of the white colour graph in the plots
IdHist[histo.c_str()].SetLineColor(colour);
colour++;
IdHist[histo.c_str()].Draw("same");
IdHist[histo.c_str()].GetXaxis()->SetTitle(histId.first.c_str());
IdHist[histo.c_str()].GetYaxis()->SetTitle("Number of events");
if (IdHist[histo.c_str()].GetMaximum() > max) max = IdHist[histo.c_str()].GetMaximum();
}
IdHist[HistPerCanvas[histId.first.c_str()][0].c_str()].SetMaximum(max*1.2);
legend_.Draw();
tempcanvas->SaveAs(("/scratch/eepgssg/plots/plots2017/tZq_lnu_Z_qq_4f/PtEtaECut/"+histId.first+".root").c_str());
tempcanvas->SaveAs(("/scratch/eepgssg/plots/plots2017/tZq_lnu_Z_qq_4f/PtEtaECut/"+histId.first+".png").c_str());
legend_.Clear();
}
*/