def __init__(self, dimensions, rust_worker, SG_info, model, h_function, hyperparameters, debug=0, **opts):

        self.rust_worker = rust_worker
        self.model = model
        self.SG_info = SG_info
        self.dimensions = dimensions
        self.h_function = h_function
        self.debug = debug

        self.topology = (
                    # s-channels first:
                    base_objects.VertexList([]),
                    # t-channels then:
                    base_objects.VertexList([
                        # The dummy vertex below is just to close the diagram and connect
                        # with the number -3 which is to be understood here as the initial state #2.
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 11,
                                    'number': -2,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 23,
                                    'number': -1,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': -11,
                                    'number': -3,
                                    'state': INITIAL,
                                })
                            ])
                        }),
                    ])
                )

        E_cm = math.sqrt(max(sum(LorentzVector(vec) for vec in hyperparameters['CrossSection']['incoming_momenta']).square(),0.0))


        self.generator = PS.SingleChannelPhasespace([0.]*2, [0.]*3,
                beam_Es =(E_cm/2.,E_cm/2.), beam_types=(0,0), 
                model=model, topology=self.topology, path = [[0,],[]],
                dimensions = self.dimensions
            )
        
        print("Considering the following topology:")
        print("-"*10)
        print(self.generator.get_topology_string(self.generator.topology, path_to_print=self.generator.path))
        print("-"*10)
예제 #2
0
    def def_pent(self):       
        """ Test the gg>gggg d*dx* tagging of a quark pentagon which is tagged"""

        # Five gluon legs with two initial states
        myleglist = base_objects.LegList([base_objects.Leg({'id':21,
                                              'number':num,
                                              'loop_line':False}) \
                                              for num in range(1, 7)])
        myleglist.append(base_objects.Leg({'id':1,'number':7,'loop_line':True}))
        myleglist.append(base_objects.Leg({'id':-1,'number':8,'loop_line':True}))                         
        l1=myleglist[0]
        l2=myleglist[1]
        l3=myleglist[2]
        l4=myleglist[3]
        l5=myleglist[4]
        l6=myleglist[5]
        l7=myleglist[6]
        l8=myleglist[7]

        # One way of constructing this diagram, with a three-point amplitude
        l17 = base_objects.Leg({'id':1,'number':1,'loop_line':True})
        l12 = base_objects.Leg({'id':1,'number':1,'loop_line':True})
        l68 = base_objects.Leg({'id':-1,'number':6,'loop_line':True}) 
        l56 = base_objects.Leg({'id':-1,'number':5,'loop_line':True})
        l34 = base_objects.Leg({'id':21,'number':3,'loop_line':False})

        self.myproc.set('legs',myleglist)

        vx17 = base_objects.Vertex({'legs':base_objects.LegList([l1, l7, l17]), 'id': 3})
        vx12 = base_objects.Vertex({'legs':base_objects.LegList([l17, l2, l12]), 'id': 3})
        vx68 = base_objects.Vertex({'legs':base_objects.LegList([l6, l8, l68]), 'id': 3})
        vx56 = base_objects.Vertex({'legs':base_objects.LegList([l5, l68, l56]), 'id': 3})
        vx34 = base_objects.Vertex({'legs':base_objects.LegList([l3, l4, l34]), 'id': 1})
        vx135 = base_objects.Vertex({'legs':base_objects.LegList([l12, l56, l34]), 'id': 3})

        myVertexList1=base_objects.VertexList([vx17,vx12,vx68,vx56,vx34,vx135])

        myPentaDiag1=loop_base_objects.LoopDiagram({'vertices':myVertexList1,'type':1})

        myStructRep=loop_base_objects.FDStructureList()
        
        myPentaDiag1.tag(myStructRep,7,8,self.myproc)
        
        return myPentaDiag1,myStructRep
