Belle II Software  release-05-01-25
object_library.py
1 
9 
10 import cmath
11 import re
12 
13 
14 class UFOError(Exception):
15  """Exception raised if when inconsistencies are detected in the UFO model."""
16  pass
17 
18 
19 class UFOBaseClass(object):
20  """The class from which all FeynRules classes are derived."""
21 
22  require_args = []
23 
24  def __init__(self, *args, **options):
25  assert(len(self.require_args) == len(args))
26 
27  for i, name in enumerate(self.require_args):
28  setattr(self, name, args[i])
29 
30  for (option, value) in options.items():
31  setattr(self, option, value)
32 
33  def get(self, name):
34  return getattr(self, name)
35 
36  def set(self, name, value):
37  setattr(self, name, value)
38 
39  def get_all(self):
40  """Return a dictionary containing all the information of the object"""
41  return self.__dict__
42 
43  def __str__(self):
44  return self.name
45 
46  def nice_string(self):
47  """ return string with the full information """
48  return '\n'.join(['%s \t: %s' % (name, value) for name, value in self.__dict__.items()])
49 
50  def __repr__(self):
51  replacements = [
52  ('+', '__plus__'),
53  ('-', '__minus__'),
54  ('@', '__at__'),
55  ('!', '__exclam__'),
56  ('?', '__quest__'),
57  ('*', '__star__'),
58  ('~', '__tilde__')
59  ]
60  text = self.name
61  for orig, sub in replacements:
62  text = text.replace(orig, sub)
63  return text
64 
65 
66 all_particles = []
67 
68 
70  """A standard Particle"""
71 
72  require_args = ['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname', 'charge']
73 
74  require_args_all = [
75  'pdg_code',
76  'name',
77  'antiname',
78  'spin',
79  'color',
80  'mass',
81  'width',
82  'texname',
83  'antitexname',
84  'counterterm',
85  'charge',
86  'line',
87  'propagating',
88  'goldstoneboson',
89  'propagator']
90 
91  def __init__(self, pdg_code, name, antiname, spin, color, mass, width, texname,
92  antitexname, charge, line=None, propagating=True, counterterm=None, goldstoneboson=False,
93  propagator=None, **options):
94 
95  args = (pdg_code, name, antiname, spin, color, mass, width, texname,
96  antitexname, float(charge))
97 
98  UFOBaseClass.__init__(self, *args, **options)
99 
100  global all_particles
101  all_particles.append(self)
102 
103  self.propagating = propagating
104  self.goldstoneboson = goldstoneboson
105 
106  self.selfconjugate = (name == antiname)
107  if not line:
108  self.line = self.find_line_type()
109  else:
110  self.line = line
111 
112  if propagator:
113  if isinstance(propagator, dict):
114  self.propagator = propagator
115  else:
116  self.propagator = {0: propagator, 1: propagator}
117 
118  def find_line_type(self):
119  """ find how we draw a line if not defined
120  valid output: dashed/straight/wavy/curly/double/swavy/scurly
121  """
122 
123  spin = self.spin
124  color = self.color
125 
126  # use default
127  if spin == 1:
128  return 'dashed'
129  elif spin == 2:
130  if not self.selfconjugate:
131  return 'straight'
132  elif color == 1:
133  return 'swavy'
134  else:
135  return 'scurly'
136  elif spin == 3:
137  if color == 1:
138  return 'wavy'
139 
140  else:
141  return 'curly'
142  elif spin == 5:
143  return 'double'
144  elif spin == -1:
145  return 'dotted'
146  else:
147  return 'dashed' # not supported yet
148 
149  def anti(self):
150  if self.selfconjugate:
151  raise Exception('%s has no anti particle.' % self.name)
152  outdic = {}
153  for k, v in self.__dict__.iteritems():
154  if k not in self.require_args_all:
155  outdic[k] = -v
156  if self.color in [1, 8]:
157  newcolor = self.color
158  else:
159  newcolor = -self.color
160 
161  return Particle(-self.pdg_code, self.antiname, self.name, self.spin, newcolor, self.mass, self.width,
162  self.antitexname, self.texname, -self.charge, self.line, self.propagating, self.goldstoneboson, **outdic)
163 
164 
165 all_parameters = []
166 
167 
169 
170  require_args = ['name', 'nature', 'type', 'value', 'texname']
171 
172  def __init__(self, name, nature, type, value, texname, lhablock=None, lhacode=None):
173 
174  args = (name, nature, type, value, texname)
175 
176  UFOBaseClass.__init__(self, *args)
177 
178  args = (name, nature, type, value, texname)
179 
180  global all_parameters
181  all_parameters.append(self)
182 
183  if (lhablock is None or lhacode is None) and nature == 'external':
184  raise Exception('Need LHA information for external parameter "%s".' % name)
185  self.lhablock = lhablock
186  self.lhacode = lhacode
187 
188 all_CTparameters = []
189 
190 
192 
193  require_args = ['name', 'nature,', 'type', 'value', 'texname']
194 
195  def __init__(self, name, type, value, texname):
196 
197  args = (name, 'internal', type, value, texname)
198 
199  UFOBaseClass.__init__(self, *args)
200 
201  args = (name, 'internal', type, value, texname)
202 
203  self.nature = 'interal'
204 
205  global all_CTparameters
206  all_CTparameters.append(self)
207 
208  def finite(self):
209  try:
210  return self.value[0]
211  except KeyError:
212  return 'ZERO'
213 
214  def pole(self, x):
215  try:
216  return self.value[-x]
217  except KeyError:
218  return 'ZERO'
219 
220 all_vertices = []
221 
222 
224 
225  require_args = ['name', 'particles', 'color', 'lorentz', 'couplings']
226 
227  def __init__(self, name, particles, color, lorentz, couplings, **opt):
228 
229  args = (name, particles, color, lorentz, couplings)
230 
231  UFOBaseClass.__init__(self, *args, **opt)
232 
233  args = (particles, color, lorentz, couplings)
234 
235  global all_vertices
236  all_vertices.append(self)
237 
238 all_CTvertices = []
239 
240 
242 
243  require_args = ['name', 'particles', 'color', 'lorentz', 'couplings', 'type', 'loop_particles']
244 
245  def __init__(self, name, particles, color, lorentz, couplings, type, loop_particles, **opt):
246 
247  args = (name, particles, color, lorentz, couplings, type, loop_particles)
248 
249  UFOBaseClass.__init__(self, *args, **opt)
250 
251  args = (particles, color, lorentz, couplings, type, loop_particles)
252 
253  global all_CTvertices
254  all_CTvertices.append(self)
255 
256 all_couplings = []
257 
258 
260 
261  require_args = ['name', 'value', 'order']
262 
263  require_args_all = ['name', 'value', 'order', 'loop_particles', 'counterterm']
264 
265  def __init__(self, name, value, order, **opt):
266 
267  args = (name, value, order)
268  UFOBaseClass.__init__(self, *args, **opt)
269  global all_couplings
270  all_couplings.append(self)
271 
272  def value(self):
273  return self.pole(0)
274 
275  def pole(self, x):
276  """ the self.value attribute can be a dictionary directly specifying the Laurent serie using normal
277  parameter or just a string which can possibly contain CTparameter defining the Laurent serie."""
278 
279  if isinstance(self.value, dict):
280  if -x in self.value.keys():
281  return self.value[-x]
282  else:
283  return 'ZERO'
284 
285  CTparam = None
286  for param in all_CTparameters:
287  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>" + param.name + r")(?P<second>\Z|\*|\+|\-|\))")
288  numberOfMatches = len(pattern.findall(self.value))
289  if numberOfMatches == 1:
290  if not CTparam:
291  CTparam = param
292  else:
293  raise UFOError("UFO does not support yet more than one occurence of CTParameters in the couplings values.")
294  elif numberOfMatches > 1:
295  raise UFOError("UFO does not support yet more than one occurence of CTParameters in the couplings values.")
296 
297  if not CTparam:
298  if x == 0:
299  return self.value
300  else:
301  return 'ZERO'
302  else:
303  if CTparam.pole(x) == 'ZERO':
304  return 'ZERO'
305  else:
306  def substitution(matchedObj):
307  return matchedObj.group('first') + "(" + CTparam.pole(x) + ")" + matchedObj.group('second')
308  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>" + CTparam.name + r")(?P<second>\Z|\*|\+|\-|\))")
309  return pattern.sub(substitution, self.value)
310 
311 all_lorentz = []
312 
313 
315 
316  require_args = ['name', 'spins', 'structure']
317 
318  def __init__(self, name, spins, structure='external', **opt):
319  args = (name, spins, structure)
320  UFOBaseClass.__init__(self, *args, **opt)
321 
322  global all_lorentz
323  all_lorentz.append(self)
324 
325 
326 all_functions = []
327 
328 
329 class Function(object):
330 
331  def __init__(self, name, arguments, expression):
332 
333  global all_functions
334  all_functions.append(self)
335 
336  self.name = name
337  self.arguments = arguments
338  self.expr = expression
339 
340  def __call__(self, *opt):
341 
342  for i, arg in enumerate(self.arguments):
343  exec('%s = %s' % (arg, opt[i]))
344 
345  return eval(self.expr)
346 
347 all_orders = []
348 
349 
350 class CouplingOrder(object):
351 
352  def __init__(self, name, expansion_order, hierarchy, perturbative_expansion=0):
353 
354  global all_orders
355  all_orders.append(self)
356 
357  self.name = name
358  self.expansion_order = expansion_order
359  self.hierarchy = hierarchy
360  self.perturbative_expansion = perturbative_expansion
361 
362 all_decays = []
363 
364 
366  require_args = ['particle', 'partial_widths']
367 
368  def __init__(self, particle, partial_widths, **opt):
369  args = (particle, partial_widths)
370  UFOBaseClass.__init__(self, *args, **opt)
371 
372  global all_decays
373  all_decays.append(self)
374 
375  # Add the information directly to the particle
376  particle.partial_widths = partial_widths
377 
378 all_form_factors = []
379 
380 
382  require_args = ['name', 'type', 'value']
383 
384  def __init__(self, name, type, value, **opt):
385  args = (name, type, value)
386  UFOBaseClass.__init__(self, *args, **opt)
387 
388  global all_form_factors
389  all_form_factors.append(self)
390 
391 
392 all_propagators = []
393 
394 
396 
397  require_args = ['name', 'numerator', 'denominator']
398 
399  def __init__(self, name, numerator, denominator=None, **opt):
400  args = (name, numerator, denominator)
401  UFOBaseClass.__init__(self, *args, **opt)
402 
403  global all_propagators
404  all_propagators.append(self)
Lmu_minus_Ltau_UFO.object_library.UFOBaseClass
Definition: object_library.py:19
Lmu_minus_Ltau_UFO.object_library.Particle.require_args_all
list require_args_all
Definition: object_library.py:74
Lmu_minus_Ltau_UFO.object_library.Propagator
Definition: object_library.py:395
Lmu_minus_Ltau_UFO.object_library.UFOBaseClass.nice_string
def nice_string(self)
Definition: object_library.py:46
Lmu_minus_Ltau_UFO.object_library.CouplingOrder
Definition: object_library.py:350
Lmu_minus_Ltau_UFO.object_library.Particle.propagating
propagating
Definition: object_library.py:101
Lmu_minus_Ltau_UFO.object_library.CTParameter.nature
nature
Definition: object_library.py:203
Lmu_minus_Ltau_UFO.object_library.Particle.goldstoneboson
goldstoneboson
Definition: object_library.py:102
Lmu_minus_Ltau_UFO.object_library.UFOBaseClass.get_all
def get_all(self)
Definition: object_library.py:39
Lmu_minus_Ltau_UFO.object_library.Decay
Definition: object_library.py:365
Lmu_minus_Ltau_UFO.object_library.Coupling.value
def value(self)
Definition: object_library.py:272
Lmu_minus_Ltau_UFO.object_library.Function.arguments
arguments
Definition: object_library.py:337
Lmu_minus_Ltau_UFO.object_library.Particle.line
line
Definition: object_library.py:106
Lmu_minus_Ltau_UFO.object_library.Particle.selfconjugate
selfconjugate
Definition: object_library.py:104
Lmu_minus_Ltau_UFO.object_library.Lorentz
Definition: object_library.py:314
Lmu_minus_Ltau_UFO.object_library.Coupling
Definition: object_library.py:259
Lmu_minus_Ltau_UFO.object_library.Parameter.lhacode
lhacode
Definition: object_library.py:186
Lmu_minus_Ltau_UFO.object_library.Particle.propagator
propagator
Definition: object_library.py:112
Lmu_minus_Ltau_UFO.object_library.CTParameter
Definition: object_library.py:191
Lmu_minus_Ltau_UFO.object_library.Function.expr
expr
Definition: object_library.py:338
Lmu_minus_Ltau_UFO.object_library.CouplingOrder.expansion_order
expansion_order
Definition: object_library.py:358
Lmu_minus_Ltau_UFO.object_library.CouplingOrder.hierarchy
hierarchy
Definition: object_library.py:359
Belle2::eval
double eval(const std::vector< double > &spl, const std::vector< double > &vals, double x)
Evaluate spline (zero order or first order) in point x.
Definition: tools.h:118
Lmu_minus_Ltau_UFO.object_library.CouplingOrder.perturbative_expansion
perturbative_expansion
Definition: object_library.py:360
Lmu_minus_Ltau_UFO.object_library.Parameter.lhablock
lhablock
Definition: object_library.py:185
Lmu_minus_Ltau_UFO.object_library.Coupling.pole
def pole(self, x)
Definition: object_library.py:275
Lmu_minus_Ltau_UFO.object_library.CouplingOrder.name
name
Definition: object_library.py:357
Lmu_minus_Ltau_UFO.object_library.CTVertex
Definition: object_library.py:241
Lmu_minus_Ltau_UFO.object_library.UFOError
Definition: object_library.py:14
Lmu_minus_Ltau_UFO.object_library.Parameter
Definition: object_library.py:168
Lmu_minus_Ltau_UFO.object_library.Particle.find_line_type
def find_line_type(self)
Definition: object_library.py:118
Lmu_minus_Ltau_UFO.object_library.Particle
Definition: object_library.py:69
Lmu_minus_Ltau_UFO.object_library.Vertex
Definition: object_library.py:223
Lmu_minus_Ltau_UFO.object_library.Function
Definition: object_library.py:329
Lmu_minus_Ltau_UFO.object_library.FormFactor
Definition: object_library.py:381
Lmu_minus_Ltau_UFO.object_library.Function.name
name
Definition: object_library.py:336