ATLAS Offline Software
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
python.LheConverterUpc.LheConverterUpc Class Reference
Inheritance diagram for python.LheConverterUpc.LheConverterUpc:
Collaboration diagram for python.LheConverterUpc.LheConverterUpc:

Public Member Functions

def __init__ (self, name='LheConverterUpc', generator='Superchic', mode='Pythia8')
 
def initialize (self)
 
def convert (self)
 

Public Attributes

 generator
 
 mode
 
 inFileName
 
 done
 

Static Public Attributes

string outFileName = 'events.lhe'
 
bool done = False
 
list leptons = ['11', '-11', '13', '-13', '15', '-15']
 

Detailed Description

Class for modifying output LHE file from Superchic and Madgraph + ensuring compatibility with Tauola
Intended for ultraperipheral collision (UPC) processes i.e. y y -> l+ l-
This code also contains a hack that was present in the earlier version in the Generators/Superchic_i/python/LheConverterTauolaPhotonHack.py
The hack was recommended by the Tauola authors, intended for the gamma gamma -> tau+ tau- process
The hack changes the PDG ID of the initial state particles, from photons to electrons

Definition at line 12 of file LheConverterUpc.py.

Constructor & Destructor Documentation

◆ __init__()

def python.LheConverterUpc.LheConverterUpc.__init__ (   self,
  name = 'LheConverterUpc',
  generator = 'Superchic',
  mode = 'Pythia8' 
)

Definition at line 21 of file LheConverterUpc.py.

21  def __init__(self, name='LheConverterUpc', generator='Superchic', mode='Pythia8'):
22  super(LheConverterUpc, self).__init__(name=name)
23  self.generator = generator # options: 'Superchic' (default), 'Madgraph5'
24  self.mode = mode # options: 'Pythia8' (default), 'Tauolapp'
25 

Member Function Documentation

◆ convert()

def python.LheConverterUpc.LheConverterUpc.convert (   self)
Modifies `events.lhe` output file from Madgraph by doing the following:
    - Replaces init block
    - Changes photon px and py to zero and energy to pz
    - Recalculates energy scales as an average of lepton pair transverse momentum

Definition at line 44 of file LheConverterUpc.py.

44  def convert(self):
45  '''
46  Modifies `events.lhe` output file from Madgraph by doing the following:
47  - Replaces init block
48  - Changes photon px and py to zero and energy to pz
49  - Recalculates energy scales as an average of lepton pair transverse momentum
50  '''
51  if not self.done:
52  DOMTree = xml.dom.minidom.parse(self.inFileName)
53  collection = DOMTree.documentElement
54 
55  # Replace init block
56  init = collection.getElementsByTagName('init')
57  init_repl = r'''
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
60  '''
61  init[0].firstChild.data = init_repl
62 
63  # The comment line below indicates which part of the regex grabs the parton-level information that's to be modified. The index in list(header.groups()) is also shown
64  # energy scale [1]
65  event_header = r'^(\s*\S*\s*\S*\s*\S*\s*)(\S*)(.*)$'
66 
67  # The comment line below indicates which part of the regex grabs the parton-level information that's to be modified. The index in list(particle) is also shown
68  # pdgid [1] px [3] py [5] pz [7] e [9]
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+)(.*)$'
70 
71  events = collection.getElementsByTagName('event')
72  for i, event in enumerate(events):
73 
74  # Remove the <mgrwt> block in case of Madgraph (not needed in UPC)
75  nodes = event.getElementsByTagName('mgrwt')
76  for node in nodes:
77  parent = node.parentNode
78  parent.removeChild(node)
79 
80  new_particles = []
81  lepton_mom = []
82 
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': # photon
87  # Zero photon transverse momentum, change energy to be equal pz
88  particle[3] = '0.'
89  particle[5] = '0.'
90  particle[9] = particle[7]
91  # If Tauolapp requested, change PID of photons to electrons (hack recommended by Tauola authors)
92  if self.mode == 'Tauolapp':
93  if i%2 == 0:
94  particle[1] = '11' if float(particle[7]) > 0.0 else '-11'
95  else:
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:
99  # Read leptons px and py
100  lepton_mom.append(float(particle[3]))
101  lepton_mom.append(float(particle[5]))
102  new_particles.append(''.join(particle))
103  else:
104  new_particles.append(''.join(particle))
105 
106  # Calculate new energy scale
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}'
111 
112  header = re.search(event_header, event.firstChild.data, re.MULTILINE)
113  header = list(header.groups())
114  header[1] = energy_scale
115 
116  if self.generator == 'Superchic':
117  event.firstChild.data = '\n'.join([''.join(header)] + new_particles) + '\n'
118  if self.generator == 'Madgraph5':
119  event.firstChild.data = '\n'.join([''.join(header)] + new_particles)
120 
121  with open(self.outFileName, 'w') as output:
122  output.write(DOMTree.toxml().replace('<?xml version="1.0" ?>', ' '))
123 
124  self.done = True
125 
126  return StatusCode.Success
127 

◆ initialize()

def python.LheConverterUpc.LheConverterUpc.initialize (   self)

Definition at line 30 of file LheConverterUpc.py.

30  def initialize(self):
31 
32  self.inFileName = self.fileName
33 
34  if self.inFileName==self.outFileName:
35  import shutil
36  shutil.move('./events.lhe','events.lhe_tmpconverter')
37  self.inFileName = 'events.lhe_tmpconverter'
38  if(os.path.isfile(self.inFileName)):
39  print(self.fileName)
40  return self.convert()
41  else:
42  return StatusCode.Failure
43 

Member Data Documentation

◆ done [1/2]

bool python.LheConverterUpc.LheConverterUpc.done = False
static

Definition at line 27 of file LheConverterUpc.py.

◆ done [2/2]

python.LheConverterUpc.LheConverterUpc.done

Definition at line 124 of file LheConverterUpc.py.

◆ generator

python.LheConverterUpc.LheConverterUpc.generator

Definition at line 23 of file LheConverterUpc.py.

◆ inFileName

python.LheConverterUpc.LheConverterUpc.inFileName

Definition at line 32 of file LheConverterUpc.py.

◆ leptons

list python.LheConverterUpc.LheConverterUpc.leptons = ['11', '-11', '13', '-13', '15', '-15']
static

Definition at line 28 of file LheConverterUpc.py.

◆ mode

python.LheConverterUpc.LheConverterUpc.mode

Definition at line 24 of file LheConverterUpc.py.

◆ outFileName

string python.LheConverterUpc.LheConverterUpc.outFileName = 'events.lhe'
static

Definition at line 26 of file LheConverterUpc.py.


The documentation for this class was generated from the following file:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
initialize
void initialize()
Definition: run_EoverP.cxx:894
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TMVAToMVAUtils::convert
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
Definition: TMVAToMVAUtils.h:114
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
readCCLHist.float
float
Definition: readCCLHist.py:83