def test_short_check_eejjj_lo_lhapdf(self): """test that e+ e- > j j j with pdlabel='lhapdf' runs ignoring the lhapdf setting """ cmd = os.getcwd() self.generate(['e+ e- > p p p [real=QCD]'], 'sm') self.assertEqual(cmd, os.getcwd()) card = open('%s/Cards/run_card_default.dat' % self.path).read() # this check that the value of lpp/beam are change automatically self.assertTrue('0 = lpp1' in card) self.assertTrue('500.0 = ebeam' in card) # pass to the object card = banner.RunCardNLO(card) card['pdlabel'] = "lhapdf" self.assertEqual(card['lpp1'], 0) self.assertEqual(card['lpp2'], 0) self.assertEqual(card['ebeam1'], 500) self.assertEqual(card['ebeam2'], 500) card.write('%s/Cards/run_card.dat' % self.path) self.do('calculate_xsect -f LO') self.do('quit') self.assertTrue( os.path.exists('%s/Events/run_01_LO/MADatNLO.HwU' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/res_0.txt' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/res_1.txt' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/summary.txt' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/run_01_LO_tag_1_banner.txt' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/alllogs_0.html' % self.path)) self.assertTrue( os.path.exists('%s/Events/run_01_LO/alllogs_1.html' % self.path)) # check the result res = open('%s/Events/run_01_LO/res_1.txt' % self.path).read() pat = re.compile( '''\s*(\d+\.\d+e[+-]\d+) \+\- (\d+\.\d+e[+-]\d+) \((\d+\.\d+e[+-]\d+)\%\) \s*(\-?\d+\.\d+e[+-]\d+) \+\- (\d+\.\d+e[+-]\d+) \((\-?\d+\.\d+e[+-]\d+)\%\)''' ) match = re.search(pat, res) res_dict = { 'xseca': float(match.groups()[0]), 'erra': float(match.groups()[1]), 'xsect': float(match.groups()[3]), 'errt': float(match.groups()[4]) } self.assertEqual(res_dict['xseca'], res_dict['xsect']) self.assertTrue(math.fabs(res_dict['xseca'] - 3.811e-1) < 0.01)
def create_run_card(self, processes, history): """create the run_card for MadSTR, including the extra variables needed to control the OS subtraction also in banner.py""" run_card = banner_mod.RunCardNLO() run_card.create_default_for_process(self.proc_characteristic, history, processes) run_card.write(pjoin(self.dir_path, 'Cards', 'run_card_default.dat')) # now edit the run_card with the extra variables os_text = \ """#*********************************************************************** # Parameters relevant for the MasSTR plugin: * # iSTR controls the strategy for the resonance treatment * # istr = 1 -> DR without interferece * # istr = 2 -> DR with interferece * # istr = 3 -> DS with reshuffling on initial state, standard BW * # istr = 4 -> DS with reshuffling on initial state, running BW * # istr = 5 -> DS with reshuffling on all FS particles, standard BW * # istr = 6 -> DS with reshuffling on all FS particles, running BW * #*********************************************************************** 2 = istr ! strategy to be used to remove resonances ! appearing in real emissions True = str_include_pdf ! compensate for PDFs when doing reshuffling True = str_include_flux ! compensate for flux when doing reshuffling""" run_card_lines = open(pjoin(self.dir_path, 'Cards', 'run_card_default.dat')).read().split('\n') # look for the line which contains 'store_rwgt_info', after which we will insert # the OS block for isplit, line in enumerate(run_card_lines): if 'store_rwgt_info' in line: break new_run_card_lines = run_card_lines[:isplit+1] + os_text.split('\n') + run_card_lines[isplit+1:] new_run_card = open(pjoin(self.dir_path, 'Cards', 'run_card_default.dat'), 'w') new_run_card.write('\n'.join(new_run_card_lines)) new_run_card.close() # finally copy the run_card_default to run_card files.cp(pjoin(self.dir_path, 'Cards', 'run_card_default.dat'), \ pjoin(self.dir_path, 'Cards', 'run_card.dat')) # We also need to update banner.py banner_text = \ """ self.add_param('istr', 2) self.add_param('str_include_pdf', True) self.add_param('str_include_flux', True)""" banner_lines = open(pjoin(self.dir_path, 'bin', 'internal', 'banner.py')).read().split('\n') for isplit, line in enumerate(banner_lines): if 'store_rwgt_info' in line: break new_banner_lines = banner_lines[:isplit+1] + banner_text.split('\n') + banner_lines[isplit+1:] new_banner = open(pjoin(self.dir_path, 'bin', 'internal', 'banner.py'), 'w') new_banner.write('\n'.join(new_banner_lines)) new_banner.close()
def test_default(self): run_card = bannermod.RunCard() # fsock = tempfile.NamedTemporaryFile(mode = 'w') fsock = open(pjoin(self.tmpdir, 'run_card_test'), 'w') run_card.write(fsock) fsock.close() run_card2 = bannermod.RunCard(fsock.name) for key in run_card: self.assertEqual(run_card[key], run_card2[key]) run_card = bannermod.RunCardNLO() # fsock = tempfile.NamedTemporaryFile(mode = 'w') fsock = open(pjoin(self.tmpdir, 'run_card_test2'), 'w') run_card.write(fsock) fsock.close() #card should be identical if we do not run the consistency post-processing run_card2 = bannermod.RunCard(fsock.name, consistency=False) for key in run_card: self.assertEqual( run_card[key], run_card2[key], 'not equal entry for %s" %s!=%s' % (key, run_card[key], run_card2[key])) #but default can be updated otherwise run_card3 = bannermod.RunCard(fsock.name) has_difference = False has_userset = False for key in run_card: key = key.lower() if run_card[key] != run_card3[key]: has_difference = True self.assertTrue(key.lower() in run_card.hidden_param) self.assertTrue(key.lower not in run_card3.user_set) if key in run_card3.user_set: has_userset = True self.assertFalse(key in run_card.user_set) self.assertTrue(has_difference) self.assertTrue(has_userset) #write run_card3 and check that nothing is changed # fsock2 = tempfile.NamedTemporaryFile(mode = 'w') fsock2 = open(pjoin(self.tmpdir, 'run_card_test3'), 'w') run_card3.write(fsock2) fsock2.close() self.assertEqual(open(fsock.name).read(), open(fsock2.name).read())
def test_default(self): run_card = bannermod.RunCard() fsock = tempfile.NamedTemporaryFile(mode = 'w') run_card.write(fsock) run_card2 = bannermod.RunCard(fsock.name) for key in run_card: self.assertEqual(run_card[key], run_card2[key]) run_card = bannermod.RunCardNLO() fsock = tempfile.NamedTemporaryFile(mode = 'w') run_card.write(fsock) run_card2 = bannermod.RunCard(fsock.name) for key in run_card: self.assertEqual(run_card[key], run_card2[key])