How does madgraph generate events?

Asked by yuanfang

             Hi ,I am a beginner of madgraph .Although I have read many tutorials on madgraph, I just don't know how madgraph@NLO generates events. Those tutorials only tell me something about how to perform phase space integration using multi-channel method and obtain its cross section and say little about event generation details .
        I also searched it on the Internet but found little staffs on this topics. They also just tell me how to perform integrations using monto-carlo method. I have also tried to read code in madgraph but soon found the whole madgraph package is just too complicated. I also asked other people but they didn't know iteither. They just use it. I'm really frustrated.
        For event generation,the only informaton I know are:
        1. They are something related to importance sampling and acceptance-rejection method and it's not realistic .
         Those are the only thing I know. Can someone give me a brief picture on how madgraph generate events?What does the event really mean?Are there any papers or books on this topics? Can you show me an simple example ?

Question information

Language:
English Edit question
Status:
Solved
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Mattelaer
Solved:
Last query:
Last reply:
Revision history for this message
shibasipu (shibasipu) said :
#1

Hi Yuanfang,
                              Let me try my best to give answers to some of your questions. Olivier may add to this.

>>What does the event really mean?
We generate events for a physical process for example e- e+ > z h . An event contains various information related to
kinematic variables (like energy, transverse momentum etc. ) of the particles.

>>Can someone give me a brief picture on how madgraph generate events?
There are some procedures to generate the events in Madgraph. First you have to go to the Madgraph directory. Here are some of the commands.
1. then type : ./bin/mg5_aMC
2. generate e- e+ > z h (First you have to choose a physical process for which you want to generate the events)
3. output ee2zh (then you have to create a directory which will contain all the information related to the process)
3. launch ee2zh
4. then type 0
5. then type 1 (after this you can change the parameters in the param card)
6. then type 2 (here in the run_card.dat, you can give the c.m. energy and the desired no. of events)
7. then type 0
After successful run, you can find the events in the directory.

some of the references : 1405.0301, 1402.1178

Note : Olivier, please rectify me, if I am giving any wrong info.

Regards,
Shiba

Revision history for this message
Olivier Mattelaer (olivier-mattelaer) said :
#2

Dear Yuanfang.

>>> What does the event really mean?

I would define an event, as one possible collision occurring to a detector.
Each event is describe by a collection of characteristics —which depend of your simulation—
and a probability (often called weight due to the way it is normalized) of occurring.

At parton level (MG5aMc level) the characteristics that we provide correspond to the LHEF convention
- kinematics of each particles
- kinematics of on-shell propagators
- Leading color information
- Helicity of each particle (at Leading Order only)

Some sample of events are called un-weighted when all the events of the sample have the same probability of occurence/weight.

> They also just tell me how to perform integrations using monto-carlo method.

Obtaining a weighted sample from a Monte-Carlo integration is trivial. Just collect all the phase-space point that you generated and associated to those the associated contribution to the integral (that is the definition of their weight) and eventually associated to the events the other characteristics that you want to include.

Then you can apply the standard acception/rejection method to have an unweighted sample of events.

> I have also tried to read code in madgraph but soon found the whole madgraph package is just too complicated.

I fully agree also because they are a lot of optimisation performed in those simple steps.

> Can someone give me a brief picture on how madgraph generate events?

The brief picture is the one above.
1) perform a multi-channel phase-space integration with monte-carlo technique
2) keep all the phase-space point used for the estimation of the cross-section in point 1
3) un-weight the events samples.

Now If you want more details on how the unweighting works in details in madgraph, I will refer to this thread:
https://answers.launchpad.net/mg5amcnlo/+question/177691

> Are there any papers or books on this topics?

This is typically cover as the rejection/acceptance method that is describe in all the Monte-Carlo books.

Is that answer your question?

Cheers,

Olivier

