Belle II Software  release-06-02-00
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.propagatingpropagating = propagating
104  self.goldstonebosongoldstoneboson = goldstoneboson
105 
106  self.selfconjugateselfconjugate = (name == antiname)
107  if not line:
108  self.lineline = self.find_line_typefind_line_type()
109  else:
110  self.lineline = line
111 
112  if propagator:
113  if isinstance(propagator, dict):
114  self.propagatorpropagator = propagator
115  else:
116  self.propagatorpropagator = {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.selfconjugateselfconjugate:
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.selfconjugateselfconjugate:
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_allrequire_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.lineline, self.propagatingpropagating, self.goldstonebosongoldstoneboson, **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.lhablocklhablock = lhablock
186  self.lhacodelhacode = lhacode
187 
188 
189 all_CTparameters = []
190 
191 
193 
194  require_args = ['name', 'nature,', 'type', 'value', 'texname']
195 
196  def __init__(self, name, type, value, texname):
197 
198  args = (name, 'internal', type, value, texname)
199 
200  UFOBaseClass.__init__(self, *args)
201 
202  args = (name, 'internal', type, value, texname)
203 
204  self.naturenature = 'interal'
205 
206  global all_CTparameters
207  all_CTparameters.append(self)
208 
209  def finite(self):
210  try:
211  return self.value[0]
212  except KeyError:
213  return 'ZERO'
214 
215  def pole(self, x):
216  try:
217  return self.value[-x]
218  except KeyError:
219  return 'ZERO'
220 
221 
222 all_vertices = []
223 
224 
226 
227  require_args = ['name', 'particles', 'color', 'lorentz', 'couplings']
228 
229  def __init__(self, name, particles, color, lorentz, couplings, **opt):
230 
231  args = (name, particles, color, lorentz, couplings)
232 
233  UFOBaseClass.__init__(self, *args, **opt)
234 
235  args = (particles, color, lorentz, couplings)
236 
237  global all_vertices
238  all_vertices.append(self)
239 
240 
241 all_CTvertices = []
242 
243 
245 
246  require_args = ['name', 'particles', 'color', 'lorentz', 'couplings', 'type', 'loop_particles']
247 
248  def __init__(self, name, particles, color, lorentz, couplings, type, loop_particles, **opt):
249 
250  args = (name, particles, color, lorentz, couplings, type, loop_particles)
251 
252  UFOBaseClass.__init__(self, *args, **opt)
253 
254  args = (particles, color, lorentz, couplings, type, loop_particles)
255 
256  global all_CTvertices
257  all_CTvertices.append(self)
258 
259 
260 all_couplings = []
261 
262 
264 
265  require_args = ['name', 'value', 'order']
266 
267  require_args_all = ['name', 'value', 'order', 'loop_particles', 'counterterm']
268 
269  def __init__(self, name, value, order, **opt):
270 
271  args = (name, value, order)
272  UFOBaseClass.__init__(self, *args, **opt)
273  global all_couplings
274  all_couplings.append(self)
275 
276  def value(self):
277  return self.polepole(0)
278 
279  def pole(self, x):
280  """ the self.value attribute can be a dictionary directly specifying the Laurent serie using normal
281  parameter or just a string which can possibly contain CTparameter defining the Laurent serie."""
282 
283  if isinstance(self.valuevalue, dict):
284  if -x in self.valuevalue.keys():
285  return self.valuevalue[-x]
286  else:
287  return 'ZERO'
288 
289  CTparam = None
290  for param in all_CTparameters:
291  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\‍()(?P<name>" + param.name + r")(?P<second>\Z|\*|\+|\-|\‍))")
292  numberOfMatches = len(pattern.findall(self.valuevalue))
293  if numberOfMatches == 1:
294  if not CTparam:
295  CTparam = param
296  else:
297  raise UFOError("UFO does not support yet more than one occurence of CTParameters in the couplings values.")
298  elif numberOfMatches > 1:
299  raise UFOError("UFO does not support yet more than one occurence of CTParameters in the couplings values.")
300 
301  if not CTparam:
302  if x == 0:
303  return self.valuevalue
304  else:
305  return 'ZERO'
306  else:
307  if CTparam.pole(x) == 'ZERO':
308  return 'ZERO'
309  else:
310  def substitution(matchedObj):
311  return matchedObj.group('first') + "(" + CTparam.pole(x) + ")" + matchedObj.group('second')
312  pattern = re.compile(r"(?P<first>\A|\*|\+|\-|\‍()(?P<name>" + CTparam.name + r")(?P<second>\Z|\*|\+|\-|\‍))")
313  return pattern.sub(substitution, self.valuevalue)
314 
315 
316 all_lorentz = []
317 
318 
320 
321  require_args = ['name', 'spins', 'structure']
322 
323  def __init__(self, name, spins, structure='external', **opt):
324  args = (name, spins, structure)
325  UFOBaseClass.__init__(self, *args, **opt)
326 
327  global all_lorentz
328  all_lorentz.append(self)
329 
330 
331 all_functions = []
332 
333 
334 class Function(object):
335 
336  def __init__(self, name, arguments, expression):
337 
338  global all_functions
339  all_functions.append(self)
340 
341  self.namename = name
342  self.argumentsarguments = arguments
343  self.exprexpr = expression
344 
345  def __call__(self, *opt):
346 
347  for i, arg in enumerate(self.argumentsarguments):
348  exec('%s = %s' % (arg, opt[i]))
349 
350  return eval(self.exprexpr)
351 
352 
353 all_orders = []
354 
355 
356 class CouplingOrder(object):
357 
358  def __init__(self, name, expansion_order, hierarchy, perturbative_expansion=0):
359 
360  global all_orders
361  all_orders.append(self)
362 
363  self.namename = name
364  self.expansion_orderexpansion_order = expansion_order
365  self.hierarchyhierarchy = hierarchy
366  self.perturbative_expansionperturbative_expansion = perturbative_expansion
367 
368 
369 all_decays = []
370 
371 
373  require_args = ['particle', 'partial_widths']
374 
375  def __init__(self, particle, partial_widths, **opt):
376  args = (particle, partial_widths)
377  UFOBaseClass.__init__(self, *args, **opt)
378 
379  global all_decays
380  all_decays.append(self)
381 
382  # Add the information directly to the particle
383  particle.partial_widths = partial_widths
384 
385 
386 all_form_factors = []
387 
388 
390  require_args = ['name', 'type', 'value']
391 
392  def __init__(self, name, type, value, **opt):
393  args = (name, type, value)
394  UFOBaseClass.__init__(self, *args, **opt)
395 
396  global all_form_factors
397  all_form_factors.append(self)
398 
399 
400 all_propagators = []
401 
402 
404 
405  require_args = ['name', 'numerator', 'denominator']
406 
407  def __init__(self, name, numerator, denominator=None, **opt):
408  args = (name, numerator, denominator)
409  UFOBaseClass.__init__(self, *args, **opt)
410 
411  global all_propagators
412  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