1 import ROOT, random, array, sys, os, math
5 name =
"h_"+pGraph.GetName();
6 histo = ROOT.TH1D(name,name,len(new_bins)-1,array.array(
'd',new_bins));
10 if pGraph.GetN() != len(new_bins)-1:
11 print "OptimizationUtils.ConvertGraphToHisto: WARNING converting graph with",pGraph.GetN(),
"points to histogram with",len(new_bins)-1,
"bins" 13 for i
in range(0,len(new_bins)):
16 pGraph.GetPoint(i,x,y);
17 histo.SetBinContent(i+1,y)
18 histo.SetBinError(i+1,0)
23 n = histo.GetNbinsX();
28 x.append(histo.GetBinCenter(i+1));
29 y.append(histo.GetBinContent(i+1));
30 y_array = array.array(
'd',y)
32 percentiles = array.array(
'd',[0.0]);
33 probs = array.array(
'd',[1-float(X)/100.0])
35 ROOT.TMath.Quantiles(n,1,y_array,percentiles,probs,
False);
39 convert =
lambda text:
int(text)
if text.isdigit()
else text.lower()
40 alphanum_key =
lambda key: [ convert(c)
for c
in re.split(
'([0-9]+)', key) ]
41 return sorted(l, key = alphanum_key)
46 n = histo.GetNbinsX();
52 total = total + float(histo.GetBinWidth(i+1));
53 if(histo.GetBinContent(i+1)>=X):
54 greaterThanX = greaterThanX + float(histo.GetBinWidth(i+1));
57 return greaterThanX/total;
65 energies = [60,70,80,90,100,110,120]
66 potperyear = [1.71e21,1.5e21,1.33e21,1.23e21,1.14e21,1.07e21,1e21]
67 for i
in range(0,len(energies)):
68 if energy < energies[i]:
73 scale_factor = (potperyear[interp_high]+(potperyear[interp_low]-potperyear[interp_high])/(energies[interp_high]-energies[interp_low])*(energies[interp_high]-energy))/1e21
78 if histo.GetSumw2N() == 0:
83 nomfhcfile =
"/dune/data/users/ljf26/fluxfiles/g4lbne/v3r2p4/QGSP_BERT/Nominal/200kA/flux/histos_g4lbne_v3r2p4_QGSP_BERT_Nominal_200kA_LBNEFD_fastmc.root" 85 nomrhcfile =
"/dune/data/users/ljf26/fluxfiles/g4lbne/v3r2p4/QGSP_BERT/Nominal/-200kA/flux/histos_g4lbne_v3r2p4_QGSP_BERT_Nominal_-200kA_LBNEFD_fastmc.root" 89 quantity =
"cp_75thpercentile" 91 quantity =
"mh_minimum" 94 new_bins = [0.0,0.5,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,15.0,20.0,120.0]
96 null_return = [[-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1]]
99 nomfhctfile = ROOT.TFile(nomfhcfile)
100 nomrhctfile = ROOT.TFile(nomrhcfile)
101 varfhctfile = ROOT.TFile(varfhcfile)
102 varrhctfile = ROOT.TFile(varrhcfile)
104 fhcnumu_nh_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnumu_nh_"+quantity+
"_fixedScale.root");
105 fhcnumu_ih_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnumu_ih_"+quantity+
"_fixedScale.root");
106 rhcnumu_nh_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnumu_nh_"+quantity+
"_fixedScale.root");
107 rhcnumu_ih_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnumu_ih_"+quantity+
"_fixedScale.root");
108 fhcnumubar_nh_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnumubar_nh_"+quantity+
"_fixedScale.root");
109 fhcnumubar_ih_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnumubar_ih_"+quantity+
"_fixedScale.root");
110 rhcnumubar_nh_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnumubar_nh_"+quantity+
"_fixedScale.root");
111 rhcnumubar_ih_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnumubar_ih_"+quantity+
"_fixedScale.root");
112 fhcnuenuebar_nh_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnuenuebar_nh_"+quantity+
"_fixedScale.root");
113 fhcnuenuebar_ih_weightfile = ROOT.TFile(
"sensitivity_plots/fhcnuenuebar_ih_"+quantity+
"_fixedScale.root");
114 rhcnuenuebar_nh_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnuenuebar_nh_"+quantity+
"_fixedScale.root");
115 rhcnuenuebar_ih_weightfile = ROOT.TFile(
"sensitivity_plots/rhcnuenuebar_ih_"+quantity+
"_fixedScale.root");
117 files_to_check = [nomfhctfile,nomrhctfile,varfhctfile,varrhctfile]
118 for a_file
in files_to_check:
119 if(a_file.IsZombie()):
120 print "Optimizationutils::ComputeMeanPercentCPSensitivity: Could not open",a_file.GetName()
124 nom_fhcnumu = nomfhctfile.Get(
"numu_flux").Rebin(len(new_bins)-1,
"h_nomfhcnumu_flux",array.array(
'd',new_bins))
125 nom_fhcnumubar = nomfhctfile.Get(
"numubar_flux").Rebin(len(new_bins)-1,
"h_nomfhcnumubar_flux",array.array(
'd',new_bins))
126 nom_fhcnue = nomfhctfile.Get(
"nue_flux").Rebin(len(new_bins)-1,
"h_nomfhcnue_flux",array.array(
'd',new_bins))
127 nom_fhcnuebar = nomfhctfile.Get(
"nuebar_flux").Rebin(len(new_bins)-1,
"h_nomfhcnuebar_flux",array.array(
'd',new_bins))
129 nom_rhcnumu = nomrhctfile.Get(
"numu_flux").Rebin(len(new_bins)-1,
"h_nomrhcnumu_flux",array.array(
'd',new_bins))
130 nom_rhcnumubar = nomrhctfile.Get(
"numubar_flux").Rebin(len(new_bins)-1,
"h_nomrhcnumubar_flux",array.array(
'd',new_bins))
131 nom_rhcnue = nomrhctfile.Get(
"nue_flux").Rebin(len(new_bins)-1,
"h_nomrhcnue_flux",array.array(
'd',new_bins))
132 nom_rhcnuebar = nomrhctfile.Get(
"nuebar_flux").Rebin(len(new_bins)-1,
"h_nomrhcnuebar_flux",array.array(
'd',new_bins))
134 var_fhcnumu = varfhctfile.Get(
"numu_flux").Rebin(len(new_bins)-1,
"h_fhcnumu_flux",array.array(
'd',new_bins))
135 var_fhcnumubar = varfhctfile.Get(
"numubar_flux").Rebin(len(new_bins)-1,
"h_fhcnumubar_flux",array.array(
'd',new_bins))
136 var_fhcnue = varfhctfile.Get(
"nue_flux").Rebin(len(new_bins)-1,
"h_fhcnue_flux",array.array(
'd',new_bins))
137 var_fhcnuebar = varfhctfile.Get(
"nuebar_flux").Rebin(len(new_bins)-1,
"h_fhcnuebar_flux",array.array(
'd',new_bins))
139 var_rhcnumu = varrhctfile.Get(
"numu_flux").Rebin(len(new_bins)-1,
"h_rhcnumu_flux",array.array(
'd',new_bins))
140 var_rhcnumubar = varrhctfile.Get(
"numubar_flux").Rebin(len(new_bins)-1,
"h_rhcnumubar_flux",array.array(
'd',new_bins))
141 var_rhcnue = varrhctfile.Get(
"nue_flux").Rebin(len(new_bins)-1,
"h_rhcnue_flux",array.array(
'd',new_bins))
142 var_rhcnuebar = varrhctfile.Get(
"nuebar_flux").Rebin(len(new_bins)-1,
"h_rhcnuebar_flux",array.array(
'd',new_bins))
144 nom_histos = [nom_fhcnumu, nom_fhcnumubar, nom_fhcnue, nom_fhcnuebar, nom_rhcnumu, nom_rhcnumubar, nom_rhcnue, nom_rhcnuebar]
145 var_histos = [var_fhcnumu, var_fhcnumubar, var_fhcnue, var_fhcnuebar, var_rhcnumu, var_rhcnumubar, var_rhcnue, var_rhcnuebar]
149 for histo
in nom_histos+var_histos:
150 for i
in range(0,histo.GetNbinsX()):
151 if(histo.GetBinContent(i+1) != histo.GetBinContent(i+1)
or 152 histo.GetBinContent(i+1)<-10000
or histo.GetBinContent(i+1)>1):
153 print "WARNING: the",i+1,
"th bin in",histo.GetName(),
"is",histo.GetBinContent(i+1),
"... Resetting it to zero" 154 histo.SetBinContent(i+1,0)
155 histo.SetBinError(i+1,0)
159 for histo
in nom_histos+var_histos:
167 antinu_scale = antinufrac/0.5*rhc_scale_factor;
168 nu_scale = (1.0-antinufrac)/0.5*fhc_scale_factor;
170 var_fhcnumu.Scale(nu_scale);
171 var_fhcnumubar.Scale(nu_scale);
172 var_fhcnue.Scale(nu_scale);
173 var_fhcnuebar.Scale(nu_scale);
175 var_rhcnumu.Scale(antinu_scale);
176 var_rhcnumubar.Scale(antinu_scale);
177 var_rhcnue.Scale(antinu_scale);
178 var_rhcnuebar.Scale(antinu_scale);
181 fhcnumu = var_fhcnumu.Clone()
182 fhcnumu.Add(nom_fhcnumu,-1)
183 fhcnumu.Divide(nom_fhcnumu)
186 fhcnumu_ih = fhcnumu.Clone()
187 fhcnumu_nh = fhcnumu.Clone()
189 fhcnumubar = var_fhcnumubar.Clone()
190 fhcnumubar.Add(nom_fhcnumubar,-1)
191 fhcnumubar.Divide(nom_fhcnumubar)
192 fhcnumubar.Scale(100)
193 fhcnumubar_ih = fhcnumubar.Clone()
194 fhcnumubar_nh = fhcnumubar.Clone()
196 fhcnuenuebar = var_fhcnue.Clone()
197 fhcnuenuebar.Add(nom_fhcnue,-1)
198 fhcnuenuebar.Divide(nom_fhcnue)
199 fhcnuenuebar.Scale(100)
200 fhcnuenuebar_ih = fhcnuenuebar.Clone()
201 fhcnuenuebar_nh = fhcnuenuebar.Clone()
203 rhcnumu = var_rhcnumu.Clone()
204 rhcnumu.Add(nom_rhcnumu,-1)
205 rhcnumu.Divide(nom_rhcnumu)
207 rhcnumu_ih = rhcnumu.Clone()
208 rhcnumu_nh = rhcnumu.Clone()
210 rhcnumubar = var_rhcnumubar.Clone()
211 rhcnumubar.Add(nom_rhcnumubar,-1)
212 rhcnumubar.Divide(nom_rhcnumubar)
213 rhcnumubar.Scale(100)
214 rhcnumubar_ih = rhcnumubar.Clone()
215 rhcnumubar_nh = rhcnumubar.Clone()
217 rhcnuenuebar = var_rhcnuebar.Clone()
218 rhcnuenuebar.Add(nom_rhcnuebar,-1)
219 rhcnuenuebar.Divide(nom_rhcnuebar)
220 rhcnuenuebar.Scale(100)
221 rhcnuenuebar_ih = rhcnuenuebar.Clone()
222 rhcnuenuebar_nh = rhcnuenuebar.Clone()
226 tot_fhcnumubar_ih = 0;
227 tot_fhcnumubar_nh = 0;
228 tot_fhcnuenuebar_ih = 0;
229 tot_fhcnuenuebar_nh = 0;
232 tot_rhcnumubar_ih = 0;
233 tot_rhcnumubar_nh = 0;
234 tot_rhcnuenuebar_ih = 0;
235 tot_rhcnuenuebar_nh = 0;
239 err_fhcnumubar_ih = 0;
240 err_fhcnumubar_nh = 0;
241 err_fhcnuenuebar_ih = 0;
242 err_fhcnuenuebar_nh = 0;
245 err_rhcnumubar_ih = 0;
246 err_rhcnumubar_nh = 0;
247 err_rhcnuenuebar_ih = 0;
248 err_rhcnuenuebar_nh = 0;
250 for i
in range(fhcnumu.GetNbinsX()):
252 fhcnumu_ih.SetBinContent(i+1,fhcnumu_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnumu.GetBinContent(i+1)+100));
253 if(fhcnumu.GetBinContent(i+1) != 0):
254 fhcnumu_ih.SetBinError(i+1,fhcnumu.GetBinError(i+1)/fhcnumu.GetBinContent(i+1)*fhcnumu_ih.GetBinContent(i+1));
255 rhcnumu_ih.SetBinContent(i+1,rhcnumu_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnumu.GetBinContent(i+1)+100));
256 if(rhcnumu.GetBinContent(i+1) != 0):
257 rhcnumu_ih.SetBinError(i+1,rhcnumu.GetBinError(i+1)/rhcnumu.GetBinContent(i+1)*rhcnumu_ih.GetBinContent(i+1));
259 fhcnumubar_ih.SetBinContent(i+1,fhcnumubar_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnumubar.GetBinContent(i+1)+100));
260 if(fhcnumubar.GetBinContent(i+1)!=0):
261 fhcnumubar_ih.SetBinError(i+1,fhcnumubar.GetBinError(i+1)/fhcnumubar.GetBinContent(i+1)*fhcnumubar_ih.GetBinContent(i+1));
262 rhcnumubar_ih.SetBinContent(i+1,rhcnumubar_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnumubar.GetBinContent(i+1)+100));
263 if(rhcnumubar.GetBinContent(i+1)!=0):
264 rhcnumubar_ih.SetBinError(i+1,rhcnumubar.GetBinError(i+1)/rhcnumubar.GetBinContent(i+1)*rhcnumubar_ih.GetBinContent(i+1));
266 fhcnuenuebar_ih.SetBinContent(i+1,fhcnuenuebar_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnuenuebar.GetBinContent(i+1)+100));
267 if(fhcnuenuebar.GetBinContent(i+1)!=0):
268 fhcnuenuebar_ih.SetBinError(i+1,fhcnuenuebar.GetBinError(i+1)/fhcnuenuebar.GetBinContent(i+1)*fhcnuenuebar_ih.GetBinContent(i+1));
269 rhcnuenuebar_ih.SetBinContent(i+1,rhcnuenuebar_ih_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnuenuebar.GetBinContent(i+1)+100));
270 if(rhcnuenuebar.GetBinContent(i+1)!=0):
271 rhcnuenuebar_ih.SetBinError(i+1,rhcnuenuebar.GetBinError(i+1)/rhcnuenuebar.GetBinContent(i+1)*rhcnuenuebar_ih.GetBinContent(i+1));
273 fhcnumu_nh.SetBinContent(i+1,fhcnumu_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnumu.GetBinContent(i+1)+100));
274 if(fhcnumu.GetBinContent(i+1)!=0):
275 fhcnumu_nh.SetBinError(i+1,fhcnumu.GetBinError(i+1)/fhcnumu.GetBinContent(i+1)*fhcnumu_nh.GetBinContent(i+1));
276 rhcnumu_nh.SetBinContent(i+1,rhcnumu_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnumu.GetBinContent(i+1)+100));
277 if(rhcnumu.GetBinContent(i+1)!=0):
278 rhcnumu_nh.SetBinError(i+1,rhcnumu.GetBinError(i+1)/rhcnumu.GetBinContent(i+1)*rhcnumu_nh.GetBinContent(i+1));
280 fhcnumubar_nh.SetBinContent(i+1,fhcnumubar_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnumubar.GetBinContent(i+1)+100));
281 if(fhcnumubar.GetBinContent(i+1)!=0):
282 fhcnumubar_nh.SetBinError(i+1,fhcnumubar.GetBinError(i+1)/fhcnumubar.GetBinContent(i+1)*fhcnumubar_nh.GetBinContent(i+1));
283 rhcnumubar_nh.SetBinContent(i+1,rhcnumubar_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnumubar.GetBinContent(i+1)+100));
284 if(rhcnumubar.GetBinContent(i+1)!=0):
285 rhcnumubar_nh.SetBinError(i+1,rhcnumubar.GetBinError(i+1)/rhcnumubar.GetBinContent(i+1)*rhcnumubar_nh.GetBinContent(i+1));
287 fhcnuenuebar_nh.SetBinContent(i+1,fhcnuenuebar_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(fhcnuenuebar.GetBinContent(i+1)+100));
288 if(fhcnuenuebar.GetBinContent(i+1)!=0):
289 fhcnuenuebar_nh.SetBinError(i+1,fhcnuenuebar.GetBinError(i+1)/fhcnuenuebar.GetBinContent(i+1)*fhcnuenuebar_nh.GetBinContent(i+1));
290 rhcnuenuebar_nh.SetBinContent(i+1,rhcnuenuebar_nh_weightfile.Get(
"Graph;"+
str(i+1)).Eval(rhcnuenuebar.GetBinContent(i+1)+100));
291 if(rhcnuenuebar.GetBinContent(i+1)!=0):
292 rhcnuenuebar_nh.SetBinError(i+1,rhcnuenuebar.GetBinError(i+1)/rhcnuenuebar.GetBinContent(i+1)*rhcnuenuebar_nh.GetBinContent(i+1));
294 tot_fhcnumu_ih += fhcnumu_ih.GetBinContent(i+1)
295 tot_fhcnumu_nh += fhcnumu_nh.GetBinContent(i+1)
296 tot_fhcnumubar_ih += fhcnumubar_ih.GetBinContent(i+1)
297 tot_fhcnumubar_nh += fhcnumubar_nh.GetBinContent(i+1)
298 tot_fhcnuenuebar_ih += fhcnuenuebar_ih.GetBinContent(i+1)
299 tot_fhcnuenuebar_nh += fhcnuenuebar_nh.GetBinContent(i+1)
301 tot_rhcnumu_ih += rhcnumu_ih.GetBinContent(i+1)
302 tot_rhcnumu_nh += rhcnumu_nh.GetBinContent(i+1)
303 tot_rhcnumubar_ih += rhcnumubar_ih.GetBinContent(i+1)
304 tot_rhcnumubar_nh += rhcnumubar_nh.GetBinContent(i+1)
305 tot_rhcnuenuebar_ih += rhcnuenuebar_ih.GetBinContent(i+1)
306 tot_rhcnuenuebar_nh += rhcnuenuebar_nh.GetBinContent(i+1)
308 err_fhcnumu_ih +=math.pow(fhcnumu_ih.GetBinError(i+1),2)
309 err_fhcnumu_nh +=math.pow(fhcnumu_nh.GetBinError(i+1),2)
310 err_fhcnumubar_ih +=math.pow(fhcnumubar_ih.GetBinError(i+1),2)
311 err_fhcnumubar_nh +=math.pow(fhcnumubar_nh.GetBinError(i+1),2)
312 err_fhcnuenuebar_ih +=math.pow(fhcnuenuebar_ih.GetBinError(i+1),2)
313 err_fhcnuenuebar_nh +=math.pow(fhcnuenuebar_nh.GetBinError(i+1),2)
315 err_rhcnumu_ih +=math.pow(rhcnumu_ih.GetBinError(i+1),2)
316 err_rhcnumu_nh +=math.pow(rhcnumu_nh.GetBinError(i+1),2)
317 err_rhcnumubar_ih +=math.pow(rhcnumubar_ih.GetBinError(i+1),2)
318 err_rhcnumubar_nh +=math.pow(rhcnumubar_nh.GetBinError(i+1),2)
319 err_rhcnuenuebar_ih +=math.pow(rhcnuenuebar_ih.GetBinError(i+1),2)
320 err_rhcnuenuebar_nh +=math.pow(rhcnuenuebar_nh.GetBinError(i+1),2)
322 err_fhcnumu_ih = math.sqrt(err_fhcnumu_ih)
323 err_fhcnumu_nh = math.sqrt(err_fhcnumu_nh)
324 err_fhcnumubar_ih = math.sqrt(err_fhcnumubar_ih)
325 err_fhcnumubar_nh = math.sqrt(err_fhcnumubar_nh)
326 err_fhcnuenuebar_ih = math.sqrt(err_fhcnuenuebar_ih)
327 err_fhcnuenuebar_nh = math.sqrt(err_fhcnuenuebar_nh)
329 err_rhcnumu_ih = math.sqrt(err_rhcnumu_ih)
330 err_rhcnumu_nh = math.sqrt(err_rhcnumu_nh)
331 err_rhcnumubar_ih = math.sqrt(err_rhcnumubar_ih)
332 err_rhcnumubar_nh = math.sqrt(err_rhcnumubar_nh)
333 err_rhcnuenuebar_ih = math.sqrt(err_rhcnuenuebar_ih)
334 err_rhcnuenuebar_nh = math.sqrt(err_rhcnuenuebar_nh)
338 if(quantity==
"cp_75thpercentile"):
340 if(quantity==
"mh_minimum"):
342 FMC_SENSIT =
"/dune/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots" 343 nh_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP120GeV_nh_"+quantity+
"_histos.root")
344 ih_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP120GeV_ih_"+quantity+
"_histos.root")
350 fitness_types = [
"standard",
"fhcnumu",
"fhcnumubar",
"fhcnuenuebar",
"rhcnumu",
"rhcnumubar",
"rhcnuenuebar",
"standard_nh",
"standard_ih"]
351 nh_fitness = [0,0,0,0,0,0,0]
352 ih_fitness = [0,0,0,0,0,0,0]
353 nh_fiterror = [0,0,0,0,0,0,0]
354 ih_fiterror = [0,0,0,0,0,0,0]
356 nh_fitness[0] = nh_sensitivity+ tot_fhcnumu_nh + tot_fhcnumubar_nh + tot_rhcnumu_nh + tot_rhcnumubar_nh + tot_fhcnuenuebar_nh + tot_rhcnuenuebar_nh;
357 ih_fitness[0] = ih_sensitivity+ tot_fhcnumu_ih + tot_fhcnumubar_ih + tot_rhcnumu_ih + tot_rhcnumubar_ih + tot_fhcnuenuebar_ih + tot_rhcnuenuebar_ih;
358 nh_fiterror[0] = ROOT.TMath.Sqrt(ROOT.TMath.Power(err_fhcnumu_nh,2)+ROOT.TMath.Power(err_fhcnumubar_nh,2)+ROOT.TMath.Power(err_rhcnumu_nh,2)+ROOT.TMath.Power(err_rhcnumubar_nh,2)+ROOT.TMath.Power(err_fhcnuenuebar_nh,2)+ROOT.TMath.Power(err_rhcnuenuebar_nh,2))
359 ih_fiterror[0] = ROOT.TMath.Sqrt(ROOT.TMath.Power(err_fhcnumu_ih,2)+ROOT.TMath.Power(err_fhcnumubar_ih,2)+ROOT.TMath.Power(err_rhcnumu_ih,2)+ROOT.TMath.Power(err_rhcnumubar_ih,2)+ROOT.TMath.Power(err_fhcnuenuebar_ih,2)+ROOT.TMath.Power(err_rhcnuenuebar_ih,2))
361 nh_fitness[1] = tot_fhcnumu_nh
362 ih_fitness[1] = tot_fhcnumu_ih
363 nh_fiterror[1] = err_fhcnumu_nh
364 ih_fiterror[1] = err_fhcnumu_ih
366 nh_fitness[2] = tot_fhcnumubar_nh
367 ih_fitness[2] = tot_fhcnumubar_ih
368 nh_fiterror[2] = err_fhcnumubar_nh
369 ih_fiterror[2] = err_fhcnumubar_ih
371 nh_fitness[3] = tot_fhcnuenuebar_nh
372 ih_fitness[3] = tot_fhcnuenuebar_ih
373 nh_fiterror[3] = err_fhcnuenuebar_nh
374 ih_fiterror[3] = err_fhcnuenuebar_ih
376 nh_fitness[4] = tot_rhcnumu_nh
377 ih_fitness[4] = tot_rhcnumu_ih
378 nh_fiterror[4] = err_rhcnumu_nh
379 ih_fiterror[4] = err_rhcnumu_ih
381 nh_fitness[5] = tot_rhcnumubar_nh
382 ih_fitness[5] = tot_rhcnumubar_ih
383 nh_fiterror[5] = err_rhcnumubar_nh
384 ih_fiterror[5] = err_rhcnumubar_ih
386 nh_fitness[6] = tot_rhcnuenuebar_nh
387 ih_fitness[6] = tot_rhcnuenuebar_ih
388 nh_fiterror[6] = err_rhcnuenuebar_nh
389 ih_fiterror[6] = err_rhcnuenuebar_ih
393 for i
in range(len(nh_fitness)):
394 fitness.append((nh_fitness[i]+ih_fitness[i])/2.0)
395 fiterror.append(ROOT.TMath.Sqrt(nh_fiterror[i]*nh_fiterror[i]+ih_fiterror[i]*ih_fiterror[i])/2.0)
397 fitness.append(nh_fitness[0])
398 fitness.append(ih_fitness[0])
399 fiterror.append(nh_fiterror[0])
400 fiterror.append(ih_fiterror[0])
402 fhcnumu_nh_weightfile.Close()
403 fhcnumubar_nh_weightfile.Close()
404 fhcnuenuebar_nh_weightfile.Close()
405 rhcnumu_nh_weightfile.Close()
406 rhcnumubar_nh_weightfile.Close()
407 rhcnuenuebar_nh_weightfile.Close()
408 rhcnumu_nh_weightfile.Close()
409 rhcnumubar_nh_weightfile.Close()
410 rhcnuenuebar_nh_weightfile.Close()
411 rhcnumu_nh_weightfile.Close()
412 rhcnumubar_nh_weightfile.Close()
413 rhcnuenuebar_nh_weightfile.Close()
420 return [fitness_types,fitness,fiterror]
422 def AddPlotLabel(label,x,y,size=0.05,color=1,font=62,align=22,angle=0):
424 latex = ROOT.TLatex( x, y, label );
426 latex.SetTextSize(4);
427 latex.SetTextColor(color);
428 latex.SetTextFont(font);
429 latex.SetTextAlign(align);
430 latex.SetTextAngle(angle);
434 def MakeMacro(optimization,macro_template,newmac_path,new_values,parameter_prefix=""):
436 oldmac =
open(macro_template)
437 newmac =
open(newmac_path,
'w')
442 if optimization.optname
in [
"CP_run11",
"CP_run15",
"CP_run16",
"CP_run17",
"CP_run18",
"CP_run19",
"CP_run20",
"CP_run21",
"CP_run22",
"CP_run23",
"CP_run24",
"CP_run25",
"CP_run26",
"CP_run27",
"CP_run28",
"CP_run29",
"CP_run30",
"CP_run31",
"LE_run2"]:
443 HornBF1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF1")];
444 HornBF2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF2")];
445 HornBF3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF3")];
446 HornBF4 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF4")];
447 HornBF5 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF5")];
449 Btot = HornBF1+HornBF2+HornBF3+HornBF4+HornBF5
450 HornBF1 = HornBF1 / Btot
451 HornBF2 = HornBF2 / Btot
452 HornBF3 = HornBF3 / Btot
453 HornBF4 = HornBF4 / Btot
454 HornBF5 = HornBF5 / Btot
456 new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF1")] = HornBF1
457 new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF2")] = HornBF2
458 new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF3")] = HornBF3
459 new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF4")] = HornBF4
460 new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF5")] = HornBF5
462 HornCF1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF1")];
463 HornCF2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF2")];
464 HornCF3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF3")];
465 HornCF4 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF4")];
466 HornCF5 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF5")];
468 Ctot = HornCF1+HornCF2+HornCF3+HornCF4+HornCF5
469 HornCF1 = HornCF1 / Ctot
470 HornCF2 = HornCF2 / Ctot
471 HornCF3 = HornCF3 / Ctot
472 HornCF4 = HornCF4 / Ctot
473 HornCF5 = HornCF5 / Ctot
475 new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF1")] = HornCF1
476 new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF2")] = HornCF2
477 new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF3")] = HornCF3
478 new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF4")] = HornCF4
479 new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF5")] = HornCF5
483 for s
in oldmac.xreadlines():
485 if s.find(
"/LBNE/det/seHornCurrent")>=0:
486 if not (
"HornCurrent" in optimization.parameter_names
or 487 "FHCHornCurrent" in optimization.parameter_names):
489 for j
in range(0,len(optimization.parameter_names)):
490 if optimization.rhc_parameters_float_separate:
491 if (optimization.parameter_names[j].startswith(
"FHC")
and macro_num==1):
493 if (optimization.parameter_names[j].startswith(
"RHC")
and macro_num==0):
496 parameter = optimization.parameter_names[j]
497 macro_set_stage = optimization.macro_set_stages[j]
499 if macro_set_stage ==
"PreInit":
501 value = new_values[j]
503 parameter = optimization.parameter_names[j]
508 if(
"SimpleTargetLength" in parameter):
509 newmac.write(
"/LBNE/det/UseSimpleCylindricalTarget True\n")
511 newmac.write(optimization.macro_commands[j]+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
516 if optimization.optname
in [
"CP_run5",
"CP_run7",
"CP_run8",
"CP_run13"]:
517 Horn1OCRadius = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1OCRadius")];
518 Horn1ICRadius1 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICRadius1")];
519 Horn1ICRadius2 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICRadius2")];
520 Horn1ICRadius3 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICRadius3")];
521 Horn1ICRadius4 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICRadius4")];
522 Horn1ICLength1 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength1")];
523 Horn1ICLength2 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength2")];
524 Horn1ICLength3 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength3")];
525 Horn1ICLength4 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength4")];
526 Horn1ICLength5 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength5")];
527 Horn1ICLength6 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength6")];
528 Horn1ICLength7 = new_values[optimization.getParameterIndex(parameter_prefix+
"Horn1ICLength7")];
529 newmac.write(
"/LBNE/det/UseHorn1Polycone True \n")
530 newmac.write(
"/LBNE/det/NumInnerPtsHorn1Polycone 10 \n")
531 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(Horn1OCRadius)+
" 2.000 0.00 mm\n");
532 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(Horn1ICRadius1)+
" 2.000 1.00 mm\n");
533 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(Horn1ICRadius1)+
" 2.000 "+
str(1.00+Horn1ICLength1)+
" mm\n");
534 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(Horn1ICRadius2)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2)+
" mm\n")
535 newmac.write(
"/LBNE/det/Horn1PolyPt4RinThickZ "+
str(Horn1ICRadius2)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3)+
" mm\n")
536 newmac.write(
"/LBNE/det/Horn1PolyPt5RinThickZ "+
str(Horn1ICRadius3)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4)+
" mm\n")
537 newmac.write(
"/LBNE/det/Horn1PolyPt6RinThickZ "+
str(Horn1ICRadius3)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5)+
" mm\n")
538 newmac.write(
"/LBNE/det/Horn1PolyPt6RinThickZ "+
str(Horn1ICRadius4)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6)+
" mm\n")
539 newmac.write(
"/LBNE/det/Horn1PolyPt8RinThickZ "+
str(Horn1ICRadius4)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6+Horn1ICLength7)+
" mm\n")
540 newmac.write(
"/LBNE/det/Horn1PolyPt9RinThickZ "+
str(Horn1OCRadius)+
" 2.000 "+
str(2.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6+Horn1ICLength7)+
" mm\n")
541 newmac.write(
"/LBNE/det/Horn1PolyOuterRadius "+
str(Horn1OCRadius)+
" mm\n")
544 elif optimization.optname
in [
"CP_run9",
"CP_run10",
"CP_run11",
"CP_run14",
"CP_run15",
"CP_run16",
"CP_run17",
"CP_run18",
"CP_run19",
"CP_run20",
"CP_run21",
"CP_run22",
"CP_run23",
"CP_run24",
"CP_run25",
"CP_run26",
"CP_run27",
"CP_run28",
"CP_run29",
"CP_run30",
"CP_run31",
"LE_run2"]:
553 HornEndcapThick =
"2.0" 555 if optimization.optname
in [
"CP_run22",
"CP_run25"]:
565 HornEndcapThick =
"8.0" 567 HornARadiusOC = new_values[optimization.getParameterIndex(parameter_prefix+
"HornARadiusOC")];
568 HornARadius1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornARadius1")];
569 if(optimization.optname
not in [
"CP_run27",
"CP_run29",
"CP_run30"]):
570 HornARadius2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornARadius2")];
571 HornALength = new_values[optimization.getParameterIndex(parameter_prefix+
"HornALength")];
572 if(optimization.optname
not in [
"CP_run27",
"CP_run29",
"CP_run30",
"CP_run31"]):
573 HornAF1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornAF1")];
574 HornBRadiusOC = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBRadiusOC")];
575 HornBRadius1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBRadius1")];
576 HornBRadius2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBRadius2")];
577 HornBRadius3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBRadius3")];
578 HornBLength = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBLength")];
579 HornBF1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF1")];
580 HornBF2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF2")];
581 HornBF3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF3")];
582 HornBF4 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF4")];
583 HornBF5 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBF5")];
586 HornCRadiusOC = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCRadiusOC")];
587 HornCRadius1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCRadius1")];
588 HornCRadius2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCRadius2")];
589 HornCRadius3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCRadius3")];
590 HornCLength = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCLength")];
591 HornCF1 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF1")];
592 HornCF2 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF2")];
593 HornCF3 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF3")];
594 HornCF4 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF4")];
595 HornCF5 = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCF5")];
597 HornBLongPosition = new_values[optimization.getParameterIndex(parameter_prefix+
"HornBLongPosition")]
598 HornCLongPosition = new_values[optimization.getParameterIndex(parameter_prefix+
"HornCLongPosition")]
604 if optimization.optname
in [
"CP_run22",
"CP_run25"]:
606 newmac.write(
"/LBNE/det/NumberOfHornsPolycone 3 \n")
607 newmac.write(
"/LBNE/det/Horn2PolyZStartPos "+
str(HornBLongPosition)+
" \n")
608 newmac.write(
"/LBNE/det/Horn3PolyZStartPos "+
str(HornCLongPosition)+
" \n")
609 newmac.write(
"/LBNE/det/NumInnerPtsHorn2Polycone 12 \n")
610 newmac.write(
"/LBNE/det/NumInnerPtsHorn3Polycone 12 \n")
612 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(HornARadiusOC-15)+
" "+HornEndcapThick+
" 0.00 mm\n");
613 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(HornARadius1)+
" "+HornEndcapThick+
" 20.00 mm\n");
614 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(HornARadius1)+
" "+HornAThick1+
" 40.00 mm\n");
615 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(HornARadius1)+
" "+HornAThick1+
" "+
str(40.00+HornALength*HornAF1)+
" mm\n");
616 newmac.write(
"/LBNE/det/Horn1PolyPt4RinThickZ "+
str(HornARadius1)+
" "+HornAThick2+
" "+
str(41.00+HornALength*HornAF1)+
" mm\n");
617 newmac.write(
"/LBNE/det/Horn1PolyPt5RinThickZ "+
str(HornARadius2)+
" "+HornAThick2+
" "+
str(41.00+HornALength)+
" mm\n")
618 newmac.write(
"/LBNE/det/Horn1PolyPt6RinThickZ "+
str(HornARadius2)+
" "+HornEndcapThick+
" "+
str(61.00+HornALength)+
" mm\n")
619 newmac.write(
"/LBNE/det/Horn1PolyPt7RinThickZ "+
str(HornARadiusOC-15)+
" "+HornEndcapThick+
" "+
str(81.00+HornALength)+
" mm\n")
620 newmac.write(
"/LBNE/det/Horn1PolyOuterRadius "+
str(HornARadiusOC)+
" mm\n")
622 newmac.write(
"/LBNE/det/Horn2PolyPt0RinThickZ "+
str(HornBRadiusOC-15)+
" "+HornEndcapThick+
" 0.00 mm\n");
623 newmac.write(
"/LBNE/det/Horn2PolyPt1RinThickZ "+
str(HornBRadius1)+
" "+HornEndcapThick+
" 20.00 mm\n");
624 newmac.write(
"/LBNE/det/Horn2PolyPt2RinThickZ "+
str(HornBRadius1)+
" "+HornBThick1+
" 40.00 mm\n");
625 newmac.write(
"/LBNE/det/Horn2PolyPt3RinThickZ "+
str(HornBRadius1)+
" "+HornBThick1+
" "+
str(40.00+HornBLength*HornBF1)+
" mm\n");
626 newmac.write(
"/LBNE/det/Horn2PolyPt4RinThickZ "+
str(HornBRadius2)+
" "+HornBThick1+
" "+
str(40.00+HornBLength*(HornBF1+HornBF2))+
" mm\n")
627 newmac.write(
"/LBNE/det/Horn2PolyPt5RinThickZ "+
str(HornBRadius2)+
" "+HornBThick2+
" "+
str(41.00+HornBLength*(HornBF1+HornBF2))+
" mm\n")
628 newmac.write(
"/LBNE/det/Horn2PolyPt6RinThickZ "+
str(HornBRadius2)+
" "+HornBThick2+
" "+
str(41.00+HornBLength*(HornBF1+HornBF2+HornBF3))+
" mm\n")
629 newmac.write(
"/LBNE/det/Horn2PolyPt7RinThickZ "+
str(HornBRadius2)+
" "+HornBThick3+
" "+
str(42.00+HornBLength*(HornBF1+HornBF2+HornBF3))+
" mm\n")
630 newmac.write(
"/LBNE/det/Horn2PolyPt8RinThickZ "+
str(HornBRadius3)+
" "+HornBThick3+
" "+
str(42.00+HornBLength*(HornBF1+HornBF2+HornBF3+HornBF4))+
" mm\n")
631 newmac.write(
"/LBNE/det/Horn2PolyPt9RinThickZ "+
str(HornBRadius3)+
" "+HornBThick3+
" "+
str(42.00+HornBLength)+
" mm\n")
632 newmac.write(
"/LBNE/det/Horn2PolyPt10RinThickZ "+
str(HornBRadius3)+
" "+HornEndcapThick+
" "+
str(62.00+HornBLength)+
" mm\n")
633 newmac.write(
"/LBNE/det/Horn2PolyPt11RinThickZ "+
str(HornBRadiusOC-15)+
" "+HornEndcapThick+
" "+
str(82.00+HornBLength)+
" mm\n")
634 newmac.write(
"/LBNE/det/Horn2PolyOuterRadius "+
str(HornBRadiusOC)+
" mm\n")
636 newmac.write(
"/LBNE/det/Horn3PolyPt0RinThickZ "+
str(HornCRadiusOC-15)+
" "+HornEndcapThick+
" 0.00 mm\n");
637 newmac.write(
"/LBNE/det/Horn3PolyPt1RinThickZ "+
str(HornCRadius1)+
" "+HornEndcapThick+
" 20.00 mm\n");
638 newmac.write(
"/LBNE/det/Horn3PolyPt2RinThickZ "+
str(HornCRadius1)+
" "+HornCThick1+
" 40.00 mm\n");
639 newmac.write(
"/LBNE/det/Horn3PolyPt3RinThickZ "+
str(HornCRadius1)+
" "+HornCThick1+
" "+
str(40.00+HornCLength*HornCF1)+
" mm\n");
640 newmac.write(
"/LBNE/det/Horn3PolyPt4RinThickZ "+
str(HornCRadius2)+
" "+HornCThick1+
" "+
str(40.00+HornCLength*(HornCF1+HornCF2))+
" mm\n")
641 newmac.write(
"/LBNE/det/Horn3PolyPt5RinThickZ "+
str(HornCRadius2)+
" "+HornCThick2+
" "+
str(41.00+HornCLength*(HornCF1+HornCF2))+
" mm\n")
642 newmac.write(
"/LBNE/det/Horn3PolyPt6RinThickZ "+
str(HornCRadius2)+
" "+HornCThick2+
" "+
str(41.00+HornCLength*(HornCF1+HornCF2+HornCF3))+
" mm\n")
643 newmac.write(
"/LBNE/det/Horn3PolyPt7RinThickZ "+
str(HornCRadius2)+
" "+HornCThick3+
" "+
str(42.00+HornCLength*(HornCF1+HornCF2+HornCF3))+
" mm\n")
644 newmac.write(
"/LBNE/det/Horn3PolyPt8RinThickZ "+
str(HornCRadius3)+
" "+HornCThick3+
" "+
str(42.00+HornCLength*(HornCF1+HornCF2+HornCF3+HornCF4))+
" mm\n")
645 newmac.write(
"/LBNE/det/Horn3PolyPt9RinThickZ "+
str(HornCRadius3)+
" "+HornCThick3+
" "+
str(42.00+HornCLength)+
" mm\n")
646 newmac.write(
"/LBNE/det/Horn3PolyPt10RinThickZ "+
str(HornCRadius3)+
" "+HornEndcapThick+
" "+
str(62.00+HornCLength)+
" mm\n")
647 newmac.write(
"/LBNE/det/Horn3PolyPt11RinThickZ "+
str(HornCRadiusOC-15)+
" "+HornEndcapThick+
" "+
str(82.00+HornCLength)+
" mm\n")
648 newmac.write(
"/LBNE/det/Horn3PolyOuterRadius "+
str(HornCRadiusOC)+
" mm\n")
650 newmac.write(
"/LBNE/det/NumberOfHornsPolycone 3 \n")
651 newmac.write(
"/LBNE/det/Horn2PolyZStartPos "+
str(HornBLongPosition)+
" \n")
652 newmac.write(
"/LBNE/det/Horn3PolyZStartPos "+
str(HornCLongPosition)+
" \n")
653 if(optimization.optname
not in [
"CP_run27",
"CP_run29",
"CP_run30",
"CP_run31"]):
654 newmac.write(
"/LBNE/det/NumInnerPtsHorn1Polycone 5 \n")
656 newmac.write(
"/LBNE/det/NumInnerPtsHorn1Polycone 4 \n")
657 newmac.write(
"/LBNE/det/NumInnerPtsHorn2Polycone 8 \n")
658 newmac.write(
"/LBNE/det/NumInnerPtsHorn3Polycone 8 \n")
659 if(optimization.optname
not in [
"cp_run27",
"CP_run29",
"CP_run30",
"CP_run31"]):
660 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 0.00 mm\n");
661 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(HornARadius1)+
" 2.000 1.00 mm\n");
662 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(HornARadius1)+
" 2.000 "+
str(1.00+HornALength*HornAF1)+
" mm\n");
663 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(HornARadius2)+
" 2.000 "+
str(1.00+HornALength)+
" mm\n")
664 newmac.write(
"/LBNE/det/Horn1PolyPt4RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 "+
str(2.00+HornALength)+
" mm\n")
665 elif optimization.optname
not in [
"CP_run31"]:
666 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 0.00 mm\n");
667 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(HornARadius1)+
" 2.000 1.00 mm\n");
668 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(HornARadius1)+
" 2.000 "+
str(1.00+HornALength)+
" mm\n");
669 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 "+
str(2.00+HornALength)+
" mm\n")
671 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 0.00 mm\n");
672 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(HornARadius1)+
" 2.000 1.00 mm\n");
673 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(HornARadius2)+
" 2.000 "+
str(1.00+HornALength)+
" mm\n");
674 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 "+
str(2.00+HornALength)+
" mm\n")
676 newmac.write(
"/LBNE/det/Horn1PolyOuterRadius "+
str(HornARadiusOC)+
" mm\n")
678 newmac.write(
"/LBNE/det/Horn2PolyPt0RinThickZ "+
str(HornBRadiusOC-15)+
" 2.000 0.00 mm\n");
679 newmac.write(
"/LBNE/det/Horn2PolyPt1RinThickZ "+
str(HornBRadius1)+
" 2.000 1.00 mm\n");
680 newmac.write(
"/LBNE/det/Horn2PolyPt2RinThickZ "+
str(HornBRadius1)+
" 2.000 "+
str(1.00+HornBLength*HornBF1)+
" mm\n");
681 newmac.write(
"/LBNE/det/Horn2PolyPt3RinThickZ "+
str(HornBRadius2)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2))+
" mm\n")
682 newmac.write(
"/LBNE/det/Horn2PolyPt4RinThickZ "+
str(HornBRadius2)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2+HornBF3))+
" mm\n")
683 newmac.write(
"/LBNE/det/Horn2PolyPt5RinThickZ "+
str(HornBRadius3)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2+HornBF3+HornBF4))+
" mm\n")
684 newmac.write(
"/LBNE/det/Horn2PolyPt6RinThickZ "+
str(HornBRadius3)+
" 2.000 "+
str(1.00+HornBLength)+
" mm\n")
685 newmac.write(
"/LBNE/det/Horn2PolyPt7RinThickZ "+
str(HornBRadiusOC-15)+
" 2.000 "+
str(2.00+HornBLength)+
" mm\n")
686 newmac.write(
"/LBNE/det/Horn2PolyOuterRadius "+
str(HornBRadiusOC)+
" mm\n")
688 newmac.write(
"/LBNE/det/Horn3PolyPt0RinThickZ "+
str(HornCRadiusOC-15)+
" 4.000 0.00 mm\n");
689 newmac.write(
"/LBNE/det/Horn3PolyPt1RinThickZ "+
str(HornCRadius1)+
" 4.000 1.00 mm\n");
690 newmac.write(
"/LBNE/det/Horn3PolyPt2RinThickZ "+
str(HornCRadius1)+
" 4.000 "+
str(1.00+HornCLength*HornCF1)+
" mm\n");
691 newmac.write(
"/LBNE/det/Horn3PolyPt3RinThickZ "+
str(HornCRadius2)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2))+
" mm\n")
692 newmac.write(
"/LBNE/det/Horn3PolyPt4RinThickZ "+
str(HornCRadius2)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2+HornCF3))+
" mm\n")
693 newmac.write(
"/LBNE/det/Horn3PolyPt5RinThickZ "+
str(HornCRadius3)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2+HornCF3+HornCF4))+
" mm\n")
694 newmac.write(
"/LBNE/det/Horn3PolyPt6RinThickZ "+
str(HornCRadius3)+
" 4.000 "+
str(1.00+HornCLength)+
" mm\n")
695 newmac.write(
"/LBNE/det/Horn3PolyPt7RinThickZ "+
str(HornCRadiusOC-15)+
" 4.000 "+
str(2.00+HornCLength)+
" mm\n")
696 newmac.write(
"/LBNE/det/Horn3PolyOuterRadius "+
str(HornCRadiusOC)+
" mm\n")
698 if optimization.optname==
"CP_run19":
699 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 1 \n")
700 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 2 \n")
701 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 3 \n")
702 newmac.write(
"/LBNE/det/TargetLengthOutsideHorn 0 m\n")
705 elif s.find(
"/run/initialize")>=0:
707 for j
in range(0,len(optimization.parameter_names)):
708 parameter = optimization.parameter_names[j]
710 if optimization.rhc_parameters_float_separate:
711 if (optimization.parameter_names[j].startswith(
"FHC")
and 714 if (optimization.parameter_names[j].startswith(
"RHC")
and 718 macro_set_stage = optimization.macro_set_stages[j]
719 if(macro_set_stage ==
"Idle"):
720 value = new_values[j]
721 newmac.write(optimization.macro_commands[j]+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
723 if(
"GraphiteTargetFinWidth" in parameter):
726 if optimization.optname
in [
"CP_run5",
"CP_run7",
"CP_run8",
"CP_run13"]:
727 new_beam_size = 1.7 * new_values[j]/10
728 newmac.write(
"/LBNE/generator/beamSigmaX "+
str(new_beam_size)+
" mm \n");
729 newmac.write(
"/LBNE/generator/beamSigmaY "+
str(new_beam_size)+
" mm \n");
731 if parameter ==
"BeamSigma":
732 temp = optimization.macro_commands[j].replace(
"SigmaX",
"SigmaY")
733 newmac.write(temp+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
736 elif s.find(
"/LBNE/run/NEvents")>=0:
737 newmac.write(
"/LBNE/run/NEvents 10 \n")
746 if(optimization.optname==
"CP_run5" or optimization.optname==
"CP_run6" or optimization.optname==
"CP_run7" or optimization.optname==
"CP_run8" or optimization.optname==
"CP_run13"):
747 horn1length = optimization.getParameterValue(parameter_prefix+
"Horn1ICLength1",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength2",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength3",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength4",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength5",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength6",i)+optimization.getParameterValue(parameter_prefix+
"Horn1ICLength7",i)
748 horn2pos = optimization.getParameterValue(parameter_prefix+
"Horn2LongPosition",i)*1000
749 horn2length = 3.63 * optimization.getParameterValue(parameter_prefix+
"Horn2LongRescale",i) * 1000
750 if(horn2pos < horn1length):
751 print "Warning: Configuration not valid because horn2 position is less than horn1 length.. rethrowing" 754 if(optimization.optname==
"CP_run9" or optimization.optname==
"CP_run10"):
755 HornALength = optimization.getParameterValue(
"HornALength",i)
756 HornBLength = optimization.getParameterValue(
"HornBLength",i)
757 HornCLength = optimization.getParameterValue(
"HornCLength",i)
758 HornBLongPosition = optimization.getParameterValue(
"HornBLongPosition",i)
759 HornCLongPosition = optimization.getParameterValue(
"HornCLongPosition",i)
760 HornBF1 = optimization.getParameterValue(
"HornBF1",i);
761 HornBF2 = optimization.getParameterValue(
"HornBF2",i);
762 HornBF3 = optimization.getParameterValue(
"HornBF3",i);
763 HornBF4 = optimization.getParameterValue(
"HornBF4",i);
764 HornCF1 = optimization.getParameterValue(
"HornCF1",i);
765 HornCF2 = optimization.getParameterValue(
"HornCF2",i);
766 HornCF3 = optimization.getParameterValue(
"HornCF3",i);
767 HornCF4 = optimization.getParameterValue(
"HornCF4",i);
769 if HornBF1+HornBF2+HornBF3+HornBF4>0.99:
771 print HornBF1,HornBF2,HornBF3,HornBF4
773 if HornCF1+HornCF2+HornCF3+HornCF4>0.99:
774 print HornCF1,HornCF2,HornCF3,HornCF4
777 if HornBLongPosition < HornALength:
778 print "Failing HornB Start" 780 if HornCLongPosition < HornBLength + HornBLongPosition:
781 print "Failing HornC Start" 783 if HornCLongPosition + HornCLength > 21000:
784 print "Failing HornC End" 787 if(optimization.optname
in [
"CP_run11",
"CP_run15",
"CP_run16",
"CP_run17",
"CP_run18",
"CP_run19",
"CP_run21",
"CP_run22",
"CP_run23",
"CP_run24",
"CP_run25",
"CP_run26",
"CP_run27",
"CP_run28",
"CP_run29",
"CP_run30",
"CP_run31",
"LE_run2"]):
788 HornALength = optimization.getParameterValue(
"HornALength",i)
789 HornBLength = optimization.getParameterValue(
"HornBLength",i)
790 HornCLength = optimization.getParameterValue(
"HornCLength",i)
791 HornBLongPosition = optimization.getParameterValue(
"HornBLongPosition",i)
792 HornCLongPosition = optimization.getParameterValue(
"HornCLongPosition",i)
793 if HornBLongPosition < HornALength:
794 print "Failing HornB Start" 796 if HornCLongPosition < HornBLength + HornBLongPosition:
797 print "Failing HornC Start" 799 if HornCLongPosition + HornCLength > 21000:
800 print "Failing HornC End" 802 if(optimization.optname
in [
"CP_run20"]):
803 HornALength = optimization.getParameterValue(
"HornALength",i)
804 HornBLength = optimization.getParameterValue(
"HornBLength",i)
805 HornCLength = optimization.getParameterValue(
"HornCLength",i)
806 HornBLongPosition = optimization.getParameterValue(
"HornBLongPosition",i)
807 HornCLongPosition = optimization.getParameterValue(
"HornCLongPosition",i)
808 if HornBLongPosition < HornALength:
809 print "Failing HornB Start" 811 if HornCLongPosition < HornBLength + HornBLongPosition:
812 print "Failing HornC Start" 815 if(optimization.optname==
"CP_run12"):
816 HornALength = optimization.getParameterValue(
"HornAICLength1",i)+optimization.getParameterValue(
"HornAICLength2",i)
817 HornBLength = optimization.getParameterValue(
"HornBICLength1",i)+optimization.getParameterValue(
"HornBICLength2",i)+optimization.getParameterValue(
"HornBICLength3",i)+optimization.getParameterValue(
"HornBICLength4",i)+optimization.getParameterValue(
"HornBICLength5",i)
818 HornCLength = optimization.getParameterValue(
"HornCICLength1",i)+optimization.getParameterValue(
"HornCICLength2",i)+optimization.getParameterValue(
"HornCICLength3",i)+optimization.getParameterValue(
"HornCICLength4",i)+optimization.getParameterValue(
"HornCICLength5",i)
819 HornBLongPosition = optimization.getParameterValue(
"HornBLongPosition",i)
820 HornCLongPosition = optimization.getParameterValue(
"HornCLongPosition",i)
821 if HornBLongPosition < HornALength:
822 print "Failing HornB Start" 824 if HornCLongPosition < HornBLength + HornBLongPosition:
825 print "Failing HornC Start" 827 if HornCLongPosition + HornCLength > 21000:
828 print "Failing HornC End"
def GetFractionAtMoreThanXSigma(histo, X)
int open(const char *, int)
Opens a file descriptor.
def MakeMacro(optimization, macro_template, newmac_path, new_values, parameter_prefix="")
def ComputeMean75PercentSensitivityAndError(varfhcfile, varrhcfile, fhcvarenergy=120.0, rhcvarenergy=120.0, antinufrac=0.5, quantity="cp")
def ParametersOkay(optimization, i)
def GetPowerPOTScaleFactor(energy)
def GetPercentile(histo, X)
def AddPlotLabel(label, x, y, size=0.05, color=1, font=62, align=22, angle=0)
def ConvertGraphToHisto(new_bins, pGraph)