예제 #3
0
    def def_box(self):
        """ Test the drawing of a simple loop box """
        
        myleglist = base_objects.LegList([base_objects.Leg({'id':21,
                                              'number':num, 'state':True,
                                              'loop_line':False}) \
                                              for num in range(1, 5)])
        myleglist.append(base_objects.Leg({'id':1,'number':5,'loop_line':True}))
        myleglist.append(base_objects.Leg({'id':-1,'number':6,'loop_line':True}))                         
        l1=myleglist[0]
        l1.set('state',False)
        l2=myleglist[1]
        l2.set('state',False)
        l3=myleglist[2]
        l4=myleglist[3]
        l5=myleglist[4]
        l6=myleglist[5]

        
        # One way of constructing this diagram, with a three-point amplitude
        l15 = base_objects.Leg({'id':1,'number':1,'loop_line':True, 'state':False})
        l12 = base_objects.Leg({'id':1,'number':1,'loop_line':True})
        l13 = base_objects.Leg({'id':1,'number':1,'loop_line':True}) 
        lfake = base_objects.Leg({'id':1,'number':1,'loop_line':True})         

        vx15 = base_objects.Vertex({'legs':base_objects.LegList([l1, l5, l15]), 'id': 3})
        vx12 = base_objects.Vertex({'legs':base_objects.LegList([l15, l2, l12]), 'id': 3})
        vx13 = base_objects.Vertex({'legs':base_objects.LegList([l12, l3, l13]), 'id': 3})
        vx164 = base_objects.Vertex({'legs':base_objects.LegList([l13, l6, l4]), 'id': 3})
        fakevx = base_objects.Vertex({'legs':base_objects.LegList([l13, lfake]), 'id': 0})
        ctvx = base_objects.Vertex({'legs':base_objects.LegList([l1, l2, l3, l4]), 'id': 666})

        myVertexList1=base_objects.VertexList([vx15,vx12,vx13,vx164])
        myCTVertexList=base_objects.VertexList([ctvx,])
        myPentaDiag1=loop_base_objects.LoopDiagram({'vertices':myVertexList1,'type':1,\
                                                    'CT_vertices':myCTVertexList})
        
        return myPentaDiag1, []
