Exemplo n.º 1
0
def determineWeights(years, selections, regions, strategy):
    weights = {}
    for year in years:
        weights[year] = {}
        for selection in selections:
            weights[year][selection] = {}
            for region in regions:
                print region
                tt_tot = 0.
                dy_tot = 0.
                for c in cat_dict[region]:
                    tmp_tt_hist = getObjFromFile(
                        in_file_path(year, selection, region, 'TT', strategy),
                        str(c) + '_nonprompt')
                    tmp_dy_hist = getObjFromFile(
                        in_file_path(year, selection, region, 'DY', strategy),
                        str(c) + '_nonprompt')
                    tt_tot += tmp_tt_hist.GetSumOfWeights()
                    dy_tot += tmp_dy_hist.GetSumOfWeights()
                    print tt_tot, dy_tot
                weights[year][selection][region] = {
                    'DY': dy_tot / (tt_tot + dy_tot),
                    'TT': tt_tot / (tt_tot + dy_tot)
                }

    json_f = json.dumps(weights)
    out_file = open(out_file_path, 'w')
    out_file.write(json_f)
    out_file.close()
Exemplo n.º 2
0
    def __init__(self, name, var, var_tex, path, bins=None, subdirs=None):      
        self.name = name
        self.path = path
        self.var = var
        self.var_tex = var_tex
        self.bins = bins
        self.subdirs = subdirs
        self.efficiency_num = None
        self.efficiency_denom = None
        self.efficiency = None

        #If bins == None, load in histograms from the path
        bins_check = False
        try:
            if bins:    bins_check = True
        except:
            if bins.any():      bins_check = True
       
        if bins_check:
            self.efficiency_num = Histogram(name+'_num', self.var, var_tex, bins)
            self.efficiency_denom = Histogram(name+'_denom', self.var, var_tex, bins)
        else:
            obj_name = ''
            if subdirs is not None:
                for d in subdirs:
                    obj_name += d+'/'
            self.efficiency_num = Histogram(getObjFromFile(self.path, obj_name+self.name+'_num'))
            self.efficiency_denom = Histogram(getObjFromFile(self.path, obj_name+self.name+'_denom'))
     
        self.isTH2 = self.efficiency_num.isTH2
        if self.isTH2 and not self.efficiency_denom.isTH2:  print "Warning: efficiency numerator and denominator have different dimensions"
Exemplo n.º 3
0
def getReweightingFunction(year, variation='central', useMC=None):

  if   year == '2016': data = {'central' : "PU_2016_36000_XSecCentral", 'up' : "PU_2016_36000_XSecUp", 'down' : "PU_2016_36000_XSecDown"}
  elif year == '2017': data = {'central' : "PU_2017_41500_XSecCentral", 'up' : "PU_2017_41500_XSecUp", 'down' : "PU_2017_41500_XSecDown"}
  elif year == '2018': data = {'central' : "PU_2018_60000_XSecCentral", 'up' : "PU_2018_60000_XSecUp", 'down' : "PU_2018_60000_XSecDown"}

  # Data
  histoData = getObjFromFile(dataDir + data[variation] + '.root', 'pileup')
  histoData.Scale(1./histoData.Integral())

  # MC
  if not useMC:
    mcProfile = ROOT.TH1D('mc', 'mc', 100, 0, 100)
    sys.stdout = open(os.devnull, 'w')
    if year == '2016':   from SimGeneral.MixingModule.mix_2016_25ns_Moriond17MC_PoissonOOTPU_cfi import mix
    elif year == '2017': from SimGeneral.MixingModule.mix_2017_25ns_WinterMC_PUScenarioV1_PoissonOOTPU_cfi import mix
    elif year == '2018': from SimGeneral.MixingModule.mix_2018_25ns_JuneProjectionFull18_PoissonOOTPU_cfi import mix
      
    sys.stdout = sys.__stdout__
    for i, value in enumerate(mix.input.nbPileupEvents.probValue): mcProfile.SetBinContent(i+1, value)   # pylint: disable=E1103
  else:
    mcProfile = useMC
  mcProfile.Scale(1./mcProfile.Integral())

  # Create reweighting histo
  reweightingHisto = histoData.Clone('reweightingHisto')
  reweightingHisto.Divide(mcProfile)

  # Define reweightingFunc
  def reweightingFunc(nTrueInt):
    return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nTrueInt))
  return reweightingFunc
