~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to models/OLD_loopModels_backup/smQCDNLOmass/object_library.py

pass to v2.0.0

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
 
 
12
 
 
13
class UFOBaseClass(object):
 
14
    """The class from which all FeynRules classes are derived."""
 
15
 
 
16
    require_args = []
 
17
 
 
18
    def __init__(self, *args, **options):
 
19
        assert(len(self.require_args) == len (args))
 
20
    
 
21
        for i, name in enumerate(self.require_args):
 
22
            setattr(self, name, args[i])
 
23
    
 
24
        for (option, value) in options.items():
 
25
            setattr(self, option, value)
 
26
 
 
27
    def get(self, name):
 
28
        return getattr(self, name)
 
29
    
 
30
    def set(self, name, value):
 
31
        setattr(self, name, value)
 
32
        
 
33
    def get_all(self):
 
34
        """Return a dictionary containing all the information of the object"""
 
35
        return self.__dict__
 
36
 
 
37
    def __str__(self):
 
38
        return self.name
 
39
 
 
40
    def nice_string(self):
 
41
        """ return string with the full information """
 
42
        return '\n'.join(['%s \t: %s' %(name, value) for name, value in self.__dict__.items()])
 
43
 
 
44
    def __repr__(self):
 
45
        replacements = [
 
46
            ('+','__plus__'),
 
47
            ('-','__minus__'),
 
48
            ('@','__at__'),
 
49
            ('!','__exclam__'),
 
50
            ('?','__quest__'),
 
51
            ('*','__star__'),
 
52
            ('~','__tilde__')
 
53
            ]
 
54
        text = self.name
 
55
        for orig,sub in replacements:
 
56
            text = text.replace(orig,sub)
 
57
        return text
 
58
 
 
59
 
 
60
 
 
61
all_particles = []
 
62
 
 
63
    
 
64
 
 
65
class Particle(UFOBaseClass):
 
66
    """A standard Particle""" 
 
67
 
 
68
    require_args=['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname', 'charge']
 
69
 
 
70
    require_args_all = ['pdg_code', 'name', 'antiname', 'spin', 'color', 'mass', 'width', 'texname', 'antitexname', 'charge', 'loop_particles', 'counterterm','line', 'propagating', 'goldstoneboson']
 
71
 
 
72
    def __init__(self, pdg_code, name, antiname, spin, color, mass, width, texname,
 
73
                 antitexname, charge , loop_particles=None, counterterm=None, line=None, propagating=True, goldstoneboson=False, **options):
 
74
 
 
75
        args= (pdg_code, name, antiname, spin, color, mass, width, texname,
 
76
                 antitexname, float(charge))
 
77
 
 
78
        UFOBaseClass.__init__(self, *args,  **options)
 
79
 
 
80
        global all_particles
 
81
        all_particles.append(self)
 
82
 
 
83
        self.propagating = propagating
 
84
        self.goldstoneboson= goldstoneboson
 
85
 
 
86
        self.selfconjugate = (name == antiname)
 
87
        if 1: #not line:
 
88
            self.line = self.find_line_type()
 
89
        else:
 
90
            self.line = line
 
91
 
 
92
    def find_line_type(self):
 
93
        """ find how we draw a line if not defined
 
94
        valid output: dashed/straight/wavy/curly/double/swavy/scurly
 
95
        """
 
96
        
 
97
        spin = self.spin
 
98
        color = self.color
 
99
        
 
100
        #use default
 
101
        if spin == 1:
 
102
            return 'dashed'
 
103
        elif spin == 2:
 
104
            if not self.selfconjugate:
 
105
                return 'straight'
 
106
            elif color == 1:
 
107
                return 'swavy'
 
108
            else:
 
109
                return 'scurly'
 
110
        elif spin == 3:
 
111
            if color == 1:
 
112
                return 'wavy'
 
113
            
 
114
            else:
 
115
                return 'curly'
 
116
        elif spin == 5:
 
117
            return 'double'
 
118
        elif spin == -1:
 
119
            return 'dotted'
 
120
        else:
 
121
            return 'dashed' # not supported yet
 
122
 
 
123
    def anti(self):
 
124
        if self.selfconjugate:
 
125
            raise Exception('%s has no anti particle.' % self.name) 
 
126
        outdic = {}
 
127
        for k,v in self.__dict__.iteritems():
 
128
            if k not in self.require_args_all:                
 
129
                outdic[k] = -v
 
130
        if self.color in [1,8]:
 
131
            newcolor = self.color
 
132
        else:
 
133
            newcolor = -self.color
 
134
                
 
135
        return Particle(-self.pdg_code, self.antiname, self.name, self.spin, newcolor, self.mass, self.width,
 
136
                        self.antitexname, self.texname, -self.charge, self.line, self.propagating, self.goldstoneboson, **outdic)
 
137
 
 
138
 
 
139
 
 
140
all_parameters = []
 
141
 
 
142
class Parameter(UFOBaseClass):
 
143
 
 
144
    require_args=['name', 'nature', 'type', 'value', 'texname']
 
