Esempio n. 1
0
def DrawSignalEff(cut_lst,
                  inputdir="b77",
                  inputroot="sum",
                  outputname="",
                  normalization=1.0,
                  plotrange=(0, 3100),
                  logy=0):
    ### the first argument is the input directory
    ### the second argument is the output prefix name
    ### the third argument is relative to what normalization: 0 for total number of events
    ### 1 for signal mass region
    histname = "_Signal_Significance"

    canv = ROOT.TCanvas(
        outputname + "_" + str(plotrange[0]) + "_" + str(plotrange[1]),
        "Efficiency", 800, 800)
    xleg, yleg = 0.65, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg + 0.2, yleg + 0.2)

    # two pad
    pad0 = ROOT.TPad("pad0", "pad0", 0.0, 0.31, 1., 1.)
    pad0.SetRightMargin(0.05)
    pad0.SetBottomMargin(0.0001)
    pad0.SetFrameFillColor(0)
    pad0.SetFrameBorderMode(0)
    pad0.SetFrameFillColor(0)
    pad0.SetBorderMode(0)
    pad0.SetBorderSize(0)

    pad1 = ROOT.TPad("pad1", "pad1", 0.0, 0.0, 1., 0.30)
    pad1.SetRightMargin(0.05)
    pad1.SetBottomMargin(0.38)
    pad1.SetTopMargin(0.0001)
    pad1.SetFrameFillColor(0)
    pad1.SetFillStyle(0)  # transparent
    pad1.SetFrameBorderMode(0)
    pad1.SetFrameFillColor(0)
    pad1.SetBorderMode(0)
    pad1.SetBorderSize(0)

    #top pad
    canv.cd()
    pad0.SetLogy(logy)
    pad0.Draw()
    pad0.cd()
    # setup basic plot parameters
    lowmass = -50
    highmass = 3150
    # load input MC file
    input_mc = ROOT.TFile.Open(CONF.inputpath + inputdir + "/" + inputroot +
                               "_" + inputdir + ".root")
    maxbincontent = normalization
    minbincontent = 0.0001
    temp_all = input_mc.Get(cut_lst[0] + histname).Clone()
    temp_all.SetName("Combined")

    input_mc_ref = ROOT.TFile.Open(CONF.inputpath + "ref/" + "sum_ref" +
                                   ".root")
    temp_ref = input_mc_ref.Get(cut_lst[0] + histname).Clone()
    temp_ref.SetName("Run2-ref")

    temp_ratio = input_mc.Get(cut_lst[0] + histname).Clone()
    temp_ratio.SetName("Ratio")

    for j in range(1, temp_all.GetNbinsX() + 1):
        temp_all.SetBinContent(j, 0)
        temp_all.SetBinError(j, 0)
        temp_ref.SetBinContent(j, 0)
        temp_ref.SetBinError(j, 0)
        temp_all.SetMinimum(minbincontent)
        temp_ref.SetMinimum(minbincontent)

    graph_lst = []

    for i, cut in enumerate(cut_lst):
        #print cut
        sig_mc = input_mc.Get(cut + histname)  #get the input histogram
        sig_mc_ref = input_mc_ref.Get(cut + histname)  #get the input histogram
        for j in range(1, temp_all.GetNbinsX() + 1):
            #temp_all.SetBinContent(j, ROOT.TMath.Sqrt(temp_all.GetBinContent(j) * temp_all.GetBinContent(j) + sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j)))
            temp_ref.SetBinContent(
                j,
                ROOT.TMath.Sqrt(
                    temp_ref.GetBinContent(j) * temp_ref.GetBinContent(j) +
                    sig_mc_ref.GetBinContent(j) * sig_mc_ref.GetBinContent(j)))
            temp_all.SetBinContent(
                j,
                ROOT.TMath.Sqrt(
                    temp_all.GetBinContent(j) * temp_all.GetBinContent(j) +
                    sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j)))
            temp_ref.SetBinError(
                j,
                ROOT.TMath.Sqrt(
                    temp_ref.GetBinError(j) * temp_ref.GetBinError(j) +
                    sig_mc_ref.GetBinError(j) * sig_mc_ref.GetBinError(j)))
            temp_all.SetBinError(
                j,
                ROOT.TMath.Sqrt(
                    temp_all.GetBinError(j) * temp_all.GetBinError(j) +
                    sig_mc.GetBinError(j) * sig_mc.GetBinError(j)))
        del (sig_mc_ref)

        graph_lst.append(helpers.TH1toTAsym(sig_mc, pltrange=plotrange))
        graph_lst[i].SetMaximum(maxbincontent * 1.5)
        graph_lst[i].SetMinimum(minbincontent)
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(20 + i)
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        legend.AddEntry(graph_lst[i], cut.replace("_", " "), "APL")

        if cut == cut_lst[0]:
            graph_lst[i].Draw("APC")
        else:
            graph_lst[i].Draw("PC")
        del (sig_mc)

    graph_all = helpers.TH1toTAsym(temp_all)
    graph_all.SetLineColor(2)
    graph_all.SetLineStyle(2)
    graph_all.SetMarkerStyle(5)
    graph_all.SetMarkerColor(2)
    graph_all.SetMarkerSize(1)
    graph_all.GetXaxis().SetRangeUser(plotrange[0], plotrange[1])
    legend.AddEntry(graph_all, graph_all.GetName().replace("_", " "), "APL")
    graph_all.Draw("PC")

    graph_ref = helpers.TH1toTAsym(temp_ref)
    graph_ref.SetLineColor(1)
    graph_ref.SetLineStyle(3)
    graph_ref.SetMarkerStyle(4)
    graph_ref.SetMarkerColor(1)
    graph_ref.SetMarkerSize(1)
    graph_ref.GetXaxis().SetRangeUser(plotrange[0], plotrange[1])
    legend.AddEntry(graph_ref, graph_ref.GetName().replace("_", " "), "APL")
    graph_ref.Draw("PC")

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.02)
    legend.Draw()

    # draw reference lines
    xline05 = ROOT.TLine(lowmass, 0.05, highmass, 0.05)
    xline05.SetLineStyle(3)
    xline05.Draw()
    xline10 = ROOT.TLine(lowmass, 0.1, highmass, 0.1)
    xline10.SetLineStyle(4)
    xline10.Draw()
    yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent)
    yline05.SetLineStyle(9)
    yline05.Draw()
    yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent)
    yline10.SetLineStyle(9)
    yline10.Draw()
    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0")
    lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()

    #bottom pad
    canv.cd()
    pad1.Draw()
    pad1.cd()
    for j in range(1, temp_ratio.GetNbinsX() + 1):
        try:
            temp_ratio.SetBinContent(
                j,
                temp_all.GetBinContent(j) / temp_ref.GetBinContent(j))
            temp_ratio.SetBinError(j, helpers.ratioerror(\
                temp_all.GetBinContent(j), temp_ref.GetBinContent(j), \
                temp_all.GetBinError(j), temp_ref.GetBinError(j)))
        except ZeroDivisionError:
            pass
            #print "Divide by zero! Check bin content in", canv.GetName()

    temp_ratio.SetMarkerStyle(20)
    temp_ratio.SetMarkerColor(1)
    temp_ratio.SetMarkerSize(1)
    temp_ratio.GetYaxis().SetTitleFont(43)
    temp_ratio.GetYaxis().SetTitleSize(28)
    temp_ratio.GetYaxis().SetLabelFont(43)
    temp_ratio.GetYaxis().SetLabelSize(28)
    temp_ratio.GetYaxis().SetTitle(" %s/ ref" % inputdir)
    temp_ratio.GetYaxis().SetRangeUser(0.7, 1.2)  #set range for ratio plot
    temp_ratio.GetYaxis().SetNdivisions(405)

    temp_ratio.GetXaxis().SetTitleFont(43)
    temp_ratio.GetXaxis().SetTitleOffset(3.5)
    temp_ratio.GetXaxis().SetTitleSize(28)
    temp_ratio.GetXaxis().SetLabelFont(43)
    temp_ratio.GetXaxis().SetLabelSize(28)
    temp_ratio.GetXaxis().SetRangeUser(plotrange[0], plotrange[1])
    temp_ratio.GetXaxis().SetTitle("mass, GeV")

    temp_ratio.Draw("ep")
    # draw the ratio 1 line
    line = ROOT.TLine(plotrange[0], 1.0, plotrange[1], 1.0)
    line.SetLineStyle(1)
    line.Draw()

    # finish up
    if logy != 0:
        canv.SetName(canv.GetName() + "_1")
    canv.SaveAs(outputpath + canv.GetName() + ".pdf")

    pad0.Close()
    pad1.Close()
    canv.Close()
    input_mc.Close()
    input_mc_ref.Close()
    #clean up all the pointers...
    del (temp_all)
    del (temp_ref)
    del (temp_ratio)
    del (graph_all)
    del (graph_ref)
    del (graph_lst)
