1 import ROOT, glob, sys, os
2 from array
import array
3 import Optimizations, OptimizationUtils
5 optimization_name =
"power_test" 19 fluxpath =
"/lbne/data/users/ljf26/fluxfiles/g4lbne/"+optimization.g4lbne_version+
"/QGSP_BERT/" 20 fluxdirs = glob.glob(fluxpath+
"*")
26 if os.path.basename(dir).startswith(
"Optimizations-"+optimization_name):
27 iteration = dir.split(
"/")[9].
split(
"-")[2]
29 varfhcfile = dir+
"/200kA/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_QGSP_BERT_"+os.path.basename(dir)+
"_200kA_LBNEFD_fastmc.root" 30 varrhcfile = dir+
"/-200kA/flux/histos_g4lbne_"+optimization.g4lbne_version+
"_QGSP_BERT_"+os.path.basename(dir)+
"_-200kA_LBNEFD_fastmc.root" 33 energy = optimization.getEnergy(float(iteration),
"FHC")
37 fitness = tfitnesses[0]
38 print "fitness",fitness
39 fitness_error = tfiterrors[0]
42 iterations.append(float(iteration))
43 fitnesses.append(fitness)
44 fitness_errors.append(fitness_error)
45 zero_errors.append(0.0)
53 n_parameters = len(optimization.parameter_names);
54 for i
in range(0,n_parameters):
55 parameter_name = optimization.parameter_names[i]
56 parameter_values.append([])
57 parameter_histos.append(ROOT.TH1F(
"h_parameters_"+
str(i),parameter_name,10,optimization.parameter_lower_limits[i],optimization.parameter_upper_limits[i]));
59 knobturns = optimization.getKnobturns()
61 for iteration
in iterations:
62 if float(iteration)>max_iterations:
continue 63 iteration_found =
False 64 for j
in range(0,len(knobturns)):
65 if knobturns[j][0]==iteration:
66 iteration_found =
True 67 iterations2.append(knobturns[j][0])
68 for i
in range(0,n_parameters):
69 parameter_histos[i].Fill(knobturns[j][1][i])
70 parameter_values[i].append(knobturns[j][1][i])
71 if not iteration_found:
72 print "ERROR: iteration:",iteration,
" found in flux directories but can't find macros to look up knobturns... quitting." 76 canv = ROOT.TCanvas(
"MyCanvas",
"MyCanvas")
78 ROOT.gStyle.SetMarkerStyle(2);
80 for i
in range(0,n_parameters):
82 fitness_vs_parameter = ROOT.TGraphErrors(len(iterations),
array(
'd',parameter_values[i]),
array(
'd',fitnesses),
array(
'd',zero_errors),
array(
'd',fitness_errors))
83 fitness_vs_parameter.GetYaxis().SetTitle(
"Fitness")
84 x_axis_title = optimization.parameter_names[i]
85 if(optimization.parameter_units[i]!=
""):
86 x_axis_title = x_axis_title+
" ("+optimization.parameter_units[i]+
")" 87 fitness_vs_parameter.GetXaxis().SetTitle(x_axis_title);
88 fitness_vs_parameter.GetXaxis().CenterTitle()
89 fitness_vs_parameter.GetYaxis().CenterTitle()
90 fitness_vs_parameter.SetTitle(
"")
91 fitness_vs_parameter.Draw(
"AP");
94 FMC_SENSIT =
"/lbne/data/users/lblpwg_tools/FastMC_Data/outputs/ljf26/Sensitivity_Plots" 96 energies = [20,30,50,60,70,80,90,110,120,130]
97 mean_sensitivities = []
98 for energy
in energies:
101 nh_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP"+
str(
int(energy))+
"GeV_RealisticPower_nh_cp_histos.root")
102 ih_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP"+
str(
int(energy))+
"GeV_RealisticPower_ih_cp_histos.root")
104 nh_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP"+
str(
int(energy))+
"GeV_nh_cp_histos.root")
105 ih_cp_file = ROOT.TFile(FMC_SENSIT+
"/ProtonP"+
str(
int(energy))+
"GeV_ih_cp_histos.root")
110 mean_sensitivities.append((nh_sensitivity+ih_sensitivity)/2)
112 blah = ROOT.TGraph(len(energies),
array(
'd',energies),
array(
'd',mean_sensitivities));
113 blah.SetMarkerColor(2);
114 blah.SetLineColor(2);
115 blah.SetMarkerStyle(21);
116 blah.GetXaxis().SetTitle(
"Proton Energy (GeV)")
117 blah.GetYaxis().SetTitle(
"Average 75% #delta_{CP} Coverage (#sigma)")
120 fitness_vs_parameter.Draw(
"SAMEP");
122 canv.Print(
"plots/"+optimization_name+
"_fitness_vs_"+parameter_name+
".eps")
123 canv.Print(
"plots/"+optimization_name+
"_fitness_vs_"+parameter_name+
".png")
def ComputeMean75PercentSensitivityAndError(varfhcfile, varrhcfile, fhcvarenergy=120.0, rhcvarenergy=120.0, antinufrac=0.5, quantity="cp")
auto array(Array const &a)
Returns a manipulator which will print the specified array.
def GetPercentile(histo, X)
void split(std::string const &s, char c, OutIter dest)