~maddevelopers/mg5amcnlo/2.5.3

« back to all changes in this revision

Viewing changes to models/TopEffTh/object_library.py

  • Committer: olivier-mattelaer
  • Date: 2017-03-08 12:31:17 UTC
  • Revision ID: olivier-mattelaer-20170308123117-h0zkqjyh9sihsc61
empty version to have an effective freeze of the code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##
2
 
##
3
 
## Feynrules Header
4
 
##
5
 
##
6
 
##
7
 
##
8
 
##
9
 
 
10
 
import cmath
11
 
import re
12
 
 
13
 
class UFOError(Exception):
14
 
        """Exception raised if when inconsistencies are detected in the UFO model."""
15
 
        pass
16
 
 
17
 
class UFOBaseClass(object):
18
 
    """The class from which all FeynRules classes are derived."""
19
 
 
20
 
    require_args = []
21
 
 
22
 
    def __init__(self, *args, **options):
23
 
        assert(len(self.require_args) == len (args))
24
 
    
25
 
        for i, name in enumerate(self.require_args):
26
 
            setattr(self, name, args[i])
27
 
    
28
 
        for (option, value) in options.items():
29
 
            setattr(self, option, value)
30
 
 
31
 
    def get(self, name):
32
 
        return getattr(self, name)
33
 
    
34
 
    def set(self, name, value):
35
 
        setattr(self, name, value)
36
 
        
37
 
    def get_all(self):
38
 
        """Return a dictionary containing all the information of the object"""
39
 
        return self.__dict__
40
 
 
41
 
    def __str__(self):
42
 
        return self.name
43
 
 
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()])
47
 
 
48
 
    def __repr__(self):
49
 
        replacements = [
50
 
            ('+','__plus__'),
51
 
            ('-','__minus__'),
52
 
            ('@','__at__'),
53
 
            ('!','__exclam__'),
54
 
            ('?','__quest__'),
55
 
            ('*','__star__'),
56
 
            ('~','__tilde__')
57
 
            ]
58
 
        text = self.name
59
 
        for orig,sub in replacements:
60
 
            text = text.replace(orig,sub)
61
 
        return text
62
 
 
63
 
 
64
 
 
65
 
all_particles = []
66
 
 
67
 
class Particle(UFOBaseClass):
68
 
    """A standard Particle"""
69
 
 
70
 
    require_args=['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname', 'charge']
71
 
 
72
 
    require_args_all = ['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname','counterterm','charge', 'line', 'propagating', 'goldstoneboson', 'propagator']
73
 
 
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):
77
 
 
78
 
        args= (pdg_code, name, antiname, spin, color, mass, width, texname,
79
 
                antitexname, float(charge))
80
 
 
81
 
        UFOBaseClass.__init__(self, *args,  **options)
82
 
 
83
 
        global all_particles
84
 
        all_particles.append(self)
85
 
 
86
 
        self.propagating = propagating
87
 
        self.goldstoneboson= goldstoneboson
88
 
 
89
 
        self.selfconjugate = (name == antiname)
90
 
        if not line:                                                                                                                                                                                   
91
 
            self.line = self.find_line_type()
92
 
        else:
93
 
            self.line = line
94
 
 
95
 
        if propagator:
96
 
            if isinstance(propagator, dict):
97
 
                self.propagator = propagator
98
 
            else:
99
 
                self.propagator = {0: propagator, 1: propagator}
