################################################################################ # # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors # # This file is a part of the MadGraph5_aMC@NLO project, an application which # automatically generates Feynman diagrams and matrix elements for arbitrary # high-energy processes in the Standard Model and beyond. # # It is subject to the MadGraph5_aMC@NLO license which should accompany this # distribution. # # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch # ################################################################################ """Unit test library for the spin correlated decay routines in the madspin directory""" import sys import os import string import shutil pjoin = os.path.join from subprocess import Popen, PIPE, STDOUT root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0] sys.path.insert(0, os.path.join(root_path,'..','..')) import tests.unit_tests as unittest import madgraph.interface.master_interface as Cmd import madgraph.various.banner as banner import copy import array import madgraph.core.base_objects as MG import madgraph.various.misc as misc import MadSpin.decay as madspin import models.import_ufo as import_ufo from madgraph import MG5DIR # class TestBanner(unittest.TestCase): """Test class for the reading of the banner""" def test_extract_info(self): """Test that the banner is read properly""" path=pjoin(MG5DIR, 'tests', 'input_files', 'tt_banner.txt') inputfile = open(path, 'r') mybanner = banner.Banner(inputfile) # mybanner.ReadBannerFromFile() process=mybanner.get("generate") model=mybanner.get("model") self.assertEqual(process,"p p > t t~ @1") self.assertEqual(model,"sm") def test_get_final_state_particle(self): """test that we find the final state particles correctly""" cmd = Cmd.MasterCmd() cmd.do_import('sm') fct = lambda x: cmd.get_final_part(x) # self.assertEqual(set([11, -11]), fct('p p > e+ e-')) self.assertEqual(set([11, 24]), fct('p p > w+ e-')) self.assertEqual(set([11, 24]), fct('p p > W+ e-')) self.assertEqual(set([1, 2, 3, 4, -1, 11, 21, -4, -3, -2]), fct('p p > W+ e-, w+ > j j')) 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])) self.assertEqual(fct('e+ e- > all all, all > e+ e-'), set([-11,11])) self.assertEqual(fct('e+ e- > j w+, j > e+ e-'), set([-11,11,24])) class TestEvent(unittest.TestCase): """Test class for the reading of the lhe input file""" def test_madspin_event(self): """check the reading/writting of the events inside MadSpin""" inputfile = open(pjoin(MG5DIR, 'tests', 'input_files', 'madspin_event.lhe')) events = madspin.Event(inputfile) # First event event = events.get_next_event() self.assertEqual(event, 1) event = events self.assertEqual(event.string_event_compact(), """21 0.0 0.0 586.83954 586.84002 0.750577236977 21 0.0 0.0 -182.0876 182.08914 0.748887294316 6 197.60403 48.424858 76.818601 277.88922 173.00000459 -6 -212.77359 -34.669345 359.45458 453.44366 172.999981581 21 15.169561 -13.755513 -31.521232 37.59628 0.749989476383 """) self.assertEqual(event.get_tag(), (((21, 21), (-6, 6, 21)), [[21, 21], [6, -6, 21]])) event.assign_scale_line("8 3 0.1 125 0.1 0.3") event.change_wgt(factor=0.4) self.assertEqual(event.string_event().split('\n'), """ 8 3 +4.0000000e-02 1.25000000e+02 1.00000000e-01 3.00000000e-01 21 -1 0 0 503 502 +0.00000000000e+00 +0.00000000000e+00 +5.86839540000e+02 5.86840020000e+02 7.50000000000e-01 0.0000e+00 0.0000e+00 21 -1 0 0 501 503 +0.00000000000e+00 +0.00000000000e+00 -1.82087600000e+02 1.82089140000e+02 7.50000000000e-01 0.0000e+00 0.0000e+00 6 1 1 2 504 0 +1.97604030000e+02 +4.84248580000e+01 +7.68186010000e+01 2.77889220000e+02 1.73000000000e+02 0.0000e+00 0.0000e+00 -6 1 1 2 0 502 -2.12773590000e+02 -3.46693450000e+01 +3.59454580000e+02 4.53443660000e+02 1.73000000000e+02 0.0000e+00 0.0000e+00 21 1 1 2 501 504 +1.51695610000e+01 -1.37555130000e+01 -3.15212320000e+01 3.75962800000e+01 7.50000000000e-01 0.0000e+00 0.0000e+00 #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 +1.2946800e+02 +1.1581600e+02 +1.4560400e+02 +1.0034800e+02 +8.9768000e+01 +1.1285600e+02 +1.7120800e+02 +1.5316000e+02 +1.9254800e+02 """.split('\n')) # Second event event = events.get_next_event() self.assertEqual(event, 1) event =events self.assertEqual(event.get_tag(), (((21, 21), (-6, 6, 21)), [[21, 21], [6, 21, -6]])) self.assertEqual(event.string_event().split('\n'), """ 5 66 +3.2366351e+02 4.39615290e+02 7.54677160e-03 1.02860750e-01 21 -1 0 0 503 502 +0.00000000000e+00 +0.00000000000e+00 +1.20582240000e+03 1.20582260000e+03 7.50000000000e-01 0.0000e+00 0.0000e+00 21 -1 0 0 501 503 +0.00000000000e+00 +0.00000000000e+00 -5.46836110000e+01 5.46887540000e+01 7.50000000000e-01 0.0000e+00 0.0000e+00 6 1 1 2 501 0 -4.03786550000e+01 -1.41924320000e+02 +3.66089980000e+02 4.30956860000e+02 1.73000000000e+02 0.0000e+00 0.0000e+00 21 1 1 2 504 502 -2.46716450000e+01 +3.98371210000e+01 +2.49924260000e+02 2.54280130000e+02 7.50000000000e-01 0.0000e+00 0.0000e+00 -6 1 1 2 0 504 +6.50503000000e+01 +1.02087200000e+02 +5.35124510000e+02 5.75274350000e+02 1.73000000000e+02 0.0000e+00 0.0000e+00 #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 some information even more infor blabla 0.32367e+03 0.28621e+03 0.36822e+03 0.24963e+03 0.22075e+03 0.28400e+03 0.43059e+03 0.38076e+03 0.48987e+03 """.split('\n')) # Third event ! Not existing event = events.get_next_event() self.assertEqual(event, "no_event") #class Testtopo(unittest.TestCase): # """Test the extraction of the topologies for the undecayed process""" # # def test_topottx(self): # # os.environ['GFORTRAN_UNBUFFERED_ALL']='y' # path_for_me=pjoin(MG5DIR, 'tests','unit_tests','madspin') # shutil.copyfile(pjoin(MG5DIR, 'tests','input_files','param_card_sm.dat'),\ # pjoin(path_for_me,'param_card.dat')) # curr_dir=os.getcwd() # os.chdir('/tmp') # temp_dir=os.getcwd() # mgcmd=Cmd.MasterCmd() # process_prod=" g g > t t~ " # process_full=process_prod+", ( t > b w+ , w+ > mu+ vm ), " # process_full+="( t~ > b~ w- , w- > mu- vm~ ) " # decay_tools=madspin.decay_misc() # topo=decay_tools.generate_fortran_me([process_prod],"sm",0, mgcmd, path_for_me) # decay_tools.generate_fortran_me([process_full],"sm", 1,mgcmd, path_for_me) # # prod_name=decay_tools.compile_fortran_me_production(path_for_me) # decay_name = decay_tools.compile_fortran_me_full(path_for_me) # # # topo_test={1: {'branchings': [{'index_propa': -1, 'type': 's',\ # 'index_d2': 3, 'index_d1': 4}], 'get_id': {}, 'get_momentum': {}, \ # 'get_mass2': {}}, 2: {'branchings': [{'index_propa': -1, 'type': 't', \ # 'index_d2': 3, 'index_d1': 1}, {'index_propa': -2, 'type': 't', 'index_d2': 4,\ # 'index_d1': -1}], 'get_id': {}, 'get_momentum': {}, 'get_mass2': {}}, \ # 3: {'branchings': [{'index_propa': -1, 'type': 't', 'index_d2': 4, \ # 'index_d1': 1}, {'index_propa': -2, 'type': 't', 'index_d2': 3, 'index_d1': -1}],\ # 'get_id': {}, 'get_momentum': {}, 'get_mass2': {}}} # # self.assertEqual(topo,topo_test) # # # p_string='0.5000000E+03 0.0000000E+00 0.0000000E+00 0.5000000E+03 \n' # p_string+='0.5000000E+03 0.0000000E+00 0.0000000E+00 -0.5000000E+03 \n' # p_string+='0.5000000E+03 0.1040730E+03 0.4173556E+03 -0.1872274E+03 \n' # p_string+='0.5000000E+03 -0.1040730E+03 -0.4173556E+03 0.1872274E+03 \n' # # # os.chdir(pjoin(path_for_me,'production_me','SubProcesses',prod_name)) # executable_prod="./check" # external = Popen(executable_prod, stdout=PIPE, stdin=PIPE, stderr=STDOUT) # # external.stdin.write(p_string) # # info = int(external.stdout.readline()) # nb_output = abs(info)+1 # # # prod_values = ' '.join([external.stdout.readline() for i in range(nb_output)]) # # prod_values=prod_values.split() # prod_values_test=['0.59366146660637686', '7.5713552297679376', '12.386583104018380', '34.882849897228873'] # self.assertEqual(prod_values,prod_values_test) # external.terminate() # # # os.chdir(temp_dir) # # p_string='0.5000000E+03 0.0000000E+00 0.0000000E+00 0.5000000E+03 \n' # p_string+='0.5000000E+03 0.0000000E+00 0.0000000E+00 -0.5000000E+03 \n' # p_string+='0.8564677E+02 -0.8220633E+01 0.3615807E+02 -0.7706033E+02 \n' # p_string+='0.1814001E+03 -0.5785084E+02 -0.1718366E+03 -0.5610972E+01 \n' # p_string+='0.8283621E+02 -0.6589913E+02 -0.4988733E+02 0.5513262E+01 \n' # p_string+='0.3814391E+03 0.1901552E+03 0.2919968E+03 -0.1550888E+03 \n' # p_string+='0.5422284E+02 -0.3112810E+02 -0.7926714E+01 0.4368438E+02\n' # p_string+='0.2144550E+03 -0.2705652E+02 -0.9850424E+02 0.1885624E+03\n' # # os.chdir(pjoin(path_for_me,'full_me','SubProcesses',decay_name)) # executable_decay="./check" # external = Popen(executable_decay, stdout=PIPE, stdin=PIPE, stderr=STDOUT) # external.stdin.write(p_string) # # nb_output =1 # decay_value = ' '.join([external.stdout.readline() for i in range(nb_output)]) # # decay_value=decay_value.split() # decay_value_test=['3.8420345719455465E-017'] # for i in range(len(decay_value)): # self.assertAlmostEqual(eval(decay_value[i]),eval(decay_value_test[i])) # os.chdir(curr_dir) # external.terminate() # shutil.rmtree(pjoin(path_for_me,'production_me')) # shutil.rmtree(pjoin(path_for_me,'full_me')) # os.remove(pjoin(path_for_me,'param_card.dat')) # os.environ['GFORTRAN_UNBUFFERED_ALL']='n'