コード例 #1
0
def el_iso(binname=""):

    # Glob the file lists
    mcs = [
        output_dirpath + "/wj_ht.root",
        output_dirpath + "/tt_1l.root",
    ]
    qcds = [
        output_dirpath + "/qcd_em.root",
        output_dirpath + "/qcd_bc.root",
    ]

    bkg_hist = "ElClosureLoose{}__eliso".format(binname)
    qcd_hist = "OneElMR{}__iso".format(binname)

    h_bkg = ru.get_summed_histogram(mcs, bkg_hist)
    h_qcd = ru.get_summed_histogram(qcds, qcd_hist)
    h_qcd_em = ru.get_summed_histogram([output_dirpath + "/qcd_em.root"],
                                       qcd_hist)
    h_qcd_bc = ru.get_summed_histogram([output_dirpath + "/qcd_bc.root"],
                                       qcd_hist)

    h_bkg.Scale(1. / h_bkg.Integral())
    h_qcd.Scale(1. / h_qcd.Integral())
    h_qcd_em.Scale(1. / h_qcd_em.Integral())
    h_qcd_bc.Scale(1. / h_qcd_bc.Integral())

    h_qcd.SetName("QCD(e)")
    h_qcd_em.SetName("QCD(LF)")
    h_qcd_bc.SetName("QCD(HF)")

    # Color settings
    colors = [
        2001,
    ]

    # Options
    alloptions = {
        "ratio_range": [0.0, 2.0],
        "nbins": 10,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name": "plots/eliso/{}.pdf".format(bkg_hist + "__" + qcd_hist),
        "bkg_sort_method": "unsorted",
        "no_ratio": False,
        "print_yield": True,
        "yield_prec": 3,
        "draw_points": True,
        "lumi_value": 41.3,
        "legend_datalabel": "W+t#bar{t}",
    }

    # Plot them
    p.plot_hist(sigs=[h_qcd_em, h_qcd_bc],
                bgs=[h_qcd],
                data=h_bkg,
                colors=colors,
                syst=None,
                options=alloptions)
コード例 #2
0
def closure_plot(predict, estimate):

    # Glob the file lists
    bkg_list_wjets = [output_dirpath + "/wj_ht.root"]
    bkg_list_ttbar = [output_dirpath + "/tt_1l.root"]

    # Get all the histogram objects
    h_wjets_predict = ru.get_summed_histogram(bkg_list_wjets, predict)
    h_ttbar_predict = ru.get_summed_histogram(bkg_list_ttbar, predict)
    h_wjets_estimate = ru.get_summed_histogram(bkg_list_wjets, estimate)
    h_ttbar_estimate = ru.get_summed_histogram(bkg_list_ttbar, estimate)

    # Set the names of the histograms
    h_wjets_predict.SetName("W predict")
    h_ttbar_predict.SetName("Top predict")
    h_wjets_estimate.SetName("W estimate")
    h_ttbar_estimate.SetName("Top estimate")

    # Color settings
    colors = [
        2005,
        2001,
    ]

    # Options
    alloptions = {
        "ratio_range": [0.0, 2.0],
        "nbins": 1,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name":
        "plots/closure/{}.pdf".format(predict + "__" + estimate),
        "bkg_sort_method": "unsorted",
        "no_ratio": False,
        "print_yield": False,
        "yaxis_log": True if "ptcorr" in predict else False,
        "legend_smart": False if "ptcorr" in predict else True,
        "lumi_value": 41.3,
        "legend_datalabel": "Estimate",
        "yield_prec": 3,
        "print_yield": True,
    }

    # The bkg histogram list
    bgs_list = [
        h_ttbar_predict,
        h_wjets_predict,
    ]
    #bgs_list = [ h_ttbar_predict  ]

    h_estimate = h_wjets_estimate.Clone("Estimate")
    h_estimate.Add(h_ttbar_estimate)

    # Plot them
    p.plot_hist(bgs=bgs_list,
                data=h_estimate,
                colors=colors,
                syst=None,
                options=alloptions)
