~maddevelopers/mg5amcnlo/FKS_EW_granny

« back to all changes in this revision

Viewing changes to models/uutt_sch_4fermion/object_library.py

  • Committer: Marco Zaro
  • Date: 2018-04-16 14:08:47 UTC
  • mfrom: (78.403.58 2.6.2)
  • Revision ID: marco.zaro@gmail.com-20180416140847-nuz7haj3di3gqqhq
merged with 2.6.2 rev 332

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', 'line', 'propagating', 'goldstoneboson']
71
 
 
72
 
    def __init__(self, pdg_code, name, antiname, spin, color, mass, width, texname,
73
 
                 antitexname, charge , 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
 
 
93
 
 
94
 
 
95
 
    def find_line_type(self):
96
 
        """ find how we draw a line if not defined
97
 
        valid output: dashed/straight/wavy/curly/double/swavy/scurly
98
 
        """
99
 
        
100
 
        spin = self.spin
101
 
        color = self.color
102
 
        
103
 
        #use default
104
 
        if spin == 1:
105
 
            return 'dashed'
106
 
        elif spin == 2:
107
 
            if not self.selfconjugate:
108
 
                return 'straight'
109
 
            elif color == 1:
110
 
                return 'swavy'
111
 
            else:
112
 
                return 'scurly'
113
 
        elif spin == 3:
114
 
            if color == 1:
115
 
                return 'wavy'
116
 
            
117
 
            else:
118
 
                return 'curly'
119
 
        elif spin == 5:
120
 
            return 'double'
121
 
        elif spin == -1:
122
 
            return 'dotted'
123
 
        else:
124
 
            return 'dashed' # not supported yet
125
 
 
126
 
    def anti(self):
127
 
        if self.selfconjugate:
128
 
            raise Exception('%s has no anti particle.' % self.name) 
129
 
        outdic = {}
130
 
        for k,v in self.__dict__.iteritems():
131
 
            if k not in self.require_args_all:                
132
 
                outdic[k] = -v
133
 
        if self.color in [1,8]:
134
 
            newcolor = self.color
135
 
        else:
136
 
            newcolor = -self.color
137
 
                
138
 
        return Particle(-self.pdg_code, self.antiname, self.name, self.spin, newcolor, self.mass, self.width,
139
 
                        self.antitexname, self.texname, -self.charge, self.line, self.propagating, self.goldstoneboson, **outdic)
140
 
 
141
 
 
142
 
 
143
 
all_parameters = []
144
 
 
145
 
class Parameter(UFOBaseClass):
146
 
 
147
 
    require_args=['name', 'nature', 'type', 'value', 'texname']
148
 
 
149
 
    def __init__(self, name, nature, type, value, texname, lhablock=None, lhacode=None):
150
 
 
151
 
        args = (name,nature,type,value,texname)
152
 
 
153
 
        UFOBaseClass.__init__(self, *args)
154
 
 
155
 
        args=(name,nature,type,value,texname)
156
 
 
157
 
        global all_parameters
158
 
        all_parameters.append(self)
159
 
 
160
 
        if (lhablock is None or lhacode is None)  and nature == 'external':
161
 
            raise Exception('Need LHA information for external parameter "%s".' % name)
162
 
        self.lhablock = lhablock
163
 
        self.lhacode = lhacode
164
 
 
165
 
all_vertices = []
166
 
 
167
 
class Vertex(UFOBaseClass):
168
 
 
169
 
    require_args=['name', 'particles', 'color', 'lorentz', 'couplings']
170
 
 
171
 
    def __init__(self, name, particles, color, lorentz, couplings, **opt):
172
 
 
173
 
        args = (name, particles, color, lorentz, couplings)
174
 
 
175
 
        UFOBaseClass.__init__(self, *args, **opt)
176
 
 
177
 
        args=(particles,color,lorentz,couplings)
178
 
 
179
 
        global all_vertices
180
 
        all_vertices.append(self)
181
 
 
182
 
all_couplings = []
183
 
 
184
 
class Coupling(UFOBaseClass):
185
 
 
186
 
    require_args=['name', 'value', 'order']
187
 
 
188
 
    def __init__(self, name, value, order, **opt):
189
 
 
190
 
        args =(name, value, order)      
191
 
        UFOBaseClass.__init__(self, *args, **opt)
192
 
        global all_couplings
193
 
        all_couplings.append(self)
194
 
  
195
 
 
196
 
 
197
 
all_lorentz = []
198
 
 
199
 
class Lorentz(UFOBaseClass):
200
 
 
201
 
    require_args=['name','spins','structure']
202
 
    
203
 
    def __init__(self, name, spins, structure='external', **opt):
204
 
        args = (name, spins, structure)
205
 
        UFOBaseClass.__init__(self, *args, **opt)
206
 
 
207
 
        global all_lorentz
208
 
        all_lorentz.append(self)
209
 
 
210
 
 
211
 
all_functions = []
212
 
 
213
 
class Function(object):
214
 
 
215
 
    def __init__(self, name, arguments, expression):
216
 
 
217
 
        global all_functions
218
 
        all_functions.append(self)
219
 
 
220
 
        self.name = name
221
 
        self.arguments = arguments
222
 
        self.expr = expression
223
 
    
224
 
    def __call__(self, *opt):
225
 
 
226
 
        for i, arg in enumerate(self.arguments):
227
 
            exec('%s = %s' % (arg, opt[i] ))
228
 
 
229
 
        return eval(self.expr)
230
 
 
231
 
all_orders = []
232
 
 
233
 
class CouplingOrder(object):
234
 
 
235
 
    def __init__(self, name, expansion_order, hierarchy, perturbative_expansion = 0):
236
 
        
237
 
        global all_orders
238
 
        all_orders.append(self)
239
 
 
240
 
        self.name = name
241
 
        self.expansion_order = expansion_order
242
 
        self.hierarchy = hierarchy
243
 
 
244
 
 
245