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

Public Member Functions

def __init__ (self, table, ranges)
 
def accept (self, pdg)
 
def parsePDGTABLE (self)
 
def formatName (self, name, charge)
 
def formatCharge (self, charge)
 
def createList (self)
 

Public Attributes

 log
 
 table
 
 ranges
 
 extraParticles
 

Detailed Description

Definition at line 109 of file PDGHelpers.py.

Constructor & Destructor Documentation

◆ __init__()

def PDGHelpers.PDGParser.__init__ (   self,
  table,
  ranges 
)

Definition at line 111 of file PDGHelpers.py.

111  def __init__(self, table, ranges):
112  self.log = logging.getLogger(__name__)
113  self.table = table
114  self.ranges = ranges
115  self.extraParticles = {}
116  self.parsePDGTABLE()
117 

Member Function Documentation

◆ accept()

def PDGHelpers.PDGParser.accept (   self,
  pdg 
)
Function to determine which extra particles are added

Function checks the ranges member variable
and evaluates whether the particle should be accepted.

TODO Consider adding a Sim.ExtraParticlesRanges ConfigFlag

For example, '111-556,1112-9090226' matches everything from
111 to 555 and 1112 to 9090225.

Definition at line 118 of file PDGHelpers.py.

118  def accept(self, pdg):
119  """Function to determine which extra particles are added
120 
121  Function checks the ranges member variable
122  and evaluates whether the particle should be accepted.
123 
124  TODO Consider adding a Sim.ExtraParticlesRanges ConfigFlag
125 
126  For example, '111-556,1112-9090226' matches everything from
127  111 to 555 and 1112 to 9090225.
128  """
129  ranges = [r.split("-") for r in self.ranges.split(",")]
130  for r in ranges:
131  if int(r[0]) <= pdg < int(r[1]):
132  return True
133 

◆ createList()

def PDGHelpers.PDGParser.createList (   self)

Definition at line 222 of file PDGHelpers.py.

222  def createList(self):
223  pdgcodes = [ self.extraParticles[name].pdg for name in self.extraParticles ]
224  updateExtraParticleAcceptList('G4particle_acceptlist_ExtraParticles.txt', pdgcodes)
225 
226  # generate output in correct format
227  outDict = dict()
228  for name in self.extraParticles:
229  outDict.update({name: [
230  self.extraParticles[name].mass,
231  self.extraParticles[name].width,
232  self.extraParticles[name].charge,
233  self.extraParticles[name].pdg,
234  self.extraParticles[name].lifetime
235  ]})
236 
237  return outDict

◆ formatCharge()

def PDGHelpers.PDGParser.formatCharge (   self,
  charge 
)

Definition at line 206 of file PDGHelpers.py.

206  def formatCharge(self, charge):
207  # check that all characters are the same
208  # e.g.: '0', '+', '--', ...
209  if not (charge == len(charge) * charge[0]):
210  raise ValueError('Unexpected charge %s' % charge)
211 
212  # parse string
213  if '+' in charge:
214  return len(charge)
215  elif '-' in charge:
216  return -len(charge)
217  elif '0' in charge:
218  return 0
219  else:
220  raise ValueError('Unexpected charge %s' % charge)
221 

◆ formatName()

def PDGHelpers.PDGParser.formatName (   self,
  name,
  charge 
)

Definition at line 200 of file PDGHelpers.py.

200  def formatName(self, name, charge):
201  nameOut = name
202  nameOut = nameOut.replace("*", "_star").replace("'", "_prime")
203  nameOut += charge
204  return nameOut
205 

◆ parsePDGTABLE()

def PDGHelpers.PDGParser.parsePDGTABLE (   self)

Definition at line 134 of file PDGHelpers.py.

134  def parsePDGTABLE(self):
135 
136  # parse the PDGTABLE
137  with open(self.table, 'r') as f:
138  for line in f:
139  if line.startswith('*'):
140  # Comments start with '*'
141  continue
142  splitLine = line.split()
143 
144  # Name of the particle
145  baseName = splitLine[-2]
146 
147  # Number of particle entries
148  charges = splitLine[-1].split(',')
149 
150  # Mass or Width
151  prop = ''
152  symbol = splitLine[0]
153  if symbol == 'M':
154  prop = 'mass'
155  elif symbol == 'W':
156  prop = 'width'
157  else:
158  raise ValueError(
159  'Unidentified symbol %s for particle %s' % (
160  symbol, baseName))
161 
162  pdgs = splitLine[1:1+len(charges)]
163  value = float(splitLine[1+len(charges)])
164 
165  for pdg, charge in zip(pdgs, charges):
166  if not self.accept(int(pdg)):
167  continue
168  name = self.formatName(baseName, charge)
169  kwargs = dict()
170  kwargs.setdefault('name', name)
171  kwargs.setdefault(prop, value * MeV)
172  kwargs.setdefault('pdg', int(pdg))
173  kwargs.setdefault('charge', self.formatCharge(charge))
174  if name not in self.extraParticles.keys():
175  self.extraParticles[name] = ExtraParticle(**kwargs)
176  else:
177  if getattr(self.extraParticles[name], prop) != -1:
178  self.log.warning(
179  "Property %s is already"
180  "set for particle %s."
181  "Current value is %s and"
182  "incoming value is %s.",
183  prop, name,
184  getattr(self.extraParticles[name], prop),
185  value)
186  continue
187  setattr(self.extraParticles[name], prop, value)
188 
189  for name in self.extraParticles:
190  # calculate lifetime
191  width = self.extraParticles[name].width
192  if width > 0:
193  self.extraParticles[name].lifetime = hbar_Planck/width
194 
195  # create anti-particles
196  for name in [x for x in self.extraParticles.keys()]:
197  antiParticle = -self.extraParticles[name]
198  self.extraParticles.update({antiParticle.name: antiParticle})
199 

Member Data Documentation

◆ extraParticles

PDGHelpers.PDGParser.extraParticles

Definition at line 115 of file PDGHelpers.py.

◆ log

PDGHelpers.PDGParser.log

Definition at line 112 of file PDGHelpers.py.

◆ ranges

PDGHelpers.PDGParser.ranges

Definition at line 114 of file PDGHelpers.py.

◆ table

PDGHelpers.PDGParser.table

Definition at line 113 of file PDGHelpers.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
PDGHelpers.updateExtraParticleAcceptList
def updateExtraParticleAcceptList(listName='G4particle_acceptlist_ExtraParticles.txt', pdgcodes=[])
Definition: PDGHelpers.py:57
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
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
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38