1
from __future__ import division
2
__date__ = "10 Dec 2012"
3
__author__ = 'olivier.mattelaer@uclouvain.be'
5
from function_library import *
8
class ParamCardWriter(object):
11
"""######################################################################\n""" + \
12
"""## PARAM_CARD AUTOMATICALY GENERATED BY THE UFO #####################\n""" + \
13
"""######################################################################\n"""
15
def __init__(self, filename, list_of_parameters=None, generic=False):
16
"""write a valid param_card.dat"""
18
if not list_of_parameters:
19
from parameters import all_parameters
20
list_of_parameters = [param for param in all_parameters if \
21
param.nature=='external']
23
self.generic_output = generic
25
self.define_not_dep_param(list_of_parameters)
28
self.fsock = open(filename, 'w')
29
self.fsock.write(self.header)
31
self.write_card(list_of_parameters)
34
def define_not_dep_param(self, list_of_parameters):
35
"""define self.dep_mass and self.dep_width in case that they are
36
requested in the param_card.dat"""
37
from particles import all_particles
39
self.dep_mass = [(part, part.mass) for part in all_particles \
40
if part.pdg_code > 0 and \
41
part.mass not in list_of_parameters]
42
self.dep_width = [(part, part.width) for part in all_particles\
43
if part.pdg_code > 0 and \
44
part.width not in list_of_parameters]
47
def order_param(obj1, obj2):
48
""" order parameter of a given block """
50
maxlen = min([len(obj1.lhacode), len(obj2.lhacode)])
52
for i in range(maxlen):
53
if obj1.lhacode[i] < obj2.lhacode[i]:
55
elif obj1.lhacode[i] == obj2.lhacode[i]:
59
#identical up to the first finish
60
if len(obj1.lhacode) > len(obj2.lhacode):
62
elif len(obj1.lhacode) == len(obj2.lhacode):
67
def write_card(self, all_ext_param):
71
all_lhablock = set([param.lhablock for param in all_ext_param])
73
# ordonate lhablock alphabeticaly
74
all_lhablock = list(all_lhablock)
76
# put at the beginning SMINPUT + MASS + DECAY
77
for name in ['DECAY', 'MASS','SMINPUTS']:
78
if name in all_lhablock:
79
all_lhablock.remove(name)
80
all_lhablock.insert(0, name)
82
for lhablock in all_lhablock:
83
self.write_block(lhablock)
84
need_writing = [ param for param in all_ext_param if \
85
param.lhablock == lhablock]
86
need_writing.sort(self.order_param)
87
[self.write_param(param, lhablock) for param in need_writing]
89
if self.generic_output:
90
if lhablock in ['MASS', 'DECAY']:
91
self.write_dep_param_block(lhablock)
93
if self.generic_output:
96
def write_block(self, name):
97
""" write a comment for a block"""
99
self.fsock.writelines(
100
"""\n###################################""" + \
101
"""\n## INFORMATION FOR %s""" % name.upper() +\
102
"""\n###################################\n"""
105
self.fsock.write("""Block %s \n""" % name)
107
def write_param(self, param, lhablock):
109
lhacode=' '.join(['%3s' % key for key in param.lhacode])
110
if lhablock != 'DECAY':
111
text = """ %s %e # %s \n""" % (lhacode, complex(param.value).real, param.name )
113
text = '''DECAY %s %e \n''' % (lhacode, complex(param.value).real)
114
self.fsock.write(text)
119
def write_dep_param_block(self, lhablock):
121
from parameters import all_parameters
122
for parameter in all_parameters:
123
exec("%s = %s" % (parameter.name, parameter.value))
124
text = "## Not dependent paramater.\n"
125
text += "## Those values should be edited following analytical the \n"
126
text += "## analytical expression. Some generator could simply ignore \n"
127
text += "## those values and use the analytical expression\n"
129
if lhablock == 'MASS':
133
data = self.dep_width
135
for part, param in data:
136
if isinstance(param.value, str):
137
value = complex(eval(param.value)).real
141
text += """%s %s %f # %s : %s \n""" %(prefix, part.pdg_code,
142
value, part.name, param.value)
143
self.fsock.write(text)
145
sm_pdg = [1,2,3,4,5,6,11,12,13,13,14,15,16,21,22,23,24,25]
146
data="""Block QNUMBERS %(pdg)d # %(name)s
147
1 %(charge)d # 3 times electric charge
148
2 %(spin)d # number of spin states (2S+1)
149
3 %(color)d # colour rep (1: singlet, 3: triplet, 8: octet)
150
4 %(antipart)d # Particle/Antiparticle distinction (0=own anti)\n"""
152
def write_qnumber(self):
153
""" write qnumber """
154
from particles import all_particles
156
print particles.__file__
157
text="""#===========================================================\n"""
158
text += """# QUANTUM NUMBERS OF NEW STATE(S) (NON SM PDG CODE)\n"""
159
text += """#===========================================================\n\n"""
161
for part in all_particles:
162
if part.pdg_code in self.sm_pdg or part.pdg_code < 0:
164
text += self.data % {'pdg': part.pdg_code,
166
'charge': 3 * part.charge,
169
'antipart': part.name != part.antiname and 1 or 0}
171
self.fsock.write(text)
179
if '__main__' == __name__:
180
ParamCardWriter('./param_card.dat', generic=True)
181
print 'write ./param_card.dat'