1
################################################################################
3
# Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors
5
# This file is a part of the MadGraph5_aMC@NLO project, an application which
6
# automatically generates Feynman diagrams and matrix elements for arbitrary
7
# high-energy processes in the Standard Model and beyond.
9
# It is subject to the MadGraph5_aMC@NLO license which should accompany this
12
# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
14
################################################################################
16
"""Unit test library for the spin correlated decay routines
17
in the madspin directory"""
25
from subprocess import Popen, PIPE, STDOUT
27
root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
28
sys.path.insert(0, os.path.join(root_path,'..','..'))
30
import tests.unit_tests as unittest
31
import madgraph.interface.master_interface as Cmd
32
import madgraph.various.banner as banner
37
import madgraph.core.base_objects as MG
38
import madgraph.various.misc as misc
39
import MadSpin.decay as madspin
40
import models.import_ufo as import_ufo
43
from madgraph import MG5DIR
45
class TestBanner(unittest.TestCase):
46
"""Test class for the reading of the banner"""
48
def test_extract_info(self):
49
"""Test that the banner is read properly"""
51
path=pjoin(MG5DIR, 'tests', 'input_files', 'tt_banner.txt')
52
inputfile = open(path, 'r')
53
mybanner = banner.Banner(inputfile)
54
# mybanner.ReadBannerFromFile()
55
process=mybanner.get("generate")
56
model=mybanner.get("model")
57
self.assertEqual(process,"p p > t t~ @1")
58
self.assertEqual(model,"sm")
61
def test_get_final_state_particle(self):
62
"""test that we find the final state particles correctly"""
66
fct = lambda x: cmd.get_final_part(x)
69
self.assertEqual(set([11, -11]), fct('p p > e+ e-'))
70
self.assertEqual(set([11, 24]), fct('p p > w+ e-'))
71
self.assertEqual(set([11, 24]), fct('p p > W+ e-'))
72
self.assertEqual(set([1, 2, 3, 4, -1, 11, 21, -4, -3, -2]), fct('p p > W+ e-, w+ > j j'))
73
self.assertEqual(fct('p p > t t~, (t > b w+, w+ > j j) ,t~ > b~ w-'), set([1, 2, 3, 4, -1, 21, -4, -3, -2,5,-5,-24]))
74
self.assertEqual(fct('e+ e- > all all, all > e+ e-'), set([-11,11]))
75
self.assertEqual(fct('e+ e- > j w+, j > e+ e-'), set([-11,11,24]))
77
class TestEvent(unittest.TestCase):
78
"""Test class for the reading of the lhe input file"""
81
def test_madspin_event(self):
82
"""check the reading/writting of the events inside MadSpin"""
84
inputfile = open(pjoin(MG5DIR, 'tests', 'input_files', 'madspin_event.lhe'))
86
events = madspin.Event(inputfile)
89
event = events.get_next_event()
90
self.assertEqual(event, 1)
92
self.assertEqual(event.string_event_compact(), """21 0.0 0.0 586.83954 586.84002 0.750577236977
93
21 0.0 0.0 -182.0876 182.08914 0.748887294316
94
6 197.60403 48.424858 76.818601 277.88922 173.00000459
95
-6 -212.77359 -34.669345 359.45458 453.44366 172.999981581
96
21 15.169561 -13.755513 -31.521232 37.59628 0.749989476383
99
self.assertEqual(event.get_tag(), (((21, 21), (-6, 6, 21)), [[21, 21], [6, -6, 21]]))
100
event.assign_scale_line("8 3 0.1 125 0.1 0.3")
101
event.change_wgt(factor=0.4)
103
self.assertEqual(event.string_event(), """<event>
104
8 3 +4.0000000e-02 1.25000000e+02 1.00000000e-01 3.00000000e-01
105
21 -1 0 0 503 502 +0.0000000e+00 +0.0000000e+00 +5.8683954e+02 5.86840020e+02 7.50000000e-01 0.0000e+00 0.0000e+00
106
21 -1 0 0 501 503 +0.0000000e+00 +0.0000000e+00 -1.8208760e+02 1.82089140e+02 7.50000000e-01 0.0000e+00 0.0000e+00
107
6 1 1 2 504 0 +1.9760403e+02 +4.8424858e+01 +7.6818601e+01 2.77889220e+02 1.73000000e+02 0.0000e+00 0.0000e+00
108
-6 1 1 2 0 502 -2.1277359e+02 -3.4669345e+01 +3.5945458e+02 4.53443660e+02 1.73000000e+02 0.0000e+00 0.0000e+00
109
21 1 1 2 501 504 +1.5169561e+01 -1.3755513e+01 -3.1521232e+01 3.75962800e+01 7.50000000e-01 0.0000e+00 0.0000e+00
110
#amcatnlo 2 5 3 3 1 0.45933500e+02 0.45933500e+02 9 0 0 0.99999999e+00 0.69338413e+00 0.14872513e+01 0.00000000e+00 0.00000000e+00
112
<wgt id='1001'> +1.2946800e+02 </wgt>
113
<wgt id='1002'> +1.1581600e+02 </wgt>
114
<wgt id='1003'> +1.4560400e+02 </wgt>
115
<wgt id='1004'> +1.0034800e+02 </wgt>
116
<wgt id='1005'> +8.9768000e+01 </wgt>
117
<wgt id='1006'> +1.1285600e+02 </wgt>
118
<wgt id='1007'> +1.7120800e+02 </wgt>
119
<wgt id='1008'> +1.5316000e+02 </wgt>
120
<wgt id='1009'> +1.9254800e+02 </wgt>
126
event = events.get_next_event()
127
self.assertEqual(event, 1)
129
self.assertEqual(event.get_tag(), (((21, 21), (-6, 6, 21)), [[21, 21], [6, 21, -6]]))
130
self.assertEqual(event.string_event(), """<event>
131
5 66 +3.2366351e+02 4.39615290e+02 7.54677160e-03 1.02860750e-01
132
21 -1 0 0 503 502 +0.0000000e+00 +0.0000000e+00 +1.2058224e+03 1.20582260e+03 7.50000000e-01 0.0000e+00 0.0000e+00
133
21 -1 0 0 501 503 +0.0000000e+00 +0.0000000e+00 -5.4683611e+01 5.46887540e+01 7.50000000e-01 0.0000e+00 0.0000e+00
134
6 1 1 2 501 0 -4.0378655e+01 -1.4192432e+02 +3.6608998e+02 4.30956860e+02 1.73000000e+02 0.0000e+00 0.0000e+00
135
21 1 1 2 504 502 -2.4671645e+01 +3.9837121e+01 +2.4992426e+02 2.54280130e+02 7.50000000e-01 0.0000e+00 0.0000e+00
136
-6 1 1 2 0 504 +6.5050300e+01 +1.0208720e+02 +5.3512451e+02 5.75274350e+02 1.73000000e+02 0.0000e+00 0.0000e+00
137
#amcatnlo 2 5 4 4 4 0.40498390e+02 0.40498390e+02 9 0 0 0.99999997e+00 0.68201705e+00 0.15135239e+01 0.00000000e+00 0.00000000e+00
140
<scale> even more infor
146
<wgt id='1001'> 0.32367e+03 </wgt>
147
<wgt id='1002'> 0.28621e+03 </wgt>
148
<wgt id='1003'> 0.36822e+03 </wgt>
149
<wgt id='1004'> 0.24963e+03 </wgt>
150
<wgt id='1005'> 0.22075e+03 </wgt>
151
<wgt id='1006'> 0.28400e+03 </wgt>
152
<wgt id='1007'> 0.43059e+03 </wgt>
153
<wgt id='1008'> 0.38076e+03 </wgt>
154
<wgt id='1009'> 0.48987e+03 </wgt>
159
# Third event ! Not existing
160
event = events.get_next_event()
161
self.assertEqual(event, "no_event")
166
#class Testtopo(unittest.TestCase):
167
# """Test the extraction of the topologies for the undecayed process"""
169
# def test_topottx(self):
171
# os.environ['GFORTRAN_UNBUFFERED_ALL']='y'
172
# path_for_me=pjoin(MG5DIR, 'tests','unit_tests','madspin')
173
# shutil.copyfile(pjoin(MG5DIR, 'tests','input_files','param_card_sm.dat'),\
174
# pjoin(path_for_me,'param_card.dat'))
175
# curr_dir=os.getcwd()
177
# temp_dir=os.getcwd()
178
# mgcmd=Cmd.MasterCmd()
179
# process_prod=" g g > t t~ "
180
# process_full=process_prod+", ( t > b w+ , w+ > mu+ vm ), "
181
# process_full+="( t~ > b~ w- , w- > mu- vm~ ) "
182
# decay_tools=madspin.decay_misc()
183
# topo=decay_tools.generate_fortran_me([process_prod],"sm",0, mgcmd, path_for_me)
184
# decay_tools.generate_fortran_me([process_full],"sm", 1,mgcmd, path_for_me)
186
# prod_name=decay_tools.compile_fortran_me_production(path_for_me)
187
# decay_name = decay_tools.compile_fortran_me_full(path_for_me)
190
# topo_test={1: {'branchings': [{'index_propa': -1, 'type': 's',\
191
# 'index_d2': 3, 'index_d1': 4}], 'get_id': {}, 'get_momentum': {}, \
192
# 'get_mass2': {}}, 2: {'branchings': [{'index_propa': -1, 'type': 't', \
193
# 'index_d2': 3, 'index_d1': 1}, {'index_propa': -2, 'type': 't', 'index_d2': 4,\
194
# 'index_d1': -1}], 'get_id': {}, 'get_momentum': {}, 'get_mass2': {}}, \
195
# 3: {'branchings': [{'index_propa': -1, 'type': 't', 'index_d2': 4, \
196
# 'index_d1': 1}, {'index_propa': -2, 'type': 't', 'index_d2': 3, 'index_d1': -1}],\
197
# 'get_id': {}, 'get_momentum': {}, 'get_mass2': {}}}
199
# self.assertEqual(topo,topo_test)
202
# p_string='0.5000000E+03 0.0000000E+00 0.0000000E+00 0.5000000E+03 \n'
203
# p_string+='0.5000000E+03 0.0000000E+00 0.0000000E+00 -0.5000000E+03 \n'
204
# p_string+='0.5000000E+03 0.1040730E+03 0.4173556E+03 -0.1872274E+03 \n'
205
# p_string+='0.5000000E+03 -0.1040730E+03 -0.4173556E+03 0.1872274E+03 \n'
208
# os.chdir(pjoin(path_for_me,'production_me','SubProcesses',prod_name))
209
# executable_prod="./check"
210
# external = Popen(executable_prod, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
212
# external.stdin.write(p_string)
214
# info = int(external.stdout.readline())
215
# nb_output = abs(info)+1
218
# prod_values = ' '.join([external.stdout.readline() for i in range(nb_output)])
220
# prod_values=prod_values.split()
221
# prod_values_test=['0.59366146660637686', '7.5713552297679376', '12.386583104018380', '34.882849897228873']
222
# self.assertEqual(prod_values,prod_values_test)
223
# external.terminate()
228
# p_string='0.5000000E+03 0.0000000E+00 0.0000000E+00 0.5000000E+03 \n'
229
# p_string+='0.5000000E+03 0.0000000E+00 0.0000000E+00 -0.5000000E+03 \n'
230
# p_string+='0.8564677E+02 -0.8220633E+01 0.3615807E+02 -0.7706033E+02 \n'
231
# p_string+='0.1814001E+03 -0.5785084E+02 -0.1718366E+03 -0.5610972E+01 \n'
232
# p_string+='0.8283621E+02 -0.6589913E+02 -0.4988733E+02 0.5513262E+01 \n'
233
# p_string+='0.3814391E+03 0.1901552E+03 0.2919968E+03 -0.1550888E+03 \n'
234
# p_string+='0.5422284E+02 -0.3112810E+02 -0.7926714E+01 0.4368438E+02\n'
235
# p_string+='0.2144550E+03 -0.2705652E+02 -0.9850424E+02 0.1885624E+03\n'
237
# os.chdir(pjoin(path_for_me,'full_me','SubProcesses',decay_name))
238
# executable_decay="./check"
239
# external = Popen(executable_decay, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
240
# external.stdin.write(p_string)
243
# decay_value = ' '.join([external.stdout.readline() for i in range(nb_output)])
245
# decay_value=decay_value.split()
246
# decay_value_test=['3.8420345719455465E-017']
247
# for i in range(len(decay_value)):
248
# self.assertAlmostEqual(eval(decay_value[i]),eval(decay_value_test[i]))
250
# external.terminate()
251
# shutil.rmtree(pjoin(path_for_me,'production_me'))
252
# shutil.rmtree(pjoin(path_for_me,'full_me'))
253
# os.remove(pjoin(path_for_me,'param_card.dat'))
254
# os.environ['GFORTRAN_UNBUFFERED_ALL']='n'