=How can I remove some unwanted diagram?


Be carefull about gauge invariance (a non gauge invariant subset will also break lorentz invariance)


  1. This method is implemented since MG5aMC version 2.5.0
  2. This method is only implemented for leading order processes


You need to define the file who should define the function remove_diag(diag): It should return True if you want to discard the diagram.

example of file

def remove_diag(diag):
    """remove all diagram with quark in T-channel"""
    for vertex in diag['vertices']: #last
         if vertex['id'] == 0: #special final vertex
         if vertex['legs'][-1]['number'] < 3: #this means T-channel
             if abs(vertex['legs'][-1]['id']) <6:
                  return True
    return False
def remove_diag(diag):
    """remove all diagram which are not pure QCD or pure QED: Fake example"""

    if diag.get('orders')['QCD'] >0 and diag.get('orders')['QED']>0:
        return True

    return False
import madgraph.various.misc as misc

def remove_diag(diag):
    """force to have two s-channel W decaying into a specific way. 
       Designed for interference studies where decay chain are not allowed
       This is designed for keeping the following diagram generate p p > j j w- w-, w- > e- ve~ 
       from the following syntax:  p p > j j e- ve~ e- ve~

    found_w = 0
    for vertex in diag['vertices']:
        if vertex.get('id') == 0: #special final vertex
        if len(vertex['legs'])!=3:

        for i, leg in enumerate(list(vertex['legs'])):
            #misc.sprint(i, leg)
            if abs(leg['id']) != 24:
        # we have a vertex with a W
        if i == 2: #This means a vertex A B > W or W > A B
            if leg['number'] > 2: # means that we have W > A B
                # check that A B are what we want
                if not all(oleg['state'] for oleg in vertex['legs'][:2]) : # this means not final state
                #misc.sprint([oleg['id'] for oleg in vertex['legs'][:2] ])
                if set([oleg['id'] for oleg in vertex['legs'][:2] ]) == set([11,-12]):
                    found_w +=1
        else: # this means A W > B
            if vertex['legs'][-1].get('number') < 3:
                # T-channel -> continue
                #check that they are both final state
                if not vertex['legs'][-1]['state']:
                if not vertex['legs'][1 if i==0 else 0]['state']:

                other_id = [vertex['legs'][-1].get('id'), vertex['legs'][1 if i==0 else 0]['id']]
                if set(other_id) == set([11,-12]):
                    found_w += 1

    if found_w == 2:
        return True
        return False

running with user_filter

to activate the filtering, you have to add '--diagram_filter' to the command example

generate p p > w+ w+ j j --diagram_filter

If you remove any diagram you should see on the screen:

INFO: Trying process: c c > w+ w+ s s WEIGHTED<=6 @1
WARNING: Diagram filter is ON and removed 12 diagrams for this subprocess.
Last modified 17 months ago Last modified on 11/09/18 17:46:56