~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to tests/unit_tests/core/test_base_objects.py

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
################################################################################
2
2
#
3
 
# Copyright (c) 2009 The MadGraph Development team and Contributors
 
3
# Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors
4
4
#
5
 
# This file is a part of the MadGraph 5 project, an application which 
 
5
# This file is a part of the MadGraph5_aMC@NLO project, an application which 
6
6
# automatically generates Feynman diagrams and matrix elements for arbitrary
7
7
# high-energy processes in the Standard Model and beyond.
8
8
#
9
 
# It is subject to the MadGraph license which should accompany this 
 
9
# It is subject to the MadGraph5_aMC@NLO license which should accompany this 
10
10
# distribution.
11
11
#
12
 
# For more information, please visit: http://madgraph.phys.ucl.ac.be
 
12
# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
13
13
#
14
14
################################################################################
15
15
"""Unit test library for the various base objects of the core library"""
17
17
import copy
18
18
import os
19
19
 
20
 
 
21
20
import madgraph
22
21
import madgraph.core.base_objects as base_objects
23
22
import madgraph.core.color_algebra as color
47
46
                      'pdg_code':6,
48
47
                      'propagating':True,
49
48
                      'is_part':True,
 
49
                      'ghost':False,
 
50
                      'counterterm':{('QCD',((1,2),(3,4))):{0:'GC_0',-1:'GC_1'}},
50
51
                      'propagator':'',
51
52
                      'self_antipart':False}
52
53
 
164
165
        goal = goal + "    \'propagating\': True,\n"
165
166
        goal = goal + "    \'propagator\': '',\n"
166
167
        goal = goal + "    \'is_part\': True,\n"
167
 
        goal = goal + "    \'self_antipart\': False\n}"
 
168
        goal = goal + "    \'self_antipart\': False,\n"        
 
169
        goal = goal + "    \'ghost\': False,\n"
 
170
        goal = goal + "    \'counterterm\': {('QCD', ((1, 2), (3, 4))): {0: 'GC_0', -1: 'GC_1'}}\n}"
168
171
 
169
172
        self.assertEqual(goal.split('\n'), str(self.mypart).split('\n'))
170
173
 
273
276
                                    (0, 1):'g01',
274
277
                                    (1, 0):'g10',
275
278
                                    (1, 1):'g11'},
276
 
                       'orders':{'QCD':1, 'QED':1}}
 
279
                       'orders':{'QCD':1, 'QED':1},
 
280
                       'loop_particles':[[]],
 
281
                       'perturbation_type':'QCD',
 
282
                       'type':'base'}
277
283
 
278
284
        self.myinter = base_objects.Interaction(self.mydict)
279
285
 
284
290
 
285
291
        # First fill myinter2 it using set
286
292
        for prop in ['id', 'particles', 'color', 'lorentz', 'couplings',
287
 
                     'orders']:
 
293
                     'orders', 'type', 'loop_particles','perturbation_type']:
288
294
            myinter2.set(prop, self.mydict[prop])
289
295
 
290
296
        # Check equality between Interaction objects
373
379
        goal = goal + "    \'lorentz\': [\'L1\', \'L2\'],\n"
374
380
        goal = goal + "    \'couplings\': %s,\n" % \
375
381
                                    repr(self.myinter['couplings'])
376
 
        goal = goal + "    \'orders\': %s\n}" % repr(self.myinter['orders'])
 
382
        goal = goal + "    \'orders\': %s,\n" % repr(self.myinter['orders'])
 
383
        goal = goal + "    \'loop_particles\': [[]],\n"        
 
384
        goal = goal + "    \'type\': \'base\',\n"
 
385
        goal = goal + "    \'perturbation_type\': 'QCD'\n}"
377
386
 
378
387
        self.assertEqual(goal, str(self.myinter))
379
388
 
921
930
    def setUp(self):
922
931
        """ """
923
932
        import madgraph.interface.master_interface as Cmd
924
 
        cmd = Cmd.MasterCmd()
925
 
        cmd.do_load('model %s' % os.path.join(madgraph.MG5DIR, 'tests',
926
 
                                                        'input_files','sm.pkl'))
 
933
        cmd = Cmd.MasterCmd() 
 
934
        cmd.do_import('model sm')
927
935
        self.model = cmd._curr_model
928
936
        
929
937
    def test_change_to_complex_mass_scheme(self):
950
958
#                self.assertFalse(WW)
951
959
#            elif param.name == 'WW':
952
960
#                WW = param
953
 
#            else:
 
961
#            elif param.name == 'MW': 
954
962
#                MW = param
955
963
#                self.assertFalse(WW)
956
964
#                self.assertFalse(WComplex)
957
 
#        self.assertFalse(WW)
958
 
#        self.assertFalse(MW)
 
