Beispiel #1
0
    def __init__(self,
                 born_proc,
                 leglist,
                 ij,
                 ijglu,
                 perturbed_orders=['QCD']):  #test written
        """Initializes the real process based on born_proc and leglist.
        Stores the fks informations into the list of dictionaries fks_infos
        """
        self.fks_infos = []
        for leg in leglist:
            if leg.get('fks') == 'i':
                i_fks = leg.get('number')
                # i is a gluon or a photon
                need_color_links = leg.get('massless') \
                        and leg.get('spin') == 3 \
                        and leg.get('self_antipart')
            if leg.get('fks') == 'j':
                j_fks = leg.get('number')
        self.fks_infos.append({
            'i': i_fks,
            'j': j_fks,
            'ij': ij,
            'ij_glu': ijglu,
            'need_color_links': need_color_links
        })

        self.process = copy.copy(born_proc)
        orders = copy.copy(born_proc.get('orders'))
        # compute the weighted order if not present
        if not 'WEIGHTED' in orders:
            orders['WEIGHTED'] = sum([v * born_proc.get('model').get('order_hierarchy')[o] \
                        for o, v in orders.items()])

        for order in perturbed_orders:
            try:
                orders[order] += 1
            except KeyError:
                pass
            orders['WEIGHTED'] += born_proc.get('model').get(
                'order_hierarchy')[order]

        self.process.set('orders', orders)
        legs = [(leg.get('id'), leg) for leg in leglist]
        self.pdgs = array.array('i', [s[0] for s in legs])
        if 'QCD' in perturbed_orders:
            self.colors = [leg['color'] for leg in leglist]
            # in QCD, charges are irrelevant !
            self.charges = [0. for leg in leglist]
            self.perturbation = 'QCD'
        else:
            self.colors = [leg['color'] for leg in leglist]
            self.charges = [leg['charge'] for leg in leglist]
            self.perturbation = 'QED'
        self.process.set('legs', MG.LegList(leglist))
        self.process.set('legs_with_decays', MG.LegList())
        self.amplitude = diagram_generation.Amplitude()
        self.is_to_integrate = True
        self.is_nbody_only = False
        self.fks_j_from_i = {}
Beispiel #2
0
    def test_find_symmetry_decay_chain_with_subprocess_group(self):
        """Test the find_symmetry function for subprocess groups"""

        procs = [[2, -1, 24, 21, 21], [-3, 4, 24, 21, 21]]
        decays = [[24, -11, 12], [24, -13, 14]]
        amplitudes = diagram_generation.AmplitudeList()
        decay_amps = diagram_generation.DecayChainAmplitudeList()

        for proc, decay in zip(procs, decays):
            # Define the multiprocess
            my_leglist = base_objects.LegList([\
                base_objects.Leg({'id': id, 'state': True}) for id in proc])

            my_leglist[0].set('state', False)
            my_leglist[1].set('state', False)

            my_decaylegs = base_objects.LegList([\
                base_objects.Leg({'id': id, 'state': True}) for id in decay])

            my_decaylegs[0].set('state', False)
            my_process = base_objects.Process({
                'legs': my_leglist,
                'model': self.base_model
            })
            my_decay_proc = base_objects.Process({
                'legs': my_decaylegs,
                'model': self.base_model,
                'is_decay_chain': True
            })
            my_amplitude = diagram_generation.Amplitude(my_process)
            my_decay = diagram_generation.DecayChainAmplitude(my_decay_proc)
            amplitudes.append(my_amplitude)
            decay_amps.append(my_decay)

        amplitudes = diagram_generation.DecayChainAmplitudeList([\
                diagram_generation.DecayChainAmplitude({\
                        'amplitudes': amplitudes,
                        'decay_chains': decay_amps})])

        subproc_groups = \
                  group_subprocs.DecayChainSubProcessGroup.group_amplitudes(\
                         amplitudes,"madevent").generate_helas_decay_chain_subproc_groups()
        self.assertEqual(len(subproc_groups), 1)

        subproc_group = subproc_groups[0]
        self.assertEqual(len(subproc_group.get('matrix_elements')), 2)

        symmetry, perms, ident_perms = diagram_symmetry.find_symmetry(\
                                                subproc_group)

        self.assertEqual(len([s for s in symmetry if s > 0]), 5)

        self.assertEqual(symmetry, [1, -1, 1, 1, 1, -4, -5, 1])
    def test_check_u_u_six_g(self):
        """Test the process u u > six g against literature expression"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False,
                                           'number': 1}))
        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False,
                                           'number': 2}))
        myleglist.append(base_objects.Leg({'id':9000006,
                                           'state':True,
                                           'number': 3}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':True,
                                           'number': 4}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})

        comparison_results, used_lorentz = \
                            process_checks.check_processes(myproc,
                                                           quick=True)
        self.assertTrue(comparison_results[0]['passed'])
    def test_uu_to_six_g(self):
        """Test the process u u > six g against literature expression"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False,
                                           'number': 1}))
        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False,
                                           'number': 2}))
        myleglist.append(base_objects.Leg({'id':9000006,
                                           'state':True,
                                           'number': 3}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':True,
                                           'number': 4}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})

        evaluator = process_checks.MatrixElementEvaluator(self.base_model,
                                                          reuse = False)
        
        p, w_rambo = evaluator.get_momenta(myproc)

        amplitude = diagram_generation.Amplitude(myproc)
        matrix_element = helas_objects.HelasMatrixElement(amplitude)

        mg5_me_value, amp2 = evaluator.evaluate_matrix_element(matrix_element,
                                                               p)

        comparison_value = uu_Dg(p, 6, evaluator.full_model)

        self.assertAlmostEqual(mg5_me_value, comparison_value, 12)
    def setUp(self):
        """load the model"""

        import madgraph.interface.master_interface as interface
        cmd = interface.MasterCmd()
        cmd.do_import('model sm')

        self.mybasemodel = cmd._curr_model
        self.mybasemodel.change_mass_to_complex_scheme()

        leg1 = base_objects.Leg({'id': 22, 'state': False})
        leg2 = base_objects.Leg({'id': 24, 'state': False})
        leg3 = base_objects.Leg({'id': 22, 'state': True})
        leg4 = base_objects.Leg({'id': 24, 'state': True})
        leg5 = base_objects.Leg({'id': 23, 'state': True})

        legList1 = base_objects.LegList([leg1, leg2, leg3, leg4, leg5])

        myproc = base_objects.Process({
            'legs': legList1,
            'model': self.mybasemodel
        })

        myamplitude = diagram_generation.Amplitude({'process': myproc})

        self.mymatrixelement = helas_objects.HelasMatrixElement(myamplitude)
