~maddevelopers/mg5amcnlo/new_clustering

« back to all changes in this revision

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

  • Committer: Rikkert Frederix
  • Date: 2021-09-09 15:51:40 UTC
  • mfrom: (78.75.502 3.2.1)
  • Revision ID: frederix@physik.uzh.ch-20210909155140-rg6umfq68h6h47cf
merge with 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
 
1
#! /usr/bin/env python3
2
2
 
3
3
# This is an example of how to run MadLoop from Python using the f2py compilation of the wrapper file 'f2py_wrapper.f'.
4
4
 
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
        out = out.decode()
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))
25
26
            sys.exit(0)
26
27
        try:
27
28
            import allmatrix2py
28
29
        except:
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])
30
31
            sys.exit(0)
31
32
    else:
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])
34
35
            sys.exit(0)
35
36
        else:
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.")
39
40
            sys.exit(0)
40
41
 
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))
51
54
 
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]))
56
58
 
57
59
def invert_momenta(p):
58
60
    """ fortran/C-python do not order table in the same order"""
62
64
 
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)
66
 
 
 
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."
74
 
        print \
 
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.")
 
75
        print( \
75
76
"""
76
77
 
77
78
\"\"\"
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
88
89
\"\"\"
89
 
"""
90
 
        print "===================================================================================================================\n\n"
 
90
""")
 
91
        print( "===================================================================================================================\n\n")
91
92
        sys.exit(0)
92
93
    try:
93
94
        p               = {}
104
105
                current_p.append([float(line.split()[j]) for j in range(4)])
105
106
        p[current_process] = current_p
106
107
    except:
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])
108
109
        sys.exit(0)
109
110
 
110
111
 
111
112
for iProc, (process_pdgs, kinematic_config) in enumerate(p.items()):
112
 
    print '='*112
 
113
    print('='*112)
113
114
    P =invert_momenta(kinematic_config)
114
115
    # Alpha_s value
115
116
    alphas = 0.118
120
121
    # Choice of renormalization scale
121
122
    renormalization_scale = 91.188
122
123
 
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)
125
126
 
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 *'%''
139
 
    print '='*112
 
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 *'%'')
 
140
    print( '='*112)
 
141