100
 
             
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
104
 
        """
105
 
        
106
 
        spin = self.spin
107
 
        color = self.color
108
 
        
109
 
        #use default
110
 
        if spin == 1:
111
 
            return 'dashed'
112
 
        elif spin == 2:
113
 
            if not self.selfconjugate:
114
 
                return 'straight'
115
 
            elif color == 1:
116
 
                return 'swavy'
117
 
            else:
118
 
                return 'scurly'
119
 
        elif spin == 3:
120
 
            if color == 1:
121
 
                return 'wavy'
122
 
            
123
 
            else:
124
 
                return 'curly'
125
 
        elif spin == 5:
126
 
            return 'double'
127
 
        elif spin == -1:
128
 
            return 'dotted'
129
 
        else:
130
 
            return 'dashed' # not supported yet
131
 
        
132
 
    def anti(self):
133
 
        if self.selfconjugate:
134
 
            raise Exception('%s has no anti particle.' % self.name) 
135
 
        outdic = {}
136
 
        for k,v in self.__dict__.iteritems():
137
 
            if k not in self.require_args_all:                
138
 
                outdic[k] = -v
139
 
        if self.color in [1,8]:
140
 
            newcolor = self.color
141
 
        else:
142
 
            newcolor = -self.color
143
 
                
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)
146
 
 
147
 
 
148
 
 
149
 
all_parameters = []
150
 
 
151
 
class Parameter(UFOBaseClass):
152
 
 
153
 
    require_args=['name', 'nature', 'type', 'value', 'texname']
154
 
 
155
 
    def __init__(self, name, nature, type, value, texname, lhablock=None, lhacode=None):
156
 
 
157
 
        args = (name,nature,type,value,texname)
158
 
 
159
 
        UFOBaseClass.__init__(self, *args)
160
 
 
161
 
        args=(name,nature,type,value,texname)
162
 
 
163
 
        global all_parameters
164
 
        all_parameters.append(self)
165
 
 
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
170
 
 
171
 
all_CTparameters = []
172
 
 
173
 
class CTParameter(UFOBaseClass):
174
 
 
175
 
    require_args=['name', 'nature,', 'type', 'value', 'texname']
176
 
 
177
 
    def __init__(self, name, type, value, texname):
178
 
 
179
 
        args = (name,'internal',type,value,texname)
180
 
 
181
 
        UFOBaseClass.__init__(self, *args)
182
 
 
183
 
        args=(name,'internal',type,value,texname)
184
 
 
185
 
        self.nature='interal'
186
 
 
187
 
        global all_CTparameters
188
 
        all_CTparameters.append(self)
189
 
 
190
 
    def finite(self):
191
 
        try:
192
 
            return self.value[0]
193
 
        except KeyError:
194
 
            return 'ZERO'
195
 
    
196
 
    def pole(self, x):
197
 
        try:
198
 
            return self.value[-x]
199
 
        except KeyError:
200
 
            return 'ZERO'
201
 
 
202
 
all_vertices = []
203
 
 
204
 
class Vertex(UFOBaseClass):
205
 
 
206
 
    require_args=['name', 'particles', 'color', 'lorentz', 'couplings']
207
 
 
208
 
    def __init__(self, name, particles, color, lorentz, couplings, **opt):
209
 
 
210
 
        args = (name, particles, color, lorentz, couplings)
211
 
 
212
 
        UFOBaseClass.__init__(self, *args, **opt)
213
 
 
214
 
        args=(particles,color,lorentz,couplings)
215
 
 
216
 
        global all_vertices
217
 
        all_vertices.append(self)
218
 
 
219
 
all_CTvertices = []
220
 
 
221
 
class CTVertex(UFOBaseClass):
222
 
 
223
 
    require_args=['name', 'particles', 'color', 'lorentz', 'couplings', 'type', 'loop_particles']
224
 
 
225
 
    def __init__(self, name, particles, color, lorentz, couplings, type, loop_particles, **opt):
226
 
 
227
 
        args = (name, particles, color, lorentz, couplings, type, loop_particles)
228
 
 
229
 
        UFOBaseClass.__init__(self, *args, **opt)
230
 
 
231
 
        args=(particles,color,lorentz,couplings, type, loop_particles)
232
 
        
233
 
        global all_CTvertices
234
 
        all_CTvertices.append(self)
235
 
 
236
 
all_couplings = []
237
 
 
238
 
class Coupling(UFOBaseClass):
239
 
 
240
 
    require_args=['name', 'value', 'order']
241
 
 
242
 
    require_args_all=['name', 'value', 'order', 'loop_particles', 'counterterm']
243
 
 
244
 
    def __init__(self, name, value, order, **opt):
245
 
 
246
 
        args =(name, value, order)      
247
 
        UFOBaseClass.__init__(self, *args, **opt)
248
 
        global all_couplings
249
 
        all_couplings.append(self)
250
 
 
251
 
    def value(self):
252
 
        return self.pole(0)
253
 
 
254
 
    def pole(self, x):
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."""
257
 
        
258
 
        if isinstance(self.value,dict):