Esempio n. 2
0
def DrawSignalTruth(outputroot,
                    dcut_lst,
                    scut_lst,
                    inputdir="",
                    outputname="",
                    normalization=0):
    ### the first argument is the input directory
    ### the second argument is the output prefix name
    ### the third argument is relative to what normalization: 0 for total number of events
    ### 1 for signal mass region

    # setup basic plot parameters
    lowmass = -50
    highmass = 3150
    # load input MC file
    maxbincontent = .4  # approx
    minbincontent = -0.01

    for i, (dcut, scut) in enumerate(zip(dcut_lst, scut_lst)):
        canv = ROOT.TCanvas(inputdir + "_" + outputname + str(normalization),
                            "Efficiency", 800, 800)
        xleg, yleg = 0.55, 0.7
        legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2)

        sfiles = [
            "/signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass
            for mass in mass_lst
        ]
        sinfos = ["RSG " + str(m) + " GeV" for m in mass_lst]
        dfiles = ["/data_test/hist-MiniNTuple.root"]
        dinfos = ["0Tag data"]
        allmc = []
        for j, (f, info) in enumerate(zip(dfiles + sfiles, dinfos + sinfos)):
            cut = dcut if "data" in f else scut

            #here could be changed to have more options
            input_mc = ROOT.TFile.Open(CONF.inputpath + inputdir + f)
            if not input_mc:
                print CONF.inputpath + inputdir + f
            try:
                temp_mc = input_mc.Get(cut).Clone()
