Exemplo n.º 1
0
def compare_h1(h1, h2):
    h1.SetStats(False); h1.SetTitle("")
    h2.SetStats(False); h2.SetTitle("")
    
    h1 = fixup_hist_units(h1)
    h2 = fixup_hist_units(h2)
    
    h1.Scale(h2.Integral() / h1.Integral())
    
    h1.SetLineColor(R.kBlue)
    h2.SetLineColor(R.kRed)
    
    h2.Draw()
    h1.Draw("same")
    return h1, h2
Exemplo n.º 2
0
def plot(name, title, variable, *tree_parts, **kwargs):

    fallthrough = kwargs.pop("fallthrough", 0)
    def get_name(tree_part):
        for i in xrange(fallthrough):
            if not tree_part.parent:
                break
            tree_part = tree_part.parent
        return tree_part.name

    logy = kwargs.pop("logy", None)
    normalize = kwargs.pop("normalize", None)
    pos = kwargs.pop("pos", "RT")
    x_range = kwargs.pop("x_range", None)
    y_range = kwargs.pop("y_range", None)
    x_title = kwargs.pop("x_title", None)
    y_title = kwargs.pop("y_title", None)
    legend_header = kwargs.pop("legend_header", "")
    rebin = kwargs.pop("rebin", None)

    with canvas() as c:
        if logy: c.SetLogy()
        
        namehs = [("%s %s" % (tp.basename, get_name(tp)), fixup_hist_units(tp[variable])) for tp in tree_parts]
        if normalize is True:
            title += " (normalized)"
            for n, h in namehs:
                #h.GetYaxis().SetTitle("Arbitrary Units")
                y_title = "Arbitrary Units"
                h.Scale(1. / h.Integral())
        elif normalize:
            try:
                normalize_hists([h for n, h in namehs], normalize)
                title += " (normalized to %s above %i GeV)" % (namehs[0][0], normalize)
            except ZeroDivisionError:
                pass
            
        if rebin:        
            for n, h in namehs:
                h.Rebin(rebin)
                
        hs = [(h, None, hname) for hname, h in namehs]
        sl = C.StackLegend(name, pos, title, legend_header=legend_header, *hs)
        
        if x_range is not None:
            sl.set_x_range(x_range)
        if y_range is not None:
            # Doesn't seem to work
            sl.Y.SetRangeUser(*y_range)
        if x_title is not None:
            sl.X.SetTitle(x_title)
        if y_title is not None:
            sl.Y.SetTitle(y_title)
            
        sl.Draw()
        name = "_".join(expand_hname(name, variable))
        c.SaveAs("plots/purity/%s.eps" % name)