259
 
            if -x in self.value.keys():
260
 
                return self.value[-x]
261
 
            else:
262
 
                return 'ZERO'
263
 
 
264
 
        CTparam=None
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:
269
 
               if not CTparam:
270
 
                   CTparam=param
271
 
               else:
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."
275
 
 
276
 
        if not CTparam:
277
 
            if x==0:
278
 
                return self.value
279
 
            else:
280
 
                return 'ZERO'
281
 
        else:
282
 
            if CTparam.pole(x)=='ZERO':
283
 
                return 'ZERO'
284
 
            else:
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)
289
 
 
290
 
all_lorentz = []
291
 
 
292
 
class Lorentz(UFOBaseClass):
293
 
 
294
 
    require_args=['name','spins','structure']
295
 
    
296
 
    def __init__(self, name, spins, structure='external', **opt):
297
 
        args = (name, spins, structure)
298
 
        UFOBaseClass.__init__(self, *args, **opt)
299
 
 
300
 
        global all_lorentz
301
 
        all_lorentz.append(self)
302
 
 
303
 
 
304
 
all_functions = []
305
 
 
306
 
class Function(object):
307
 
 
308
 
    def __init__(self, name, arguments, expression):
309
 
 
310
 
        global all_functions
311
 
        all_functions.append(self)
312
 
 
313
 
        self.name = name
314
 
        self.arguments = arguments
315
 
        self.expr = expression
316
 
    
317
 
    def __call__(self, *opt):
318
 
 
319
 
        for i, arg in enumerate(self.arguments):
320
 
            exec('%s = %s' % (arg, opt[i] ))
321
 
 
322
 
        return eval(self.expr)
323
 
 
324
 
all_orders = []
325
 
 
326
 
class CouplingOrder(object):
327
 
 
328
 
    def __init__(self, name, expansion_order, hierarchy, perturbative_expansion = 0):
329
 
        
330
 
        global all_orders
331
 
        all_orders.append(self)
332
 
 
333
 
        self.name = name
334
 
        self.expansion_order = expansion_order
335
 
        self.hierarchy = hierarchy
336
 
        self.perturbative_expansion = perturbative_expansion
337
 
 
338
 
all_decays = []
339
 
 
340
 
class Decay(UFOBaseClass):
341
 
    require_args = ['particle','partial_widths']
342
 
 
343
 
    def __init__(self, particle, partial_widths, **opt):
344
 
        args = (particle, partial_widths)
345
 
        UFOBaseClass.__init__(self, *args, **opt)
346
 
 
347
 
        global all_decays
348
 
        all_decays.append(self)
349
 
    
350
 
        # Add the information directly to the particle
351
 
        particle.partial_widths = partial_widths
352
 
 
353
 
all_form_factors = []
354
 
 
355
 
class FormFactor(UFOBaseClass):
356
 
    require_args = ['name','type','value']
357
 
 
358
 
    def __init__(self, name, type, value, **opt):
359
 
        args = (name, type, value)
360
 
        UFOBaseClass.__init__(self, *args, **opt)
361
 
 
362
 
        global all_form_factors
363
 
        all_form_factors.append(self)
364
 
 
365
 
        
366
 
all_propagators = []
367
 
 
368
 
class Propagator(UFOBaseClass):
369
 
    
370
 
    require_args = ['name','numerator','denominator']
371
 
 
372
 
    def __init__(self, name, numerator, denominator=None, **opt):
373
 
        args = (name, numerator, denominator)
374
 
        UFOBaseClass.__init__(self, *args, **opt)
375
 
 
376
 
        global all_propagators
377
 
        all_propagators.append(self)