Beispiel #6
0
def to_legs(fkslegs):
    """Given a FKSLegList, returns the corresponding LegList.
    """
    leglist = MG.LegList()
    for leg in fkslegs:
        leglist.append(to_leg(leg))
    return leglist
Beispiel #7
0
    def def_diagrams_epemddx(self):
        """ Test the drawing of diagrams from the loop process e+e- > dd~ """

        myleglist = base_objects.LegList()
        myleglist.append(base_objects.Leg({'id': -11, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 11, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 1, 'state': True}))
        myleglist.append(base_objects.Leg({'id': -1, 'state': True}))

        myproc = base_objects.Process({
            'legs': myleglist,
            'model': self.myloopmodel,
            'orders': {},
            'perturbation_couplings': [
                'QCD',
            ],
            'squared_orders': {}
        })

        myloopamplitude = loop_diagram_generation.LoopAmplitude()
        myloopamplitude.set('process', myproc)
        myloopamplitude.generate_diagrams()

        # Now the drawing test on myloopamplitude['loop_diagrams']
        return myloopamplitude['loop_diagrams']
    def test_find_symmetry_uu_tt_with_subprocess_group(self):
        """Test the find_symmetry function for subprocess groups"""

        procs = [[2,2,6,6]]
        amplitudes = diagram_generation.AmplitudeList()

        for proc in procs:
            # Define the multiprocess
            my_leglist = base_objects.LegList([\
                base_objects.Leg({'id': id, 'state': True}) for id in proc])

            my_leglist[0].set('state', False)
            my_leglist[1].set('state', False)

            my_process = base_objects.Process({'legs':my_leglist,
                                               'model':self.base_model_4ferm})
            my_amplitude = diagram_generation.Amplitude(my_process)
            amplitudes.append(my_amplitude)

        subproc_group = \
                  group_subprocs.SubProcessGroup.group_amplitudes(amplitudes, "madevent")[0]

        symmetry, perms, ident_perms = diagram_symmetry.find_symmetry(\
                                                                  subproc_group)

        self.assertEqual(len([s for s in symmetry if s > 0]), 1)

        self.assertEqual(symmetry,
                         [1])

        return
Beispiel #9
0
    def addIOTestsForProcess(self,
                             testName,
                             testFolder,
                             particles_ids,
                             exporters,
                             orders,
                             files_to_check=IOTests.IOTest.all_files,
                             perturbation_couplings=['QCD'],
                             NLO_mode='virt',
                             model=None,
                             fortran_model=None):
        """ Simply adds a test for the process defined and all the exporters
        specified."""

        if model == None:
            model = self.models['loop_sm']
        if fortran_model == None:
            fortran_model = self.fortran_models['fortran_model']

        needed = False
        if not isinstance(exporters, dict):
            if self.need(testFolder, testName):
                needed = True
        elif any(self.need('%s_%s'%(testFolder,exporter) ,testName) for \
                                                  exporter in exporters.keys()):
            needed = True
        if not needed:
            return

        myleglist = base_objects.LegList()
        for i, pid in enumerate(particles_ids):
            myleglist.append(
                base_objects.Leg({
                    'id': pid,
                    'state': False if i < 2 else True
                }))
        myproc = base_objects.Process({
            'legs': myleglist,
            'model': model,
            'orders': orders,
            'perturbation_couplings': perturbation_couplings,
            'NLO_mode': NLO_mode
        })

        # Exporter directly given
        if not isinstance(exporters, dict):
            test_list = [(testFolder, exporters)]
        # Several exporters given in a dictionary
        else:
            test_list = [('%s_%s'%(testFolder,exp),exporters[exp]) for exp in \
                                                               exporters.keys()]

        for (folderName, exporter) in test_list:
            if self.need(folderName, testName):
                self.addIOTest(folderName,testName, IOTests.IOTest(\
                  procdef=myproc,
                  exporter=exporter,
                  helasModel=fortran_model,
                  testedFiles=files_to_check,
                  outputPath=_proc_file_path))
