コード例 #1
0
ファイル: calcSignalEfficiency.py プロジェクト: lwezenbe/HNL
def createEfficiencies(output_name, event_categories, var_for_eff):
    efficiency = {}

    if args.divideByCategory is None:
        efficiency['noCategories'] = {}
    else:
        for c in event_categories:
            efficiency[c] = {}

    bins_for_eff = var_for_eff['HNLmass'][1] if not args.makePlots else None
    if args.compareTriggerCuts is None:
        for k in efficiency.keys():
            efficiency[k]['regularRun'] = Efficiency('efficiency_'+str(k), var_for_eff['HNLmass'][0], var_for_eff['HNLmass'][2], output_name, bins=bins_for_eff, 
                                                    subdirs=['efficiency_'+str(k), 'l1_'+str('r')+'_l2_'+str('e')+'_l3_'+str('g')])
    elif args.compareTriggerCuts == 'full':
        if args.divideByCategory is None:
            print "Inconsistent input: This mode is to be used together with divideByCategory. Exiting"
            exit(0)
        for k in efficiency.keys():
            efficiency[k]['full'] = Efficiency('efficiency_'+str(k), var_for_eff['HNLmass'][0], var_for_eff['HNLmass'][2], output_name, bins=bins_for_eff, 
                                            subdirs=['efficiency_'+str(k), 'l1_'+str('f')+'_l2_'+str('u')+'_l3_'+str('l')])
            # efficiency[k]['full'] = Efficiency('efficiency_'+str(k), var_for_eff['HNLmass'][0], var_for_eff['HNLmass'][2], output_name, bins=bins_for_eff)
    else: #'single' or 'cumulative'
        if args.divideByCategory is None:
            print "Inconsistent input: This mode is to be used together with divideByCategory. Exiting"
            exit(0)
        for c in event_categories:
            for ptcuts in returnCategoryPtCuts(c):
                efficiency[c][ptcuts] = Efficiency('efficiency_'+str(c)+'_l1_'+str(ptcuts[0])+'_l2_'+str(ptcuts[1])+'_l3_'+str(ptcuts[2]), 
                    var_for_eff['HNLmass'][0], var_for_eff['HNLmass'][2], output_name, bins=bins_for_eff, subdirs=['efficiency_'+str(c), 
                    'l1_'+str(ptcuts[0])+'_l2_'+str(ptcuts[1])+'_l3_'+str(ptcuts[2])])

    return efficiency
コード例 #2
0
ファイル: plotEfficiency.py プロジェクト: gmestdac/HNL
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] = []
    
#         rf = ROOT.TFile(f)
#         if args.triggerTest or args.cumulativeCuts:    get_nested = True
コード例 #3
0
    if "Results" in mf: merge_files.pop(merge_files.index(mf))
    if not args.onlyReco and 'onlyReco' in mf: merge_files.pop(merge_files.index(mf))
script = os.path.expandvars(os.path.join('$CMSSW', 'src', 'HNL', 'ObjectSelection', 'compareTauID.py'))
merge(merge_files, script, jobs, ('sample', 'subJob'), argParser, istest=args.isTest)

list_of_bkgr_eff = {}
list_of_signal_eff = {}
list_of_bkgr_pt = {}
list_of_signal_pt = {}

