16
16
if os.path.isfile(pjoin(root_path,'makefile')) and \
17
17
os.path.isfile(pjoin(root_path,'all_matrix.f')) and \
18
18
not os.path.isfile(pjoin(root_path,'allmatrix2py.so')):
19
print "Trying to automatically generate the python module 'allmatrix2py.so' with f2py..."
19
print( "Trying to automatically generate the python module 'allmatrix2py.so' with f2py...")
20
20
p = subprocess.Popen(['make','allmatrix2py.so'], stdout=subprocess.PIPE,
21
21
stderr=subprocess.PIPE, cwd=root_path)
22
22
(out, err) = p.communicate()
23
24
if p.returncode or not os.path.isfile(pjoin(root_path,'allmatrix2py.so')):
24
print "ERROR: Failed to produce 'allmatrix2py.so' with 'make allmatrix2py.so' in '%s'. The error was:\n%s"%(root_path,err)
25
print( "ERROR: Failed to produce 'allmatrix2py.so' with 'make allmatrix2py.so' in '%s'. The error was:\n%s"%(root_path,err))
27
28
import allmatrix2py
29
print "ERROR: Could not load the f2py module 'allmatrix2py.so'. The following error occurred:\n",sys.exc_info()[0]
30
print( "ERROR: Could not load the f2py module 'allmatrix2py.so'. The following error occurred:\n",sys.exc_info()[0])
32
33
if os.path.exists(pjoin(root_path,'allmatrix2py.so')):
33
print "ERROR: Could not load the f2py module 'matrix2py.so'. The following error occurred:\n",sys.exc_info()[0]
34
print( "ERROR: Could not load the f2py module 'matrix2py.so'. The following error occurred:\n",sys.exc_info()[0])
36
print "ERROR: Could not find the 'matrix2py.so' f2py module. Please generate it by running:\n"+\
37
print( "ERROR: Could not find the 'matrix2py.so' f2py module. Please generate it by running:\n"+\
37
38
" > make matrix2py.so\n"+\
38
"in the <PROC_OUTPUT>/SubProcesses/P<chosen_proc> directory."
39
"in the <PROC_OUTPUT>/SubProcesses/P<chosen_proc> directory.")
41
42
# Now we can use this MadLoop python module.
48
49
# Specify where MadLoop5_resources is
49
50
allmatrix2py.set_madloop_path(os.path.abspath(pjoin(root_path,'MadLoop5_resources')))
50
51
# List all processes available in this module
52
pdgs_order, pids = allmatrix2py.get_pdg_order()
53
all_procs_available = list(zip(pdgs_order, pids))
52
all_procs_available = [[pdg for pdg in proc_pdgs if pdg!=0] for proc_pdgs in allmatrix2py.get_pdg_order()]
53
print "Available processes are:"
55
print( "Available processes are:")
54
56
for process_pdgs in all_procs_available:
55
print " --> %s"%str(process_pdgs)
57
print( " --> %s: process id: %i "%str(process_pdgs[0], process_pdgs[1]))
57
59
def invert_momenta(p):
58
60
""" fortran/C-python do not order table in the same order"""
63
65
# The kinematic configuration in the convention (E, px, py, pz) and with particles ordered as in the process definition.
64
66
# This is the structure of this dictionary.
65
p= dict( (tuple(process_pdgs),[[None,]*4]*len(process_pdgs)) for process_pdgs in all_procs_available)
67
p= dict( (tuple(process_pdgs),[[None,]*4]*len(process_pdgs)) for (process_pdgs,pid) in all_procs_available)
67
68
if (p.values()[0])[0][0] is None:
68
69
if not os.path.isfile(pjoin(root_path,'PS.input')):
69
print "\n\n==================================================================================================================="
70
print "* No kinematics defined! *"
71
print "* ------------------------------------- *"
72
print "* Please either define your kinematic configuration directly in check_sa.py or in a file 'PS.input'. Exiting now. *"
73
print " Here is an example of the content of such a file for a process output containing g g > h and g g > h g."
70
print( "\n\n===================================================================================================================")
71
print( "* No kinematics defined! *")
72
print( "* ------------------------------------- *")
73
print( "* Please either define your kinematic configuration directly in check_sa.py or in a file 'PS.input'. Exiting now. *")
74
print( " Here is an example of the content of such a file for a process output containing g g > h and g g > h g.")
86
87
5.078125000000001E+002 -1.567603625592635E+002 2.039552324827553E+002 4.196152845517468E+002
87
88
4.921874999999999E+002 1.567603625592635E+002 -2.039552324827552E+002 -4.196152845517467E+002
90
print "===================================================================================================================\n\n"
91
print( "===================================================================================================================\n\n")
104
105
current_p.append([float(line.split()[j]) for j in range(4)])
105
106
p[current_process] = current_p
107
print "ERROR: File PS.input is malformed. Error was:\n",sys.exc_info()[0]
108
print( "ERROR: File PS.input is malformed. Error was:\n",sys.exc_info()[0])
111
112
for iProc, (process_pdgs, kinematic_config) in enumerate(p.items()):
113
114
P =invert_momenta(kinematic_config)
120
121
# Choice of renormalization scale
121
122
renormalization_scale = 91.188
123
finite_loop_me, return_code = allmatrix2py.smatrixhel(pdgs=list(process_pdgs),
124
finite_loop_me, return_code = allmatrix2py.smatrixhel(pdgs=list(process_pdgs), procid=-1,
124
125
p=P, alphas=alphas,scales2=renormalization_scale,nhel=nhel)
126
print '* %-108s *'%' MadLoop evaluation for the process '
127
print '* %-108s *'%(' %s'%str(process_pdgs))
128
print '* %-108s *'%' and the kinematic configuration:'
129
print '* %-108s *'%((' %-3s'+' %-25s'*4)%('#','E',' p_x',' p_y',' p_z'))
127
print( '* %-108s *'%' MadLoop evaluation for the process ')
128
print( '* %-108s *'%(' %s'%str(process_pdgs)))
129
print( '* %-108s *'%' and the kinematic configuration:')
130
print( '* %-108s *'%((' %-3s'+' %-25s'*4)%('#','E',' p_x',' p_y',' p_z')))
130
131
for i,k in enumerate(kinematic_config):
131
132
# The complicated printout below is just so as to align the digits negative numbers with positive ones
132
print '* %-108s *'%((' %-3d%s')%(i,
133
''.join([' %-25.15e'%e if j==0 or e<0.0 else ' %-24.15e'%e for j,e in enumerate(k)])))
134
print '* %-108s *'%('-'*108)
135
print '* %-108s *'%(' Finite part obtained for the loop matrix element (Madloop return_code=%d )'%return_code)
136
print '* %-108s *'%''
137
print '* %-108s *'%(' %.18e'%finite_loop_me)
138
print '* %-108s *'%''
133
print( '* %-108s *'%((' %-3d%s')%(i,
134
''.join([' %-25.15e'%e if j==0 or e<0.0 else ' %-24.15e'%e for j,e in enumerate(k)]))))
135
print( '* %-108s *'%('-'*108))
136
print( '* %-108s *'%(' Finite part obtained for the loop matrix element (Madloop return_code=%d )'%return_code))
137
print( '* %-108s *'%'')
138
print( '* %-108s *'%(' %.18e'%finite_loop_me))
139
print( '* %-108s *'%'')