Beispiel #10
0
    def test_colorize_uu_gg(self):
        """Test the colorize function for uu~ > gg"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': -2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))

        myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 2)

        myprocess = base_objects.Process({
            'legs': myleglist,
            'model': self.mymodel
        })

        myamplitude = diagram_generation.Amplitude()

        myamplitude.set('process', myprocess)

        myamplitude.generate_diagrams()

        my_col_basis = color_amp.ColorBasis()

        # S channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][0],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(-1000, 1, 2),
                               color.f(3, 4, -1000)])
        }

        self.assertEqual(col_dict, goal_dict)

        # T channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][1],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(3, 1, -1000),
                               color.T(4, -1000, 2)])
        }

        self.assertEqual(col_dict, goal_dict)

        # U channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][2],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(4, 1, -1000),
                               color.T(3, -1000, 2)])
        }

        self.assertEqual(col_dict, goal_dict)
Beispiel #11
0
    def __init__(self, start_proc = None, remove_reals = True):
        """initialization: starts either from an amplitude or a process,
        then init the needed variables.
        remove_borns tells if the borns not needed for integration will be removed
        from the born list (mainly used for testing)"""
                
        self.splittings = {}
        self.reals = []
        self.fks_dirs = []
        self.leglist = []
        self.myorders = {}
        self.pdg_codes = []
        self.colors = []
        self.nlegs = 0
        self.fks_ipos = []
        self.fks_j_from_i = {}
        self.real_amps = []
        self.remove_reals = remove_reals
        self.nincoming = 0
        self.virt_amp = None

        if not remove_reals in [True, False]:
            raise fks_common.FKSProcessError(\
                    'Not valid type for remove_reals in FKSProcess')
        
        if start_proc:
            if isinstance(start_proc, MG.Process):
                self.born_proc = fks_common.sort_proc(start_proc) 
                self.born_amp = diagram_generation.Amplitude(self.born_proc)
            elif isinstance(start_proc, diagram_generation.Amplitude):
                self.born_proc = fks_common.sort_proc(start_proc.get('process'))
                self.born_amp = diagram_generation.Amplitude(self.born_proc)
            else:
                raise fks_common.FKSProcessError(\
                    'Not valid start_proc in FKSProcess')

            self.born_proc.set('legs_with_decays', MG.LegList())

            self.leglist = fks_common.to_fks_legs(
                                    self.born_proc['legs'], self.born_proc['model'])
            self.nlegs = len(self.leglist)
            self.pdg_codes = [leg.get('id') for leg in self.leglist]
            self.colors = [leg.get('color') for leg in self.leglist]
            self.isr = set([leg.get('color') for leg in self.leglist if not leg.get('state')]) != set([1])
            self.fsr = set([leg.get('color') for leg in self.leglist if leg.get('state')]) != set([1])
            for leg in self.leglist:
                if not leg['state']:
                    self.nincoming += 1
            self.orders = self.born_amp['process']['orders']
            # this is for cases in which the user specifies e.g. QED=0
            if sum(self.orders.values()) == 0:
                self.orders = fks_common.find_orders(self.born_amp)
                
            self.ndirs = 0
            for order in self.born_proc.get('perturbation_couplings'):
                self.find_reals(order)
Beispiel #12
0
    def test_find_symmetry_qq_qqg_with_subprocess_group(self):
        """Test the find_symmetry function for subprocess groups"""

        procs = [[2,-2,2,-2,21], [2,2,2,2,21]]
        amplitudes = diagram_generation.AmplitudeList()

        for proc in procs:
            # Define the multiprocess
            my_leglist = base_objects.LegList([\
                base_objects.Leg({'id': id, 'state': True}) for id in proc])

            my_leglist[0].set('state', False)
            my_leglist[1].set('state', False)

            my_process = base_objects.Process({'legs':my_leglist,
                                               'model':self.base_model})
            my_amplitude = diagram_generation.Amplitude(my_process)
            amplitudes.append(my_amplitude)

        subproc_group = \
                  group_subprocs.SubProcessGroup.group_amplitudes(amplitudes,"madevent")[0]

        symmetry, perms, ident_perms = diagram_symmetry.find_symmetry(\
                                                subproc_group)

        self.assertEqual(len([s for s in symmetry if s > 0]), 19)

        self.assertEqual(symmetry,[1, 1, 1, 1, -2, -3, -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -8, -9, -10, -11, -12, -13, -14, -18, -19])

        return

        # The test below doesn't apply with the new way of determining
        # config symmetry for subprocess groups, since we don't demand
        # that symmetric diagrams have identical particles.

        # Check that the momentum assignments work
        matrix_element = \
                     subproc_group.get('matrix_elements')[1]
        process = matrix_element.get('processes')[0]

        evaluator = process_checks.MatrixElementEvaluator(self.base_model,
                                                          auth_skipping = True,
                                                          reuse = True)
        p, w_rambo = evaluator.get_momenta(process)
        me_value, amp2_org = evaluator.evaluate_matrix_element(\
                                                        matrix_element, p)

        for isym, (sym, perm) in enumerate(zip(symmetry, perms)):
            new_p = [p[i] for i in perm]
            if sym >= 0:
                continue
            iamp = subproc_group.get('diagram_maps')[1].index(isym+1)
            isymamp = subproc_group.get('diagram_maps')[1].index(-sym)
            me_value, amp2 = evaluator.evaluate_matrix_element(\
                                              matrix_element, new_p)
            self.assertAlmostEqual(amp2[iamp], amp2_org[isymamp])
    def test_get_s_and_t_ub_tdg(self):
        """test that for the single-top (ub>tdg) the s-and t-channels are correctly
        returned"""

        myleglist = MG.LegList()
        myleglist.append(MG.Leg({'id': 2, 'state': False}))
        myleglist.append(MG.Leg({'id': 5, 'state': False}))
        myleglist.append(MG.Leg({'id': 6, 'state': True}))
        myleglist.append(MG.Leg({'id': 1, 'state': True}))
        myleglist.append(MG.Leg({'id': 21, 'state': True}))
        proc = MG.Process({
            'legs': myleglist,
            'model': self.base_model,
            'orders': {
                'QCD': 1,
                'QED': 2
            }
        })
        me = helas_objects.HelasMatrixElement(
            diagram_generation.Amplitude(proc))

        #without flipping: s-and-t channel legs
        # note that leg 2 never appears
        target = [[[1, 4, -1], [-1, 3, -2], [-2, 5, -3]],
                  [[5, 3, -1], [1, 4, -2], [-2, -1, -3]],
                  [[1, 5, -1], [-1, 4, -2], [-2, 3, -3]],
                  [[5, 4, -1], [1, -1, -2], [-2, 3, -3]]]

        #if we flip the s-and-t channel legs should be
        # note that leg 1 never appears
        target_flip = [[[2, 5, -1], [-1, 3, -2], [-2, 4, -3]],
                       [[5, 3, -1], [2, -1, -2], [-2, 4, -3]],
                       [[2, 3, -1], [-1, 4, -2], [-2, 5, -3]],
                       [[5, 4, -1], [2, 3, -2], [-2, -1, -3]]]

        for id, diag in enumerate(me.get('diagrams')):
            s_ch, t_ch = diag.get('amplitudes')[0].get_s_and_t_channels(
                ninitial=2,
                model=self.base_model,
                new_pdg=7,
                reverse_t_ch=False)
            self.assertEqual( [ [l['number'] for l in v['legs']] for v in s_ch] + \
                              [ [l['number'] for l in v['legs']] for v in t_ch] ,
                              target[id])

        for id, diag in enumerate(me.get('diagrams')):
            s_ch, t_ch = diag.get('amplitudes')[0].get_s_and_t_channels(
                ninitial=2,
                model=self.base_model,
                new_pdg=7,
                reverse_t_ch=True)
            self.assertEqual( [ [l['number'] for l in v['legs']] for v in s_ch] + \
                              [ [l['number'] for l in v['legs']] for v in t_ch] ,
                              target_flip[id])
    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)
Beispiel #15
0
def sort_proc(process,pert = 'QCD'):
    """Given a process, this function returns the same process 
    but with sorted FKSLegs.
    """
    leglist = to_fks_legs(process.get('legs'), process.get('model'))
    leglist.sort(pert = pert)
    for n, leg in enumerate(leglist):
        leg['number'] = n + 1
    process['legs'] = leglist
    # add this line to pass ./test_managers.py -p A test_check_ppzjj
    process['legs_with_decays']=MG.LegList()

    return process
Beispiel #16
0
    def test_get_momenta(self):
        """Test the get_momenta function"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':-11,
                                           'state':False,
                                           'number': 1}))
        myleglist.append(base_objects.Leg({'id':11,
                                           'state':False,
                                           'number': 2}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True,
                                           'number': 3}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True,
                                           'number': 4}))
        myleglist.append(base_objects.Leg({'id':23,
                                           'state':True,
                                           'number': 5}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})

        evaluator = process_checks.MatrixElementEvaluator(self.base_model)
        full_model = evaluator.full_model
        p, w_rambo = evaluator.get_momenta(myproc)

        # Check massless external momenta
        for mom in p[:-1]:
            mass = mom[0]**2-(mom[1]**2+mom[2]**2+mom[3]**2)
            self.assertAlmostEqual(mass, 0., 8)

        mom = p[-1]
        mass = math.sqrt(mom[0]**2-(mom[1]**2+mom[2]**2+mom[3]**2))
        self.assertAlmostEqual(mass,
                               full_model.get('parameter_dict')['mdl_MZ'],
                               8)

        # Check momentum balance
        outgoing = [0]*4
        incoming = [0]*4
        for i in range(4):
            incoming[i] = sum([mom[i] for mom in p[:2]])
            outgoing[i] = sum([mom[i] for mom in p[2:]])
            self.assertAlmostEqual(incoming[i], outgoing[i], 8)

        # Check non-zero final state momenta
        for mom in p[2:]:
            for i in range(4):
                self.assertTrue(abs(mom[i]) > 0.)