Exemplo n.º 4
0
def extractRawLimits(input_file_path):
    tree = getObjFromFile(input_file_path, 'limit')
    limits = {}
    for entry in xrange(tree.GetEntries()):
        tree.GetEntry(entry)
        limits[tree.quantileExpected] = tree.limit
    return limits
Exemplo n.º 5
0
def printCutFlow(in_file_paths, out_file_path, in_file_path_names):
    print in_file_path_names
    in_file_paths = makeList(in_file_paths)
    in_file_path_names = makeList(in_file_path_names)
    if len(in_file_paths) != len(in_file_path_names):
        print 'inconsistent file paths and names'
        exit(0)

    list_of_cut_values = {}
    for ifp, ifpn in zip(in_file_paths, in_file_path_names):
        in_file = TFile(ifp)
        key_names = [k[0] for k in rootFileContent(in_file, '/', starting_dir = 'cutflow')]
        in_file.Close()
        list_of_cut_values[ifpn] = {}
        for k in key_names:
            list_of_cut_values[ifpn][k] = getObjFromFile(ifp, 'cutflow/'+k).GetSumOfWeights()

    out_file = open(out_file_path, 'w')
    out_file.write(' \t \t ' + '\t'.join(in_file_path_names) + '\n')
    for k in key_names:
        out_file.write(k.split('/')[-1] +'\t \t ' + '\t'.join([str(list_of_cut_values[n][k]) for n in in_file_path_names]) + '\n')
    # out_file.write('NAME \t \t \t ' + '\t'.join([k.split('/')[-1] for k in key_names]) + '\n')
    # for n in in_file_path_names:
    #     out_file.write(n +'\t \t \t ' + '\t'.join([str(list_of_cut_values[n][k]) for k in key_names]) + '\n')
    out_file.close()
Exemplo n.º 6
0
    def getHist(self, name, sub_path=None):
        if sub_path is None:
            sub_path = self.path

        if sub_path.endswith('.root'):
            hcounter = getObjFromFile(sub_path, 'blackJackAndHookers/' + name)
            if hcounter is None:
                hcounter = getObjFromFile(
                    sub_path, name)  #Try without blackJackAndHookers
            return hcounter
        else:
            hcounter = None
            listOfFiles = glob.glob(sub_path + '/*/*/*.root')
            for f in listOfFiles:
                if hcounter is None:
                    hcounter = self.getHist(name, f)
                else:
                    hcounter.Add(self.getHist(name, f))
            return hcounter
Exemplo n.º 7
0
Arquivo: ROC.py Projeto: lwezenbe/HNL
    def __init__(self, name, path, working_points=None, misid_path=None):
        self.name = name
        self.path = path
        self.working_points = working_points

        if working_points is not None:
            self.chain = TChain(name, name)
            self.chain.var_roc = np.arange(0.5, len(working_points) + 0.5, 1)
            self.var = lambda c, i: c.var_roc[i]
            self.var_tex = 'workingpoints'
            self.bins = np.arange(0., len(working_points) + 1., 1)
        self.eff_numerator = None
        self.eff_denominator = None
        self.misid_numerator = None
        self.misid_denominator = None

        if self.working_points is not None:
            self.eff_numerator = Histogram(name + '_eff_numerator', self.var,
                                           self.var_tex, self.bins)
            self.misid_numerator = Histogram(name + '_misid_numerator',
                                             self.var, self.var_tex, self.bins)
            self.eff_denominator = Histogram(name + '_eff_denominator',
                                             self.var, self.var_tex, self.bins)
            self.misid_denominator = Histogram(name + '_misid_denominator',
                                               self.var, self.var_tex,
                                               self.bins)

        else:
            self.eff_numerator = Histogram(
                getObjFromFile(self.path,
                               name + '/' + name + '_eff_numerator'))
            self.eff_denominator = Histogram(
                getObjFromFile(self.path,
                               name + '/' + name + '_eff_denominator'))

            #Use different file for misid in case you split the jobs for signal and bkgr up
            tmp_path = misid_path if misid_path is not None else self.path
            self.misid_numerator = Histogram(
                getObjFromFile(tmp_path,
                               name + '/' + name + '_misid_numerator'))
            self.misid_denominator = Histogram(
                getObjFromFile(tmp_path,
                               name + '/' + name + '_misid_denominator'))
