1 import ROOT, os, array, sys
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,200,500]
66 nus = [
"numu",
"numubar",
"nuenuebar"]
68 vars = [
"0to0p5GeVPlus10per",
"0p5to1GeVPlus10per",
"1to2GeVPlus10per",
"2to3GeVPlus10per",
"3to4GeVPlus10per",
"4to5GeVPlus10per",
"5to6GeVPlus10per",
"6to7GeVPlus10per",
"7to8GeVPlus10per",
"8to9GeVPlus10per",
"9to10GeVPlus10per",
"10to15GeVPlus10per",
"15to20GeVPlus10per",
"20to120GeVPlus10per"]
70 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]
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:
79 outfile = ROOT.TFile(
"temp.root",
"RECREATE");
83 for hierarchy
in hierarchies:
84 for plotvar
in plotvars:
88 mixing_param = plotvar[0:2]
89 baseline_file = ROOT.TFile(
"/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/ProtonP120GeV_"+hierarchy+
"_"+mixing_param+
"_histos.root");
91 if(plotvar==
"cp_median"):
92 baseline_medians.append(
GetMedian(baseline_file.Get(
"h1")))
93 baseline_medians.append(
GetMedian(baseline_file.Get(
"h2")))
94 baseline_medians.append(
GetMedian(baseline_file.Get(
"h3")))
95 if(plotvar==
"cp_75thpercentile"):
96 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h1"),75))
97 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h2"),75))
98 baseline_medians.append(
GetPercentile(baseline_file.Get(
"h3"),75))
99 elif(plotvar==
"cp_3sigma"):
103 elif(plotvar==
"cp_5sigma"):
107 elif(plotvar==
"mh_minimum"):
108 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h1")))
109 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h2")))
110 baseline_medians.append(
GetMinimum(baseline_file.Get(
"h3")))
112 for i
in range(0,len(vars)):
114 var = vars[i]+
str(amount_varied)
115 if(amount_varied==110):
117 file_prefix = mode+nu+var+
"_"+hierarchy+
"_"+mixing_param
119 t_file = ROOT.TFile(
"/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots/"+file_prefix+
"_histos.root");
121 if(plotvar==
"cp_median"):
122 medians[0].append(
GetMedian(t_file.Get(
"h1"))-baseline_medians[0])
123 medians[1].append(
GetMedian(t_file.Get(
"h2"))-baseline_medians[1])
124 medians[2].append(
GetMedian(t_file.Get(
"h3"))-baseline_medians[2])
125 if(plotvar==
"cp_75thpercentile"):
126 medians[0].append(
GetPercentile(t_file.Get(
"h1"),75)-baseline_medians[0])
127 medians[1].append(
GetPercentile(t_file.Get(
"h2"),75)-baseline_medians[1])
128 medians[2].append(
GetPercentile(t_file.Get(
"h3"),75)-baseline_medians[2])
130 elif(plotvar==
"cp_3sigma"):
134 elif(plotvar==
"cp_5sigma"):
138 elif(plotvar==
"mh_minimum"):
139 medians[0].append(
GetMinimum(t_file.Get(
"h1"))-baseline_medians[0])
140 medians[1].append(
GetMinimum(t_file.Get(
"h2"))-baseline_medians[1])
141 medians[2].append(
GetMinimum(t_file.Get(
"h3"))-baseline_medians[2])
145 for var
in range(len(vars)):
146 if medians[i][var]==-1.0*baseline_medians[i]:
149 ROOT.gStyle.SetMarkerStyle(21);
150 ROOT.gStyle.SetMarkerStyle(21);
152 c1 = ROOT.TCanvas(file_prefix);
156 line_styles = [1,2,3]
157 line_colors = [1,2,4]
161 temp = ROOT.TGraph(len(bin_centers_array),bin_centers_array,array.array(
'd',medians[i]));
162 temp.SetName(plotvar+
"_"+mode+
"_"+nu+
"_"+hierarchy)
163 nu_string =
"#nu_{#mu}" 165 nu_string =
"#bar{#nu}_{#mu}" 166 temp.SetTitle(
"Effect of increasing "+nu_string+
" "+mode+
" flux by "+
str(amount_varied)+
"%")
168 t_graphs.append(temp)
170 if(plotvar ==
"cp_median"):
172 t_graphs[i].GetYaxis().SetTitleOffset(1.1)
173 t_graphs[i].GetYaxis().SetTitle(
"Change in Median CP Sensitivity (#sigma)");
174 elif(plotvar ==
"cp_75thpercentile"):
176 t_graphs[i].GetYaxis().SetTitleOffset(1.1)
177 t_graphs[i].GetYaxis().SetTitle(
"Change in 75% CP Sensitivity (#sigma)");
178 elif(plotvar ==
"cp_3sigma"):
180 t_graphs[i].GetYaxis().SetTitle(
"Fraction > 3#sigma Coverage (%)");
181 elif(plotvar ==
"cp_5sigma"):
183 t_graphs[i].GetYaxis().SetTitle(
"Fraction > 5#sigma Coverage (%)");
184 elif(plotvar ==
"mh_minimum"):
186 t_graphs[i].GetYaxis().SetTitle(
"Change in Minimum MH Sensitivity (#sigma)");
189 t_graphs[i].GetXaxis().SetTitle(
"Neutrino Energy (GeV)");
192 t_graphs[i].SetLineColor(line_colors[i])
193 t_graphs[i].SetMarkerColor(line_colors[i])
197 t_graphs[i].Draw(
"ACP");
199 t_graphs[i].Draw(
"SAME CP");
202 leg = ROOT.TLegend(0.45,0.3,0.85,0.55);
203 leg.SetHeader(
"Sig/Bkgd Uncertainties");
204 leg.AddEntry(t_graphs[0],
"1%/5%",
"lp");
205 leg.AddEntry(t_graphs[1],
"2%/5%",
"lp");
206 leg.AddEntry(t_graphs[2],
"5%/10%",
"lp");
208 leg.SetBorderSize(0);
211 file_prefix =
"sensitivity_plots/"+mode+
str(amount_varied)+nu+
"_"+hierarchy+
"_"+plotvar
216 c1.Print(file_prefix+
".eps")
217 c1.Print(file_prefix+
".png")
226 modes = [
"fhc",
"rhc"]
227 nus = [
"numu",
"numubar",
"nuenuebar"]
228 vars = [
"0to0p5GeVPlus10per",
"0p5to1GeVPlus10per",
"1to2GeVPlus10per",
"2to3GeVPlus10per",
"3to4GeVPlus10per",
"4to5GeVPlus10per",
"5to6GeVPlus10per",
"6to7GeVPlus10per",
"7to8GeVPlus10per",
"8to9GeVPlus10per",
"9to10GeVPlus10per",
"10to15GeVPlus10per",
"15to20GeVPlus10per",
"20to120GeVPlus10per"]
229 bin_centers_array = array.array(
'd',bin_centers)
230 hierarchies = [
"nh",
"ih"]
232 plotvars = [
"cp_75thpercentile",
"mh_minimum"]
234 amounts_varied = [0,50,90,100,200,500]
238 for hierarchy
in hierarchies:
239 for plotvar
in plotvars:
240 file_prefix =
"sensitivity_plots/"+mode+nu+
"_"+hierarchy+
"_"+plotvar
241 c1 = ROOT.TCanvas(file_prefix,file_prefix,1800,1000)
245 sensitivity_changes = []
247 for bin_iter
in range(0,len(vars)):
248 sensitivity_changes.append([])
249 flux_changes.append([])
251 for variation_iter
in range(0,len(amounts_varied)):
252 variation = amounts_varied[variation_iter]
254 for bin_iter
in range(len(vars)):
255 sensitivity_changes[bin_iter].append(0)
256 flux_changes[bin_iter].append(100)
258 temp_file = ROOT.TFile(
"/lbne/data/users/ljf26/fluxfiles/sensitivity_comps_"+
str(variation)+
"_2Feb2015.root");
259 mygraph = temp_file.Get(plotvar+
"_"+mode+
"_"+nu+
"_"+hierarchy)
260 for bin_iter
in range(mygraph.GetN()):
261 if(mygraph.GetY()[bin_iter] != -999):
262 sensitivity_changes[bin_iter].append(mygraph.GetY()[bin_iter])
263 flux_changes[bin_iter].append(amounts_varied[variation_iter])
268 for bin_iter
in range(0,len(vars)):
270 temps.append(ROOT.TGraph(len(flux_changes[bin_iter]),array.array(
'd',flux_changes[bin_iter]),array.array(
'd',sensitivity_changes[bin_iter])));
272 temps[bin_iter].Draw(
"AP")
275 temps[bin_iter].GetXaxis().SetLimits(xlow,xhigh);
277 if((mode==
"fhc" and nu ==
"numu")
or 278 (mode==
"rhc" and nu ==
"numubar")):
285 maximum = temps[bin_iter].GetHistogram().GetMaximum()
286 minimum = temps[bin_iter].GetHistogram().
GetMinimum()
287 myrange = ROOT.TMath.Max(ROOT.TMath.Abs(maximum),ROOT.TMath.Abs(minimum));
288 temps[bin_iter].GetHistogram().SetMinimum(-1.0*myrange)
289 temps[bin_iter].GetHistogram().SetMaximum(myrange)
290 temps[bin_iter].SetMarkerStyle(21);
291 temps[bin_iter].SetMarkerSize(2);
292 temps[bin_iter].SetMarkerColor(4);
293 temps[bin_iter].GetXaxis().SetNdivisions(4);
294 temps[bin_iter].GetYaxis().SetNdivisions(4);
295 temps[bin_iter].Draw(
"AP")
297 temps[bin_iter].GetXaxis().SetLabelSize(0.08)
298 ROOT.gStyle.SetOptTitle(1);
299 temps[bin_iter].GetXaxis().SetTitle(
"Change in Flux (%)")
300 temps[bin_iter].GetYaxis().SetTitle(
"Change in CP Sens. (#sigma)")
301 temps[bin_iter].GetXaxis().SetTitleSize(0.07)
302 temps[bin_iter].GetYaxis().SetTitleSize(0.07)
303 temps[bin_iter].GetXaxis().SetTitleOffset(0.9)
304 temps[bin_iter].GetYaxis().SetTitleOffset(1.05)
305 temps[bin_iter].GetYaxis().SetLabelSize(0.07)
306 temps[bin_iter].SetTitle(vars[bin_iter].
split(
"Plus")[0])
308 title = ROOT.gPad.GetPrimitive(
"title");
309 title.SetBorderSize(0);
310 ROOT.gStyle.SetTitleY(0.95)
311 title.SetTextSize(0.08)
312 title.SetTextColor(8)
320 for i
in range(len(flux_changes[bin_iter])):
321 if flux_changes[bin_iter][i] == 100:
323 if flux_changes[bin_iter][i] == 110:
326 if(iter_100 == -1
or iter_110==-1):
328 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]);
329 y_int = sensitivity_changes[bin_iter][iter_110]-slope*flux_changes[bin_iter][iter_110];
330 ylow_line = slope*xlow+y_int
331 yhigh_line = slope*xhigh+y_int
334 if ylow_line < -1.0*myrange:
335 ylow_line = -1.0*myrange
336 xlow_line = (ylow_line-y_int)/slope
337 if yhigh_line > 1.0*myrange:
338 yhigh_line = 1.0*myrange
339 xhigh_line = (yhigh_line-y_int)/slope
340 lines.append(ROOT.TLine(xlow_line,ylow_line,xhigh_line,yhigh_line))
341 lines[bin_iter].SetLineColor(2)
342 lines[bin_iter].Draw(
"SAME")
346 tempgraphs[bin_iter] = temps[bin_iter]
347 tempfuncs.append(ROOT.TF1(
"f"+
str(bin_iter),myfunc,xlow,xhigh,1))
348 tempfuncs[bin_iter].SetParameter(0,bin_iter)
349 tempfuncs[bin_iter].SetLineColor(38)
350 tempfuncs[bin_iter].Draw(
"SAME")
352 scale_string =
"fixedScale" 353 if not use_fixed_scale:
354 scale_string =
"variableScale" 355 c1.Print(file_prefix+
"_"+scale_string+
".eps")
356 c1.Print(file_prefix+
"_"+scale_string+
".png")
358 outfile = ROOT.TFile(
"temp.root",
"RECREATE")
def GetFractionAtMoreThanXSigma(histo, X)
def GetPercentile(histo, X)
void split(std::string const &s, char c, OutIter dest)