コード例 #3
0
def el_fakerate():

    # Glob the file lists
    mcs = [
        output_dirpath + "/wj_ht.root",
        output_dirpath + "/tt_1l.root",
    ]
    num = "ElClosureTight__elptcorretarolledcoarse"
    den = "ElClosureLoose__elptcorretarolledcoarse"
    h_num = ru.get_summed_histogram(mcs, num)
    h_den = ru.get_summed_histogram(mcs, den)
    u.move_in_overflows(h_num)
    u.move_in_overflows(h_den)
    h_num.Divide(h_den)

    qcds = [
        output_dirpath + "/qcd_em.root",
        output_dirpath + "/qcd_bc.root",
    ]
    qcd_num = "OneElTightMR__elptcorretarolledcoarse"
    qcd_den = "OneElMR__elptcorretarolledcoarse"
    h_qcd_num = ru.get_summed_histogram(qcds, qcd_num)
    h_qcd_den = ru.get_summed_histogram(qcds, qcd_den)
    u.move_in_overflows(h_qcd_num)
    u.move_in_overflows(h_qcd_den)
    h_qcd_num.Divide(h_qcd_den)
    h_qcd_num.SetName("QCD(e)")

    # Color settings
    colors = [
        2005,
        2001,
    ]

    # Options
    alloptions = {
        "ratio_range": [0.0, 2.0],
        "nbins": 180,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name": "plots/fakeratemc/{}.pdf".format(num + "__" + den),
        "bkg_sort_method": "unsorted",
        "no_ratio": False,
        "print_yield": True,
        "yield_prec": 3,
        "draw_points": True,
        "lumi_value": 41.3,
        "legend_datalabel": "W+t#bar{t}"
    }

    # Plot them
    p.plot_hist(bgs=[h_qcd_num],
                data=h_num,
                colors=colors,
                syst=None,
                options=alloptions)
コード例 #4
0
def main():

    output_dirpath = "outputs/HWW2016_skimmed_v17_v1.15.1/"

    histnames = [
        "CutISR400ElPlusRecoClassA__yield",
        "CutISR400ElPlusRecoClassB__yield",
        "CutISR400ElMinusRecoClassA__yield",
        "CutISR400ElMinusRecoClassB__yield",
        "CutISR400MuPlusRecoClassA__yield",
        "CutISR400MuPlusRecoClassB__yield",
        "CutISR400MuMinusRecoClassA__yield",
        "CutISR400MuMinusRecoClassB__yield",
    ]

    histnames = [
        #"CutISR400ElPlusRecoClassAStrawMan__yield",
        #"CutISR400ElPlusRecoClassBStrawMan__yield",
        #"CutISR400ElMinusRecoClassAStrawMan__yield",
        #"CutISR400ElMinusRecoClassBStrawMan__yield",
        "CutISR400MuPlusRecoClassAStrawMan__yield",
        "CutISR400MuPlusRecoClassBStrawMan__yield",
        "CutISR400MuMinusRecoClassAStrawMan__yield",
        "CutISR400MuMinusRecoClassBStrawMan__yield",
    ]

    histnames = [
        "CutISR300MuMinusRecoClassB__recowhad_mlep_puppi_mass",
    ]

    bkg_list_ttbar = glob.glob(output_dirpath + "/TT*.root")
    bkg_list_wjets = glob.glob(output_dirpath + "/WJets*.root")
    bkg_list_hww = glob.glob(output_dirpath +
                             "/Glu*.root") + glob.glob(output_dirpath +
                                                       "/VBF*.root")
    #data_list = glob.glob(output_dirpath+"/data_*.root")

    h_wjets = ru.get_summed_histogram(bkg_list_wjets, histnames)
    h_ttbar = ru.get_summed_histogram(bkg_list_ttbar, histnames)
    h_hww = ru.get_summed_histogram(bkg_list_hww, histnames)
    #h_data    = ru.get_summed_histogram(data_list        , histnames)

    h_wjets.SetName("W")
    h_ttbar.SetName("t#bar{t}")
    h_hww.SetName("HWW (x10)")

    colors = [2005, 2001, 2]
    alloptions = {
        "ratio_range": [0.0, 2.0],
        "nbins": 60,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name": "plots/test.pdf",
        "bkg_sort_method": "unsorted",
        "no_ratio": True,
        "print_yield": True,
        "signal_scale": 500,
    }
    p.plot_hist(
        sigs=[h_hww],
        bgs=[h_ttbar, h_wjets, h_hww.Clone("HWW (stacked)")],
        #data = h_data,
        data=None,
        colors=colors,
        syst=None,
        options=alloptions)
