Esempio n. 1
0
def make_lumi_plot(samples, region):
    print "make_lumi_plot()    Making lumi plot for %s" % region.name

    lumican = lumiCanvas("lumican_%s" % region.name)
    lumican.canvas.cd()

    # only plot those runs with >= 10/pb of data
    new_samples = []
    for s in samples:
        if s.lumi >= 10:
            new_samples.append(s)
    samples = new_samples

    # only 2015
    # new_samples = []
    # for s in samples :
    #    if int(s.run_number) < 297730 : new_samples.append(s)
    # samples = new_samples

    lumican.pad.cd()
    h = pu.th1f("h_lumi_" + region.name, "", int(len(samples)), 0, int(len(samples)), "Run Number", "Events/pb^{-1}")

    # h.SetBinErrorOption(r.TH1.kPoisson)
    # h.Sumw2()

    samples = sorted(samples, key=lambda x: x.run_number, reverse=False)

    maxy = -1

    sum_ev = 0.0

    lumi_list = []

    for ibin, s_ in enumerate(samples):
        yld = s_.yields[region.name]
        lumi = s_.lumi
        lumi_list.append(lumi)
        norm = float(yld) / float(lumi)
        sum_ev += norm
        if norm > maxy:
            maxy = norm
        h.SetBinContent(ibin + 1, norm)
        h.SetBinError(ibin + 1, sqrt(yld) / float(lumi))
        h.GetXaxis().SetBinLabel(ibin + 1, "%s" % str(s_.run_number))

    avg_norm = float(sum_ev) / len(samples)

    maxima = {}
    maxima["srwPreselEE"] = 10.0
    maxima["srwPreselMM"] = 10.0
    maxima["srwPreselDF"] = 1.8
    maxima["srtPreselEE"] = 5.0
    maxima["srtPreselMM"] = 5.0
    maxima["srtPreselDF"] = 8.0

    # h.SetMaximum(maxima[region.name])
    h.SetMaximum(2.15 * avg_norm)
    h.SetMarkerColor(r.TColor.GetColor("#386672"))
    h.SetMarkerSize(1.5 * h.GetMarkerSize())

    h.SetMinimum(0)

    h.SetFillColor(0)
    h.SetLineColor(r.kBlack)

    ## labels
    h.GetXaxis().LabelsOption("v")
    h.GetXaxis().SetLabelFont(42)
    h.GetXaxis().SetLabelOffset(3.2 * h.GetXaxis().GetLabelOffset())
    h.GetXaxis().SetLabelSize(1.2 * h.GetXaxis().GetLabelSize())

    ## title
    # x
    h.GetXaxis().SetTitleSize(1.75 * h.GetXaxis().GetTitleSize())
    h.GetXaxis().SetTitleOffset(1.5 * h.GetXaxis().GetTitleOffset())

    # y
    h.GetYaxis().SetTitleOffset(0.5 * h.GetYaxis().GetTitleOffset())
    h.GetYaxis().SetTitleSize(1.25 * h.GetYaxis().GetTitleSize())

    # draw average norm lumi line
    pu.draw_line(0, avg_norm, len(samples), avg_norm, color=r.kRed, style=2, width=1)

    h.Draw("hist e")

    h.Fit("pol1")
    lumican.canvas.Update()

    h.Draw()
    pu.draw_line(0, avg_norm, len(samples), avg_norm, color=r.kRed, style=2, width=1)

    ## get periods and lines
    #  period_lines = get_periodlines(samples, h.GetMaximum(), region.name)
    #  for line in period_lines :
    #      line.Draw()

    pu.draw_text_on_top(region.displayname + "  2015 + 2016 (DS1)")

    lumican.canvas.Update()
    lumican.canvas.SaveAs("normlumi_%s.eps" % region.name)
Esempio n. 2
0
    c = pu.basic_canvas()
    c.cd()

    h1 = pu.th1f("test", "", 25, 0, 200, "p_{T} [GeV]", "Entries")
    h1.SetLineColor(b.color)
    h2 = pu.th1f("test2", "", 25, 0, 200, "p_{T} [GeV]", "Entries")
    h2.SetLineColor(s.color)
    cmd1 = "l_pt[0]>>%s"%h1.GetName()
    cmd2 = "l_pt[0]>>%s"%h2.GetName()
    print "background : %s"%str(b.tree.GetEntries())
    print "signal     : %s"%str(s.tree.GetEntries())
    b.tree.Draw(cmd1, testregion.tcut)
    s.tree.Draw(cmd2, testregion.tcut)
    h1.Draw("hist")
    h2.Draw("hist same")

    leg = pu.default_legend()
    leg.AddEntry(h1, b.displayname, "l")
    leg.AddEntry(h2, s.displayname, "l")
    leg.Draw("same")
    c.Update()

    pu.draw_text_on_top(text="%s: %s"%(testregion.displayname, testregion.tcut), size=0.03)
    c.Update()

    c.Print("test.eps")
    


Esempio n. 3
0
        x_map[float(init)] = ii
    for yy, fin in enumerate(finals):
        y_map[float(fin)] = yy
    for reg in reg_yields:
        hbin_x = h_stat.GetXaxis().FindBin(x_map[float(reg.init)])
        h_stat.GetXaxis().SetBinLabel(x_map[float(reg.init)] + 1, reg.init)
        h_stat.GetXaxis().CenterLabels(True)

        hbin_y = h_stat.GetYaxis().FindBin(y_map[float(reg.fin)])
        h_stat.GetYaxis().SetBinLabel(y_map[float(reg.fin)] + 1, reg.fin)
        h_stat.GetYaxis().CenterLabels()

        h_stat.SetBinContent(hbin_x, hbin_y, float(reg.significance))

    h_stat.Draw("colz")

    tex = r.TLatex(0.0, 0.0, "")
    tex.SetTextFont(42)
    tex.SetTextSize(0.3 * tex.GetTextSize())
    for reg in reg_yields:
        # write s/b and deltaB/b
        info_1 = "s/b: %.2f" % float(reg.s_over_b)
        info_2 = "#deltaB: %.2f" % (float(reg.tot_error) / float(reg.tot_yield) * 100.0)
        info_3 = "bkg: %.2f" % float(reg.tot_yield)
        tex.DrawLatex(x_map[float(reg.init)] + 0.1, y_map[float(reg.fin)] + 0.70, info_1)
        tex.DrawLatex(x_map[float(reg.init)] + 0.1, y_map[float(reg.fin)] + 0.50, info_2)
        tex.DrawLatex(x_map[float(reg.init)] + 0.1, y_map[float(reg.fin)] + 0.30, info_3)

    pu.draw_text_on_top("#Delta#phi_{#beta}^{R} > ( X * |cos#theta_{B}| + Y ) \t\t\tZ = Significance", pushup=1.02)
    can.SaveAs("test.eps")