def get_2body(self, particle): """use FR to get the list of particles being in the 1->2 final state""" dir_name = 'TEST_DECAY3_%s_%s' % (self.model,particle) os.system('rm -rf %s >/dev/null' % dir_name) pid = self.particles_id[particle] #make a fake output self.cmd._curr_model.write_param_card() self.cmd.exec_cmd('generate z > e+ e-') self.cmd.exec_cmd('output %s -f' % dir_name) me_cmd = me_interface.MadEventCmd(dir_name) self.cmd.define_child_cmd_interface(me_cmd, False) me_cmd.model_name = self.model me_cmd.do_compute_widths(' %s -f --body_decay=2' % particle) # now get the results: pids = set() path = pjoin(dir_name, 'Cards', 'param_card.dat') card = card_reader.ParamCard(path) if pid not in card['decay'].decay_table: return set(), {} for partial_width in card['decay'].decay_table[pid]: pids.update(list(partial_width.lhacode)[1:]) labels = set() for id in pids: part = self.cmd._curr_model.get_particle(id) #if part.get('mass').lower() == 'zero': # continue #if part.get('width').lower() == 'zero': # continue labels.add(part.get('name')) labels.add(part.get('antiname')) os.system('rm -rf %s >/dev/null' % dir_name) me_cmd.do_quit('') return labels, card['decay'].decay_table[pid]
def has_same_decay(self, particle, run_fr=True): """create mg5 directory and then use fr to compare. Returns the ratio of the decay or None if this ratio is not constant for all channel. Check only 2 body. """ enter_time = time.time() dir_name = 'TEST_DECAY_%s_%s' % (self.model, particle) pid = self.particles_id[particle] # clean previous run os.system('rm -rf %s >/dev/null' % dir_name) os.system('rm -rf %s_dec >/dev/null' % dir_name) # # RUN MG5 # start1 = time.time() self.cmd.run_cmd("set automatic_html_opening False --no-save") try: self.cmd.exec_cmd('generate %s > all all --optimize' % particle) except InvalidCmd: return 'True' if self.cmd._curr_amps: self.cmd.exec_cmd('output %s -f' % dir_name) files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'), '%s/Cards/run_card.dat' % dir_name, log=True) self.cmd.exec_cmd("set automatic_html_opening False --no-save") self.cmd.exec_cmd('launch -f') stop_mg5 = time.time() print 'MG5 Running time: %s s ' % (stop_mg5 - start1) # # Run MG Decay module # start4 = time.time() self.cmd.run_cmd("set automatic_html_opening False --no-save") self.cmd.exec_cmd('calculate_width %s 2' % particle) if self.cmd._curr_amps: self.cmd.exec_cmd('output %s_dec -f' % dir_name) files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'), '%s_dec/Cards/run_card.dat' % dir_name, log=True) print "279 launch" self.cmd.exec_cmd('launch -f') stop_mg5 = time.time() print 'DECAY Running time: %s s ' % (stop_mg5 - start4) # # RUN FR DECAY # if run_fr: me_cmd = me_interface.MadEventCmd(dir_name) self.cmd.define_child_cmd_interface(me_cmd, False) start3 = time.time() me_cmd.model_name = self.model me_cmd.run_cmd("set automatic_html_opening False --no-save") me_cmd.do_compute_widths(' %s -f --body_decay=2' % particle) stop_fr = time.time() print 'FR Running time: %s s ' % (stop_fr - start3) out1 = self.compare( pjoin(dir_name, 'Cards', 'param_card.dat'), pjoin(dir_name, 'Events', 'run_01', 'param_card.dat'), pid, 'FR', 'MG5') out2 = self.compare( pjoin(dir_name, 'Cards', 'param_card.dat'), pjoin('%s_dec' % dir_name, 'Events', 'run_01', 'param_card.dat'), pid, 'FR', 'DECAY') me_cmd.do_quit('') if out1 == out2 == 'True': os.system('rm -rf %s >/dev/null' % dir_name) os.system('rm -rf %s_dec >/dev/null' % dir_name) return 'True' else: return out1 + out2 else: return self.compare( pjoin(dir_name, 'Events', 'run_01', 'param_card.dat'), pjoin('%s_dec' % dir_name, 'Events', 'run_01', 'param_card.dat'), pid, 'MG5', 'DECAY')
def launch_program(self): """launch the main program""" # Check for number of cores if multicore mode mode = str(self.cluster) nb_node = 1 if mode == "2": import multiprocessing max_node = multiprocessing.cpu_count() if max_node == 1: logger.warning( 'Only one core is detected on your computer! Pass in single machine' ) self.cluster = 0 self.launch_program() return elif max_node == 2: nb_node = 2 elif not self.force: nb_node = self.ask('How many cores do you want to use?', max_node, range(2, max_node + 1)) else: nb_node = max_node import madgraph.interface.madevent_interface as ME stdout_level = self.cmd_int.options['stdout_level'] if self.shell: usecmd = ME.MadEventCmdShell(me_dir=self.running_dir, options=self.options) else: usecmd = ME.MadEventCmd(me_dir=self.running_dir, options=self.options) usecmd.pass_in_web_mode() #Check if some configuration were overwritten by a command. If so use it set_cmd = [ l for l in self.cmd_int.history if l.strip().startswith('set') ] all_options = usecmd.options_configuration.keys( ) + usecmd.options_madgraph.keys() + usecmd.options_madevent.keys() for line in set_cmd: arg = line.split() if arg[1] not in all_options: continue try: usecmd.do_set(line[3:], log=False) except usecmd.InvalidCmd: pass usecmd.do_set('stdout_level %s' % stdout_level, log=False) #ensure that the logger level launch = self.cmd_int.define_child_cmd_interface(usecmd, interface=False) #launch.me_dir = self.running_dir if self.unit == 'pb': command = 'generate_events %s' % self.name else: warning_text = '''\ This command will create a new param_card with the computed width. This param_card makes sense only if you include all processes for the computation of the width.''' logger.warning(warning_text) command = 'calculate_decay_widths %s' % self.name if mode == "1": command += " --cluster" elif mode == "2": command += " --nb_core=%s" % nb_node if self.force: command += " -f" if self.laststep: command += ' --laststep=%s' % self.laststep try: os.remove('ME5_debug') except: pass launch.run_cmd(command) launch.run_cmd('quit') if os.path.exists('ME5_debug'): return True # Display the cross-section to the screen path = os.path.join(self.running_dir, 'SubProcesses', 'results.dat') if not os.path.exists(path): logger.error('Generation failed (no results.dat file found)') return fsock = open(path) line = fsock.readline() cross, error = line.split()[0:2] logger.info('more information in %s' % os.path.join(self.running_dir, 'index.html'))