11 from ROOT
import TFile, TCanvas, TH2D, TH1D, TGraph, TGraph2D, TStyle, TLegend, THStack, TPad
24 countfile = TFile(args.cntfile)
27 for key
in countfile.GetListOfKeys():
29 if key[:key.find(
"_")]
not in dets:
30 dets.append(key[:key.find(
"_")])
33 for key
in countfile.GetListOfKeys():
35 if key[key.find(
"_")+1:key.find(
"_")+1+key[key.find(
"_")+1:].find(
"_")]
not in samples:
36 samples.append(key[key.find(
"_")+1:key.find(
"_")+1+key[key.find(
"_")+1:].find(
"_")])
38 samplename = {
"numu":
"#nu_{#mu}",
"nue":
"#nu_{e}"}
39 canvases = []; stacks = []; ct_hists = []; bkg_hists = []; legends = []
42 canvases.append(TCanvas(sample+
"_canvas"))
43 canvases[s].Divide(len(dets), 1)
53 ct_hists[s].append(countfile.Get(det+
"_"+sample+
"_cts"))
54 ct_hists[s][d].SetLineColor(38)
55 ct_hists[s][d].SetFillColor(38)
57 bkg_hists[s].append(countfile.Get(det+
"_"+sample+
"_bkg"))
58 bkg_hists[s][d].SetLineColor(30)
59 bkg_hists[s][d].SetFillColor(30)
61 for b
in range(ct_hists[s][d].GetNbinsX()):
62 ct_hists[s][d].SetBinContent(1+b, ct_hists[s][d].GetBinContent(1+b) / ct_hists[s][d].GetBinWidth(1+b))
63 bkg_hists[s][d].SetBinContent(1+b, bkg_hists[s][d].GetBinContent(1+b) / bkg_hists[s][d].GetBinWidth(1+b))
65 stacks[s].append(THStack(det+
"_"+sample+
"_stack", det+
"; Counts; Energy (GeV)"))
66 stacks[s][d].Add(bkg_hists[s][d])
67 stacks[s][d].Add(ct_hists[s][d])
69 legends[s].append(TLegend())
70 legends[s][d].AddEntry(ct_hists[s][d],
'CC -> #mu + X',
'f')
71 legends[s][d].AddEntry(bkg_hists[s][d],
'NC -> #pi^{#pm} + X',
'f')
74 stacks[s][d].Draw(
"hist")
81 canvases[s].SaveAs(args.outdir + sample +
"_selection.pdf")
88 covfile = TFile(args.covfile)
93 gStyle.SetPadLeftMargin(0.25); gStyle.SetPadRightMargin(0.15)
96 for matname
in (
'cov',
'fcov',
'corr'):
98 mat = covfile.Get(matname)
100 mat.GetYaxis().LabelsOption(
'v')
101 mat.GetYaxis().SetLabelSize(0.07)
102 mat.GetXaxis().SetLabelSize(0.07)
104 mat.SetTitleSize(0.3,
't')
106 if matname ==
'corr':
107 mat.GetZaxis().SetRangeUser(-0.4, 1)
108 mat.SetTitle(
"Flux Correlation Matrix")
112 covcanvas.SetLeftMargin(0.25)
114 covcanvas.SaveAs(args.outdir + matname +
"_plot.pdf")
121 chi2file = TFile(args.chifile)
125 chi2 = chi2file.Get(
'chisq')
127 chi2canvas = TCanvas()
129 chi2.SetTitle(
'#chi^{2}; log_{10}(sin^{2}(2#theta)); log_{10}(#Delta m^{2}); #chi^{2}');
132 chi2canvas.SaveAs(args.outdir +
"chisq.pdf")
136 contcanvas = TCanvas(
'cont_canvas',
'', 1020, 990)
137 gStyle.SetPadLeftMargin(0.15); gStyle.SetPadRightMargin(0.15)
139 colours = [30, 38, 46]
140 contours = [chi2file.Get(
'90pct'),
141 chi2file.Get(
'3sigma'),
142 chi2file.Get(
'5sigma')]
144 for g
in range(len(contours)):
146 contours[g].SetMarkerStyle(20)
147 contours[g].SetMarkerSize(0.25)
148 contours[g].SetMarkerColor(colours[g])
149 contours[g].SetLineColor(colours[g])
152 gr_range.SetPoint(0, 0.001, 0.01)
153 gr_range.SetPoint(1, 1, 100)
154 gr_range.SetMarkerColor(0)
157 bestfit.SetPoint(0, 0.062, 1.7)
158 bestfit.SetMarkerStyle(29)
159 bestfit.SetMarkerSize(1.6)
160 bestfit.SetMarkerColor(40)
162 gr_range.SetTitle(
'SBN Sensitivity; sin^{2}(2#theta); #Delta m^{2} (eV^{2})')
165 legend.AddEntry(contours[0],
'90% CL',
'l')
166 legend.AddEntry(contours[1],
'3#sigma CL',
'l')
167 legend.AddEntry(contours[2],
'5#sigma CL',
'l')
168 legend.AddEntry(bestfit,
'Best Fit Point',
'p')
174 gr_range.GetXaxis().SetRangeUser(0.001, 1)
175 gr_range.GetYaxis().SetRangeUser(0.01, 100)
177 contours[0].Draw(
'P same')
178 contours[1].Draw(
'P same')
179 contours[2].Draw(
'P same')
182 bestfit.Draw(
'P same')
184 contcanvas.SetLeftMargin(0.15)
186 contcanvas.SaveAs(args.outdir+
'Sensitivity.pdf')
191 chi2file = TFile(args.chifile)
194 gStyle.SetPadLeftMargin(0.15); gStyle.SetPadRightMargin(0.15)
196 colours = [30, 38, 46]
197 contours = [chi2file.Get(
'90pct'),
198 chi2file.Get(
'3sigma'),
199 chi2file.Get(
'5sigma')]
202 contournames = [
'90pct',
'3s',
'5s']
203 contourtitles = [
'90% Confidence Level',
'3#sigma Confidence Level',
'5#sigma Confidence Level']
206 gr_range.SetPoint(0, 0.001, 0.01)
207 gr_range.SetPoint(1, 1, 100)
208 gr_range.SetMarkerColor(0)
211 bestfit.SetPoint(0, 0.062, 1.7)
212 bestfit.SetMarkerStyle(29)
213 bestfit.SetMarkerSize(1.6)
214 bestfit.SetMarkerColor(40)
216 print(
"contours has length " + str(len(contours)))
218 for i
in range(len(contours)):
223 with
open(args.compdir+
'numu'+contournames[i]+
'.txt')
as f:
226 x.append(float(line.split(
', ')[0]))
227 y.append(float(line.split(
', ')[1].replace(
"\n",
"")))
229 propcontours.append(TGraph())
230 for j
in range(len(x)):
231 propcontours[i].SetPoint(j, x[j], y[j])
233 tempcanvas = TCanvas(
'temp_canvas',
'', 1020, 990)
235 templegend = TLegend()
236 templegend.AddEntry(contours[i],
'Our contour',
'l')
237 templegend.AddEntry(propcontours[i],
'From proposal',
'l')
238 templegend.AddEntry(bestfit,
'Best Fit Point',
'p')
243 gr_range.SetTitle(contourtitles[i]+
' Comparison; sin^{2}(2#theta); #Delta m^{2} (eV^{2})')
246 gr_range.GetXaxis().SetRangeUser(0.001, 1)
247 gr_range.GetYaxis().SetRangeUser(0.01, 100)
249 for lst
in (contours, propcontours):
250 lst[i].SetMarkerStyle(20)
251 lst[i].SetMarkerSize(0.25)
252 lst[i].SetMarkerColor(colours[i]
if lst == contours
else 1)
253 lst[i].SetLineColor(colours[i]
if lst == contours
else 1)
255 contours[i].Draw(
'P same')
256 propcontours[i].Draw(
'P same')
259 bestfit.Draw(
'P same')
261 tempcanvas.SaveAs(args.outdir+contournames[i]+
'_comparison.pdf')
266 dm2s = [float(dm2)
for dm2
in args.dm2list.split(
",")]
268 chi2file = TFile(args.chifile)
269 chi2 = chi2file.Get(
'chisq')
271 min_sin = chi2.GetXmin(); max_sin = chi2.GetXmax()
272 min_dm2 = chi2.GetYmin(); max_dm2 = chi2.GetYmax()
274 chi2_vals = [float(chi)
for chi
in chi2.GetZ()]
275 NP = int(math.sqrt(len(chi2_vals)))
277 reusable_canvas = TCanvas()
279 print(
"min_sin = " + str(min_sin) +
" and max_sin = " + str(max_sin))
280 print(
"min_dm2 = " + str(min_dm2) +
" and max_dm2 + " + str(max_dm2))
281 print(
"NP + " + str(NP))
285 jval = int((math.log10(dm2) - min_dm2)*(NP-1)/(max_dm2-min_dm2))
286 tempslice = [chi2_vals[i*NP + jval]
for i
in range(NP)]
288 slices.append(TGraph())
290 slices[m].SetPoint(c, (min_sin + c*(max_sin - min_sin)/(NP-1)), chi)
293 chilims = [float(lim)
for lim
in args.chilims.split(
",")]
294 if len(chilims) == 1:
295 slices[m].GetYaxis().SetRangeUser(0, chilims[0])
297 slices[m].GetYaxis().SetRangeUser(chilims[0], chilims[1])
299 slices[m].SetTitle(
"#chi^{2} @ #Delta m^{2} = " + str(dm2) +
"; log_{10}(sin^{2}(2#theta)); #chi^{2}")
302 reusable_canvas.SaveAs(args.outdir +
"dm2_"+str(dm2).replace(
".",
"-")+
"_slice.pdf")
306 sins = [float(sin)
for sin
in args.sinlist.split(
",")]
308 chi2file = TFile(args.chifile)
309 chi2 = chi2file.Get(
'chisq')
311 min_sin = chi2.GetXmin(); max_sin = chi2.GetXmax()
312 min_dm2 = chi2.GetYmin(); max_dm2 = chi2.GetYmax()
314 chi2_vals = [float(chi)
for chi
in chi2.GetZ()]
315 NP = int(math.sqrt(len(chi2_vals)))
317 reusable_canvas = TCanvas()
322 ival = int((math.log10(sin) - min_sin)*(NP-1)/(max_sin-min_sin))
323 tempslice = [chi2_vals[ival*NP + j]
for j
in range(NP)]
325 slices.append(TGraph())
327 slices[s].SetPoint(c, 10**(min_dm2 + c*(max_dm2 - min_dm2)/(NP-1)), chi)
330 chilims = [float(lim)
for lim
in args.chilims.split(
",")]
331 if len(chilims) == 1:
332 slices[s].GetYaxis().SetRangeUser(0, chilims[0])
334 slices[s].GetYaxis().SetRangeUser(chilims[0], chilims[1])
336 slices[s].SetTitle(
"#chi^{2} @ #sin^{2}(2#theta) = " + str(sin) +
"; log_{10}(#Delta m^{2}); #chi^{2}")
338 reusable_canvas.SaveAs(args.outdir +
"sin_"+str(sin).replace(
".",
"-")+
"_slice.pdf")
341 if __name__ ==
"__main__":
343 buildpath = os.environ[
'SBN_LIB_DIR']
345 print(
'ERROR: SBNDDAQ_ANALYSIS_BUILD_PATH not set')
348 ROOT.gROOT.ProcessLine(
'.L ' + buildpath +
'/libsbnanalysis_Event.so')
349 ROOT.gROOT.ProcessLine(
'.L ' + buildpath +
'/libsbnanalysis_SBNOsc_classes.so')
351 parser = argparse.ArgumentParser()
352 parser.add_argument(
"-chi",
"--chifile", default =
False)
353 parser.add_argument(
"-cov",
"--covfile", default =
False)
354 parser.add_argument(
"-cts",
"--cntfile", default =
False)
355 parser.add_argument(
"-o",
"--outdir", required =
True)
356 parser.add_argument(
"-comp",
"--compdir", default =
False)
357 parser.add_argument(
"-dm2slice",
"--dm2list", default =
False)
358 parser.add_argument(
"-sinslice",
"--sinlist", default =
False)
359 parser.add_argument(
"-chilims",
"--chilims", default =
False)
361 args = parser.parse_args()
do one_file $F done echo for F in find $TOP name CMakeLists txt print
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def make_count_plot
Main function ~~~~~~~~~~~~~.
open(RACETRACK) or die("Could not open file $RACETRACK for writing")