> On Apr 20, 2016, at 18:32, shibasipu <email address hidden> wrote:
>
> Question #291534 on MadGraph5_aMC@NLO changed:
> https://answers.launchpad.net/mg5amcnlo/+question/291534
>
> Status: Open => Answered
>
> shibasipu proposed the following answer:
> Hi Yuanfang,
> Let me try my best to give answers to some of your questions. Olivier may add to this.
>
>>> What does the event really mean?
> We generate events for a physical process for example e- e+ > z h . An event contains various information related to
> kinematic variables (like energy, transverse momentum etc. ) of the particles.
>
>>> Can someone give me a brief picture on how madgraph generate events?
> There are some procedures to generate the events in Madgraph. First you have to go to the Madgraph directory. Here are some of the commands.
> 1. then type : ./bin/mg5_aMC
> 2. generate e- e+ > z h (First you have to choose a physical process for which you want to generate the events)
> 3. output ee2zh (then you have to create a directory which will contain all the information related to the process)
> 3. launch ee2zh
> 4. then type 0
> 5. then type 1 (after this you can change the parameters in the param card)
> 6. then type 2 (here in the run_card.dat, you can give the c.m. energy and the desired no. of events)
> 7. then type 0
> After successful run, you can find the events in the directory.
>
> some of the references : 1405.0301, 1402.1178
>
> Note : Olivier, please rectify me, if I am giving any wrong info.
>
>
> Regards,
> Shiba
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
shibasipu (shibasipu) said :
#3

Hi Olivier,
                            I thought Yuanfang asking the procedures. Thanks for clarifying the details.

Regards,
Shiba

