Belle II Software  release-05-01-25
object_library.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
12 
13 import cmath
14 import re
15 
16 
17 class UFOError(Exception):
18 
19  """Exception raised if when inconsistencies are detected in the UFO model."""
20 
21  pass
22 
23 
24 class UFOBaseClass(object):
25 
26  """The class from which all FeynRules classes are derived."""
27 
28  require_args = []
29 
30  def __init__(self, *args, **options):
31  assert len(self.require_args) == len(args)
32 
33  for (i, name) in enumerate(self.require_args):
34  setattr(self, name, args[i])
35 
36  for (option, value) in options.items():
37  setattr(self, option, value)
38 
39  def get(self, name):
40  return getattr(self, name)
41 
42  def set(self, name, value):
43  setattr(self, name, value)
44 
45  def get_all(self):
46  """Return a dictionary containing all the information of the object"""
47 
48  return self.__dict__
49 
50  def __str__(self):
51  return self.name
52 
53  def nice_string(self):
54  """ return string with the full information """
55 
56  return '\n'.join(['%s \t: %s' % (name, value) for (name, value) in
57  self.__dict__.items()])
58 
59  def __repr__(self):
60  replacements = [
61  ('+', '__plus__'),
62  ('-', '__minus__'),
63  ('@', '__at__'),
64  ('!', '__exclam__'),
65  ('?', '__quest__'),
66  ('*', '__star__'),
67  ('~', '__tilde__'),
68  ]
69  text = self.name
70  for (orig, sub) in replacements:
71  text = text.replace(orig, sub)
72  return text
73 
74 
75 all_particles = []
76 
77 
79 
80  """A standard Particle"""
81 
82  require_args = [
83  'pdg_code',
84  'name',
85  'antiname',
86  'spin',
87  'color',
88  'mass',
89  'width',
90  'texname',
91  'antitexname',
92  'charge',
93  ]
94 
95  require_args_all = [
96  'pdg_code',
97  'name',
98  'antiname',
99  'spin',
100  'color',
101  'mass',
102  'width',
103  'texname',
104  'antitexname',
105  'counterterm',
106  'charge',
107  'line',
108  'propagating',
109  'goldstoneboson',
110  'propagator',
111  ]
112 
113  def __init__(
114  self,
115  pdg_code,
116  name,
117  antiname,
118  spin,
119  color,
120  mass,
121  width,
122  texname,
123  antitexname,
124  charge,
125  line=None,
126  propagating=True,
127  counterterm=None,
128  goldstoneboson=False,
129  propagator=None,
130  **options
131  ):
132 
133  args = (
134  pdg_code,
135  name,
136  antiname,
137  spin,
138  color,
139  mass,
140  width,
141  texname,
142  antitexname,
143  float(charge),
144  )
145 
146  UFOBaseClass.__init__(self, *args, **options)
147 
148  global all_particles
149  all_particles.append(self)
150 
151  self.propagating = propagating
152  self.goldstoneboson = goldstoneboson
153 
154  self.selfconjugate = name == antiname
155  if not line:
156  self.line = self.find_line_type()
157  else:
158  self.line = line
159 
160  if propagator:
161  if isinstance(propagator, dict):
162  self.propagator = propagator
163  else:
164  self.propagator = {0: propagator, 1: propagator}
165 
166  def find_line_type(self):
167  """ find how we draw a line if not defined
168  valid output: dashed/straight/wavy/curly/double/swavy/scurly
169  """
170 
171  spin = self.spin
172  color = self.color
173 
174  # use default
175  if spin == 1:
176  return 'dashed'
177  elif spin == 2:
178  if not self.selfconjugate:
179  return 'straight'
180  elif color == 1:
181  return 'swavy'
182  else:
183  return 'scurly'
184  elif spin == 3:
185  if color == 1:
186  return 'wavy'
187  else:
188 
189  return 'curly'
190  elif spin == 5:
191  return 'double'
192  elif spin == -1:
193  return 'dotted'
194  else:
195  return 'dashed' # not supported yet
196 
197  def anti(self):
198  if self.selfconjugate:
199  raise Exception('%s has no anti particle.' % self.name)
200  outdic = {}
201  for (k, v) in self.__dict__.iteritems():
202  if k not in self.require_args_all:
203  outdic[k] = -v
204  if self.color in [1, 8]:
205  newcolor = self.color
206  else:
207  newcolor = -self.color
208 
209  return Particle(
210  -self.pdg_code,
211  self.antiname,
212  self.name,
213  self.spin,
214  newcolor,
215  self.mass,
216  self.width,
217  self.antitexname,
218  self.texname,
219  -self.charge,
220  self.line,
221  self.propagating,
222  self.goldstoneboson,
223  **outdic
224  )
225 
226 
227 all_parameters = []
228 
229 
231 
232  require_args = ['name', 'nature', 'type', 'value', 'texname']
233 
234  def __init__(
235  self,
236  name,
237  nature,
238  type,
239  value,
240  texname,
241  lhablock=None,
242  lhacode=None,
243  ):
244 
245  args = (name, nature, type, value, texname)
246 
247  UFOBaseClass.__init__(self, *args)
248 
249  args = (name, nature, type, value, texname)
250 
251  global all_parameters
252  all_parameters.append(self)
253 
254  if (lhablock is None or lhacode is None) and nature == 'external':
255  raise Exception('Need LHA information for external parameter "%s".'
256  % name)
257  self.lhablock = lhablock
258  self.lhacode = lhacode
259 
260 
261 all_CTparameters = []
262 
263 
265 
266  require_args = ['name', 'nature,', 'type', 'value', 'texname']
267 
268  def __init__(
269  self,
270  name,
271  type,
272  value,
273  texname,
274  ):
275 
276  args = (name, 'internal', type, value, texname)
277 
278  UFOBaseClass.__init__(self, *args)
279 
280  args = (name, 'internal', type, value, texname)
281 
282  self.nature = 'interal'
283 
284  global all_CTparameters
285  all_CTparameters.append(self)
286 
287  def finite(self):
288  try:
289  return self.value[0]
290  except KeyError:
291  return 'ZERO'
292 
293  def pole(self, x):
294  try:
295  return self.value[-x]
296  except KeyError:
297  return 'ZERO'
298 
299 
300 all_vertices = []
301 
302 
304 
305  require_args = ['name', 'particles', 'color', 'lorentz', 'couplings']
306 
307  def __init__(
308  self,
309  name,
310  particles,
311  color,
312  lorentz,
313  couplings,
314  **opt
315  ):
316 
317  args = (name, particles, color, lorentz, couplings)
318 
319  UFOBaseClass.__init__(self, *args, **opt)
320 
321  args = (particles, color, lorentz, couplings)
322 
323  global all_vertices
324  all_vertices.append(self)
325 
326 
327 all_CTvertices = []
328 
329 
331 
332  require_args = [
333  'name',
334  'particles',
335  'color',
336  'lorentz',
337  'couplings',
338  'type',
339  'loop_particles',
340  ]
341 
342  def __init__(
343  self,
344  name,
345  particles,
346  color,
347  lorentz,
348  couplings,
349  type,
350  loop_particles,
351  **opt
352  ):
353 
354  args = (
355  name,
356  particles,
357  color,
358  lorentz,
359  couplings,
360  type,
361  loop_particles,
362  )
363 
364  UFOBaseClass.__init__(self, *args, **opt)
365 
366  args = (
367  particles,
368  color,
369  lorentz,
370  couplings,
371  type,
372  loop_particles,
373  )
374 
375  global all_CTvertices
376  all_CTvertices.append(self)
377 
378 
379 all_couplings = []
380 
381 
383 
384  require_args = ['name', 'value', 'order']
385 
386  require_args_all = ['name', 'value', 'order', 'loop_particles',
387  'counterterm']
388 
389  def __init__(
390  self,
391  name,
392  value,
393  order,
394  **opt
395  ):
396 
397  args = (name, value, order)
398  UFOBaseClass.__init__(self, *args, **opt)
399  global all_couplings
400  all_couplings.append(self)
401 
402  def value(self):
403  return self.pole(0)
404 
405  def pole(self, x):
406  """ the self.value attribute can be a dictionary directly specifying the Laurent serie using normal
407  parameter or just a string which can possibly contain CTparameter defining the Laurent serie."""
408 
409  if isinstance(self.value, dict):
410  if -x in self.value.keys():
411  return self.value[-x]
412  else:
413  return 'ZERO'
414 
415  CTparam = None
416  for param in all_CTparameters:
417  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>"
418  + param.name + r")(?P<second>\Z|\*|\+|\-|\))")
419  numberOfMatches = len(pattern.findall(self.value))
420  if numberOfMatches == 1:
421  if not CTparam:
422  CTparam = param
423  else:
424  raise UFOError, \
425  'UFO does not support yet more than one occurence of CTParameters in the couplings values.'
426  elif numberOfMatches > 1:
427  raise UFOError, \
428  'UFO does not support yet more than one occurence of CTParameters in the couplings values.'
429 
430  if not CTparam:
431  if x == 0:
432  return self.value
433  else:
434  return 'ZERO'
435  else:
436  if CTparam.pole(x) == 'ZERO':
437  return 'ZERO'
438  else:
439 
440  def substitution(matchedObj):
441  return matchedObj.group('first') + '(' + CTparam.pole(x) \
442  + ')' + matchedObj.group('second')
443 
444  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>"
445  + CTparam.name
446  + r")(?P<second>\Z|\*|\+|\-|\))")
447  return pattern.sub(substitution, self.value)
448 
449 
450 all_lorentz = []
451 
452 
454 
455  require_args = ['name', 'spins', 'structure']
456 
457  def __init__(
458  self,
459  name,
460  spins,
461  structure='external',
462  **opt
463  ):
464 
465  args = (name, spins, structure)
466  UFOBaseClass.__init__(self, *args, **opt)
467 
468  global all_lorentz
469  all_lorentz.append(self)
470 
471 
472 all_functions = []
473 
474 
475 class Function(object):
476 
477  def __init__(
478  self,
479  name,
480  arguments,
481  expression,
482  ):
483 
484  global all_functions
485  all_functions.append(self)
486 
487  self.name = name
488  self.arguments = arguments
489  self.expr = expression
490 
491  def __call__(self, *opt):
492 
493  for (i, arg) in enumerate(self.arguments):
494  exec '%s = %s' % (arg, opt[i])
495 
496  return eval(self.expr)
497 
498 
499 all_orders = []
500 
501 
502 class CouplingOrder(object):
503 
504  def __init__(
505  self,
506  name,
507  expansion_order,
508  hierarchy,
509  perturbative_expansion=0,
510  ):
511 
512  global all_orders
513  all_orders.append(self)
514 
515  self.name = name
516  self.expansion_order = expansion_order
517  self.hierarchy = hierarchy
518  self.perturbative_expansion = perturbative_expansion
519 
520 
521 all_decays = []
522 
523 
525 
526  require_args = ['particle', 'partial_widths']
527 
528  def __init__(
529  self,
530  particle,
531  partial_widths,
532  **opt
533  ):
534 
535  args = (particle, partial_widths)
536  UFOBaseClass.__init__(self, *args, **opt)
537 
538  global all_decays
539  all_decays.append(self)
540 
541  # Add the information directly to the particle
542  particle.partial_widths = partial_widths
543 
544 
545 all_form_factors = []
546 
547 
549 
550  require_args = ['name', 'type', 'value']
551 
552  def __init__(
553  self,
554  name,
555  type,
556  value,
557  **opt
558  ):
559 
560  args = (name, type, value)
561  UFOBaseClass.__init__(self, *args, **opt)
562 
563  global all_form_factors
564  all_form_factors.append(self)
565 
566 
567 all_propagators = []
568 
569 
571 
572  require_args = ['name', 'numerator', 'denominator']
573 
574  def __init__(
575  self,
576  name,
577  numerator,
578  denominator=None,
579  **opt
580  ):
581 
582  args = (name, numerator, denominator)
583  UFOBaseClass.__init__(self, *args, **opt)
584 
585  global all_propagators
586  all_propagators.append(self)
587 
588 
darkphoton.object_library.Function.arguments
arguments
Definition: object_library.py:483
darkphoton.object_library.UFOBaseClass.nice_string
def nice_string(self)
Definition: object_library.py:53
darkphoton.object_library.FormFactor
Definition: object_library.py:548
darkphoton.object_library.Function
Definition: object_library.py:475
darkphoton.object_library.UFOBaseClass.get_all
def get_all(self)
Definition: object_library.py:45
darkphoton.object_library.Particle.propagating
propagating
Definition: object_library.py:133
darkphoton.object_library.Coupling
Definition: object_library.py:382
darkphoton.object_library.Decay
Definition: object_library.py:524
darkphoton.object_library.Particle.selfconjugate
selfconjugate
Definition: object_library.py:136
darkphoton.object_library.Parameter
Definition: object_library.py:230
darkphoton.object_library.Function.expr
expr
Definition: object_library.py:484
darkphoton.object_library.CTVertex
Definition: object_library.py:330
darkphoton.object_library.CTParameter
Definition: object_library.py:264
darkphoton.object_library.UFOError
Definition: object_library.py:17
darkphoton.object_library.Particle.find_line_type
def find_line_type(self)
Definition: object_library.py:166
darkphoton.object_library.CouplingOrder.perturbative_expansion
perturbative_expansion
Definition: object_library.py:512
darkphoton.object_library.Propagator
Definition: object_library.py:570
darkphoton.object_library.Vertex
Definition: object_library.py:303
darkphoton.object_library.CTParameter.nature
nature
Definition: object_library.py:276
darkphoton.object_library.Particle.goldstoneboson
goldstoneboson
Definition: object_library.py:134
darkphoton.object_library.Coupling.value
def value(self)
Definition: object_library.py:402
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
darkphoton.object_library.Lorentz
Definition: object_library.py:453
darkphoton.object_library.Particle.line
line
Definition: object_library.py:138
darkphoton.object_library.CouplingOrder.expansion_order
expansion_order
Definition: object_library.py:510
darkphoton.object_library.Parameter.lhablock
lhablock
Definition: object_library.py:248
darkphoton.object_library.UFOBaseClass
Definition: object_library.py:24
darkphoton.object_library.Function.name
name
Definition: object_library.py:482
darkphoton.object_library.Particle
Definition: object_library.py:78
darkphoton.object_library.CouplingOrder.name
name
Definition: object_library.py:509
darkphoton.object_library.CouplingOrder
Definition: object_library.py:502
darkphoton.object_library.Particle.require_args_all
list require_args_all
Definition: object_library.py:95
darkphoton.object_library.Coupling.pole
def pole(self, x)
Definition: object_library.py:405
darkphoton.object_library.CouplingOrder.hierarchy
hierarchy
Definition: object_library.py:511
darkphoton.object_library.Particle.propagator
propagator
Definition: object_library.py:144
darkphoton.object_library.Parameter.lhacode
lhacode
Definition: object_library.py:249