def generate(self, process, model, multiparticles=[]): """Create a process""" def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) interface = MGCmd.MasterCmd() interface.no_notification() # Select the Tensor Integral to include in the test misc.deactivate_dependence('pjfry', cmd = interface, log='stdout') misc.deactivate_dependence('samurai', cmd = interface, log='stdout') misc.activate_dependence('golem', cmd = interface, log='stdout') misc.activate_dependence('ninja', cmd = interface, log='stdout',MG5dir=MG5DIR) run_cmd('import model %s' % model) for multi in multiparticles: run_cmd('define %s' % multi) if isinstance(process, str): run_cmd('generate %s' % process) else: for p in process: run_cmd('add process %s' % p) files.rm(self.IOpath) run_cmd('output %s -f' % self.IOpath)
def setUp(self): self.tmp_process_dir = pjoin(_file_path, 'TMP_TestME7_colorful_epem_jjj_output') # Generate the process output if it does not exist yet or if we # are not in debug mode. if os.path.isdir(self.tmp_process_dir): if not self.is_process_generated and not self.debugging: shutil.rmtree(self.tmp_process_dir) else: TestME7_NLO_colorful_epem_jjj.is_process_generated = True if not self.is_process_generated: self.cmd = Cmd.MasterCmd() if os.path.isdir(self.tmp_process_dir): shutil.rmtree(self.tmp_process_dir) # Now generate and output a process, so as to run ME7 commands on it self.do('import model loop_sm') self.do('set subtraction_scheme colorful') self.do('generate e+ e- > j j j --NLO=QCD') self.do('output %s' % self.tmp_process_dir) TestME7_NLO_colorful_epem_jjj.is_process_generated = True if self.debugging: misc.sprint(debugging_warning) misc.sprint( debugging_written % (self.__class__.__name__, self.tmp_process_dir)) else: if self.debugging: misc.sprint(debugging_warning) misc.sprint( debugging_reused % (self.__class__.__name__, self.tmp_process_dir)) # Now initialize an ME7 interface on the above process output self.cmd = ME7_interface.MadEvent7Cmd(me_dir=self.tmp_process_dir) self.cmd.no_notification()
def setUp(self): """ Initialize the test """ self.interface = MGCmd.MasterCmd() self.interface.no_notification() # Below the key is the name of the logger and the value is a tuple with # first the handlers and second the level. self.logger_saved_info = {}
def testIO_TIR_output(self): """ target: [ggttx_IOTest/SubProcesses/(.*)\.f] """ interface = MGCmd.MasterCmd() interface.no_notification() def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) # Select the Tensor Integral to include in the test misc.deactivate_dependence('pjfry', cmd=interface, log='stdout') misc.deactivate_dependence('samurai', cmd=interface, log='stdout') misc.activate_dependence('golem', cmd=interface, log='stdout') misc.activate_dependence('ninja', cmd=interface, log='stdout', MG5dir=MG5DIR) run_cmd('generate g g > t t~ [virt=QCD]') interface.onecmd('output %s -f' % str(pjoin(self.IOpath, 'ggttx_IOTest')))
def test_InvalidCmd(self): """test that the Invalid Command are dealt with correctly""" master = cmd.MasterCmd() master.no_notification() self.assertRaises(master.InvalidCmd, master.do_generate, ('aa')) try: master.run_cmd('aa') except Exception as error: print(error) self.assertTrue(False, 'error are not treated correctly') # Madspin master = ms_cmd.MadSpinInterface() master.no_notification() self.assertRaises(Exception, master.do_define, ('aa')) with misc.MuteLogger(['fatalerror'], [40], ['/tmp/fatalerror.log'], keep=False): try: master.run_cmd('define aa') except Exception as error: self.assertTrue(False, 'error are not treated correctly: %s' % error) text = open('/tmp/fatalerror.log').read() self.assertTrue('{' not in text) self.assertTrue('MS_debug' in text)
def testIO_TIR_output(self): """ target: [ggttx_IOTest/SubProcesses/(.*)\.f] """ interface = MGCmd.MasterCmd() interface.no_notification() def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) # Select the Tensor Integral to include in the test misc.deactivate_dependence('pjfry', cmd=interface, log='stdout') misc.deactivate_dependence('samurai', cmd=interface, log='stdout') misc.activate_dependence('golem', cmd=interface, log='stdout') misc.activate_dependence('ninja', cmd=interface, log='stdout', MG5dir=MG5DIR) run_cmd('generate g g > t t~ [virt=QCD]') interface.onecmd('output %s -f' % str(pjoin(self.IOpath, 'ggttx_IOTest'))) #remove some function from some file: IOTests.IOTest.remove_f77_function_from_file( pjoin(self.IOpath, 'ggttx_IOTest', 'SubProcesses', 'MadLoopCommons.f'), 'PRINT_MADLOOP_BANNER')
def test_group_subprocess(self): """check that both u u > u u gives the same result""" mg_cmd = MGCmd.MasterCmd() mg_cmd.exec_cmd('set automatic_html_opening False --no_save') mg_cmd.exec_cmd(' generate u u > u u') mg_cmd.exec_cmd('output %s/'% self.run_dir) self.cmd_line = MECmd.MadEventCmdShell(me_dir= self.run_dir) self.cmd_line.exec_cmd('set automatic_html_opening False') self.do('generate_events -f') val1 = self.cmd_line.results.current['cross'] err1 = self.cmd_line.results.current['error'] self.run_dir = pjoin(self.path, 'MGPROC2') mg_cmd.exec_cmd('set group_subprocesses False') mg_cmd.exec_cmd('generate u u > u u') mg_cmd.exec_cmd('output %s' % self.run_dir) self.cmd_line = MECmd.MadEventCmdShell(me_dir= self.run_dir) self.cmd_line.exec_cmd('set automatic_html_opening False') self.do('generate_events -f') val2 = self.cmd_line.results.current['cross'] err2 = self.cmd_line.results.current['error'] self.assertTrue(abs(val2 - val1) / (err1 + err2) < 5) target = 1310200.0 self.assertTrue(abs(val2 - target) / (err2) < 5) #check precision self.assertTrue(err2 / val2 < 0.005) self.assertTrue(err1 / val1 < 0.005)
def __init__(self, event_path=None, *completekey, **stdin): """initialize the interface with potentially an event_path""" if not event_path: cmd_logger.info('************************************************************') cmd_logger.info('* *') cmd_logger.info('* Welcome to Reweight Module *') cmd_logger.info('* *') cmd_logger.info('************************************************************') extended_cmd.Cmd.__init__(self, *completekey, **stdin) self.model = None self.has_standalone_dir = False self.options = {'curr_dir': os.path.realpath(os.getcwd())} self.events_file = None self.processes = {} self.mg5cmd = master_interface.MasterCmd() self.seed = None if event_path: logger.info("Extracting the banner ...") self.do_import(event_path) # dictionary to fortan evaluator self.calculator = {} self.calculator_nbcall = {} #all the cross-section for convenience self.all_cross_section = {}
def create_MG5_process_dir(model, process, dir): """ create_MG5_process_dir(model, process, dir) Example: create_MG5_process_dir('MWT_MG', 'p p > z h', './samples/pp_zh_LO_MG5_242' ) """ # - Command line interface import madgraph.interface.master_interface as interface # - Logging - # import logging, logging.config import madgraph.interface.coloring_logging logging.config.fileConfig( os.path.join(MG5_root_dir, 'madgraph', 'interface', '.mg5_logging.conf')) logging.root.setLevel(logging.ERROR) logging.getLogger('madgraph').setLevel(logging.ERROR) logging.getLogger('madevent').setLevel(logging.ERROR) # - me5_configuration.txt me5_card_original_path = os.path.join('./mg5_cards/me5_configuration.txt') cmd_line = interface.MasterCmd() cmd_line.run_cmd('import {}'.format(model)) cmd_line.run_cmd('generate {}'.format(process)) cmd_line.run_cmd('output {}'.format(dir)) me5_card_path = os.path.join(dir, './Cards/me5_configuration.txt') shutil.copy2(me5_card_original_path, me5_card_path)
def test_w_nlo_gen_gosam(self): """check that the new generation mode works when gosam is set for p p > w [QCD] """ path = tempfile.mkdtemp('', 'TMPWTest', None) def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) interface = MGCmd.MasterCmd() try: run_cmd('set low_mem_multicore_nlo_generation True') run_cmd('set OLP GoSam') run_cmd('generate p p > w+ [QCD]') try: run_cmd('output %s' % os.path.join(path, 'W-newway')) except fks_common.FKSProcessError, err: # catch the error if gosam is not there if not 'Generation of the virtuals with GoSam failed' in str(err): raise Exception, err except Exception as e: run_cmd('set low_mem_multicore_nlo_generation False') run_cmd('set OLP MadLoop') raise e finally: run_cmd('set low_mem_multicore_nlo_generation False') run_cmd('set OLP MadLoop') shutil.rmtree(path)
def test_width_nlocomputation(self): """test the param_card created is correct""" cmd = os.getcwd() interface = MGCmd.MasterCmd() interface.no_notification() interface.exec_cmd("import model loop_qcd_qed_sm", errorhandling=False, printcmd=False, precmd=True, postcmd=False) interface.exec_cmd("compute_widths H Z W+ t --nlo --output=%s" % \ pjoin(self.path, "param_card.dat") , errorhandling=False, printcmd=False, precmd=True, postcmd=False) # test the param_card is correctly written self.assertTrue(os.path.exists('%s/param_card.dat' % self.path)) text = open('%s/param_card.dat' % self.path).read() pattern = re.compile(r"decay\s+23\s+([+-.\de]*)", re.I) value = float(pattern.search(text).group(1)) self.assertAlmostEqual(2.42823, value, delta=1e-3) pattern = re.compile(r"decay\s+24\s+([+-.\de]*)", re.I) value = float(pattern.search(text).group(1)) self.assertAlmostEqual(2.028440, value, delta=1e-3) pattern = re.compile(r"decay\s+25\s+([+-.\de]*)", re.I) value = float(pattern.search(text).group(1)) self.assertAlmostEqual(3.514960e-03, value, delta=1e-3) pattern = re.compile(r"decay\s+6\s+([+-.\de]*)", re.I) value = float(pattern.search(text).group(1)) self.assertAlmostEqual(1.354080, value, delta=5e-3)
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)
def test_e_e_collision(self): """check that e+ e- > t t~ gives the correct result""" mg_cmd = MGCmd.MasterCmd() mg_cmd.no_notification() mg_cmd.exec_cmd('set automatic_html_opening False --save') mg_cmd.exec_cmd(' generate e+ e- > e+ e-') mg_cmd.exec_cmd('output %s/' % self.run_dir) self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir) self.cmd_line.no_notification() # couple of test checking that default run_card is as expected run_card = banner.RunCardLO( pjoin(self.run_dir, 'Cards', 'run_card.dat')) self.assertFalse('ptj' in run_card.user_set) self.assertFalse('drjj' in run_card.user_set) self.assertFalse('ptj2min' in run_card.user_set) self.assertFalse('ptj3min' in run_card.user_set) self.assertFalse('mmjj' in run_card.user_set) self.assertFalse('ptheavy' in run_card.user_set) self.assertTrue('el' in run_card.user_set) self.assertTrue('polbeam1' in run_card.user_set) self.assertTrue('ptl' in run_card.user_set) shutil.copy(os.path.join(_file_path, 'input_files', 'run_card_ee.dat'), '%s/Cards/run_card.dat' % self.run_dir) self.do('generate_events -f') val1 = self.cmd_line.results.current['cross'] err1 = self.cmd_line.results.current['error'] target = 155.9 self.assertTrue(abs(val1 - target) / err1 < 2.)
def generate(self, process, model): """Create a process""" try: shutil.rmtree(self.run_dir) except Exception as error: pass interface = MGCmd.MasterCmd() interface.no_notification() interface.run_cmd('import model %s' % model) if isinstance(process, str): interface.run_cmd('generate %s' % process) else: for p in process: interface.run_cmd('add process %s' % p) if logging.getLogger('madgraph').level <= 20: stdout = None stderr = None else: devnull = open(os.devnull, 'w') stdout = devnull stderr = devnull if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')): print("install pythia-pgs") p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')], stdin=subprocess.PIPE, stdout=stdout, stderr=stderr) out = p.communicate('install pythia-pgs'.encode()) misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs')) if not os.path.exists(pjoin(MG5DIR, 'MadAnalysis')): print("install MadAnalysis") p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')], stdin=subprocess.PIPE, stdout=stdout, stderr=stderr) out = p.communicate('install MadAnalysis4'.encode()) misc.compile(cwd=pjoin(MG5DIR, 'MadAnalysis')) if not misc.which('root'): raise Exception('root is require for this test') interface.exec_cmd('set pythia-pgs_path %s --no_save' % pjoin(MG5DIR, 'pythia-pgs')) interface.exec_cmd('set madanalysis_path %s --no_save' % pjoin(MG5DIR, 'MadAnalysis')) interface.onecmd('output madevent %s -f' % self.run_dir) if os.path.exists(pjoin(interface.options['syscalc_path'], 'sys_calc')): shutil.rmtree(interface.options['syscalc_path']) #print "install SysCalc" #interface.onecmd('install SysCalc') self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir) self.cmd_line.no_notification() self.cmd_line.options['syscalc_path'] = pjoin(MG5DIR, 'SysCalc')
def run(self, proc_list, model, orders={}, energy=1000): """Execute MG5 on the list of processes mentioned in proc_list, using the specified model, the specified maximal coupling orders and a certain energy for incoming particles (for decay, incoming particle is at rest). """ self.res_list = [] # ensure that to be void, and avoid pointer problem self.proc_list = proc_list self.model = model self.orders = orders self.energy = energy self.non_zero = 0 dir_name = os.path.join(self.mg4_path, self.temp_dir_name) # Create a proc_card.dat in the v5 format proc_card_location = os.path.join(self.mg4_path, 'proc_card_%s.dat' % \ self.temp_dir_name) proc_card_file = open(proc_card_location, 'w') proc_card_file.write( self.format_mg5_proc_card(proc_list, model, orders)) proc_card_file.close() logging.info("proc_card.dat file for %i processes successfully created in %s" % \ (len(proc_list), os.path.join(dir_name, 'Cards'))) # Run mg5 logging.info("Running mg5") proc_card = open(proc_card_location, 'r').read() new_proc_list = [] cmd = cmd_interface.MasterCmd() cmd.no_notification() for line in proc_card.split('\n'): try: cmd.exec_cmd(line, errorhandling=False) except MadGraph5Error: pass else: if line.startswith('add'): self.non_zero += 1 new_proc_list.append(line) if hasattr(self, 'store_proc_card'): self.new_proc_list = '\n'.join(new_proc_list) # Remove the temporary proc_card os.remove(proc_card_location) if self.non_zero: self.fix_energy_in_check(dir_name, energy) # Get the ME value for i, proc in enumerate(proc_list): value = self.get_me_value(proc, i) self.res_list.append(value) return self.res_list else: self.res_list = [((0.0, 0), [])] * len(proc_list) return self.res_list
class TestMECmdShell(unittest.TestCase): """this treats all the command not related to MG_ME""" loadtime = time.time() def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='amc') self.tmpdir = "/tmp/" # if we need to keep the directory for testing purpose #if os.path.exists(self.tmpdir): # shutil.rmtree(self.tmpdir) #os.mkdir(self.tmpdir) self.path = pjoin(self.tmpdir, 'MGProcess') def tearDown(self): pass #shutil.rmtree(self.tmpdir) def generate(self, process, model, multiparticles=[]): """Create a process""" def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) try: shutil.rmtree(self.path) except Exception, error: pass interface = MGCmd.MasterCmd() run_cmd('import model %s' % model) for multi in multiparticles: run_cmd('define %s' % multi) if isinstance(process, str): run_cmd('generate %s' % process) else: for p in process: run_cmd('add process %s' % p) if logging.getLogger('madgraph').level <= 20: stdout = None stderr = None #else: # devnull =open(os.devnull,'w') # stdout=devnull # stderr=devnull interface.onecmd('output %s -f' % self.path) proc_card = open('%s/Cards/proc_card_mg5.dat' % self.path).read() self.assertTrue('generate' in proc_card or 'add process' in proc_card) run_cmd('set automatic_html_opening False --no_save') self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir='%s' % self.path) self.cmd_line.run_cmd('set automatic_html_opening False --no_save') self.assertFalse(self.cmd_line.options['automatic_html_opening'])
def __init__(self, model): self.model = model self.cmd = cmd_interface.MasterCmd() self.cmd.exec_cmd('set automatic_html_opening False') self.cmd.exec_cmd('import model %s --modelname' % model, precmd=True) self.cmd._curr_model = import_ufo.import_model(model, decay=True) self.particles_id = dict([(p.get('name'), p.get('pdg_code')) for p in self.cmd._curr_model.get('particles')])
def test_InvalidCmd(self): """test that the Invalid Command are dealt with correctly""" master = cmd.MasterCmd() self.assertRaises(master.InvalidCmd, master.do_generate, ('aa')) try: master.run_cmd('aa') except Exception, error: print error self.assertTrue(False, 'error are not treated correctly')
def setUp(self): if not hasattr(UFOParserTest, 'model'): self.cmd = Cmd.MasterCmd() self.cmd.exec_cmd("import model loop_qcd_qed_sm") UFOParserTest.model = self.cmd._curr_model if not hasattr(self, 'calc'): self.calc = parsers.UFOExpressionParserFortran(UFOParserTest.model) if not hasattr(self, 'mp_calc'): self.mp_calc = parsers.UFOExpressionParserMPFortran( UFOParserTest.model)
def setUp(self): """ Initialize the test """ self.interface = MGCmd.MasterCmd() self.interface.no_notification() # Below the key is the name of the logger and the value is a tuple with # first the handlers and second the level. self.logger_saved_info = {} # Select the Tensor Integral to include in the test misc.deactivate_dependence('pjfry', cmd=self.interface, log='stdout') misc.activate_dependence('golem', cmd=self.interface, log='stdout')
def __init__(self): """ launch all the compilation """ self.make_UFO_pkl() self.make_v4_pkl() self.make_stdHep() self.make_CutTools() self.make_IREGI() #important for UCL cluster files.cp(pjoin(MG5DIR, 'input', '.mg5_configuration_default.txt'), pjoin(MG5DIR, 'input', 'mg5_configuration.txt')) self.cmd = interface.MasterCmd() self.install_package()
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]))
def test_w_nlo_gen(self): """check that the new (memory and cpu efficient) and old generation mode at NLO give the same results for p p > w [QCD] """ path = tempfile.mkdtemp('', 'TMPWTest', None) def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) interface = MGCmd.MasterCmd() run_cmd('generate p p > w+ [QCD]') run_cmd('output %s' % os.path.join(path, 'W-oldway')) run_cmd('set low_mem_multicore_nlo_generation True') run_cmd('generate p p > w+ [QCD]') run_cmd('output %s' % os.path.join(path, 'W-newway')) run_cmd('set low_mem_multicore_nlo_generation False') # the P0 dirs for oldf in \ (glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', '*.inc')) + \ glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', '*.f')) + \ [os.path.join(path, 'W-oldway', 'SubProcesses', 'proc_characteristics')]): if os.path.islink(oldf): continue newf = oldf.replace('oldway', 'newway') for old_l, new_l in zip(open(oldf), open(newf)): self.assertEqual(old_l, new_l) # the V0 dirs for oldf in \ (glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', 'V0*', '*.inc')) + \ glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', 'V0*', '*.f'))): if os.path.islink(oldf): continue newf = oldf.replace('oldway', 'newway') for old_l, new_l in zip(open(oldf), open(newf)): self.assertEqual(old_l, new_l)
def test_complex_mass_scheme(self): """check that auto-width and Madspin works nicely with complex-mass-scheme""" mg_cmd = MGCmd.MasterCmd() mg_cmd.no_notification() mg_cmd.exec_cmd('set automatic_html_opening False --save') mg_cmd.exec_cmd('set complex_mass_scheme', precmd=True) mg_cmd.exec_cmd('generate g g > t t~', precmd=True) mg_cmd.exec_cmd('output %s' % self.run_dir, precmd=True) self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir) self.cmd_line.no_notification() self.cmd_line.exec_cmd('set automatic_html_opening False') #modify run_card run_card = banner_mod.RunCard( pjoin(self.run_dir, 'Cards', 'run_card.dat')) run_card.set('nevents', 100) run_card.write(pjoin(self.run_dir, 'Cards', 'run_card.dat')) # check the auto-width self.cmd_line.exec_cmd('compute_widths 6 -f') # check value for the width import models.check_param_card as check_param_card param_card = check_param_card.ParamCard( pjoin(self.run_dir, 'Cards', 'param_card.dat')) self.assertTrue(misc.equal(1.491257, param_card['decay'].get(6).value), 3) # generate events self.cmd_line.exec_cmd('launch -f') val1 = self.cmd_line.results.current['cross'] err1 = self.cmd_line.results.current['error'] target = 440.779 self.assertTrue(misc.equal(target, val1, 4 * err1)) # run madspin fsock = open(pjoin(self.run_dir, 'Cards', 'madspin_card.dat'), 'w') fsock.write('decay t > w+ b \n launch') fsock.close() self.cmd_line.exec_cmd('decay_events run_01 -f') val1 = self.cmd_line.results.current['cross'] err1 = self.cmd_line.results.current['error'] target = 440.779 self.assertTrue(misc.equal(target, val1, 4 * err1))
def __init__(self, event_path=None, *completekey, **stdin): """initialize the interface with potentially an event_path""" cmd_logger.info( '************************************************************') cmd_logger.info( '* *') cmd_logger.info( '* W E L C O M E to M A D S P I N *') cmd_logger.info( '* *') cmd_logger.info( '************************************************************') extended_cmd.Cmd.__init__(self, *completekey, **stdin) self.decay = madspin.decay_misc() self.model = None self.mode = "madspin" # can be flat/bridge change the way the decay is done. # note amc@nlo does not support bridge. self.options = { 'max_weight': -1, 'curr_dir': os.path.realpath(os.getcwd()), 'Nevents_for_max_weigth': 0, 'max_weight_ps_point': 400, 'BW_cut': -1, 'nb_sigma': 0, 'ms_dir': None, 'max_running_process': 100, 'onlyhelicity': False, 'spinmode': "madspin", 'use_old_dir': False, #should be use only for faster debugging 'run_card': None # define cut for spinmode==none. } self.events_file = None self.decay_processes = {} self.list_branches = {} self.to_decay = {} self.mg5cmd = master_interface.MasterCmd() self.seed = None self.err_branching_ratio = 0 if event_path: logger.info("Extracting the banner ...") self.do_import(event_path)
def generate(self, process, model): """Create a process""" try: shutil.rmtree('/tmp/MGPROCESS/') except Exception as error: pass interface = MGCmd.MasterCmd() interface.no_notification() interface.onecmd('import model %s' % model) if isinstance(process, str): interface.onecmd('generate %s' % process) else: for p in process: interface.onecmd('add process %s' % p) interface.onecmd('output madevent /tmp/MGPROCESS/ -f')
class Testmadweight(unittest.TestCase): """ check if the ValidCmd works correctly """ def generate(self, process, model): """Create a process""" try: shutil.rmtree('/tmp/MGPROCESS/') except Exception, error: pass interface = MGCmd.MasterCmd() interface.onecmd('import model %s' % model) if isinstance(process, str): interface.onecmd('generate %s' % process) else: for p in process: interface.onecmd('add process %s' % p) interface.onecmd('output madweight /tmp/MGPROCESS/ -f')
def test_e_e_collision(self): """check that e+ e- > t t~ gives the correct result""" mg_cmd = MGCmd.MasterCmd() mg_cmd.exec_cmd('set automatic_html_opening False --save') mg_cmd.exec_cmd(' generate e+ e- > e+ e-') mg_cmd.exec_cmd('output %s/' % self.run_dir) self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir) self.cmd_line.exec_cmd('set automatic_html_opening False') shutil.copy(os.path.join(_file_path, 'input_files', 'run_card_ee.dat'), '%s/Cards/run_card.dat' % self.run_dir) self.do('generate_events -f') val1 = self.cmd_line.results.current['cross'] err1 = self.cmd_line.results.current['error'] target = 155.9 self.assertTrue(abs(val1 - target) / err1 < 1.)
class TestMEfromPdirectory(unittest.TestCase): """test that we can launch everything from the P directory""" def generate(self, process, model): """Create a process""" try: shutil.rmtree('/tmp/MGPROCESS/') except Exception, error: pass interface = MGCmd.MasterCmd() interface.no_notification() interface.onecmd('import model %s' % model) if isinstance(process, str): interface.onecmd('generate %s' % process) else: for p in process: interface.onecmd('add process %s' % p) interface.onecmd('output madevent /tmp/MGPROCESS/ -f')
def generate(self, process, model, multiparticles=[]): """Create a process""" def run_cmd(cmd): interface.exec_cmd(cmd, errorhandling=False, printcmd=False, precmd=True, postcmd=True) interface = MGCmd.MasterCmd() run_cmd('import model %s' % model) for multi in multiparticles: run_cmd('define %s' % multi) if isinstance(process, str): run_cmd('generate %s' % process) else: for p in process: run_cmd('add process %s' % p) files.rm(self.IOpath) run_cmd('output %s -f' % self.IOpath)