예제 #4
0
    def test_multi_channel_phase_space(self):
        """ Test the multichannel phase-space that is aligned along specific s- and t-channels."""
        
        # A specific sets of s- and t-channels for this test:

        ####################################################################
        # a) A simple unique massless photon s-channel from e+ e- > d d~ / z
        ####################################################################
        
        massless_photon_schannel_specifier = (
            # s-channels first:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 15,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': -1,
                            'number': 4,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 1,
                            'number': 3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 22,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        })
                    ])
                }),
            ]),
            # t-channels then:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 34,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 11,
                            'number': 1,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 22,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': -11,
                            'number': -2,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        })
                    ])
                }),
            ])
        )                          
        
        ####################################################################
        # a) A simple unique massive Z-boson s-channel from e+ e- > d d~ / a
        ####################################################################
        
        massive_zboson_schannel_specifier = (
            # s-channels first:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 22,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': -1,
                            'number': 4,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 1,
                            'number': 3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
            ]),
            # t-channels then:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 40,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 11,
                            'number': 1,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': -11,
                            'number': -2,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
            ]),
        )
      
        ###############################################################################
        # c) A complicated fully decayed VBF topology: 
        #    from: generate u c > h > u c e+ e- mu+ mu- $$ c u / a s d s~ d~ QCD=0 --LO
        ###############################################################################
        vbf_topology_s_and_t_channel_specifier = (
            # s-channels first:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 41,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 13,
                            'number': 8,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': -13,
                            'number': 7,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 40,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 11,
                            'number': 6,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': -11,
                            'number': 5,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -2,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 13,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -2,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 25,
                            'number': -3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                })
            ]),
            # t-channels then:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 63,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': -2,
                            'number': 1,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 2,
                            'number': 3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -4,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 13,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -4,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None  
                        }),
                        base_objects.Leg({
                            'id': 25,
                            'number': -3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -5,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 64,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -5,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None  
                        }),
                        base_objects.Leg({
                            'id': 4,
                            'number': 4,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': -4,
                            'number': -6,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
            ]),
        )


        ###############################################################################
        # d) A complicated fully decayed VBF topology: 
        #    from: generate e- e+ > h > e+ e- mu+ mu- ta+ ta- $$ e+ e- \ a QCD=0 --diagram_filter --LO
        ###############################################################################
        # where diagram filter removes the first three diagrams
        # import model sm-dario
        self.vbf_topology_s_and_t_channel_specifier2 = (
            # s-channels first:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 42,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 15,
                            'number': 8,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None  
                        }),
                        base_objects.Leg({
                            'id': -15,
                            'number': 7,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 41,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 13,
                            'number': 6,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': -13,
                            'number': 5,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -2,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 13,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -1,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -2,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 25,
                            'number': -3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                })
            ]),
            # t-channels then:
            base_objects.VertexList([
                base_objects.Vertex({
                    'id': 40,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                             'id': -11,
                             'number': 1,
                             'state': False,
                             'from_group': True,
                             'loop_line': False,
                             'onshell': None   
                        }),
                        base_objects.Leg({
                            'id': 11,
                            'number': 4,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -4,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 13,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -4,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None  
                        }),
                        base_objects.Leg({
                            'id': 25,
                            'number': -3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 23,
                            'number': -5,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
                base_objects.Vertex({
                    'id': 40,
                    'legs': base_objects.LegList([
                        base_objects.Leg({
                            'id': 23,
                            'number': -5,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None 
                        }),
                        base_objects.Leg({
                            'id': -11,
                            'number': 3,
                            'state': True,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                        base_objects.Leg({
                            'id': 11,
                            'number': -6,
                            'state': False,
                            'from_group': True,
                            'loop_line': False,
                            'onshell': None
                        }),
                    ])
                }),
            ]),
        )
def get_topology(channel_name):

        # A specific sets of s- and t-channels for this example:

        ##############################################################################
        # a) e+(1) e-(2) > mu+(3) mu-(4) a(5) with (p3+p4)^2 sampled as a z-resonance
        ##############################################################################
        topology = None

        if channel_name=='2_to_3_s34':

                topology = (
                    # s-channels first:
                    base_objects.VertexList([
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': -12,
                                    'number': 3,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 12,
                                    'number': 4,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 23,
                                    'number': -1,
                                    'state': FINAL,
                                })
                            ])
                        }),
                    ]),
                    # t-channels then:
                    base_objects.VertexList([
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 11,
                                    'number': 1,
                                    'state': INITIAL,
                                }),
                                base_objects.Leg({
                                    'id': 22,
                                    'number': 5,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 11,
                                    'number': -2,
                                    'state': FINAL,
                                })
                            ])
                        }),
                        # The dummy vertex below is just to close the diagram and connect
                        # with the number -3 which is to be understood here as the initial state #2.
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 11,
                                    'number': -2,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 23,
                                    'number': -1,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': -11,
                                    'number': -3,
                                    'state': INITIAL,
                                })
                            ])
                        }),
                    ])
                )
            
        else:
            print(("Channel name '%s' not implemented."%channel_name))

        return topology
    def __init__(self, dimensions, rust_worker, SG_info, model, h_function, hyperparameters, debug=0, **opts):

        self.rust_worker = rust_worker
        self.model = model
        self.SG_info = SG_info
        self.dimensions = dimensions
        self.h_function = h_function
        self.debug = debug

        # The process is e+(1) e-(2) > a > d(3) d~(4) g(5) g(6)
        # The SG_QG36 topoology assigns externals as follows:
        # LMB vec #1 = pq3 = -d(3)
        # LMB vec #2 = pq6 = +d~(4)
        # LMB vec #3 = pq10 = +g(5)
        # dependnet momentum = pq9 = -(-#1 +#2 +#3 +Q) 

        # Topology is 
        # g(5) g(6) -> -1
        # -1 d~(4) -> -2
        # -2 d(3) -> incoming "decaying" particle

        self.topology = (
                    # s-channels first:
                    base_objects.VertexList([
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 21,
                                    'number': 5,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 21,
                                    'number': 6,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 21,
                                    'number': -1,
                                    'state': FINAL,
                                })
                            ])
                        }),
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 21,
                                    'number': -1,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 1,
                                    'number': 4,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 1,
                                    'number': -2,
                                    'state': FINAL,
                                })
                            ])
                        }),
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 1,
                                    'number': -2,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 1,
                                    'number': 3,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 22,
                                    'number': -3,
                                    'state': FINAL,
                                })
                            ])
                        }),
                    ]),
                    # t-channels then:
                    base_objects.VertexList([
                        # The dummy vertex below is just to close the diagram and connect
                        # with the number -3 which is to be understood here as the initial state #2.
                        base_objects.Vertex({
                            'id': DUMMY, # Irrelevant
                            'legs': base_objects.LegList([
                                base_objects.Leg({
                                    'id': 11,
                                    'number': 1,
                                    'state': INITIAL,
                                }),
                                base_objects.Leg({
                                    'id': 22,
                                    'number': -3,
                                    'state': FINAL,
                                }),
                                base_objects.Leg({
                                    'id': 11,
                                    'number': -4,
                                    'state': INITIAL,
                                })
                            ])
                        }),
                    ])
                )

        E_cm = math.sqrt(max(sum(LorentzVector(vec) for vec in hyperparameters['CrossSection']['incoming_momenta']).square(),0.0))
        self.E_cm = E_cm
        if debug: print("E_cm detected=%.16e"%self.E_cm)

        self.generator = PS.SingleChannelPhasespace([0.]*2, [0.]*(SG_info['topo']['n_loops']+1),
                beam_Es =(self.E_cm/2.,self.E_cm/2.), beam_types=(0,0), 
                model=model, topology=self.topology, #path = [[0,1], []],
                dimensions = self.dimensions
        )

        print("Considering the following topology:")
        print("-"*10)
        print(self.generator.get_topology_string(self.generator.topology, path_to_print=self.generator.path))
        print("-"*10)
        print("With the following path = ",self.generator.path)

