Belle II Software  release-06-01-15
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.propagatingpropagating = propagating
152  self.goldstonebosongoldstoneboson = goldstoneboson
153 
154  self.selfconjugateselfconjugate = name == antiname
155  if not line:
156  self.lineline = self.find_line_typefind_line_type()
157  else:
158  self.lineline = line
159 
160  if propagator:
161  if isinstance(propagator, dict):
162  self.propagatorpropagator = propagator
163  else:
164  self.propagatorpropagator = {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.selfconjugateselfconjugate:
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.selfconjugateselfconjugate:
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_allrequire_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.lineline,
221  self.propagatingpropagating,
222  self.goldstonebosongoldstoneboson,
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.lhablocklhablock = lhablock
258  self.lhacodelhacode = 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.naturenature = '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.polepole(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.valuevalue, dict):
410  if -x in self.valuevalue.keys():
411  return self.valuevalue[-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.valuevalue))
420  if numberOfMatches == 1:
421  if not CTparam:
422  CTparam = param
423  else:
424  raise UFOError('UFO does not support yet more than one occurence of CTParameters in the couplings values.')
425  elif numberOfMatches > 1:
426  raise UFOError('UFO does not support yet more than one occurence of CTParameters in the couplings values.')
427 
428  if not CTparam:
429  if x == 0:
430  return self.valuevalue
431  else:
432  return 'ZERO'
433  else:
434  if CTparam.pole(x) == 'ZERO':
435  return 'ZERO'
436  else:
437 
438  def substitution(matchedObj):
439  return matchedObj.group('first') + '(' + CTparam.pole(x) \
440  + ')' + matchedObj.group('second')
441 
442  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\‍()(?P<name>"
443  + CTparam.name
444  + r")(?P<second>\Z|\*|\+|\-|\‍))")
445  return pattern.sub(substitution, self.valuevalue)
446 
447 
448 all_lorentz = []
449 
450 
452 
453  require_args = ['name', 'spins', 'structure']
454 
455  def __init__(
456  self,
457  name,
458  spins,
459  structure='external',
460  **opt
461  ):
462 
463  args = (name, spins, structure)
464  UFOBaseClass.__init__(self, *args, **opt)
465 
466  global all_lorentz
467  all_lorentz.append(self)
468 
469 
470 all_functions = []
471 
472 
473 class Function(object):
474 
475  def __init__(
476  self,
477  name,
478  arguments,
479  expression,
480  ):
481 
482  global all_functions
483  all_functions.append(self)
484 
485  self.namename = name
486  self.argumentsarguments = arguments
487  self.exprexpr = expression
488 
489  def __call__(self, *opt):
490 
491  for (i, arg) in enumerate(self.argumentsarguments):
492  exec '%s = %s' % (arg, opt[i])
493 
494  return eval(self.exprexpr)
495 
496 
497 all_orders = []
498 
499 
500 class CouplingOrder(object):
501 
502  def __init__(
503  self,
504  name,
505  expansion_order,
506  hierarchy,
507  perturbative_expansion=0,
508  ):
509 
510  global all_orders
511  all_orders.append(self)
512 
513  self.namename = name
514  self.expansion_orderexpansion_order = expansion_order
515  self.hierarchyhierarchy = hierarchy
516  self.perturbative_expansionperturbative_expansion = perturbative_expansion
517 
518 
519 all_decays = []
520 
521 
523 
524  require_args = ['particle', 'partial_widths']
525 
526  def __init__(
527  self,
528  particle,
529  partial_widths,
530  **opt
531  ):
532 
533  args = (particle, partial_widths)
534  UFOBaseClass.__init__(self, *args, **opt)
535 
536  global all_decays
537  all_decays.append(self)
538 
539  # Add the information directly to the particle
540  particle.partial_widths = partial_widths
541 
542 
543 all_form_factors = []
544 
545 
547 
548  require_args = ['name', 'type', 'value']
549 
550  def __init__(
551  self,
552  name,
553  type,
554  value,
555  **opt
556  ):
557 
558  args = (name, type, value)
559  UFOBaseClass.__init__(self, *args, **opt)
560 
561  global all_form_factors
562  all_form_factors.append(self)
563 
564 
565 all_propagators = []
566 
567 
569 
570  require_args = ['name', 'numerator', 'denominator']
571 
572  def __init__(
573  self,
574  name,
575  numerator,
576  denominator=None,
577  **opt
578  ):
579 
580  args = (name, numerator, denominator)
581  UFOBaseClass.__init__(self, *args, **opt)
582 
583  global all_propagators
584  all_propagators.append(self)
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:115