1 import ROOT, glob, sys, os
2 from array
import array
3 import Optimizations, OptimizationUtils
7 if not len(sys.argv) > 1:
8 print "Please specify an optimization name" 11 optimization_name = sys.argv[1]
13 max_configurations = 3200
16 max_configurations =
int(sys.argv[2])
30 fluxpath = optimization.output_location+
"users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/"+optimization.physics_list+
"/" 31 fluxdirs = glob.glob(fluxpath+
"*")
32 if optimization.rhc_parameters_float_separate:
33 fluxdirs=glob.glob(fluxpath+
"*FHC*")
40 if os.path.basename(dir).startswith(
"Optimizations-"+optimization_name):
41 configuration = dir.split(
"/")[9].
split(
"-")[2]
43 if float(configuration) >max_configurations:
continue 44 [fitness_types,tfitnesses,fiterrors] = optimization.getFitness(float(configuration))
45 fitness = tfitnesses[0]
46 fitness_error = fiterrors[0]
47 print "AAAA",configuration, fitness, fitness_error
50 configurations.append(float(configuration))
51 fitnesses.append(fitness)
52 fitness_errors.append(fitness_error)
53 zero_errors.append(0.0)
56 ordered_indices = [i[0]
for i
in sorted(
enumerate(fitnesses), key=
lambda x:x[1],reverse=
True)]
58 knobturns = optimization.getKnobturns()
61 config_number = configurations[ordered_indices[i]]
63 print "config_number",config_number
66 for j
in range(0,len(knobturns)):
67 if float(knobturns[j][0])==float(config_number):
71 print "ERROR: Could not find knobs for configuration",config_number
72 knob_names = optimization.parameter_names
74 print "\n\nFitness rank:",i+1
75 print "Configuration number:",
int(config_number)
76 all_fitnesses = optimization.getFitness(
int(config_number))
78 print " ",all_fitnesses
80 print " ",optimization.getFitness(
int(config_number),
"mh")
82 for j
in range(0,len(knobturns[knob_index][1])):
83 print " ",optimization.parameter_names[j],knobturns[knob_index][1][j]
86 nom_flux_file_fhc = ROOT.TFile(
"/lbne/data/users/ljf26/fluxfiles/g4lbne/v3r2p4/QGSP_BERT/Nominal/200kA/flux/histos_g4lbne_v3r2p4_QGSP_BERT_Nominal_200kA_LBNEFD_fastmc.root")
87 nom_flux_file_rhc = ROOT.TFile(
"/lbne/data/users/ljf26/fluxfiles/g4lbne/v3r2p4/QGSP_BERT/Nominal/-200kA/flux/histos_g4lbne_v3r2p4_QGSP_BERT_Nominal_-200kA_LBNEFD_fastmc.root")
90 nom_flux.append(nom_flux_file_fhc.Get(
"numu_flux"))
91 nom_flux.append(nom_flux_file_fhc.Get(
"numubar_flux"))
92 nom_flux.append(nom_flux_file_fhc.Get(
"nue_flux"))
93 nom_flux.append(nom_flux_file_fhc.Get(
"nuebar_flux"))
94 nom_flux.append(nom_flux_file_rhc.Get(
"numu_flux"))
95 nom_flux.append(nom_flux_file_rhc.Get(
"numubar_flux"))
96 nom_flux.append(nom_flux_file_rhc.Get(
"nue_flux"))
97 nom_flux.append(nom_flux_file_rhc.Get(
"nuebar_flux"))
101 var_flux_files_fhc = []
102 var_flux_files_rhc = []
104 new_bins = [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8]
105 for i
in range(0,n_fluxes_to_plot):
107 configuration = configurations[ordered_indices[i]]
108 print "configuration",configuration
109 if optimization.rhc_parameters_float_separate:
110 var_flux_files_fhc.append(ROOT.TFile(optimization.output_location+
"users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/"+optimization.physics_list+
"/Optimizations-"+optimization_name+
"FHC-"+
str(
int(configuration))+
"/200kA/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_"+optimization.physics_list+
"_Optimizations-"+optimization_name+
"FHC-"+
str(
int(configuration))+
"_200kA_"+optimization.detector_location_name+
"_fastmc.root"))
111 var_flux_files_rhc.append(ROOT.TFile(optimization.output_location+
"users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/"+optimization.physics_list+
"/Optimizations-"+optimization_name+
"RHC-"+
str(
int(configuration))+
"/-200kA/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_"+optimization.physics_list+
"_Optimizations-"+optimization_name+
"RHC-"+
str(
int(configuration))+
"_-200kA_"+optimization.detector_location_name+
"_fastmc.root"))
113 var_flux_files_fhc.append(ROOT.TFile(optimization.output_location+
"users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/"+optimization.physics_list+
"/Optimizations-"+optimization_name+
"-"+
str(
int(configuration))+
"/neutrino/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_"+optimization.physics_list+
"_Optimizations-"+optimization_name+
"-"+
str(
int(configuration))+
"_neutrino_"+optimization.detector_location_name+
"_fastmc.root"))
114 var_flux_files_rhc.append(ROOT.TFile(optimization.output_location+
"users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/"+optimization.physics_list+
"/Optimizations-"+optimization_name+
"-"+
str(
int(configuration))+
"/antineutrino/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_"+optimization.physics_list+
"_Optimizations-"+optimization_name+
"-"+
str(
int(configuration))+
"_antineutrino_"+optimization.detector_location_name+
"_fastmc.root"))
116 var_fluxes.append([])
117 var_fluxes[i].append(var_flux_files_fhc[i].Get(
"numu_flux"))
118 var_fluxes[i].append(var_flux_files_fhc[i].Get(
"numubar_flux"))
119 var_fluxes[i].append(var_flux_files_fhc[i].Get(
"nue_flux"))
120 var_fluxes[i].append(var_flux_files_fhc[i].Get(
"nuebar_flux"))
121 var_fluxes[i].append(var_flux_files_rhc[i].Get(
"numu_flux"))
122 var_fluxes[i].append(var_flux_files_rhc[i].Get(
"numubar_flux"))
123 var_fluxes[i].append(var_flux_files_rhc[i].Get(
"nue_flux"))
124 var_fluxes[i].append(var_flux_files_rhc[i].Get(
"nuebar_flux"))
125 fhcenergy = optimization.getEnergy(configuration,
"FHC")
126 rhcenergy = optimization.getEnergy(configuration,
"RHC")
127 print "Energies",fhcenergy,rhcenergy
134 print scale_factor_fhc
136 var_fluxes[i][j] = var_fluxes[i][j].Rebin(len(new_bins)-1,
"var_flux_"+
str(j),
array(
'd',new_bins))
137 var_fluxes[i][j].
Scale(scale_factor_fhc)
138 var_fluxes[i][j].
Scale(1.0,
"width")
140 var_fluxes[i][j] = var_fluxes[i][j].Rebin(len(new_bins)-1,
"var_flux_"+
str(j),
array(
'd',new_bins))
141 var_fluxes[i][j].
Scale(scale_factor_rhc)
142 var_fluxes[i][j].
Scale(1.0,
"width")
146 nom_flux[j] = nom_flux[j].Rebin(len(new_bins)-1,
"nom_flux",
array(
'd',new_bins))
147 nom_flux[j].
Scale(7.5e13/1.2,
"width")
150 canv = ROOT.TCanvas(
"MyCanvas",
"MyCanvas")
151 maxes = [nom_flux[j].GetMaximum()]
157 nom_flux[j].SetMaximum(plot_max)
158 nom_flux[j].SetTitle(
"")
161 frame = ROOT.TH2D(
"frame",
"frame",100,0,8,100,0,plot_max);
162 frame.GetXaxis().SetTitle(nom_flux[j].GetXaxis().GetTitle())
163 frame.GetYaxis().SetTitle(nom_flux[j].GetYaxis().GetTitle().replace(
"POT",
"s"))
164 frame.GetXaxis().CenterTitle()
165 frame.GetYaxis().CenterTitle()
169 nom_flux[j].Draw(
"HSAME")
172 for i
in range(0,n_var_plots):
173 var_fluxes[i][j].SetLineColor(colors[i])
175 var_fluxes[i][j].SetLineWidth(4);
177 var_fluxes[i][j].SetLineWidth(2);
178 var_fluxes[i][j].Draw(
"HSAME")
180 nom_flux[j].Draw(
"HSAME")
182 leg = ROOT.TLegend(0.6,0.6,0.8,0.8)
183 leg.SetBorderSize(0);
185 leg.AddEntry(nom_flux[j],
"Nominal",
"l");
187 labels.append(
"Optimized (#"+
str(
int(configurations[ordered_indices[0]]))+
")")
188 labels.append(
"2nd Best (#"+
str(
int(configurations[ordered_indices[1]]))+
")")
189 labels.append(
"3rd Best (#"+
str(
int(configurations[ordered_indices[2]]))+
")")
190 labels.append(
"4th Best (#"+
str(
int(configurations[ordered_indices[3]]))+
")")
192 for i
in range(0,n_var_plots):
193 leg.AddEntry(var_fluxes[i][j],labels[i],
"l")
196 flavor_strings = [
"numu_fhc",
"numubar_fhc",
"nue_fhc",
"nuebar_fhc",
"numu_rhc",
"numubar_rhc",
"nue_rhc",
"nuebar_rhc"]
197 canv.Print(
"plots/"+optimization_name+
"_"+flavor_strings[j]+
"_best_fluxes.eps");
198 canv.Print(
"plots/"+optimization_name+
"_"+flavor_strings[j]+
"_best_fluxes.png");
Scale(size_t pos, T factor) -> Scale< T >
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
def GetPowerPOTScaleFactor(energy)
static int max(int a, int b)
void split(std::string const &s, char c, OutIter dest)