#       For testing we can substitute here a flat PS generator.
#        self.generator = PS.FlatInvertiblePhasespace(
#            [0.]*2, [0.]*(SG_info['topo']['n_loops']+1), 
#            beam_Es =(E_cm/2.,E_cm/2.), beam_types=(0,0),
#            dimensions = self.dimensions
#        )

        # Variables for testing that the inverse jacobian works well.
        # Sett test_inverse_jacobian to True in order to debug the inverse jacobian.
        self.test_inverse_jacobian = False
        if self.test_inverse_jacobian:
            print("WARNING: Running in debug mode 'test_inverse_jacobian'.")
            time.sleep(1.0)
        self.rv = None
        self.i_count = 0
예제 #7
0
def make_vertexlist(model):

    # Initialization
    global full_leglist
    global full_vertexlist
    global full_vertexlist_newindex

    full_leglist = {}
    full_vertexlist = {}
    full_vertexlist_newindex = {}
    make_legs(model)

    #Prepare the vertexlist
    for inter in model['interactions']:

        #Calculate the particle number, total mass
        partnum = len(inter['particles']) - 1
        if partnum > 3:
            continue

        total_mass = math.fsum([eval('decay_objects.' + part.get('mass')).real\
                                for part in inter['particles']])
        #Create the original legs
        temp_legs = base_objects.LegList([
            copy.copy(full_leglist[part2.get_pdg_code()])
            for part2 in inter['particles']
        ])

        for num, part in enumerate(inter['particles']):
            #Ignore massless incoming particle
            if part.get('mass') == 'ZERO' or part.get('pdg_code') in [
                    1, 2, 3, 4, 5, 11, 12, 13, 14, 16, 21, 22
            ]:
                continue

            pid = part.get_anti_pdg_code()
            radiation = False
            for num2, other in enumerate(inter['particles']):
                if (num2 != num) and (other.get('pdg_code') == abs(pid)):
                    radiation = True
                    break

            if radiation:
                continue

            ini_mass = eval('decay_objects.' + part.get('mass')).real

            temp_legs_new = copy.deepcopy(temp_legs)
            #If part is not self-conjugate, change the particle into anti-part
            temp_legs_new[num].set('id', pid)

            # Initial leg should be in the last
            ini_leg = temp_legs_new.pop(num)

            # Sort the other legs
            temp_legs_new.sort(lambda l1, l2: cmp(l1['id'], l2['id']),
                               reverse=True)
            temp_legs_new.append(ini_leg)
            temp_vertex = base_objects.Vertex({
                'id': inter.get('id'),
                'legs': temp_legs_new
            })

            # Record the vertex with key = (interaction_id, part_id)
            try:
                full_vertexlist[(inter.get('id'), pid)] = temp_vertex
            except KeyError:
                full_vertexlist[(inter.get('id'), pid)] = \
                    base_objects.VertexList([temp_vertex])

            # new index list made for testing find_vertexlist
            try:
                full_vertexlist_newindex[(
                    pid, partnum, ini_mass >
                    (total_mass - ini_mass))].append(temp_vertex)

            except KeyError:
                full_vertexlist_newindex[(pid, partnum,
                                          ini_mass > (total_mass - ini_mass))]=\
                                          base_objects.VertexList([temp_vertex])

            #Reset the leg to normal state and normal id
            temp_legs[num].set('state', True)
            temp_legs[num].set('id', part.get_pdg_code())