makeCovariance2.py
Go to the documentation of this file.
1 import ROOT,array,math,sys
2 
3 beam_config = "reference"
4 #beam_config = "opt"
5 
6 
7 ROOT.gStyle.SetPadRightMargin(0.15);
8 ROOT.gStyle.SetPadLeftMargin(0.15);
9 
10 
11 plots = ["numu_neutrino_ND","numubar_neutrino_ND","nue_neutrino_ND","nuebar_neutrino_ND","numu_antineutrino_ND","numubar_antineutrino_ND","nue_antineutrino_ND","nuebar_antineutrino_ND","numu_neutrino_FD","numubar_neutrino_FD","nue_neutrino_FD","nuebar_neutrino_FD","numu_antineutrino_FD","numubar_antineutrino_FD","nue_antineutrino_FD","nuebar_antineutrino_FD"]
12 
13 start_indices = [0,19,38,45,52,71,90,97,104,123,142,149,156,175,194,201]
14 
15 # Helper function that makes a error histogram out of a bunch of universes
16 # by calculating rms of universes in each bin
17 def MakeErrorHistogram(universes,asFrac=True):
18  n_universes = len(universes)
19  avg_hist = universes[0].Clone(universes[0].GetName()+"_avg")
20  error_hist = universes[0].Clone(universes[0].GetName()+"_error")
21  avg_hist.Reset()
22  error_hist.Reset()
23  avg_hist.Reset()
24  error_hist.Reset()
25  for i in range(n_universes):
26  avg_hist.Add(universes[i])
27  avg_hist.Scale(1/float(n_universes))
28 
29  # Calculate Error = RMS of universes
30  for j in range(error_hist.GetNbinsX()+2):
31  error = 0
32  for i in range(n_universes):
33  error += 1/float(n_universes)*ROOT.TMath.Power(universes[i].GetBinContent(j)-avg_hist.GetBinContent(j),2)
34  error_hist.SetBinContent(j,ROOT.TMath.Sqrt(error))
35  if asFrac:
36  error_hist.Divide(avg_hist)
37  return error_hist
38 
39 # Helper function that makes a covariance matrix out of a bunch of universes
40 # by calculating rms of universes in each bin
41 def MakeCovariance(universes,asFrac=True):
42  n_universes = len(universes)
43  avg_hist = universes[0].Clone(universes[0].GetName()+"_avg")
44  avg_hist.Reset()
45  nbins = universes[0].GetNbinsX()
46 
47  for i in range(n_universes):
48  avg_hist.Add(universes[i])
49  avg_hist.Scale(1/float(n_universes))
50 
51  covariance = ROOT.TH2D("Flux_Covariance","Flux_Covariance",nbins,0.5,nbins+0.5,nbins,0.5,nbins+0.5)
52  # Calculate Error = RMS of universes
53  for j in range(avg_hist.GetNbinsX()):
54  for k in range(avg_hist.GetNbinsX()):
55  cov = 0
56  for i in range(n_universes):
57  cov += 1/float(n_universes)*(universes[i].GetBinContent(j+1)-avg_hist.GetBinContent(j+1))*(universes[i].GetBinContent(k+1)-avg_hist.GetBinContent(k+1))
58  if asFrac:
59  if(avg_hist.GetBinContent(j+1)*avg_hist.GetBinContent(k+1) != 0):
60  cov = cov / avg_hist.GetBinContent(j+1) / avg_hist.GetBinContent(k+1)
61  else:
62  cov = 0
63  covariance.SetBinContent(j+1,k+1,cov)
64  return covariance
65 
66 def MergeHistograms(cvs,universes,name):
67  nbins = 0
68  for cv in cvs:
69  nbins += cv.GetNbinsX()
70  new_cv = ROOT.TH1D("Flux_CV","Flux_CV",nbins,0.5,nbins+0.5)
71  new_universes = []
72  for universe in range(len(universes[0])):
73  new_universes.append(ROOT.TH1D("Flux_Universe_"+str(universe)+name,"Flux_Universe_"+str(universe)+name,nbins,0.5,nbins+0.5))
74  global_bin_iter = 1
75  for cv in range(len(cvs)):
76  for local_bin_iter in range(cvs[cv].GetNbinsX()):
77 
78  new_cv.SetBinContent(global_bin_iter,cvs[cv].GetBinContent(local_bin_iter+1))
79  for universe in range(len(universes[0])):
80  new_universes[universe].SetBinContent(global_bin_iter,universes[cv][universe].GetBinContent(local_bin_iter+1))
81  global_bin_iter = global_bin_iter+1
82  return_array = [new_cv,new_universes]
83  return return_array
84 
85 def GetCorrelation(cov_matrix):
86  cor_matrix = cov_matrix.Clone()
87  for i in range(cor_matrix.GetNbinsX()):
88  for j in range(cor_matrix.GetNbinsX()):
89  if cov_matrix.GetBinContent(i+1,i+1)!=0 and cov_matrix.GetBinContent(j+1,j+1)!=0:
90  cor_matrix.SetBinContent(i+1,j+1,cov_matrix.GetBinContent(i+1,j+1)/ROOT.TMath.Sqrt(cov_matrix.GetBinContent(i+1,i+1))/ROOT.TMath.Sqrt(cov_matrix.GetBinContent(j+1,j+1)))
91  else:
92  if i==j: cor_matrix.SetBinContent(i+1,j+1,1)
93  else: cor_matrix.SetBinContent(i+1,j+1,0)
94  cor_matrix.SetMinimum(-1.0)
95  cor_matrix.SetMaximum(1.0)
96  return cor_matrix
97 
98 
99 # Open ppfx output file
100 in_files = []
101 if(beam_config=="reference"):
102  in_files.append(ROOT.TFile("laura_histos_24Jan2017/histos_g4lbne_v3r4p3_QGSP_BERT_DUNECDR_Ref80GeV_neutrino_LBNFND_ppfx_500_rebinned.root"))
103  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_DUNECDR_Ref80GeV_antineutrino_LBNFND_ppfx_500_rebinned.root"))
104  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_DUNECDR_Ref80GeV_neutrino_LBNFFD_ppfx_500_rebinned.root"))
105  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_DUNECDR_Ref80GeV_antineutrino_LBNFFD_ppfx_500_rebinned.root"))
106 
107 else:
108  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_CP_run15_12388_neutrino_LBNFND_500_rebinned.root"))
109  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_CP_run15_12388_antineutrino_LBNFND_500_rebinned.root"))
110  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_CP_run15_12388_neutrino_LBNFFD_500_rebinned.root"))
111  in_files.append(ROOT.TFile("amit_histos_10August2016/histos_g4lbne_v3r4p3_QGSP_BERT_CP_run15_12388_antineutrino_LBNFFD_500_rebinned.root"))
112 
113 # Get the central value flux out
114 cv_histos = []
115 for in_file in in_files:
116  cv_histos.append(in_file.Get("nom/hcv_numu"))
117  cv_histos.append(in_file.Get("nom/hcv_numubar"))
118  cv_histos.append(in_file.Get("nom/hcv_nue"))
119  cv_histos.append(in_file.Get("nom/hcv_nuebar"))
120 
121 # Get the error universes out
122 n_universes = 100
123 error_universes = []
124 error_types = ["total","others","targetpcpi","targetpck","targetncpi","targetpcnu","targetmesonInc","targetnuA","tgtabsorption","totabsorption"]
125 error_types2 = ["total","others","targetpcpi","targetpcK","targetncpi","targetpcnu","targetmesonInc","targetnucleonA","targetabsorption","absorption"]
126 error_titles = ["Total","Other","pC#rightarrow#pi","pC#rightarrowK","nC#rightarrow#pi","pc#rightarrowN","Meson Inc","NucleonA","Target Absorption","Other Absorption"]
127 for error in error_types:
128  error_universes.append([])
129 
130 for in_file in in_files:
131  for error_iter in range(len(error_types)):
132  error_universes[error_iter].append([])
133  for i in range(n_universes):
134  error_universes[error_iter][-1].append(in_file.Get("numu_"+error_types[error_iter]+"/h"+error_types2[error_iter]+"_numu_"+str(i)))
135 
136  error_universes[error_iter].append([])
137  for i in range(n_universes):
138  error_universes[error_iter][-1].append(in_file.Get("numubar_"+error_types[error_iter]+"/h"+error_types2[error_iter]+"_numubar_"+str(i)))
139 
140  error_universes[error_iter].append([])
141  for i in range(n_universes):
142  error_universes[error_iter][-1].append(in_file.Get("nue_"+error_types[error_iter]+"/h"+error_types2[error_iter]+"_nue_"+str(i)))
143 
144  error_universes[error_iter].append([])
145  for i in range(n_universes):
146  error_universes[error_iter][-1].append(in_file.Get("nuebar_"+error_types[error_iter]+"/h"+error_types2[error_iter]+"_nuebar_"+str(i)))
147 
148 # Rebin
149 numu_bins = [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,7 ,8,12,16,20,40,100]
150 flavors = ["neutrino_near_numu","neutrino_near_numubar","neutrino_near_nue","neutrino_near_nuebar","antineutrino_near_numu","antineutrino_near_numubar","antineutrino_near_nue","antineutrino_near_nuebar","neutrino_far_numu","neutrino_far_numubar","neutrino_far_nue","neutrino_far_nuebar","antineutrino_far_numu","antineutrino_far_numubar","antineutrino_far_nue","antineutrino_far_nuebar"]
151 #for i in range(len(flavors)):
152 # cv_histos[i] = cv_histos[i].Rebin(len(new_bins)-1,"cv_flux_"+flavors[i],array.array('d',new_bins))
153 # for j in range(n_universes):
154 # total_error_universes[i][j] = total_error_universes[i][j].Rebin(len(new_bins)-1,"universe_"+str(i)+"_"+flavors[i],array.array('d',new_bins))
155 
156 # Merge into one histogram
157 merged_histograms = []
158 merged_universes = []
159 flux_uncertainties = []
160 for error_iter in range(len(error_types)):
161 
162  merged_histograms.append(MergeHistograms(cv_histos,error_universes[error_iter],error_types[error_iter]))
163  merged_universes.append(merged_histograms[error_iter][1])
164 
165  flux_uncertainties.append(MakeErrorHistogram(merged_universes[error_iter]))
166 
167 
168 c1 = ROOT.TCanvas("c1","",1000,800)
169 
170 flux_uncertainties[error_types.index("total")].Draw()
171 print "BLAH6",flux_uncertainties[error_types.index("total")].GetBinContent(start_indices[plots.index("numubar_antineutrino_FD")]+5)
172 c1.Print("HP_error_"+beam_config+".eps")
173 c1.Print("HP_error_"+beam_config+".png")
174 
175 flux_covariance = MakeCovariance(merged_universes[error_types.index("total")])
176 # For some reason, the total doesn't equal the sum of the individual componenents
177 flux_covariance.Reset()
178 for i in range(1,len(error_types)):
179  flux_covariance.Add(MakeCovariance(merged_universes[i]))
180 
181 flux_covariance.SetMaximum(0.06)
182 flux_covariance.SetMinimum(-0.005)
183 flux_covariance.SetLabelSize(0.001,"X")
184 flux_covariance.SetLabelSize(0.001,"Y")
185 flux_covariance.SetTitle("Flux Hadron Production Covariance Matrix")
186 flux_covariance.Draw("COLZ")
187 
188 latex0 = ROOT.TLatex( 0.5, 0.93, "Flux Hadron Production Fractional Covariance Matrix" );
189 latex0.SetTextSize(0.04)
190 latex0.SetTextAlign(22)
191 latex0.SetNDC()
192 latex0.SetTextFont(42)
193 latex0.Draw()
194 
195 if(1>0):
196  latex1 = ROOT.TLatex( 0.24, 0.035, "Near Detector" );
197  latex1.SetTextSize(0.035);
198  latex1.SetNDC()
199  latex1.SetTextFont(42);
200  latex1.Draw()
201  latex2 = latex1.Clone()
202  latex2.SetText(0.61,0.035,"Far Detector")
203  latex2.Draw()
204  latex3 = latex1.Clone()
205  latex3.SetText(0.05,0.24,"Near Detector")
206  latex3.SetTextAngle(90)
207  latex3.Draw()
208  latex4 = latex1.Clone()
209  latex4.SetText(0.05,0.62,"Far Detector")
210  latex4.SetTextAngle(90)
211  latex4.Draw()
212 
213  latex5 = ROOT.TLatex(0.2,0.08,"#nu Mode")
214  latex5.SetTextSize(0.025);
215  latex5.SetNDC()
216  latex5.SetTextFont(42)
217  latex5.Draw()
218  latex6 = latex5.Clone()
219  latex6.SetText(0.38,0.08,"#bar{#nu} Mode")
220  latex6.Draw()
221  latex7 = latex5.Clone()
222  latex7.SetText(0.56,0.08,"#nu Mode")
223  latex7.Draw()
224  latex8 = latex5.Clone()
225  latex8.SetText(0.74,0.08,"#bar{#nu} Mode")
226  latex8.Draw()
227 
228  latex9 = ROOT.TLatex(0.085,0.21,"#nu Mode")
229  latex9.SetTextSize(0.025);
230  latex9.SetNDC()
231  latex9.SetTextFont(42)
232  latex9.SetTextAngle(90)
233  latex9.Draw()
234  latex10 = latex9.Clone()
235  latex10.SetText(0.085,0.4,"#bar{#nu} Mode")
236  latex10.Draw()
237  latex11 = latex9.Clone()
238  latex11.SetText(0.085,0.59,"#nu Mode")
239  latex11.Draw()
240  latex12 = latex9.Clone()
241  latex12.SetText(0.085,0.77,"#bar{#nu} Mode")
242  latex12.Draw()
243 
244  latex13 = ROOT.TLatex( 0.175, 0.124, "#nu_{#mu}" );
245  latex13.SetTextSize(0.02);
246  latex13.SetNDC()
247  latex13.SetTextFont(42);
248  latex13.Draw()
249  latex14 = ROOT.TLatex( 0.245, 0.124, "#bar{#nu}_{#mu}" );
250  latex14.SetTextSize(0.02);
251  latex14.SetNDC()
252  latex14.SetTextFont(42);
253  latex14.Draw()
254  latex15 = ROOT.TLatex( 0.285, 0.124, "#nu_{e}" );
255  latex15.SetTextSize(0.02);
256  latex15.SetNDC()
257  latex15.SetTextFont(42);
258  latex15.Draw()
259  latex16 = ROOT.TLatex( 0.31, 0.124, "#bar{#nu}_{e}" );
260  latex16.SetTextSize(0.02);
261  latex16.SetNDC()
262  latex16.SetTextFont(42);
263  latex16.Draw()
264 
265  latex17 = ROOT.TLatex( 0.35, 0.124, "#nu_{#mu}" );
266  latex17.SetTextSize(0.02);
267  latex17.SetNDC()
268  latex17.SetTextFont(42);
269  latex17.Draw()
270  latex18 = ROOT.TLatex( 0.415, 0.124, "#bar{#nu}_{#mu}" );
271  latex18.SetTextSize(0.02);
272  latex18.SetNDC()
273  latex18.SetTextFont(42);
274  latex18.Draw()
275  latex19 = ROOT.TLatex( 0.46, 0.124, "#nu_{e}" );
276  latex19.SetTextSize(0.02);
277  latex19.SetNDC()
278  latex19.SetTextFont(42);
279  latex19.Draw()
280  latex20 = ROOT.TLatex( 0.485, 0.124, "#bar{#nu}_{e}" );
281  latex20.SetTextSize(0.02);
282  latex20.SetNDC()
283  latex20.SetTextFont(42);
284  latex20.Draw()
285 
286  latex21 = ROOT.TLatex( 0.53, 0.124, "#nu_{#mu}" );
287  latex21.SetTextSize(0.02);
288  latex21.SetNDC()
289  latex21.SetTextFont(42);
290  latex21.Draw()
291  latex22 = ROOT.TLatex( 0.595, 0.124, "#bar{#nu}_{#mu}" );
292  latex22.SetTextSize(0.02);
293  latex22.SetNDC()
294  latex22.SetTextFont(42);
295  latex22.Draw()
296  latex23 = ROOT.TLatex( 0.631, 0.124, "#nu_{e}" );
297  latex23.SetTextSize(0.02);
298  latex23.SetNDC()
299  latex23.SetTextFont(42);
300  latex23.Draw()
301  latex24 = ROOT.TLatex( 0.654, 0.124, "#bar{#nu}_{e}" );
302  latex24.SetTextSize(0.02);
303  latex24.SetNDC()
304  latex24.SetTextFont(42);
305  latex24.Draw()
306 
307  latex25 = ROOT.TLatex( 0.70, 0.124, "#nu_{#mu}" );
308  latex25.SetTextSize(0.02);
309  latex25.SetNDC()
310  latex25.SetTextFont(42);
311  latex25.Draw()
312  latex26 = ROOT.TLatex( 0.77, 0.124, "#bar{#nu}_{#mu}" );
313  latex26.SetTextSize(0.02);
314  latex26.SetNDC()
315  latex26.SetTextFont(42);
316  latex26.Draw()
317  latex27 = ROOT.TLatex( 0.81, 0.124, "#nu_{e}" );
318  latex27.SetTextSize(0.02);
319  latex27.SetNDC()
320  latex27.SetTextFont(42);
321  latex27.Draw()
322  latex28 = ROOT.TLatex( 0.835, 0.124, "#bar{#nu}_{e}" );
323  latex28.SetTextSize(0.02);
324  latex28.SetNDC()
325  latex28.SetTextFont(42);
326  latex28.Draw()
327 
328  latex29 = ROOT.TLatex( 0.11,0.18, "#nu_{#mu}" );
329  latex29.SetTextAngle(90)
330  latex29.SetTextSize(0.02);
331  latex29.SetNDC()
332  latex29.SetTextFont(42);
333  latex29.Draw()
334  latex30 = ROOT.TLatex( 0.11,0.25, "#bar{#nu}_{#mu}" );
335  latex30.SetTextAngle(90)
336  latex30.SetTextSize(0.02);
337  latex30.SetNDC()
338  latex30.SetTextFont(42);
339  latex30.Draw()
340  latex31 = ROOT.TLatex( 0.11,0.295, "#nu_{e}" );
341  latex31.SetTextAngle(90)
342  latex31.SetTextSize(0.02);
343  latex31.SetNDC()
344  latex31.SetTextFont(42);
345  latex31.Draw()
346  latex32 = ROOT.TLatex( 0.11,0.32, "#bar{#nu}_{e}" );
347  latex32.SetTextAngle(90)
348  latex32.SetTextSize(0.02);
349  latex32.SetNDC()
350  latex32.SetTextFont(42);
351  latex32.Draw()
352 
353  latex33 = ROOT.TLatex( 0.11,0.37, "#nu_{#mu}" );
354  latex33.SetTextAngle(90)
355  latex33.SetTextSize(0.02);
356  latex33.SetNDC()
357  latex33.SetTextFont(42);
358  latex33.Draw()
359  latex34 = ROOT.TLatex( 0.11,0.435, "#bar{#nu}_{#mu}" );
360  latex34.SetTextAngle(90)
361  latex34.SetTextSize(0.02);
362  latex34.SetNDC()
363  latex34.SetTextFont(42);
364  latex34.Draw()
365  latex35 = ROOT.TLatex( 0.11,0.48, "#nu_{e}" );
366  latex35.SetTextAngle(90)
367  latex35.SetTextSize(0.02);
368  latex35.SetNDC()
369  latex35.SetTextFont(42);
370  latex35.Draw()
371  latex36 = ROOT.TLatex( 0.11,0.505, "#bar{#nu}_{e}" );
372  latex36.SetTextAngle(90)
373  latex36.SetTextSize(0.02);
374  latex36.SetNDC()
375  latex36.SetTextFont(42);
376  latex36.Draw()
377 
378  latex37 = ROOT.TLatex( 0.11,0.56, "#nu_{#mu}" );
379  latex37.SetTextAngle(90)
380  latex37.SetTextSize(0.02);
381  latex37.SetNDC()
382  latex37.SetTextFont(42);
383  latex37.Draw()
384  latex38 = ROOT.TLatex( 0.11,0.62, "#bar{#nu}_{#mu}" );
385  latex38.SetTextAngle(90)
386  latex38.SetTextSize(0.02);
387  latex38.SetNDC()
388  latex38.SetTextFont(42);
389  latex38.Draw()
390  latex39 = ROOT.TLatex( 0.11,0.67, "#nu_{e}" );
391  latex39.SetTextAngle(90)
392  latex39.SetTextSize(0.02);
393  latex39.SetNDC()
394  latex39.SetTextFont(42);
395  latex39.Draw()
396  latex40 = ROOT.TLatex( 0.11,0.70, "#bar{#nu}_{e}" );
397  latex40.SetTextAngle(90)
398  latex40.SetTextSize(0.02);
399  latex40.SetNDC()
400  latex40.SetTextFont(42);
401  latex40.Draw()
402 
403  latex41 = ROOT.TLatex( 0.11,0.75, "#nu_{#mu}" );
404  latex41.SetTextAngle(90)
405  latex41.SetTextSize(0.02);
406  latex41.SetNDC()
407  latex41.SetTextFont(42);
408  latex41.Draw()
409  latex42 = ROOT.TLatex( 0.11,0.81, "#bar{#nu}_{#mu}" );
410  latex42.SetTextAngle(90)
411  latex42.SetTextSize(0.02);
412  latex42.SetNDC()
413  latex42.SetTextFont(42);
414  latex42.Draw()
415  latex43 = ROOT.TLatex( 0.11,0.855, "#nu_{e}" );
416  latex43.SetTextAngle(90)
417  latex43.SetTextSize(0.02);
418  latex43.SetNDC()
419  latex43.SetTextFont(42);
420  latex43.Draw()
421  latex44 = ROOT.TLatex( 0.11,0.88, "#bar{#nu}_{e}" );
422  latex44.SetTextAngle(90)
423  latex44.SetTextSize(0.02);
424  latex44.SetNDC()
425  latex44.SetTextFont(42);
426  latex44.Draw()
427 
428  line_1 = ROOT.TLine(19.5,0.5,19.5,208)
429  line_2 = ROOT.TLine(38.5,0.5,38.5,208)
430  line_3 = ROOT.TLine(45.5,0.5,45.5,208)
431  line_4 = ROOT.TLine(52.5,0.5,52.5,208)
432  line_5 = ROOT.TLine(71.5,0.5,71.5,208)
433  line_6 = ROOT.TLine(90.5,0.5,90.5,208)
434  line_7 = ROOT.TLine(97.5,0.5,97.5,208)
435  line_8 = ROOT.TLine(104.5,0.5,104.5,208)
436  line_9 = ROOT.TLine(123.5,0.5,123.5,208)
437  line_10 = ROOT.TLine(142.5,0.5,142.5,208)
438  line_11 = ROOT.TLine(149.5,0.5,149.5,208)
439  line_12 = ROOT.TLine(156.5,0.5,156.5,208)
440  line_13 = ROOT.TLine(175.5,0.5,175.5,208)
441  line_14 = ROOT.TLine(194.5,0.5,194.5,208)
442  line_15 = ROOT.TLine(201.5,0.5,201.5,208)
443  lineb_1 = ROOT.TLine(0.5,19.5,208,19.5)
444  lineb_2 = ROOT.TLine(0.5,38.5,208,38.5)
445  lineb_3 = ROOT.TLine(0.5,45.5,208,45.5)
446  lineb_4 = ROOT.TLine(0.5,52.5,208,52.5)
447  lineb_5 = ROOT.TLine(0.5,71.5,208,71.5)
448  lineb_6 = ROOT.TLine(0.5,90.5,208,90.5)
449  lineb_7 = ROOT.TLine(0.5,97.5,208,97.5)
450  lineb_8 = ROOT.TLine(0.5,104.5,208,104.5)
451  lineb_9 = ROOT.TLine(0.5,123.5,208,123.5)
452  lineb_10 = ROOT.TLine(0.5,142.5,208,142.5)
453  lineb_11 = ROOT.TLine(0.5,149.5,208,149.5)
454  lineb_12 = ROOT.TLine(0.5,156.5,208,156.5)
455  lineb_13 = ROOT.TLine(0.5,175.5,208,175.5)
456  lineb_14 = ROOT.TLine(0.5,194.5,208,194.5)
457  lineb_15 = ROOT.TLine(0.5,201.5,208,201.5)
458 
459  line_8.SetLineWidth(4)
460  lineb_8.SetLineWidth(4)
461 
462  line_4.SetLineWidth(2)
463  lineb_4.SetLineWidth(2)
464  line_12.SetLineWidth(2)
465  lineb_12.SetLineWidth(2)
466 
467  for line in [line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8,line_9,line_10,line_11,line_12,line_13,line_14,line_15,lineb_1,lineb_2,lineb_3,lineb_4,lineb_5,lineb_6,lineb_7,lineb_8,lineb_9,lineb_10,lineb_11,lineb_12,lineb_13,lineb_14,lineb_15]:
468  line.SetLineColor(13)
469  line.Draw()
470 
471 
472 c1.Print("HP_covariance_"+beam_config+".eps")
473 c1.Print("HP_covariance_"+beam_config+".png")
474 
475 # Draw total matrix (with focusing matrix included)
476 f_foc = ROOT.TFile("focusing_covariance_"+beam_config+".root")
477 covariance_focusing = f_foc.Get("Focusing_Covariance")
478 
479 print "BLAH5",ROOT.TMath.Sqrt(flux_covariance.GetBinContent(start_indices[plots.index("numubar_antineutrino_FD")]+5,start_indices[plots.index("numubar_antineutrino_FD")]+5))
480 
481 
482 total_covariance = flux_covariance.Clone("total_covariance")
483 total_covariance.Add(covariance_focusing)
484 
485 total_covariance.SetMaximum(0.06)
486 total_covariance.SetMinimum(-0.005)
487 total_covariance.SetLabelSize(0.001,"X")
488 total_covariance.SetLabelSize(0.001,"Y")
489 total_covariance.SetTitle("Fractional Flux Covariance Matrix")
490 total_covariance.Draw("COLZ")
491 
492 latex0b = ROOT.TLatex( 0.5, 0.93, "Fractional Flux Covariance Matrix" );
493 latex0b.SetTextSize(0.04)
494 latex0b.SetTextAlign(22)
495 latex0b.SetNDC()
496 latex0b.SetTextFont(42)
497 latex0b.Draw()
498 
499 for line in [line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8,line_9,line_10,line_11,line_12,line_13,line_14,line_15,lineb_1,lineb_2,lineb_3,lineb_4,lineb_5,lineb_6,lineb_7,lineb_8,lineb_9,lineb_10,lineb_11,lineb_12,lineb_13,lineb_14,lineb_15]:
500  line.SetLineColor(13)
501  line.Draw()
502 
503 for latex in [latex1,latex2,latex3,latex4,latex5,latex6,latex7,latex8,latex9,latex10,latex11,latex12,latex13,latex14,latex15,latex16,latex17,latex18,latex19,latex20,latex21,latex22,latex23,latex24,latex25,latex26,latex27,latex28,latex29,latex30,latex31,latex32,latex33,latex34,latex35,latex35,latex36,latex37,latex38,latex39,latex40,latex41,latex42,latex43,latex44]:
504  latex.Draw();
505 
506 c1.Print("Total_covariance_"+beam_config+".eps")
507 c1.Print("Total_covariance_"+beam_config+".png")
508 
509 f_out = ROOT.TFile("total_covariance_DUNE_"+beam_config+".root","RECREATE")
510 total_covariance.Write()
511 f_out.Close()
512 
513 total_error = ROOT.TH1D("Total Error","Total Error",208,0.5,208.5);
514 for i in range(208):
515  total_error.SetBinContent(i+1,ROOT.TMath.Sqrt(total_covariance.GetBinContent(i+1,i+1)))
516 total_error.SetLabelSize(0.001,"X")
517 total_error.SetLabelSize(0.05,"Y")
518 total_error.GetYaxis().SetTitleOffset(1.3)
519 total_error.GetYaxis().SetTitle("Fractional Flux Uncertainty")
520 
521 total_error.SetMaximum(0.4)
522 total_error.SetMinimum(0)
523 total_error.Draw()
524 
525 
526 linec_1 = ROOT.TLine(19.5,0,19.5,total_error.GetMaximum())
527 linec_2 = ROOT.TLine(38.5,0,38.5,total_error.GetMaximum())
528 linec_3 = ROOT.TLine(45.5,0,45.5,total_error.GetMaximum())
529 linec_4 = ROOT.TLine(52.5,0,52.5,total_error.GetMaximum())
530 linec_5 = ROOT.TLine(71.5,0,71.5,total_error.GetMaximum())
531 linec_6 = ROOT.TLine(90.5,0,90.5,total_error.GetMaximum())
532 linec_7 = ROOT.TLine(97.5,0,97.5,total_error.GetMaximum())
533 linec_8 = ROOT.TLine(104.5,0,104.5,total_error.GetMaximum())
534 linec_9 = ROOT.TLine(123.5,0,123.5,total_error.GetMaximum())
535 linec_10 = ROOT.TLine(142.5,0,142.5,total_error.GetMaximum())
536 linec_11 = ROOT.TLine(149.5,0,149.5,total_error.GetMaximum())
537 linec_12 = ROOT.TLine(156.5,0,156.5,total_error.GetMaximum())
538 linec_13 = ROOT.TLine(175.5,0,175.5,total_error.GetMaximum())
539 linec_14 = ROOT.TLine(194.5,0,194.5,total_error.GetMaximum())
540 linec_15 = ROOT.TLine(201.5,0,201.5,total_error.GetMaximum())
541 
542 for line in [linec_1,linec_2,linec_3,linec_4,linec_5,linec_6,linec_7,linec_8,linec_9,linec_10,linec_11,linec_12,linec_13,linec_14,linec_15]:
543  line.SetLineColor(2)
544  line.SetLineStyle(2)
545  line.Draw()
546 
547 for latex in [latex1,latex2,latex5,latex6,latex7,latex8,latex13,latex14,latex15,latex16,latex17,latex18,latex19,latex20,latex21,latex22,latex23,latex24,latex25,latex26,latex27,latex28]:
548  latex.Draw();
549 
550 c1.Print("Total_error_"+beam_config+".eps")
551 c1.Print("Total_error_"+beam_config+".png")
552 
553 """
554 const int NRGBs = 3, NCont = 999;
555  gStyle.xSetNumberContours(NCont);
556  Double_t stops[NRGBs] = { 0.00, 0.50, 1.00};
557  Double_t red[NRGBs] = { 0.00, 1.00, 1.00};
558  Double_t green[NRGBs] = { 0.00, 1.00, 0.00};
559  Double_t blue[NRGBs] = { 1.00, 1.00, 0.00};
560  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
561 """
562 NRGBs = 3;
563 NCont = 999;
564 ROOT.gStyle.SetNumberContours(NCont);
565 stops = [ 0.00, 0.50, 1.00];
566 red = [ 0.00, 1.00, 1.00];
567 green = [ 0.00, 1.00, 0.00];
568 blue = [ 1.00, 1.00, 0.00];
569 ROOT.TColor.CreateGradientColorTable(NRGBs, array.array('d',stops), array.array('d',red), array.array('d',green), array.array('d',blue), NCont);
570 
571 correlation = GetCorrelation(total_covariance)
572 correlation.Draw("COLZ")
573 
574 for line in [line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8,line_9,line_10,line_11,line_12,line_13,line_14,line_15,lineb_1,lineb_2,lineb_3,lineb_4,lineb_5,lineb_6,lineb_7,lineb_8,lineb_9,lineb_10,lineb_11,lineb_12,lineb_13,lineb_14,lineb_15]:
575  line.SetLineColor(13)
576  line.Draw()
577 for latex in [latex1,latex2,latex3,latex4,latex5,latex6,latex7,latex8,latex9,latex10,latex11,latex12,latex13,latex14,latex15,latex16,latex17,latex18,latex19,latex20,latex21,latex22,latex23,latex24,latex25,latex26,latex27,latex28,latex29,latex30,latex31,latex32,latex33,latex34,latex35,latex36,latex37,latex38,latex39,latex40,latex41,latex42,latex43,latex44]:
578  latex.Draw();
579 
580 c1.Print("total_correlation_"+beam_config+".eps")
581 c1.Print("total_correlation_"+beam_config+".png")
582 
583 # Draw pretty error histograms
584 
585 for plot in plots:
586  error_bins = [0,2,4,6,8,10]
587  if plot.startswith("numu"):
588  error_bins = [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,7 ,8,12,20,40]
589  error_hists = []
590  total_uncertainties = [0]*(len(error_bins)-1)
591  for i in range(1,len(error_types)):
592 
593  temp_hist = ROOT.TH1D(error_types[i],error_types[i],len(error_bins)-1,array.array('d',error_bins))
594  for j in range(len(error_bins)-1):
595  temp_hist.SetBinContent(j+1,abs(flux_uncertainties[i].GetBinContent(start_indices[plots.index(plot)]+j+1)))
596  total_uncertainties[j] = total_uncertainties[j]+math.pow(flux_uncertainties[i].GetBinContent(start_indices[plots.index(plot)]+j+1),2)
597  error_hists.append(temp_hist)
598 
599  temp_hist = ROOT.TH1D("Total","Total",len(error_bins)-1,array.array('d',error_bins))
600  for j in range(len(error_bins)-1):
601  temp_hist.SetBinContent(j+1,math.sqrt(total_uncertainties[j]))
602  error_hists.append(temp_hist)
603 
604  error_hists[-1].SetMinimum(0);
605  error_hists[-1].SetMaximum(0.2);
606  error_hists[-1].SetLineWidth(3)
607  error_hists[-1].Draw("hist")
608  error_hists[-1].GetXaxis().SetTitle("Neutrino Energy (GeV)")
609  error_hists[-1].GetYaxis().SetTitle("Fractional Uncertainty")
610  error_hists[-1].GetYaxis().SetTitleOffset(1.3)
611  for i in range(0,len(error_hists)-1):
612  colors = [2,ROOT.kOrange+3,6,ROOT.kOrange+7,ROOT.kGreen+2,3,ROOT.kAzure+7,ROOT.kBlue-4,7,ROOT.kViolet+1,13,15,17,19]
613  error_hists[i].SetLineColor(colors[i])
614  error_hists[i].SetLineWidth(3)
615  error_hists[i].Draw("histsame")
616 
617  leg = ROOT.TLegend(0.25,0.6,0.5,0.88)
618  leg.AddEntry(error_hists[-1],"Total","l")
619  for i in range(0,len(error_hists)-1):
620  leg.AddEntry(error_hists[i],error_titles[i+1],"l")
621  leg.SetFillStyle(0)
622  leg.Draw()
623 
624  c1.Print("HP_error_overlay_"+plot+"_"+beam_config+".eps")
625  c1.Print("HP_error_overlay_"+plot+"_"+beam_config+".png")
626 
627  # Draw plots with focusing and hp errors overlaid
628  focusing_unc = ROOT.TH1D("Focusing","Focusing",len(error_bins)-1,array.array('d',error_bins))
629  total_unc = ROOT.TH1D("Total","Total",len(error_bins)-1,array.array('d',error_bins))
630  for j in range(len(error_bins)-1):
631  focusing_unc.SetBinContent(j+1,ROOT.TMath.Sqrt(covariance_focusing.GetBinContent(start_indices[plots.index(plot)]+j+1,start_indices[plots.index(plot)]+j+1)))
632  total_unc.SetBinContent(j+1,ROOT.TMath.Sqrt(total_covariance.GetBinContent(start_indices[plots.index(plot)]+j+1,start_indices[plots.index(plot)]+j+1)))
633 
634  total_unc.SetMinimum(0)
635  total_unc.SetMaximum(0.2)
636  total_unc.SetLineWidth(3)
637  focusing_unc.SetLineWidth(3)
638  total_unc.GetXaxis().SetTitle("Neutrino Energy (GeV)")
639  total_unc.GetYaxis().SetTitle("Fractional Uncertainty")
640  total_unc.GetYaxis().SetTitleOffset(1.3)
641  total_unc.Draw("hist")
642  focusing_unc.SetLineColor(2)
643  error_hists[-1].SetLineColor(4)
644  focusing_unc.Draw("histsame")
645  error_hists[-1].Draw("histsame")
646 
647  if plot=="numubar_antineutrino_FD":
648  print "blah3",total_unc.GetBinContent(5),focusing_unc.GetBinContent(5),error_hists[-1].GetBinContent(5)
649  print "BLAH4",ROOT.TMath.Sqrt(total_covariance.GetBinContent(start_indices[plots.index("numubar_antineutrino_FD")]+5,start_indices[plots.index("numubar_antineutrino_FD")]+5))
650  total_unc.Print("ALL")
651  print plots.index("numubar_antineutrino_FD"),plots.index(plot)
652 
653 
654  leg2 = ROOT.TLegend(0.25,0.7,0.6,0.88)
655  leg2.AddEntry(total_unc,"Total","l")
656  leg2.AddEntry(error_hists[-1],"Hadron Production","l")
657  leg2.AddEntry(focusing_unc,"Focusing","l")
658  leg2.SetFillStyle(0)
659  leg2.Draw()
660 
661  c1.Print("error_overlay_"+plot+"_"+beam_config+".eps")
662  c1.Print("error_overlay_"+plot+"_"+beam_config+".png")
663 
def MergeHistograms(cvs, universes, name)
def MakeErrorHistogram(universes, asFrac=True)
def GetCorrelation(cov_matrix)
T abs(T value)
def MakeCovariance(universes, asFrac=True)
if(!yymsg) yymsg
static QCString str