inputfiles_eff = glob.glob(input_file_path + '*/*root')
samples = {f.split('/')[-2] for f in inputfiles_eff}
from HNL.Tools.efficiency import Efficiency
from HNL.Tools.helpers import getObjFromFile
for sample in samples:
    eff = Efficiency('efficiency_pt', None, None, input_file_path + sample+'/efficiency.root', subdirs = ['deeptauVSjets-none-none-'+args.wp, 'efficiency_pt'])
    if 'HNL' in sample:
        list_of_signal_eff[sample] = eff.getEfficiency() 
        list_of_signal_pt[sample] = getObjFromFile(os.path.expandvars('$CMSSW_BASE/src/HNL/Test/data/plotTau/gen/' + sample + '/variables.root'), 'pt/'+sample+'-pt')
        list_of_signal_pt[sample].Scale(1./list_of_signal_pt[sample].GetSumOfWeights())
    else:
        list_of_bkgr_eff[sample] = eff.getEfficiency()
        list_of_bkgr_pt[sample] = getObjFromFile(os.path.expandvars('$CMSSW_BASE/src/HNL/Test/data/plotTau/gen/' + sample + '/variables.root'), 'pt/'+sample+'-pt')
        list_of_bkgr_pt[sample].Scale(1./list_of_bkgr_pt[sample].GetSumOfWeights())

from HNL.Plotting.plot import Plot

if args.isTest:
    output_dir = os.getcwd()+'/data/testArea/Results/compareTauID/includeReco/'
else:
    output_dir = os.getcwd()+'/data/Results/compareTauID/includeReco/'
コード例 #4
0
ファイル: compareLightLeptonId.py プロジェクト: gmestdac/HNL
            lambda c: c.eta_l,
            np.arange(-2.5, 3., 0.5),
            ('#eta^{#tau}(offline) [GeV]', 'Efficiency')
        ]
    }

    list_of_var_hist['efficiency'][algo] = {}
    list_of_var_hist['fakerate'][algo] = {}
    for v in var_hist.keys():
        list_of_var_hist['efficiency'][algo][v] = {}
        list_of_var_hist['fakerate'][algo][v] = {}
        for wp in algo_wp:
            tot_name = output_name + '/' + sample.name + '_efficiency-' + str(
                args.flavor) + '_' + args.subJob + '.root'
            list_of_var_hist['efficiency'][algo][v][wp] = Efficiency(
                'efficiency_' + v + algo, var_hist[v][0], var_hist[v][2],
                tot_name, var_hist[v][1])
            tot_name = output_name + '/' + sample.name + '_fakerate-' + str(
                args.flavor) + '_' + args.subJob + '.root'
            list_of_var_hist['fakerate'][algo][v][wp] = Efficiency(
                'fakerate_' + v + algo, var_hist[v][0], var_hist[v][2],
                tot_name, var_hist[v][1])

#Determine if testrun so it doesn't need to calculate the number of events in the getEventRange
if args.isTest:
    event_range = xrange(150)
else:
    event_range = sample.getEventRange(int(args.subJob))

from HNL.Tools.helpers import progress
from HNL.ObjectSelection.electronSelector import isBaseElectron
コード例 #5
0
ファイル: plotLightLepId.py プロジェクト: gmestdac/HNL
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')}
for eff_name in ['efficiency', 'fakerate']:
    for f in inputFiles[eff_name]:
        print f
        rf = TFile(f)
        key_names = [k[0] for k in rootFileContent(rf)]
        filtered_key_names = {fk.rsplit('-', 1)[0].split('/')[-1] for fk in key_names}
        list_of_eff = {}
        for fk in filtered_key_names: #algo
            list_of_eff[fk] = {}
            sample = f.split('/')[-2]
            for k in [i.split('-', 1)[1] for i in key_names if fk in i]: #wps
                list_of_eff[fk][k] = {}
                for v in var:
                    list_of_eff[fk][k][v] = Efficiency(eff_name+'_'+v, None, None, f, subdirs = [fk+'-'+k, eff_name+'_'+v])
                
        for fk in filtered_key_names: #algo
            for v in var:
                bkgr_hist = getObjFromFile(f, fk+'-'+k+'/'+eff_name+'_'+v+'/'+eff_name+'_'+v+'_denom')
                tmp_list = [list_of_eff[fk][i][v] for i in list_of_eff[fk].keys()]
                scale_factor = 0.25 if v == 'pt' else 1.
                bkgr_hist.Scale(scale_factor*tmp_list[0].getEfficiency().GetSumOfWeights()/bkgr_hist.GetSumOfWeights())
                p = Plot([efficiency.getEfficiency() for efficiency in tmp_list], [i+' '+fk for i in list_of_eff[fk].keys()]+['lepton distribution'],  eff_name+'_'+args.flavor+'_'+v, bkgr_hist = bkgr_hist)
                p.drawHist(output_dir = os.getcwd()+'/data/Results/compareLightLeptonId/'+fk+'/var/'+sample, draw_option = 'Hist')
                
        
 
