1 import ROOT, os, array, sys, math
3 use_realistic_powers =
True 11 return tempgraphs[
int(par[0])].Eval(x[0]);
14 n = histo.GetNbinsX();
19 x.append(histo.GetBinCenter(i+1));
20 y.append(histo.GetBinContent(i+1));
21 y_array = array.array(
'd',y)
23 percentiles = array.array(
'd',[0.0]);
24 probs = array.array(
'd',[1-float(X)/100.0])
26 ROOT.TMath.Quantiles(n,1,y_array,percentiles,probs,
False);
31 n = histo.GetNbinsX();
36 x.append(histo.GetBinCenter(i+1));
37 y.append(histo.GetBinContent(i+1));
38 y_array = array.array(
'd',y)
40 return ROOT.TMath.Median(n,y_array);
44 for i
in range(0,histo.GetNbinsX()):
45 if histo.GetBinContent(i+1) < min:
46 min = histo.GetBinContent(i+1)
50 n = histo.GetNbinsX();
56 total = total + float(histo.GetBinWidth(i+1));
57 if(histo.GetBinContent(i+1)>=X):
58 greaterThanX = greaterThanX + float(histo.GetBinWidth(i+1));
61 return greaterThanX/total
63 amounts_varied = [0,50,90,110,200,500]
66 nus = [
"numu",
"numubar",
"nuenuebar"]
68 vars = [
"0to0p5GeVPlus10per",
"0p5to1GeVPlus10per",
"1to2GeVPlus10per",
"2to3GeVPlus10per",
"3to4GeVPlus10per",
"4to5GeVPlus10per",
"5to6GeVPlus10per",
"6to7GeVPlus10per",
"7to8GeVPlus10per",
"8to9GeVPlus10per",
"9to10GeVPlus10per",
"10to15GeVPlus10per",
"15to20GeVPlus10per",
"20to120GeVPlus10per"]
69 bin_centers = [0.25,0.75,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,12.5,17.5,70.0]
71 bin_centers_array = array.array(
'd',bin_centers)
72 hierarchies = [
"nh",
"ih"]
74 plotvars = [
"cp_75thpercentile",
"mh_minimum"]
76 for amount_varied
in amounts_varied:
78 outfile = ROOT.TFile(
"/lbne/data/users/ljf26/fluxfiles/sensitivity_comps_"+
str(amount_varied)+
"_improved.root",
"RECREATE");
82 for hierarchy
in hierarchies:
83 for plotvar
in plotvars:
87 mixing_param = plotvar[0:2]
88 baseline_file = ROOT.TFile(
"/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP120GeV_"+hierarchy+
"_"+mixing_param+
"_histos.root");
90 if(plotvar==
"cp_median"):
91 baseline_medians.append(
GetMedian(baseline_file.Get(
"h1")))
92 baseline_medians.append(
GetMedian(baseline_file.Get(
"h2")))
93 baseline_medians.append(
GetMedian(baseline_file.Get(
"h3")))
94 if(plotvar==
"cp_75thpercentile"):
95 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h1"),75))
96 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h2"),75))
97 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h3"),75))
98 elif(plotvar==
"cp_3sigma"):
102 elif(plotvar==
"cp_5sigma"):
106 elif(plotvar==
"mh_minimum"):
107 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h1")))
108 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h2")))
109 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h3")))
111 for i
in range(0,len(vars)):
113 var = vars[i]+
str(amount_varied)
114 if(amount_varied==110):
116 file_prefix = mode+nu+var+
"_"+hierarchy+
"_"+mixing_param
118 t_file = ROOT.TFile(
"/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/"+file_prefix+
"_histos.root");
120 if(plotvar==
"cp_median"):
121 medians[0].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMedian(t_file.Get(
"h1")),2)-math.pow(baseline_medians[0],2))),math.pow(
GetMedian(t_file.Get(
"h1")),2)-math.pow(baseline_medians[0],2)))
122 medians[1].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMedian(t_file.Get(
"h2")),2)-math.pow(baseline_medians[1],2))),math.pow(
GetMedian(t_file.Get(
"h2")),2)-math.pow(baseline_medians[1],2)))
123 medians[2].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMedian(t_file.Get(
"h3")),2)-math.pow(baseline_medians[2],2))),math.pow(
GetMedian(t_file.Get(
"h3")),2)-math.pow(baseline_medians[2],2)))
125 if(plotvar==
"cp_75thpercentile"):
126 medians[0].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetPercentile(t_file.Get(
"h1"),75),2)-math.pow(baseline_medians[0],2))),math.pow(
GetPercentile(t_file.Get(
"h1"),75),2)-math.pow(baseline_medians[0],2)))
127 medians[1].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetPercentile(t_file.Get(
"h2"),75),2)-math.pow(baseline_medians[1],2))),math.pow(
GetPercentile(t_file.Get(
"h2"),75),2)-math.pow(baseline_medians[1],2)))
128 medians[2].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetPercentile(t_file.Get(
"h3"),75),2)-math.pow(baseline_medians[2],2))),math.pow(
GetPercentile(t_file.Get(
"h3"),75),2)-math.pow(baseline_medians[2],2)))
130 elif(plotvar==
"mh_minimum"):
131 medians[0].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMinimum(t_file.Get(
"h1")),2)-math.pow(baseline_medians[0],2))),math.pow(
GetMinimum(t_file.Get(
"h1")),2)-math.pow(baseline_medians[0],2)))
132 medians[1].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMinimum(t_file.Get(
"h2")),2)-math.pow(baseline_medians[1],2))),math.pow(
GetMinimum(t_file.Get(
"h2")),2)-math.pow(baseline_medians[1],2)))
133 medians[2].append(math.copysign(math.sqrt(math.fabs(math.pow(
GetMinimum(t_file.Get(
"h3")),2)-math.pow(baseline_medians[2],2))),math.pow(
GetMinimum(t_file.Get(
"h3")),2)-math.pow(baseline_medians[2],2)))
137 for var
in range(len(vars)):
138 if medians[i][var]==-1.0*baseline_medians[i]:
141 ROOT.gStyle.SetMarkerStyle(21);
142 ROOT.gStyle.SetMarkerStyle(21);
144 c1 = ROOT.TCanvas(file_prefix);
148 line_styles = [1,2,3]
149 line_colors = [1,2,4]
153 temp = ROOT.TGraph(len(bin_centers_array),bin_centers_array,array.array(
'd',medians[i]));
154 temp.SetName(plotvar+
"_"+mode+
"_"+nu+
"_"+hierarchy)
155 nu_string =
"#nu_{#mu}" 157 nu_string =
"#bar{#nu}_{#mu}" 158 temp.SetTitle(
"Effect of increasing "+nu_string+
" "+mode+
" flux by 10%")
159 t_graphs.append(temp)
161 if(plotvar ==
"cp_median"):
163 t_graphs[i].GetYaxis().SetTitle(
"Change in Median CP Sensitivity (#sigma)");
164 elif(plotvar ==
"cp_75thpercentile"):
166 t_graphs[i].GetYaxis().SetTitle(
"75% CP Sensitivity (#sigma)");
167 elif(plotvar ==
"cp_3sigma"):
169 t_graphs[i].GetYaxis().SetTitle(
"Fraction > 3#sigma Coverage (%)");
170 elif(plotvar ==
"cp_5sigma"):
172 t_graphs[i].GetYaxis().SetTitle(
"Fraction > 5#sigma Coverage (%)");
173 elif(plotvar ==
"mh_minimum"):
175 t_graphs[i].GetYaxis().SetTitle(
"Change in Minimum MH Sensitivity (#sigma)");
178 t_graphs[i].GetXaxis().SetTitle(
"Neutrino Energy (GeV)");
181 t_graphs[i].SetLineColor(line_colors[i])
182 t_graphs[i].SetMarkerColor(line_colors[i])
186 t_graphs[i].Draw(
"ACP");
188 t_graphs[i].Draw(
"SAME CP");
191 leg = ROOT.TLegend(0.45,0.3,0.85,0.55);
192 leg.SetHeader(
"Sig/Bkgd Uncertainties");
193 leg.AddEntry(t_graphs[0],
"1%/5%",
"lp");
194 leg.AddEntry(t_graphs[1],
"2%/5%",
"lp");
195 leg.AddEntry(t_graphs[2],
"5%/10%",
"lp");
197 leg.SetBorderSize(0);
200 file_prefix =
"sensitivity_plots/"+mode+
str(amount_varied)+nu+
"_"+hierarchy+
"_"+plotvar
205 c1.Print(file_prefix+
"_improved.eps")
206 c1.Print(file_prefix+
"_improved.png")
215 modes = [
"fhc",
"rhc"]
216 nus = [
"numu",
"numubar",
"nuenuebar"]
217 vars = [
"0to0p5GeVPlus10per",
"0p5to1GeVPlus10per",
"1to2GeVPlus10per",
"2to3GeVPlus10per",
"3to4GeVPlus10per",
"4to5GeVPlus10per",
"5to6GeVPlus10per",
"6to7GeVPlus10per",
"7to8GeVPlus10per",
"8to9GeVPlus10per",
"9to10GeVPlus10per",
"10to15GeVPlus10per",
"15to20GeVPlus10per",
"20to120GeVPlus10per"]
218 bin_centers_array = array.array(
'd',bin_centers)
219 hierarchies = [
"nh",
"ih"]
221 plotvars = [
"cp_75thpercentile",
"mh_minimum"]
223 amounts_varied = [0, 50,90,100,110,200,500,1000]
227 for hierarchy
in hierarchies:
228 for plotvar
in plotvars:
229 file_prefix =
"sensitivity_plots/"+mode+nu+
"_"+hierarchy+
"_"+plotvar
230 c1 = ROOT.TCanvas(file_prefix,file_prefix,1800,1000)
234 sensitivity_changes = []
236 for bin_iter
in range(0,len(vars)):
237 sensitivity_changes.append([])
238 flux_changes.append([])
240 for variation_iter
in range(0,len(amounts_varied)):
241 variation = amounts_varied[variation_iter]
243 for bin_iter
in range(len(vars)):
244 sensitivity_changes[bin_iter].append(0)
245 flux_changes[bin_iter].append(100)
247 temp_file = ROOT.TFile(
"/lbne/data/users/ljf26/fluxfiles/sensitivity_comps_"+
str(variation)+
"_improved.root");
248 mygraph = temp_file.Get(plotvar+
"_"+mode+
"_"+nu+
"_"+hierarchy)
249 for bin_iter
in range(mygraph.GetN()):
250 if(mygraph.GetY()[bin_iter] != -999):
251 sensitivity_changes[bin_iter].append(mygraph.GetY()[bin_iter])
252 flux_changes[bin_iter].append(amounts_varied[variation_iter])
257 for bin_iter
in range(0,len(vars)):
259 temps.append(ROOT.TGraph(len(flux_changes[bin_iter]),array.array(
'd',flux_changes[bin_iter]),array.array(
'd',sensitivity_changes[bin_iter])));
260 temps[bin_iter].Draw(
"AP")
263 temps[bin_iter].GetXaxis().SetLimits(xlow,xhigh);
268 maximum = temps[bin_iter].GetHistogram().GetMaximum()
269 minimum = temps[bin_iter].GetHistogram().
GetMinimum()
270 myrange = ROOT.TMath.Max(ROOT.TMath.Abs(maximum),ROOT.TMath.Abs(minimum));
271 temps[bin_iter].GetHistogram().SetMinimum(-1.0*myrange)
272 temps[bin_iter].GetHistogram().SetMaximum(myrange)
273 temps[bin_iter].SetMarkerStyle(21);
274 temps[bin_iter].SetMarkerSize(2);
275 temps[bin_iter].SetMarkerColor(4);
276 temps[bin_iter].GetXaxis().SetNdivisions(4);
277 temps[bin_iter].GetYaxis().SetNdivisions(4);
278 temps[bin_iter].Draw(
"AP")
280 temps[bin_iter].GetXaxis().SetLabelSize(0.08)
281 ROOT.gStyle.SetOptTitle(1);
282 temps[bin_iter].GetXaxis().SetTitle(
"Change in Flux (%)")
283 temps[bin_iter].GetYaxis().SetTitle(
"Change in CP Sens. (#sigma)")
284 temps[bin_iter].GetXaxis().SetTitleSize(0.07)
285 temps[bin_iter].GetYaxis().SetTitleSize(0.07)
286 temps[bin_iter].GetXaxis().SetTitleOffset(0.9)
287 temps[bin_iter].GetYaxis().SetTitleOffset(1.05)
288 temps[bin_iter].GetYaxis().SetLabelSize(0.07)
289 temps[bin_iter].SetTitle(vars[bin_iter].
split(
"Plus")[0])
291 title = ROOT.gPad.GetPrimitive(
"title");
292 title.SetBorderSize(0);
293 ROOT.gStyle.SetTitleY(0.95)
294 title.SetTextSize(0.08)
295 title.SetTextColor(8)
303 for i
in range(len(flux_changes[bin_iter])):
304 if flux_changes[bin_iter][i] == 100:
306 if flux_changes[bin_iter][i] == 110:
309 if(iter_100 == -1
or iter_110==-1):
311 slope = (sensitivity_changes[bin_iter][iter_110]-sensitivity_changes[bin_iter][iter_100])/(flux_changes[bin_iter][iter_110]-flux_changes[bin_iter][iter_100]);
312 y_int = sensitivity_changes[bin_iter][iter_110]-slope*flux_changes[bin_iter][iter_110];
313 ylow_line = slope*xlow+y_int
314 yhigh_line = slope*xhigh+y_int
317 if ylow_line < -1.0*myrange:
318 ylow_line = -1.0*myrange
319 xlow_line = (ylow_line-y_int)/slope
320 if yhigh_line > 1.0*myrange:
321 yhigh_line = 1.0*myrange
322 xhigh_line = (yhigh_line-y_int)/slope
323 lines.append(ROOT.TLine(xlow_line,ylow_line,xhigh_line,yhigh_line))
324 lines[bin_iter].SetLineColor(2)
325 lines[bin_iter].Draw(
"SAME")
329 tempgraphs[bin_iter] = temps[bin_iter]
330 tempfuncs.append(ROOT.TF1(
"f"+
str(bin_iter),myfunc,xlow,xhigh,1))
331 tempfuncs[bin_iter].SetParameter(0,bin_iter)
332 tempfuncs[bin_iter].SetLineColor(38)
333 tempfuncs[bin_iter].Draw(
"SAME")
335 scale_string =
"fixedScale" 336 if not use_fixed_scale:
337 scale_string =
"variableScale" 338 c1.Print(file_prefix+
"_"+scale_string+
"_improved.eps")
339 c1.Print(file_prefix+
"_"+scale_string+
"_improved.png")
340 outfile = ROOT.TFile(file_prefix+
"_"+scale_string+
"_improved.root",
"RECREATE")
def GetPercentile(histo, X)
def GetFractionAtMoreThanXSigma(histo, X)
void split(std::string const &s, char c, OutIter dest)