145
 
 
146
    def __init__(self, name, nature, type, value, texname, lhablock=None, lhacode=None):
 
147
 
 
148
        args = (name,nature,type,value,texname)
 
149
 
 
150
        UFOBaseClass.__init__(self, *args)
 
151
 
 
152
        args=(name,nature,type,value,texname)
 
153
 
 
154
        global all_parameters
 
155
        all_parameters.append(self)
 
156
 
 
157
        if (lhablock is None or lhacode is None)  and nature == 'external':
 
158
            raise Exception('Need LHA information for external parameter "%s".' % name)
 
159
        self.lhablock = lhablock
 
160
        self.lhacode = lhacode
 
161
 
 
162
all_CTparameters = []
 
163
 
 
164
class CTParameter(UFOBaseClass):
 
165
 
 
166
    require_args=['name', 'type', 'value', 'texname']
 
167
 
 
168
    def __init__(self, name, type, value, texname):
 
169
 
 
170
        args = (name,type,value,texname)
 
171
 
 
172
        UFOBaseClass.__init__(self, *args)
 
173
 
 
174
        args=(name,type,value,texname)
 
175
 
 
176
        self.nature='interal'
 
177
 
 
178
        global all_CTparameters
 
179
        all_CTparameters.append(self)
 
180
 
 
181
    def finite(self):
 
182
        try:
 
183
            return value[0]
 
184
        except KeyError:
 
185
            return 'ZERO'
 
186
    
 
187
    def pole(self, x):
 
188
        try:
 
189
            return value[-x]
 
190
        except KeyError:
 
191
            return 'ZERO'
 
192
 
 
193
all_vertices = []
 
194
 
 
195
class Vertex(UFOBaseClass):
 
196
 
 
197
    require_args=['name', 'particles', 'color', 'lorentz', 'couplings']
 
198
 
 
199
    def __init__(self, name, particles, color, lorentz, couplings, **opt):
 
200
 
 
201
        args = (name, particles, color, lorentz, couplings)
 
202
 
 
203
        UFOBaseClass.__init__(self, *args, **opt)
 
204
 
 
205
        args=(particles,color,lorentz,couplings)
 
206
        
 
207
        global all_vertices
 
208
        all_vertices.append(self)
 
209
 
 
210
all_CTvertices = []
 
211
 
 
212
class CTVertex(UFOBaseClass):
 
213
 
 
214
    require_args=['name', 'particles', 'color', 'lorentz', 'couplings', 'type', 'loop_particles']
 
215
 
 
216
    def __init__(self, name, particles, color, lorentz, couplings, type, loop_particles, **opt):
 
217
 
 
218
        args = (name, particles, color, lorentz, couplings, type, loop_particles)
 
219
 
 
220
        UFOBaseClass.__init__(self, *args, **opt)
 
221
 
 
222
        args=(particles,color,lorentz,couplings, type, loop_particles)
 
223
        
 
224
        global all_CTvertices
 
225
        all_CTvertices.append(self)
 
226
 
 
227
all_couplings = []
 
228
 
 
229
class Coupling(UFOBaseClass):
 
230
 
 
231
    require_args=['name', 'value', 'order']
 
232
 
 
233
    require_args_all=['name', 'value', 'order', 'loop_particles', 'counterterm']
 
234
 
 
235
    def __init__(self, name, value, order, loop_particles=None, counterterm=None, **opt):
 
236
 
 
237
        args =(name, value, order)      
 
238
        UFOBaseClass.__init__(self, *args, **opt)
 
239
        global all_couplings
 
240
        all_couplings.append(self)
 
241
  
 
242
 
 
243
 
 
244
all_lorentz = []
 
245
 
 
246
class Lorentz(UFOBaseClass):
 
247
 
 
248
    require_args=['name','spins','structure']
 
249
    
 
250
    def __init__(self, name, spins, structure='external', **opt):
 
251
        args = (name, spins, structure)
 
252
        UFOBaseClass.__init__(self, *args, **opt)
 
253
 
 
254
        global all_lorentz
 
255
        all_lorentz.append(self)
 
256
 
 
257
 
 
258
all_functions = []
 
259
 
 
260
class Function(object):
 
261
 
 
262
    def __init__(self, name, arguments, expression):
 
263
 
 
264
        global all_functions
 
265
        all_functions.append(self)
 
266
 
 
267
        self.name = name
 
268
        self.arguments = arguments
 
269
        self.expr = expression
 
270
    
 
271
    def __call__(self, *opt):
 
272
 
 
273
        for i, arg in enumerate(self.arguments):
 
274
            exec('%s = %s' % (arg, opt[i] ))
 
275
 
 
276
        return eval(self.expr)
 
277
 
 
278
all_orders = []
 
279
 
 
280
class CouplingOrder(object):
 
281
 
 
282
    def __init__(self, name, expansion_order, hierarchy, perturbative_expansion = 0):
 
283
        
 
284
        global all_orders
 
285
        all_orders.append(self)
 
286
 
 
287
        self.name = name
 
288
        self.expansion_order = expansion_order
 
289
        self.hierarchy = hierarchy