Exemple #1
0
def OptLeptmass(cor, misid, mistag):

    c = pltmgr.NewCanvas()
    leg = pltmgr.NewLegend(0.68, 0.57, 0.8, 0.87)
    leg.SetTextSize(16)
    leg.SetFillColorAlpha(0, 1)

    cor.Draw("hist")
    misid.Draw("hist same")
    mistag.Draw("hist same")
    leg.Draw()

    cor.SetLineColor(pltmgr.Green)
    misid.SetLineColor(pltmgr.Magenta)
    mistag.SetLineColor(pltmgr.Cyan)
    cor.SetLineWidth(2)
    misid.SetLineWidth(2)
    mistag.SetLineWidth(2)

    leg.AddEntry(cor, "Correct", "l")
    leg.AddEntry(misid, "Mistidentified", "l")
    leg.AddEntry(mistag, "Mistag", "l")

    pltmgr.SetSinglePad(c)
    pltmgr.SetAxis(cor)
    cor.SetMaximum(pltmgr.GetHistYmax(cor) * 1.1)
    cor.GetYaxis().SetTitle("Events x 10^{3}")
    cor.GetXaxis().SetTitle("M_{lb} [GeV]")

    pltmgr.DrawCMSLabelOuter(pltmgr.SIMULATION)
    c.SaveAs(opt.GetResultName("Optimisation"))

    mistag.Add(misid)
    eff_cor = EffHist(cor, mistag)

    eff_cor.Draw("hist e")
    eff_cor.SetLineColor(pltmgr.Cyan)
    eff_cor.SetLineWidth(2)
    eff_cor.GetYaxis().SetTitle("Correct b-tagged rate")
    eff_cor.GetXaxis().SetTitle("M_{lb} [GeV]")
    eff_cor.SetMaximum(1)

    leg2 = pltmgr.NewLegend(0.68, 0.57, 0.8, 0.87)
    leg2.SetTextSize(16)
    leg2.SetFillColorAlpha(0, 1)
    leg2.AddEntry(eff_cor, "Correct type", "l")
    leg2.Draw()

    line = ROOT.TLine(150, 0, 150, 1)
    line.Draw()
    line.SetLineColor(ROOT.kRed)
    line.SetLineWidth(2)

    pltmgr.SetSinglePad(c)
    pltmgr.SetAxis(eff_cor)
    pltmgr.DrawCMSLabelOuter(pltmgr.SIMULATION)
    c.SaveAs(opt.GetResultName("Correct_eff"))
Exemple #2
0
def Plot2D(hist):
    c = pltmgr.NewCanvas()

    hist.Draw("COLZ")

    pltmgr.SetAxis(hist)
    pltmgr.SetSinglePadWithPalette(c)
    pltmgr.DrawCMSLabel(pltmgr.SIMULATION)
    pltmgr.DrawEntryLeft(opt.Entry())
    c.SaveAs(opt.GetResultName("2D_chi2_tmass"))
Exemple #3
0
def main():

    # Initiailze plot manager
    histmgr = pltmgr.Plotmgr()
    objlst = [
        "GenObs2", "Obs2", "GenObs3", "Obs3", "GenObs4", "Obs4", "GenObs7",
        "Obs7"
    ]
    filelst = [
        "results/Hist_co_TTbar_chi2_20_Acp_-20_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_-15_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_-10_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_-5_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_0_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_5_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_10_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_15_Opt_150.root",
        "results/Hist_co_TTbar_chi2_20_Acp_20_Opt_150.root"
    ]
    for file in filelst:
        histmgr.SetObjlst(file, objlst)

    # Loop object list
    for obj in ["Observable13", "Observable6", "Observable3", "Observable12"]:
        gr1 = GetGraph(histmgr)
        gr2 = GetGraph(histmgr)

        c = pltmgr.NewCanvas()
        pltmgr.SetSinglePad(c)

        pltmgr.SetAxis(gr1)
        gr1.SetTitle('')
        gr1.GetXaxis().SetTitle("Input asymmetry A_{CP} [%]")
        gr1.GetYaxis().SetTitle("Output asymmetry A_{CP} [%]")
        gr1.SetMarkerColor(ROOT.kAzure - 3)
        gr1.SetMarkerStyle(20)
        gr1.SetMaximum(pltmgr.GetGraphYmax(gr1) * 1.1)
        gr1.SetMinimum(pltmgr.GetGraphYmin(gr1) * 1.1)

        gr2.SetMarkerColor(ROOT.kRed - 7)
        gr2.SetMarkerStyle(22)

        fit_x1 = ROOT.TF1("fit_x1", "pol1", 0)
        fit_x1.SetLineColor(ROOT.kAzure - 3)
        gr1.Fit("fit_x1")

        fit_x2 = ROOT.TF1("fit_x2", "pol1", 0)
        fit_x2.SetLineColor(ROOT.kRed - 7)
        fit_x2.SetLineStyle(7)
        gr2.Fit("fit_x2")

        gr1.Draw('AEP')
        gr2.Draw('EP SAME')
        pltmgr.DrawCMSLabel(pltmgr.SIMULATION)
        pltmgr.DrawEntryLeft("1 lep, #geq 4 jets ( 2 b jets )")

        leg = pltmgr.NewLegend(0.65, 0.2, 0.85, 0.5)
        leg.SetHeader(obj)
        leg.AddEntry(gr1, "A_{CP}", "P")
        leg.AddEntry(gr2, "A'_{CP}", "P")
        leg.AddEntry(fit_x1, "Fit to A_{CP}", "L")
        leg.AddEntry(fit_x2, "Fit to A'_{CP}", "L")
        leg.Draw()

        c.SaveAs("results/Hist_{}.pdf".format(obj))
