~maddevelopers/mg5amcnlo/simple_unlops

« back to all changes in this revision

Viewing changes to tests/input_files/DM_pion/write_param_card.py

  • Committer: olivier-mattelaer
  • Date: 2021-11-12 09:29:31 UTC
  • mfrom: (967.1.15 3.3.0)
  • Revision ID: olivier-mattelaer-20211112092931-4ec9qfzgxkeovqog
versionĀ 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
from __future__ import absolute_import
3
 
from __future__ import print_function
4
 
from six.moves import range
5
 
__date__ = "02 Aug 2012"
 
2
__date__ = "3 june 2010"
6
3
__author__ = 'olivier.mattelaer@uclouvain.be'
7
4
 
8
 
import sys
9
 
if sys.version_info[0] ==2:
10
 
    PY3 = False
11
 
else:
12
 
    PY3 = True
13
 
 
14
 
if not __package__:
15
 
    import os
16
 
    pjoin = os.path.join
17
 
    root = os.path.abspath(os.path.dirname(__file__))
18
 
    sys.path.append(os.path.dirname(root))
19
 
    __package__ = os.path.basename(root)
20
 
    import importlib
21
 
    importlib.import_module(os.path.basename(root))
22
 
 
23
 
 
24
 
from .function_library import *
25
 
 
26
5
class ParamCardWriter(object):
27
6
    
28
7
    header = \
34
13
        """write a valid param_card.dat"""
35
14
        
36
15
        if not list_of_parameters:
37
 
            from .parameters import all_parameters
 
16
            from parameters import all_parameters
38
17
            list_of_parameters = [param for param in all_parameters if \
39
18
                                                       param.nature=='external']
40
19
        
47
26
        self.fsock.write(self.header)
48
27
        
49
28
        self.write_card(list_of_parameters)
50
 
        self.fsock.close()
51
29
    
52
30
    def define_not_dep_param(self, list_of_parameters):
53
31
        """define self.dep_mass and self.dep_width in case that they are 
54
32
        requested in the param_card.dat"""
55
 
        from .particles import all_particles
 
33
        from particles import all_particles
56
34
        
57
35
        self.dep_mass = [(part, part.mass) for part in all_particles \
58
36
                            if part.pdg_code > 0 and \
101
79
            self.write_block(lhablock)
102
80
            need_writing = [ param for param in all_ext_param if \
103
81
                                                     param.lhablock == lhablock]
104
 
            need_writing.sort(self.order_param)
 
82
            from functools import cmp_to_key
 
83
            need_writing.sort(key=cmp_to_key(self.order_param))
105
84
            [self.write_param(param, lhablock) for param in need_writing]
106
85
            
107
86
            if self.generic_output:
136
115
    
137
116
    def write_dep_param_block(self, lhablock):
138
117
        import cmath
139
 
        from .parameters import all_parameters
140
 
        from .particles import all_particles
 
118
        from parameters import all_parameters
141
119
        for parameter in all_parameters:
142
 
            exec("%s = %s" % (parameter.name, parameter.value))
 
120
            try:
 
121
                exec("%s = %s" % (parameter.name, parameter.value))
 
122
            except Exception:
 
123
                pass
143
124
        text = "##  Not dependent paramater.\n"
144
125
        text += "## Those values should be edited following analytical the \n"
145
126
        text += "## analytical expression. Some generator could simply ignore \n"
151
132
        else:
152
133
            data = self.dep_width
153
134
            prefix = "DECAY "
154
 
 
155
135
        for part, param in data:
156
136
            if isinstance(param.value, str):
157
137
                value = complex(eval(param.value)).real
160
140
            
161
141
            text += """%s %s %f # %s : %s \n""" %(prefix, part.pdg_code, 
162
142
                        value, part.name, param.value)
163
 
        # If more than a particles has the same mass/width we need to write it here
164
 
        # as well
165
 
        if lhablock == 'MASS':
166
 
            arg = 'mass'
167
 
            done = [part for (part, param) in self.dep_mass]
168
 
        else:
169
 
            arg = 'width'
170
 
            done = [part for (part, param) in self.dep_width]
171
 
        for particle in all_particles:
172
 
            if particle.pdg_code <0:
173
 
                continue
174
 
            is_define = True
175
 
            if particle not in done:
176
 
                if getattr(particle, arg).lhacode[0] != particle.pdg_code:
177
 
                    is_define = False                
178
 
            if  not is_define:
179
 
                value = float(particle.get(arg).value )
180
 
                name =  particle.get(arg).name 
181
 
                text += """%s %s %f # %s : %s \n""" %(prefix, particle.pdg_code, 
182
 
                        value, particle.name, name)
183
 
 
184
 
 
185
 
 
186
 
 
187
143
        self.fsock.write(text)    
188
 
        
 
144
    
189
145
    sm_pdg = [1,2,3,4,5,6,11,12,13,13,14,15,16,21,22,23,24,25]
190
146
    data="""Block QNUMBERS %(pdg)d  # %(name)s 
191
147
        1 %(charge)d  # 3 times electric charge
195
151
    
196
152
    def write_qnumber(self):
197
153
        """ write qnumber """
198
 
        from .particles import all_particles
199
 
        from . import particles
200
 
        print(particles.__file__)
 
154
        from particles import all_particles
 
155
        
201
156
        text="""#===========================================================\n"""
202
157
        text += """# QUANTUM NUMBERS OF NEW STATE(S) (NON SM PDG CODE)\n"""
203
158
        text += """#===========================================================\n\n"""
208
163
            text += self.data % {'pdg': part.pdg_code,
209
164
                                 'name': part.name,
210
165
                                 'charge': 3 * part.charge,
211
 
                                 'spin': part.spin,
 
166
                                 'spin': 2 * part.spin + 1,
212
167
                                 'color': part.color,
213
168
                                 'antipart': part.name != part.antiname and 1 or 0}
214
169
        
215
170
        self.fsock.write(text)
216
171
        
 
172
        
217
173
            
218
174
            
219
175