def do_import(self, inputfile): """import the event file""" # change directory where to write the output self.options['curr_dir'] = os.path.realpath(os.path.dirname(inputfile)) if os.path.basename(os.path.dirname(os.path.dirname(inputfile))) == 'Events': self.options['curr_dir'] = pjoin(self.options['curr_dir'], os.path.pardir, os.pardir) if not os.path.exists(inputfile): if inputfile.endswith('.gz'): if not os.path.exists(inputfile[:-3]): raise self.InvalidCmd('No such file or directory : %s' % inputfile) else: inputfile = inputfile[:-3] elif os.path.exists(inputfile + '.gz'): inputfile = inputfile + '.gz' else: raise self.InvalidCmd('No such file or directory : %s' % inputfile) if inputfile.endswith('.gz'): misc.gunzip(inputfile) inputfile = inputfile[:-3] # Read the banner of the inputfile self.lhe_input = lhe_parser.EventFile(os.path.realpath(inputfile)) if not self.lhe_input.banner: value = self.ask("What is the path to banner", 0, [0], "please enter a path", timeout=0) self.lhe_input.banner = open(value).read() self.banner = self.lhe_input.get_banner() # Check the validity of the banner: if 'slha' not in self.banner: self.events_file = None raise self.InvalidCmd('Event file does not contain model information') elif 'mg5proccard' not in self.banner: self.events_file = None raise self.InvalidCmd('Event file does not contain generation information') if 'madspin' in self.banner: raise self.InvalidCmd('Reweight should be done before running MadSpin') # load information process = self.banner.get_detail('proc_card', 'generate') if '[' in process: msg = 'Reweighting options is valid only for LO events' raise Exception, msg if not process: msg = 'Invalid proc_card information in the file (no generate line):\n %s' % self.banner['mg5proccard'] raise Exception, msg process, option = mg_interface.MadGraphCmd.split_process_line(process) self.proc_option = option logger.info("process: %s" % process) logger.info("options: %s" % option)
def __init__(self, path, mode='r', *args, **opt): """open file and read the banner [if in read mode]""" if mode in ['r', 'rb']: mode = 'r' self.mode = mode if not path.endswith(".gz"): self.file = open(path, mode, *args, **opt) elif mode == 'r' and not os.path.exists(path) and os.path.exists( path[:-3]): self.file = open(path[:-3], mode, *args, **opt) path = path[:-3] else: try: self.file = gzip.GzipFile(path, mode, *args, **opt) self.zip_mode = True except IOError as error: raise except Exception as error: misc.sprint(error) if mode == 'r': misc.gunzip(path) else: self.to_zip = True self.file = open(path[:-3], mode, *args, **opt) path = path[:-3] self.parsing = True # check if/when we need to parse the event. self.eventgroup = False self.header = '' if mode == 'r': line = '' while 'HepMC::IO_GenEvent-START_EVENT_LISTING' not in line: line = self.file.readline() if not line: self.seek(0) self.banner = '' break if 'b' in mode or self.zip_mode: line = str(line.decode()) self.header += line self.start_event = ''
def do_check_events(self, line): """MadWeight Function: check that the events are valid and write the events to MG mapping""" self.configure() evt_file = pjoin(self.me_dir, 'Events', 'input.lhco') if not os.path.exists(evt_file): question = 'Which LHCO file do you want to use?' default = '' if os.path.exists('%s.gz' % evt_file): input_file = '%s.gz' % evt_file else: input_file = self.ask(question, default, path_msg='valid path') if not input_file: raise self.InvalidCmd('Please specify a valid LHCO File') if input_file.endswith('.gz'): misc.gunzip(input_file, keep=True, stdout=evt_file) else: files.cp(input_file, evt_file) verif_event.verif_event(self.MWparam)
def do_check_events(self, line): """MadWeight Function: check that the events are valid and write the events to MG mapping""" self.configure() evt_file = pjoin(self.me_dir,'Events','input.lhco') if not os.path.exists(evt_file): question = 'Which LHCO file do you want to use?' default = '' if os.path.exists('%s.gz' % evt_file): input_file = '%s.gz' % evt_file else: input_file = self.ask(question, default, path_msg='valid path') if not input_file: raise self.InvalidCmd('Please specify a valid LHCO File') if input_file.endswith('.gz'): misc.gunzip(input_file, keep=True, stdout=evt_file) else: files.cp(input_file, evt_file) verif_event.verif_event(self.MWparam)
class TestMEfromfile(unittest.TestCase): """test that we can launch everything from a single file""" def setUp(self): self.debuging = False if self.debuging: self.path = pjoin(MG5DIR, 'ACC_TEST') if os.path.exists(self.path): shutil.rmtree(self.path) os.mkdir(self.path) else: self.path = tempfile.mkdtemp(prefix='acc_test_mg5') self.run_dir = pjoin(self.path, 'MGPROC') def tearDown(self): if not self.debuging: shutil.rmtree(self.path) def test_add_time_of_flight(self): """checking time of flight is working fine""" 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')): p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')], stdin=subprocess.PIPE, stdout=stdout, stderr=stderr) out = p.communicate('install pythia-pgs') misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs')) try: shutil.rmtree('/tmp/MGPROCESS/') except Exception, error: pass cmd = """import model sm set automatic_html_opening False --no_save set notification_center False --no_save generate p p > w+ z output %s -f -nojpeg launch -i set automatic_html_opening False --no_save generate_events parton set nevents 100 set event_norm sum set systematics_program none add_time_of_flight --threshold=4e-14 pythia """ % self.run_dir open(pjoin(self.path, 'mg5_cmd'), 'w').write(cmd) if logging.getLogger('madgraph').level <= 20: stdout = None stderr = None else: devnull = open(os.devnull, 'w') stdout = devnull stderr = devnull subprocess.call( [ pjoin(_file_path, os.path.pardir, 'bin', 'mg5'), pjoin(self.path, 'mg5_cmd') ], #cwd=self.path, stdout=stdout, stderr=stderr) self.check_parton_output(cross=15.62, error=0.19) self.check_pythia_output() event = '%s/Events/run_01/unweighted_events.lhe' % self.run_dir if not os.path.exists(event): misc.gunzip(event) has_zero = False has_non_zero = False for event in lhe_parser.EventFile(event): for particle in event: if particle.pid in [23, 25]: self.assertTrue(particle.vtim == 0 or particle.vtim > 4e-14) if particle.vtim == 0: has_zero = True else: has_non_zero = True self.assertTrue(has_zero) self.assertTrue(has_non_zero) self.assertFalse(self.debuging)
def do_import(self, inputfile): """import the event file""" args = self.split_arg(inputfile) if not args: return self.InvalidCmd, 'import requires arguments' elif args[0] == 'model': return self.import_model(args[1:]) # change directory where to write the output self.options['curr_dir'] = os.path.realpath(os.path.dirname(inputfile)) if os.path.basename(os.path.dirname( os.path.dirname(inputfile))) == 'Events': self.options['curr_dir'] = pjoin(self.options['curr_dir'], os.path.pardir, os.pardir) if not os.path.exists(inputfile): if inputfile.endswith('.gz'): if not os.path.exists(inputfile[:-3]): raise self.InvalidCmd('No such file or directory : %s' % inputfile) else: inputfile = inputfile[:-3] elif os.path.exists(inputfile + '.gz'): inputfile = inputfile + '.gz' else: raise self.InvalidCmd('No such file or directory : %s' % inputfile) if inputfile.endswith('.gz'): misc.gunzip(inputfile) inputfile = inputfile[:-3] # Read the banner of the inputfile self.events_file = open(os.path.realpath(inputfile)) self.banner = banner.Banner(self.events_file) # Check the validity of the banner: if 'slha' not in self.banner: self.events_file = None raise self.InvalidCmd( 'Event file does not contain model information') elif 'mg5proccard' not in self.banner: self.events_file = None raise self.InvalidCmd( 'Event file does not contain generation information') if 'madspin' in self.banner: raise self.InvalidCmd( 'This event file was already decayed by MS. This is not possible to add to it a second decay' ) if 'mgruncard' in self.banner: if not self.options['Nevents_for_max_weigth']: nevents = int(self.banner.get_detail('run_card', 'nevents')) N_weight = max([75, int(3 * nevents**(1 / 3))]) self.options['Nevents_for_max_weigth'] = N_weight N_sigma = max(4.5, math.log(nevents, 7.7)) self.options['nb_sigma'] = N_sigma if self.options['BW_cut'] == -1: self.options['BW_cut'] = float( self.banner.get_detail('run_card', 'bwcutoff')) else: if not self.options['Nevents_for_max_weigth']: self.options['Nevents_for_max_weigth'] = 75 self.options['nb_sigma'] = 4.5 if self.options['BW_cut'] == -1: self.options['BW_cut'] = 15.0 # load information process = self.banner.get_detail('proc_card', 'generate') if not process: msg = 'Invalid proc_card information in the file (no generate line):\n %s' % self.banner[ 'mg5proccard'] raise Exception, msg process, option = mg_interface.MadGraphCmd.split_process_line(process) self.proc_option = option logger.info("process: %s" % process) logger.info("options: %s" % option) if not hasattr(self, 'multiparticles_ms'): for key, value in self.banner.get_detail('proc_card', 'multiparticles'): try: self.do_define('%s = %s' % (key, value)) except self.mg5cmd.InvalidCmd: pass # Read the final state of the production process: # "_full" means with the complete decay chain syntax # "_compact" means without the decay chain syntax self.final_state_full = process[process.find(">") + 1:] self.final_state_compact, self.prod_branches=\ self.decay.get_final_state_compact(self.final_state_full) # Load the model complex_mass = False has_cms = re.compile( r'''set\s+complex_mass_scheme\s*(True|T|1|true|$|;)''') for line in self.banner.proc_card: if line.startswith('set'): self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) if has_cms.search(line): complex_mass = True info = self.banner.get('proc_card', 'full_model_line') if '-modelname' in info: mg_names = False else: mg_names = True model_name = self.banner.get('proc_card', 'model') if model_name: self.load_model(model_name, mg_names, complex_mass) else: raise self.InvalidCmd('Only UFO model can be loaded in MadSpin.') # check particle which can be decayed: self.final_state = set() final_model = False for line in self.banner.proc_card: line = ' '.join(line.strip().split()) if line.startswith('generate'): self.final_state.update(self.mg5cmd.get_final_part(line[8:])) elif line.startswith('add process'): self.final_state.update(self.mg5cmd.get_final_part(line[11:])) elif line.startswith('define'): try: self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) except self.mg5cmd.InvalidCmd: if final_model: raise else: key = line.split()[1] if key in self.multiparticles_ms: del self.multiparticles_ms[key] elif line.startswith('set'): self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) elif line.startswith('import model'): if model_name in line: final_model = True
def do_import(self, inputfile): """import the event file""" args = self.split_arg(inputfile) if not args: return self.InvalidCmd, 'import requires arguments' elif args[0] == 'model': return self.import_model(args[1:]) # change directory where to write the output self.options['curr_dir'] = os.path.realpath(os.path.dirname(inputfile)) if os.path.basename(os.path.dirname(os.path.dirname(inputfile))) == 'Events': self.options['curr_dir'] = pjoin(self.options['curr_dir'], os.path.pardir, os.pardir) if not os.path.exists(inputfile): if inputfile.endswith('.gz'): if not os.path.exists(inputfile[:-3]): raise self.InvalidCmd('No such file or directory : %s' % inputfile) else: inputfile = inputfile[:-3] elif os.path.exists(inputfile + '.gz'): inputfile = inputfile + '.gz' else: raise self.InvalidCmd('No such file or directory : %s' % inputfile) if inputfile.endswith('.gz'): misc.gunzip(inputfile) inputfile = inputfile[:-3] # Read the banner of the inputfile self.events_file = open(os.path.realpath(inputfile)) self.banner = banner.Banner(self.events_file) # Check the validity of the banner: if 'slha' not in self.banner: self.events_file = None raise self.InvalidCmd('Event file does not contain model information') elif 'mg5proccard' not in self.banner: self.events_file = None raise self.InvalidCmd('Event file does not contain generation information') if 'madspin' in self.banner: raise self.InvalidCmd('This event file was already decayed by MS. This is not possible to add to it a second decay') if 'mgruncard' in self.banner: if not self.options['Nevents_for_max_weigth']: nevents = int(self.banner.get_detail('run_card', 'nevents')) N_weight = max([75, int(3*nevents**(1/3))]) self.options['Nevents_for_max_weigth'] = N_weight N_sigma = max(4.5, math.log(nevents,7.7)) self.options['nb_sigma'] = N_sigma if self.options['BW_cut'] == -1: self.options['BW_cut'] = float(self.banner.get_detail('run_card', 'bwcutoff')) else: if not self.options['Nevents_for_max_weigth']: self.options['Nevents_for_max_weigth'] = 75 self.options['nb_sigma'] = 4.5 if self.options['BW_cut'] == -1: self.options['BW_cut'] = 15.0 # load information process = self.banner.get_detail('proc_card', 'generate') if not process: msg = 'Invalid proc_card information in the file (no generate line):\n %s' % self.banner['mg5proccard'] raise Exception, msg process, option = mg_interface.MadGraphCmd.split_process_line(process) self.proc_option = option logger.info("process: %s" % process) logger.info("options: %s" % option) if not hasattr(self,'multiparticles_ms'): for key, value in self.banner.get_detail('proc_card','multiparticles'): try: self.do_define('%s = %s' % (key, value)) except self.mg5cmd.InvalidCmd: pass # Read the final state of the production process: # "_full" means with the complete decay chain syntax # "_compact" means without the decay chain syntax self.final_state_full = process[process.find(">")+1:] self.final_state_compact, self.prod_branches=\ self.decay.get_final_state_compact(self.final_state_full) # Load the model complex_mass = False has_cms = re.compile(r'''set\s+complex_mass_scheme\s*(True|T|1|true|$|;)''') for line in self.banner.proc_card: if line.startswith('set'): self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) if has_cms.search(line): complex_mass = True info = self.banner.get('proc_card', 'full_model_line') if '-modelname' in info: mg_names = False else: mg_names = True model_name = self.banner.get('proc_card', 'model') if model_name: self.load_model(model_name, mg_names, complex_mass) else: raise self.InvalidCmd('Only UFO model can be loaded in MadSpin.') # check particle which can be decayed: self.final_state = set() final_model = False for line in self.banner.proc_card: line = ' '.join(line.strip().split()) if line.startswith('generate'): self.final_state.update(self.mg5cmd.get_final_part(line[8:])) elif line.startswith('add process'): self.final_state.update(self.mg5cmd.get_final_part(line[11:])) elif line.startswith('define'): try: self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) except self.mg5cmd.InvalidCmd: if final_model: raise else: key = line.split()[1] if key in self.multiparticles_ms: del self.multiparticles_ms[key] elif line.startswith('set'): self.mg5cmd.exec_cmd(line, printcmd=False, precmd=False, postcmd=False) elif line.startswith('import model'): if model_name in line: final_model = True
def test_read_write_gzip(self): """ """ input = """<LesHouchesEvents version="1.0"> <header> DATA </header> <init> 2212 2212 0.70000000000E+04 0.70000000000E+04 0 0 10042 10042 3 1 0.16531958660E+02 0.18860728290E+00 0.17208000000E+00 0 </init> <event> 4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01 -1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00 24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00 23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00 </event> <event> 4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01 -1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00 24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00 23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00 # balbalblb #bbbb3 </event> <event> 7 66 +1.5024446e-03 3.15138740e+02 7.95774720e-02 9.66701260e-02 21 -1 0 0 502 501 +0.0000000e+00 +0.0000000e+00 -6.4150959e+01 6.41553430e+01 7.49996552e-01 0.0000e+00 0.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 +8.1067989e+02 8.10679950e+02 3.11899968e-01 0.0000e+00 0.0000e+00 24 2 1 2 0 0 -1.5294533e+02 +1.0783429e+01 +4.5796553e+02 4.89600040e+02 8.04190039e+01 0.0000e+00 0.0000e+00 2 1 3 3 503 0 -1.5351296e+02 +1.2743130e+01 +4.6093709e+02 4.85995489e+02 0.00000000e+00 0.0000e+00 0.0000e+00 -1 1 3 3 0 503 +5.6763429e-01 -1.9597014e+00 -2.9715566e+00 3.60455091e+00 0.00000000e+00 0.0000e+00 0.0000e+00 23 1 1 2 0 0 +4.4740095e+01 +3.2658177e+01 +4.6168760e+01 1.16254200e+02 9.11880036e+01 0.0000e+00 0.0000e+00 1 1 1 2 502 0 +1.0820523e+02 -4.3441605e+01 +2.4239464e+02 2.68981060e+02 3.22945297e-01 0.0000e+00 0.0000e+00 # 2 5 2 2 1 0.11659994e+03 0.11659994e+03 8 0 0 0.10000000e+01 0.88172677e+00 0.11416728e+01 0.00000000e+00 0.00000000e+00 <rwgt> <wgt id='1001'> +9.1696000e+03 </wgt> <wgt id='1002'> +1.1264000e+04 </wgt> <wgt id='1003'> +6.9795000e+03 </wgt> <wgt id='1004'> +9.1513000e+03 </wgt> <wgt id='1005'> +1.1253000e+04 </wgt> </rwgt> </event> </LesHouchesEvents> """ open(pjoin(self.path, 'event.lhe'), 'w').write(input) input_lhe = lhe_parser.EventFile(pjoin(self.path, 'event.lhe.gz')) output_lhe = lhe_parser.EventFile(pjoin(self.path, 'event2.lhe.gz'), 'w') output_lhe.write(input_lhe.banner) for event in input_lhe: output_lhe.write(str(event)) output_lhe.close() self.assertTrue(pjoin(self.path, 'event2.lhe.gz')) text = open(pjoin(self.path, 'event2.lhe.gz')).read() self.assertFalse(text.startswith('<LesHouchesEvents version="1.0">')) misc.gunzip(pjoin(self.path, 'event2.lhe.gz')) self.assertTrue(pjoin(self.path, 'event2.lhe')) input_lhe = lhe_parser.EventFile(pjoin(self.path, 'event.lhe'))
def test_read_write_gzip(self): """ """ input= """<LesHouchesEvents version="1.0"> <header> DATA </header> <init> 2212 2212 0.70000000000E+04 0.70000000000E+04 0 0 10042 10042 3 1 0.16531958660E+02 0.18860728290E+00 0.17208000000E+00 0 </init> <event> 4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01 -1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00 24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00 23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00 </event> <event> 4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01 -1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00 24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00 23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00 # balbalblb #bbbb3 </event> <event> 7 66 +1.5024446e-03 3.15138740e+02 7.95774720e-02 9.66701260e-02 21 -1 0 0 502 501 +0.0000000e+00 +0.0000000e+00 -6.4150959e+01 6.41553430e+01 7.49996552e-01 0.0000e+00 0.0000e+00 2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 +8.1067989e+02 8.10679950e+02 3.11899968e-01 0.0000e+00 0.0000e+00 24 2 1 2 0 0 -1.5294533e+02 +1.0783429e+01 +4.5796553e+02 4.89600040e+02 8.04190039e+01 0.0000e+00 0.0000e+00 2 1 3 3 503 0 -1.5351296e+02 +1.2743130e+01 +4.6093709e+02 4.85995489e+02 0.00000000e+00 0.0000e+00 0.0000e+00 -1 1 3 3 0 503 +5.6763429e-01 -1.9597014e+00 -2.9715566e+00 3.60455091e+00 0.00000000e+00 0.0000e+00 0.0000e+00 23 1 1 2 0 0 +4.4740095e+01 +3.2658177e+01 +4.6168760e+01 1.16254200e+02 9.11880036e+01 0.0000e+00 0.0000e+00 1 1 1 2 502 0 +1.0820523e+02 -4.3441605e+01 +2.4239464e+02 2.68981060e+02 3.22945297e-01 0.0000e+00 0.0000e+00 # 2 5 2 2 1 0.11659994e+03 0.11659994e+03 8 0 0 0.10000000e+01 0.88172677e+00 0.11416728e+01 0.00000000e+00 0.00000000e+00 <rwgt> <wgt id='1001'> +9.1696000e+03 </wgt> <wgt id='1002'> +1.1264000e+04 </wgt> <wgt id='1003'> +6.9795000e+03 </wgt> <wgt id='1004'> +9.1513000e+03 </wgt> <wgt id='1005'> +1.1253000e+04 </wgt> </rwgt> </event> </LesHouchesEvents> """ open(pjoin(self.path, 'event.lhe'),'w').write(input) input_lhe = lhe_parser.EventFile(pjoin(self.path, 'event.lhe.gz')) output_lhe = lhe_parser.EventFile(pjoin(self.path, 'event2.lhe.gz'),'w') output_lhe.write(input_lhe.banner) for event in input_lhe: output_lhe.write(str(event)) output_lhe.close() self.assertTrue(pjoin(self.path,'event2.lhe.gz')) text = open(pjoin(self.path, 'event2.lhe.gz')).read() self.assertFalse(text.startswith('<LesHouchesEvents version="1.0">')) misc.gunzip(pjoin(self.path,'event2.lhe.gz')) self.assertTrue(pjoin(self.path,'event2.lhe')) input_lhe = lhe_parser.EventFile(pjoin(self.path, 'event.lhe'))