Exemple #4
0
def main():
    # Initialize parsing manager
    opt = parmgr.Parsemgr()
    opt.AddInput("c", "chi2").AddInput("e", "uncertainty").AddInput(
        "o", "opt").AddInput("r", "region")
    opt.AddFlag("p", "pileup").AddFlag("d", "driven").AddFlag("b",
                                                              "0bjet").AddFlag(
                                                                  "i", "ISO")

    opt.SetName("chi2", "uncertainty", "opt", "region", "pileup", "0bjet",
                "ISO")
    opt.Parsing()
    # Initialize plot manager
    histmgr = pltmgr.Plotmgr()
    objlst = [
        "Obs3", "Obs6", "Obs12", "Obs13", "had_tmass", "lep_tmass", "chi2",
        "LBJetPt", "HBJetPt", "LJetPt", "LJetEta", "LepPt", "LepEta", "LepIso",
        "nVtx", "Rho"
    ]
    for sample in input.samplelst:
        histmgr.SetObjlst(opt.GetFileName(sample), objlst, sample)

    if opt.GetOption("driven"):
        qcd_histlst = [histmgr.GetMergedObj("QCD") for o in objlst]
        histmgr.RemoveObj("QCD")
        histmgr.SetObjlst(
            opt.GetFileName("Data").replace("_WJets", "_QCD"), objlst, "QCD")
        opt.SetName("driven")

    # Loop objlst
    for obj in objlst:

        c = pltmgr.NewCanvas(obj)
        leg = pltmgr.NewLegend(0.67, 0.51, 0.8, 0.81)
        bg = ROOT.THStack()
        # Initiailze hist
        data = histmgr.GetObj("Data")
        histlst = []
        for i, mc in enumerate(info.mclst):
            histlst.append(histmgr.GetMergedObj(mc))
            histlst[i].SetLineColor(pltmgr.colorlst[i])
            histlst[i].SetFillColor(pltmgr.colorlst[i])
            bg.Add(histlst[i])
            leg.AddEntry(histlst[i], mc, "F")
            if mc == "QCD" and opt.GetOption("driven"):
                pltmgr.SetNormToUnity(histlst[i])
                histlst[i].Scale(qcd_histlst[i].Integral())
        leg.AddEntry(data, "Data", "le")

        bg_sum = pltmgr.SumHist(histlst)
        top = pltmgr.NewTopPad()
        top.Draw()
        top.cd()

        bg.Draw("HIST")
        data.Draw("EP same")
        leg.Draw()

        bg.GetYaxis().SetTitle("Events")
        bg.SetMaximum(pltmgr.GetHistYmax(data) * 1.5)
        pltmgr.SetTopPlotAxis(bg)
        data.SetLineColor(1)
        data.SetLineWidth(1)
        data.SetMarkerSize(0.5)
        data.SetMarkerStyle(20)

        c.cd()

        bot = pltmgr.NewBottomPad()
        bot.Draw()
        bot.cd()

        xmin = data.GetXaxis().GetXmin()
        xmax = data.GetXaxis().GetXmax()

        line = ROOT.TLine(xmin, 1.0, xmax, 1.0)
        upper = ROOT.TLine(xmin, 1.5, xmax, 1.5)
        lower = ROOT.TLine(xmin, 0.5, xmax, 0.5)
        rel = pltmgr.DivideHist(data, bg_sum, 1)

        rel.Draw("EP")
        upper.Draw("same")
        lower.Draw("same")
        line.Draw("same")

        line.SetLineColor(ROOT.kRed)
        upper.SetLineStyle(3)
        lower.SetLineStyle(3)

        rel.SetMaximum(1.6)
        rel.SetMinimum(0.4)
        rel.GetYaxis().SetTitle("Data/MC")
        rel.GetXaxis().SetTitle(data.GetXaxis().GetTitle())
        pltmgr.SetBottomPlotAxis(rel)

        c.cd()

        pltmgr.DrawCMSLabel(pltmgr.PRELIMINARY)
        pltmgr.DrawLuminosity(41540)
        pltmgr.DrawEntryLeft(opt.Entry())
        c.SaveAs(opt.GetResultName(obj))

        top.SetLogy(True)
        c.SaveAs(opt.GetResultName(obj + "_logy"))