#temp_mc = temp_mc.ProjectionY()
            except:
                print CONF.inputpath + inputdir + f
                print cut
                raise

# rebin the hist for pt
# set other options
            temp_mc.GetYaxis().SetTitle("Normalized")
            temp_mc.GetXaxis().SetNdivisions(510)
            temp_mc.GetXaxis().SetLabelSize(0.03)
            temp_mc.GetYaxis().SetNdivisions(505)
            if cut.split("_")[-1] == "pt":
                temp_mc.Rebin(10)
                temp_mc.GetXaxis().SetTitle(temp_mc.GetXaxis().GetTitle() +
                                            " [GeV]")
            elif "deta" in cut.lower():
                temp_mc.Rebin(30)
                maxbincontent = .6 / 1.5
                # draw line at the cut value
                cutval = 1.7
                line = ROOT.TLine(1.7, 0, 1.7, 0.4)
                line.SetLineWidth(3)
                line.SetLineStyle(9)
                line.Draw()
            else:
                temp_mc.GetXaxis().SetTitle("#DeltaR between H, child b")
                dR_type = cut.split("/")[1][0:4]
                if dR_type != "h0h1":
                    temp_mc.GetXaxis().SetRangeUser(0, 3)
                    maxbincontent = 1.0 / 1.5
                else:
                    maxbincontent = .5
                if dR_type == "h1b2" or dR_type == "h0b0":
                    dR1_line = ROOT.TLine(1, 0, 1, maxbincontent)
                    dR04_line = ROOT.TLine(.4, 0, .4, maxbincontent)
                    dR1_line.Draw("")
                    dR04_line.Draw("")
                elif dR_type == "b0b1" or dR_type == "b2b3":
                    dR1_line = ROOT.TLine(2, 0, 2, maxbincontent)
                    dR04_line = ROOT.TLine(.8, 0, .8, maxbincontent)
                    dR1_line.Draw("")
                    dR04_line.Draw("")

            if temp_mc.GetNbinsX() == 76:
                temp_mc.Rebin(4)
            elif temp_mc.GetNbinsX() > 20:
                temp_mc.Rebin(temp_mc.GetNbinsX() / 20)

            if "data" in f:
                temp_mc.Sumw2(True)

            outputroot.cd()
            temp_mc.Scale(1 / temp_mc.Integral())
            temp_mc.SetName("RSG_" + info + "_" + cut.replace("/", "_"))
            temp_mc.Write()
            temp2_mc = outputroot.Get(temp_mc.GetName())

            if temp_mc.Integral() < 1e-4:
                continue
            truth_mc = helpers.TH1toTAsym(temp2_mc, efficiency=False)

            truth_mc.SetLineColor(CONF.clr_lst[j])
            truth_mc.SetMarkerStyle(20 + j)
            truth_mc.SetMarkerColor(CONF.clr_lst[j])
            truth_mc.SetMarkerSize(1)
            truth_mc.SetMaximum(maxbincontent * 1.5)
            truth_mc.SetMinimum(minbincontent)
            truth_mc.GetXaxis().SetTitle(cut.split("/")[1].replace("_", " "))
            canv.cd()
            #reset data style
            if "data" in f:
                truth_mc.SetLineColor(1)
                truth_mc.SetMarkerColor(1)
            if j == 0:
                truth_mc.Draw("APC")
            else:
                truth_mc.Draw("PC")

            allmc.append(truth_mc)
            legend.AddEntry(truth_mc, info, "apl")
            input_mc.Close()

        legend.SetBorderSize(0)
        legend.SetMargin(0.3)
        legend.SetTextSize(0.04)
        legend.Draw()

        # draw watermarks
        xatlas, yatlas = 0.35, 0.87
        atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
        hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0")
        lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV")
        watermarks = [atlas, hh4b, lumi]

        for wm in watermarks:
            wm.SetTextAlign(22)
            wm.SetTextSize(0.04)
            wm.SetTextFont(42)
            wm.SetNDC()
            wm.Draw()

        # finish up
        outputroot.cd()
        helpers.checkpath(CONF.inputpath + inputdir + "/Plot/Truth/")
        #print CONF.inputpath + inputdir + "/Plot/Truth/"
        canv.SaveAs(CONF.inputpath + inputdir + "/Plot/Truth/" +
                    canv.GetName() + "_" + cut.replace("/", "_") + ".pdf")
        canv.Close()
