def makeDiscr(discr_dict,
              outfile,
              xtitle="discriminator",
              nbins=30,
              x_min=0,
              x_max=1):
    c = ROOT.TCanvas("c", "c", 800, 500)
    ROOT.gStyle.SetOptStat(0)
    ROOT.gPad.SetMargin(0.15, 0.1, 0.2, 0.1)
    #ROOT.gPad.SetLogy(1)
    #ROOT.gPad.SetGrid(1,1)
    ROOT.gStyle.SetGridColor(17)
    l = TLegend(0.17, 0.75, 0.88, 0.88)
    l.SetTextSize(0.055)
    l.SetBorderSize(0)
    l.SetFillStyle(0)
    l.SetNColumns(2)

    colors = [2, 4, 8, ROOT.kCyan + 2]
    counter = 0
    for leg, discr in discr_dict.iteritems():
        a = Hist(nbins, x_min, x_max)
        #fill_hist_with_ndarray(a, discr)
        a.fill_array(discr)
        a.SetLineColor(colors[counter])
        a.SetLineWidth(2)
        a.GetXaxis().SetTitle(xtitle)
        a.GetXaxis().SetLabelSize(0.05)
        a.GetXaxis().SetTitleSize(0.05)
        a.GetXaxis().SetTitleOffset(1.45)
        a.GetYaxis().SetTitle("a.u.")
        a.GetYaxis().SetTickSize(0)
        a.GetYaxis().SetLabelSize(0)
        a.GetYaxis().SetTitleSize(0.06)
        a.GetYaxis().SetTitleOffset(0.9)
        a.Scale(1. / a.Integral())
        #a.GetYaxis().SetRangeUser(0.00001,100)
        a.GetYaxis().SetRangeUser(0, 0.2)
        if counter == 0: a.draw("hist")
        else: a.draw("same hist")
        l.AddEntry(a, leg, "l")
        counter += 1

    l.Draw("same")
    c.SaveAs(outfile)
Example #2
0
def makeDiscr(train_discr_dict, discr_dict, outfile, xtitle="discriminator"):
    c = ROOT.TCanvas("c", "c", 800, 500)
    ROOT.gStyle.SetOptStat(0)
    ROOT.gPad.SetMargin(0.15, 0.1, 0.2, 0.1)
    #ROOT.gPad.SetLogy(1)
    #ROOT.gPad.SetGrid(1,1)
    ROOT.gStyle.SetGridColor(17)
    l = TLegend(0.17, 0.75, 0.88, 0.88)
    l.SetTextSize(0.055)
    l.SetBorderSize(0)
    l.SetFillStyle(0)
    l.SetNColumns(2)

    colors = [2, 1, 4, ROOT.kCyan + 2]
    counter = 0
    for leg, discr in train_discr_dict.iteritems():
        a = Hist(30, 0, 1)
        #fill_hist_with_ndarray(a, discr)
        a.fill_array(discr)
        a.SetLineColor(colors[counter])
        a.SetLineWidth(2)
        a.GetXaxis().SetTitle(xtitle)
        a.GetXaxis().SetLabelSize(0.05)
        a.GetXaxis().SetTitleSize(0.06)
        a.GetXaxis().SetTitleOffset(1.45)
        a.GetYaxis().SetTitle("a.u.")
        a.GetYaxis().SetTickSize(0)
        a.GetYaxis().SetLabelSize(0)
        a.GetYaxis().SetTitleSize(0.06)
        a.GetYaxis().SetTitleOffset(0.9)
        a.Scale(1. / a.Integral())
        #a.GetYaxis().SetRangeUser(0.00001,100)
        a.GetYaxis().SetRangeUser(0, 0.9)
        if counter == 0: a.draw("hist")
        else: a.draw("same hist")
        l.AddEntry(a, leg, "l")
        counter += 1

    counter = 0
    for leg, discr in discr_dict.iteritems():
        a = Hist(30, 0, 1)
        #fill_hist_with_ndarray(a, discr)
        a.fill_array(discr)
        a.SetLineColor(colors[counter])
        a.SetMarkerColor(colors[counter])
        a.SetMarkerStyle(34)
        a.SetMarkerSize(1.8)
        a.SetLineWidth(2)
        a.GetXaxis().SetTitle(xtitle)
        a.GetXaxis().SetLabelSize(0.05)
        a.GetXaxis().SetTitleSize(0.06)
        a.GetXaxis().SetTitleOffset(1.45)
        a.GetYaxis().SetTitle("a.u.")
        a.GetYaxis().SetTickSize(0)
        a.GetYaxis().SetLabelSize(0)
        a.GetYaxis().SetTitleSize(0.06)
        a.GetYaxis().SetTitleOffset(0.9)
        a.Scale(1. / a.Integral())
        #a.GetYaxis().SetRangeUser(0.00001,100)
        a.GetYaxis().SetRangeUser(0, 0.4)
        a.draw("same p X0")
        l.AddEntry(a, leg, "p")
        counter += 1

    # counter = 0


#     for leg,discr in train_discr_dict.iteritems():
#         d = Hist(30, 0, 1)
#         d.fill_array(discr)
#         d.SetLineColor(colors[counter])
#         d.SetLineWidth(2)
#         l.AddEntry(d,leg,"l")
#
#         b = Hist(30, 0, 1)
#         d.fill_array(discr_dict[leg.split(" ")[0] + " test"])
#         b.SetLineColor(colors[counter])
#         b.SetMarkerColor(colors[counter])
#         b.SetMarkerStyle(34)
#         b.SetMarkerSize(1.8)
#         b.SetLineWidth(2)
#         l.AddEntry(b,leg,"p")
#         counter += 1

    l.Draw("same")

    c.SaveAs(outfile)
Example #3
0
                            expr = expr.format(
                                var_info['name'] + '*' + str(var_info['scale']),
                                h.name,
                                (var_info['bins'], var_info['range'][0], var_info['range'][1]))
                        else:
                            expr = expr.format(
                                var_info['name'], h.name,
                                (var_info['bins'], var_info['range'][0], var_info['range'][1]))
                        print expr
                        tree.Draw(expr, cut, var_info['style'])
                        h = asrootpy(ROOT.gPad.GetPrimitive(h.name))
                        h.xaxis.title = get_label(var_info)
                        h.yaxis.title = 'Number of Events'
                        if h.integral() != 0:
                            h /= h.integral() 
                        h.SetLineWidth(2)
                        h.yaxis.SetRangeUser(0, 0.5)
                        if 'binlabels' in var_info.keys():
                            for ib, lab in enumerate(var_info['binlabels']):
                                h.xaxis.SetBinLabel(ib + 1, lab)

                        c = Canvas()
                        # c.SetLogy()
                        c.SetTopMargin(0.08)
                        h.Draw('HIST')
                        label = ROOT.TLatex(
                            c.GetLeftMargin() + 0.05, 1 - c.GetTopMargin() + 0.02,
                            '{0}H #rightarrow #tau#tau (m_{{H}} = {1} GeV) - Hist Integral = {2}'.format(
                                get_dir_mode(d), get_dir_mass(d), h.Integral()))
                        label.SetNDC()
                        label.SetTextSize(20)