13 from optparse
import OptionParser
14 import sys, os, subprocess, shutil
15 opt_path = os.path.abspath(
'../BeamSimStudies/GeneticOptimization/')
16 sys.path.append(opt_path)
17 import OptimizationUtils
26 usage =
"usage: %prog [options]" 27 parser = OptionParser(usage=usage)
29 parser.add_option(
"-d",
"--fmc_dir", dest=
"fmc_dir",
30 help=
"Name of directory you want to create in $FMC_FLUX_FILES", default=
"")
31 parser.add_option(
"-c",
"--current", dest=
"current",
32 help=
"Magnitude of horn current", default=
"neutrino")
33 parser.add_option(
"-p",
"--physics_list", dest=
"physics_list",
34 help=
"Geant4 Physics List", default=
"QGSP_BERT");
35 parser.add_option(
"-v",
"--g4lbne_version", dest=
"g4lbne_version",
36 help=
"G4LBNE version", default=
"v2r4p1");
37 parser.add_option(
"-w",
"--fmc_version", dest=
"fmc_version",
38 help=
"FMC version", default=
"v3r2p4b");
39 parser.add_option(
"-m",
"--macro", dest=
"macro",
40 help=
"G4LBNE Macro", default=
"nubeam-G4PBeam-stdnubeam")
41 parser.add_option(
"-t",
"--test", dest=
"test",action=
"store_true",
42 help=
"Test mode -- just print file locations but don't move anything", default=
False)
43 parser.add_option(
"-f",
"--fdloc", dest=
"fdloc",
44 help=
"Far Detector Location", default=
"LBNEFD");
45 parser.add_option(
"-n",
"--ndloc", dest=
"ndloc",
46 help=
"Near Detector Location", default=
"LBNEND");
47 parser.add_option(
"-e",
"--proton_energy", dest=
"proton_energy",
48 help=
"Primary Proton Beam Energy in GeV")
51 (options, args) = parser.parse_args()
53 if options.fmc_dir ==
"":
54 print "\nPlease specify a $FMC_FLUX_FILES subdirectory name using --fmc_dir flag" 55 print "Execute \"python copy_fastmc_flux.py --help\" for more info\n" 63 username = os.getenv(
"USER")
67 sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_"+options.current+
"_"+options.fdloc+
"_fastmc.root")
68 sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/anti"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_anti"+options.current+
"_"+options.fdloc+
"_fastmc.root")
69 sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_"+options.current+
"_"+options.ndloc+
"_fastmc.root")
70 sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/anti"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_anti"+options.current+
"_"+options.ndloc+
"_fastmc.root")
74 globes_sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_"+options.current+
"_"+options.fdloc+
"_globes_flux.txt")
75 globes_sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/anti"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_anti"+options.current+
"_"+options.fdloc+
"_globes_flux.txt")
76 globes_sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_"+options.current+
"_"+options.ndloc+
"_globes_flux.txt")
77 globes_sources.append(
"/dune/data/users/"+username+
"/fluxfiles/g4lbne/"+options.g4lbne_version+
"/"+options.physics_list+
"/"+options.macro+
"/anti"+options.current+
"/flux/histos_g4lbne_"+options.g4lbne_version+
"_"+options.physics_list+
"_"+options.macro+
"_anti"+options.current+
"_"+options.ndloc+
"_globes_flux.txt")
87 if not os.getenv(
"FMC_FLUX_FILES"):
88 print "$FMC_FLUX_FILES is not set. Please run the FastMC Setup before running this script." 90 dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_FHC_FD.root")
91 dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_RHC_FD.root")
92 dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_FHC_ND.root")
93 dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_RHC_ND.root")
97 if not os.getenv(
"FMC_FLUX_FILES"):
98 print "$FMC_FLUX_FILES is not set. Please run the FastMC Setup before running this script." 100 globes_dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_FHC_FD_globes_flux.txt")
101 globes_dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_RHC_FD_globes_flux.txt")
102 globes_dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_FHC_ND_globes_flux.txt")
103 globes_dests.append(os.getenv(
"FMC_FLUX_FILES")+
"/"+options.fmc_version+
"/"+options.fmc_dir+
"/g4lbne_"+options.fmc_version+
"_RHC_ND_globes_flux.txt")
106 if os.path.exists(sources[i]):
107 print "Copying "+sources[i]+
" to "+dests[i]
109 print "ERROR: Could not find "+sources[i]
110 if os.path.exists(globes_sources[i]):
111 print "Copying "+globes_sources[i]+
" to "+globes_dests[i]
113 print "ERROR: Could not find "+globes_sources[i]
117 print "You requested test mode, so I'm not actually going to copy anything." 125 if not os.path.exists(os.path.dirname(dests[0])):
126 os.makedirs(os.path.dirname(dests[0]))
127 os.chmod(os.path.dirname(dests[0]),0777)
136 if os.path.exists(sources[i]):
137 print (
"root -q -b addPowerFactor.C\(\\\""+sources[i]+
"\\\","+
str(power_factor)+
"\)")
138 os.system(
"root -q -b addPowerFactor.C\(\\\""+sources[i]+
"\\\","+
str(power_factor)+
"\)")
147 if os.path.exists(sources[i]):
148 shutil.copyfile(sources[i],dests[i])
150 os.chmod(dests[i],0777)
152 print "Could not change permissions for file: "+dests[i]
154 if os.path.exists(globes_sources[i]):
155 shutil.copyfile(globes_sources[i],globes_dests[i])
157 os.chmod(globes_dests[i],0777)
159 print "Could not change permissions for file: "+globes_dests[i]
166 os.system(
"root -b -q $FMC_GENIE/addfineflux.C\\(\\\""+dests[0]+
"\\)")
167 os.system(
"root -b -q $FMC_GENIE/addfineflux.C\\(\\\""+dests[1]+
"\\)")
168 os.system(
"root -b -q $FMC_GENIE/addfineflux.C\\(\\\""+dests[2]+
"\\)")
169 os.system(
"root -b -q $FMC_GENIE/addfineflux.C\\(\\\""+dests[3]+
"\\)")
def GetPowerPOTScaleFactor(energy)