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

Public Member Functions

def __init__ (self, info, particles, extra_lines=None, spurious_event_markup=False)
 
def from_lines (cls, lines)
 
def is_buggy (self)
 
def to_string (self)
 
def __len__ (self)
 
def __getitem__ (self, index)
 
def __delitem__ (self, index)
 

Public Attributes

 info
 
 particles
 
 extra_lines
 
 spurious_event_markup
 

Detailed Description

Definition at line 98 of file LHETools.py.

Constructor & Destructor Documentation

◆ __init__()

def LHETools.Event.__init__ (   self,
  info,
  particles,
  extra_lines = None,
  spurious_event_markup = False 
)

Definition at line 99 of file LHETools.py.

99  def __init__(self, info, particles, extra_lines=None, spurious_event_markup=False):
100  self.info = info
101  self.particles = particles
102  self.extra_lines = extra_lines or []
103  self.spurious_event_markup = spurious_event_markup
104 
105  for p in self.particles:
106  p.event = self
107 

Member Function Documentation

◆ __delitem__()

def LHETools.Event.__delitem__ (   self,
  index 
)

Definition at line 168 of file LHETools.py.

168  def __delitem__(self, index):
169  if not isinstance(index, (int)):
170  LHEToolsLog.error("Index must be integer")
171  raise TypeError
172 
173  # When removing a particle at a location ``index`` -- which corresponds
174  # to LHE id ``i_lhe`` -- we need to correct two things:
175  #
176  # 1.) Any particle that had ``i_lhe`` as mother, needs to get the
177  # mother of the particle to be removed as mother.
178  #
179  # - If both have exactly one mother, perform the replacement
180  # verbatim.
181  # - If the particle that is deleted has two mothers but the
182  # child particle has only one (the particle to be deleted),
183  # set the two mother reference of the child particle to the
184  # ones of the particle to be deleted.
185  # - If the particle that is deleted has one mother but the
186  # child particle has two, abort.
187  #
188  # 2.) Since we've changed the LHE indexing, any particle that had a
189  # mother reference ``mother > i_lhe`` must get a new mother
190  # reference ``mother - 1``
191  p_rm = self[index]
192  i_lhe = index + 1
193 
194  mo0, mo1 = p_rm.mother0, p_rm.mother1
195  for p in self.particles:
196  if p is p_rm:
197  continue
198 
199  if p.mother0 == i_lhe or p.mother1 == i_lhe:
200  if p.mother0 != p.mother1:
201  LHEToolsLog.error("Can not delete particle whose child has also other parents")
202  raise RuntimeError
203 
204  p.mother0 = mo0
205  p.mother1 = mo1
206 
207  # Remove the particle.
208  del self.particles[index]
209 
210  for p in self.particles:
211  if p.mother0 > i_lhe:
212  p.mother0 -= 1
213  if p.mother1 > i_lhe:
214  p.mother1 -= 1
215 
216  # Decrement the particle counter.
217  self.info.nparticles -= 1
218 
219 

◆ __getitem__()

def LHETools.Event.__getitem__ (   self,
  index 
)

Definition at line 161 of file LHETools.py.

161  def __getitem__(self, index):
162  if not isinstance(index, (int)):
163  LHEToolsLog.error("Index must be integer")
164  raise TypeError
165 
166  return self.particles[index]
167 

◆ __len__()

def LHETools.Event.__len__ (   self)

Definition at line 158 of file LHETools.py.

158  def __len__(self):
159  return len(self.particles)
160 

◆ from_lines()

def LHETools.Event.from_lines (   cls,
  lines 
)

Definition at line 109 of file LHETools.py.

109  def from_lines(cls, lines):
110  info = None
111  particles = []
112  extra_lines = []
113  spurious_event_markup = False
114  event_markup = re.compile('<event>')
115 
116  for i, datum in enumerate(lines):
117  # there shouldn't be a <event> markup in the middle of the event record; if yes, we shouldn't keep the event
118  if event_markup.match(datum):
119  LHEToolsLog.warning("Spurious <event> markup was found in the middle of an event record. Probably the result of one event being incompletely written.")
120  spurious_event_markup = True
121 
122  # The first line is the info block.
123  if not info:
124  info = EventInfo.from_string(datum)
125  if info.invalid:
126  LHEToolsLog.warning("Could not retrieve EventInfo from input lhe file")
127  continue
128 
129  # The lines [1, N_PARTICLE] define particles.
130  if 1 <= i <= info.nparticles:
131  p = Particle.from_string(datum)
132  if p.invalid:
133  LHEToolsLog.warning("Could not retrieve Particle from input lhe file")
134  particles.append(p)
135  continue
136 
137  # All subsequent lines are additional configuration which is
138  # retrieved but isn't parsed.
139  extra_lines.append(datum)
140 
141  return cls(info=info,
142  particles=particles,
143  extra_lines=extra_lines,
144  spurious_event_markup=spurious_event_markup)
145 

◆ is_buggy()

def LHETools.Event.is_buggy (   self)

Definition at line 146 of file LHETools.py.

146  def is_buggy(self):
147  return self.info.invalid or self.spurious_event_markup or any(part.invalid for part in self.particles)
148 
149 

◆ to_string()

def LHETools.Event.to_string (   self)

Definition at line 150 of file LHETools.py.

150  def to_string(self):
151  lines = [self.info.to_string() + '\n']
152  for p in self.particles:
153  lines.append(p.to_string() + '\n')
154  lines.extend(self.extra_lines)
155 
156  return ''.join(lines)
157 

Member Data Documentation

◆ extra_lines

LHETools.Event.extra_lines

Definition at line 102 of file LHETools.py.

◆ info

LHETools.Event.info

Definition at line 100 of file LHETools.py.

◆ particles

LHETools.Event.particles

Definition at line 101 of file LHETools.py.

◆ spurious_event_markup

LHETools.Event.spurious_event_markup

Definition at line 103 of file LHETools.py.


The documentation for this class was generated from the following file:
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.Bindings.__getitem__
__getitem__
Definition: Control/AthenaPython/python/Bindings.py:779