~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/iolibs/template_files/loop_optimized/check_sa.py.inc

  • Committer: olivier Mattelaer
  • Date: 2016-05-12 11:00:18 UTC
  • mfrom: (262.1.150 2.3.4)
  • Revision ID: olivier.mattelaer@uclouvain.be-20160512110018-sevb79f0wm4g8mpp
pass to 2.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# This is an example of how to run MadLoop from Python using the f2py compilation of the wrapper file 'f2py_wrapper.f'.
 
4
 
 
5
import os
 
6
import sys
 
7
import subprocess
 
8
 
 
9
pjoin = os.path.join
 
10
root_path = os.path.dirname(os.path.realpath( __file__ ))
 
11
sys.path.insert(0, root_path)
 
12
 
 
13
try:
 
14
    import matrix2py
 
15
except:
 
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)
 
25
            sys.exit(0)
 
26
        try:
 
27
            import matrix2py
 
28
        except:
 
29
            print "ERROR: Could not load the f2py module 'matrix2py.so'. The following error occurred:\n",sys.exc_info()[0]
 
30
            sys.exit(0)
 
31
    else:
 
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]
 
34
            sys.exit(0)
 
35
        else:
 
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."
 
39
            sys.exit(0)
 
40
 
 
41
# Now we can use this MadLoop python module.
 
42
 
 
43
# This is a handy way of looking at what is available in the imported f2py module
 
44
# print help(matrix2py)
 
45
 
 
46
# Read the model parameters
 
47
matrix2py.initialise(os.path.abspath(pjoin(root_path,os.pardir,os.pardir,'Cards','param_card.dat')))
 
48
 
 
49
 
 
50
def invert_momenta(p):
 
51
        """ fortran/C-python do not order table in the same order"""
 
52
        new_p = []
 
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):
 
56
                new_p[j][i] = x
 
57
        return new_p
 
58
 
 
59
# Now chose MadLoop's inputs for this evaluation
 
60
 
 
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.
 
63
{0}
 
64
if p[0][0] is None:
 
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"
 
71
        sys.exit(0)
 
72
    try:
 
73
        for i, line in enumerate(open(pjoin(root_path,'PS.input'),'r').readlines()):
 
74
            if i==len(p): break        
 
75
            p[i]=[float(line.split()[j]) for j in range(4)]
 
76
    except:
 
77
        print "ERROR: File PS.input is malformed. Error was:\n",sys.exc_info()[0]
 
78
        sys.exit(0)
 
79
P =invert_momenta(p)
 
80
# Alpha_s value
 
81
alphas = 0.118
 
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
 
88
 
 
89
finite_loop_me, return_code = matrix2py.get_me(P, alphas, renormalization_scale, nhel)
 
90
 
 
91
 
 
92
print '='*112
 
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 *'%''
 
106
print '='*112