Exemple #1
0
def main(args):
    base_histos = [util.get_tobject(args, r) for r in args.base_histos]
    util.validate_hists(args.base_histos, base_histos)
    base_histos = [util.resize_histo(args, util.get_tobject(args, r)) for r in args.base_histos]

    cut_histos = [util.get_tobject(args, r) for r in args.cut_histos]
    util.validate_hists(args.cut_histos, cut_histos)
    cut_histos = [util.resize_histo(args, util.get_tobject(args, r)) for r in args.cut_histos]

    canvas = ROOT.TCanvas("canvas", "Canvas", 250,100,700,500)

    all_histos = []
    for i, (base_histo,cut_histo) in enumerate(zip(base_histos,cut_histos)):
        ratio = cut_histo.Clone()
        ratio.Divide(base_histo)
        ratio.SetLineColor(util.fillcolors(i))
        ratio.SetLineWidth(2)
        if i == 0:
            util.style(args, canvas, ratio)
            ratio.Draw("PE")
        else:
            ratio.Draw("PE SAME")
        all_histos.append(ratio)

        if args.names: 
            name = args.names[i]
            ratio.SetTitle(name)

    legend = ROOT.gPad.BuildLegend(*(args.legend_position + [""]))
    if args.title is not None:
        all_histos[0].SetTitle(args.title)
    canvas.Update()

    util.wait(args)
    util.write(args, canvas)
Exemple #2
0
def main(args):
    f = ROOT.TFile(args.input)
    effs = []
    puritys = []

    signal_base = get_integral(f, args.variable, args.base_cut,
                               args.signal_names)
    background_base = get_integral(f, args.variable, args.base_cut,
                                   args.background_names)

    effs.append(1.)
    puritys.append(signal_base / (signal_base + background_base))

    for cut in args.cuts:
        this_signal = get_integral(f, args.variable, cut, args.signal_names)
        this_background = get_integral(f, args.variable, cut,
                                       args.background_names)
        this_eff = this_signal / signal_base
        this_purity = this_signal / (this_signal + this_background)
        effs.append(this_eff)
        puritys.append(this_purity)

    effs = array('d', effs)
    puritys = array('d', puritys)
    xvals = array('d', range(len(effs)))

    g_eff = ROOT.TGraph(len(effs), xvals, effs)
    g_eff.SetName("Efficiency")
    g_eff.SetTitle("Efficiency")

    g_purity = ROOT.TGraph(len(puritys), xvals, puritys)
    g_purity.SetName("Purity")
    g_purity.SetTitle("Purity")

    canvas = ROOT.TCanvas("canvas", "Canvas", 250, 100, 700, 500)

    g_eff.Draw("AL")
    g_eff.SetLineColor(ROOT.kGreen)
    util.style(args, g_eff)
    for i in range(len(effs)):
        g_eff.GetXaxis().SetBinLabel(g_eff.GetXaxis().FindBin(i),
                                     args.names[i])
    g_purity.Draw("SAME")
    g_purity.SetLineColor(ROOT.kRed)

    legend = ROOT.gPad.BuildLegend(0.75, 0.75, 0.95, 0.95, "")
    canvas.Update()

    util.wait(args)
    util.write(args, canvas)
Exemple #3
0
def main(args):
    hists = [[util.get_tobject(args, h.lstrip("-")) for h in hlist]
             for hlist in args.hstack]
    util.validate_hists(args.hstack, hists)
    hists = [[util.resize_histo(args, h) for h in hlist] for hlist in hists]

    canvas = ROOT.TCanvas("canvas", "Canvas", 250, 100, 700, 500)
    hstack = ROOT.THStack()

    for i, (hlist, hnames) in enumerate(zip(hists, args.hstack)):
        h = hlist[0]
        if len(hlist) > 1:
            for hadd, hname in zip(hlist[1:], hnames[1:]):
                #if "InTime-" in hname:
                #   h.Add(hadd, 10. / 1837.)
                if hname.startswith("-"):
                    h.Add(hadd, -1)
                else:
                    h.Add(hadd)

        if args.area_normalize and h.Integral() > 1e-4:
            h.Scale(1. / h.Integral())
        color = util.namecolors(args.names[i] if args.names else hnames[0])
        if args.stack:
            h.SetFillColor(color)
        else:
            h.SetLineColor(color)
            h.SetLineWidth(3)
        if args.names:
            name = args.names[i]
            if args.nevent_in_legend:
                name += " (%i)" % int(h.Integral())
            h.SetTitle(name)
        hstack.Add(h)

    drawstr = "HIST" if args.stack else "NOSTACK HIST"
    hstack.Draw(drawstr)
    util.style(args, canvas, hstack)
    if args.legend_position:
        legend = ROOT.gPad.BuildLegend(*(args.legend_position + [""]))
    if args.logy:
        canvas.SetLogy()

    box = util.draw_text(args)
    canvas.Update()

    util.wait(args)
    util.write(args, canvas)