コード例 #5
0
ファイル: makeplot.py プロジェクト: sgnoohc/WWWAnalysis
def get_hists(histnames, use_data_driven_fakes=False):

    bkg_lists = {}
    bkg_lists["lostlep"] = [
        x for x in glob.glob(output_dirpath + "/lostlep.root")
    ]
    bkg_lists["photon"] = [
        x for x in glob.glob(output_dirpath + "/photon.root")
    ]
    bkg_lists["qflip"] = [x for x in glob.glob(output_dirpath + "/qflip.root")]
    bkg_lists["ddfakes"] = [
        x for x in glob.glob(output_dirpath + "/ddfakes.root")
    ]
    bkg_lists["ewksubt"] = [
        x for x in glob.glob(output_dirpath + "/ewksubt.root")
    ]
    bkg_lists["mcfakes"] = [
        x for x in glob.glob(output_dirpath + "/fakes.root")
    ]
    bkg_lists["prompt"] = [
        x for x in glob.glob(output_dirpath + "/prompt.root")
    ]
    bkg_lists["fakes"] = bkg_lists[
        "ddfakes"] if use_data_driven_fakes else bkg_lists["mcfakes"]

    sig_list = glob.glob(output_dirpath + "/*t_www_*/*.root")
    vh_list = glob.glob(output_dirpath + "/*VH*t_www_*/*.root")
    www_list = glob.glob(output_dirpath + "/*WWW*t_www_*/*.root")
    data_list = glob.glob(output_dirpath + "/*Run2017*_t_ss*/*.root")
    sig_list = glob.glob(output_dirpath + "/signal.root")
    data_list = glob.glob(output_dirpath + "/data.root")

    hists = {}
    if "__" in histnames[0]:
        hists["lostlep"] = ru.get_summed_histogram(bkg_lists["lostlep"],
                                                   histnames)
        hists["photon"] = ru.get_summed_histogram(bkg_lists["photon"],
                                                  histnames)
        hists["qflip"] = ru.get_summed_histogram(bkg_lists["qflip"], histnames)
        hists["fakes"] = ru.get_summed_histogram(bkg_lists["fakes"], histnames)
        hists["ewksubt"] = ru.get_summed_histogram(bkg_lists["ewksubt"],
                                                   histnames)
        hists["prompt"] = ru.get_summed_histogram(bkg_lists["prompt"],
                                                  histnames)
        hists["sig"] = ru.get_summed_histogram(sig_list, histnames)
        hists["data"] = ru.get_summed_histogram(data_list, histnames)
    else:
        hists["lostlep"] = ru.get_yield_histogram(bkg_lists["lostlep"],
                                                  histnames)
        hists["photon"] = ru.get_yield_histogram(bkg_lists["photon"],
                                                 histnames)
        hists["qflip"] = ru.get_yield_histogram(bkg_lists["qflip"], histnames)
        hists["fakes"] = ru.get_yield_histogram(bkg_lists["fakes"], histnames)
        hists["ewksubt"] = ru.get_yield_histogram(bkg_lists["ewksubt"],
                                                  histnames)
        hists["prompt"] = ru.get_yield_histogram(bkg_lists["prompt"],
                                                 histnames)
        hists["sig"] = ru.get_yield_histogram(sig_list, histnames)
        hists["data"] = ru.get_yield_histogram(data_list, histnames)

    if bkg_lists["fakes"] == bkg_lists["ddfakes"]:
        for i in xrange(1, hists["ewksubt"].GetNbinsX() + 1):
            if hists["ewksubt"].GetBinContent(i) > 0:
                hists["ewksubt"].SetBinContent(i, 0)
        hists["fakes"].Add(hists["ewksubt"])

    hists["lostlep"].SetName("Lost/three lep")
    hists["photon"].SetName("#gamma#rightarrowlepton")
    hists["qflip"].SetName("Charge mis-id")
    hists["fakes"].SetName("Non-prompt")
    hists["prompt"].SetName("Irredu.")
    hists["sig"].SetName("WWW")
    hists["data"].SetName("Data")

    return hists