Esempio n. 3
0
def DrawPtEff(inputdir, outputname=""):
    ### the first argument is the input directory
    ### the second argument is the output prefix name
    ### the third argument is relative to what normalization: 0 for total number of events
    ### 1 for signal mass region

    canv = ROOT.TCanvas(inputdir + "_pT_" + "Efficiency", "Efficiency", 800,
                        800)
    xleg, yleg = 0.55, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2)
    # setup basic plot parameters
    # load input MC file
    eff_lst = []
    graph_lst = []
    maxbincontent = 1
    minbincontent = -0.01
    year = (outputname.split("_")[1] if "_" in outputname else "")
    file_lst = [
        "data_test", "signal_G_hh_c10_M1000", "signal_G_hh_c10_M1100",
        "signal_G_hh_c10_M1200"
    ]
    leg_lst = ["Data" + year, "RSG 1TeV", "RSG 1.1TeV", "RSG 1.2TeV"]
    for i, file in enumerate(file_lst):

        input_mc = ROOT.TFile.Open(inputpath + file +
                                   (year if "data" in file else "") +
                                   "/hist-MiniNTuple" + ".root")
        hist_tag = input_mc.Get(
            "h_leadHCand_pT_pre_trig").Clone()  #hist before trigger
        hist_prob = input_mc.Get(
            "h_leadHCand_pT_aft_trig").Clone()  #hist after trigger

        xMin = hist_tag.GetXaxis().GetXmin()
        xMax = hist_tag.GetXaxis().GetXmax()
        #print xMin, xMax
        eff_lst.append(
            ROOT.TH1F(file + "_pT_eff", ";p_{T} [GeV]; Efficiency",
                      hist_tag.GetXaxis().GetNbins(), xMin, xMax))

        for j in range(hist_tag.GetXaxis().GetNbins() + 1):
            #print j, hist_prob.GetBinContent(j), hist_prob.GetBinCenter(j)
            if hist_prob.GetBinContent(j) > 0:
                eff_lst[i].SetBinContent(
                    j,
                    hist_prob.GetBinContent(j) / hist_tag.GetBinContent(j))
                eff_lst[i].SetBinError(
                    j,
                    helpers.ratioerror(hist_prob.GetBinContent(j),
                                       hist_tag.GetBinContent(j),
                                       hist_prob.GetBinError(j),
                                       hist_tag.GetBinError(j)))

        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(20 + i)
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        graph_lst[i].SetMaximum(maxbincontent * 1.5)
        graph_lst[i].SetMinimum(minbincontent)
        legend.AddEntry(graph_lst[i], leg_lst[i].replace("_", " "), "apl")
        canv.cd()
        if i == 0:
            graph_lst[i].Draw("APC")
        else:
            graph_lst[i].Draw("PC")
        input_mc.Close()

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.04)
    legend.Draw()

    # draw reference lines
    xline90 = ROOT.TLine(xMin, 0.9, xMax, 0.9)
    xline90.SetLineStyle(3)
    xline90.Draw()
    xline95 = ROOT.TLine(xMin, 0.95, xMax, 0.95)
    xline95.SetLineStyle(4)
    xline95.Draw()
    xline98 = ROOT.TLine(xMin, 0.98, xMax, 0.98)
    xline98.SetLineStyle(5)
    xline98.Draw()
    yline45 = ROOT.TLine(450, 0.00, 450, 1.00)
    yline45.SetLineStyle(5)
    yline45.Draw()

    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0")
    lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()
    # finish up
    canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf")
    canv.Close()