965
#        self.assertTrue(WW)
 
966
#        self.assertTrue(MW)
959
967
#        self.assertTrue(WComplex)
960
968
#        # Check that WW and MW are the real/imaginary part
961
969
#        self.assertEqual(WW.expr, '-1 * im(CMASS_MW**2) / MW')
962
 
#        self.assertEqual('cmath.sqrt(re(%s**2))' % WComplex.expr, MW.expr)
 
970
#        self.assertEqual(['cmath.sqrt(re(%s**2))' % WComplex.expr], [MW.expr])
963
971
        
964
972
        # Check that MZ has a complex_mass definition
965
973
        # and that the width and the mass are external
999
1007
                      'number':5,
1000
1008
                      'state':True,
1001
1009
                      'from_group':False,
1002
 
                      'onshell':None}
 
1010
                      'onshell':None,                       
 
1011
                      'loop_line':False}
1003
1012
 
1004
1013
        self.myleg = base_objects.Leg(self.mydict)
1005
1014
 
1078
1087
        goal = goal + "    \'id\': 3,\n"
1079
1088
        goal = goal + "    \'number\': 5,\n"
1080
1089
        goal = goal + "    \'state\': True,\n"
1081
 
        goal = goal + "    \'from_group\': False,\n"
 
1090
        goal = goal + "    \'from_group\': False,\n" 
 
1091
        goal = goal + "    \'loop_line\': False,\n"
1082
1092
        goal = goal + "    \'onshell\': None\n}"
1083
1093
 
1084
1094
        self.assertEqual(goal, str(self.myleg))
1509
1519
                       'forbidden_s_channels':[],
1510
1520
                       'forbidden_onsh_s_channels':[],
1511
1521
                       'forbidden_particles':[],
 
1522
                       'perturbation_couplings':[],
1512
1523
                       'is_decay_chain': False,
1513
1524
                       'decay_chains': base_objects.ProcessList(),
1514
1525
                       'legs_with_decays': self.myleglist,
1515
 
                       'overall_orders': {}}
 
1526
                       'squared_orders': {},
 
1527
                       'has_born': True,
 
1528
                       'overall_orders': {},
 
1529
                       'NLO_mode':'tree'}
1516
1530
 
1517
1531
        self.myprocess = base_objects.Process(self.mydict)
1518
1532
 
1585
1599
        goal = goal + "    \'orders\': %s,\n" % repr(self.myprocess['orders'])
1586
1600
        goal = goal + "    \'overall_orders\': %s,\n" % \
1587
1601
               repr(self.myprocess['overall_orders'])
 
1602
        goal = goal + "    \'squared_orders\': %s,\n" % repr(self.myprocess['squared_orders'])
1588
1603
        goal = goal + "    \'model\': %s,\n" % repr(self.myprocess['model'])
1589
1604
        goal = goal + "    \'id\': 1,\n"
1590
1605
        goal = goal + "    \'required_s_channels\': [],\n"
1593
1608
        goal = goal + "    \'forbidden_particles\': [],\n"
1594
1609
        goal = goal + "    \'is_decay_chain\': False,\n"
1595
1610
        goal = goal + "    \'decay_chains\': [],\n"
1596
 
        goal = goal + "    \'legs_with_decays\': %s\n}" % repr(self.myleglist)
 
1611
        goal = goal + "    \'legs_with_decays\': %s,\n" % repr(self.myleglist)
 
1612
        goal = goal + "    \'perturbation_couplings\': [],\n"
 
1613
        goal = goal + "    \'has_born\': True,\n"
 
1614
        goal = goal + "    \'NLO_mode\': 'tree'\n}"
1597
1615
 
 
1616
        for a, b in zip(goal.split('\n'), str(self.myprocess).split('\n')):
 
1617
            self.assertEqual(a,b)
1598
1618
        self.assertEqual(goal, str(self.myprocess))
1599
1619
 
1600
1620
    def test_nice_string(self):
1601
1621
        """Test Process nice_string representation"""
1602
1622
 
1603
 
        goal_str = "Process: c c > c c c QCD=5 QED=1 @1"
 
1623
        goal_str = "Process: c c > c c c QED=1 QCD=5 @1"
1604
1624
 
1605
1625
        self.assertEqual(goal_str, self.myprocess.nice_string())
1606
1626
 
1607
1627
    def test_input_string(self):
1608
1628
        """Test Process nice_string representation"""
1609
1629
 
1610
 
        goal_str = "c c > c c c QCD=5 QED=1, (c > c c c c, c > c c c c)"
 
1630
        goal_str = "c c > c c c QED=1 QCD=5, (c > c c c c, c > c c c c)"
1611
1631
 
1612
1632
        decay = copy.copy(self.myprocess)