Exemple #5
0
def main():
    # Initialize parsing manager
    opt = parmgr.Parsemgr()
    opt.AddInput("c", "chi2").AddInput("A", "Acp").AddInput("o", "opt")
    opt.Parsing("Simulation")

    # Initialize plot manager
    histmgr = pltmgr.Plotmgr()
    objlst = ["Obs3", "Obs6", "Obs12", "Obs13"]
    histmgr.SetObjlst(opt.GetFileName("ttbar"), objlst, "ttbar")

    hist = ROOT.TH1D("hist", "", 4, 0, 4)
    err1 = ROOT.TH1D("err1", "", 4, 0, 4)
    err2 = ROOT.TH1D("err2", "", 4, 0, 4)
    # Loop objlst
    for idx, obj in enumerate(objlst):

        # Initiailze hist
        h = histmgr.GetObj("ttbar")
        nm = h.Integral(0, h.FindBin(0) - 1)
        np = h.Integral(h.FindBin(0), 201)
        acp = (np - nm) / (np + nm)

        err_sq = 4. * np * nm / ((np + nm)**3)
        err = math.sqrt(err_sq)

        hist.SetBinContent(i + 1, Acp * 100)
        hist.SetBinError(i + 1, err * 100)
        err1.SetBinContent(i + 1, Acp * 100)
        err1.SetBinContent(i + 1, Acp * 100)
        err2.SetBinContent(i + 1, Acp * 100)
        err2.SetBinContent(i + 1, Acp * 200)

        hist.GetXaxis().SetBinLanbel(i + 1, obj)

    c = pltmgr.NewCanvas()
    hist.Draw()
    err2.Draw("E2 same")
    err1.Draw("E2 same")
    hist.Draw("EP same")

    err2.SetFillColor(ROOT.kYello)
    err1.SetFillColor(ROOT.kGreen)

    line = ROOT.TLine(0, 0, 4, 0)
    line.Draw("same")
    line.SetLineColor(ROOT.kRed)
    line.SetLineWidth(2)

    leg = pltmgr.NewLegend(0.65, 0.7, 0.8, 0.87)
    leg.Draw()
    leg.AddEntry(hist, "NOminal value", "LEP")
    leg.AddEntry(err1, "1#sigma stat. error", "F")
    leg.AddEntry(err2, "2#sigma stat. error", "F")

    hist.SetMaximum(pltmgr.GetHistYmax(hist) * 1.1)
    hist.SetMinimum(-1 * pltmgr.GetHistYmax(data) * 1.1)
    hist.GetYaxis().SetTitle("A'_{cp}[%]")

    pltmgr.SetSinglePad(c)
    pltmgr.SetAxis(hist)
    pltmgr.DrawCMSLabelOuter(pltmgr.SIMULATION)
    c.SaveAs(opt.GetResultName("Acp"))
