8 from GeneratorModules.EvgenAnalysisAlg
import EvgenAnalysisAlg
9 from AthenaPython.PyAthena
import StatusCode
14 Class for modifying output LHE file from Superchic and Madgraph + ensuring compatibility with Tauola
15 Intended for ultraperipheral collision (UPC) processes i.e. y y -> l+ l-
16 This code also contains a hack that was present in the earlier version in the Generators/Superchic_i/python/LheConverterTauolaPhotonHack.py
17 The hack was recommended by the Tauola authors, intended for the gamma gamma -> tau+ tau- process
18 The hack changes the PDG ID of the initial state particles, from photons to electrons
21 def __init__(self, name='LheConverterUpc', generator='Superchic', mode='Pythia8'):
22 super(LheConverterUpc, self).
__init__(name=name)
26 outFileName =
'events.lhe'
28 leptons = [
'11',
'-11',
'13',
'-13',
'15',
'-15']
36 shutil.move(
'./events.lhe',
'events.lhe_tmpconverter')
42 return StatusCode.Failure
46 Modifies `events.lhe` output file from Madgraph by doing the following:
48 - Changes photon px and py to zero and energy to pz
49 - Recalculates energy scales as an average of lepton pair transverse momentum
52 DOMTree = xml.dom.minidom.parse(self.
inFileName)
53 collection = DOMTree.documentElement
56 init = collection.getElementsByTagName(
'init')
58 13 -13 2.510000e+03 2.510000e+03 0 0 0 0 3 1
59 1.000000e+00 0.000000e+00 1.000000e+00 9999
61 init[0].firstChild.data = init_repl
65 event_header =
r'^(\s*\S*\s*\S*\s*\S*\s*)(\S*)(.*)$'
69 event_particle =
r'^(\s*)([0-9-]+)(\s+[0-9-]+\s+[0-9-]+\s+[0-9-]+\s+[0-9-]+\s+[0-9-]+\s+)(\S+)(\s+)(\S+)(\s+)(\S+)(\s+)(\S+)(.*)$'
71 events = collection.getElementsByTagName(
'event')
72 for i, event
in enumerate(events):
75 nodes = event.getElementsByTagName(
'mgrwt')
77 parent = node.parentNode
78 parent.removeChild(node)
83 particles = re.findall(event_particle, event.firstChild.data, re.MULTILINE)
84 for particle
in particles:
85 particle =
list(particle)
86 if particle[1] ==
'22':
90 particle[9] = particle[7]
92 if self.
mode ==
'Tauolapp':
94 particle[1] =
'11' if float(particle[7]) > 0.0
else '-11'
96 particle[1] =
'-11' if float(particle[7]) > 0.0
else '11'
97 new_particles.append(
''.
join(particle))
98 elif particle[1]
in self.
leptons:
100 lepton_mom.append(
float(particle[3]))
101 lepton_mom.append(
float(particle[5]))
102 new_particles.append(
''.
join(particle))
104 new_particles.append(
''.
join(particle))
107 l1_px, l1_py, l2_px, l2_py = lepton_mom
108 l1_pt = math.sqrt(l1_px**2 + l1_py**2)
109 l2_pt = math.sqrt(l2_px**2 + l2_py**2)
110 energy_scale = f
'{(l1_pt + l2_pt) / 2.:.9E}'
112 header = re.search(event_header, event.firstChild.data, re.MULTILINE)
113 header =
list(header.groups())
114 header[1] = energy_scale
117 event.firstChild.data =
'\n'.
join([
''.
join(header)] + new_particles) +
'\n'
119 event.firstChild.data =
'\n'.
join([
''.
join(header)] + new_particles)
122 output.write(DOMTree.toxml().
replace(
'<?xml version="1.0" ?>',
' '))
126 return StatusCode.Success