Exemplo n.º 8
0
def extractScaledLimitsPromptHNL(input_file_path, coupling):
    tree = getObjFromFile(input_file_path, 'limit')
    exclusion_coupling = {}
    try:
        for entry in xrange(tree.GetEntries()):
            tree.GetEntry(entry)
            exclusion_coupling[round(tree.quantileExpected,
                                     3)] = tree.limit * coupling**2
        return exclusion_coupling
    except:
        return None
Exemplo n.º 9
0
 def __init__(self, name, var, var_tex, path):
     super(FakeRateEmulator, self).__init__(name,
                                            var,
                                            var_tex,
                                            path,
                                            bins=tmp_bins)
     self.efficiency_num = None
     self.efficiency_denom = None
     self.efficiency = getObjFromFile(self.path, self.name)
     efficiency_hist_obj = Histogram(self.efficiency)
     self.isTH2 = efficiency_hist_obj.isTH2
Exemplo n.º 10
0
def plotCutFlow(in_file_paths, out_file_path, in_file_path_names, ignore_weights=False, output_name = None):
    in_file_paths = makeList(in_file_paths)
    in_file_path_names = makeList(in_file_path_names)
    if len(in_file_paths) != len(in_file_path_names):
        print 'inconsistent file paths and names'
        exit(0)

    list_of_cut_hist = []
    tex_names = []
    x_name = []
    #If one input file, plot keys on x
    if len(in_file_paths) == 1:
        in_file = TFile(in_file_paths[0], 'read')
        key_names = [k[0] for k in rootFileContent(in_file, starting_dir = 'cutflow')]
        in_file.Close()
        list_of_cut_hist.append(ROOT.TH1D('cutflow', 'cutflow', len(key_names), 0, len(key_names)))
        for i, k in enumerate(key_names):
            if ignore_weights:
                list_of_cut_hist[0].SetBinContent(i+1, getObjFromFile(in_file_paths[0], k).GetEntries())
            else:
                list_of_cut_hist[0].SetBinContent(i+1, getObjFromFile(in_file_paths[0], k).GetSumOfWeights())
        tex_names = in_file_path_names
        x_name = [k.split('/')[-1] for k in key_names]
    #Plot samples on x
    else:
        in_file = TFile(in_file_paths[0])
        key_names = [k[0] for k in rootFileContent(in_file, starting_dir='cutflow')]
        in_file.Close()
        for j, k in enumerate(key_names):
            list_of_cut_hist.append(ROOT.TH1D('cutflow_'+k, 'cutflow_'+k, len(in_file_paths), 0, len(in_file_paths)))
            for i, ifp in enumerate(in_file_paths):
                if ignore_weights:
                    print ifp, k
                    list_of_cut_hist[j].SetBinContent(i+1, getObjFromFile(ifp, k).GetEntries())
                else:
                    list_of_cut_hist[j].SetBinContent(i+1, getObjFromFile(ifp, k).GetSumOfWeights())
        tex_names = [k.split('/')[-1] for k in key_names]
        x_name = in_file_path_names

    p = Plot(list_of_cut_hist, tex_names, name = 'cutflow' if output_name is None else output_name, x_name = x_name, y_log = True)
    p.drawBarChart(out_file_path, index_colors=True, parallel_bins=True)
