Changes between Version 5 and Version 6 of FAQ-General-4


Ignore:
Timestamp:
10/06/17 21:01:05 (22 months ago)
Author:
omatt
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FAQ-General-4

    v5 v6  
    1414}}}
    1515
     16=== Pythton
     17
    1618If you want to have acces to the matrix-element via python. The easiest is to have the fortran code wrapped into python (evaluating a matrix element in python is just too slow to be usable). Each of the SubProcesses/P_xx_xxxx of the standalone directory can be compiled to be python linkable (note this require f2py part of numpy and to have python-devel package installed):
    1719{{{
     
    2022
    2123Then you can link this from your python code. Here is an example:
     24{{{
     25import matrix2py
     26
     27def invert_momenta(p):
     28        """ fortran/C-python do not order table in the same order"""
     29        new_p = []
     30        for i in range(len(p[0])):  new_p.append([0]*len(p))
     31        for i, onep in enumerate(p):
     32            for j, x in enumerate(onep):
     33                new_p[j][i] = x
     34        return new_p
     35
     36matrix2py.initialisemodel('../../Cards/param_card.dat')
     37p = [[   0.5000000E+03,  0.0000000E+00,  0.0000000E+00,  0.5000000E+03],
     38     [   0.5000000E+03,  0.0000000E+00,  0.0000000E+00, -0.5000000E+03],
     39     [   0.5000000E+03,  0.1109243E+03,  0.4448308E+03, -0.1995529E+03],
     40     [   0.5000000E+03, -0.1109243E+03, -0.4448308E+03,  0.1995529E+03]]
     41
     42P =invert_momenta(p)
     43alphas = 0.13
     44nhel = -1 # means sum over all helicity                                                                                                                                                                   
     45me2 = matrix2py.get_value(P, alphas, nhel)
     46print me2
     47}}}
     48
     49=== Full library of process in python
     50
     51If you are interested to have a single python library for a set of matrix-element.
     52This is also possible in fortran/python.
     53This is possible both for loop output ([sqr=virt]) and for tree level.
     54{{{
     55   generate p p > t t~
     56   output standalone PATH --prefix=int
     57}}}
     58
     59then you can compile the library by going to the SubProcesses  directory and
     60{{{
     61make allmatrix2py.so
     62}}}
     63
     64Here is one example in that case
     65{{{
     66import allmatrix2py
     67allmatrix2py.initialise('../Cards/param_card.dat')
     68
     69def invert_momenta(p):
     70        """ fortran/C-python do not order table in the same order"""
     71        new_p = []
     72        for i in range(len(p[0])):  new_p.append([0]*len(p))
     73        for i, onep in enumerate(p):
     74            for j, x in enumerate(onep):
     75                new_p[j][i] = x
     76        return new_p
     77p =[[  0.5000000E+03,  0.0000000E+00,  0.0000000E+00,  0.5000000E+03],
     78    [0.5000000E+03,  0.0000000E+00,  0.0000000E+00, -0.5000000E+03],
     79    [ 0.5000000E+03,  0.1040730E+03,  0.4173556E+03, -0.1872274E+03],
     80    [ 0.5000000E+03, -0.1040730E+03, -0.4173556E+03,  0.1872274E+03]
     81    ]
     82
     83p =invert_momenta(p)
     84nhel = -1 # means sum over all helicity
     85pdgs = [21,21,6,-6] #which pdg is requested
     86scale2 = 0.  #only used for loop matrix element. should be set to 0 for tree-level
     87alphas=0.13
     88
     89ans = allmatrix2py.smatrixhel(pdgs,p,alphas,scale2,nhel)
     90print ans
     91}}}
     92
     93=== Python for version MG5_aMC version 2.5.x
     94
     95For version of the code older than 2.6.0, the syntax was:
     96
    2297{{{
    2398import matrix2py