def simplistic_shift_bg_to_signal(path, procs): """ open datacards located at path, search for the indices for the processes listed in procs. For those processes switch the sign of the index to change the definition from BG to sig. """ proc_old = [] proc_names = [] file = open(path, 'r') for line in file : words = line.lstrip().split() if words[0] == 'process' : if is_number(words[1]) : proc_old = words[1:] else : proc_names = words[1:] file.close() proc_line = 'process\t'+'\t'.join(proc_old) for j in range(len(procs)) : for i in range(len(proc_old)) : if proc_names[i] == procs[j] : proc_old[i] = str(int(proc_old[0])-j-1) #print 'process\t'+'\t'.join(proc_old) #print 'process\t'+'\t'.join(proc_names) source = open(path, 'r') target = open(path+'_tmp', 'w') for line in source : words = line.lstrip().split() if words[0] == 'process' : if is_number(words[1]) : line = 'process\t'+'\t'.join(proc_old)+'\n' else : line = 'process\t'+'\t'.join(proc_names)+'\n' target.write(line) os.system("mv {SOURCE} {TARGET}".format(SOURCE=path+'_tmp', TARGET=path)) return
def submit(name, key, masses) : ''' prepare the submission script ''' submit_name = '%s_submit.sh' % name with open(submit_name, 'w') as submit_script: if options.lxq : submit_script.write('export scram_arch=$SCRAM_ARCH\n') submit_script.write('export cmssw_base=$CMSSW_BASE\n') if not os.path.exists(name): os.system("mkdir -p %s" % name) ##print masses for i, mass in enumerate(masses[key]): dir=key+'/'+mass if not is_number(dir[dir.rstrip('/').rfind('/')+1:]) : continue ## do not submit jobs on old LSF output if 'LSFJOB' in dir: continue log.info(" Generating submision script for %s", dir) script_file_name = '%s/%s_%i.sh' % (name, name, i) with open(script_file_name, 'w') as script: script.write(script_template.format( working_dir = os.getcwd(), directory = dir )) os.system('chmod a+x %s' % script_file_name) if options.lxq : submit_script.write('qsub -l site=hh -j y -o /dev/null -l h_vmem=4000M -v scram_arch -v cmssw_base %s\n' % script_file_name) else : os.system('touch {PWD}/log/{LOG}'.format( PWD=os.getcwd(), LOG=script_file_name[script_file_name.rfind('/')+1:].replace('.sh', '.log'))) submit_script.write('bsub -q 8nh -oo {PWD}/log/{LOG} {PWD}/{FILE}\n'.format( LOG=script_file_name[script_file_name.rfind('/')+1:].replace('.sh', '.log'), PWD=os.getcwd(), FILE=script_file_name)) os.system('chmod a+x %s' % submit_name)
def submit(name, key, masses): """ prepare the submission script """ submit_name = "%s_submit.sh" % name with open(submit_name, "w") as submit_script: if options.condor: submit_script.write(condor_sub_template) if options.lxq: submit_script.write("export cmssw_base=$CMSSW_BASE\n") if not os.path.exists(name): os.system("mkdir -p %s" % name) ##print masses for i, mass in enumerate(masses[key]): dir = key + "/" + mass if not is_number(dir[dir.rstrip("/").rfind("/") + 1 :]): continue ## do not submit jobs on old LSF output if "LSFJOB" in dir: continue log.info(" Generating submision script for %s", dir) script_file_name = "%s/%s_%i.sh" % (name, name, i) with open(script_file_name, "w") as script: script.write( script_template.format( working_dir=os.getcwd(), directory=dir, OLD="--old" if options.old else "", MODEL=options.modelname, ANATYPE=options.ana_type, MSSMvsSM="--MSSMvsSM" if options.MSSMvsSM else "", SMARTGRID="--smartGrid" if options.smartGrid else "", customTanb=("--customTanb " + options.customTanb) if not options.customTanb == "" else "", ) ) os.system("chmod a+x %s" % script_file_name) if options.condor: submit_script.write("\n") submit_script.write("executable = %s/%s\n" % (os.getcwd(), script_file_name)) submit_script.write("output = %s/%s\n" % (os.getcwd(), script_file_name.replace(".sh", ".stdout"))) submit_script.write("error = %s/%s\n" % (os.getcwd(), script_file_name.replace(".sh", ".stderr"))) submit_script.write("queue\n") elif options.lxq: submit_script.write("qsub -j y -o /dev/null -l h_vmem=2000M -v cmssw_base %s\n" % script_file_name) else: os.system( "touch {PWD}/log/{LOG}".format( PWD=os.getcwd(), LOG=script_file_name[script_file_name.rfind("/") + 1 :].replace(".sh", ".log") ) ) submit_script.write( "bsub -q 8nh -oo {PWD}/log/{LOG} {PWD}/{FILE}\n".format( LOG=script_file_name[script_file_name.rfind("/") + 1 :].replace(".sh", ".log"), PWD=os.getcwd(), FILE=script_file_name, ) ) os.system("chmod a+x %s" % submit_name)
def directories(args) : ## prepare structure of parent directories dirs = [] for dir in args : if is_number(get_mass(dir)) or get_mass(dir) == "common" : dir = dir[:dir.rstrip('/').rfind('/')] if not dir in dirs : dirs.append(dir) ## prepare mapping of masses per parent directory masses = {} for dir in dirs : buffer = [] for path in args : if dir+'/' in path : if is_number(get_mass(path)) : mass = get_mass(path) if not contained(mass, buffer) : buffer.append(mass) masses[dir] = list(buffer) return (dirs, masses)
def submit(name, key, masses) : ''' prepare the submission script ''' submit_name = '%s_submit.sh' % name with open(submit_name, 'w') as submit_script: if options.condor: submit_script.write(condor_sub_template) if options.lxq : submit_script.write('export cmssw_base=$CMSSW_BASE\n') if not os.path.exists(name): os.system("mkdir -p %s" % name) ##print masses for i, mass in enumerate(masses[key]): dir=key+'/'+mass if not is_number(dir[dir.rstrip('/').rfind('/')+1:]) : continue ## do not submit jobs on old LSF output if 'LSFJOB' in dir: continue log.info(" Generating submision script for %s", dir) script_file_name = '%s/%s_%i.sh' % (name, name, i) with open(script_file_name, 'w') as script: script.write(script_template.format( working_dir = os.getcwd(), directory = dir, MODEL = options.modelname, ANATYPE = options.ana_type, MSSMvsSM = "--MSSMvsSM" if options.MSSMvsSM else "", SMARTGRID= "--smartGrid" if options.smartGrid else "", customTanb = ("--customTanb " + options.customTanb) if not options.customTanb == "" else "", FINEGRID = "fineGrid" if options.fineGrid else "")) os.system('chmod a+x %s' % script_file_name) if options.condor : submit_script.write("\n") submit_script.write( "executable = %s/%s\n" % (os.getcwd(), script_file_name)) submit_script.write( "output = %s/%s\n" % ( os.getcwd(), script_file_name.replace('.sh', '.stdout'))) submit_script.write( "error = %s/%s\n" % (os.getcwd(), script_file_name.replace('.sh', '.stderr'))) submit_script.write("queue\n") elif options.lxq : submit_script.write('qsub -j y -o /dev/null -l h_vmem=4000M -v cmssw_base %s %s\n' % (bsubargs, script_file_name)) else : os.system('touch {PWD}/log/{LOG}'.format( PWD=os.getcwd(), LOG=script_file_name[script_file_name.rfind('/')+1:].replace('.sh', '.log'))) submit_script.write('bsub -q 8nh -oo {BSUBARGS} {PWD}/log/{LOG} {PWD}/{FILE}\n'.format( BSUBARGS=bsubargs, LOG=script_file_name[script_file_name.rfind('/')+1:].replace('.sh', '.log'), PWD=os.getcwd(), FILE=script_file_name)) os.system('chmod a+x %s' % submit_name)
def simplistic_shift_bg_to_signal(path, procs): """ open datacards located at path, search for the indices for the processes listed in procs. For those processes switch the sign of the index to change the definition from BG to sig. """ proc_old = [] proc_names = [] file = open(path, 'r') for line in file : words = line.lstrip().split() if words[0] == 'process' : if is_number(words[1]) : proc_old = words[1:] else : proc_names = words[1:] file.close() proc_line = 'process\t'+'\t'.join(proc_old) for j in range(len(procs)) : for i in range(len(proc_old)) : if proc_names[i] == procs[j] : proc_old[i] = str(int(proc_old[0])-j-1) #print 'process\t'+'\t'.join(proc_old) #print 'process\t'+'\t'.join(proc_names) source = open(path, 'r') target = open(path+'_tmp', 'w') for line in source : words = line.lstrip().split() if words[0] == 'shapes' : for sig in ['ggH','qqH'] : if sig in line : line+='\n'+line.replace(sig,sig+'_hww').replace('$MASS','125')+'\n' if words[0] == 'process' : if is_number(words[1]) : line = 'process\t'+'\t'.join(proc_old)+'\n' else : line = ('process\t'+'\t'.join(proc_names)+'\n').replace('hww125','hww') target.write(line) os.system("mv {SOURCE} {TARGET}".format(SOURCE=path+'_tmp', TARGET=path)) return
if options.optInject : ## the input for lxb-injected.py should be a path, that is passed on as an ## option and the masses in question. Prepare here the corresponding paths ## and directories. paths = [] dirs = {} for dir in args : head = dir[:dir.rstrip('/').rfind('/')] if not contained(head, paths) : paths.append(head) dirs[head] = [] for dir in args : for path in paths : if path in dir : tail = dir[dir.rstrip('/').rfind('/')+1:] if is_number(tail) : dirs[path].append(tail) if not options.calculate_injected : ## prepare options opts = options.opt opts+=" --observedOnly" if not options.nuisances == "" : opts+=" --no-prefit --external-pulls \"{PATH}\" --signal-plus-background {SPLUSB}".format(PATH=options.nuisances, SPLUSB=options.signal_plus_BG) method = options.injected_method#"--asymptotic" if options.injected_method == "significance" : method = "--significance-frequentist" if options.injected_method == "pvalue" : method = "--pvalue-frequentist" if options.injected_method == "max-likelihood" : method = "--max-likelihood" preinject = ""