copy_fastmc_flux.py
Go to the documentation of this file.
1 ##################################################
2 ##
3 ## copy_fastmc_flux.py
4 ##
5 ## Laura Fields
6 ## Aug 2013
7 ##
8 ## Copies FastMC flux histograms from user area
9 ## to FMC area
10 ##
11 ###################################################
12 
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
18 
19 
20 ###################################################
21 #
22 # Setup parser that reads in options
23 #
24 ###################################################
25 
26 usage = "usage: %prog [options]"
27 parser = OptionParser(usage=usage)
28 
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")
49 
50 
51 (options, args) = parser.parse_args()
52 
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"
56  sys.exit()
57 
58 ###################################################
59 #
60 # Find source files
61 #
62 ###################################################
63 username = os.getenv("USER")
64 
65 sources = []
66 
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")
71 
72 globes_sources = []
73 
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")
78 
79 ###################################################
80 #
81 # Define destination
82 #
83 ###################################################
84 
85 dests = []
86 
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."
89 
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")
94 
95 globes_dests = []
96 
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."
99 
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")
104 
105 for i in range(0,4):
106  if os.path.exists(sources[i]):
107  print "Copying "+sources[i]+" to "+dests[i]
108  else:
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]
112  else:
113  print "ERROR: Could not find "+globes_sources[i]
114 
115 if options.test:
116 
117  print "You requested test mode, so I'm not actually going to copy anything."
118  sys.exit()
119 
120 ###################################################
121 #
122 # Create Directories
123 #
124 ###################################################
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)
128 
129 ###################################################
130 #
131 # Add power factor for fast mc
132 #
133 ###################################################
134 power_factor = OptimizationUtils.GetPowerPOTScaleFactor(float(options.proton_energy))
135 for i in range(0,4):
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)+"\)")
139 
140 
141 ###################################################
142 #
143 # Copy files
144 #
145 ###################################################
146 for i in range(0,4):
147  if os.path.exists(sources[i]):
148  shutil.copyfile(sources[i],dests[i])
149  try:
150  os.chmod(dests[i],0777)
151  except:
152  print "Could not change permissions for file: "+dests[i]
153 
154  if os.path.exists(globes_sources[i]):
155  shutil.copyfile(globes_sources[i],globes_dests[i])
156  try:
157  os.chmod(globes_dests[i],0777)
158  except:
159  print "Could not change permissions for file: "+globes_dests[i]
160 
161 ###################################################
162 #
163 # Create RIK files
164 #
165 ###################################################
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)
static QCString str