3
# This is an example of how to run MadLoop from Python using the f2py compilation of the wrapper file 'f2py_wrapper.f'.
10
root_path = os.path.dirname(os.path.realpath( __file__ ))
11
sys.path.insert(0, root_path)
16
if os.path.isfile(pjoin(root_path,'makefile')) and \
17
os.path.isfile(pjoin(root_path,'f2py_wrapper.f')) and \
18
not os.path.isfile(pjoin(root_path,'matrix2py.so')):
19
print "Trying to automatically generate the python module 'matrix2py.so' with f2py..."
20
p = subprocess.Popen(['make','matrix2py.so'], stdout=subprocess.PIPE,
21
stderr=subprocess.PIPE, cwd=root_path)
22
(out, err) = p.communicate()
23
if p.returncode or not os.path.isfile(pjoin(root_path,'matrix2py.so')):
24
print "ERROR: Failed to produce 'matrix2py.so' with 'make matrix2py.so' in '%s'. The error was:\n%s"%(root_path,err)
29
print "ERROR: Could not load the f2py module 'matrix2py.so'. The following error occurred:\n",sys.exc_info()[0]
32
if os.path.exists(pjoin(root_path,'matrix2py.so')):
33
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
" > make matrix2py.so\n"+\
38
"in the <PROC_OUTPUT>/SubProcesses/P<chosen_proc> directory."
41
# Now we can use this MadLoop python module.
43
# This is a handy way of looking at what is available in the imported f2py module
44
# print help(matrix2py)
46
# Read the model parameters
47
matrix2py.initialise(os.path.abspath(pjoin(root_path,os.pardir,os.pardir,'Cards','param_card.dat')))
50
def invert_momenta(p):
51
""" fortran/C-python do not order table in the same order"""
53
for i in range(len(p[0])): new_p.append([0]*len(p))
54
for i, onep in enumerate(p):
55
for j, x in enumerate(onep):
59
# Now chose MadLoop's inputs for this evaluation
61
# The kinematic configuration in the convention (E, px, py, pz) and with particles ordered as in the process definition.
62
# This is here a random trial PS point.
65
if not os.path.isfile(pjoin(root_path,'PS.input')):
66
print "\n\n==================================================================================================================="
67
print "* No kinematics defined! *"
68
print "* ------------------------------------- *"
69
print "* Please either define your kinematic configuration directly in check_sa.py or in a file 'PS.input'. Exiting now. *"
70
print "===================================================================================================================\n\n"
73
for i, line in enumerate(open(pjoin(root_path,'PS.input'),'r').readlines()):
75
p[i]=[float(line.split()[j]) for j in range(4)]
77
print "ERROR: File PS.input is malformed. Error was:\n",sys.exc_info()[0]
82
# -1 means that the MadLoop averages/sum over helicity configuration.
83
# If a positive integer is picked it corresponds to the position of the helicity configuration listed in the file
84
# 'MadLoop5_resouces/ML5_<id>_HelConfigs.dat'
85
nhel = -1 # means sum over all helicity
86
# Choice of renormalization scale
87
renormalization_scale = 91.188
89
finite_loop_me, return_code = matrix2py.get_me(P, alphas, renormalization_scale, nhel)
93
print '* %-108s *'%' MadLoop evaluation for the process '
94
print '* %-108s *'%' {1}'
95
print '* %-108s *'%' and the kinematic configuration:'
96
print '* %-108s *'%((' %-3s'+' %-25s'*4)%('#','E',' p_x',' p_y',' p_z'))
97
for i,k in enumerate(p):
98
# The complicated printout below is just so as to align the digits negative numbers with positive ones
99
print '* %-108s *'%((' %-3d%s')%(i,
100
''.join([' %-25.15e'%e if j==0 or e<0.0 else ' %-24.15e'%e for j,e in enumerate(k)])))
101
print '* %-108s *'%('-'*108)
102
print '* %-108s *'%(' Finite part obtained for the loop matrix element (Madloop return_code=%d )'%return_code)
103
print '* %-108s *'%''
104
print '* %-108s *'%(' %.18e'%finite_loop_me)
105
print '* %-108s *'%''