Exemplo n.º 11
0
    hist_list = glob.glob(os.getcwd() + '/data/plotTau/' + reco_or_gen_str +
                          '/*')

    # Merge files if necessary
    for n in hist_list:
        merge(n)

    list_of_hist = {}
    # Load in the histograms from the files
    for h in hist_list:
        sample_name = h.split('/')[-1]
        list_of_hist[sample_name] = {}
        for v in var.keys():
            list_of_hist[sample_name][v] = Histogram(
                getObjFromFile(h + '/variables.root',
                               v + '/' + sample_name + '-' + v))

#
#       Plot!
#
if args.runOnCream or args.isTest:
    exit(0)

#
# Necessary imports
#
from HNL.Plotting.plot import Plot
from HNL.Plotting.plottingTools import extraTextFormat
from HNL.Tools.helpers import makePathTimeStamped
from HNL.EventSelection.eventCategorization import returnCategoryPtCuts
Exemplo n.º 12
0
Arquivo: ROC.py Projeto: lwezenbe/HNL
 def loadEfficiency(self, name, path):
     self.eff_numerator = getObjFromFile(path, name + '_eff_numerator')
     self.eff_denominator = getObjFromFile(path, name + '_eff_denominator')
Exemplo n.º 13
0
            list_of_tot_bkgr[algo] = {}
            for iso_wp in algos[algo]:
                list_of_tot_bkgr[algo][iso_wp] = {}
                for ele_wp in getEleWPs(algo):
                    list_of_tot_bkgr[algo][iso_wp][ele_wp] = {}
                    for mu_wp in getMuWPs(algo):
                        list_of_tot_bkgr[algo][iso_wp][ele_wp][mu_wp] = {}
                        for channel in ['Ditau', 'SingleTau']:
                            list_of_tot_bkgr[algo][iso_wp][ele_wp][mu_wp][
                                channel] = None
                            for i, bkgr in enumerate(
                                    list_of_input['Background']):
                                if i == 0:
                                    list_of_tot_bkgr[algo][iso_wp][ele_wp][
                                        mu_wp][channel] = getObjFromFile(
                                            bkgr, channel + '/' + channel +
                                            '_' + algo + '_' + iso_wp + '_' +
                                            ele_wp + '_' + mu_wp)
                                else:
                                    list_of_tot_bkgr[algo][iso_wp][ele_wp][
                                        mu_wp][channel].Add(
                                            getObjFromFile(
                                                bkgr, channel + '/' + channel +
                                                '_' + algo + '_' + iso_wp +
                                                '_' + ele_wp + '_' + mu_wp))

        # for signal in list_of_input['Signal']:
        #     for channel in ['Ditau', 'SingleTau']:
        #         out_name = os.path.join(os.getcwd(), 'data', 'Results',  __file__.split('.')[0].rsplit('/')[-1], args.year, 'TextResults', signal.split('/')[-2]+'_'+channel+'.txt')
        #         makeDirIfNeeded(out_name)
        #         out_file = open(out_name, 'w')
        #         list_of_significances = []
Exemplo n.º 14
0
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')
#graph.Draw()
Exemplo n.º 15
0
        keyNames = [k[0] for k in rootFileContent(rf, getNested=get_nested)]
        filtered_names = {k.rsplit('_', 1)[0] for k in keyNames}

        file_name_comp[sample] = makeNameCompList([x for x in filtered_names])

        hists[sample] = {}

        for c in file_name_comp[sample].keys():
            hists[sample][c] = {}
            for v in file_name_comp[sample][c].keys():
                hists[sample][c][v] = {}
                if args.separateTriggers is None:
                    obj_name = file_name_comp[sample][c][v]['allTriggers']
                    hists[sample][c][v]['allTriggers'] = getObjFromFile(
                        f, '/' + c + '/' + v + '/' + obj_name +
                        '_num').Clone(c + '/' + v + '/' + obj_name +
                                      '_efficiency')
                    hists[sample][c][v]['allTriggers'].Divide(
                        getObjFromFile(
                            f, c + '/' + v + '/' + obj_names[0] + '_denom'))
                else:
                    for t in file_name_comp[sample][c][v]:
                        eff = Efficiency(file_name_comp[sample][c][v][t],
                                         None,
                                         None,
                                         f,
                                         subdirs=[c, v, t])
                        if not '2D' in v:
                            hists[sample][c][v][t] = eff.getEfficiency()
                        else:
                            hists[sample][c][v][t] = eff.getEfficiency()