Revision history for this message
yuanfang (yuanfang405) said :
#4

       Thanks all of you liver and Shiba ,I know the whole procedures. I know how to use those commands like " generate e- e+ > z h ". I am sorry I didn't make it clear . What I really want to know is that how madgraph works .
      I have seen Oliver's answer which is really of great help for me.
      Like Olivier said: 1) First madgraph perform a multichannel phase-space integration; 2). keep all the phase space points , then calculate cross section; 3). un-weight the events samples.
      I just read the recommended slides in 2011 KIAS madgraph school:
          ( https://answers.launchpad.net/mg5amcnlo/+question/177691 )
        Now I want to know: Are these events are distribution of the cross section ? If I give a process ,say " generate e- e+ > z h" ,then "output " ,"launch " , madgraph then calculates its matrix element , performs phase space integration to obtain its cross section ,then generate a distributions according to our cross section via the method rejection/acceptance method . Am I right?

Revision history for this message
yuanfang (yuanfang405) said :
#5

   I just saw the slides in KIAS 2011 madgraph school . In slide "KIAS-MG5-lectures1-2(Alwall)",page 74 ,it says:
        1. pick x distributed as p(x)
        2. calculate f(x) and p(x)
        3. pick 0<y<1
        4. Compare:
                   if f(x)>y p(x) accept event,
           else reject it.
   Then it says(next page):
          In practice it performs a large number of (sometimes very difficult) integrals and then unweight to give the four momenta of the particles that interact with the detector"
         So my problem is :
       1. what's the relations between the monto carlo integration and event generation ? What's order of these two steps( First perform the integration ,then generate event ? Or first generate events ,then perform integration and obtain its cross section ) ?
     2. If I change some parameters in param_card ,so its cross section would change . So what would happen to my generated events ? This troubles me most because I have ever changed some parameters ,its cross section changed ,but its events didn't . So I am very confused abut that .

Revision history for this message
Olivier Mattelaer (olivier-mattelaer) said :
#6

Hi Yuanfang,

> Are these events are distribution of the cross section

If you plot any distributions of a sample of events, you indeed have the associated differential distributions.
You obviously have to use the weight for weighted sample (i.e. in your histogram you enter the weight in the bin for the event entering in this bin).

> If I give a process ,say " generate e- e+ > z h" ,then "output " ,"launch " , madgraph then calculates its matrix element , performs phase space integration to obtain its cross section ,then generate a distributions according to our cross section via the method rejection/acceptance method . Am I right?

Yes it is.

> 1. what's the relations between the monto carlo integration and event generation ? What's order of these two steps( First perform the integration ,then generate event ? Or first generate events ,then perform integration and obtain its cross section ) ?

The two are strongly correlated, and efficient monte-carlo integration, will have an higher efficiency of producing un-weighted.
> What’s order of these two steps?

This actually depends of the algorithm.
For Leading Order process, this is simultaneous.
For NLO generation, we first compute the cross-section, then we generate-events in a separate steps (i.e. the phase-space points used for the computation of the cross-sections are not used at all as candidate for the event generation)

> 2. If I change some parameters in param_card ,so its cross section would change . So what would happen to my generated events ? This troubles me most because I have ever changed some parameters ,its cross section changed ,but its events didn't . So I am very confused abut that .

Depends what you change.
If you generate with the same seed and the change in the param_card is just a rescaling of the cross-section.
(changing alpha_EW for example)
then you will have the same events but with a different weight.

If either the seed is different or the change is not a global factor (like changing a final state particle mass) then you will have completely different event.

Cheers,

Olivier

> On Apr 21, 2016, at 09:13, yuanfang <email address hidden> wrote:
>
> Question #291534 on MadGraph5_aMC@NLO changed:
> https://answers.launchpad.net/mg5amcnlo/+question/291534
>
> yuanfang posted a new comment:
> Thanks all of you liver and Shiba ,I know the whole procedures. I know how to use those commands like " generate e- e+ > z h ". I am sorry I didn't make it clear . What I really want to know is that how madgraph works .
> I have seen Oliver's answer which is really of great help for me.
> Like Olivier said: 1) First madgraph perform a multichannel phase-space integration; 2). keep all the phase space points , then calculate cross section; 3). un-weight the events samples.
> I just read the recommended slides in 2011 KIAS madgraph school:
> ( https://answers.launchpad.net/mg5amcnlo/+question/177691 )
> Now I want to know: Are these events are distribution of the cross section ? If I give a process ,say " generate e- e+ > z h" ,then "output " ,"launch " , madgraph then calculates its matrix element , performs phase space integration to obtain its cross section ,then generate a distributions according to our cross section via the method rejection/acceptance method . Am I right?
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
yuanfang (yuanfang405) said :
#7

Hi Olivier
        Thank you so much for your patient answer . It's really helpful .
        1. If madgraph generates events according to its cross section and the final events(parton level) is a distribution. For example , if I want to generate event samples distributed as a function f(x) , then its variable is x, f(x) act as its probability density ; Then I want to know what's the random variables of my events . Because for a specific process ,when computing cross sections, its param_meters ,such as mass , coupling constants etc. , are fixed , so what's the random variable corresponding to x ? Is the cross section acting as probability density of some random variables ?

           2. > Depends what you change.
           If you generate with the same seed and the change in the param_card is just a rescaling of the cross-section.

           I remember I only changed its mixing matrix in param_card and found no change in my event distribution(after analysis) . I was really confused about that . That's why I asked this question.
        https://answers.launchpad.net/mg5amcnlo/+question/291449
        I have read the part of mixing matrix in SUSY Les Houches Accord you recommended . I think the way I modified mixing matrix may be right . I just don't understand why the event distribution does not change. I must be wrong somewhere .
       Thank you again . I'm really grateful .

Revision history for this message
yuanfang (yuanfang405) said :
#8

     One more question , Is there any demo code showing me a simple specific process on event generation details ? Any programing language ,say C++ , fortran , python is ok .

Revision history for this message
Best Olivier Mattelaer (olivier-mattelaer) said :
#9

Hi,

> Is the cross section acting as probability density of some random variables ?

The cross-section is a number and not a probability density.
The probability density is the convolution of the matrix-element times the PDF.

> what’s the random variable corresponding to x ?

That’s the invariant mass of particles, angles between the particles, the total energy of the system,…
Those variables depends of the change of variable used to perform the integration (and we used more than one change of variable to do such type of integration).

> I just don't understand why the event distribution does not change. I must be wrong somewhere.

I would advise to check that you have the correct set of Feynman Diagram and then check the associated coupling definition.
This might help you to understand the situation.
It is also possible that the effect is there but hidden by another much bigger contribution to the cross-section.

Cheers,

Olivier

> On Apr 21, 2016, at 13:28, yuanfang <email address hidden> wrote:
>
> Question #291534 on MadGraph5_aMC@NLO changed:
> https://answers.launchpad.net/mg5amcnlo/+question/291534
>
> yuanfang posted a new comment:
> Hi Olivier
> Thank you so much for your patient answer . It's really helpful .
> 1. If madgraph generates events according to its cross section and the final events(parton level) is a distribution. For example , if I want to generate event samples distributed as a function f(x) , then its variable is x, f(x) act as its probability density ; Then I want to know what's the random variables of my events . Because for a specific process ,when computing cross sections, its param_meters ,such as mass , coupling constants etc. , are fixed , so what's the random variable corresponding to x ? Is the cross section acting as probability density of some random variables ?
>
> 2. > Depends what you change.
> If you generate with the same seed and the change in the param_card is just a rescaling of the cross-section.
>
> I remember I only changed its mixing matrix in param_card and found no change in my event distribution(after analysis) . I was really confused about that . That's why I asked this question.
> https://answers.launchpad.net/mg5amcnlo/+question/291449
> I have read the part of mixing matrix in SUSY Les Houches Accord you recommended . I think the way I modified mixing matrix may be right . I just don't understand why the event distribution does not change. I must be wrong somewhere .
> Thank you again . I'm really grateful .
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
Olivier Mattelaer (olivier-mattelaer) said :
#10

You should be able to do one from the slide of Johan,
For the fun, here is one python example that i wrote, comparing the weighted and un-weighted distribution.
Cheers,

Olivier

from __future__ import division
import math
import random

#parameter of the monte-carlo integraion
Ntry = 500000
fct = lambda x: 1 + math.cos(2*math.pi*x) # note that the function should be definite positive for this example

# initialise some global variable
all_try = []
max_f = 0
cross = 0

# perform the Monte-Carlo integration
for i in xrange(Ntry):
    x = random.random()
    f = fct(x)/Ntry
    all_try.append((x,f))
    max_f = max(max_f,f)
    cross += f

# perform the unweighting
accepted = []
for x,f in all_try:
    if random.random() < f/max_f:
        accepted.append(x)
    else:
        continue

print "the integral is", cross
print len(accepted), 'efficiency is', len(accepted)/Ntry, "max_f is",max_f

# plot the distribution from the unweighted events
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
gs1 = gridspec.GridSpec(2, 1, height_ratios=[3,1])
ax = plt.subplot(gs1[0])
ax2 = plt.subplot(gs1[1])
n1, bins, patches = ax.hist(accepted, 50, weights=[max_f]*len(accepted), histtype='step', label='unweighted')
all_x = [x for x,f in all_try]
all_wgt = [f for x,f in all_try]
n2, bins, patches = ax.hist(all_x, 50, weights=all_wgt, histtype='step', label='weighted')
ratio = [n1[i]/n2[i] for i in xrange(len(n1))]
ax2.plot(bins, ratio+[1], label='unweighted/weighted')

ax.legend(loc=3)
ax2.set_ylim([0,2])
ax2.legend(loc=3)
plt.show()

> On Apr 21, 2016, at 13:43, yuanfang <email address hidden> wrote:
>
> Question #291534 on MadGraph5_aMC@NLO changed:
> https://answers.launchpad.net/mg5amcnlo/+question/291534
>
> yuanfang posted a new comment:
> One more question , Is there any demo code showing me a simple
> specific process on event generation details ? Any programing language
> ,say C++ , fortran , python is ok .
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
yuanfang (yuanfang405) said :
#11

       Thank you very much Olivier and Shiba. You solved my problem . I'm very happy now .

Revision history for this message
yuanfang (yuanfang405) said :
#12

Thanks Olivier Mattelaer, that solved my question.