def makeCondorFile(logfile, i, runscriptname, condor_base): logfile = os.path.realpath(logfile) submit_file_name = makePathTimeStamped(condor_base) submit_file_name += '_' + str(i) + '.sub' submit_file = open(submit_file_name, 'w') submit_file.write('Universe = vanilla \n') submit_file.write('Executable = ' + runscriptname + ' \n') submit_file.write('Log = ' + logfile + '\n') submit_file.write('Output = ' + logfile.split('.log')[0] + '.out \n') submit_file.write('Error = ' + logfile.split('.log')[0] + '.err \n') submit_file.write('Queue \n') submit_file.close() return submit_file_name
for f_name in f_names: if 'FO' in f_name: continue sub_files = glob.glob(input_name + '/'+f_name+'.root') # # TODO: THIS CODE SEEMS VERY OUTDATED, PLEASE UPDATE # print 'plotting', f_name for f in sub_files: output_dir = os.path.join(os.getcwd(), 'data', 'Results', 'calcSignalEfficiency', f_name, category_split_str, trigger_str, mass_str, flavor_name) output_dir = makePathTimeStamped(output_dir) eff = Efficiency('efficiency_noCategories', None, None, f, subdirs = ['efficiency_noCategories', 'l1_r_l2_e_l3_g']) h = eff.getEfficiency() p = Plot(h, 'V_{'+args.flavor+'N} = 0.01', 'efficiency', h.GetXaxis().GetTitle(), h.GetYaxis().GetTitle(), x_log=True, color_palette = 'Black') p.drawHist(output_dir = output_dir, draw_option = 'EP') # dict_of_categories = {} # dict_of_names = {} # for category in CATEGORIES: # dict_of_categories[category] = [] # dict_of_names[category] = []
args.flavor, '-'.join([region_to_select, args.selection])) in_files = glob.glob(os.path.join(base_path_in, '*')) merge(in_files, __file__, jobs, ('sample', 'subJob'), argParser, istest=args.isTest) if args.inData: os.system("hadd -f " + base_path_in + "/events.root " + base_path_in + '/*/events.root') samples_to_plot = ['Data'] if args.inData else sample_manager.getOutputs() for sample_output in samples_to_plot: if args.isTest and sample_output != 'DY': continue if args.inData: output_dir = makePathTimeStamped(base_path_out) in_file = base_path_in + '/events.root' else: output_dir = makePathTimeStamped(base_path_out + '/' + sample_output) in_file = base_path_in + '/' + sample_output + '/events.root' fakerates = createFakeRatesWithJetBins('tauttl', None, None, in_file) for fr in fakerates.bin_collection: ttl = fakerates.getFakeRate(fr).getEfficiency() p = Plot(signal_hist=ttl, name='ttl_' + fr, year=int(args.year)) p.draw2D(output_dir=output_dir, names=['ttl_' + fr])
argParser.add_argument('flavor', action='store', default=None, help='0: electrons, 1:muons') args = argParser.parse_args() #Merges subfiles if needed merge_files = glob.glob(os.getcwd()+'/data/compareLightLeptonId/*') for mf in merge_files: if "Results" in mf: continue merge(mf) input_signal = glob.glob(os.getcwd()+'/data/compareLightLeptonId/'+args.signal+'/*ROC-'+args.flavor+'.root') bkgr_prefix = os.getcwd()+'/data/compareLightLeptonId/'+args.bkgr from HNL.Plotting.plot import Plot output_dir = makePathTimeStamped(os.getcwd()+'/data/Results/compareLightLeptonId/ROC/'+args.signal+'-'+args.bkgr) curves = [] ordered_f_names = [] for f_path in input_signal: f_name = f_path.rsplit('/', 1)[1].split('.')[0] ordered_f_names.append(f_name) roc_curve = ROC(f_name.split('-')[0], 1., '', f_path, misid_path =bkgr_prefix + '/'+f_name+'.root') curves.append(roc_curve.returnGraph()) p = Plot(curves, ordered_f_names, args.signal+'_'+args.flavor, 'efficiency', 'misid', y_log=True) p.drawGraph(output_dir = output_dir) from HNL.Tools.efficiency import Efficiency from HNL.Tools.helpers import rootFileContent from ROOT import TFile var = ['pt', 'eta'] inputFiles = {'efficiency' : glob.glob(os.getcwd()+'/data/compareLightLeptonId/'+args.signal+'/efficiency-'+str(args.flavor)+'.root'), 'fakerate': glob.glob(os.getcwd()+'/data/compareLightLeptonId/'+args.bkgr+'/fakerate-'+str(args.flavor)+'.root')}
v, eff_list[0].GetXaxis().GetTitle(), eff_list[0].GetYaxis().GetTitle(), extra_text=extra_text) if '2D' in v: p.draw2D(output_dir=out_dir + '/' + sample) else: p.drawHist(output_dir=out_dir + '/' + sample) exit(0) for f_name in f_names: if args.isTest: output_dir = makePathTimeStamped(os.getcwd() + '/data/testArea/Results/' + args.separateTriggers + '/' + f_name) else: output_dir = makePathTimeStamped(os.getcwd() + '/data/Results/' + args.separateTriggers + '/' + f_name) hists = {} keyNames = [] sub_files = glob.glob(os.getcwd() + '/data/calcTriggerEff/*/' + args.separateTriggers + '/' + f_name + '.root') hists = {} file_name_comp = {} print 'plotting', f_name for f in sub_files: split_f = f.split('/')
if args.compareTriggerCuts is None: if args.divideByCategory is not None: for cut_key in efficiency.keys(): for sk_key in SUPER_CATEGORIES.keys(): efficiency[cut_key][sk_key] = {} for icat, cat_key in enumerate(SUPER_CATEGORIES[sk_key]): if icat == 0: efficiency[cut_key][sk_key]['regularRun'] = efficiency[cut_key][cat_key]['regularRun'].clone() else: if args.divideByCategory == 'both': efficiency[cut_key][sk_key]['regularRun'].add(efficiency[cut_key][cat_key]['regularRun']) else: efficiency[cut_key][sk_key]['regularRun'].addNumeratorOnly(efficiency[cut_key][cat_key]['regularRun']) if args.isTest: output_dir = makePathTimeStamped(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'EventSelection', 'data', 'testArea', 'Results', __file__.split('.')[0].rsplit('/')[-1], category_split_str, trigger_str, '-'.join([args.strategy, args.region, args.selection]), args.flavor, cut_str, args.year)) else: output_dir = makePathTimeStamped(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'EventSelection', 'data', 'Results', __file__.split('.')[0].rsplit('/')[-1], category_split_str, trigger_str, '-'.join([args.strategy, args.region, args.selection]), args.flavor, cut_str, args.year)) legend_dict = { 'noFilter' : 'No Filter', 'threeLeptonGenFilter': '#splitline{At least 3 gen light leptons}{with p_{T} > 5 GeV}', 'threeLeptonGenFilter7GeV': '#splitline{At least 3 gen light leptons}{with p_{T} > 7 GeV}', 'hadronicTauGenFilter': '#splitline{At least 1 gen #tau_{h}}{with p_{T} > 18 GeV}', 'tauPlusLightGenFilter': '#splitline{At least 1 gen #tau_{h} with p_{T} > 18 GeV}{and 1 light lepton w p_{T} > 15 GeV}', 'threeLeptonGenFilterInverted': '#splitline{No more than 3 gen light leptons}{with p_{T} > 5 GeV}', 'threeLeptonGenFilter7GeVInverted': '#splitline{No more than 3 gen light leptons}{with p_{T} > 7 GeV}', 'hadronicTauGenFilterInverted': '#splitline{No gen #tau_{h}}{with p_{T} > 18 GeV}', 'tauPlusLightGenFilterInverted': '#splitline{No 1 gen #tau_{h} with p_{T} > 18 GeV}{and 1 light lepton w p_{T} > 5 GeV}',
observed_AN = getObjFromFile(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsElectronMixing.root'), 'observed_promptDecays') expected_AN = getObjFromFile(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsElectronMixing.root'), 'expected_central') tex_names = ['observed (EXO-17-012)', 'expected (EXO-17-012)'] elif args.flavor == 'mu': observed_AN = getObjFromFile(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsMuonMixing.root'), 'observed_promptDecays') expected_AN = getObjFromFile(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsMuonMixing.root'), 'expected_central') tex_names = ['observed (EXO-17-012)', 'expected (EXO-17-012)'] else: observed_AN = None expected_AN = None tex_names = None coupling_dict = {'tau':'#tau', 'mu':'#mu', 'e':'e', '2l':'l'} from HNL.Plotting.plot import Plot destination = makePathTimeStamped(os.path.expandvars('$CMSSW_BASE/src/HNL/Stat/data/Results/runAsymptoticLimits/'+args.strategy+'-'+args.selection+'/'+args.flavor+'/'+card+'/'+ year_to_read)) if observed_AN is None and expected_AN is None: bkgr_hist = None else: bkgr_hist = [observed_AN, expected_AN] if args.compareToCards is not None: for compare_key in compare_graphs.keys(): compare_sel, compare_reg = compare_key.split(' ') if bkgr_hist is None: bkgr_hist = [compare_graphs[compare_key][0]] tex_names = [compare_dict[compare_sel] + ' ' +compare_reg] else: bkgr_hist.append(compare_graphs[compare_key][0]) tex_names.append(compare_dict[compare_sel] + ' ' +compare_reg)
list_of_errors[is_signal_str][sn][v][sr] for v in CATEGORIES ] list_of_values[is_signal_str][sn]['total'][sr], list_of_errors[ is_signal_str][sn]['total'][sr] = mergeValues( values_to_merge, errors_to_merge) search_region_keys = range( 1, srm[args.region].getNumberOfSearchRegions() + 1) + srm[args.region].getListOfSearchRegionGroups() + ['total'] from HNL.Tools.helpers import makePathTimeStamped from HNL.Plotting.plottingTools import extraTextFormat from HNL.Tools.helpers import getObjFromFile, rootFileContent, tab destination = makePathTimeStamped( os.path.expandvars( '$CMSSW_BASE/src/HNL/Analysis/data/Results/calcYields/' + args.selection + '/' + args.region + '/' + args.flavor)) coupling_squared = args.coupling**2 if args.rescaleSignal is None else args.rescaleSignal if args.makeDataCards is not None: from HNL.Stat.combineTools import makeDataCard # # If we just want cut and count without shapes, simply write datacards for everything you have # if args.makeDataCards == 'cutAndCount': for ac in ['total'] + SUPER_CATEGORIES.keys(): for sr in search_region_keys: for s in list_of_values['signal'].keys(): sig_yield = list_of_values['signal'][s][ac][sr]
import os skipDirs = ['documents', 'log', '.git', 'virenv', 'utils'] skipFiles = [] extensions_to_copy = ['root', 'pdf', 'png'] file_paths = [] base_path = os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL') for root, dirs, files in os.walk(base_path, topdown=True): dirs[:] = [d for d in dirs if d not in skipDirs] root_files = [ os.path.join(root, f) for f in files if f.split('.')[-1] in extensions_to_copy and f not in skipFiles ] if len(root_files) != 0: for ext in extensions_to_copy: file_paths.append(os.path.join(root, '*.' + ext)) cmssw_version = os.path.expandvars('$CMSSW_BASE').rsplit('/', 1)[-1] central_destination = makePathTimeStamped('/user/lwezenbe/private/Backup/' + cmssw_version + '/AllOutput') for rf in file_paths: try: index_for_backup = rf.split('/').index('src') except: index_for_backup = None backup_path = '/'.join([central_destination] + rf.split('/')[index_for_backup + 1:-1]) makeDirIfNeeded(backup_path + '/x') os.system('scp ' + rf + ' ' + backup_path + '/.')
observed_AN = getObjFromFile( os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsMuonMixing.root'), 'observed_promptDecays') expected_AN = getObjFromFile( os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'StateOfTheArt', 'limitsMuonMixing.root'), 'expected_central') tex_names = ['observed (AN-2017-014)', 'expected (AN-2017-014)'] else: observed_AN = None expected_AN = None tex_names = None coupling_dict = {'tau': '#tau', 'mu': '#mu', 'e': 'e', '2l': 'l'} from HNL.Plotting.plot import Plot destination = makePathTimeStamped( os.path.expandvars( '$CMSSW_BASE/src/HNL/Stat/data/Results/runAsymptoticLimits/' + args.flavor)) p = Plot(graphs, tex_names, 'limits', bkgr_hist=[observed_AN, expected_AN], y_log=True, x_log=True, x_name='m_{N} [GeV]', y_name='|V_{' + coupling_dict[args.flavor] + ' N}|^{2}') p.drawBrazilian(output_dir=destination)
list_of_values[is_signal][sample.output][c][sr]= tmp_hist.GetBinContent(1) list_of_errors[is_signal][sample.output][c][sr]= tmp_hist.GetBinError(1) # # Add some grouped search regions for easier access # for group_name in srm.getListOfSearchRegionGroups(): list_of_values[is_signal][sample.output][c][group_name], list_of_errors[is_signal][sample.output][c][group_name] = mergeSearchRegions(srm.getGroupValues(group_name), list_of_values[is_signal][sample.output][c], list_of_errors[is_signal][sample.output][c], str(c)+'_'+str(group_name)) list_of_values[is_signal][sample.output][c]['total'], list_of_errors[is_signal][sample.output][c]['total'] = mergeSearchRegions(range(1, srm.getNumberOfSearchRegions()+1), list_of_values[is_signal][sample.output][c], list_of_errors[is_signal][sample.output][c], str(c)+'_'+str('total')) search_region_names = range(1, srm.getNumberOfSearchRegions()+1) + srm.getListOfSearchRegionGroups() + ['total'] from HNL.Tools.helpers import makePathTimeStamped from HNL.Plotting.plottingTools import extraTextFormat destination = makePathTimeStamped(os.path.expandvars('$CMSSW_BASE/src/HNL/EventSelection/data/Results/eventsPerCategory/'+selection_str+'/'+mass_str)) # # Make text files if requested # if not args.noTextFiles: from HNL.Tools.helpers import getObjFromFile, rootFileContent, makeDirIfNeeded from ROOT import TFile for sr in search_region_names: makeDirIfNeeded(destination+'/Tables/table_'+str(sr)+'.txt') out_file = open(destination+'/Tables/table_'+str(sr)+'.txt', 'w') out_file.write('\t \t tte \t ttm \t tee \t tem \t tmm \t lll \t total \n')
from HNL.Tools.mergeFiles import merge import glob from HNL.Tools.helpers import mergeHistograms from HNL.Plotting.plot import Plot base_path = getOutputBase() in_files = glob.glob(os.path.join(base_path, '*')) merge(in_files, __file__, jobs, ('sample', 'subJob'), argParser, istest=args.isTest) base_path_split = base_path.rsplit('/data/') output_dir = makePathTimeStamped(base_path_split[0] + '/data/Results/' + base_path_split[1]) closureObjects = {} for in_file in in_files: if 'Results' in in_file: continue if 'isCheck' in in_file and not args.isCheck: continue sample_name = in_file.rsplit('/', 1)[-1] closureObjects[sample_name] = {} for c in getCategories(): closureObjects[sample_name][c] = {} for v in var: closureObjects[sample_name][c][v] = ClosureObject( 'closure-' + v + '-' + c, None, None, in_file + '/events.root') if not args.inData and not args.stackMC: