How does madgraph apply the weights to events while unweighting?

Asked by Marco Rossi on 2021-05-05

Hi, I'm trying to exploit, in madgraph 2.8.3, the unweight method of the EventFile class defined in madgraph/various/lhe_parser.py at line 440.

I'd like to use the unweight function on a custom written Les Houches Event file of weighted event for a simple process g g > t t~ to output unweighted events in LHE format.
So far after loading the weighted LHE event file in an EventFile object, I call unweight on it and this works good. The only point is that this method misses to replace the unweighted events weights with the cross section value (I'm using the default normalization='avarage' option), as normally madgraph generation pipeline does. Instead, I get the maximum weight encountered in the weighted file.

This should be expected since I read from lines 561-568 of lhe_parser.py (in particular line 563):

561: elif wgt > 0:
562: nb_keep += 1
563: event.wgt = written_weight(max(wgt, max_wgt))
564: if abs(wgt) > max_wgt:
565: trunc_cross += abs(wgt) - max_wgt
566: if event_target ==0 or nb_keep <= event_target:
567: if outputpath:
568: outfile.write(str(event))

My objective is to retrieve the madgraph behavior, but I wouldn't like to store the weights manually overwriting each event.wgt in EventFile.

I'd like to know where, in the generation pipeline, madgraph assigns the cross section value to unweighted event weights.

Thanks

Question information

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

This is done by hand when we decide to truncate the number of event to the number requested by the user.

cheers,

Olivier

Revision history for this message
Marco Rossi (romarco) said :
#2

Hello Olivier,

Could you please point me out the relevant piece of code where this is done?

Thanks

Marco

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

Should be in the function unweight of the class MultiEventFile in madgraph/various/lhe_parser.py

where we define what the new weight (self.written_weight = new_wgt) will be depending of the normalisation picked.

Cheers,

Olivier

Can you help with this problem?

Provide an answer of your own, or ask Marco Rossi for more information if necessary.

To post a message you must log in.