#graph = roc_curve.return_graph()
#import ROOT
#c = ROOT.TCanvas('x', 'x')
コード例 #6
0
ファイル: calcTriggerEff.py プロジェクト: lwezenbe/HNL
        'l3-2D' : (lambda c : (c.l_pt[2], abs(c.l_eta[2])),      (np.arange(0., 100., 15.), np.arange(0., 3., .5)), ('p_{T}(l3) [GeV]', '|#eta|(subleading)'))}

if chain.is_signal:
    var['HNLmass'] = (lambda c : c.HNLmass,        np.array(mass_range),   ('m_{N} [GeV]', 'Efficiency'))

from HNL.Tools.efficiency import Efficiency
from HNL.EventSelection.eventCategorization import returnCategoryTriggers
from HNL.Triggers.triggerSelection import applyCustomTriggers
eff = {}
for c in categories:
    for v in {k for k in var.keys()}:
        for t in category_map[c]:
            if args.separateTriggers is None or args.separateTriggers == 'full':
                name = str(c)+ '_' +v + '_' + t
                if v != 'HNLmass':
                    eff[(c, v, t)] = Efficiency(name, var[v][0], var[v][2], getOutputName(v), var[v][1], subdirs=['efficiency_'+str(c), v, 'allTriggers'])
                else:
                    eff[(c, v, t)] = Efficiency(name, var[v][0], var[v][2], getOutputName(v), var[v][1], subdirs=['efficiency_'+str(c), v, 'allTriggers'])
                makeDirIfNeeded(getOutputName(v))
            else:
                for i, trigger in enumerate(category_triggers(chain, c)):
                    name = str(c)+ '_' +v + '_' + t +'_'+str(i)
                    if v != 'HNLmass':
                        eff[(c, v, t, i)] = Efficiency(name, var[v][0], var[v][2], getOutputName(v), var[v][1], subdirs=['efficiency_'+str(c), v, str(returnCategoryTriggerNames(c)[i])])
                    else:
                        eff[(c, v, t, i)] = Efficiency(name, var[v][0], var[v][2], getOutputName(v), var[v][1], subdirs=['efficiency_'+str(c), v, str(returnCategoryTriggerNames(c)[i])])
                    makeDirIfNeeded(getOutputName(v))
                
#
# Set event range
#
コード例 #7
0
ファイル: plotTriggerInfo.py プロジェクト: lwezenbe/HNL
            extra_text = [extraTextFormat(CATEGORY_TEX_NAMES[cat], ypos=0.83)
                          ] if cat is not None else None
            var = [
                k[0].split('/')[-1]
                for k in rootFileContent(rf,
                                         starting_dir='efficiency_' + str(cat))
            ]
            for v in var:
                if args.separateTriggers is None or args.separateTriggers == 'full':
                    trigger_list = ['allTriggers']
                else:
                    trigger_list = returnCategoryTriggerNames(cat)
                eff_lists[cat][v] = [
                    Efficiency('_'.join([str(cat), v, 'integral',
                                         str(i)]),
                               None,
                               None,
                               sub_f,
                               subdirs=['efficiency_' + str(cat), v, t])
                    for i, t in enumerate(trigger_list)
                ]
        rf.Close()

        if not args.ignoreCategories:
            for trigger_cat_name in sorted(TRIGGER_CATEGORIES.keys()):
                to_merge = [
                    eff_lists[c] for c in TRIGGER_CATEGORIES[trigger_cat_name]
                ]
                eff_lists[trigger_cat_name] = mergeEfficiencies(
                    to_merge, trigger_cat_name)

                for v in eff_lists[trigger_cat_name].keys():