Esempio n. 4
0
def Compare_Optimise(targetdir="AllTag_Signal",
                     targetplot="hCandDeta",
                     masslist=[1000, 1200, 1500, 1800, 2000, 2500, 3000]):
    print targetdir, targetplot
    canv = ROOT.TCanvas(targetdir + "_" + targetplot, "Optimizer", 800, 800)
    xleg, yleg = 0.52, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2)
    # setup basic plot parameters
    # load input MC file
    eff_lst = []
    graph_lst = []
    maxbincontent = 0.0001
    minbincontent = 0.00001

    for i, mass in enumerate(masslist):
        print mass,
        eff_lst.append(
            Optimise(
                "data_test/hist-MiniNTuple.root",
                ("signal_G_hh_c10_M" if not ops.Xhh else "signal_X_hh_M") +
                str(mass) + "/hist-MiniNTuple.root", "NoTag_Signal", targetdir,
                targetplot))
        maxbincontent = max(eff_lst[i].GetMaximum(), maxbincontent)

        canv.cd()
        #convert it to a TGraph
        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(20 + i)
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        graph_lst[i].SetMaximum(maxbincontent * 1.5)
        graph_lst[i].SetMinimum(minbincontent)
        legend.AddEntry(graph_lst[i], str(mass).replace("_", " "), "apl")
        if i == 0:
            graph_lst[i].Draw("APC")
            #gr.Draw("same L hist")
        else:
            graph_lst[i].Draw("PC")
            #gr.Draw("same L hist")

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.04)
    legend.Draw()

    # draw reference lines
    yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent)
    yline05.SetLineStyle(9)
    yline05.Draw()
    yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent)
    yline10.SetLineStyle(9)
    yline10.Draw()
    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b = ROOT.TLatex(xatlas, yatlas - 0.06,
                       "RSG c=1.0" if not ops.Xhh else "2HDM")
    lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()
    # finish up
    # canv.SetLogy(1)
    canv.SaveAs(outputpath + ("G10_" if not ops.Xhh else "2HDM_") +
                canv.GetName() + ".pdf")
    canv.Close()
Esempio n. 5
0
def DrawSignalEff(cut_lst,
                  inputdir="b77",
                  outputname="",
                  normalization="All",
                  doint=False,
                  donormint=False,
                  dorel=False):
    ### the first argument is the input directory
    ### the second argument is the output prefix name
    ### the third argument is relative to what normalization: 0 for total number of events
    ### 1 for signal mass region
    afterscript = "_rel" if dorel else ""
    canv = ROOT.TCanvas(
        inputdir + "_" + "Efficiency" + "_" + normalization + afterscript,
        "Efficiency", 800, 800)
    xleg, yleg = 0.55, 0.73
    legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.18)
    # setup basic plot parameters
    # load input MC file
    eff_lst = []
    graph_lst = []
    maxbincontent = 0.001
    minbincontent = -0.001

    for i, cut in enumerate(cut_lst):
        eff_lst.append(
            ROOT.TH1F(inputdir + "_" + cut,
                      "%s; Mass [GeV]; Acceptance x Efficiency" % cut,
                      int((highmass - lowmass) / 100), lowmass, highmass))

        for mass in mass_lst:
            #here could be changed to have more options
            input_mc = ROOT.TFile.Open(
                inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass)
            cutflow_mc = input_mc.Get("CutFlowNoWeight").Clone(
            )  #notice here we use no weight for now!
            cutflow_mc_w = input_mc.Get("CutFlowWeight").Clone()
            if dorel:
                maxbincontent = 1.0
                if i > 0:
                    normalization = cut_lst[i - 1]
            totevt_mc = cutflow_mc.GetBinContent(
                cutflow_mc.GetXaxis().FindBin(normalization))
            cutevt_mc = cutflow_mc.GetBinContent(
                cutflow_mc.GetXaxis().FindBin(cut))
            #this is a really dirty temp fix
            scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\
                / (cutflow_mc_w.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)
            #for cuts that are defined in folders but not in the cutflow table...
            if doint:
                cuthist_temp = input_mc.Get(cut + "/mHH_l")
                cutevt_mc = cuthist_temp.Integral(
                    0,
                    cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight
            if donormint:
                cuthist_temp = input_mc.Get(normalization + "/mHH_l")
                totevt_mc = cuthist_temp.Integral(
                    0,
                    cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight

            eff_content = cutevt_mc / totevt_mc
            eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass),
                                     cutevt_mc / totevt_mc)
            eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass),
                                   helpers.ratioerror(cutevt_mc, totevt_mc))
            maxbincontent = max(maxbincontent, eff_content)
            # print ratioerror(cutevt_mc, totevt_mc)
            input_mc.Close()

        canv.cd()
        #maxbincontent = 0.15
        #convert it to a TGraph
        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(CONF.mrk_lst[i])
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        graph_lst[i].SetMaximum(maxbincontent * 1.6)
        graph_lst[i].SetMinimum(minbincontent)
        #print cut_dic[cut]
        legend.AddEntry(graph_lst[i], cut_dic[cut], "apl")
        if cut == cut_lst[0]:
            graph_lst[i].Draw("APC")
            #gr.Draw("same L hist")
        else:
            graph_lst[i].Draw("PC")
            #gr.Draw("same L hist")

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextFont(42)
    legend.SetTextSize(0.03)
    legend.Draw()

    # draw reference lines
    yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent)
    yline05.SetLineStyle(9)
    #yline05.Draw()
    yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent)
    yline10.SetLineStyle(9)
    #yline10.Draw()
    # draw watermarks
    xatlas, yatlas = 0.2, 0.87
    #atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Preliminary")
    #ATLASLabel(xatlas, yatlas, "Preliminary")
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS")
    #atlas.SetTextAlign(22)
    atlas.SetTextSize(0.04)
    atlas.SetTextFont(72)
    atlas.SetNDC()
    atlas.Draw()
    status = ROOT.TLatex(xatlas + 0.14, yatlas, CONF.StatusLabel)
    #status.SetTextAlign(22)
    status.SetTextSize(0.04)
    status.SetTextFont(42)
    status.SetNDC()
    status.Draw()

    myText(xatlas, yatlas - 0.05, 1, "G c=1.0, #sqrt{s} = 13 TeV",
           CONF.paperlegsize - 2)
    myText(xatlas, yatlas - 0.1, 1, "Boosted", CONF.paperlegsize - 2)
    # finish up
    canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf")
    canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".eps")
    canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".png")
    canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".C")
    canv.Close()
