2
from __future__ import absolute_import
3
from __future__ import print_function
4
from six.moves import range
5
__date__ = "3 june 2010"
6
__author__ = 'olivier.mattelaer@uclouvain.be'
8
from function_library import *
10
class ParamCardWriter(object):
13
"""######################################################################\n""" + \
14
"""## PARAM_CARD AUTOMATICALY GENERATED BY THE UFO #####################\n""" + \
15
"""######################################################################\n"""
17
def __init__(self, filename, list_of_parameters=None, generic=False):
18
"""write a valid param_card.dat"""
20
if not list_of_parameters:
21
from parameters import all_parameters
22
list_of_parameters = [param for param in all_parameters if \
23
param.nature=='external']
25
self.generic_output = generic
27
self.define_not_dep_param(list_of_parameters)
30
self.fsock = open(filename, 'w')
31
self.fsock.write(self.header)
33
self.write_card(list_of_parameters)
35
def define_not_dep_param(self, list_of_parameters):
36
"""define self.dep_mass and self.dep_width in case that they are
37
requested in the param_card.dat"""
38
from particles import all_particles
40
self.dep_mass = [(part, part.mass) for part in all_particles \
41
if part.pdg_code > 0 and \
42
part.mass not in list_of_parameters]
43
self.dep_width = [(part, part.width) for part in all_particles\
44
if part.pdg_code > 0 and \
45
part.width not in list_of_parameters]
48
def order_param(obj1, obj2):
49
""" order parameter of a given block """
51
maxlen = min([len(obj1.lhacode), len(obj2.lhacode)])
53
for i in range(maxlen):
54
if obj1.lhacode[i] < obj2.lhacode[i]:
56
elif obj1.lhacode[i] == obj2.lhacode[i]:
60
#identical up to the first finish
61
if len(obj1.lhacode) > len(obj2.lhacode):
63
elif len(obj1.lhacode) == len(obj2.lhacode):
68
def write_card(self, all_ext_param):
72
all_lhablock = set([param.lhablock for param in all_ext_param])
74
# ordonate lhablock alphabeticaly
75
all_lhablock = list(all_lhablock)
77
# put at the beginning SMINPUT + MASS + DECAY
78
for name in ['DECAY', 'MASS','SMINPUTS']:
79
if name in all_lhablock:
80
all_lhablock.remove(name)
81
all_lhablock.insert(0, name)
83
for lhablock in all_lhablock:
84
self.write_block(lhablock)
85
need_writing = [ param for param in all_ext_param if \
86
param.lhablock == lhablock]
87
from functools import cmp_to_key
88
need_writing.sort(key=cmp_to_key(self.order_param))
89
[self.write_param(param, lhablock) for param in need_writing]
91
if self.generic_output:
92
if lhablock in ['MASS', 'DECAY']:
93
self.write_dep_param_block(lhablock)
95
if self.generic_output:
98
def write_block(self, name):
99
""" write a comment for a block"""
101
self.fsock.writelines(
102
"""\n###################################""" + \
103
"""\n## INFORMATION FOR %s""" % name.upper() +\
104
"""\n###################################\n"""
107
self.fsock.write("""Block %s \n""" % name)
109
def write_param(self, param, lhablock):
111
lhacode=' '.join(['%3s' % key for key in param.lhacode])
112
if lhablock != 'DECAY':
113
text = """ %s %e # %s \n""" % (lhacode, complex(param.value).real, param.name )
115
text = '''DECAY %s %e \n''' % (lhacode, complex(param.value).real)
116
self.fsock.write(text)
121
def write_dep_param_block(self, lhablock):
123
from parameters import all_parameters
124
for parameter in all_parameters:
125
exec("%s = %s" % (parameter.name, parameter.value))
126
text = "## Not dependent paramater.\n"
127
text += "## Those values should be edited following analytical the \n"
128
text += "## analytical expression. Some generator could simply ignore \n"
129
text += "## those values and use the analytical expression\n"
131
if lhablock == 'MASS':
135
data = self.dep_width
137
for part, param in data:
138
if isinstance(param.value, str):
139
value = complex(eval(param.value)).real
143
text += """%s %s %f # %s : %s \n""" %(prefix, part.pdg_code,
144
value, part.name, param.value)
145
self.fsock.write(text)
147
sm_pdg = [1,2,3,4,5,6,11,12,13,13,14,15,16,21,22,23,24,25]
148
data="""Block QNUMBERS %(pdg)d # %(name)s
149
1 %(charge)d # 3 times electric charge
150
2 %(spin)d # number of spin states (2S+1)
151
3 %(color)d # colour rep (1: singlet, 3: triplet, 8: octet)
152
4 %(antipart)d # Particle/Antiparticle distinction (0=own anti)\n"""
154
def write_qnumber(self):
155
""" write qnumber """
156
from particles import all_particles
158
text="""#===========================================================\n"""
159
text += """# QUANTUM NUMBERS OF NEW STATE(S) (NON SM PDG CODE)\n"""
160
text += """#===========================================================\n\n"""
162
for part in all_particles:
163
if part.pdg_code in self.sm_pdg or part.pdg_code < 0:
165
text += self.data % {'pdg': part.pdg_code,
167
'charge': 3 * part.charge,
168
'spin': 2 * part.spin + 1,
170
'antipart': part.name != part.antiname and 1 or 0}
172
self.fsock.write(text)
181
if '__main__' == __name__:
182
ParamCardWriter('./param_card.dat', generic=True)
183
print('write ./param_card.dat')