Exemplo n.º 16
0
Arquivo: ROC.py Projeto: lwezenbe/HNL
 def loadMisid(self, name, path):
     self.misid_numerator = getObjFromFile(path, name + '_misid_numerator')
     self.misid_denominator = getObjFromFile(path,
                                             name + '_misid_denominator')
Exemplo n.º 17
0
    for c in categories:
        list_of_hist[c] = {}
        for v in var:
            list_of_hist[c][v] = {'signal':{}, 'bkgr':{}}


    # Load in the signal histograms from the files
    for c in categories: 
        print 'loading', c
        for v in var.keys():
            if not args.bkgrOnly:
                for s in signal_list:
                    sample_name = s.split('/')[-1]
                    sample_mass = int(sample_name.split('-m')[-1])
                    if args.masses is not None and sample_mass not in args.masses: continue
                    list_of_hist[c][v]['signal'][sample_name] = Histogram(getObjFromFile(s+'/variables.root', v+'/'+str(c)+'-'+v+'-'+sample_name+'-total')) 
                    # list_of_hist[c][v]['signal'][sample_name].hist.Scale(1000.)

    for c in categories: 
        print 'loading', c
        for v in var.keys():   
            if not args.signalOnly:
                for b in background_collection:
                    list_of_hist[c][v]['bkgr'][b] = Histogram(b, var[v][0], var[v][2], var[v][1])

    for c in categories: 
        print 'loading', c
        for v in var.keys():   
            if not args.signalOnly:
                for b in bkgr_list:
                    bkgr = b.split('/')[-1]
Exemplo n.º 18
0
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/'
if args.onlyReco:     output_dir += 'onlyReco/'
output_dir = makePathTimeStamped(output_dir)
Exemplo n.º 19
0
        else:
            path_name = os.path.expandvars('$CMSSW_BASE/src/HNL/EventSelection/data/testArea/eventsPerCategory/'+selection_str+'/'+mass_str+'/'+sample.output+'/events.root')
        is_signal = 'signal' if 'HNL' in sample.output else 'bkgr'
        if args.signalOnly and is_signal == 'bkgr': continue
        if args.backgroundOnly and is_signal == 'signal': continue
        if 'HNL' in sample.name and not 'HNL-'+args.coupling in sample.name: continue
        if args.masses is not None and is_signal=='signal' and not any([str(m) == sample.output.rsplit('-m')[-1] for m in args.masses]): continue
        list_of_values[is_signal][sample.output] = {}
        list_of_errors[is_signal][sample.output] = {}
        for c in listOfCategories():
            if c not in accepted_categories: continue
            list_of_values[is_signal][sample.output][c] = {}
            list_of_errors[is_signal][sample.output][c] = {}
            for sr in xrange(1, srm.getNumberOfSearchRegions()+1):
                #list_of_values[is_signal][sample.output][c][sr]= Histogram(getObjFromFile(path_name, '_'.join([str(c), str(sr)])+'/'+'_'.join([str(c), str(sr)])))
                tmp_hist = getObjFromFile(path_name, '_'.join([str(c), str(sr)])+'/'+'_'.join([str(c), str(sr)]))
                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