1613
1633
        decay.set('legs', copy.deepcopy(decay.get('legs')))
1655
1675
        self.assertTrue(len(self.myprocess.shell_string()) < 70)
1656
1676
        self.assertEqual(goal_str, self.myprocess.shell_string())
1657
1677
        
 
1678
    def test_get_final_ids_after_decay(self):
 
1679
        """check that we get the correct ids and in the correct order"""
 
1680
        
 
1681
        mymodel = base_objects.Model()
 
1682
        mypartlist = base_objects.ParticleList([
 
1683
                     base_objects.Particle({'name':'c',
 
1684
                                             'antiname':'c~',
 
1685
                                             'pdg_code':3}),
 
1686
                     base_objects.Particle({'name':'l',
 
1687
                                             'antiname':'l~',
 
1688
                                             'pdg_code':11}),
 
1689
                     base_objects.Particle({'name':'H',
 
1690
                                             'antiname':'H',
 
1691
                                             'pdg_code':25}),                                                                                                
 
1692
                                                ])
 
1693
        
 
1694
        mymodel.set('particles', mypartlist)
 
1695
 
 
1696
        # Check for c c~ > h c, h > l l~
 
1697
 
 
1698
        myleglist = base_objects.LegList(\
 
1699
            [base_objects.Leg({'id':3,
 
1700
                                         'number':1,
 
1701
                                         'state':False,
 
1702
                                         'from_group':False}),
 
1703
             base_objects.Leg({'id':3,
 
1704
                                         'number':2,
 
1705
                                         'state':False,
 
1706
                                         'from_group':False}),
 
1707
             base_objects.Leg({'id':25,
 
1708
                                         'number':3,
 
1709
                                         'state':True,
 
1710
                                         'from_group':False}),
 
1711
             base_objects.Leg({'id':3,
 
1712
                                         'number':4,
 
1713
                                         'state':True,
 
1714
                                         'from_group':False})])
 
1715
 
 
1716
        mylegdecay = base_objects.LegList(\
 
1717
            [base_objects.Leg({'id':25,
 
1718
                                         'number':1,
 
1719
                                         'state':False,
 
1720
                                         'from_group':False}),
 
1721
             base_objects.Leg({'id':11,
 
1722
                                         'number':2,
 
1723
                                         'state':True,
 
1724
                                         'from_group':False}),
 
1725
             base_objects.Leg({'id':-11,
 
1726
                                         'number':3,
 
1727
                                         'state':True,
 
1728
                                         'from_group':False})])
 
1729
        
 
1730
        mydecay = {'legs':mylegdecay,
 
1731
                  'orders':{'QCD':5, 'QED':1},
 
1732
                  'model':mymodel,
 
1733
                  'id': 1,
 
1734
                  'uid':0,
 
1735
                       'required_s_channels':[],
 
1736
                       'forbidden_s_channels':[],
 
1737
                       'forbidden_onsh_s_channels':[],
 
1738
                       'forbidden_particles':[],
 
1739
                       'perturbation_couplings':[],
 
1740
                       'is_decay_chain': False,
 
1741
                       'decay_chains': base_objects.ProcessList(),
 
1742
                       'legs_with_decays': [],
 
1743
                       'squared_orders': {},
 
1744
                       'has_born': True,
 
1745
                       'overall_orders': {},
 
1746
                       'NLO_mode':'tree'}
 
1747
            
 
1748
 
 
1749
        mydecay = base_objects.Process(mydecay)
 
1750
        
 
1751
        myprocess = copy.copy(mydecay)
 
1752
        myprocess['legs'] = myleglist
 
1753
        myprocess['is_decay_chain'] = True
 
1754
        proclist = base_objects.ProcessList()
 
1755
        proclist.append(mydecay)
 
1756
        myprocess['decay_chains'] = proclist
 
1757
        
 
1758
        # checking
 
1759
        output = myprocess.get_final_ids_after_decay()
 
1760
        self.assertEqual(output, [11, -11, 3])
 
1761
        
 
1762
        ## c c~ > c h c~ h c, h > l l, h > l~ l~ 
 
1763
        myleglist = base_objects.LegList(\
 
1764
            [base_objects.Leg({'id':3,
 
1765
                                         'number':1,
 
1766
                                         'state':False,
 
1767
                                         'from_group':False}),
 
1768
             base_objects.Leg({'id':-3,
 
1769
                                         'number':2,
 
1770
                                         'state':False,
 
1771
                                         'from_group':False}),
 
1772
             base_objects.Leg({'id':3,
 
1773
                                         'number':3,
 
1774
                                         'state':True,
 
1775
                                         'from_group':False}),
 
1776
             base_objects.Leg({'id':25,
 
1777
                                         'number':4,
 
1778
                                         'state':True,
 
1779
                                         'from_group':False}),
 
1780
            base_objects.Leg({'id':-3,
 
1781
                                         'number':3,
 
1782
                                         'state':True,
 
1783
                                         'from_group':False}),
 
1784
             base_objects.Leg({'id':25,
 
1785
                                         'number':4,
 
1786
                                         'state':True,
 
1787
                                         'from_group':False}),
 
1788
              base_objects.Leg({'id':3,
 
1789
                                         'number':3,
 
1790
                                         'state':True,
 
1791
                                         'from_group':False})])
 
