1 import ROOT, glob, sys, os, re
2 from array
import array
3 import Optimizations, OptimizationUtils
7 if not len(sys.argv) > 2:
8 print "Please specify an optimization name and configuration number" 11 optimization_name = sys.argv[1]
12 configuration =
int(sys.argv[2])
15 macro_template =
"../../macros/NoSnout.mac" 23 for par_iter
in range(len(optimization.parameter_names)):
24 if par_iter < 2:
continue 26 lower_limit = optimization.parameter_lower_limits[par_iter]
27 upper_limit = optimization.parameter_upper_limits[par_iter]
33 for scan_iter
in range(n_scan_points+1):
35 scan_value = lower_limit + scan_iter*(upper_limit-lower_limit)/n_scan_points
38 macro_output =
"../../macros/Optimizations/"+optimization.optname+
"/"+optimization.optname+
"_"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value)+
".mac" 39 macro_outputRHC =
"../../macros/Optimizations/"+optimization.optname+
"/"+optimization.optname+
"_"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value)+
".mac" 40 if optimization.rhc_parameters_float_separate:
41 macro_output =
"../../macros/Optimizations/"+optimization.optname+
"FHC/"+optimization.optname+
"FHC_"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value)+
".mac" 42 macro_outputRHC =
"../../macros/Optimizations/"+optimization.optname+
"RHC/"+optimization.optname+
"RHC_"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value)+
".mac" 45 oldmac =
open(macro_template)
46 oldmac_lines = oldmac.readlines()
48 newmac =
open(macro_output,
'w')
49 newmacRHC =
open(macro_outputRHC,
'w')
51 par_values = optimization.readVariationFromMacros(configuration)
52 par_values[par_iter] = scan_value
55 if optimization.rhc_parameters_float_separate:
59 for s
in oldmac_lines:
62 output_file = newmacRHC
64 if s.find(
"/LBNE/det/seHornCurrent")>=0:
65 if not mode+
"HornCurrent" in optimization.parameter_names
and not "HornCurrent" in optimization.parameter_names:
67 for j
in range(0,len(optimization.parameter_names)):
68 if optimization.rhc_parameters_float_separate:
69 if (optimization.parameter_names[j].startswith(
"FHC")
and 72 if (optimization.parameter_names[j].startswith(
"RHC")
and 75 parameter = optimization.parameter_names[j]
76 macro_set_stage = optimization.macro_set_stages[j]
78 if macro_set_stage ==
"PreInit":
80 output_file.write(optimization.macro_commands[j]+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
82 if(
"MultiSphereTargetRadius" in parameter):
83 output_file.write(
"/LBNE/det/UseMultiSphereTarget\n")
84 output_file.write(
"/LBNE/det/TargetMaterial Beryllium\n")
85 if(
"SimpleTargetLength" in parameter):
86 output_file.write(
"/LBNE/det/UseSimpleCylindricalTarget\n")
89 if optimization.rhc_parameters_float_separate:
93 if optimization.optname
in [
"CP_run5",
"CP_run7",
"CP_run8",
"CP_run13"]:
94 Horn1OCRadius = par_values[optimization.getParameterIndex(prefix+
"Horn1OCRadius")];
95 Horn1ICRadius1 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICRadius1")];
96 Horn1ICRadius2 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICRadius2")];
97 Horn1ICRadius3 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICRadius3")];
98 Horn1ICRadius4 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICRadius4")];
99 Horn1ICLength1 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength1")];
100 Horn1ICLength2 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength2")];
101 Horn1ICLength3 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength3")];
102 Horn1ICLength4 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength4")];
103 Horn1ICLength5 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength5")];
104 Horn1ICLength6 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength6")];
105 Horn1ICLength7 = par_values[optimization.getParameterIndex(prefix+
"Horn1ICLength7")];
106 output_file.write(
"/LBNE/det/UseHorn1Polycone True \n")
107 output_file.write(
"/LBNE/det/NumInnerPtsHorn1Polycone 10 \n")
108 output_file.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(Horn1OCRadius)+
" 2.000 0.00 mm\n");
109 output_file.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(Horn1ICRadius1)+
" 2.000 1.00 mm\n");
110 output_file.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(Horn1ICRadius1)+
" 2.000 "+
str(1.00+Horn1ICLength1)+
" mm\n");
111 output_file.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(Horn1ICRadius2)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2)+
" mm\n")
112 output_file.write(
"/LBNE/det/Horn1PolyPt4RinThickZ "+
str(Horn1ICRadius2)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3)+
" mm\n")
113 output_file.write(
"/LBNE/det/Horn1PolyPt5RinThickZ "+
str(Horn1ICRadius3)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4)+
" mm\n")
114 output_file.write(
"/LBNE/det/Horn1PolyPt6RinThickZ "+
str(Horn1ICRadius3)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5)+
" mm\n")
115 output_file.write(
"/LBNE/det/Horn1PolyPt7RinThickZ "+
str(Horn1ICRadius4)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6)+
" mm\n")
116 output_file.write(
"/LBNE/det/Horn1PolyPt8RinThickZ "+
str(Horn1ICRadius4)+
" 2.000 "+
str(1.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6+Horn1ICLength7)+
" mm\n")
117 output_file.write(
"/LBNE/det/Horn1PolyPt9RinThickZ "+
str(Horn1OCRadius)+
" 2.000 "+
str(2.00+Horn1ICLength1+Horn1ICLength2+Horn1ICLength3+Horn1ICLength4+Horn1ICLength5+Horn1ICLength6+Horn1ICLength7)+
" mm\n")
118 output_file.write(
"/LBNE/det/Horn1PolyOuterRadius "+
str(Horn1OCRadius)+
" mm\n")
120 output_file.write(
"/LBNE/det/TargetLengthOutsideHorn 0 m\n")
121 elif optimization.optname
in [
"CP_run9",
"CP_run10",
"CP_run11",
"CP_run14",
"CP_run15",
"CP_run16",
"CP_run17",
"CP_run18",
"CP_run19"]:
124 HornARadiusOC = par_values[optimization.getParameterIndex(prefix+
"HornARadiusOC")];
125 HornARadius1 = par_values[optimization.getParameterIndex(prefix+
"HornARadius1")];
126 HornARadius2 = par_values[optimization.getParameterIndex(prefix+
"HornARadius2")];
127 HornALength = par_values[optimization.getParameterIndex(prefix+
"HornALength")];
128 HornAF1 = par_values[optimization.getParameterIndex(prefix+
"HornAF1")];
129 HornBRadiusOC = par_values[optimization.getParameterIndex(prefix+
"HornBRadiusOC")];
130 HornBRadius1 = par_values[optimization.getParameterIndex(prefix+
"HornBRadius1")];
131 HornBRadius2 = par_values[optimization.getParameterIndex(prefix+
"HornBRadius2")];
132 HornBRadius3 = par_values[optimization.getParameterIndex(prefix+
"HornBRadius3")];
133 HornBLength = par_values[optimization.getParameterIndex(prefix+
"HornBLength")];
134 HornBF1 = par_values[optimization.getParameterIndex(prefix+
"HornBF1")];
135 HornBF2 = par_values[optimization.getParameterIndex(prefix+
"HornBF2")];
136 HornBF3 = par_values[optimization.getParameterIndex(prefix+
"HornBF3")];
137 HornBF4 = par_values[optimization.getParameterIndex(prefix+
"HornBF4")];
138 HornBF5 = par_values[optimization.getParameterIndex(prefix+
"HornBF5")];
141 HornCRadiusOC = par_values[optimization.getParameterIndex(prefix+
"HornCRadiusOC")];
142 HornCRadius1 = par_values[optimization.getParameterIndex(prefix+
"HornCRadius1")];
143 HornCRadius2 = par_values[optimization.getParameterIndex(prefix+
"HornCRadius2")];
144 HornCRadius3 = par_values[optimization.getParameterIndex(prefix+
"HornCRadius3")];
145 HornCLength = par_values[optimization.getParameterIndex(prefix+
"HornCLength")];
146 HornCF1 = par_values[optimization.getParameterIndex(prefix+
"HornCF1")];
147 HornCF2 = par_values[optimization.getParameterIndex(prefix+
"HornCF2")];
148 HornCF3 = par_values[optimization.getParameterIndex(prefix+
"HornCF3")];
149 HornCF4 = par_values[optimization.getParameterIndex(prefix+
"HornCF4")];
150 HornCF5 = par_values[optimization.getParameterIndex(prefix+
"HornCF5")];
152 HornBLongPosition = par_values[optimization.getParameterIndex(prefix+
"HornBLongPosition")]
153 HornCLongPosition = par_values[optimization.getParameterIndex(prefix+
"HornCLongPosition")]
155 newmac.write(
"/LBNE/det/NumberOfHornsPolycone 3 \n")
156 newmac.write(
"/LBNE/det/Horn2PolyZStartPos "+
str(HornBLongPosition)+
" \n")
157 newmac.write(
"/LBNE/det/Horn3PolyZStartPos "+
str(HornCLongPosition)+
" \n")
158 newmac.write(
"/LBNE/det/NumInnerPtsHorn1Polycone 5 \n")
159 newmac.write(
"/LBNE/det/NumInnerPtsHorn2Polycone 8 \n")
160 newmac.write(
"/LBNE/det/NumInnerPtsHorn3Polycone 8 \n")
162 newmac.write(
"/LBNE/det/Horn1PolyPt0RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 0.00 mm\n");
163 newmac.write(
"/LBNE/det/Horn1PolyPt1RinThickZ "+
str(HornARadius1)+
" 2.000 1.00 mm\n");
164 newmac.write(
"/LBNE/det/Horn1PolyPt2RinThickZ "+
str(HornARadius1)+
" 2.000 "+
str(1.00+HornALength*HornAF1)+
" mm\n");
165 newmac.write(
"/LBNE/det/Horn1PolyPt3RinThickZ "+
str(HornARadius2)+
" 2.000 "+
str(1.00+HornALength)+
" mm\n")
166 newmac.write(
"/LBNE/det/Horn1PolyPt4RinThickZ "+
str(HornARadiusOC-15)+
" 2.000 "+
str(2.00+HornALength)+
" mm\n")
167 newmac.write(
"/LBNE/det/Horn1PolyOuterRadius "+
str(HornARadiusOC)+
" mm\n")
169 newmac.write(
"/LBNE/det/Horn2PolyPt0RinThickZ "+
str(HornBRadiusOC-15)+
" 2.000 0.00 mm\n");
170 newmac.write(
"/LBNE/det/Horn2PolyPt1RinThickZ "+
str(HornBRadius1)+
" 2.000 1.00 mm\n");
171 newmac.write(
"/LBNE/det/Horn2PolyPt2RinThickZ "+
str(HornBRadius1)+
" 2.000 "+
str(1.00+HornBLength*HornBF1)+
" mm\n");
172 newmac.write(
"/LBNE/det/Horn2PolyPt3RinThickZ "+
str(HornBRadius2)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2))+
" mm\n")
173 newmac.write(
"/LBNE/det/Horn2PolyPt4RinThickZ "+
str(HornBRadius2)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2+HornBF3))+
" mm\n")
174 newmac.write(
"/LBNE/det/Horn2PolyPt5RinThickZ "+
str(HornBRadius3)+
" 2.000 "+
str(1.00+HornBLength*(HornBF1+HornBF2+HornBF3+HornBF4))+
" mm\n")
175 newmac.write(
"/LBNE/det/Horn2PolyPt6RinThickZ "+
str(HornBRadius3)+
" 2.000 "+
str(1.00+HornBLength)+
" mm\n")
176 newmac.write(
"/LBNE/det/Horn2PolyPt7RinThickZ "+
str(HornBRadiusOC-15)+
" 2.000 "+
str(2.00+HornBLength)+
" mm\n")
177 newmac.write(
"/LBNE/det/Horn2PolyOuterRadius "+
str(HornBRadiusOC)+
" mm\n")
179 newmac.write(
"/LBNE/det/Horn3PolyPt0RinThickZ "+
str(HornCRadiusOC-15)+
" 4.000 0.00 mm\n");
180 newmac.write(
"/LBNE/det/Horn3PolyPt1RinThickZ "+
str(HornCRadius1)+
" 4.000 1.00 mm\n");
181 newmac.write(
"/LBNE/det/Horn3PolyPt2RinThickZ "+
str(HornCRadius1)+
" 4.000 "+
str(1.00+HornCLength*HornCF1)+
" mm\n");
182 newmac.write(
"/LBNE/det/Horn3PolyPt3RinThickZ "+
str(HornCRadius2)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2))+
" mm\n")
183 newmac.write(
"/LBNE/det/Horn3PolyPt4RinThickZ "+
str(HornCRadius2)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2+HornCF3))+
" mm\n")
184 newmac.write(
"/LBNE/det/Horn3PolyPt5RinThickZ "+
str(HornCRadius3)+
" 4.000 "+
str(1.00+HornCLength*(HornCF1+HornCF2+HornCF3+HornCF4))+
" mm\n")
185 newmac.write(
"/LBNE/det/Horn3PolyPt6RinThickZ "+
str(HornCRadius3)+
" 4.000 "+
str(1.00+HornCLength)+
" mm\n")
186 newmac.write(
"/LBNE/det/Horn3PolyPt7RinThickZ "+
str(HornCRadiusOC-15)+
" 4.000 "+
str(2.00+HornCLength)+
" mm\n")
187 newmac.write(
"/LBNE/det/Horn3PolyOuterRadius "+
str(HornCRadiusOC)+
" mm\n")
189 newmac.write(
"/LBNE/det/TargetLengthOutsideHorn 0 m\n")
191 if optimization.optname==
"CP_run19":
192 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 1 \n")
193 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 2 \n")
194 newmac.write(
"/LBNE/det/SetPolyconeHornParabolic 3 \n")
198 elif s.find(
"/run/initialize")>=0:
200 for j
in range(0,len(optimization.parameter_names)):
202 if (optimization.parameter_names[j].startswith(
"FHC")
and 205 if (optimization.parameter_names[j].startswith(
"RHC")
and 209 parameter = optimization.parameter_names[j]
211 macro_set_stage = optimization.macro_set_stages[j]
212 if(macro_set_stage ==
"Idle"):
213 value = par_values[j]
214 output_file.write(optimization.macro_commands[j]+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
219 if(parameter==prefix+
"GraphiteTargetFinWidth"):
220 if optimization.optname
in [
"CP_run5",
"CP_run7",
"CP_run8",
"CP_run13"]:
223 new_beam_size = 1.7 * par_values[j]/10
224 output_file.write(
"/LBNE/generator/beamSigmaX "+
str(new_beam_size)+
" mm \n");
225 output_file.write(
"/LBNE/generator/beamSigmaY "+
str(new_beam_size)+
" mm \n");
226 if parameter ==
"BeamSigma":
227 temp = optimization.macro_commands[j].replace(
"SigmaX",
"SigmaY")
228 newmac.write(temp+
" "+
str(value)+
" "+optimization.parameter_units[j]+
"\n")
232 output_file.write(s);
238 print "prefix",prefix
239 print "opt parnames",optimization.parameter_names[par_iter]
240 if not optimization.rhc_parameters_float_separate:
241 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode neutrino --notuples -m Optimizations-"+optimization.optname+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
242 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode antineutrino --notuples -m Optimizations-"+optimization.optname+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
243 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode neutrino --notuples -p FTFP_BERT -m Optimizations-"+optimization.optname+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
244 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode antineutrino --notuples -p FTFP_BERT -m Optimizations-"+optimization.optname+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
246 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode neutrino --notuples -m Optimizations-"+optimization.optname+mode+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
247 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode neutrino --notuples -p FTFP_BERT -m Optimizations-"+optimization.optname+mode+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
249 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode antineutrino --notuples -m Optimizations-"+optimization.optname+mode+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
250 os.system(
"python ProductionScripts/submit_flux.py -n 100000 -f 1 -l 5 --mode antineutrino --notuples -p FTFP_BERT -m Optimizations-"+optimization.optname+mode+
"-"+
str(configuration)+
"_Scan_"+optimization.parameter_names[par_iter]+
"_"+
str(scan_value))
252 os.chdir(
"BeamSimStudies/GeneticOptimization")
int open(const char *, int)
Opens a file descriptor.