Exemplo n.º 20
0
            else:
                sname = cc
                cname = card

            file_list = []
            for m in passed_masses:
                file_name  = glob.glob(os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL', 'Stat', 'data', 'output', str(year_to_read), sname, args.flavor, 
                                        'HNL-'+args.flavor+'-m'+str(m), 'shapes', asymptotic_str+'/'+cname+'/*'))
                if len(file_name) == 0:
                    file_list.append(None)
                else:
                    file_list.append(file_name[0])
            compare_graphs[sname + ' ' +cname] = makeGraphs(passed_masses, couplings = passed_couplings, limits=None, input_paths = file_list)

    if args.flavor == 'e':
        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))
Exemplo n.º 21
0
        else:
            bkgr_names.append(sample.output)

    #Loading in signal

    for signal in signal_names:
        print 'Loading', signal
        path_name = os.path.join(base_path, signal, 'total/events.root')

        list_of_values['signal'][signal] = {}
        list_of_errors['signal'][signal] = {}
        for c in listOfCategories(args.region):
            list_of_values['signal'][signal][c] = {}
            list_of_errors['signal'][signal][c] = {}
            tmp_hist = getObjFromFile(
                path_name, '_'.join([str(c), 'total']) + '/' +
                '_'.join([str(c), 'total']))
            #Rescale if requested
            if args.rescaleSignal is not None:
                tmp_hist.Scale(args.rescaleSignal / (args.coupling**2))
            for sr in xrange(1,
                             srm[args.region].getNumberOfSearchRegions() + 1):
                list_of_values['signal'][signal][c][
                    sr] = tmp_hist.GetBinContent(sr)
                list_of_errors['signal'][signal][c][sr] = tmp_hist.GetBinError(
                    sr)

    #Loading in background

    if args.groupSamples:
        background_collection = sample_manager.sample_groups.keys()
Exemplo n.º 22
0
            for v in var:
                list_of_hist[c][v] = {'signal': {}, 'bkgr': {}, 'data': {}}

        # Load in the signal histograms from the files
        for c in categories:
            print 'loading signal ', c
            for v in var.keys():
                if not args.bkgrOnly:
                    for s in signal_list:
                        sample_name = s.split('/')[-1]

                        # print sample_name
                        sample_mass = float(sample_name.split('-m')[-1])
                        list_of_hist[c][v]['signal'][sample_name] = Histogram(
                            getObjFromFile(
                                s + '/variables.root', v + '/' + str(c) + '-' +
                                v + '-' + sample_name + '-total'))

                        coupling_squared = args.rescaleSignal if args.rescaleSignal is not None else signal_couplingsquared[
                            args.flavor][sample_mass]
                        list_of_hist[c][v]['signal'][sample_name].hist.Scale(
                            coupling_squared / (args.coupling**2))

                        # if args.rescaleSignal is not None:
                        #    list_of_hist[c][v]['signal'][sample_name].hist.Scale(args.rescaleSignal/(args.coupling**2))

        if len(args.includeData) > 0:
            for c in categories:
                for v in var:
                    list_of_hist[c][v]['data']['sideband'] = Histogram(
                        getObjFromFile(
Exemplo n.º 23
0
    hist_list = glob.glob(os.getcwd()+'/data/'+__file__.split('.')[0]+'/'+args.year+'/*')

    # Merge files if necessary
    for n in hist_list:
        merge(n)

    list_of_hist = {}
    legend_names = {}
    # Load in the histograms from the files
    for v in var.keys():
        list_of_hist[v] = []
        legend_names[v] = []
        for h in hist_list:
            sample_name = h.split('/')[-1]
            list_of_hist[v].append(Histogram(getObjFromFile(h+'/variables.root', v+'/'+sample_name+'-'+v)))
            legend_names[v].append(sample_name)

#
#       Plot!
#
if args.runOnCream or args.isTest: 
    exit(0)

#
# Necessary imports
#
from HNL.Plotting.plot import Plot
from HNL.Plotting.plottingTools import extraTextFormat
from HNL.Tools.helpers import makePathTimeStamped
from HNL.EventSelection.eventCategorization import returnCategoryPtCuts