Esempio n. 6
0
def DrawSignalEff(cut_lst,
                  inputdir="b77",
                  outputname="",
                  normalization="All",
                  doint=False,
                  donormint=False,
                  dorel=False,
                  dorelfcomp=False):
    ### the first argument is the input directory
    ### the second argument is the output prefix name
    ### the third argument is relative to what normalization: 0 for total number of events
    ### 1 for signal mass region
    afterscript = ("_rel" if dorel else "") + ("_ref" if dorelfcomp else "")
    canv = ROOT.TCanvas(
        inputdir + "_" + "Efficiency" + "_" + normalization + afterscript,
        "Efficiency", 800, 800)
    xleg, yleg = 0.52, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2)
    # setup basic plot parameters
    # load input MC file
    eff_lst = []
    graph_lst = []
    maxbincontent = 0.001
    minbincontent = -0.001

    for i, cut in enumerate(cut_lst):
        eff_lst.append(
            ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" % cut,
                      int((highmass - lowmass) / 100), lowmass, highmass))

        for mass in mass_lst:
            #here could be changed to have more options
            input_mc_type = "signal_G_hh_c10_M" if not ops.Xhh else "signal_X_hh_M"
            input_mc = ROOT.TFile.Open(inputpath + input_mc_type +
                                       "%i/hist-MiniNTuple.root" % mass)
            cutflow_mc = input_mc.Get("CutFlowNoWeight").Clone(
                "CutFlowNoWeight")  #notice here we use no weight for now!
            cutflow_mc_w = input_mc.Get("CutFlowWeight").Clone("CutFlowWeight")
            if dorel:
                maxbincontent = 1.0
                if i > 0:
                    normalization = cut_lst[i - 1]
            totevt_mc = cutflow_mc.GetBinContent(
                cutflow_mc.GetXaxis().FindBin(normalization))
            cutevt_mc = cutflow_mc.GetBinContent(
                cutflow_mc.GetXaxis().FindBin(cut))
            #this is a really dirty temp fix
            scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\
                / (cutflow_mc_w.GetBinContent(cutflow_mc_w.GetXaxis().FindBin("All")) * 1.0)

            #this is really only for doing reference comparison only!
            input_mc_ref = ROOT.TFile.Open(CONF.inputpath + "ref" + "/" +
                                           "signal_G_hh_c10_M" +
                                           "%i/hist-MiniNTuple.root" % mass)
            cutflow_mc_ref = input_mc_ref.Get("CutFlowNoWeight").Clone(
                "CutFlowNoWeight_ref")  #notice here we use no weight for now!
            cutflow_mc_w_ref = input_mc_ref.Get("CutFlowWeight").Clone(
                "CutFlowWeight_ref")
            totevt_mc_ref = cutflow_mc_ref.GetBinContent(
                cutflow_mc_ref.GetXaxis().FindBin(normalization))
            cutevt_mc_ref = cutflow_mc_ref.GetBinContent(
                cutflow_mc_ref.GetXaxis().FindBin(cut))
            scale_weight_ref = (cutflow_mc_ref.GetBinContent(cutflow_mc_ref.GetXaxis().FindBin("All")) * 1.0)\
                / (cutflow_mc_w_ref.GetBinContent(cutflow_mc_w_ref.GetXaxis().FindBin("All")) * 1.0)

            #print cut, mass, cutevt_mc, totevt_mc, cutevt_mc_ref, totevt_mc_ref
            #for cuts that are defined in folders but not in the cutflow table...
            if doint:
                cuthist_temp = input_mc.Get(cut + "/mHH_l")
                cutevt_mc = cuthist_temp.Integral(
                    0,
                    cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight
                cuthist_temp_ref = input_mc_ref.Get(cut + "/mHH_l")
                cutevt_mc_ref = cuthist_temp_ref.Integral(
                    0,
                    cuthist_temp_ref.GetXaxis().GetNbins() +
                    1) * scale_weight_ref
            if donormint:
                cuthist_temp = input_mc.Get(normalization + "/mHH_l")
                totevt_mc = cuthist_temp.Integral(
                    0,
                    cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight
                cuthist_temp_ref = input_mc_ref.Get(normalization + "/mHH_l")
                totevt_mc_ref = cuthist_temp_ref.Integral(
                    0,
                    cuthist_temp_ref.GetXaxis().GetNbins() +
                    1) * scale_weight_ref

            #for ref comparison
            if dorel and dorelfcomp:
                totevt_mc = totevt_mc * (cutevt_mc_ref / totevt_mc_ref) * 1.0
            elif dorelfcomp:
                totevt_mc = cutevt_mc_ref * 1.0
                minbincontent = 0.5

            # if mass == 2500:
            #     print "m:{:>5} c:{:>24} evt:{:>8};".format(mass, cut, cutevt_mc)

            #continue as usual
            eff_content = cutevt_mc / totevt_mc
            eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass),
                                     cutevt_mc / totevt_mc)
            eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass),
                                   helpers.ratioerror(cutevt_mc, totevt_mc))
            maxbincontent = max(maxbincontent, eff_content)
            # print ratioerror(cutevt_mc, totevt_mc)
            input_mc.Close()
            input_mc_ref.Close()

        canv.cd()
        #convert it to a TGraph
        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(20 + i)
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        graph_lst[i].SetMaximum(maxbincontent * 1.5)
        graph_lst[i].SetMinimum(minbincontent)
        legend.AddEntry(graph_lst[i], cut.replace("_", " "), "apl")
        if cut == cut_lst[0]:
            graph_lst[i].Draw("APC")
            #gr.Draw("same L hist")
        else:
            graph_lst[i].Draw("PC")
            #gr.Draw("same L hist")

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.03)
    legend.Draw()

    # draw reference lines
    yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent)
    yline05.SetLineStyle(9)
    yline05.Draw()
    yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent)
    yline10.SetLineStyle(9)
    yline10.Draw()
    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b = ROOT.TLatex(xatlas, yatlas - 0.06,
                       "RSG c=1.0" if not ops.Xhh else "2HDM")
    lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi] if not CONF.thesis else [hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()
    # finish up
    canv.SaveAs(outputpath + outputname + ("_" if not ops.Xhh else "_2HDM_") +
                canv.GetName() + ".pdf")
    canv.Close()
Esempio n. 7
0
def plot_RSG_syst_detail(masterdic, cut):
    canv = ROOT.TCanvas(cut  + "_" +  "RSG" + "_" + "syst_detail", "Sytematics", 800, 800)
    xleg, yleg = 0.52, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2)
    # setup basic plot parameters
    # load input MC file
    mass_lst = [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1800, 2000, 2250, 2500, 2750, 3000]
    eff_lst = []
    graph_lst = []
    maxbincontent = 100.0
    minbincontent = -0.001
    lowmass  = 950
    highmass = 3150

    #create bsyst list
    bsyst_lst = []
    for i in bsyst:
        if "up" in i:
            bsyst_lst.append(i.replace("up", ""))

    #now loop
    draw_counter = 0
    for i, syst in enumerate(bsyst_lst):
        eff_lst.append( ROOT.TH1F(syst, "%s; Mass, GeV; Systematic Percentage Diff" %syst, int((highmass-lowmass)/100), lowmass, highmass) )
        maxsyst = 0.0
        for mass in mass_lst:
            temp_col_dic = find_syst(masterdic, cut, syst, "RSG1_" + str(mass))
            syst_eff = add_syst(temp_col_dic) #this is a tuple!
            # if (syst_eff[0] * 100 < 3): #if the systematic contribution is less than 3 percent
            #     continue
            eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), syst_eff[0] * 100)
            eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), 0)
            #print syst, syst_eff[0]
            maxbincontent = max(maxbincontent, syst_eff[0] * 100)
            maxsyst = max(maxsyst, syst_eff[0] * 100)
        #print maxsyst, i
        #start the canvas
        canv.cd()
        #convert it to a graph
        if maxsyst < 3: #don't draw everything
            print syst
            continue
        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[-1].SetLineColor(CONF.clr_lst[draw_counter])
        graph_lst[-1].SetMarkerStyle(20 + draw_counter)
        graph_lst[-1].SetMarkerColor(CONF.clr_lst[draw_counter])
        graph_lst[-1].SetMarkerSize(1)
        graph_lst[-1].SetMaximum(maxbincontent * 1.5)
        graph_lst[-1].SetMinimum(minbincontent)
        legend.AddEntry(graph_lst[-1], syst.replace("_", " "), "apl")
        if draw_counter==0: 
            graph_lst[-1].Draw("APC")
            draw_counter += 1
        else: 
            graph_lst[-1].Draw("PC")
            draw_counter += 1

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.04)
    legend.Draw()
    # draw reference lines
    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b  = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0")
    lumi  = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()
    # finish up
    helpers.checkpath(CONF.inputpath + ops.inputdir + "/" + "Plot/Syst/")
    canv.SaveAs(CONF.inputpath + ops.inputdir + "/" + "Plot/Syst/"  +  canv.GetName() + ".pdf")
    canv.Close()