Beispiel #17
0
    def test_comparison_for_process(self):
        """Test check process for e+ e- > a Z"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':-11,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':11,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':23,
                                           'state':True}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})
        process_checks.clean_added_globals(process_checks.ADDED_GLOBAL)
        comparison = process_checks.check_processes(myproc)[0][0]

        self.assertEqual(len(comparison['values']), 8)
        self.assertTrue(comparison['values'][0] > 0)
        self.assertTrue(comparison['passed'])

        comparison = process_checks.check_gauge(myproc)
        
        #check number of helicities/jamp
        nb_hel = []
        nb_jamp = [] 
        for one_comp in comparison:
            nb_hel.append(len(one_comp['value']['jamp']))
            nb_jamp.append(len(one_comp['value']['jamp'][0]))
        self.assertEqual(nb_hel, [24])
        self.assertEqual(nb_jamp, [1])
        
        nb_fail = process_checks.output_gauge(comparison, output='fail')
        self.assertEqual(nb_fail, 0)
        
        comparison = process_checks.check_lorentz(myproc)
        #check number of helicities/jamp
        nb_hel = []
        nb_jamp = [] 
        for one_comp in comparison:
            nb_hel.append(len(one_comp['results'][0]['jamp']))
            nb_jamp.append(len(one_comp['results'][0]['jamp'][0]))
        self.assertEqual(nb_hel, [24])
        self.assertEqual(nb_jamp, [1])
        
        nb_fail = process_checks.output_lorentz_inv(comparison, output='fail')
        self.assertEqual(0, nb_fail)        
Beispiel #18
0
    def test_find_symmetry_epem_aaa(self):
        """Test the find_symmetry function"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':-11,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':11,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':22,
                                           'state':True}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})

        myamplitude = diagram_generation.Amplitude(myproc)

        matrix_element = helas_objects.HelasMatrixElement(myamplitude)

        symmetry, perms, ident_perms = diagram_symmetry.find_symmetry(matrix_element)

        self.assertEqual(symmetry, [6,-1,-1,-1,-1,-1])

        # Check that the momentum assignments work
        process = matrix_element.get('processes')[0]

        evaluator = process_checks.MatrixElementEvaluator(self.base_model,
                                                          auth_skipping = True,
                                                          reuse = True)
        
        p, w_rambo = evaluator.get_momenta(process)
        me_value, amp2_org = evaluator.evaluate_matrix_element(\
                                          matrix_element, p)

        for isym, (sym, perm) in enumerate(zip(symmetry, perms)):
            new_p = [p[i] for i in perm]
            if sym >= 0:
                continue
            me_value, amp2 = evaluator.evaluate_matrix_element(matrix_element,
                                                               new_p)
            self.assertAlmostEqual(amp2[isym], amp2_org[-sym-1])
Beispiel #19
0
    def test_rotate_momenta(self):
        """Test that matrix element and amp2 identical for rotated momenta"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':-2,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':2,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':-2,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':True}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})

        myamp = diagram_generation.Amplitude(myproc)

        matrix_element = helas_objects.HelasMatrixElement(myamp)

        evaluator = process_checks.MatrixElementEvaluator(self.base_model,
                                                          auth_skipping = True,
                                                          reuse = True)
        p, w_rambo = evaluator.get_momenta(myproc)

        me_val, amp2 = evaluator.evaluate_matrix_element(\
                                          matrix_element,p)
        # Rotate momenta around x axis
        for mom in p:
            mom[2] = -mom[2]
            mom[3] = -mom[3]

        new_me_val, new_amp2 = evaluator.evaluate_matrix_element(\
                                          matrix_element, p)

        self.assertAlmostEqual(me_val, new_me_val, 10)

        for amp, new_amp in zip(amp2, new_amp2):
            self.assertAlmostEqual(amp, new_amp, 10)
    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
    def uu_to_ttng_test(self, nglue = 0):
        """Test the process u u > t t g for 4fermion models"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':2,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':6}))
        myleglist.append(base_objects.Leg({'id':6}))
        myleglist.extend([base_objects.Leg({'id':21}) for i in range(nglue)])

        values = {}
        p = None
        for model in 'scalar', '4ferm':

            base_model = eval('self.base_model_%s' % model)
            full_model = eval('self.full_model_%s' % model)
            myproc = base_objects.Process({'legs':myleglist,
                                           'model':base_model})

            evaluator = process_checks.MatrixElementEvaluator(base_model,
                                                                  reuse = False)
            evaluator.full_model = full_model
            
            if not p:
                p, w_rambo = evaluator.get_momenta(myproc)

            amplitude = diagram_generation.Amplitude(myproc)

            matrix_element = helas_objects.HelasMatrixElement(amplitude)

            stored_quantities = {}

            values[model] = evaluator.evaluate_matrix_element(matrix_element,
                                                              p)[0]

            
        self.assertAlmostEqual(values['scalar'], values['4ferm'], 3)