Exemple #6
0
def PlotIntegral(correct, misid, mistag):

    cor_eff = ROOT.TH1D("cor_eff", "", 200, 0, 200)
    tag_eff = ROOT.TH1D("tag_eff", "", 200, 0, 200)
    ide_eff = ROOT.TH1D("ide_eff", "", 200, 0, 200)
    eve_eff = ROOT.TH1D("eve_eff", "", 200, 0, 200)

    total = correct.Integral(1, 201) + misid.Integral(
        1, 201) + mistag.Integral(1, 201)
    print total

    for i in range(202):
        cor = correct.Integral(1, i)
        ide = misid.Integral(1, i)
        tag = mistag.Integral(1, i)
        sum = cor + ide + tag

        cor_eff.SetBinContent(i, float(cor / sum))
        tag_eff.SetBinContent(i, float(tag / sum))
        ide_eff.SetBinContent(i, float(ide / sum))

        eve_eff.SetBinContent(i, float(sum / total))

    c = pltmgr.NewCanvas()
    leg = pltmgr.NewLegend(0.7, 0.6, 0.92, 0.87)
    leg.SetTextSize(16)
    leg.SetFillColorAlpha(0, 1)
    cor_eff.Draw("hist")
    tag_eff.Draw("hist same")
    ide_eff.Draw("hist same")
    eve_eff.Draw("hist same")
    leg.Draw()

    cor_eff.SetStats(0)
    cor_eff.GetXaxis().SetTitle("#chi^{2}_{min} upper cut")
    cor_eff.GetYaxis().SetTitle("Rate")

    cor_eff.SetLineColor(pltmgr.Green)
    tag_eff.SetLineColor(pltmgr.Magenta)
    ide_eff.SetLineColor(pltmgr.Cyan)
    eve_eff.SetLineColor(pltmgr.Blue)

    cor_eff.SetLineWidth(2)
    tag_eff.SetLineWidth(2)
    ide_eff.SetLineWidth(2)
    eve_eff.SetLineWidth(2)

    leg.AddEntry(cor_eff, "Correct", "l")
    leg.AddEntry(tag_eff, "Mistag", "l")
    leg.AddEntry(ide_eff, "b-Misidentified", "l")
    leg.AddEntry(eve_eff, "Event efficiency", "l")

    line = ROOT.TLine(20, 0, 20, 1)
    line.Draw("same")
    line.SetLineColor(ROOT.kRed)
    line.SetLineWidth(2)
    line.SetLineStyle(7)

    cor_eff.SetMaximum(1.)
    cor_eff.SetMinimum(0.)
    pltmgr.SetSinglePad(c)
    pltmgr.SetAxis(cor_eff)

    c.SetGrid()
    pltmgr.DrawCMSLabelOuter(pltmgr.SIMULATION)
    pltmgr.DrawEntryRight(opt.Entry())
    c.SaveAs(opt.GetResultName("Chi2_uppercut"))
Exemple #7
0
def main():
    # Initialize parsing manager
    global opt
    opt = parmgr.Parsemgr()
    opt.AddInput("c", "chi2").AddFlag("B", "bbSep").AddFlag("p", "pileup")
    opt.Parsing("MatchType")

    # Initialize plot manager
    histmgr = pltmgr.Plotmgr()
    objlst = [
        "chi2_tmass", "chi2_Correct", "chi2_Misid", "chi2_Mistag",
        "Cor_leptmass", "Misid_leptmass", "Mistag_leptmass"
    ]
    histmgr.SetObjlst(opt.GetFileName("ttbar"), objlst)

    # Plot 2D_chi2_tmass
    Plot2D(histmgr.GetObj("ttbar"))

    # Plot objlst
    correct = histmgr.GetObj("ttbar")
    misid = histmgr.GetObj("ttbar")
    mistag = histmgr.GetObj("ttbar")

    Cor_leptmas = histmgr.GetObj("ttbar")
    Misid_leptmass = histmgr.GetObj("ttbar")
    Mistag_leptmass = histmgr.GetObj("ttbar")

    OptLeptmass(Cor_leptmas, Misid_leptmass, Mistag_leptmass)

    PlotIntegral(correct, misid, mistag)

    c = pltmgr.NewCanvas()
    leg = pltmgr.NewLegend(0.7, 0.65, 0.83, 0.87)

    correct.Draw("hist")
    misid.Draw("hist same")
    mistag.Draw("hist same")
    leg.Draw()

    correct.SetLineColor(pltmgr.Azure)
    misid.SetLineColor(pltmgr.Green)
    mistag.SetLineColor(pltmgr.Red)

    correct.SetLineWidth(2)
    misid.SetLineWidth(2)
    mistag.SetLineWidth(2)

    pltmgr.SetNormToUnity(correct)
    pltmgr.SetNormToUnity(misid)
    pltmgr.SetNormToUnity(mistag)

    pltmgr.SetSinglePad(c)
    pltmgr.SetAxis(correct)
    correct.SetMaximum(1.)

    leg.AddEntry(correct, "Correct", "l")
    leg.AddEntry(misid, "b-Misidentified", "l")
    leg.AddEntry(mistag, "Mistag", "l")

    c.SetLogy(True)
    pltmgr.DrawEntryRight(opt.Entry())
    pltmgr.DrawCMSLabelOuter(pltmgr.SIMULATION)
    c.SaveAs(opt.GetResultName("Rate_PDF"))