DevelopmentPage/BeyondProjects: create_helas.py

File create_helas.py, 5.8 KB (added by Will Link, 14 years ago)
Line 
1################################################################################
2#
3# Copyright (c) 2010 The MadGraph Development team and Contributors
4#
5# This file is a part of the MadGraph 5 project, an application which
6# automatically generates Feynman diagrams and matrix elements for arbitrary
7# high-energy processes in the Standard Model and beyond.
8#
9# It is subject to the MadGraph license which should accompany this
10# distribution.
11#
12# For more information, please visit: http://madgraph.phys.ucl.ac.be
13#
14################################################################################
15
16import helasamp_object as HelasObject
17#import helasamp_lib as HelasLib
18import lorentz as Lorentz
19import WriteHelas as WriteHelas
20import copy
21
22
23class CreatingHelas(object):
24 """ Launch the creation of the Helas Routine"""
25
26 spin_to_type={1:'Scalar', 2:'Spinor', 3:'Vector', 5: 'Spin2'}
27
28
29 def __init__(self, lorentz, language='Fortran', modes='all', **opt):
30
31 self.language = language #class = eval('WriteHelas.HelasWriterFor'+language)
32 self.parttype = [self.spin_to_type[spin] for spin in lorentz['Particles']]
33 self.name = lorentz['Name']
34 self.lorentzstructure = lorentz['Structure']
35
36 if modes == 'all':
37 modes = self.return_all_mode()
38
39 for mode in modes:
40 self.write(mode)
41
42 def return_all_mode(self):
43 """Return a list with tuple (particle, Onshell/Offshell) """
44
45 out = []
46 #First fill the onshell
47 onshell=[]
48 for particles in self.parttype:
49 onshell.append((particles, 1))
50 out.append(onshell)
51
52 #Add the Offshell routines
53 for i, particles in enumerate(self.parttype):
54 offshell= copy.copy(onshell)
55 offshell[i] = (particles, 0)
56 out.append(offshell)
57 return out
58
59
60 def define_Helas_obj(self, mode):
61 """Multiplying the lorentz with Amplitude/Propagator"""
62
63 out=[]
64 #Loop over All Helas Amplitude
65 for lorentz in self.lorentzstructure:
66
67
68 nb_offshell = 0
69 nb_spinor =0
70 for (part_id, info ) in enumerate(mode):
71 onshell = info[1]
72 typepart = info[0]
73
74 if typepart == 'Scalar':
75 if onshell:
76 lorentz *= HelasObject.Scalar(part_id+1)
77 else:
78 nb_offshell += 1
79 lorentz *= complex(0,1) / \
80 HelasObject.DenominatorPropagator(part_id+1)
81
82 elif typepart == 'Spinor':
83 nb_spinor += 1
84 if onshell:
85 lorentz *= HelasObject.Spinor(part_id+1,part_id+1)
86 elif nb_spinor %2:
87 nb_offshell += 1
88 lorentz *= HelasObject.SpinorPropagator('I2', part_id+1, part_id+1)
89 lorentz /= HelasObject.DenominatorPropagator(part_id+1)
90 else:
91 nb_offshell += 1
92 lorentz *= HelasObject.SpinorPropagator(part_id+1,'I2', part_id+1)
93 lorentz /= HelasObject.DenominatorPropagator(part_id+1)
94
95 elif typepart == 'Vector':
96 if onshell:
97 lorentz *= HelasObject.Vector(part_id+1, part_id+1)
98 else:
99 nb_offshell += 1
100 lorentz *= HelasObject.VectorPropagator(part_id+1,'I2', part_id+1)
101 lorentz /= HelasObject.DenominatorPropagator(part_id+1)
102
103 elif typepart == 'Spin2':
104 if onshell:
105 lorentz *= HelasObject.Spin2(10*(part_id+1)+1, 10*(part_id+1)+2)
106 else:
107 nb_offshell += 1
108 lorentz *= HelasObject.Spin2Propagator(10*(part_id+1)+1, \
109 10*(part_id)+1,'I2','I3', part_id+1)
110 lorentz /= HelasObject.DenominatorPropagator(part_id+1)
111 # If no particle OffShell
112 if nb_offshell == 0:
113 lorentz *= complex(0,-1)
114
115 out.append(lorentz)
116 return out
117
118 def getonshellname(self,mode):
119
120 out=""
121 for spin, onshell in mode:
122 if onshell:
123 out += "1"
124 else:
125 out +='0'
126 return out
127
128 def write(self, mode):
129 """write the lorentz structure in the Helas Routine file filepos"""
130
131 lorentzs = self.define_Helas_obj(mode)
132 for lorentz in lorentzs:
133 spin_to_type = {'Scalar':'S', 'Spinor':'F', 'Vector':'V','Spin2':'T'}
134 info = [(spin_to_type[data1], data2) for data1, data2 in mode]
135
136 onshellinfo = self.getonshellname(mode)
137 name = self.name +'_'+onshellinfo
138 infostr =str(lorentz)
139 lorentz = lorentz.simplify()
140 lorentz = lorentz.expand()
141 lorentz = lorentz.simplify()
142 lorentz.factorize()
143 getattr(WriteHelas, 'HelasWriterFor%s' % self.language)\
144 (lorentz, info, name, infostr).write()
145
146
147if '__main__' == __name__:
148
149 def main():
150
151 for i,data in enumerate(Lorentz.Lorentz[:]):
152 print i
153 CreatingHelas(data)
154 print 'all done'
155
156 if 0:
157 import profile
158 profile.run('main()')
159 elif 1:
160 import time
161 start = time.time()
162 main()
163 print (time.time() - start) /len(Lorentz.Lorentz)
164
165
166
167
168
169
170