コード例 #6
0
ファイル: makeplot.py プロジェクト: sgnoohc/WWWAnalysis
def oscr():

    output_dirpath = "outputs/WWW2017_analysis_v0.44.1_byproc"
    sample_lists = {}
    sample_lists["Z"] = [x for x in glob.glob(output_dirpath + "/DY*.root")]
    sample_lists["top"] = [x for x in glob.glob(output_dirpath + "/TT*.root")]
    sample_lists["top"] += [
        x for x in glob.glob(output_dirpath + "/ST_*.root")
    ]
    sample_lists["W"] = [x for x in glob.glob(output_dirpath + "/WJ*.root")]
    sample_lists["MB"] = [x for x in glob.glob(output_dirpath + "/WW*.root")]
    sample_lists["MB"] += [
        x for x in glob.glob(output_dirpath + "/WZTo1*.root")
    ]
    sample_lists["MB"] += [
        x for x in glob.glob(output_dirpath + "/WZTo2*.root")
    ]
    sample_lists["MB"] += [
        x for x in glob.glob(output_dirpath + "/WZTo3LNu_Tu*.root")
    ]
    sample_lists["MB"] += [x for x in glob.glob(output_dirpath + "/ZZ*.root")]
    sample_lists["data"] = [
        x for x in glob.glob(output_dirpath + "/*Run2017*.root")
    ]

    bkgs = ["Z", "top", "W", "MB"]

    #histnames = ["OSCRmm__MllSS"]
    #histnames = ["OSCRee__MllSS"]
    #histnames = ["OSCRem__nb"]
    #histnames = ["OSCRem__nj"]
    #histnames = ["OSCRem__nj30"]
    #histnames = ["OSCRem__nvtx"]
    #histnames = ["OSCRem__MET"]
    #histnames = ["OSCRem__MllSS"]
    #histnames = ["WZCRSSmm__MllSS"]

    histnames = [
        "WZCRSSeeFull",
        "WZCRSSemFull",
        "WZCRSSmmFull",
        "WZCR1SFOSFull",
        "WZCR2SFOSFull",
    ]

    hists = {}
    for bkg in bkgs:
        if "__" in histnames[0]:
            hists[bkg] = ru.get_summed_histogram(sample_lists[bkg],
                                                 histnames).Clone(bkg)
        else:
            hists[bkg] = ru.get_yield_histogram(sample_lists[bkg],
                                                histnames).Clone(bkg)

    if "__" in histnames[0]:
        hists["data"] = ru.get_summed_histogram(sample_lists["data"],
                                                histnames).Clone("data")
    else:
        hists["data"] = ru.get_yield_histogram(sample_lists["data"],
                                               histnames).Clone("data")

    colors = [920, 2007, 2005, 2003, 2001, 2]

    alloptions = {
        "ratio_range": [0.3, 1.7],
        "nbins": 15,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name": "plots/test.pdf",
        "bkg_sort_method": "unsorted",
        "no_ratio": False,
        "print_yield": True,
        #"blind": True if "SR" in histnames[0] else False,
        "blind": False,
        "lumi_value": "41.3",
        #"yaxis_log": True,
        #"yaxis_range": [1, 5e10],
        "legend_smart": False,
    }

    bgs = [hists[x] for x in bkgs]

    p.plot_hist(sigs=[],
                bgs=bgs,
                data=hists["data"],
                colors=colors,
                syst=None,
                options=alloptions)
