def run_from_pickle(self): import madgraph.iolibs.save_load_object as save_load_object generate_all = save_load_object.load_from_file(pjoin(self.options['ms_dir'], 'madspin.pkl')) # Re-create information which are not save in the pickle. generate_all.evtfile = self.events_file generate_all.curr_event = madspin.Event(self.events_file, self.banner ) generate_all.mgcmd = self.mg5cmd generate_all.mscmd = self generate_all.pid2width = lambda pid: generate_all.banner.get('param_card', 'decay', abs(pid)).value generate_all.pid2mass = lambda pid: generate_all.banner.get('param_card', 'mass', abs(pid)).value if generate_all.path_me != self.options['ms_dir']: for decay in generate_all.all_ME.values(): decay['path'] = decay['path'].replace(generate_all.path_me, self.options['ms_dir']) for decay2 in decay['decays']: decay2['path'] = decay2['path'].replace(generate_all.path_me, self.options['ms_dir']) generate_all.path_me = self.options['ms_dir'] # directory can have been move generate_all.ms_dir = generate_all.path_me if not hasattr(self.banner, 'param_card'): self.banner.charge_card('slha') for name, block in self.banner.param_card.items(): if name.startswith('decay'): continue orig_block = generate_all.banner.param_card[name] if block != orig_block: raise Exception, """The directory %s is specific to a mass spectrum. Your event file is not compatible with this one. (Different param_card: %s different) orig block: %s new block: %s""" \ % (self.options['ms_dir'], name, orig_block, block) #replace init information generate_all.banner['init'] = self.banner['init'] # NOW we have all the information available for RUNNING if self.seed: #seed is specified need to use that one: open(pjoin(self.options['ms_dir'],'seeds.dat'),'w').write('%s\n'%self.seed) #remove all ranmar_state for name in glob.glob(pjoin(self.options['ms_dir'], '*', 'SubProcesses','*','ranmar_state.dat')): os.remove(name) generate_all.ending_run() self.branching_ratio = generate_all.branching_ratio evt_path = self.events_file.name try: self.events_file.close() except: pass misc.gzip(evt_path) decayed_evt_file=evt_path.replace('.lhe', '_decayed.lhe') misc.gzip(pjoin(self.options['curr_dir'],'decayed_events.lhe'), stdout=decayed_evt_file) if not self.mother: logger.info("Decayed events have been written in %s.gz" % decayed_evt_file)
def close(self, *args, **opts): out = self.file.close(*args, **opts) if self.to_zip: misc.gzip(self.path)
def run_from_pickle(self): import madgraph.iolibs.save_load_object as save_load_object generate_all = save_load_object.load_from_file( pjoin(self.options['ms_dir'], 'madspin.pkl')) # Re-create information which are not save in the pickle. generate_all.evtfile = self.events_file generate_all.curr_event = madspin.Event(self.events_file, self.banner) generate_all.mgcmd = self.mg5cmd generate_all.mscmd = self generate_all.pid2width = lambda pid: generate_all.banner.get( 'param_card', 'decay', abs(pid)).value generate_all.pid2mass = lambda pid: generate_all.banner.get( 'param_card', 'mass', abs(pid)).value if generate_all.path_me != self.options['ms_dir']: for decay in generate_all.all_ME.values(): decay['path'] = decay['path'].replace(generate_all.path_me, self.options['ms_dir']) for decay2 in decay['decays']: decay2['path'] = decay2['path'].replace( generate_all.path_me, self.options['ms_dir']) generate_all.path_me = self.options[ 'ms_dir'] # directory can have been move generate_all.ms_dir = generate_all.path_me if not hasattr(self.banner, 'param_card'): self.banner.charge_card('slha') # Special treatment for the mssm. Convert the param_card to the correct # format if self.banner.get('model').startswith('mssm-') or self.banner.get( 'model') == 'mssm': self.banner.param_card = check_param_card.convert_to_mg5card(\ self.banner.param_card, writting=False) for name, block in self.banner.param_card.items(): if name.startswith('decay'): continue orig_block = generate_all.banner.param_card[name] if block != orig_block: raise Exception, """The directory %s is specific to a mass spectrum. Your event file is not compatible with this one. (Different param_card: %s different) orig block: %s new block: %s""" \ % (self.options['ms_dir'], name, orig_block, block) #replace init information generate_all.banner['init'] = self.banner['init'] #replace run card if present in header (to make sure correct random seed is recorded in output file) if 'mgruncard' in self.banner: generate_all.banner['mgruncard'] = self.banner['mgruncard'] # NOW we have all the information available for RUNNING if self.seed: #seed is specified need to use that one: open(pjoin(self.options['ms_dir'], 'seeds.dat'), 'w').write('%s\n' % self.seed) #remove all ranmar_state for name in misc.glob( pjoin('*', 'SubProcesses', '*', 'ranmar_state.dat'), self.options['ms_dir']): os.remove(name) generate_all.ending_run() self.branching_ratio = generate_all.branching_ratio try: self.err_branching_ratio = generate_all.err_branching_ratio except Exception: # might not be define in some gridpack mode self.err_branching_ratio = 0 evt_path = self.events_file.name try: self.events_file.close() except: pass misc.gzip(evt_path) decayed_evt_file = evt_path.replace('.lhe', '_decayed.lhe') misc.gzip(pjoin(self.options['curr_dir'], 'decayed_events.lhe'), stdout=decayed_evt_file) if not self.mother: logger.info("Decayed events have been written in %s.gz" % decayed_evt_file)
def do_launch(self, line): """end of the configuration launched the code""" if self.options["spinmode"] in ["none"]: return self.run_bridge(line) elif self.options["spinmode"] == "bridge": raise Exception, "Bridge mode not yet available due to lack of validation." if self.options['ms_dir'] and os.path.exists( pjoin(self.options['ms_dir'], 'madspin.pkl')): return self.run_from_pickle() args = self.split_arg(line) self.check_launch(args) for part in self.list_branches.keys(): if part in self.mg5cmd._multiparticles: if any(pid in self.final_state for pid in self.mg5cmd._multiparticles[part]): break pid = self.mg5cmd._curr_model.get('name2pdg')[part] if pid in self.final_state: break # else: # logger.info("Nothing to decay ...") # return model_line = self.banner.get('proc_card', 'full_model_line') if not self.seed: self.seed = random.randint(0, int(30081 * 30081)) self.do_set('seed %s' % self.seed) logger.info('Will use seed %s' % self.seed) self.history.insert(0, 'set seed %s' % self.seed) if self.seed > 30081 * 30081: # can't use too big random number msg = 'Random seed too large ' + str(self.seed) + ' > 30081*30081' raise Exception, msg self.options['seed'] = self.seed text = '%s\n' % '\n'.join([line for line in self.history if line]) self.banner.add_text('madspin', text) self.update_status('generating Madspin matrix element') generate_all = madspin.decay_all_events(self, self.banner, self.events_file, self.options) self.update_status('running MadSpin') generate_all.run() self.branching_ratio = generate_all.branching_ratio try: self.err_branching_ratio = generate_all.err_branching_ratio except Exception: self.err_branching_ratio = 0 evt_path = self.events_file.name try: self.events_file.close() except: pass misc.gzip(evt_path) decayed_evt_file = evt_path.replace('.lhe', '_decayed.lhe') misc.gzip(pjoin(self.options['curr_dir'], 'decayed_events.lhe'), stdout=decayed_evt_file) if not self.mother: logger.info("Decayed events have been written in %s.gz" % decayed_evt_file) # Now arxiv the shower card used if RunMaterial is present ms_card_path = pjoin(self.options['curr_dir'], 'Cards', 'madspin_card.dat') run_dir = os.path.realpath(os.path.dirname(decayed_evt_file)) if os.path.exists(ms_card_path): if os.path.exists(pjoin(run_dir, 'RunMaterial.tar.gz')): misc.call(['tar', '-xzpf', 'RunMaterial.tar.gz'], cwd=run_dir) base_path = pjoin(run_dir, 'RunMaterial') else: base_path = pjoin(run_dir) evt_name = os.path.basename(decayed_evt_file).replace('.lhe', '') ms_card_to_copy = pjoin(base_path, 'madspin_card_for_%s.dat' % evt_name) count = 0 while os.path.exists(ms_card_to_copy): count += 1 ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s_%d.dat'%\ (evt_name,count)) files.cp(str(ms_card_path), str(ms_card_to_copy)) if os.path.exists(pjoin(run_dir, 'RunMaterial.tar.gz')): misc.call( ['tar', '-czpf', 'RunMaterial.tar.gz', 'RunMaterial'], cwd=run_dir) shutil.rmtree(pjoin(run_dir, 'RunMaterial'))
def do_launch(self, line): """end of the configuration launched the code""" if self.options["spinmode"] in ["none"]: return self.run_bridge(line) elif self.options["spinmode"] == "bridge": raise Exception, "Bridge mode not yet available due to lack of validation." if self.options['ms_dir'] and os.path.exists(pjoin(self.options['ms_dir'], 'madspin.pkl')): return self.run_from_pickle() args = self.split_arg(line) self.check_launch(args) for part in self.list_branches.keys(): if part in self.mg5cmd._multiparticles: if any(pid in self.final_state for pid in self.mg5cmd._multiparticles[part]): break pid = self.mg5cmd._curr_model.get('name2pdg')[part] if pid in self.final_state: break # else: # logger.info("Nothing to decay ...") # return model_line = self.banner.get('proc_card', 'full_model_line') if not self.seed: self.seed = random.randint(0, int(30081*30081)) self.do_set('seed %s' % self.seed) logger.info('Will use seed %s' % self.seed) self.history.insert(0, 'set seed %s' % self.seed) if self.seed > 30081*30081: # can't use too big random number msg = 'Random seed too large ' + str(self.seed) + ' > 30081*30081' raise Exception, msg self.options['seed'] = self.seed text = '%s\n' % '\n'.join([ line for line in self.history if line]) self.banner.add_text('madspin' , text) self.update_status('generating Madspin matrix element') generate_all = madspin.decay_all_events(self, self.banner, self.events_file, self.options) self.update_status('running MadSpin') generate_all.run() self.branching_ratio = generate_all.branching_ratio try: self.err_branching_ratio = generate_all.err_branching_ratio except Exception: self.err_branching_ratio = 0 evt_path = self.events_file.name try: self.events_file.close() except: pass misc.gzip(evt_path) decayed_evt_file=evt_path.replace('.lhe', '_decayed.lhe') misc.gzip(pjoin(self.options['curr_dir'],'decayed_events.lhe'), stdout=decayed_evt_file) if not self.mother: logger.info("Decayed events have been written in %s.gz" % decayed_evt_file) # Now arxiv the shower card used if RunMaterial is present ms_card_path = pjoin(self.options['curr_dir'],'Cards','madspin_card.dat') run_dir = os.path.realpath(os.path.dirname(decayed_evt_file)) if os.path.exists(ms_card_path): if os.path.exists(pjoin(run_dir,'RunMaterial.tar.gz')): misc.call(['tar','-xzpf','RunMaterial.tar.gz'], cwd=run_dir) base_path = pjoin(run_dir,'RunMaterial') else: base_path = pjoin(run_dir) evt_name = os.path.basename(decayed_evt_file).replace('.lhe', '') ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s.dat'%evt_name) count = 0 while os.path.exists(ms_card_to_copy): count += 1 ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s_%d.dat'%\ (evt_name,count)) files.cp(str(ms_card_path),str(ms_card_to_copy)) if os.path.exists(pjoin(run_dir,'RunMaterial.tar.gz')): misc.call(['tar','-czpf','RunMaterial.tar.gz','RunMaterial'], cwd=run_dir) shutil.rmtree(pjoin(run_dir,'RunMaterial'))