コード例 #8
0
ファイル: plotTauID.py プロジェクト: gmestdac/HNL
                    for k in glob.glob(ip + '/' + algo + '/*')
                    if not 'all' in k
                }
            ]

        if args.includeReco == 'noIso' and d == 'iso':
            rf = TFile(ip + '/' + default_iso_algo + '/None/efficiency.root')
            var = [k[0].split('/')[1] for k in rootFileContent(rf)]
            rf.Close()

            for v in var:
                list_of_eff = []
                var_hist = []
                eff_signal = Efficiency(
                    'efficiency',
                    None,
                    None,
                    ip + '/' + default_iso_algo + '/None/efficiency.root',
                    subdirs=[v, default_iso_algo + '-None'])
                list_of_eff.append(eff_signal.getEfficiency())
                var_hist_signal = eff_signal.getDenominator()
                var_hist_signal.Scale(1. / var_hist_signal.GetSumOfWeights())
                var_hist.append(var_hist_signal)
                if args.overlaySignalAndBackground:
                    eff_bkgr = Efficiency(
                        'efficiency',
                        None,
                        None,
                        input_paths['background'][d][0] + '/' +
                        default_iso_algo + '/None/efficiency.root',
                        subdirs=[v, default_iso_algo + '-None'])
                    var_hist_bkgr = eff_bkgr.getDenominator()
コード例 #9
0
ec = EventCategory(chain)

from HNL.Tools.efficiency import Efficiency
from HNL.EventSelection.oldEventCategorization import returnCategoryPtCuts

efficiency = {}

if not args.divideByCategory:
    efficiency['noCategories'] = {}
else:
    for c in ec.categories:
        efficiency[c] = {}

if args.compareTriggerCuts is None:
    for k in efficiency.keys():
        efficiency[k]['regularRun'] = Efficiency('efficiency_'+str(k), var['HNLmass'][0], var['HNLmass'][2], output_name, bins=var['HNLmass'][1])
elif args.compareTriggerCuts == 'full':
    if not args.divideByCategory:
        print "Inconsistent input: This mode is to be used together with divideByCategory. Exiting"
        exit(0)
    for k in efficiency.keys():
        efficiency[k]['full'] = Efficiency('efficiency_'+str(k), var['HNLmass'][0], var['HNLmass'][2], output_name, bins=var['HNLmass'][1])
else: #'single' or 'cumulative'
    if not args.divideByCategory:
        print "Inconsistent input: This mode is to be used together with divideByCategory. Exiting"
        exit(0)
    for c in ec.categories:
        for ptcuts in returnCategoryPtCuts(c):
            efficiency[c][ptcuts] = Efficiency('efficiency_'+str(c)+'_l1_'+str(ptcuts[0])+'_l2_'+str(ptcuts[1])+'_l3_'+str(ptcuts[2]), var['HNLmass'][0], var['HNLmass'][2], output_name, bins=var['HNLmass'][1])