コード例 #7
0
def plot(histnames, ps=0, sf=0):

    # Glob the file lists
    #    bkg_list_wjets  = glob.glob(output_dirpath+"/WJetsToLNu_Tune*.root")
    #    bkg_list_dy     = glob.glob(output_dirpath+"/DY*.root")
    #    bkg_list_ttbar  = glob.glob(output_dirpath+"/TTJets_Tune*.root")
    #    bkg_list_vv     = glob.glob(output_dirpath+"/WW*.root") + glob.glob(output_dirpath+"/WW*.root")
    #    bkg_list_qcd_mu = glob.glob(output_dirpath+"/QCD*MuEn*.root")
    #    bkg_list_qcd_el = glob.glob(output_dirpath+"/QCD*EMEn*.root")
    #    bkg_list_qcd_bc = glob.glob(output_dirpath+"/QCD*bcToE*.root")
    bkg_list_wjets = [output_dirpath + "/wj_incl.root"]
    bkg_list_dy = [output_dirpath + "/dy.root"]
    bkg_list_ttbar = [output_dirpath + "/tt_incl.root"]
    bkg_list_vv = [output_dirpath + "/ww.root", output_dirpath + "/wz.root"]
    bkg_list_qcd_mu = [output_dirpath + "/qcd_mu.root"]
    bkg_list_qcd_el = [output_dirpath + "/qcd_em.root"]
    bkg_list_qcd_bc = [output_dirpath + "/qcd_bc.root"]
    bkg_list_all = bkg_list_wjets + bkg_list_dy + bkg_list_ttbar + bkg_list_vv

    # Glob the data file list depending on the region
    if "Mu" in histnames:
        data_list = [output_dirpath + "/data_mu.root"]
    elif "El" in histnames:
        data_list = [output_dirpath + "/data_el.root"]
    else:
        data_list = [
            output_dirpath + "/data_mu.root", output_dirpath + "/data_el.root"
        ]

    # Get all the histogram objects
    h_wjets = ru.get_summed_histogram(bkg_list_wjets, histnames)
    h_dy = ru.get_summed_histogram(bkg_list_dy, histnames)
    h_ttbar = ru.get_summed_histogram(bkg_list_ttbar, histnames)
    h_vv = ru.get_summed_histogram(bkg_list_vv, histnames)
    h_qcd_mu = ru.get_summed_histogram(bkg_list_qcd_mu, histnames)
    h_qcd_el = ru.get_summed_histogram(bkg_list_qcd_el, histnames)
    h_qcd_bc = ru.get_summed_histogram(bkg_list_qcd_bc, histnames)
    h_data = ru.get_summed_histogram(data_list, histnames)

    # Set the names of the histograms
    h_wjets.SetName("W")
    h_dy.SetName("Z")
    h_ttbar.SetName("Top")
    h_vv.SetName("VV")
    h_qcd_mu.SetName("QCD(#mu)")
    h_qcd_el.SetName("QCD(e)")
    h_qcd_bc.SetName("QCD(bc)")
    h_data.SetName("Data")

    # Scale the histograms appropriately from SF from the EWKCR
    if sf > 0:
        h_wjets.Scale(sf)
        h_dy.Scale(sf)
        h_ttbar.Scale(sf)
        h_vv.Scale(sf)

    # If the data needs some additional correction for the prescale
    if ps > 0:
        h_data.Scale(ps)

    # Color settings
    colors = [2007, 2005, 2003, 2001, 920, 2]

    # Options
    alloptions = {
        "ratio_range": [0.0, 2.0],
        "nbins": 30,
        "autobin": False,
        "legend_scalex": 1.8,
        "legend_scaley": 1.1,
        "output_name": "plots/plot/{}.pdf".format(histnames),
        "bkg_sort_method": "unsorted",
        "no_ratio": False,
        "print_yield": False,
        "yaxis_log": True if "ptcorr" in histnames else False,
        #"yaxis_log": False,
        "divide_by_bin_width": True,
        "legend_smart": False if "ptcorr" in histnames else True,
        "lumi_value": 41.3,
    }

    # The bkg histogram list
    bgs_list = [h_vv, h_ttbar, h_dy, h_wjets, h_qcd_mu],
    bgs_list = [
        h_vv, h_ttbar, h_dy, h_wjets, h_qcd_mu
    ] if "Mu" in histnames else [h_vv, h_ttbar, h_dy, h_wjets, h_qcd_el]

    # Plot them
    p.plot_hist(bgs=bgs_list,
                data=h_data.Clone("Data"),
                colors=colors,
                syst=None,
                options=alloptions)

    # Obtain the histogram again to return the object for further calculations

    # Data-driven QCD = data - bkg
    h_ddqcd = ru.get_summed_histogram(data_list, histnames)
    h_bkg = ru.get_summed_histogram(bkg_list_all, histnames)
    if ps > 0:
        h_ddqcd.Scale(ps)
    if sf > 0:
        h_bkg.Scale(sf)
    h_ddqcd.Add(h_bkg, -1)

    # MC QCD
    h_qcd_mu = ru.get_summed_histogram(bkg_list_qcd_mu,
                                       histnames).Clone("QCD(#mu)")
    h_qcd_el = ru.get_summed_histogram(bkg_list_qcd_el,
                                       histnames).Clone("QCD(EM)")
    h_qcd_bc = ru.get_summed_histogram(bkg_list_qcd_bc,
                                       histnames).Clone("QCD(HF)")

    return h_ddqcd, h_data, h_bkg, h_qcd_mu, h_qcd_el, h_qcd_bc