1 """! Miscellaneous math functions."""
6 logger = logging.getLogger(
"hpsmc.func")
9 def lint(target_dz, num_electrons, density=6.306e-14):
11 Calculate integrated luminosity.
12 @param target_dz target thickness in cm
13 @param num_electrons number of electrons in bunch
14 @param density 1/(cm*pb), default value is for tungsten
15 @return integrated luminosity in 1/pb
17 return density * target_dz * num_electrons
22 Extract cross-section from gzipped LHE file.
23 WARNING: This function does not work!
25 \todo remove or replace by more useful function
26 @param filename name of input file
28 logger.info(
"Using gzip to open '%s'" % filename)
30 with gzip.open(filename,
'rb')
as in_file:
31 lines = in_file.readlines()
34 if "Integrated weight" in line:
35 xs = float(line[line.rfind(
":") + 1:].strip())
38 if "xs" not in locals():
39 raise Exception(
"Could not find 'Integrated weight' in LHE input file.")
44 def mu(filename, target_dz, num_electrons):
46 Calculate mu = number of events per bunch.
47 WARNING: This function does not work properly because csection() is broken!
49 @param filename name of input LHE input file containing cross section
50 @param target_dz target thickness in cm
51 @param num_electrons number of electrons in bunch
52 @return number of events per bunch (L_int[1/pb] * xsec[pb])
54 return lint(target_dz, num_electrons) *
csection(filename)
59 Read number of events in file from LHE header and optionally confirm by counting <event> blocks.
60 @param filename name of input LHE file
61 @param confirm set to True to confirm number of events
63 with gzip.open(filename,
'rb')
as in_file:
64 lines = in_file.readlines()
68 nevents = int(line.split()[0])
70 if "nevents" not in locals():
71 raise Exception(
"Could not find 'nevents' in LHE input file.")
78 if event_count != nevents:
79 raise Exception(
"The number of events %d from header does not match the count %d in file '%s'." % (nevents, event_count, filename))
84 def nbunches(filename, target_dz, num_electrons):
86 Get the approximate number of beam bunches represented by an LHE file from its event count.
87 @param filename name of input LHE file
88 @param target_dz target thickness in cm
89 @param num_electrons number of electrons in bunch
92 m =
mu(filename, target_dz, num_electrons)
98 echo "Transmuting A's to photons..."
100 sed -i 's/\\([:blank:]*\\)622 /\1 22 /' wab.lhe
def csection(filename)
Extract cross-section from gzipped LHE file.
def nbunches(filename, target_dz, num_electrons)
Get the approximate number of beam bunches represented by an LHE file from its event count.
def lint(target_dz, num_electrons, density=6.306e-14)
Calculate integrated luminosity.
def nevents(filename, confirm=False)
Read number of events in file from LHE header and optionally confirm by counting <event> blocks.
def mu(filename, target_dz, num_electrons)
Calculate mu = number of events per bunch.