1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """Module to allow reading a param_card and setting all parameters and
16 couplings for a model"""
17
18 from __future__ import division
19
20 import array
21 import cmath
22 import copy
23 import itertools
24 import logging
25 import math
26 import os
27 import re
28
29 import madgraph.core.base_objects as base_objects
30 import models.check_param_card as card_reader
31 from madgraph import MadGraph5Error, MG5DIR
32
33 ZERO = 0
34
35
36
37
38
39 logger = logging.getLogger('models.model_reader')
40
41
42
43
44
46 """Object to read all parameters and couplings of a model
47 """
48
50 """The particles is changed to ParticleList"""
51 self['coupling_dict'] = {}
52 self['parameter_dict'] = {}
53 super(ModelReader, self).default_setup()
54
56 """Read a param_card and calculate all parameters and
57 couplings. Set values directly in the parameters and
58 couplings, plus add new dictionary coupling_dict from
59 parameter name to value."""
60
61
62 external_parameters = self['parameters'][('external',)]
63
64
65 if param_card:
66
67
68 if not os.path.isfile(param_card):
69 raise MadGraph5Error, \
70 "No such file %s" % param_card
71
72
73
74 parameter_dict = {}
75 for param in external_parameters:
76 try:
77 dictionary = parameter_dict[param.lhablock.lower()]
78 except KeyError:
79 dictionary = {}
80 parameter_dict[param.lhablock.lower()] = dictionary
81 dictionary[tuple(param.lhacode)] = param
82
83 param_card = card_reader.ParamCard(param_card)
84
85 key = [k for k in param_card.keys() if not k.startswith('qnumbers ')
86 and not k.startswith('decay_table')]
87
88 if set(key) != set(parameter_dict.keys()):
89 raise MadGraph5Error, '''Invalid restriction card (not same block)
90 %s != %s
91 ''' % (set(key), set(parameter_dict.keys()))
92 for block in key:
93 for id in parameter_dict[block]:
94 try:
95 value = param_card[block].get(id).value
96 except:
97 raise MadGraph5Error, '%s %s not define' % (block, id)
98 else:
99 exec("locals()[\'%s\'] = %s" % (parameter_dict[block][id].name,
100 value))
101 parameter_dict[block][id].value = float(value)
102
103 else:
104
105 for param in external_parameters:
106 exec("locals()[\'%s\'] = %s" % (param.name, param.value))
107
108
109 for func in self['functions']:
110 exec("def %s(%s):\n return %s" % (func.name,
111 ",".join(func.arguments),
112 func.expr))
113
114
115 derived_parameters = []
116 keys = [key for key in self['parameters'].keys() if \
117 key != ('external',)]
118 keys.sort(key=len)
119 for key in keys:
120 derived_parameters += self['parameters'][key]
121
122
123
124 for param in derived_parameters:
125 try:
126 exec("locals()[\'%s\'] = %s" % (param.name, param.expr))
127 except Exception as error:
128 msg = 'Unable to evaluate %s: raise error: %s' % (param.expr, error)
129 raise MadGraph5Error, msg
130 param.value = complex(eval(param.name))
131 if not eval(param.name) and eval(param.name) != 0:
132 logger.warning("%s has no expression: %s" % (param.name,
133 param.expr))
134
135
136
137 for particle in self.get('particles'):
138 if particle.is_fermion() and particle.get('self_antipart') and \
139 particle.get('width').lower() != 'zero' and \
140 eval(particle.get('mass')).real < 0:
141 exec("locals()[\'%(width)s\'] = -abs(%(width)s)" % \
142 {'width': particle.get('width')})
143
144
145 couplings = sum(self['couplings'].values(), [])
146
147 for coup in couplings:
148 exec("locals()[\'%s\'] = %s" % (coup.name, coup.expr))
149 coup.value = complex(eval(coup.name))
150 if not eval(coup.name) and eval(coup.name) != 0:
151 logger.warning("%s has no expression: %s" % (coup.name,
152 coup.expr))
153
154
155
156 self.set('parameter_dict', dict([(param.name, param.value) \
157 for param in external_parameters + \
158 derived_parameters]))
159
160
161 self.get('parameter_dict')['ZERO'] = complex(0.)
162
163 self.set('coupling_dict', dict([(coup.name, coup.value) \
164 for coup in couplings]))
165