Beispiel #22
0
    def test_failed_process(self):
        """Test that check process fails for wrong color-Lorentz."""

        # Change 4g interaction so color and lorentz don't agree
        id = [int.get('id') for int in self.base_model.get('interactions')
               if [p['pdg_code'] for p in int['particles']] == [21,21,21,21]][0]
        gggg = self.base_model.get_interaction(id)
        assert [p['pdg_code'] for p in gggg['particles']] == [21,21,21,21]
        gggg.set('lorentz', ['VVVV1', 'VVVV4', 'VVVV3'])

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id':21,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':False}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':True}))
        myleglist.append(base_objects.Leg({'id':21,
                                           'state':True}))

        myproc = base_objects.Process({'legs':myleglist,
                                       'model':self.base_model})
        process_checks.clean_added_globals(process_checks.ADDED_GLOBAL)
        comparison = process_checks.check_processes(myproc)[0][0]

        self.assertFalse(comparison['passed'])

        comparison = process_checks.check_processes(myproc, quick = True)[0][0]

        self.assertFalse(comparison['passed'])
        
        comparison = process_checks.check_gauge(myproc)
        nb_fail = process_checks.output_gauge(comparison, output='fail')
        self.assertNotEqual(nb_fail, 0)
        
        comparison = process_checks.check_lorentz(myproc)
        nb_fail = process_checks.output_lorentz_inv(comparison, output='fail')
        self.assertNotEqual(0, nb_fail)
Beispiel #23
0
    def test_color_matrix_Nc_restrictions(self):
        """Test the Nc power restriction during color basis building """

        goal = [
            fractions.Fraction(3, 8),
            fractions.Fraction(-9, 4),
            fractions.Fraction(45, 16)
        ]

        for n in range(3):
            myleglist = base_objects.LegList()

            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))
            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))

            myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 2)

            myprocess = base_objects.Process({
                'legs': myleglist,
                'model': self.mymodel
            })

            myamplitude = diagram_generation.Amplitude()

            myamplitude.set('process', myprocess)

            myamplitude.generate_diagrams()

            col_basis = color_amp.ColorBasis(myamplitude)

            col_matrix = color_amp.ColorMatrix(col_basis,
                                               Nc=3,
                                               Nc_power_min=n,
                                               Nc_power_max=2 * n)

            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(i, i)],
                                 (goal[n], 0))
Beispiel #24
0
    def setUp(self):
        """ Setup the model and the overhead common to all tests  """
        
        model_with_params_set = import_ufo.import_model(
                pjoin(MG5DIR,'models','loop_sm'), prefix=True,
                complex_mass_scheme = False )
        model_with_params_set.pass_particles_name_in_mg_default()
        model_with_params_set.set_parameters_and_couplings(
                param_card = pjoin(MG5DIR,'models','loop_sm','restrict_default.dat'),
                complex_mass_scheme=False )

        self.model = model_with_params_set
        self.current_exporter = subtraction.SubtractionCurrentExporter(
            self.model, export_dir=None, current_set='colorful')
        
        self.walker = walkers.FinalRescalingNLOWalker
        
        legs = base_objects.LegList([
            base_objects.Leg(
                    {'id': 1, 'state': base_objects.Leg.INITIAL, 'number': 1}),
            base_objects.Leg(
                    {'id': -1, 'state': base_objects.Leg.INITIAL, 'number': 2}),
            base_objects.Leg(
                    {'id': 22, 'state': base_objects.Leg.FINAL, 'number': 3}),
            base_objects.Leg(
                    {'id': 1,  'state': base_objects.Leg.FINAL, 'number': 4}),
            base_objects.Leg(
                    {'id': -1, 'state': base_objects.Leg.FINAL, 'number': 5}),
            base_objects.Leg(
                    {'id': 21, 'state': base_objects.Leg.FINAL, 'number': 6}),
            base_objects.Leg(
                    {'id': 21, 'state': base_objects.Leg.FINAL, 'number': 7}),
        ])
        
        self.reduced_process = base_objects.Process({
            'legs': legs,
            'model': self.model
        })
    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, []
