13
class UFOError(Exception):
14
"""Exception raised if when inconsistencies are detected in the UFO model."""
17
class UFOBaseClass(object):
18
"""The class from which all FeynRules classes are derived."""
22
def __init__(self, *args, **options):
23
assert(len(self.require_args) == len (args))
25
for i, name in enumerate(self.require_args):
26
setattr(self, name, args[i])
28
for (option, value) in options.items():
29
setattr(self, option, value)
32
return getattr(self, name)
34
def set(self, name, value):
35
setattr(self, name, value)
38
"""Return a dictionary containing all the information of the object"""
44
def nice_string(self):
45
""" return string with the full information """
46
return '\n'.join(['%s \t: %s' %(name, value) for name, value in self.__dict__.items()])
59
for orig,sub in replacements:
60
text = text.replace(orig,sub)
67
class Particle(UFOBaseClass):
68
"""A standard Particle"""
70
require_args=['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname', 'charge']
72
require_args_all = ['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname','counterterm','charge', 'line', 'propagating', 'goldstoneboson', 'propagator']
74
def __init__(self, pdg_code, name, antiname, spin, color, mass, width, texname,
75
antitexname, charge , line=None, propagating=True, counterterm=None, goldstoneboson=False,
76
propagator=None, **options):
78
args= (pdg_code, name, antiname, spin, color, mass, width, texname,
79
antitexname, float(charge))
81
UFOBaseClass.__init__(self, *args, **options)
84
all_particles.append(self)
86
self.propagating = propagating
87
self.goldstoneboson= goldstoneboson
89
self.selfconjugate = (name == antiname)
91
self.line = self.find_line_type()
96
if isinstance(propagator, dict):
97
self.propagator = propagator
99
self.propagator = {0: propagator, 1: propagator}
101
def find_line_type(self):
102
""" find how we draw a line if not defined
103
valid output: dashed/straight/wavy/curly/double/swavy/scurly
113
if not self.selfconjugate:
130
return 'dashed' # not supported yet
133
if self.selfconjugate:
134
raise Exception('%s has no anti particle.' % self.name)
136
for k,v in self.__dict__.iteritems():
137
if k not in self.require_args_all:
139
if self.color in [1,8]:
140
newcolor = self.color
142
newcolor = -self.color
144
return Particle(-self.pdg_code, self.antiname, self.name, self.spin, newcolor, self.mass, self.width,
145
self.antitexname, self.texname, -self.charge, self.line, self.propagating, self.goldstoneboson, **outdic)
151
class Parameter(UFOBaseClass):
153
require_args=['name', 'nature', 'type', 'value', 'texname']
155
def __init__(self, name, nature, type, value, texname, lhablock=None, lhacode=None):
157
args = (name,nature,type,value,texname)
159
UFOBaseClass.__init__(self, *args)
161
args=(name,nature,type,value,texname)
163
global all_parameters
164
all_parameters.append(self)
166
if (lhablock is None or lhacode is None) and nature == 'external':
167
raise Exception('Need LHA information for external parameter "%s".' % name)
168
self.lhablock = lhablock
169
self.lhacode = lhacode
171
all_CTparameters = []
173
class CTParameter(UFOBaseClass):
175
require_args=['name', 'nature,', 'type', 'value', 'texname']
177
def __init__(self, name, type, value, texname):
179
args = (name,'internal',type,value,texname)
181
UFOBaseClass.__init__(self, *args)
183
args=(name,'internal',type,value,texname)
185
self.nature='interal'
187
global all_CTparameters
188
all_CTparameters.append(self)
198
return self.value[-x]
204
class Vertex(UFOBaseClass):
206
require_args=['name', 'particles', 'color', 'lorentz', 'couplings']
208
def __init__(self, name, particles, color, lorentz, couplings, **opt):
210
args = (name, particles, color, lorentz, couplings)
212
UFOBaseClass.__init__(self, *args, **opt)
214
args=(particles,color,lorentz,couplings)
217
all_vertices.append(self)
221
class CTVertex(UFOBaseClass):
223
require_args=['name', 'particles', 'color', 'lorentz', 'couplings', 'type', 'loop_particles']
225
def __init__(self, name, particles, color, lorentz, couplings, type, loop_particles, **opt):
227
args = (name, particles, color, lorentz, couplings, type, loop_particles)
229
UFOBaseClass.__init__(self, *args, **opt)
231
args=(particles,color,lorentz,couplings, type, loop_particles)
233
global all_CTvertices
234
all_CTvertices.append(self)
238
class Coupling(UFOBaseClass):
240
require_args=['name', 'value', 'order']
242
require_args_all=['name', 'value', 'order', 'loop_particles', 'counterterm']
244
def __init__(self, name, value, order, **opt):
246
args =(name, value, order)
247
UFOBaseClass.__init__(self, *args, **opt)
249
all_couplings.append(self)
255
""" the self.value attribute can be a dictionary directly specifying the Laurent serie using normal
256
parameter or just a string which can possibly contain CTparameter defining the Laurent serie."""
258
if isinstance(self.value,dict):
259
if -x in self.value.keys():
260
return self.value[-x]
265
for param in all_CTparameters:
266
pattern=re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>"+param.name+r")(?P<second>\Z|\*|\+|\-|\))")
267
numberOfMatches=len(pattern.findall(self.value))
268
if numberOfMatches==1:
272
raise UFOError, "UFO does not support yet more than one occurence of CTParameters in the couplings values."
273
elif numberOfMatches>1:
274
raise UFOError, "UFO does not support yet more than one occurence of CTParameters in the couplings values."
282
if CTparam.pole(x)=='ZERO':
285
def substitution(matchedObj):
286
return matchedObj.group('first')+"("+CTparam.pole(x)+")"+matchedObj.group('second')
287
pattern=re.compile(r"(?P<first>\A|\*|\+|\-|\()(?P<name>"+CTparam.name+r")(?P<second>\Z|\*|\+|\-|\))")
288
return pattern.sub(substitution,self.value)
292
class Lorentz(UFOBaseClass):
294
require_args=['name','spins','structure']
296
def __init__(self, name, spins, structure='external', **opt):
297
args = (name, spins, structure)
298
UFOBaseClass.__init__(self, *args, **opt)
301
all_lorentz.append(self)
306
class Function(object):
308
def __init__(self, name, arguments, expression):
311
all_functions.append(self)
314
self.arguments = arguments
315
self.expr = expression
317
def __call__(self, *opt):
319
for i, arg in enumerate(self.arguments):
320
exec('%s = %s' % (arg, opt[i] ))
322
return eval(self.expr)
326
class CouplingOrder(object):
328
def __init__(self, name, expansion_order, hierarchy, perturbative_expansion = 0):
331
all_orders.append(self)
334
self.expansion_order = expansion_order
335
self.hierarchy = hierarchy
336
self.perturbative_expansion = perturbative_expansion
340
class Decay(UFOBaseClass):
341
require_args = ['particle','partial_widths']
343
def __init__(self, particle, partial_widths, **opt):
344
args = (particle, partial_widths)
345
UFOBaseClass.__init__(self, *args, **opt)
348
all_decays.append(self)
350
# Add the information directly to the particle
351
particle.partial_widths = partial_widths
353
all_form_factors = []
355
class FormFactor(UFOBaseClass):
356
require_args = ['name','type','value']
358
def __init__(self, name, type, value, **opt):
359
args = (name, type, value)
360
UFOBaseClass.__init__(self, *args, **opt)
362
global all_form_factors
363
all_form_factors.append(self)
368
class Propagator(UFOBaseClass):
370
require_args = ['name','numerator','denominator']
372
def __init__(self, name, numerator, denominator=None, **opt):
373
args = (name, numerator, denominator)
374
UFOBaseClass.__init__(self, *args, **opt)
376
global all_propagators
377
all_propagators.append(self)