Calling MadWeight from external code

Asked by Jan Therhaag on 2012-03-05

Dear all,

I'd like to use MadWeight to assign matrix-element-based weights to events within my own software framework. This means it would be helpfull to call MadWeight from my (C++) code and pass it a fourvector, getting the result of the phase-space integration in return. What would be the best strategy to achieve this and what code would I have to download to get all the resource I need?

Any help is greatly appreciated
Regards
Jan

Question information

Language:
English Edit question
Status:
Solved
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Mattelaer
Solved:
2012-03-06
Last query:
2012-03-06
Last reply:
2012-03-06

Hi Jan,

I think that what you need is the (C++) standalone version of Madgraph.

I see the following steps:
./bin/mg5
mg5> generate p p > e+ e-
mg5> output standalone_cpp MYOUTPUTDIR

Then in ./MYOUTPUTDIR, you will have a simple code (in C++) which is doing exactly what you ask:
(from the 4- momentum it returns the square matrix element).
Be carefull that they are no PDF and no transfer functions.

To give a bit more details,
you will have different directory:
 MYOUTPUTDIR/SubProcesses/PXXXXXX
each of them corresponding to a set of internal/external particles.
in this directory you have an example of code (check_sa.cpp) returning the square matrix element of a
given event.
(this is fully functional, so you can test it by doing make ./check, in each of those directory)

Cheers,

Olivier

Jan Therhaag (therhaag) said : #2

Hi Olivier,

thank you for your help. However, just calling the matrix-element from my code is not quite what I'm looking for (I've done that before by directly linking the FORTRAN subprocesses to my code). I would like to benefit from the capabilities of MadWeight to perform a good parametrization of the phasespace and carry out the necessary integration even if there are unknown quantities (like neutrino momenta) in the event. My line of thought was more like:

Preparation:
i) Produce matrix-elements for the relevant process with MadGraph
ii) define transfer functions etc. as one would normally do it when using MadWeight standalone

Then:
1) Select events within my analysis
2) Pass four-momenta of events that pass the selection to MadWeight, e.g. do something like
MadWeight(px1,py1,pz1,....,pzN) and have MadWeight carry out the phasespace integration
3) Use result of integration for further analysis (for example discriminate between different processes or estimate a parameter)

Can this be done? That is, where in the MadWeight/MadGraph code would be the "hook" where I could make a call from an external routine?

Thank you for your help
Jan

Hi Jan,

Ah ok mis-understood your question.
In fact i have no experience on how to link C++ to Frotran code.
but it's looks like that this is not your problem.

Except that technical problem, this should be possible to do but I
will see the following step
i) Produce matrix-elements for the relevant process with MadWeight
ii) define the transfer functions (as done in MW)
iii) modify the file SubProcesses/MWP_XXXXXXXX/driver.f
such that
1) this is now a function and not the main progran.
2) the momentum are not read anymore from the local file but passed in
arguments.
3) this returns the value and not writing it in a file.
iv) launch ./bin/madweight.py -12
(This creates the Phase space parametrization)
v) compile this fortran code and link it your C++ code.
vi) use this function directly in your C++ code.

Cheers,

Olivier

On Mar 6, 2012, at 2:25 AM, Jan Therhaag wrote:

> Question #189761 on MadGraph5 changed:
> https://answers.launchpad.net/madgraph5/+question/189761
>
> Status: Answered => Open
>
> Jan Therhaag is still having a problem:
> Hi Olivier,
>
> thank you for your help. However, just calling the matrix-element from
> my code is not quite what I'm looking for (I've done that before by
> directly linking the FORTRAN subprocesses to my code). I would like to
> benefit from the capabilities of MadWeight to perform a good
> parametrization of the phasespace and carry out the necessary
> integration even if there are unknown quantities (like neutrino
> momenta)
> in the event. My line of thought was more like:
>
> Preparation:
> i) Produce matrix-elements for the relevant process with MadGraph
> ii) define transfer functions etc. as one would normally do it when
> using MadWeight standalone
>
> Then:
> 1) Select events within my analysis
> 2) Pass four-momenta of events that pass the selection to MadWeight,
> e.g. do something like
> MadWeight(px1,py1,pz1,....,pzN) and have MadWeight carry out the
> phasespace integration
> 3) Use result of integration for further analysis (for example
> discriminate between different processes or estimate a parameter)
>
> Can this be done? That is, where in the MadWeight/MadGraph code
> would be
> the "hook" where I could make a call from an external routine?
>
> Thank you for your help
> Jan
>
> --
> You received this question notification because you are a member of
> MadTeam, which is an answer contact for MadGraph5.

Jan Therhaag (therhaag) said : #4

Thanks Olivier Mattelaer, that solved my question.