def find_symmetry_by_evaluation(matrix_element, evaluator, max_time=600):
    """Find symmetries between amplitudes by comparing the squared
    amplitudes for all permutations of identical particles.
    
    Return list of positive number corresponding to number of
    symmetric diagrams and negative numbers corresponding to the
    equivalent diagram (for e+e->3a, get [6, -1, -1, -1, -1, -1]),
    list of the corresponding permutations needed, and list of all
    permutations of identical particles.
    max_time gives a cutoff time for finding symmetries (in s)."""

    #if isinstance(matrix_element, group_subprocs.SubProcessGroup):
    #    return find_symmetry_subproc_group(matrix_element, evaluator, max_time)

    assert isinstance(matrix_element, helas_objects.HelasMatrixElement)

    # Exception class and routine to handle timeout
    class TimeOutError(Exception):
        pass

    def handle_alarm(signum, frame):
        raise TimeOutError

    (nexternal, ninitial) = matrix_element.get_nexternal_ninitial()

    # Prepare the symmetry vector with non-used amp2s (due to
    # multiparticle vertices)
    symmetry = []
    for diag in matrix_element.get('diagrams'):
        if max(diag.get_vertex_leg_numbers()) > 3:
            # Ignore any diagrams with 4-particle vertices
            symmetry.append(0)
        else:
            symmetry.append(1)

    # Check for matrix elements with no identical particles
    if matrix_element.get("identical_particle_factor") == 1:
        return symmetry, \
               [range(nexternal)]*len(symmetry),\
               [range(nexternal)]

    logger.info("Finding symmetric diagrams for process %s" % \
                 matrix_element.get('processes')[0].nice_string().\
                 replace("Process: ", ""))

    process = matrix_element.get('processes')[0]
    base_model = process.get('model')
    equivalent_process = base_objects.Process({\
                     'legs': base_objects.LegList([base_objects.Leg({
                               'id': wf.get('pdg_code'),
                               'state': wf.get('leg_state')}) \
                       for wf in matrix_element.get_external_wavefunctions()]),
                     'model': base_model})

    # Get phase space point
    p, w_rambo = evaluator.get_momenta(equivalent_process)

    # Check matrix element value for all permutations
    amp2start = []
    final_states = [l.get('id') for l in \
                    equivalent_process.get('legs')[ninitial:]]
    nperm = 0
    perms = []
    ident_perms = []

    # Set timeout for max_time
    signal.signal(signal.SIGALRM, handle_alarm)
    signal.alarm(max_time)
    try:
        for perm in itertools.permutations(range(ninitial, nexternal)):
            if [equivalent_process.get('legs')[i].get('id') for i in perm] != \
               final_states:
                # Non-identical particles permutated
                continue
            ident_perms.append([0, 1] + list(perm))
            nperm += 1
            new_p = p[:ninitial] + [p[i] for i in perm]

            res = evaluator.evaluate_matrix_element(matrix_element, new_p)
            if not res:
                break
            me_value, amp2 = res
            # Make a list with (8-pos value, magnitude) to easily compare
            amp2sum = sum(amp2)
            amp2mag = []
            for a in amp2:
                a = a * me_value / max(amp2sum, 1e-30)
                if a > 0:
                    amp2mag.append(int(math.floor(math.log10(abs(a)))))
                else:
                    amp2mag.append(0)
            amp2 = [(int(a * 10**(8 - am)), am)
                    for (a, am) in zip(amp2, amp2mag)]

            if not perms:
                # This is the first iteration - initialize lists
                # Initiate symmetry with all 1:s
                symmetry = [1 for i in range(len(amp2))]
                # Store initial amplitudes
                amp2start = amp2
                # Initialize list of permutations
                perms = [range(nexternal) for i in range(len(amp2))]
                continue

            for i, val in enumerate(amp2):
                if val == (0, 0):
                    # If amp2 is 0, just set symmetry to 0
                    symmetry[i] = 0
                    continue
                # Only compare with diagrams below this one
                if val in amp2start[:i]:
                    ind = amp2start.index(val)
                    # Replace if 1) this amp is unmatched (symmetry[i] > 0) or
                    # 2) this amp is matched but matched to an amp larger
                    # than ind
                    if symmetry[ind] > 0 and \
                       (symmetry[i] > 0 or \
                        symmetry[i] < 0 and -symmetry[i] > ind + 1):
                        symmetry[i] = -(ind + 1)
                        perms[i] = [0, 1] + list(perm)
                        symmetry[ind] += 1
    except TimeOutError:
        # Symmetry canceled due to time limit
        logger.warning("Cancel diagram symmetry - time exceeded")

    # Stop the alarm since we're done with this process
    signal.alarm(0)

    return (symmetry, perms, ident_perms)
    def test_triplet_color_flow_output(self):
        """Test the color flow output for color triplets"""

        # Test u u > trip~ g

        myleglist = base_objects.LegList()

        myleglist.append(
            base_objects.Leg({
                'id': 2,
                'state': False,
                'number': 1
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 6,
                'state': False,
                'number': 2
            }))
        myleglist.append(
            base_objects.Leg({
                'id': -9000006,
                'state': True,
                'number': 3
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 21,
                'state': True,
                'number': 4
            }))

        myproc = base_objects.Process({
            'legs': myleglist,
            'model': self.base_model
        })

        myamp = diagram_generation.Amplitude(myproc)
        matrix_element = helas_objects.HelasMatrixElement(myamp)

        # First build a color representation dictionnary
        repr_dict = {}
        for l in myleglist:
            repr_dict[l.get('number')] = \
                self.base_model.get_particle(l.get('id')).get_color()

        # Get the color flow decomposition
        col_flow = \
           matrix_element.get('color_basis').color_flow_decomposition(repr_dict,
                                                                      2)
        self.assertEqual(col_flow, [{
            1: [501, 0],
            2: [502, 0],
            3: [0, 504],
            4: [504, 503]
        }, {
            1: [501, 0],
            2: [504, 0],
            3: [0, 502],
            4: [504, 503]
        }, {
            1: [504, 0],
            2: [501, 0],
            3: [0, 502],
            4: [504, 503]
        }])

        # Test u u > trip~ > u u g

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 6, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 2, 'state': True}))
        myleglist.append(base_objects.Leg({'id': 6, 'state': True}))
        myleglist.append(base_objects.Leg({'id': 21, 'state': True}))

        myproc = base_objects.Process({
            'legs': myleglist,
            'model': self.base_model,
            'required_s_channels': [[-9000006]]
        })

        myamp = diagram_generation.Amplitude(myproc)
        self.assertEqual(len(myamp.get('diagrams')), 5)
        matrix_element = helas_objects.HelasMatrixElement(myamp)

        # First build a color representation dictionnary
        repr_dict = {}
        for l in myleglist:
            repr_dict[l.get('number')] = \
                self.base_model.get_particle(l.get('id')).get_color()

        # Get the color flow decomposition
        col_flow = \
           matrix_element.get('color_basis').color_flow_decomposition(repr_dict,
                                                                      2)
        self.assertEqual(col_flow, [{
            1: [501, 0],
            2: [502, 0],
            3: [504, 0],
            4: [505, 0],
            5: [506, 503]
        }, {
            1: [501, 0],
            2: [503, 0],
            3: [501, 0],
            4: [502, 0],
            5: [503, 502]
        }, {
            1: [503, 0],
            2: [501, 0],
            3: [501, 0],
            4: [502, 0],
            5: [503, 502]
        }, {
            1: [502, 0],
            2: [503, 0],
            3: [501, 0],
            4: [502, 0],
            5: [503, 501]
        }, {
            1: [503, 0],
            2: [502, 0],
            3: [501, 0],
            4: [502, 0],
            5: [503, 501]
        }])
    def setUp(self):
        # Set up model

        mypartlist = base_objects.ParticleList()
        myinterlist = base_objects.InteractionList()

        # A photon
        mypartlist.append(
            base_objects.Particle({
                'name': 'a',
                'antiname': 'a',
                'spin': 3,
                'color': 1,
                'mass': 'zero',
                'width': 'zero',
                'texname': '\gamma',
                'antitexname': '\gamma',
                'line': 'wavy',
                'charge': 0.,
                'pdg_code': 22,
                'propagating': True,
                'is_part': True,
                'self_antipart': True
            }))
        a = mypartlist[len(mypartlist) - 1]

        # W+ and W-
        mypartlist.append(
            base_objects.Particle({
                'name': 'w+',
                'antiname': 'w-',
                'spin': 3,
                'color': 1,
                'mass': 'wmas',
                'width': 'wwid',
                'texname': 'W^+',
                'antitexname': 'W^-',
                'line': 'wavy',
                'charge': 1.,
                'pdg_code': 24,
                'propagating': True,
                'is_part': True,
                'self_antipart': False
            }))
        wplus = mypartlist[len(mypartlist) - 1]
        wminus = copy.copy(wplus)
        wminus.set('is_part', False)

        # Z
        mypartlist.append(
            base_objects.Particle({
                'name': 'z',
                'antiname': 'z',
                'spin': 3,
                'color': 1,
                'mass': 'zmas',
                'width': 'zwid',
                'texname': 'Z',
                'antitexname': 'Z',
                'line': 'wavy',
                'charge': 1.,
                'pdg_code': 23,
                'propagating': True,
                'is_part': True,
                'self_antipart': True
            }))
        z = mypartlist[len(mypartlist) - 1]

        # a-a-w+w- 4-vertex
        myinterlist.append(base_objects.Interaction({
                      'id': 1,
                      'particles': base_objects.ParticleList(\
                                            [a, \
                                             a,
                                             wminus,
                                             wplus]),
                      'color': [],
                      'lorentz':['VVVV1'],
                      'couplings':{(0, 0):'GC_51'},
                      'orders':{'QED':2}}))

        # w+w-z vertex
        myinterlist.append(base_objects.Interaction({
                      'id': 2,
                      'particles': base_objects.ParticleList(\
                                            [wminus,
                                             wplus,
                                             z]),
                      'color': [],
                      'lorentz':['VVV1'],
                      'couplings':{(0, 0):'GC_12'},
                      'orders':{'QED':1}}))

        self.mybasemodel.set('particles', mypartlist)
        self.mybasemodel.set('interactions', myinterlist)
        self.mybasemodel.set('name', 'sm')

        #import madgraph.interface.cmd_interface as cmd
        #CMD = cmd.MadGraphCmdShell()
        #CMD._curr_model = self.mybasemodel
        #CMD._curr_fortran_model = helas_call_writers.FortranUFOHelasCallWriter
        #CMD.do_generate('a w- > w- a z')
        #CMD.do_export('matrix_v4 /tmp/')

        leg1 = base_objects.Leg({'id': 22, 'state': False})
        leg2 = base_objects.Leg({'id': 24, 'state': False})
        leg3 = base_objects.Leg({'id': 22, 'state': True})
        leg4 = base_objects.Leg({'id': 24, 'state': True})
        leg5 = base_objects.Leg({'id': 23, 'state': True})

        legList1 = base_objects.LegList([leg1, leg2, leg3, leg4, leg5])

        myproc = base_objects.Process({
            'legs': legList1,
            'model': self.mybasemodel
        })

        myamplitude = diagram_generation.Amplitude({'process': myproc})

        self.mymatrixelement = helas_objects.HelasMatrixElement(myamplitude)
    def test_w_and_z_amplitudes(self):
        """Test wavefunction and amplitude calls for W and Z"""

        goal = [ \
            'CALL JWWWXX(W(1,2),W(1,3),W(1,4),MGVX6,wmas,wwid,W(1,1))',
            'CALL JWWWXX(W(1,1),W(1,3),W(1,4),MGVX6,wmas,wwid,W(1,2))',
            'CALL JWWWXX(W(1,1),W(1,2),W(1,4),MGVX6,wmas,wwid,W(1,3))',
            'CALL JWWWXX(W(1,1),W(1,2),W(1,3),MGVX6,wmas,wwid,W(1,4))',
            '# Amplitude(s) for diagram number 1',
            'CALL WWWWXX(W(1,1),W(1,2),W(1,3),W(1,4),MGVX6,AMP(1))',
            'CALL JW3WXX(W(1,2),W(1,3),W(1,4),MGVX8,wmas,wwid,W(1,1))',
            'CALL JW3WXX(W(1,1),W(1,3),W(1,4),MGVX8,wmas,wwid,W(1,2))',
            'CALL JW3WXX(W(1,1),W(1,2),W(1,4),MGVX8,zmas,zwid,W(1,3))',
            'CALL JW3WXX(W(1,1),W(1,2),W(1,3),MGVX8,zmas,zwid,W(1,4))',
            '# Amplitude(s) for diagram number 1',
            'CALL W3W3XX(W(1,1),W(1,2),W(1,3),W(1,4),MGVX8,AMP(1))']

        goal_counter = 0

        myleglist = base_objects.LegList()

        myleglist.append(
            base_objects.Leg({
                'id': 24,
                'number': 1,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': -24,
                'number': 2,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 24,
                'number': 3,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': -24,
                'number': 4,
                'state': False
            }))

        wfs = helas_objects.HelasWavefunctionList(\
            [ helas_objects.HelasWavefunction(leg, 8,
                                              self.mybasemodel) \
              for leg in myleglist ])

        fortran_model = helas_call_writers.FortranHelasCallWriter()

        for wf in wfs:
            mothers = copy.copy(wfs)
            mothers.remove(wf)
            wf.set('mothers', mothers)
            # Not yet implemented special wavefunctions for W/Z
            #self.assertEqual(fortran_model.get_wavefunction_call(wf),
            #                 goal[goal_counter])
            goal_counter = goal_counter + 1

        amplitude = helas_objects.HelasAmplitude({\
            'mothers': wfs,
            'number': 1})
        amplitude.set('interaction_id', 8, self.mybasemodel)
        # Not yet implemented special wavefunctions for W/Z
        #self.assertEqual(fortran_model.get_amplitude_call(amplitude),
        #                 goal[goal_counter])
        goal_counter = goal_counter + 1

        myleglist = base_objects.LegList()

        myleglist.append(
            base_objects.Leg({
                'id': 24,
                'number': 1,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': -24,
                'number': 2,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 23,
                'number': 3,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 23,
                'number': 4,
                'state': False
            }))

        wfs = helas_objects.HelasWavefunctionList(\
            [ helas_objects.HelasWavefunction(leg, 9,
                                              self.mybasemodel) \
              for leg in myleglist ])

        fortran_model = helas_call_writers.FortranHelasCallWriter()

        for wf in wfs:
            mothers = copy.copy(wfs)
            mothers.remove(wf)
            wf.set('mothers', mothers)
            # Not yet implemented special wavefunctions for W/Z
            # self.assertEqual(fortran_model.get_wavefunction_call(wf),
            #                 goal[goal_counter])
            goal_counter = goal_counter + 1


        amplitude = helas_objects.HelasAmplitude({\
            'mothers': wfs,
            'number': 1})
        amplitude.set('interaction_id', 9, self.mybasemodel)
        # Not yet implemented special wavefunctions for W/Z
        #self.assertEqual(fortran_model.get_amplitude_call(amplitude),
        #                 goal[goal_counter])
        goal_counter = goal_counter + 1
    def test_generate_wavefunctions_and_amplitudes(self):
        """Test automatic generation of wavefunction and amplitude calls"""

        goal = [ \
            'CALL IXXXXX(P(0,1),me,NHEL(1),+1*IC(1),W(1,1))',
            'CALL OXXXXX(P(0,2),me,NHEL(2),-1*IC(2),W(1,2))',
            'CALL VXXXXX(P(0,3),zero,NHEL(3),-1*IC(3),W(1,3))',
            'CALL FVOXXX(W(1,2),W(1,3),MGVX12,me,zero,W(1,1))',
            'CALL FVIXXX(W(1,1),W(1,3),MGVX12,me,zero,W(1,2))',
            'CALL JIOXXX(W(1,1),W(1,2),MGVX12,zero,zero,W(1,3))',
            'CALL IOVXXX(W(1,1),W(1,2),W(1,3),MGVX12,AMP(1))',
            'CALL VXXXXX(P(0,1),zero,NHEL(1),-1*IC(1),W(1,1))',
            'CALL VXXXXX(P(0,2),zero,NHEL(2),-1*IC(2),W(1,2))',
            'CALL TXXXXX(P(0,3),zero,NHEL(3),-1*IC(3),W(1,3))',
            'CALL JVTAXX(W(1,2),W(1,3),MGVX2,zero,zero,W(1,1))',
            'CALL JVTAXX(W(1,1),W(1,3),MGVX2,zero,zero,W(1,2))',
            'CALL UVVAXX(W(1,1),W(1,2),MGVX2,zero,zero,zero,W(1,3))',
            'CALL VVTAXX(W(1,1),W(1,2),W(1,3),MGVX2,zero,AMP(2))',
            'CALL VXXXXX(P(0,1),zero,NHEL(1),-1*IC(1),W(1,1))',
            'CALL VXXXXX(P(0,2),zero,NHEL(2),-1*IC(2),W(1,2))',
            'CALL SXXXXX(P(0,3),-1*IC(3),W(1,3))',
            'CALL SXXXXX(P(0,4),-1*IC(4),W(1,4))',
            'CALL JVSSXX(W(1,2),W(1,3),W(1,4),MGVX89,zero,zero,W(1,1))',
            'CALL JVSSXX(W(1,1),W(1,3),W(1,4),MGVX89,zero,zero,W(1,2))',
            'CALL HVVSXX(W(1,2),W(1,1),W(1,4),MGVX89,Musq2,Wusq2,W(1,3))',
            'CALL HVVSXX(W(1,2),W(1,1),W(1,3),MGVX89,Musq2,Wusq2,W(1,4))',
            'CALL VVSSXX(W(1,2),W(1,1),W(1,3),W(1,4),MGVX89,AMP(1))']

        myleglist = base_objects.LegList()

        myleglist.append(
            base_objects.Leg({
                'id': 11,
                'number': 1,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': -11,
                'number': 2,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 22,
                'number': 3,
                'state': False
            }))

        wfs = helas_objects.HelasWavefunctionList(\
            [ helas_objects.HelasWavefunction(leg, 7,
                                              self.mybasemodel) \
              for leg in myleglist ])

        fortran_model = helas_call_writers.FortranHelasCallWriter()

        goal_counter = 0

        for wf in wfs:
            self.assertEqual(fortran_model.get_wavefunction_call(wf),
                             goal[goal_counter])
            goal_counter = goal_counter + 1

        for wf in wfs:
            mothers = copy.copy(wfs)
            mothers.remove(wf)
            wf.set('mothers', mothers)
            if not wf.get('self_antipart'):
                wf.flip_part_antipart()
            self.assertEqual(fortran_model.get_wavefunction_call(wf),
                             goal[goal_counter])
            if not wf.get('self_antipart'):
                wf.flip_part_antipart()
            goal_counter = goal_counter + 1

        amplitude = helas_objects.HelasAmplitude({\
            'mothers': wfs,
            'number': 1})
        amplitude.set('interaction_id', 7, self.mybasemodel)

        self.assertEqual(fortran_model.get_amplitude_call(amplitude),
                         goal[goal_counter])
        goal_counter = goal_counter + 1

        myleglist = base_objects.LegList()

        myleglist.append(
            base_objects.Leg({
                'id': 21,
                'number': 1,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 21,
                'number': 2,
                'state': False
            }))
        myleglist.append(
            base_objects.Leg({
                'id': 8000002,
                'number': 3,
                'state': False
            }))

        wfs = helas_objects.HelasWavefunctionList(\
            [ helas_objects.HelasWavefunction(leg, 5,
                                              self.mybasemodel) \
              for leg in myleglist ])

        fortran_model = helas_call_writers.FortranHelasCallWriter()

        for wf in wfs:
            self.assertEqual(fortran_model.get_wavefunction_call(wf),
                             goal[goal_counter])
            goal_counter = goal_counter + 1

        for wf in wfs:
            mothers = copy.copy(wfs)
            mothers.remove(wf)
            wf.set('mothers', mothers)
            self.assertEqual(fortran_model.get_wavefunction_call(wf),
                             goal[goal_counter])
            goal_counter = goal_counter + 1

        amplitude = helas_objects.HelasAmplitude({\
            'mothers': wfs,
            'number': 2})
        amplitude.set('interaction_id', 5, self.mybasemodel)
        self.assertEqual(fortran_model.get_amplitude_call(amplitude),
                         goal[goal_counter])
        goal_counter = goal_counter + 1