pidPlotProng.C
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <sstream>
4 #include <algorithm>
5 #include <math.h>
6 #include <stdlib.h>
7 #include <string>
8 
9 #include "TChain.h"
10 #include "TROOT.h"
11 #include "TStyle.h"
12 #include "TLegend.h"
13 
14 #include "TH1D.h"
15 #include "TH2D.h"
16 #include "TLatex.h"
17 #include "TCanvas.h"
18 
19 void pidPlotProng(string input) {
20  gROOT->ForceStyle();
21 
22  TChain *ch=new TChain("t");
23  ch->SetMakeClass(1); //<===== important
24  ch->Add(input.c_str());
25 
26  int truelabelall=0;
27  double proton=0;
28  double pion=0;
29  double muon=0;
30  double electron=0;
31  double gamma=0;
32 
33  ch->SetBranchAddress("truelabelall",&truelabelall);
34  ch->SetBranchAddress("proton",&proton);
35  ch->SetBranchAddress("pion",&pion);
36  ch->SetBranchAddress("muon",&muon);
37  ch->SetBranchAddress("electron",&electron);
38  ch->SetBranchAddress("gamma",&gamma);
39 
40 
41  TH1D *protonPID_proton= new TH1D( "protonPID_proton", "", 50,0,1);
42  TH1D *protonPID_pion= new TH1D( "protonPID_pion", "", 50,0,1);
43  TH1D *protonPID_muon= new TH1D( "protonPID_muon", "", 50,0,1);
44  TH1D *protonPID_electron= new TH1D( "protonPID_electron", "", 50,0,1);
45  TH1D *protonPID_gamma= new TH1D( "protonPID_gamma", "", 50,0,1);
46 
47  TH1D *pionPID_proton= new TH1D( "pionPID_proton", "", 50,0,1);
48  TH1D *pionPID_pion= new TH1D( "pionPID_pion", "", 50,0,1);
49  TH1D *pionPID_muon= new TH1D( "pionPID_muon", "", 50,0,1);
50  TH1D *pionPID_electron= new TH1D( "pionPID_electron", "", 50,0,1);
51  TH1D *pionPID_gamma= new TH1D( "pionPID_gamma", "", 50,0,1);
52 
53  TH1D *electronPID_proton= new TH1D( "electronPID_proton", "", 50,0,1);
54  TH1D *electronPID_pion= new TH1D( "electronPID_pion", "", 50,0,1);
55  TH1D *electronPID_muon= new TH1D( "electronPID_muon", "", 50,0,1);
56  TH1D *electronPID_electron= new TH1D( "electronPID_electron", "", 50,0,1);
57  TH1D *electronPID_gamma= new TH1D( "electronPID_gamma", "", 50,0,1);
58 
59  TH1D *gammaPID_proton= new TH1D( "gammaPID_proton", "", 50,0,1);
60  TH1D *gammaPID_pion= new TH1D( "gammaPID_pion", "", 50,0,1);
61  TH1D *gammaPID_muon= new TH1D( "gammaPID_muon", "", 50,0,1);
62  TH1D *gammaPID_electron= new TH1D( "gammaPID_electron", "", 50,0,1);
63  TH1D *gammaPID_gamma= new TH1D( "gammaPID_gamma", "", 50,0,1);
64 
65  TH1D *muonPID_proton= new TH1D( "muonPID_proton", "", 50,0,1);
66  TH1D *muonPID_pion= new TH1D( "muonPID_pion", "", 50,0,1);
67  TH1D *muonPID_muon= new TH1D( "muonPID_muon", "", 50,0,1);
68  TH1D *muonPID_electron= new TH1D( "muonPID_electron", "", 50,0,1);
69  TH1D *muonPID_gamma= new TH1D( "muonPID_gamma", "", 50,0,1);
70 
71  //heatmap->SetBit(TH1::kCanRebin);
72  Int_t nevent =ch->GetEntries();
73  for(Int_t i=0;i<nevent;i++){
74  ch->GetEntry(i);
75  if(truelabelall==2){
76  protonPID_proton->Fill(proton);
77  pionPID_proton->Fill(pion);
78  electronPID_proton->Fill(electron);
79  gammaPID_proton->Fill(gamma);
80  muonPID_proton->Fill(muon);
81  }
82  if(truelabelall==4){
83  protonPID_pion->Fill(proton);
84  pionPID_pion->Fill(pion);
85  electronPID_pion->Fill(electron);
86  gammaPID_pion->Fill(gamma);
87  muonPID_pion->Fill(muon);
88  }
89  if(truelabelall==1){
90  protonPID_muon->Fill(proton);
91  pionPID_muon->Fill(pion);
92  electronPID_muon->Fill(electron);
93  gammaPID_muon->Fill(gamma);
94  muonPID_muon->Fill(muon);
95  }
96  if(truelabelall==0){
97  protonPID_electron->Fill(proton);
98  pionPID_electron->Fill(pion);
99  electronPID_electron->Fill(electron);
100  gammaPID_electron->Fill(gamma);
101  muonPID_electron->Fill(muon);
102  }
103  if(truelabelall==6){
104  protonPID_gamma->Fill(proton);
105  pionPID_gamma->Fill(pion);
106  electronPID_gamma->Fill(electron);
107  gammaPID_gamma->Fill(gamma);
108  muonPID_gamma->Fill(muon);
109  }
110  }
111 
112  string title="protonID";
113 
114  TCanvas c1("c1",title.c_str(),1400,1000);
115 
116  protonPID_proton->SetTitle("");
117  protonPID_proton->SetXTitle("Proton PID");
118  protonPID_proton->SetYTitle("Test Sample Events");
119  protonPID_proton->GetXaxis()->CenterTitle();
120  protonPID_proton->GetYaxis()->CenterTitle();
121 
122  protonPID_proton->SetLineWidth(3);
123  protonPID_pion->SetLineWidth(3);
124  protonPID_muon->SetLineWidth(3);
125  protonPID_electron->SetLineWidth(3);
126  protonPID_gamma->SetLineWidth(3);
127 
128  protonPID_proton->SetLineColor(kRed);
129  protonPID_pion->SetLineColor(kOrange-3);
130  protonPID_muon->SetLineColor(kAzure-2);
131  protonPID_electron->SetLineColor(kSpring-8);
132  protonPID_gamma->SetLineColor(kPink+6);
133 
134 
135  protonPID_proton->GetYaxis()->SetTitleSize(0.05);
136  protonPID_proton->GetXaxis()->SetTitleSize(0.06);
137  protonPID_proton->GetYaxis()->SetLabelSize(.03);
138  protonPID_proton->GetXaxis()->SetLabelSize(.03);
139  protonPID_proton->GetYaxis()->SetTitleOffset(1.5);
140  protonPID_proton->GetXaxis()->SetTitleOffset(0.7);
141 
142 
143  protonPID_proton->Scale(1/protonPID_proton->Integral());
144  protonPID_proton->GetYaxis()->SetRangeUser(0.000001,.999999);
145  protonPID_proton->Draw("hist");
146  protonPID_pion->Scale(1/protonPID_pion->Integral());
147  protonPID_pion->Draw("histsame");
148  protonPID_muon->Scale(1/protonPID_muon->Integral());
149  protonPID_muon->Draw("histsame");
150  protonPID_electron->Scale(1/protonPID_electron->Integral());
151  protonPID_electron->Draw("histsame");
152  protonPID_gamma->Scale(1/protonPID_gamma->Integral());
153  protonPID_gamma->Draw("histsame");
154  gPad->RedrawAxis();
155 
156  TLegend *mylegend = new TLegend(0.4,0.67,0.6,0.87);
157  mylegend->AddEntry(protonPID_proton,"Proton","L");
158  mylegend->AddEntry(protonPID_pion,"Pion","L");
159  mylegend->AddEntry(protonPID_muon,"Muon","L");
160  mylegend->AddEntry(protonPID_electron,"Electron","L");
161  mylegend->AddEntry(protonPID_gamma,"Gamma","L");
162  mylegend->SetFillStyle(0);
163  mylegend->Draw("same");
164 
165  TLatex *prelim = new TLatex(0.1, 0.93, "Particle Only");
166  prelim->SetNDC();
167  prelim->SetTextSize(1/30.);
168  prelim->SetTextAlign(11);
169  prelim->Draw();
170 
171 // Simulation();
172 
173  c1.SetLogy();
174 
175  string output = "plots/"+title+".pdf";
176  c1.Print(output.c_str());
177  output = "plots/"+title+".C";
178  c1.Print(output.c_str());
179  output = "plots/"+title+".eps";
180  c1.Print(output.c_str());
181 
182  ////////////
183 
184  string title2="pionID";
185 
186  TCanvas c2("c2",title2.c_str(),1400,1000);
187 
188  pionPID_pion->SetTitle("");
189  pionPID_pion->SetXTitle("Pion PID");
190  pionPID_pion->SetYTitle("Test Sample Events");
191  pionPID_pion->GetXaxis()->CenterTitle();
192  pionPID_pion->GetYaxis()->CenterTitle();
193 
194  pionPID_proton->SetLineWidth(3);
195  pionPID_pion->SetLineWidth(3);
196  pionPID_muon->SetLineWidth(3);
197  pionPID_electron->SetLineWidth(3);
198  pionPID_gamma->SetLineWidth(3);
199 
200  pionPID_proton->SetLineColor(kRed);
201  pionPID_pion->SetLineColor(kOrange-3);
202  pionPID_muon->SetLineColor(kAzure-2);
203  pionPID_electron->SetLineColor(kSpring-8);
204  pionPID_gamma->SetLineColor(kPink+6);
205 
206  pionPID_pion->GetYaxis()->SetTitleSize(0.05);
207  pionPID_pion->GetXaxis()->SetTitleSize(0.06);
208  pionPID_pion->GetYaxis()->SetLabelSize(.03);
209  pionPID_pion->GetXaxis()->SetLabelSize(.03);
210  pionPID_pion->GetYaxis()->SetTitleOffset(1.5);
211  pionPID_pion->GetXaxis()->SetTitleOffset(0.7);
212 
213  pionPID_pion->Scale(1/pionPID_pion->Integral());
214  pionPID_pion->GetYaxis()->SetRangeUser(0.00001,.99999);
215  pionPID_pion->Draw("hist");
216  pionPID_proton->Scale(1/pionPID_proton->Integral());
217  pionPID_proton->Draw("histsame");
218  pionPID_muon->Scale(1/pionPID_muon->Integral());
219  pionPID_muon->Draw("histsame");
220  pionPID_electron->Scale(1/pionPID_electron->Integral());
221  pionPID_electron->Draw("histsame");
222  pionPID_gamma->Scale(1/pionPID_gamma->Integral());
223  pionPID_gamma->Draw("histsame");
224  gPad->RedrawAxis();
225  mylegend->Draw("same");
226  prelim->Draw("same");
227 // Simulation();
228  c2.SetLogy();
229  string output2 = "plots/"+title2+".pdf";
230  c2.Print(output2.c_str());
231  output2 = "plots/"+title2+".C";
232  c2.Print(output2.c_str());
233  output2 = "plots/"+title2+".eps";
234  c2.Print(output2.c_str());
235 
236  ////////////
237 
238  string title3="electronID";
239 
240  TCanvas c3("c3",title3.c_str(),1400,1000);
241 
242  electronPID_electron->SetTitle("");
243  electronPID_electron->SetXTitle("Electron PID");
244  electronPID_electron->SetYTitle("Test Sample Events");
245  electronPID_electron->GetXaxis()->CenterTitle();
246  electronPID_electron->GetYaxis()->CenterTitle();
247 
248  electronPID_proton->SetLineWidth(3);
249  electronPID_pion->SetLineWidth(3);
250  electronPID_muon->SetLineWidth(3);
251  electronPID_electron->SetLineWidth(3);
252  electronPID_gamma->SetLineWidth(3);
253 
254  electronPID_proton->SetLineColor(kRed);
255  electronPID_pion->SetLineColor(kOrange-3);
256  electronPID_muon->SetLineColor(kAzure-2);
257  electronPID_electron->SetLineColor(kSpring-8);
258  electronPID_gamma->SetLineColor(kPink+6);
259 
260  electronPID_electron->GetYaxis()->SetTitleSize(0.05);
261  electronPID_electron->GetXaxis()->SetTitleSize(0.06);
262  electronPID_electron->GetYaxis()->SetLabelSize(.03);
263  electronPID_electron->GetXaxis()->SetLabelSize(.03);
264  electronPID_electron->GetYaxis()->SetTitleOffset(1.5);
265  electronPID_electron->GetXaxis()->SetTitleOffset(0.7);
266 
267 
268  electronPID_electron->Scale(1/electronPID_electron->Integral());
269  electronPID_electron->GetYaxis()->SetRangeUser(0.00001,.99999);
270  electronPID_electron->Draw("hist");
271  electronPID_proton->Scale(1/electronPID_proton->Integral());
272  electronPID_proton->Draw("histsame");
273  electronPID_muon->Scale(1/electronPID_muon->Integral());
274  electronPID_muon->Draw("histsame");
275  electronPID_pion->Scale(1/electronPID_pion->Integral());
276  electronPID_pion->Draw("histsame");
277  electronPID_gamma->Scale(1/electronPID_gamma->Integral());
278  electronPID_gamma->Draw("histsame");
279  gPad->RedrawAxis();
280  mylegend->Draw("same");
281  prelim->Draw("same");
282 // Simulation();
283  c3.SetLogy();
284  string output3 = "plots/"+title3+".pdf";
285  c3.Print(output3.c_str());
286  output3 = "plots/"+title3+".C";
287  c3.Print(output3.c_str());
288  output3 = "plots/"+title3+".eps";
289  c3.Print(output3.c_str());
290 
291  ////////////
292 
293  string title4="gammaID";
294 
295  TCanvas c4("c4",title4.c_str(),1400,1000);
296 
297  gammaPID_gamma->SetTitle("");
298  gammaPID_gamma->SetXTitle("Gamma PID");
299  gammaPID_gamma->SetYTitle("Test Sample Events");
300  gammaPID_gamma->GetXaxis()->CenterTitle();
301  gammaPID_gamma->GetYaxis()->CenterTitle();
302 
303  gammaPID_proton->SetLineWidth(3);
304  gammaPID_pion->SetLineWidth(3);
305  gammaPID_muon->SetLineWidth(3);
306  gammaPID_electron->SetLineWidth(3);
307  gammaPID_gamma->SetLineWidth(3);
308 
309  gammaPID_proton->SetLineColor(kRed);
310  gammaPID_pion->SetLineColor(kOrange-3);
311  gammaPID_muon->SetLineColor(kAzure-2);
312  gammaPID_electron->SetLineColor(kSpring-8);
313  gammaPID_gamma->SetLineColor(kPink+6);
314 
315  gammaPID_gamma->GetYaxis()->SetTitleSize(0.05);
316  gammaPID_gamma->GetXaxis()->SetTitleSize(0.06);
317  gammaPID_gamma->GetYaxis()->SetLabelSize(.03);
318  gammaPID_gamma->GetXaxis()->SetLabelSize(.03);
319  gammaPID_gamma->GetYaxis()->SetTitleOffset(1.5);
320  gammaPID_gamma->GetXaxis()->SetTitleOffset(0.7);
321 
322  gammaPID_gamma->Scale(1/gammaPID_gamma->Integral());
323  gammaPID_gamma->GetYaxis()->SetRangeUser(0.00001,.99999);
324  gammaPID_gamma->Draw("hist");
325  gammaPID_proton->Scale(1/gammaPID_proton->Integral());
326  gammaPID_proton->Draw("histsame");
327  gammaPID_muon->Scale(1/gammaPID_muon->Integral());
328  gammaPID_muon->Draw("histsame");
329  gammaPID_electron->Scale(1/gammaPID_electron->Integral());
330  gammaPID_electron->Draw("histsame");
331  gammaPID_pion->Scale(1/gammaPID_pion->Integral());
332  gammaPID_pion->Draw("histsame");
333  gPad->RedrawAxis();
334  mylegend->Draw("same");
335  prelim->Draw("same");
336 // Simulation();
337  c4.SetLogy();
338  string output4 = "plots/"+title4+".pdf";
339  c4.Print(output4.c_str());
340  output4 = "plots/"+title4+".C";
341  c4.Print(output4.c_str());
342  output4 = "plots/"+title4+".eps";
343  c4.Print(output4.c_str());
344 
345  string title5="muonID";
346 
347  TCanvas c5("c5",title5.c_str(),1400,1000);
348 
349  //muonPID_muon->SetTitle("");
350  muonPID_muon->SetXTitle("Muon PID");
351  muonPID_muon->SetYTitle("Test Sample Events");
352  muonPID_muon->GetXaxis()->CenterTitle();
353  muonPID_muon->GetYaxis()->CenterTitle();
354 
355  muonPID_proton->SetLineWidth(3);
356  muonPID_pion->SetLineWidth(3);
357  muonPID_muon->SetLineWidth(3);
358  muonPID_electron->SetLineWidth(3);
359  muonPID_gamma->SetLineWidth(3);
360 
361  muonPID_proton->SetLineColor(kRed);
362  muonPID_pion->SetLineColor(kOrange-3);
363  muonPID_muon->SetLineColor(kAzure-2);
364  muonPID_electron->SetLineColor(kSpring-8);
365  muonPID_gamma->SetLineColor(kPink+6);
366 
367  muonPID_muon->GetYaxis()->SetTitleSize(0.05);
368  muonPID_muon->GetXaxis()->SetTitleSize(0.06);
369  muonPID_muon->GetYaxis()->SetLabelSize(.03);
370  muonPID_muon->GetXaxis()->SetLabelSize(.03);
371  muonPID_muon->GetYaxis()->SetTitleOffset(1.5);
372  muonPID_muon->GetXaxis()->SetTitleOffset(0.7);
373 
374  muonPID_muon->Scale(1/muonPID_muon->Integral());
375  muonPID_muon->GetYaxis()->SetRangeUser(0.00001,.99999);
376  muonPID_muon->Draw("hist");
377  muonPID_proton->Scale(1/muonPID_proton->Integral());
378  muonPID_proton->Draw("histsame");
379  muonPID_gamma->Scale(1/muonPID_gamma->Integral());
380  muonPID_gamma->Draw("histsame");
381  muonPID_electron->Scale(1/muonPID_electron->Integral());
382  muonPID_electron->Draw("histsame");
383  muonPID_pion->Scale(1/muonPID_pion->Integral());
384  muonPID_pion->Draw("histsame");
385  gPad->RedrawAxis();
386  mylegend->Draw("same");
387  prelim->Draw("same");
388 // Simulation();
389  c5.SetLogy();
390 
391  string output5 = "plots/"+title5+".pdf";
392  c5.Print(output5.c_str());
393  output5 = "plots/"+title5+".C";
394  c5.Print(output5.c_str());
395  output5 = "plots/"+title5+".eps";
396  c5.Print(output5.c_str());
397 
398  //return;
399 }
400 
ofstream output
c2
Definition: demo5.py:33
TLatex * prelim
Definition: Xsec_final.C:133
Int_t nevent
Definition: macro.C:10
void pidPlotProng(string input)
Definition: pidPlotProng.C:19
c1
Definition: demo5.py:24