Esempio n. 8
0
def plot_RSG_syst(masterdic, cut):
    ### the first argument is the input dictionary
    ### the second argument is the 2b/3b/4b regions
    canv = ROOT.TCanvas(cut  + "_" +  "RSG" + "_" + "syst", "Sytematics", 800, 800)
    xleg, yleg = 0.52, 0.7
    legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2)
    # setup basic plot parameters
    # load input MC file
    mass_lst = [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1800, 2000, 2250, 2500, 2750, 3000]
    systag_lst = ["JER", "JMR", "Rtrk", "EFF", "Stat"]
    systag_dic = {"JER":"JER", "JMR":"JMR", "Rtrk":"JES/JMS", "EFF":"b-tag SF", "Stat":"Stats"}
    eff_lst = []
    graph_lst = []
    maxbincontent = 40.0
    minbincontent = -0.001
    lowmass  = 950
    highmass = 3150

    for i, syst in enumerate(systag_lst):
        eff_lst.append( ROOT.TH1F(syst, "%s; Mass, GeV; Systematic Percentage Diff" %syst, int((highmass-lowmass)/100), lowmass, highmass) )
        for mass in mass_lst:
            if syst is "Stat":
                for key2 in masterdic[cut]:
                    if "RSG1_" + str(mass) in key2:
                        eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), masterdic[cut][key2]["int_err"]/masterdic[cut][key2]["int"] * 100)
                        eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), 0)
            else:
                temp_col_dic = find_syst(masterdic, cut, syst, "RSG1_" + str(mass))
                syst_eff = add_syst(temp_col_dic) #this is a tuple!
                eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), syst_eff[0] * 100)
                eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), 0)
            #print syst_eff[0]
            maxbincontent = max(maxbincontent, syst_eff[0])
        #start the canvas
        canv.cd()
        #convert it to a TGraph
        graph_lst.append(helpers.TH1toTAsym(eff_lst[i]))
        graph_lst[i].SetLineColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerStyle(20 + i)
        graph_lst[i].SetMarkerColor(CONF.clr_lst[i])
        graph_lst[i].SetMarkerSize(1)
        graph_lst[i].SetMaximum(maxbincontent * 1.5)
        graph_lst[i].SetMinimum(minbincontent)
        legend.AddEntry(graph_lst[i], systag_dic[syst].replace("_", " "), "apl")
        if syst==systag_lst[0]: 
            graph_lst[i].Draw("APC")
            #gr.Draw("same L hist")
        else: 
            graph_lst[i].Draw("PC")
            #gr.Draw("same L hist")

    legend.SetBorderSize(0)
    legend.SetMargin(0.3)
    legend.SetTextSize(0.04)
    legend.Draw()
    # draw reference lines
    # draw watermarks
    xatlas, yatlas = 0.35, 0.87
    atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal")
    hh4b  = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0")
    lumi  = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV")
    watermarks = [atlas, hh4b, lumi]
    for wm in watermarks:
        wm.SetTextAlign(22)
        wm.SetTextSize(0.04)
        wm.SetTextFont(42)
        wm.SetNDC()
        wm.Draw()
    # finish up
    helpers.checkpath(CONF.inputpath + ops.inputdir + "/" + "Plot/Syst/")
    canv.SaveAs(CONF.inputpath + ops.inputdir + "/" + "Plot/Syst/"  +  canv.GetName() + ".pdf")
    canv.Close()