plotSensitivity.py
Go to the documentation of this file.
1 import ROOT, array, os
2 
3 # Set information related to the beams you want to compare
4 x_title = "Beam Options"
5 macros = ["Nominal","CP_run5_9116_80GeV","CP_run15_12388","CP_run17_6432","CP_run18_3849"]
6 xs = [1,2,3,4,5]
7 energies = [120.0,80.0,62.4,111.4,108.8]
8 versions = ["v3r4p2","v3r4p2","v3r4p2","v3r4p2","v3r4p2"]
9 users = ["ljf26","ljf26","ljf26","ljf26","ljf26"]
10 locs = ["data","data","data","data","data"]
11 sens_min = 1.4
12 sens_max = 2.4
13 flux_min = 0e-12
14 flux_max = 150e-12
15 text_axis = True # puts words rather than numbers on the x axis
16 axis_labels = ["Nominal","2Horn","3HornNuMI","3HornSphere","3HornCyl"]
17 
18 """
19 x_title = "Horn A Downstream Endcap Thickness (mm)"
20 macros = ["CP_run15_12388_NoWater","CP_run15_12388_Horn1DE4mm_NoWater","CP_run15_12388_Horn1DE6mm_NoWater","CP_run15_12388_Horn1DE8mm_NoWater","CP_run15_12388_Horn1DE10mm_NoWater","CP_run15_12388_Horn1DE15mm_NoWater","CP_run15_12388_Horn1DE20mm_NoWater"]
21 xs = [2.0,4.0,6.0,8.0,10.0,15.0,20.0]
22 locs = ["data","data","data","data","data","data","data"]
23 energies = [62.4,62.4,62.4,62.4,62.4,62.4,62.4]
24 versions = ["v3r4p2","v3r4p2","v3r4p2","v3r4p2","v3r4p2","v3r4p2","v3r4p2"]
25 sens_min = 1.8
26 sens_max = 2.2
27 flux_min = 50e-12
28 flux_max = 100e-12
29 text_axis = False
30 """
31 
32 # Helper function for calculating 75th percentile of a set of numbers
33 def GetPercentile(y,X):
34  n = len(y);
35 
36  y_array = array.array('d',y)
37  percentiles = array.array('d',[0.0]);
38  probs = array.array('d',[1-float(X)/100.0])
39 
40  ROOT.TMath.Quantiles(n,1,y_array,percentiles,probs,False);
41  return percentiles[0]
42 
43 
44 cp_75th_percentiles = []
45 sens_v_dcp = []
46 dcps = []
47 max = 0
48 
49 # Loop over the beams to plot
50 for i in range(len(xs)):
51  version = versions[i]
52  user = users[i]
53  macro = macros[i]
54 
55  # Look up the flux files
56  fhc_file = "/dune/"+locs[i]+"/users/"+user+"/fluxfiles/g4lbne/"+version+"/QGSP_BERT/"+macros[i]+"/neutrino/flux/histos_g4lbne_"+version+"_QGSP_BERT_"+macros[i]+"_neutrino_LBNEFD_fastmc.root"
57  rhc_file = "/dune/"+locs[i]+"/users/"+user+"/fluxfiles/g4lbne/"+version+"/QGSP_BERT/"+macros[i]+"/antineutrino/flux/histos_g4lbne_"+version+"_QGSP_BERT_"+macros[i]+"_antineutrino_LBNEFD_fastmc.root"
58  fhc_tfile = ROOT.TFile(fhc_file)
59  rhc_tfile = ROOT.TFile(rhc_file)
60 
61 
62  # Get sensitivity
63  sensitivity_file = open("/dune/data/users/"+os.getenv("USER")+"/sensitivities/"+macro+"_cpsens.dat")
64  lines = sensitivity_file.readlines()
65  sensitivity_file.close()
66  cp_sens = []
67  for line in lines:
68  splitline = line.split()
69  deltacp = float(splitline[0])
70  delta_chi2 = float(splitline[1])
71  if delta_chi2 <0: delta_chi2 = 0
72  cp_sens.append(ROOT.TMath.Sqrt(delta_chi2))
73  if cp_sens[-1]>max:
74  max = cp_sens[-1]
75  dcps.append(deltacp/ROOT.TMath.Pi())
76 
77  cp_75th_percentiles.append(GetPercentile(cp_sens,75))
78  sens_v_dcp.append(cp_sens)
79 
80 # Plot 75% CP sensitivity
81 if(text_axis):
82  ROOT.gStyle.SetPadBottomMargin(0.25);
83 c1 = ROOT.TCanvas()
84 ROOT.gPad.SetGrid(1)
85 g1 = ROOT.TGraph(len(xs),array.array('d',xs),array.array('d',cp_75th_percentiles))
86 g1.GetXaxis().SetTitle(x_title)
87 g1.GetYaxis().SetTitle("GLoBES 75% CP Sensitivity (NH)")
88 if(text_axis):
89  g1.GetXaxis().SetTitle("")
90  for i in range(len(xs)):
91  g1.GetXaxis().SetBinLabel(g1.GetXaxis().FindBin(i+1),axis_labels[i])
92 
93 g1.SetTitle("")
94 g1.SetLineStyle(2)
95 g1.SetMinimum(sens_min)
96 g1.SetMaximum(sens_max)
97 g1.SetMarkerStyle(21)
98 g1.Draw("ACP")
99 
100 c1.Print(x_title.replace(" ","")+"_Sensitivity.eps")
101 c1.Print(x_title.replace(" ","")+"_Sensitivity.png")
102 
103 # Plot CP sensitivity vs delta_CP w. different beams overlaid
104 
105 ROOT.gStyle.SetTitleY(0.978);
106 ROOT.gStyle.SetOptStat(False);
107 
108 height = 1.5*max
109 n = len(sens_v_dcp[0])
110 
111 c = ROOT.TCanvas("c","c",500,500);
112 
113 frame = ROOT.TH2D("frame","frame",100,-1,1,100,0,height);
114 frame.SetTitle("CP violation sensitivity");
115 frame.GetXaxis().SetTitle("#delta_{cp}/#pi");
116 frame.GetXaxis().SetTitleSize(0.05);
117 frame.GetXaxis().CenterTitle()
118 frame.GetXaxis().SetTitleOffset(1.1);
119 frame.GetXaxis().SetLabelSize(0.035);
120 
121 frame.GetYaxis().SetTitle("#sigma = #sqrt{#Delta#chi^{2}}");
122 frame.GetYaxis().SetTitleSize(0.05);
123 frame.GetYaxis().CenterTitle()
124 frame.GetYaxis().SetTitleOffset(1.1);
125 frame.GetYaxis().SetLabelSize(0.035);
126 
127 
128 frame.Draw();
129 
130 graphs = []
131 colors = [2,4,6,8,ROOT.kOrange]
132 legend = ROOT.TLegend(0.2,0.7,0.8,0.9);
133 legend.SetFillStyle(0);
134 legend.SetBorderSize(0);
135 for k in range(len(macros)):
136 
137  temp_graph = ROOT.TGraph(n,array.array('d',dcps),array.array('d',sens_v_dcp[k]))
138  temp_graph.SetLineWidth(3);
139  temp_graph.SetLineColor(colors[k])
140 
141  temp_graph.Draw("lsame")
142 
143  graphs.append(temp_graph)
144 
145  legend.AddEntry(temp_graph,axis_labels[k],"l");
146 
147 
148 legend.Draw();
149 
150 c.SetTopMargin(0.9);
151 c.SetBottomMargin(0.15);
152 c.SetLeftMargin(0.15);
153 c.Update();
154 
155 c.Print("CP_sens.eps");
156 c.Print("CP_sens.png");
int open(const char *, int)
Opens a file descriptor.
def GetPercentile(y, X)
if(!yymsg) yymsg