Exemple #4
0
def main(args):
    f = ROOT.TFile(args.input)
    graph = f.Get(args.graph)
    canvas = ROOT.TCanvas("canvas", "Canvas", 250, 100, 700, 500)
    util.style(args, graph)
    graph.Draw("AC")
    util.resize_graph(args, graph)
    graph.Draw("AC")

    line = ROOT.TGraph(2, array('d', [0., 1.]), array('d', [1., 0.]))
    line.SetLineColor(ROOT.kRed)
    line.Draw("SAME")

    canvas.Update()

    util.wait(args)
    util.write(args, canvas)
Exemple #5
0
def main(args):
    util.optstat(args)
    f = ROOT.TFile(args.input)
    hist = f.Get(args.hist)
    util.validate_hists([args.hist], [hist])
    hist = util.resize_histo(args, hist, "")
    hstack = ROOT.THStack()
    canvas = ROOT.TCanvas("canvas", "Canvas", 250, 100, 700, 500)

    class ArgDict(dict):
        __getattr__ = dict.get

    hists = []
    for i, (low, high) in enumerate(zip(args.lows, args.highs)):
        this_args = ArgDict({"y_min": low, "y_max": high, "projectionX": True})
        h = util.resize_histo(this_args, hist.Clone(), str(i))
        h.SetLineColor(util.fillcolors(i))
        h.SetLineWidth(3)
        if args.names:
            name = args.names[i]
            h.SetTitle(name)
        hists.append(h)
        hstack.Add(h)

    hstack.Draw("NOSTACK HIST")
    legend = ROOT.gPad.BuildLegend(*(args.legend_position + [""]))
    if args.title is not None:
        hstack.SetTitle(args.title)
    util.style(args, canvas, hstack)

    box = util.draw_text(args)

    canvas.Update()

    util.wait(args)
    util.write(args, canvas)
Exemple #6
0
def main(args):
    util.optstat(args)
    hist = util.get_tobject(args, args.hist)
    util.validate_hists([args.hist], [hist])
    hist = util.resize_histo(args, hist)

    if args.make_percentages:
        if isinstance(hist, ROOT.TH2D):
            for i in range(1, hist.GetNbinsX() + 1):
                this_norm = hist.Integral(i, i, 1, hist.GetNbinsY())
                for j in range(1, hist.GetNbinsY() + 1):
                    if this_norm < 1e-3:
                        hist.SetBinContent(i, j, 0)
                    else:
                        hist.SetBinContent(
                            i, j,
                            hist.GetBinContent(i, j) / this_norm)
        else:
            for k in range(1, hist.GetNbinsZ() + 1):
                for i in range(1, hist.GetNbinsX() + 1):
                    this_norm = hist.Integral(i, i, 1, hist.GetNbinsY(), k, k)
                    for j in range(1, hist.GetNbinsY() + 1):
                        if this_norm < 1e-3:
                            hist.SetBinContent(i, j, k, 0)
                        else:
                            hist.SetBinContent(
                                i, j, k,
                                hist.GetBinContent(i, j, k) / this_norm)

    hist2 = None
    if args.meanY:
        hist2 = mean_and_err(hist)

    canvas = ROOT.TCanvas("canvas", "Canvas", 250, 100, 700, 500)
    drawstr = ""
    if args.drawstr is not None:
        drawstr = args.drawstr
    elif isinstance(hist, ROOT.TH2D):
        drawstr = "COLZ"
        if args.draw_text:
            drawstr += " TEXT"
            hist.SetMarkerSize(3)
            ROOT.gStyle.SetPaintTextFormat("1.3f")
    elif isinstance(hist, ROOT.TH1D):
        drawstr = "HIST"
    elif isinstance(hist, ROOT.TGraph):
        drawstr = "AL"
    hist.Draw(drawstr)
    if hist2:
        hist2.SetLineColor(ROOT.kRed)
        hist2.SetLineWidth(3)
        hist2.SetMarkerSize(1)
        hist2.SetMarkerStyle(21)
        hist2.SetMarkerColor(ROOT.kRed)
        hist2.Draw("P")
    if args.title is not None:
        hist.SetTitle(args.title)
    util.style(args, canvas, hist)

    if args.logy:
        canvas.SetLogy()
    if args.logz:
        canvas.SetLogz()
    box = util.draw_text(args)

    canvas.Update()

    util.wait(args)
    util.write(args, canvas)