drawSensitivitySummaries.py
Go to the documentation of this file.
1 import ROOT, os, array, sys
2 
3 use_realistic_powers = True
4 
5 def GetMedian(histo):
6  n = histo.GetNbinsX();
7  x = []
8  y = []
9 
10  for i in range(0,n):
11  x.append(histo.GetBinCenter(i+1));
12  y.append(histo.GetBinContent(i+1));
13  y_array = array.array('d',y)
14 
15  return ROOT.TMath.Median(n,y_array);
16 
17 def GetPercentile(histo,X):
18  n = histo.GetNbinsX();
19  x = []
20  y = []
21 
22  for i in range(0,n):
23  x.append(histo.GetBinCenter(i+1));
24  y.append(histo.GetBinContent(i+1));
25  y_array = array.array('d',y)
26 
27  percentiles = array.array('d',[0.0]);
28  probs = array.array('d',[1-float(X)/100.0])
29 
30  ROOT.TMath.Quantiles(n,1,y_array,percentiles,probs,False);
31  return percentiles[0]
32 
33 def GetPercentileCheck(histo,X):
34  n = histo.GetNbinsX();
35  x = []
36  y = []
37 
38  for i in range(0,n):
39  x.append(histo.GetBinCenter(i+1));
40  y.append(histo.GetBinContent(i+1));
41  y.sort()
42  print y
43  pos = float(100-X)/100.0 * n;
44  if ROOT.TMath.Floor(pos)==pos:
45  return y[pos]
46  else:
47  i = ROOT.TMath.FloorNint(pos)
48  return (y[i]+y[i+1])/2
49 
51  n = histo.GetNbinsX();
52 
53  greaterThanX = 0.0;
54  total = 0.0;
55 
56  for i in range(0,n):
57  total = total + float(histo.GetBinWidth(i+1));
58  if(histo.GetBinContent(i+1)>=X):
59  greaterThanX = greaterThanX + float(histo.GetBinWidth(i+1));
60 
61  return greaterThanX/total;
62 
63 
64 def GetMinimum(histo):
65  min = 99999
66  for i in range(0,histo.GetNbinsX()):
67  if histo.GetBinContent(i+1) < min:
68  min = histo.GetBinContent(i+1)
69  return min
70 
71 
72 
73 sigma = 3
74 
75 energies = [20,30,40,50,60,70,80,90,100,120,130]
76 energies_array = array.array('d',energies)
77 
78 nh_cp_medians = [[],[],[]]
79 ih_cp_medians = [[],[],[]]
80 nh_cp_75thpercentiles = [[],[],[]]
81 ih_cp_75thpercentiles = [[],[],[]]
82 nh_cp_3sigmafracs = [[],[],[]]
83 ih_cp_3sigmafracs = [[],[],[]]
84 nh_cp_5sigmafracs = [[],[],[]]
85 ih_cp_5sigmafracs = [[],[],[]]
86 nh_mh_minimums = [[],[],[]]
87 ih_mh_minimums = [[],[],[]]
88 
89 for energy in energies:
90  nh_cp_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_nh_cp_histos.root");
91  if(use_realistic_powers and energy!=120):
92  nh_cp_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_RealisticPower_nh_cp_histos.root");
93 
94  nh_cp_medians[0].append(GetMedian(nh_cp_file.Get("h1")))
95  nh_cp_medians[1].append(GetMedian(nh_cp_file.Get("h2")))
96  nh_cp_medians[2].append(GetMedian(nh_cp_file.Get("h3")))
97 
98  nh_cp_75thpercentiles[0].append(GetPercentile(nh_cp_file.Get("h1"),75))
99  nh_cp_75thpercentiles[1].append(GetPercentile(nh_cp_file.Get("h2"),75))
100  nh_cp_75thpercentiles[2].append(GetPercentile(nh_cp_file.Get("h3"),75))
101 
102  nh_cp_3sigmafracs[0].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h1"),3.0)*100)
103  nh_cp_3sigmafracs[1].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h2"),3.0)*100)
104  nh_cp_3sigmafracs[2].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h3"),3.0)*100)
105 
106  nh_cp_5sigmafracs[0].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h1"),5.0)*100)
107  nh_cp_5sigmafracs[1].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h2"),5.0)*100)
108  nh_cp_5sigmafracs[2].append(GetFractionAtMoreThanXSigma(nh_cp_file.Get("h3"),5.0)*100)
109 
110  ih_cp_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_ih_cp_histos.root");
111  if(use_realistic_powers and energy!=120):
112  ih_cp_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_RealisticPower_ih_cp_histos.root");
113 
114  ih_cp_medians[0].append(GetMedian(ih_cp_file.Get("h1")))
115  ih_cp_medians[1].append(GetMedian(ih_cp_file.Get("h2")))
116  ih_cp_medians[2].append(GetMedian(ih_cp_file.Get("h3")))
117 
118  ih_cp_75thpercentiles[0].append(GetPercentile(ih_cp_file.Get("h1"),75))
119  ih_cp_75thpercentiles[1].append(GetPercentile(ih_cp_file.Get("h2"),75))
120  ih_cp_75thpercentiles[2].append(GetPercentile(ih_cp_file.Get("h3"),75))
121 
122  ih_cp_3sigmafracs[0].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h1"),3.0)*100)
123  ih_cp_3sigmafracs[1].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h2"),3.0)*100)
124  ih_cp_3sigmafracs[2].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h3"),3.0)*100)
125 
126  ih_cp_5sigmafracs[0].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h1"),5.0)*100)
127  ih_cp_5sigmafracs[1].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h2"),5.0)*100)
128  ih_cp_5sigmafracs[2].append(GetFractionAtMoreThanXSigma(ih_cp_file.Get("h3"),5.0)*100)
129 
130  nh_mh_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_nh_mh_histos.root");
131  if(use_realistic_powers and energy !=120):
132  nh_mh_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_RealisticPower_nh_mh_histos.root");
133 
134  nh_mh_minimums[0].append(GetMinimum(nh_mh_file.Get("h1")))
135  nh_mh_minimums[1].append(GetMinimum(nh_mh_file.Get("h2")))
136  nh_mh_minimums[2].append(GetMinimum(nh_mh_file.Get("h3")))
137 
138  ih_mh_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_ih_mh_histos.root");
139  if(use_realistic_powers and energy !=120):
140  ih_mh_file = ROOT.TFile("/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP"+str(energy)+"GeV_RealisticPower_ih_mh_histos.root");
141 
142  ih_mh_minimums[0].append(GetMinimum(ih_mh_file.Get("h1")))
143  ih_mh_minimums[1].append(GetMinimum(ih_mh_file.Get("h2")))
144  ih_mh_minimums[2].append(GetMinimum(ih_mh_file.Get("h3")))
145 
146 
147 
148 ROOT.gStyle.SetMarkerStyle(21);
149 ROOT.gStyle.SetMarkerStyle(21);
150 
151 c_nh_cp_m = ROOT.TCanvas("nh_cp_m");
152 c_ih_cp_m = ROOT.TCanvas("ih_cp_m");
153 c_nh_cp_p = ROOT.TCanvas("nh_cp_p");
154 c_ih_cp_p = ROOT.TCanvas("ih_cp_p");
155 c_nh_cp_3 = ROOT.TCanvas("nh_cp_3");
156 c_ih_cp_3 = ROOT.TCanvas("ih_cp_3");
157 c_nh_cp_5 = ROOT.TCanvas("nh_cp_5");
158 c_ih_cp_5 = ROOT.TCanvas("ih_cp_5");
159 
160 c_nh_mh = ROOT.TCanvas("nh_mh");
161 c_ih_mh = ROOT.TCanvas("ih_mh");
162 
163 nh_cp_mgraphs = []
164 ih_cp_mgraphs = []
165 nh_cp_pgraphs = []
166 ih_cp_pgraphs = []
167 nh_cp_3graphs = []
168 ih_cp_3graphs = []
169 nh_cp_5graphs = []
170 ih_cp_5graphs = []
171 nh_mh_mgraphs = []
172 ih_mh_mgraphs = []
173 
174 line_styles = [1,2,3]
175 line_colors = [1,2,4]
176 
177 for i in 0,1,2:
178  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',nh_cp_medians[i]));
179  nh_cp_mgraphs.append(temp)
180  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',ih_cp_medians[i]));
181  ih_cp_mgraphs.append(temp)
182 
183  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',nh_cp_75thpercentiles[i]));
184  nh_cp_pgraphs.append(temp)
185  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',ih_cp_75thpercentiles[i]));
186  ih_cp_pgraphs.append(temp)
187 
188  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',nh_cp_3sigmafracs[i]));
189  nh_cp_3graphs.append(temp)
190  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',ih_cp_3sigmafracs[i]));
191  ih_cp_3graphs.append(temp)
192  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',nh_cp_5sigmafracs[i]));
193  nh_cp_5graphs.append(temp)
194  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',ih_cp_5sigmafracs[i]));
195  ih_cp_5graphs.append(temp)
196  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',nh_mh_minimums[i]));
197  nh_mh_mgraphs.append(temp)
198  temp = ROOT.TGraph(len(energies),energies_array,array.array('d',ih_mh_minimums[i]));
199  ih_mh_mgraphs.append(temp)
200 
201  nh_cp_mgraphs[i].SetMinimum(1);
202  ih_cp_mgraphs[i].SetMinimum(1);
203  nh_cp_pgraphs[i].SetMinimum(1);
204  ih_cp_pgraphs[i].SetMinimum(1);
205  nh_cp_3graphs[i].SetMinimum(30);
206  ih_cp_3graphs[i].SetMinimum(30);
207  nh_cp_5graphs[i].SetMinimum(30);
208  ih_cp_5graphs[i].SetMinimum(30);
209  nh_cp_3graphs[i].SetMaximum(80);
210  ih_cp_3graphs[i].SetMaximum(80);
211  nh_cp_5graphs[i].SetMaximum(100);
212  ih_cp_5graphs[i].SetMaximum(100);
213  nh_mh_mgraphs[i].SetMinimum(2.5);
214  ih_mh_mgraphs[i].SetMinimum(2.5);
215 
216  nh_cp_mgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
217  ih_cp_mgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
218  nh_cp_pgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
219  ih_cp_pgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
220  nh_cp_3graphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
221  ih_cp_3graphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
222  nh_cp_5graphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
223  ih_cp_5graphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
224  nh_mh_mgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
225  ih_mh_mgraphs[i].GetXaxis().SetTitle("Proton Energy (GeV)");
226 
227  nh_cp_mgraphs[i].GetYaxis().SetTitle("Median CP Sensitivity (#sigma)");
228  ih_cp_mgraphs[i].GetYaxis().SetTitle("Median CP Sensitivity (#sigma)");
229  nh_cp_pgraphs[i].GetYaxis().SetTitle("75% CP Sensitivity) (#sigma)");
230  ih_cp_pgraphs[i].GetYaxis().SetTitle("75% CP Sensitivity) (#sigma)");
231  nh_cp_3graphs[i].GetYaxis().SetTitle("3 Sigma Coverage (%)");
232  ih_cp_3graphs[i].GetYaxis().SetTitle("3 Sigma Coverage (%)");
233  nh_cp_5graphs[i].GetYaxis().SetTitle("5 Sigma Coverage (%)");
234  ih_cp_5graphs[i].GetYaxis().SetTitle("5 Sigma Coverage (%)");
235  nh_mh_mgraphs[i].GetYaxis().SetTitle("Minimum MH Sensitivity (#sigma)");
236  ih_mh_mgraphs[i].GetYaxis().SetTitle("Minimum MH Sensitivity (#sigma)");
237 
238  nh_cp_mgraphs[i].SetTitle("");
239  ih_cp_mgraphs[i].SetTitle("");
240  nh_cp_pgraphs[i].SetTitle("");
241  ih_cp_pgraphs[i].SetTitle("");
242  nh_cp_3graphs[i].SetTitle("");
243  ih_cp_3graphs[i].SetTitle("");
244  nh_cp_5graphs[i].SetTitle("");
245  ih_cp_5graphs[i].SetTitle("");
246  nh_mh_mgraphs[i].SetTitle("");
247  ih_mh_mgraphs[i].SetTitle("");
248 
249  #nh_cp_mgraphs[i].SetLineStyle(line_styles[i])
250  #ih_cp_mgraphs[i].SetLineStyle(line_styles[i])
251  #nh_mh_mgraphs[i].SetLineStyle(line_styles[i])
252  #ih_mh_mgraphs[i].SetLineStyle(line_styles[i])
253 
254  nh_cp_mgraphs[i].SetLineColor(line_colors[i])
255  ih_cp_mgraphs[i].SetLineColor(line_colors[i])
256  nh_cp_pgraphs[i].SetLineColor(line_colors[i])
257  ih_cp_pgraphs[i].SetLineColor(line_colors[i])
258  nh_cp_3graphs[i].SetLineColor(line_colors[i])
259  ih_cp_3graphs[i].SetLineColor(line_colors[i])
260  nh_cp_5graphs[i].SetLineColor(line_colors[i])
261  ih_cp_5graphs[i].SetLineColor(line_colors[i])
262  nh_mh_mgraphs[i].SetLineColor(line_colors[i])
263  ih_mh_mgraphs[i].SetLineColor(line_colors[i])
264 
265  nh_cp_mgraphs[i].SetMarkerColor(line_colors[i])
266  ih_cp_mgraphs[i].SetMarkerColor(line_colors[i])
267  nh_cp_pgraphs[i].SetMarkerColor(line_colors[i])
268  ih_cp_pgraphs[i].SetMarkerColor(line_colors[i])
269  nh_cp_3graphs[i].SetMarkerColor(line_colors[i])
270  ih_cp_3graphs[i].SetMarkerColor(line_colors[i])
271  nh_cp_5graphs[i].SetMarkerColor(line_colors[i])
272  ih_cp_5graphs[i].SetMarkerColor(line_colors[i])
273  nh_mh_mgraphs[i].SetMarkerColor(line_colors[i])
274  ih_mh_mgraphs[i].SetMarkerColor(line_colors[i])
275 
276  c_nh_cp_m.cd()
277  if i == 0:
278  nh_cp_mgraphs[i].Draw("ACP");
279  else:
280  nh_cp_mgraphs[i].Draw("SAME CP");
281 
282  c_ih_cp_m.cd()
283  if i == 0:
284  ih_cp_mgraphs[i].Draw("ACP");
285  else:
286  ih_cp_mgraphs[i].Draw("SAME CP");
287 
288  c_nh_cp_p.cd()
289  if i == 0:
290  nh_cp_pgraphs[i].Draw("ACP");
291  else:
292  nh_cp_pgraphs[i].Draw("SAME CP");
293 
294  c_ih_cp_p.cd()
295  if i == 0:
296  ih_cp_pgraphs[i].Draw("ACP");
297  else:
298  ih_cp_pgraphs[i].Draw("SAME CP");
299 
300  c_nh_cp_3.cd()
301  if i == 0:
302  nh_cp_3graphs[i].Draw("ACP");
303  else:
304  nh_cp_3graphs[i].Draw("SAME CP");
305 
306  c_ih_cp_3.cd()
307  if i == 0:
308  ih_cp_3graphs[i].Draw("ACP");
309  else:
310  ih_cp_3graphs[i].Draw("SAME CP");
311 
312  c_nh_cp_5.cd()
313  if i == 0:
314  nh_cp_5graphs[i].Draw("ACP");
315  else:
316  nh_cp_5graphs[i].Draw("SAME CP");
317 
318  c_ih_cp_5.cd()
319  if i == 0:
320  ih_cp_5graphs[i].Draw("ACP");
321  else:
322  ih_cp_5graphs[i].Draw("SAME CP");
323 
324  c_nh_mh.cd()
325  if i == 0:
326  nh_mh_mgraphs[i].Draw("ACP");
327  else:
328  nh_mh_mgraphs[i].Draw("SAME CP");
329 
330  c_ih_mh.cd()
331  if i == 0:
332  ih_mh_mgraphs[i].Draw("ACP");
333  else:
334  ih_mh_mgraphs[i].Draw("SAME CP");
335 
336 leg = ROOT.TLegend(0.45,0.2,0.85,0.45);
337 leg.SetHeader("Sig/Bkgd Uncertainties");
338 leg.AddEntry(nh_cp_mgraphs[0],"1%/5%","lp");
339 leg.AddEntry(nh_cp_mgraphs[1],"2%/5%","lp");
340 leg.AddEntry(nh_cp_mgraphs[2],"5%/10%","lp");
341 leg.SetFillStyle(0);
342 leg.SetBorderSize(0);
343 
344 c_nh_cp_m.cd();
345 leg.Draw();
346 c_ih_cp_m.cd();
347 leg.Draw();
348 c_nh_cp_p.cd();
349 leg.Draw();
350 c_ih_cp_p.cd();
351 leg.Draw();
352 c_nh_cp_3.cd();
353 leg.Draw();
354 c_ih_cp_3.cd();
355 leg.Draw();
356 c_nh_cp_5.cd();
357 leg.Draw();
358 c_ih_cp_5.cd();
359 leg.Draw();
360 c_nh_mh.cd();
361 leg.Draw();
362 c_ih_mh.cd();
363 leg.Draw();
364 
365 
366 if(use_realistic_powers):
367 
368  c_nh_cp_m.Print("summary_rp_nh_cp_median.eps");
369  c_nh_cp_m.Print("summary_rp_nh_cp_median.png");
370 
371  c_ih_cp_m.Print("summary_rp_ih_cp_median.eps");
372  c_ih_cp_m.Print("summary_rp_ih_cp_median.png");
373 
374  c_nh_cp_p.Print("summary_rp_nh_cp_75thpercentile.eps");
375  c_nh_cp_p.Print("summary_rp_nh_cp_75thpercentile.png");
376 
377  c_ih_cp_p.Print("summary_rp_ih_cp_75thpercentile.eps");
378  c_ih_cp_p.Print("summary_rp_ih_cp_75thpercentile.png");
379 
380  c_nh_cp_3.Print("summary_rp_nh_cp_3sigmafrac.eps");
381  c_nh_cp_3.Print("summary_rp_nh_cp_3sigmafrac.png");
382 
383  c_ih_cp_3.Print("summary_rp_ih_cp_3sigmafrac.eps");
384  c_ih_cp_3.Print("summary_rp_ih_cp_3sigmafrac.png");
385 
386  c_nh_cp_5.Print("summary_rp_nh_cp_5sigmafrac.eps");
387  c_nh_cp_5.Print("summary_rp_nh_cp_5sigmafrac.png");
388 
389  c_ih_cp_5.Print("summary_rp_ih_cp_5sigmafrac.eps");
390  c_ih_cp_5.Print("summary_rp_ih_cp_5sigma.png");
391 
392  c_nh_mh.Print("summary_rp_nh_mh.eps");
393  c_nh_mh.Print("summary_rp_nh_mh.png");
394 
395  c_ih_mh.Print("summary_rp_ih_mh.eps");
396  c_ih_mh.Print("summary_rp_ih_mh.png");
397 
398 else:
399 
400  c_nh_cp_m.Print("summary_nh_cp_median.eps");
401  c_nh_cp_m.Print("summary_nh_cp_median.png");
402 
403  c_ih_cp_m.Print("summary_ih_cp_median.eps");
404  c_ih_cp_m.Print("summary_ih_cp_median.png");
405 
406  c_nh_cp_m.Print("summary_nh_cp_75thpercentile.eps");
407  c_nh_cp_m.Print("summary_nh_cp_75thperceentile.png");
408 
409  c_ih_cp_m.Print("summary_ih_cp_75thpercentile.eps");
410  c_ih_cp_m.Print("summary_ih_cp_75thpercentile.png");
411 
412  c_nh_cp_3.Print("summary_nh_cp_3sigmafrac.eps");
413  c_nh_cp_3.Print("summary_nh_cp_3sigmafrac.png");
414 
415  c_ih_cp_3.Print("summary_ih_cp_3sigmafrac.eps");
416  c_ih_cp_3.Print("summary_rp_ih_cp_3sigmafrac.png");
417 
418  c_nh_cp_5.Print("summary_nh_cp_5sigmafrac.eps");
419  c_nh_cp_5.Print("summary_nh_cp_5sigmafrac.png");
420 
421  c_ih_cp_5.Print("summary_ih_cp_5sigmafrac.eps");
422  c_ih_cp_5.Print("summary_ih_cp_5sigma.png");
423 
424  c_nh_mh.Print("summary_nh_mh.eps");
425  c_nh_mh.Print("summary_nh_mh.png");
426 
427  c_ih_mh.Print("summary_ih_mh.eps");
428  c_ih_mh.Print("summary_ih_mh.png");
429 
if(!yymsg) yymsg
static QCString str