1792
 
 
1793
        mylegdecay = base_objects.LegList(\
 
1794
            [base_objects.Leg({'id':25,
 
1795
                                         'number':1,
 
1796
                                         'state':False,
 
1797
                                         'from_group':False}),
 
1798
             base_objects.Leg({'id':11,
 
1799
                                         'number':2,
 
1800
                                         'state':True,
 
1801
                                         'from_group':False}),
 
1802
             base_objects.Leg({'id':11,
 
1803
                                         'number':3,
 
1804
                                         'state':True,
 
1805
                                         'from_group':False})])        
 
1806
        mydecay['legs'] = mylegdecay
 
1807
        
 
1808
        mylegdecay2 = base_objects.LegList(\
 
1809
            [base_objects.Leg({'id':25,
 
1810
                                         'number':1,
 
1811
                                         'state':False,
 
1812
                                         'from_group':False}),
 
1813
             base_objects.Leg({'id':-11,
 
1814
                                         'number':2,
 
1815
                                         'state':True,
 
1816
                                         'from_group':False}),
 
1817
             base_objects.Leg({'id':-11,
 
1818
                                         'number':3,
 
1819
                                         'state':True,
 
1820
                                         'from_group':False})]) 
 
1821
        mydecay2 = copy.copy(mydecay)
 
1822
        mydecay2['legs'] = mylegdecay2
 
1823
        
 
1824
        
 
1825
        myprocess['legs'] = myleglist
 
1826
        myprocess['is_decay_chain'] = True
 
1827
        proclist = base_objects.ProcessList()
 
1828
        proclist.append(mydecay)
 
1829
        proclist.append(mydecay2)
 
1830
        myprocess['decay_chains'] = proclist       
 
1831
        # checking
 
1832
        output = myprocess.get_final_ids_after_decay()
 
1833
        self.assertEqual(output, [3, 11, 11, -3,-11,-11,3])
 
1834
        
1658
1835
#===============================================================================
1659
1836
# ProcessDefinitionTest
1660
1837
#===============================================================================
1692
1869
                       'forbidden_s_channels':[],
1693
1870
                       'forbidden_onsh_s_channels':[],
1694
1871
                       'forbidden_particles':[],
 
1872
                       'perturbation_couplings':[],
1695
1873
                       'is_decay_chain': False,
1696
1874
                       'decay_chains': base_objects.ProcessList(),
1697
 
                       'overall_orders':{}}
 
1875
                       'squared_orders':{},
 
1876
                       'has_born': True,
 
1877
                       'overall_orders':{},
 
1878
                       'NLO_mode':'tree'}
1698
1879
 
1699
1880
        self.my_process_definition = base_objects.ProcessDefinition(self.mydict)
1700
1881
 
1766
1947
        goal = goal + "    \'legs\': %s,\n" % repr(self.my_multi_leglist)
1767
1948
        goal = goal + "    \'orders\': %s,\n" % repr(self.my_process_definition['orders'])
1768
1949
        goal = goal + "    \'overall_orders\': %s,\n" % repr(self.my_process_definition['overall_orders'])
 
1950
        goal = goal + "    \'squared_orders\': %s,\n" % repr(self.my_process_definition['squared_orders'])
1769
1951
        goal = goal + "    \'model\': %s,\n" % repr(self.my_process_definition['model'])
1770
1952
        goal = goal + "    \'id\': %s,\n" % repr(self.my_process_definition['id'])
1771
1953
        goal = goal + "    \'required_s_channels\': [],\n"
1773
1955
        goal = goal + "    \'forbidden_s_channels\': [],\n"
1774
1956
        goal = goal + "    \'forbidden_particles\': [],\n"
1775
1957
        goal = goal + "    \'is_decay_chain\': False,\n"
1776
 
        goal = goal + "    \'decay_chains\': []\n}"
 
1958
        goal = goal + "    \'decay_chains\': [],\n"
 
1959
        goal = goal + "    \'perturbation_couplings\': [],\n"
 
1960
        goal = goal + "    \'has_born\': True,\n"
 
1961
        goal = goal + "    \'NLO_mode\': 'tree'\n}"        
1777
1962
        self.assertEqual(goal, str(self.my_process_definition))
1778
1963
 
1779
1964
#===============================================================================