#
コード例 #10
0
 for eff_or_fake in ['efficiency', 'fakerate']:
     list_of_var_hist[eff_or_fake][discr] = {}
     for algo in algos[discr]:
         list_of_var_hist[eff_or_fake][discr][algo] = {}
         for v in var_hist.keys():
             list_of_var_hist[eff_or_fake][discr][algo][v] = {}
             if discr != 'iso' or args.includeReco == 'noIso' or not args.makeCombinations:
                 for wp in algos[discr][algo]:
                     out_path = output_name(
                         discr, algo, wp
                     ) + '/' + sample.name + '_' + eff_or_fake + subjobAppendix + '.root'
                     list_of_var_hist[eff_or_fake][discr][algo][v][
                         wp] = Efficiency('-'.join(
                             [eff_or_fake, v, algo,
                              str(wp)]),
                                          var_hist[v][0],
                                          var_hist[v][2],
                                          out_path,
                                          var_hist[v][1],
                                          subdirs=[v, algo + '-' + str(wp)])
             else:
                 for wp in algos[discr][algo]:
                     out_path = output_name(
                         discr, algo, wp
                     ) + '/' + sample.name + '_' + eff_or_fake + subjobAppendix + '.root'
                     list_of_var_hist[eff_or_fake][discr][algo][v][wp] = {}
                     for ele_wp in algos['ele'][linkIsoToLep('ele', algo)]:
                         list_of_var_hist[eff_or_fake][discr][algo][v][wp][
                             ele_wp] = {}
                         for mu_wp in algos['mu'][linkIsoToLep('mu', algo)]:
                             list_of_var_hist[eff_or_fake][discr][algo][v][
                                 wp][ele_wp][mu_wp] = Efficiency(
コード例 #11
0
if chain.is_signal:
    var['HNLmass'] = (lambda c: c.HNLmass, np.array(mass_range),
                      ('m_{N} [GeV]', 'Efficiency'))

from HNL.Tools.efficiency import Efficiency
from HNL.EventSelection.eventCategorization import returnCategoryTriggers
from HNL.Triggers.triggerSelection import applyCustomTriggers
eff = {}
for c in categories:
    for v in {k for k in var.keys()}:
        for t in category_map[c]:
            if args.separateTriggers is None or args.separateTriggers == 'full':
                name = str(c) + '_' + v + '_' + t
                if v != 'HNLmass':
                    eff[(c, v, t)] = Efficiency(name, var[v][0], var[v][2],
                                                getOutputName(v), var[v][1])
                else:
                    eff[(c, v, t)] = Efficiency(name, var[v][0], var[v][2],
                                                getOutputName(v), var[v][1])
                makeDirIfNeeded(getOutputName(v))
            else:
                for i, trigger in enumerate(category_triggers(chain, c)):
                    name = str(c) + '_' + v + '_' + t + '_' + str(i)
                    if v != 'HNLmass':
                        eff[(c, v, t, i)] = Efficiency(name, var[v][0],
                                                       var[v][2],
                                                       getOutputName(v),
                                                       var[v][1])
                    else:
                        eff[(c, v, t, i)] = Efficiency(name, var[v][0],
                                                       var[v][2],
コード例 #12
0
ファイル: compareLightLeptonId.py プロジェクト: lwezenbe/HNL
            ('#eta^{#tau}(offline) [GeV]', 'Efficiency')
        ]
    }

    list_of_var_hist['efficiency'][algo] = {}
    list_of_var_hist['fakerate'][algo] = {}
    for v in var_hist.keys():
        list_of_var_hist['efficiency'][algo][v] = {}
        list_of_var_hist['fakerate'][algo][v] = {}
        for wp in algo_wp:
            tot_name = output_name + '/' + sample.name + '_efficiency-' + str(
                args.flavor) + '_' + args.subJob + '.root'
            list_of_var_hist['efficiency'][algo][v][wp] = Efficiency(
                'efficiency_' + v + algo,
                var_hist[v][0],
                var_hist[v][2],
                tot_name,
                var_hist[v][1],
                subdirs=[algo + '-' + wp, 'efficiency_' + v])
            tot_name = output_name + '/' + sample.name + '_fakerate-' + str(
                args.flavor) + '_' + args.subJob + '.root'
            list_of_var_hist['fakerate'][algo][v][wp] = Efficiency(
                'fakerate_' + v + algo,
                var_hist[v][0],
                var_hist[v][2],
                tot_name,
                var_hist[v][1],
                subdirs=[algo + '-' + wp, 'fakerate_' + v])

#Determine if testrun so it doesn't need to calculate the number of events in the getEventRange
if args.isTest: