Esempio n. 1
0
def main(infile, outdir, mvas=""):

    ## initialize ROOT style and set-up the html helper
    setStyle()
    hth = HtmlHelper(outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("kinematics").set(
        "href", "./")

    kh = plot_kin(infile, hth)

    ih, rh = plot_jet_id(
        infile,
        hth,
        variables_to_plot=[
            ("jetPt", "jetEta", "nvtx"),
            ("dR2Mean", "dRMean", "beta", "betaStar", "dZ"),  ## "dR2Mean",
            tuple(v for v in mvas.split(',') if v != ""),
        ])
    ## done: create images and html
    hth.dump()
    save_rocs(rh, outdir)

    ###  reweightX = [ kh.reweight.GetBinLowEdge(i) for  i in range(1,kh.reweight.GetNbinsX())]
    ###  reweightY = [ kh.reweight.GetBinContent(i) for  i in range(1,kh.reweight.GetNbinsX())]
    ###  print reweightX
    ###  print reweightY

    print kh.reweight_f.GetExpFormula("p")
Esempio n. 2
0
def main(options, args):
    from ROOT import gROOT
    gROOT.SetBatch(options.batch)

    from lip.Tools.rootutils import loadToolsLib, getQuantilesGraphs, apply_modifs, xtitle, ytitle
    loadToolsLib()

    from ROOT import TCut, TCanvas, gDirectory, gPad, kRed, kBlue, kWhite, setStyle, gStyle, TLegend, HtmlHelper, HtmlTag, HtmlTable, HtmlPlot, TPaveText, kOpenCircle, TF1, TLine
    setStyle()
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)

    print "Getting list of files"
    files = getListOfFiles(options.indir, options.filePattern)

    chain = mkChain(files, options.treename)
    ## chain = mkChain(files[0:100],options.treename)
    ## chain = mkChain(files[0:1],options.treename)

    hth = HtmlHelper(options.outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    wptag = hth.body().addobj(HtmlTag("pre"))
    tab = hth.body().add(HtmlTable())

    quants = {}
    objs = []

    var, binning = options.variable.split(":")
    limits = [float(i) for i in binning.split(",")[1:]]
    delta = 0.1 * max(abs(limits[0]), abs(limits[1]))
    limits[0] -= delta
    limits[1] += delta

    xlab = "p_{T} (GeV)"
    if options.vsnvtx:
        xlab = "N_{PV}"
    sig_style = [("SetLineColor", kBlue), ("SetMarkerColor", kBlue),
                 (xtitle, xlab), (ytitle, "%s cut" % var), ("SetFillStyle", 0),
                 ("SetMarkerColor", kOpenCircle)]
    bkg_style = [("SetLineColor", kRed), ("SetMarkerColor", kRed),
                 (xtitle, xlab), (ytitle, "%s cut" % var), ("SetFillStyle", 0)]
    lab_style = [("SetFillColor", kWhite), ("SetShadowColor", kWhite),
                 ("SetLineColor", kWhite), ("SetFillStyle", 0)]

    fitl = TF1("fitl", "pol1", 12, 19)
    fitr = TF1("fitl", "pol1", 20, 35)
    fita = TF1("fita", "pol1", 15, 25)

    ## wps = { "loose":[0,0.05,0.1,0.1,0.1], "medium":[0,0.10,0.2,0.2,0.2], "tight":[1,0.95,0.9,0.9,0.9] }
    wps = {
        "loose": [0, 0.05, 0.05, 0.05, 0.05],
        "medium": [0, 0.1, 0.1, 0.1, 0.1],
        "tight": [0, 0.2, 0.2, 0.2, 0.2]
    }
    if options.chs:
        wps = {
            "loose": [0, 0.02, 0.1, 0.1, 0.1],
            "medium": [0, 0.05, 0.2, 0.2, 0.2],
            "tight": [1, 0.95, 0.9, 0.9, 0.9]
        }
    wpf = {}
    for a in wps.keys():
        wpf[a] = {}
    wpref = 20.

    icat = 0
    for cut, name, vars in options.categories:
        print "Making TH2 ", name

        icat += 1
        vtxbins = [(10, 20), (20, 999), (1, 999)]
        if options.integrateall:
            vtxbins = [(1, 999)]
        ivtx = 0
        for vtx in vtxbins:
            print(name, ) + vtx
            hname = "%s_%d_%d" % ((name, ) + vtx)

            vtxcut = TCut("nvtx > %d && nvtx < %d" % vtx)

            if options.vsnvtx:
                chain.Draw(
                    "%s:nvtx>>h_sig_%s(50,0.5,50.5,%s)" %
                    (var, hname, binning),
                    TCut("jetPt>20") * vtxcut * TCut(cut) *
                    TCut(options.sigcut), "colz goff")
                chain.Draw(
                    "%s:nvtx>>h_bkg_%s(50,0.5,50.5,%s)" %
                    (var, hname, binning),
                    TCut("jetPt>20") * vtxcut * TCut(cut) *
                    TCut(options.bkgcut), "colz goff")
            else:
                chain.Draw(
                    "%s:jetPt>>h_sig_%s(25,10,60,%s)" % (var, hname, binning),
                    vtxcut * TCut(cut) * TCut(options.sigcut), "colz goff")
                chain.Draw(
                    "%s:jetPt>>h_bkg_%s(25,10,60,%s)" % (var, hname, binning),
                    vtxcut * TCut(cut) * TCut(options.bkgcut), "colz goff")

            gDirectory.ls()
            h_sig = gDirectory.Get("h_sig_%s" % hname)
            h_bkg = gDirectory.Get("h_bkg_%s" % hname)

            print "Getting quantiles ", hname
            sig_qvals = [0.1, 0.2, 0.3, 0.5, 0.02, 0.05, 0.15]
            bkg_qvals = [0.4, 0.7, 0.6, 0.8, 0.9, 0.95, 0.9]
            quants[hname] = getQuantilesGraphs(h_sig,
                                               sig_qvals), getQuantilesGraphs(
                                                   h_bkg, bkg_qvals)

            for i in range(len(sig_qvals)):
                if options.integrateall:
                    quants[hname][0][i].SetTitle(
                        "%1.0f%% efficiency" % (((1. - sig_qvals[i]) * 100.)))
                    if options.vsnvtx:
                        quants[hname][0][i].Fit(fita.Clone(), "R+")
                    else:
                        quants[hname][0][i].Fit(fitl.Clone(), "R+")
                        quants[hname][0][i].Fit(fitr.Clone(), "R+")
                    for wpn, wp in wps.iteritems():
                        if wp[0] == 0 and wp[icat] == sig_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat, name)] = quants[hname][
                                0][i].GetListOfFunctions(
                                ), quants[hname][0][i].GetTitle()
                else:
                    quants[hname][0][i].SetTitle(
                        "%1.0f%% efficiency %d<N_{PV}<%d" %
                        (((1. - sig_qvals[i]) * 100., ) + vtx))
                style = sig_style + [("SetLineColor", kBlue - 2 * ivtx),
                                     ("SetMarkerColor", kBlue - 2 * ivtx)]
                apply_modifs(quants[hname][0][i], style)
                for f in quants[hname][0][i].GetListOfFunctions():
                    apply_modifs(f, style)

            for i in range(len(bkg_qvals)):
                if options.integrateall:
                    quants[hname][1][i].SetTitle("%1.0f%% rejection" %
                                                 ((bkg_qvals[i] * 100.)))
                    if options.vsnvtx:
                        quants[hname][1][i].Fit(fita.Clone(), "R+")
                    else:
                        quants[hname][1][i].Fit(fitl.Clone(), "R+")
                        quants[hname][1][i].Fit(fitr.Clone(), "R+")
                    for wpn, wp in wps.iteritems():
                        if wp[0] == 1 and wp[icat] == bkg_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat, name)] = quants[hname][
                                1][i].GetListOfFunctions(
                                ), quants[hname][1][i].GetTitle()
                else:
                    quants[hname][1][i].SetTitle(
                        "%1.0f%% rejection  %d<N_{PV}<%d" %
                        ((bkg_qvals[i] * 100., ) + vtx))
                style = bkg_style + [("SetLineColor", kRed - 2 * ivtx),
                                     ("SetMarkerColor", kRed - 2 * ivtx)]
                apply_modifs(quants[hname][1][i], style)
                for f in quants[hname][1][i].GetListOfFunctions():
                    apply_modifs(f, style)
            ivtx += 1

        chain.Draw("nvtx>>h_nvtx_%s(50,0.5,50.5)" % (hname),
                   TCut(cut) * TCut(options.sigcut), "goff")
        canv = TCanvas("%s_nvtx" % (name), ("%s" % (name)), 800, 1000)
        canv.cd()
        h_nvtx = gDirectory.Get("h_nvtx_%s" % hname)
        line = TLine(h_nvtx.GetMean(), 0., h_nvtx.GetMean(),
                     h_nvtx.GetMaximum())
        h_nvtx.Draw("hist")
        line.Draw("same")
        objs.append(line)
        objs.append(canv)
        tab.row().cell(HtmlPlot(canv, False, "", True, True, True))

        nvals = len(sig_qvals)
        plotsperline = 4
        for i in range(nvals):
            if i % plotsperline == 0:
                row = tab.row()
            canv = TCanvas("%s_%d" % (name, i), ("%s_%d" % (name, i)), 800,
                           1000)
            canv.SetGridx(), canv.SetGridy()

            first = True
            for vtx in vtxbins:
                kname = "%s_%d_%d" % ((name, ) + vtx)
                if first:
                    quants[kname][0][i].Draw("ap")
                else:
                    quants[kname][0][i].Draw("p")
                quants[kname][1][i].Draw("p")
                quants[kname][0][i].GetYaxis().SetLimits(limits[0], limits[1])
                quants[kname][0][i].GetYaxis().SetRangeUser(
                    limits[0], limits[1])

                if first:
                    leg1 = TLegend(0.2, 0.95, 0.5, 1.0)
                    apply_modifs(leg1, lab_style)
                    leg2 = TLegend(0.5, 0.95, 0.8, 1.0)
                    apply_modifs(leg2, lab_style)
                    first = False

                leg1.AddEntry(quants[kname][0][i], "", "lp")
                leg2.AddEntry(quants[kname][1][i], "", "lp")

            leg1.Draw("SAME")
            leg2.Draw("SAME")

            lab = TPaveText(0.1, 0.95, 0.2, 1.0, "brNDC")
            apply_modifs(lab, lab_style)
            lab.AddText(name)
            lab.Draw("SAME")

            row.cell(HtmlPlot(canv, False, "", True, True, True))
            objs.append(lab)
            objs.append(leg1)
            objs.append(leg2)
            objs.append(canv)

    wpstr = "Working points\n"
    wpstr += "--------------\n"
    for wpn, wpfs in wpf.iteritems():
        wpstr += "\n%s\n" % wpn
        wpstr += "-------\n"
        keys = wpfs.keys()
        keys.sort()
        ## for cat,val in wpfs.iteritems():
        ##    funcs,tit = val
        for cat in keys:
            funcs, tit = wpfs[cat]
            wpstr += ("%s (%s) " % (cat.ljust(8), tit.ljust(14)))
            for f in funcs:
                if options.vsnvtx:
                    wpstr += "%1.0f-%1.0f: %1.3f " % (f.GetXmin(), f.GetXmax(),
                                                      f.GetParameter(1))
                else:
                    wpstr += "%1.0f-%1.0f: %1.2f " % (f.GetXmin(), f.GetXmax(),
                                                      f.Eval(wpref))
            wpstr += "\n"
    wptag.txt(str(wpstr))

    if not os.path.isdir(options.outdir):
        os.mkdir(options.outdir)
    hth.dump()

    return quants, objs
Esempio n. 3
0
def main(options, args):

    from ROOT import gSystem, gROOT, gStyle
    gROOT.SetBatch()
    gSystem.Load("libRooFitCore")

    if options.doWebPage:
        from lip.Tools.rootutils import loadToolsLib, apply_modifs
        loadToolsLib()

    from ROOT import TFile, RooFit, RooArgSet, RooDataHist, RooKeysPdf, RooHistPdf, TCanvas, TLegend, TLatex, TArrow, TPaveText, RooAddPdf, RooArgList
    from ROOT import kWhite, kBlue, kOpenSquare
    if options.doWebPage:
        from ROOT import HtmlHelper, HtmlTag, HtmlTable, HtmlPlot

    rootglobestyle.setTDRStyle()
    gStyle.SetMarkerSize(1.5)
    gStyle.SetTitleYOffset(1.5)

    gStyle.SetPadLeftMargin(0.16)
    gStyle.SetPadRightMargin(0.05)
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadBottomMargin(0.13)

    gStyle.SetLabelFont(42, "XYZ")
    gStyle.SetLabelOffset(0.007, "XYZ")
    gStyle.SetLabelSize(0.05, "XYZ")

    gStyle.SetTitleSize(0.06, "XYZ")
    gStyle.SetTitleXOffset(0.9)
    gStyle.SetTitleYOffset(1.24)
    gStyle.SetTitleFont(42, "XYZ")

    ##
    ## Read files
    ##
    options.outdir = "%s_m%1.0f" % (options.outdir, options.mH)
    if options.fp:
        options.outdir += "_fp"

    ncat = options.ncat
    cats = options.cats
    if cats is "":
        categories = ["_cat%d" % i for i in range(0, ncat)]
    else:
        categories = ["_cat%s" % i for i in cats.split(",")]

    if options.mva:
        clables = {
            "_cat0": ("MVA > 0.89", ""),
            "_cat1": ("0.74 #leq MVA", "MVA < 0.89"),
            "_cat2": ("0.545 #leq MVA", "MVA < 0.74"),
            "_cat3": ("0.05 #leq MVA", "MVA < 0.545"),
            "_cat4": ("Di-jet", "Tagged"),
            "_cat5": ("Di-jet", "Tagged"),
            "_combcat": ("All Classes", "Combined")
        }
    else:
        clables = {
            "_cat0": ("max(|#eta|<1.5", "min(R_{9})>0.94"),
            "_cat1": ("max(|#eta|<1.5", "min(R_{9})<0.94"),
            "_cat2": ("max(|#eta|>1.5", "min(R_{9})>0.94"),
            "_cat3": ("max(|#eta|>1.5", "min(R_{9})<0.94"),
            "_cat4": ("Di-jet", "Tagged"),
            "_cat5": ("Di-jet", "Tagged"),
            "_combcat": ("All Classes", "Combined")
        }
    helper = Helper()

    fin = TFile.Open(options.infile)
    helper.files.append(fin)
    ws = fin.Get("cms_hgg_workspace")
    mass = ws.var("CMS_hgg_mass")
    mass.SetTitle("m_{#gamma#gamma}")
    mass.setUnit("GeV")
    mass.setRange(100., 150.)
    mass.setBins(100, "plot")
    mass.setBins(5000)

    print ws

    aset = RooArgSet(mass)

    helper.objs.append(mass)
    helper.objs.append(aset)

    fitopt = (RooFit.Minimizer("Minuit2", ""), RooFit.Minos(False),
              RooFit.SumW2Error(False), RooFit.NumCPU(8))

    if not options.binned and not options.refit:
        finpdf = TFile.Open(options.infilepdf)
        helper.files.append(finpdf)
        wspdf = finpdf.Get("wsig")
    else:
        wspdf = ws

    for c in categories:
        processes = ["ggh", "vbf", "wzh"]
        if options.fp:
            processes = ["vbf", "wzh"]
        ### elif clables[c][0] == "Di-jet":
        ###     processes = [ "vbf", "ggh" ]

        dsname = "sig_mass_m%1.0f%s" % (options.mH, c)
        print dsname
        print ws
        ds = ws.data("sig_%s_mass_m%1.0f%s" %
                     (processes[0], options.mH, c)).Clone(dsname)
        for proc in processes[1:]:
            ds.append(ws.data("sig_%s_mass_m%1.0f%s" % (proc, options.mH, c)))
        helper.dsets.append(ds)

        if options.binned:
            binned_ds = RooDataHist("binned_%s" % dsname, "binned_%s" % dsname,
                                    aset, ds)
            pdf = RooKeysPdf("pdf_%s_%s" % (dsname, f), "pdf_%s" % dsname,
                             mass, ds)
            plot_pdf = RooHistPdf("pdf_%s" % dsname, "pdf_%s" % dsname, aset,
                                  plot_ds)
            helper.add(binned_ds, binned_ds.GetName())
        else:
            if options.refit:
                if options.refitall and clables[c][0] != "Di-jet":
                    rpdfs = []
                    for proc in processes:
                        for ngaus in range(1, 4):
                            pp = build_pdf(ws, "%s_%s" % (c, proc), ngaus,
                                           ngaus == 3)
                            pp.fitTo(
                                ws.data("sig_%s_mass_m%1.0f%s" %
                                        (proc, options.mH, c)),
                                RooFit.Strategy(0), *fitopt)
                        rpdfs.append(pp)
                    pdf = RooAddPdf("hggpdfrel%s" % c, "hggpdfrel%s" % c,
                                    RooArgList(*tuple(rpdfs)))
                else:
                    if options.refitall and clables[c][0] == "Di-jet":
                        for ngaus in range(1, 5):
                            pdf = build_pdf(ws, c, ngaus, ngaus == 5)
                            pdf.fitTo(ds, RooFit.Strategy(0), *fitopt)
                    else:
                        for ngaus in range(1, 4):
                            pdf = build_pdf(ws, c, ngaus, ngaus == 3)
                            pdf.fitTo(ds, RooFit.Strategy(0), *fitopt)
            else:
                pdfs = (wspdf.pdf("hggpdfrel%s_%s" % (c, p))
                        for p in processes)
                pdf = RooAddPdf("hggpdfrel%s" % c, "hggpdfrel%s" % c,
                                RooArgList(*pdfs))
            helper.add(pdf, pdf.GetName())
            plot_pdf = pdf.Clone("pdf_%s" % dsname)

        plot_ds = RooDataHist("plot_%s" % dsname, "plot_%s" % dsname, aset,
                              "plot")
        plot_ds.add(ds)

        cdf = pdf.createCdf(aset)
        hmin, hmax, hm = get_FWHM(mass, pdf, cdf, options.mH - 10.,
                                  options.mH + 10.)
        wmin, wmax = get_eff_sigma(mass, pdf, cdf, options.mH - 10.,
                                   options.mH + 10.)
        ### hmin, hmax, hm = get_FWHM( points )

        helper.add(plot_ds, plot_ds.GetName())
        helper.add(plot_pdf, plot_pdf.GetName())
        helper.add((wmin, wmax), "eff_sigma%s" % c)
        helper.add((hmin, hmax, hm), "FWHM%s" % c)
        helper.add(ds.sumEntries(),
                   "sumEntries%s" % c)  # signal model integral

        # data integral for PAS tables
        data = ws.data("data_mass%s" % c)
        helper.add(
            data.sumEntries("CMS_hgg_mass>=%1.4f && CMS_hgg_mass<=%1.4f" %
                            (options.mH - 10., options.mH + 10.)),
            "data_sumEntries%s" % c)

        del cdf
        del pdf

    dsname = "sig_mass_m%1.0f_combcat" % options.mH
    print dsname
    combined_ds = helper.dsets[0].Clone(dsname)
    for d in helper.dsets[1:]:
        combined_ds.append(d)

    if options.binned:
        binned_ds = RooDataHist("binned_%s" % dsname, "binned_%s" % dsname,
                                aset, combined_ds)
        pdf = RooKeysPdf("pdf_%s" % (dsname), "pdf_%s" % dsname, mass,
                         combined_ds)
        plot_pdf = RooHistPdf("pdf_%s" % dsname, "pdf_%s" % dsname, aset,
                              plot_ds)
        helper.add(binned_ds, binned_ds.GetName())
    else:
        #### pdf = build_pdf(ws,"_combcat")
        #### pdf.fitTo(combined_ds, RooFit.Strategy(0), *fitopt )
        #### plot_pdf = pdf.Clone( "pdf_%s" % dsname )
        pdf = RooAddPdf(
            "pdf_%s" % dsname, "pdf_%s" % dsname,
            RooArgList(*(helper.histos["hggpdfrel%s" % c]
                         for c in categories)))
        plot_pdf = pdf

    cdf = pdf.createCdf(aset)

    plot_ds = RooDataHist("plot_%s" % dsname, "plot_%s" % dsname, aset, "plot")
    plot_ds.add(combined_ds)

    wmin, wmax = get_eff_sigma(mass, pdf, cdf, options.mH - 10.,
                               options.mH + 10.)
    hmin, hmax, hm = get_FWHM(mass, pdf, cdf, options.mH - 10.,
                              options.mH + 10.)

    helper.add(plot_ds, plot_ds.GetName())
    helper.add(plot_pdf, plot_pdf.GetName())
    helper.add((wmin, wmax), "eff_sigma_combcat")
    helper.add((hmin, hmax, hm), "FWHM_combcat")
    helper.add(plot_ds.sumEntries(), "sumEntries_combcat")

    mass.setRange("higgsrange", options.mH - 25., options.mH + 15.)

    del cdf
    del pdf
    del helper.dsets

    ### label = TLatex(0.1812081,0.8618881,"#scale[0.8]{#splitline{CMS preliminary}{Simulation}}")
    label = TLatex(0.7, 0.86,
                   "#scale[0.65]{#splitline{CMS preliminary}{Simulation}}")
    label.SetNDC(1)

    ##
    ## Make web page with plots
    ##
    if options.doWebPage:
        hth = HtmlHelper(options.outdir)
        hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
            "href", "../?C=M;O=D")
        hth.navbar().cell(HtmlTag("a")).firstChild().txt("home").set(
            "href", "./")

        tab = hth.body().add(HtmlTable())

    ip = 0
    for c in ["_combcat"] + categories:
        ### for c in categories:
        if options.doWebPage and ip % 4 == 0:
            row = tab.row()
        ip = ip + 1

        dsname = "sig_mass_m%1.0f%s" % (options.mH, c)
        canv = TCanvas(dsname, dsname, 600, 600)
        helper.objs.append(canv)

        ### leg = TLegend(0.4345638,0.6835664,0.9362416,0.9178322)
        leg = TLegend(0.2, 0.96, 0.5, 0.55)
        #apply_modifs( leg, [("SetLineColor",kWhite),("SetFillColor",kWhite),("SetFillStyle",0),("SetLineStyle",0)] )

        hplotcompint = mass.frame(RooFit.Bins(250), RooFit.Range("higgsrange"))
        helper.objs.append(hplotcompint)
        helper.objs.append(leg)

        plot_ds = helper.histos["plot_%s" % dsname]
        plot_pdf = helper.histos["pdf_%s" % dsname]
        wmin, wmax = helper.histos["eff_sigma%s" % c]
        hmin, hmax, hm = helper.histos["FWHM%s" % c]
        print hmin, hmax, hm

        style = (RooFit.LineColor(kBlue), RooFit.LineWidth(2),
                 RooFit.FillStyle(0))
        style_seff = (
            RooFit.LineWidth(2),
            RooFit.FillStyle(1001),
            RooFit.VLines(),
            RooFit.LineColor(15),
        )
        style_ds = (RooFit.MarkerStyle(kOpenSquare), )

        plot_ds.plotOn(hplotcompint, RooFit.Invisible())

        plot_pdf.plotOn(hplotcompint, RooFit.NormRange("higgsrange"),
                        RooFit.Range(wmin, wmax), RooFit.FillColor(19),
                        RooFit.DrawOption("F"), *style_seff)
        seffleg = hplotcompint.getObject(int(hplotcompint.numItems() - 1))
        plot_pdf.plotOn(hplotcompint, RooFit.NormRange("higgsrange"),
                        RooFit.Range(wmin, wmax), RooFit.LineColor(15),
                        *style_seff)

        plot_pdf.plotOn(hplotcompint, RooFit.NormRange("higgsrange"),
                        RooFit.Range("higgsrange"), *style)
        pdfleg = hplotcompint.getObject(int(hplotcompint.numItems() - 1))

        plot_ds.plotOn(hplotcompint, *style_ds)
        pointsleg = hplotcompint.getObject(int(hplotcompint.numItems() - 1))

        iob = int(hplotcompint.numItems() - 1)
        leg.AddEntry(pointsleg, "Simulation", "pe")
        leg.AddEntry(pdfleg, "Parametric model", "l")
        leg.AddEntry(seffleg,
                     "#sigma_{eff} = %1.2f GeV " % (0.5 * (wmax - wmin)), "fl")

        clabel = TLatex(0.74, 0.65,
                        "#scale[0.65]{#splitline{%s}{%s}}" % clables[c])
        clabel.SetNDC(1)
        helper.objs.append(clabel)

        hm = hplotcompint.GetMaximum() * 0.5 * 0.9
        ### hm = pdfleg.GetMaximum()*0.5
        fwhmarrow = TArrow(hmin, hm, hmax, hm)
        fwhmarrow.SetArrowSize(0.03)
        helper.objs.append(fwhmarrow)
        fwhmlabel = TPaveText(0.20, 0.58, 0.56, 0.48, "brNDC")
        fwhmlabel.SetFillStyle(0)
        fwhmlabel.SetLineColor(kWhite)
        reducedFWHM = (hmax - hmin) / 2.3548200
        fwhmlabel.AddText("FWHM/2.35 = %1.2f GeV" % reducedFWHM)
        helper.objs.append(fwhmlabel)

        hplotcompint.SetTitle("")
        hplotcompint.GetXaxis().SetNoExponent(True)
        hplotcompint.GetXaxis().SetTitle("m_{#gamma#gamma} (GeV)")
        hplotcompint.GetXaxis().SetNdivisions(509)
        ## hplotcompint.GetYaxis().SetTitle("A.U.");
        ## hplotcompint.GetYaxis().SetRangeUser(0.,hplotcompint.GetMaximum()*1.4);
        hplotcompint.Draw()
        leg.Draw("same")
        label.Draw("same")
        clabel.Draw("same")
        fwhmarrow.Draw("<>")
        fwhmlabel.Draw("same")

        plot_ds.sumEntries()

        if options.doWebPage:
            hpl = HtmlPlot(canv, False, "", True, True, True)
            hpl.caption("<i>%s</i>" % canv.GetTitle())
            row.cell(hpl)
        else:
            if os.path.isdir(options.outdir) is False:
                os.mkdir(options.outdir)
            for ext in "C", "png", "pdf":
                canv.SaveAs(
                    os.path.join(options.outdir,
                                 "%s.%s" % (canv.GetName(), ext)))

        if "comb" in c:
            ip = 0

    if options.doWebPage:
        print "Creating pages..."
        hth.dump()

    for f in helper.files:
        f.Close()
    gROOT.Reset()

    from pprint import pprint
    pprint(helper)

    print 'Summary statistics per event class'
    print 'Cat\tSignal\t\tData/GeV (in %3.1f+/-10)\tsigEff\tFWHM/2.35' % options.mH
    sigTotal = 0.
    dataTotal = 0.
    for c in categories:
        sigVal = helper.histos["sumEntries%s" % c]
        datVal = helper.histos["data_sumEntries%s" % c]
        sigTotal += sigVal
        dataTotal += datVal
    for c in categories:
        sigVal = helper.histos["sumEntries%s" % c]
        datVal = helper.histos["data_sumEntries%s" % c]
        effSig = 0.5 * (helper.histos["eff_sigma%s" % c][1] -
                        helper.histos["eff_sigma%s" % c][0])
        fwhm = (helper.histos["FWHM%s" % c][1] -
                helper.histos["FWHM%s" % c][0]) / 2.3548200
        print c, '\t%3.1f (%3.1f%%)\t%3.1f (%3.1f%%)\t\t\t%2.2f\t%2.2f' % (
            sigVal, 100. * sigVal / sigTotal, datVal /
            (10. + 10.), 100. * datVal / dataTotal, effSig, fwhm)

    print "Done."
Esempio n. 4
0
def main(indir, input, outdir):

    ## initialize ROOT style and set-up the html helper
    setStyle()
    if not os.path.isdir(outdir):
        os.mkdir(outdir)
    inputs = [i.split(":") for i in input.split(",") if ":" in i]
    from binning import vtxlabels, ptbins, ptlabels, etalables

    helpers = []
    hth = HtmlHelper(outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    for vtx in vtxlabels:
        page = hth.addPage(vtx.replace("_vtx", "Nvtx"))
        page.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
            "type", "text/css").set("href", "../res/style.css")
        page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../../res/jquery.js").txt(" ")
        page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../res/style.js").txt(" ")

        helper = PlotHelper([{
            "file": "%s/%s" % (indir, file),
            "dir": var,
            "id": var,
            "cat": vtx,
            "label": "%s" % (lab),
            "nostack": 1
        } for file, var, lab in inputs])

        helper.defaultStyles = [
            [
                (setcolors, ROOT.kRed),
                ("SetMarkerStyle", ROOT.kFullCircle),
            ],
            [
                (setcolors, ROOT.kBlack),
                ("SetMarkerStyle", ROOT.kFullTriangleDown),
            ],
            [
                (setcolors, ROOT.kMagenta),
                ("SetMarkerStyle", ROOT.kOpenDiamond),
            ],
            [
                (setcolors, ROOT.kGreen),
                ("SetMarkerStyle", ROOT.kFullStar),
            ],
            [
                (setcolors, ROOT.kBlue),
                ("SetMarkerStyle", ROOT.kOpenTriangleUp),
            ],
            [
                (setcolors, ROOT.kOrange),
                ("SetMarkerStyle", ROOT.kOpenCircle),
            ],
            [
                (setcolors, ROOT.kOrange - 4),
                ("SetMarkerStyle", ROOT.kOpenStar),
            ],
            [
                (setcolors, ROOT.kOrange + 2),
                ("SetMarkerStyle", ROOT.kOpenStar),
            ],
        ]

        histos_to_read = [("%s%s%s" % (eta, "%(cat)s", pt), [],
                           "%s%s" % (eta, pt)) for eta in etalables
                          for pt in ptlabels]
        helper.read(histos_to_read)

        canvstyle = []
        lab_style = [("SetFillColor", kWhite), ("SetShadowColor", kWhite),
                     ("SetLineColor", kWhite)]

        helper.nodisc = TF1("nodisc", "1. - x", 0., 1.)
        tab = page.body().add(HtmlTable())

        page_plots = []
        for eta in etalables:
            for pt in ptlabels:
                lab = TPaveText(0.1, 0.95, 0.4, 1.0, "brNDC")
                apply_modifs(lab, lab_style)
                rng = pt.replace("_pt", "").split("_")
                lab.AddText("%s %s<p_{T}<%s" % (eta, rng[0], rng[1]))
                lab.Draw("SAME")
                page_plots += [(["%s%s" % (eta, pt)], "histo", "pe", canvstyle,
                                (0.2, 0.2, 0.5,
                                 0.5), 0.5, "%s%s%s" % (eta, pt, vtx), [lab])]
            page_plots += [()]

        plot_page(page_plots,
                  tab,
                  helper,
                  None, [helper.nodisc],
                  plots_per_row=3)
        helpers.append(helper)

    ## done: create images and html
    hth.dump()

    print outdir
Esempio n. 5
0
def plot_jet_id(
    infile,
    hth,
    variables_to_plot=[
        ("nvtx", "mva"),
        ("jetPt", "jetEta"),  ##,"jetPhi"),
        ### ("nParticles","nCharged", "nNeutrals"),
        ### ("leadFrac","secondFrac","thirdFrac","fourthFrac"),
        ### ("leadChFrac","secondChFrac","thirdChFrac","fourthChFrac"),
        ### ("leadNeutFrac","secondNeutFrac","thirdNeutFrac","fourthNeutFrac"),
        ### ("leadEmFrac","secondEmFrac","thirdEmFrac","fourthEmFrac"),
        ### ("etaW","phiW",## "jetW",
        ###  "majW","minW"),
        ("dRMean", "dR2Mean", "beta", "betaStar"),
        ### ("dRMean","dRLeadCent","dRLead2nd"),
        ### ("dRMeanNeut","dRMeanEm","dRMeanCh"),
        ### ("frac01","frac02","frac03","frac04","frac05"),
        ### ("chFrac01","chFrac02","chFrac03","chFrac04","chFrac05"),
        ### ("neutFrac01","neutFrac02","neutFrac03","neutFrac04","neutFrac05"),
        ### ("emFrac01","emFrac02","emFrac03","emFrac04","emFrac05"),
        ### ("ptD",),
        ### ("d0","dZ"),
    ],
    helper_inputs=[],
    vtxlabels=["_vtx%s" % l for l in mkBinLabels((10, 20), addOFlow=True)],
    ## vtxlabels = [ "_vtx%s" % l for l in  mkBinLabels((15,20,30),addOFlow=False) ],
    ptbins=[],
    etalables=["TK", "HEin", "HEout", "HF"],
    ### etalables = ["central","endNOtk","fwd"]
):
    from array import array
    from ROOT import setStyle, HtmlHelper, HtmlTag, HtmlTable, HtmlPlot, TF1

    ## etalables = ["endNOtk"]
    if len(helper_inputs) == 0:
        helper_inputs = [{
            "file":
            infile,
            "dir":
            "UnmatchedCleanHistosId",
            "id":
            "UnmatchedCleanHistosId",
            "cat":
            vtx,
            "label":
            "PU %s < N_{vtx} < %s" % tuple(vtx.replace("_vtx", "").split("_")),
            "nostack":
            1
        } for vtx in vtxlabels] + [{
            "file":
            infile,
            "dir":
            "QuarkMatchedCleanHistosId",
            "id":
            "QuarkMatchedCleanHistosId",
            "cat":
            vtx,
            "label":
            "u,d,s %s < N_{vtx} < %s" %
            tuple(vtx.replace("_vtx", "").split("_")),
            "nostack":
            1
        } for vtx in vtxlabels]
        ### + [ {
        ###     "file":infile, "dir":"GluonMatchedCleanHistosId",   "id":"GluonMatchedCleanHistosId",
        ###     "cat": vtx,  "label":"glu %s < N_{vtx} < %s"   % tuple(vtx.replace("_vtx","").split("_")), "nostack" : 1 } for vtx in vtxlabels ]
    if len(ptbins) == 0:
        ## ptbins = (20,30,50)
        ptbins = (10, 20, 25, 30, 40, 50)
    ptlabels = ["_pt%s" % l for l in mkBinLabels(ptbins, addOFlow=True)]

    ## instantiate plot helper
    helper = PlotHelper(helper_inputs)
    helper.defaultStyles = [[(setcolors, ROOT.kRed - 2 + 2 * i),
                             ("SetFillStyle", 0), ("SetLineWidth", 2),
                             ("SetMarkerStyle", ROOT.kOpenTriangleUp)]
                            for i in range(len(vtxlabels))] + [
                                [(setcolors, ROOT.kBlue - 2 + 2 * i),
                                 ("SetFillStyle", 0), ("SetLineWidth", 2),
                                 ("SetMarkerStyle", ROOT.kOpenTriangleUp)]
                                for i in range(len(vtxlabels))
                            ] + [[(setcolors, ROOT.kMagenta - 2 + 2 * i),
                                  ("SetFillStyle", 0), ("SetLineWidth", 2),
                                  ("SetMarkerStyle", ROOT.kOpenTriangleUp)]
                                 for i in range(len(vtxlabels))]

    canvstyle = []

    ## list of variables to plot: one row per tuple
    #### variables_to_plot=[
    ####     ("mva",),
    ####     ("jetPt","jetEta","jetPhi"),
    ####     ("nParticles","nCharged", "nNeutrals"),
    ####     ("leadFrac","secondFrac","thirdFrac","fourthFrac"),
    ####     ("leadChFrac","secondChFrac","thirdChFrac","fourthChFrac"),
    ####     ("leadNeutFrac","secondNeutFrac","thirdNeutFrac","fourthNeutFrac"),
    ####     ("leadEmFrac","secondEmFrac","thirdEmFrac","fourthEmFrac"),
    ####     ("etaW","phiW",## "jetW",
    ####      "majW","minW"),
    ####     ("dRMean","dRLeadCent","dRLead2nd"),
    ####     ("dRMeanNeut","dRMeanEm","dRMeanCh"),
    ####     ("frac01","frac02","frac03","frac04","frac05"),
    ####     ("chFrac01","chFrac02","chFrac03","chFrac04","chFrac05"),
    ####     ("neutFrac01","neutFrac02","neutFrac03","neutFrac04","neutFrac05"),
    ####     ("emFrac01","emFrac02","emFrac03","emFrac04","emFrac05"),
    ####     ("ptD",),
    ####     ("d0","dZ"),
    ####                     ]

    ## compile the list of histograms to be read  and set the layout of the output web page
    histos_to_read = []
    page_template = []
    roc_page_template = []
    for variabs in variables_to_plot:
        ## each tuple corresponds to one histogram
        ##   (histo name, list of modifiers, new name)
        histos_to_read += [
            ("%s_%s%s%s_%s" % ("%(id)s", eta, "%(cat)s", pt, var), [
                normalize,
                (appendtitle,
                 " %s < p_{T} < %s" % tuple(pt.replace("_pt", "").split("_")))
            ], "%s%s_%s" % (eta, pt, var)) for var in variabs
            for eta in etalables for pt in ptlabels
        ]
        for pt in ptlabels:
            ## each tuple in the list corresponds to a plot
            ##  ( list_of_histograms, MC draw option, data draw option, canvas style, legend constructor arguments, y-scale adjustment, canvas name )
            page_template += [(["%s_%s" % (pt, var)], "histo", "pe", canvstyle,
                               (0.5, 0.6, 0.8, 0.9), 0.7, "")
                              for var in variabs]
            ## an empty tuple breaks the line
            page_template.append(())
        ## ROC integrals
        roc_page_template += [(["_roc_integrals_%s" % var], "nostackl", "pe",
                               canvstyle + [("SetGridx", True),
                                            ("SetGridy", True)],
                               (0.5, 0.7, 0.8, 0.9), None, "rocint_%s" % var)
                              for var in variabs]
        roc_page_template.append(())

    ## read the histograms
    helper.read(histos_to_read)

    ## compute the ROC curves
    rochelper = PlotHelper([])
    rochelper.defaultStyles = [[(setcolors, ROOT.kBlue - 8 + 4 * i),
                                ("SetFillStyle", 0), ("SetLineWidth", 2),
                                ("SetMarkerStyle", ROOT.kFullCircle + i)]
                               for i in range(len(vtxlabels))]
    rochelper.optsMap["nostackl"] = "l"

    for vtx in vtxlabels:
        lab = "%s < N_{vtx} < %s" % tuple(vtx.replace("_vtx", "").split("_"))
        for eta in etalables:
            for variabs in variables_to_plot:
                for var in variabs:
                    iname = "%s_roc_integrals%s_%s" % (eta, vtx, var)
                    integrals = TH1F(iname,
                                     "%s %s; p_{T} (GeV/c);" % (var, vtx),
                                     len(ptbins),
                                     array('d', ptbins + (100., )))
                    integrals.GetYaxis().SetRangeUser(0., 1.2)
                    rochelper.add(integrals,
                                  "%s_roc_integrals_%s" % (eta, var), lab)
                    for ipt in range(len(ptlabels)):
                        hname = "%s%s_%s" % (eta, ptlabels[ipt], var)
                        sig = helper.histos["u,d,s %s" % lab][hname]
                        bkg = helper.histos["PU %s" % lab][hname]
                        roc = ROCBuilder(
                            "%s%s" % (hname, vtx),
                            str(sig.GetTitle()).replace(
                                "NoPU",
                                sig.GetXaxis().GetTitle()), sig, bkg).getRoc()
                        rochelper.add(roc, hname, lab)
                        integrals.SetBinContent(ipt + 1, roc.Integral("width"))

    ## prepare one page per eta region
    rochelper.nodisc = TF1("nodisc", "1. - x", 0., 1.)
    rochelper.nodisc_int = TF1("nodisc_int", "0.5", 0., 1000.)
    rochelper.full_nodisc_int = TF1("full_nodisc_int", "1.0", 0., 1000.)
    for eta in etalables:
        page = hth.addPage(eta)
        page.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
            "type", "text/css").set("href", "../res/style.css")
        page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../../res/jquery.js").txt(" ")
        page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../res/style.js").txt(" ")
        tab = page.body().add(HtmlTable())

        roc_page = hth.addPage("ROC_%s" % eta)
        roc_page.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
            "type", "text/css").set("href", "../res/style.css")
        roc_page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../../res/jquery.js").txt(" ")
        roc_page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../res/style.js").txt(" ")
        roc_tab = roc_page.body().add(HtmlTable())

        rocint_page = hth.addPage("ROCIntegrals_%s" % eta)
        rocint_page.header().addobj(HtmlTag("link")).set(
            "rel", "stylesheet").set("type",
                                     "text/css").set("href",
                                                     "../res/style.css")
        rocint_page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../../res/jquery.js").txt(" ")
        rocint_page.header().addobj(HtmlTag("script")).set(
            "language", "javascript").set("type", "text/javascript").set(
                "src", "../res/style.js").txt(" ")
        rocint_tab = rocint_page.body().add(HtmlTable())

        ## build the list of plots from the template
        page_plots = []
        roc_plots = []
        rocint_plots = []
        for p in page_template:
            if len(p) > 0:
                page_plots.append((map(lambda x: eta + x, p[0]), ) + p[1:])
                roc_plots.append((map(lambda x: eta + x, p[0]), ) +
                                 ("nostackl", p[2], p[3] +
                                  [("SetGridx", True), ("SetGridy", True)]) +
                                 p[4:5] + (1.5, "roc_%s" % eta + p[0][0]))
            else:
                page_plots.append(p)
                roc_plots.append(p)
        for p in roc_page_template:
            if len(p) > 0:
                rocint_plots.append((map(lambda x: eta + x, p[0]), ) + p[1:6] +
                                    (eta + p[6], ))
            else:
                rocint_plots.append(p)

        ## generate the plots
        plot_page(page_plots, tab, helper, None, plots_per_row=5)
        for k, v in rochelper.histos.iteritems():
            print k  ## , v.keys()

        plot_page(
            roc_plots,
            roc_tab,
            rochelper,
            None, [rochelper.nodisc],
            plots_per_row=5)  ## ,html_plot_options=(False,"",True,True,False))
        plot_page(rocint_plots,
                  rocint_tab,
                  rochelper,
                  None, [rochelper.nodisc_int],
                  plots_per_row=5)

    rochelper.variables_to_plot = variables_to_plot
    rochelper.vtxlabels = vtxlabels
    rochelper.etalables = etalables
    rochelper.ptlabels = ptlabels

    return helper, rochelper
Esempio n. 6
0
def main(options, args):
    from ROOT import gROOT
    gROOT.SetBatch(options.batch)

    from lip.Tools.rootutils import loadToolsLib, getEfficiencyGraphs, apply_modifs, xtitle, ytitle
    loadToolsLib()

    from ROOT import TCut, TCanvas, gDirectory, gPad, kRed, kBlue, kWhite, setStyle, TLegend, HtmlHelper, HtmlTag, HtmlTable, HtmlPlot, TPaveText
    setStyle()

    print "Getting list of files"
    files = getListOfFiles(options.indir, options.filePattern)

    chain = mkChain(files, options.treename)
    ### chain = mkChain(files[0:100],options.treename)
    ### chain = mkChain(files[0:10],options.treename)
    ### chain = mkChain(files[0:1],options.treename)

    hth = HtmlHelper(options.outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    tab = hth.body().add(HtmlTable())

    quants = {}
    objs = []

    var, binning = options.variable.split(":")
    limits = [float(i) for i in binning.split(",")[1:]]
    delta = 0.1 * max(abs(limits[0]), abs(limits[1]))
    limits[0] -= delta
    limits[1] += delta

    sig_style = [("SetLineColor", kBlue), ("SetMarkerColor", kBlue),
                 (xtitle, "p_{T} (GeV)"), (ytitle, "%s eff or rej" % var),
                 ("SetFillStyle", 0)]
    bkg_style = [("SetLineColor", kRed), ("SetMarkerColor", kRed),
                 (xtitle, "p_{T} (GeV)"), (ytitle, "%s eff or rej" % var),
                 ("SetFillStyle", 0)]
    lab_style = [("SetFillColor", kWhite), ("SetShadowColor", kWhite),
                 ("SetLineColor", kWhite)]

    for cut, name, vars in options.categories:
        print "Making TH2 ", name

        ### chain.Draw("4*(%s & 1) + 2*( (%s & 2) / 2) + (%s & 8)/8:jetPt>>h_sig_%s(25,10,60,%s)" % (var, var, var, name, binning), TCut(cut)*TCut(options.sigcut),"goff")
        ### chain.Draw("4*(%s & 1) + 2*( (%s & 2) / 2) + (%s & 8)/8:jetPt>>h_bkg_%s(25,10,60,%s)" % (var, var, var, name, binning), TCut(cut)*TCut(options.bkgcut), "goff")

        chain.Draw("%s:jetPt>>h_sig_%s(20,20,60,%s)" % (var, name, binning),
                   TCut("ijet==1") * TCut(cut) * TCut(options.sigcut), "goff")
        chain.Draw("%s:jetPt>>h_bkg_%s(20,20,60,%s)" % (var, name, binning),
                   TCut(cut) * TCut(options.bkgcut), "goff")

        h_sig = gDirectory.Get("h_sig_%s" % name)
        h_bkg = gDirectory.Get("h_bkg_%s" % name)

        print "Gatting efficiencies ", name
        names = {(0., 6.): "tight", (0., 4.): "medium", (0., 2.): "loose"}
        sig_qvals = [(0., 2.), (0., 4.), (0., 6.)]
        bkg_qvals = [(0., 2.), (0., 4.), (0., 6.)]
        quants[name] = getEfficiencyGraphs(h_sig, sig_qvals,
                                           True), getEfficiencyGraphs(
                                               h_bkg, bkg_qvals)

        for i in range(len(sig_qvals)):
            quants[name][0][i].SetTitle("sig eff %s" % names[sig_qvals[i]])
            apply_modifs(quants[name][0][i], sig_style)

        for i in range(len(bkg_qvals)):
            quants[name][1][i].SetTitle("bkg rej %s" % names[bkg_qvals[i]])
            apply_modifs(quants[name][1][i], bkg_style)

        nvals = len(sig_qvals)
        plotsperline = 4
        for i in range(nvals):
            if i % plotsperline == 0:
                row = tab.row()
            canv = TCanvas("%s_%d" % (name, i), ("%s_%d" % (name, i)), 800,
                           1000)
            canv.SetGridx(), canv.SetGridy()

            quants[name][0][i].Draw("ap")
            quants[name][1][i].Draw("p")
            quants[name][0][i].GetYaxis().SetLimits(0., 1.2)
            quants[name][0][i].GetYaxis().SetRangeUser(0., 1.2)

            leg1 = TLegend(0.2, 0.95, 0.5, 1.0)
            apply_modifs(leg1, lab_style)
            leg1.AddEntry(quants[name][0][i], "", "lp")
            leg1.Draw("SAME")

            leg2 = TLegend(0.5, 0.95, 0.8, 1.0)
            apply_modifs(leg2, lab_style)
            leg2.AddEntry(quants[name][1][i], "", "lp")
            leg2.Draw("SAME")

            lab = TPaveText(0.1, 0.95, 0.2, 1.0, "brNDC")
            apply_modifs(lab, lab_style)
            lab.AddText(name)
            lab.Draw("SAME")

            row.cell(HtmlPlot(canv, False, "", True, True, True))
            objs.append(lab)
            objs.append(leg1)
            objs.append(leg2)
            objs.append(canv)

    if not os.path.isdir(options.outdir):
        os.mkdir(options.outdir)
    hth.dump()

    return quants, objs, chain
Esempio n. 7
0
def main(infile, outdir, label, variables="", mvas=""):

    ## initialize ROOT style and set-up the html helper
    setStyle()
    hth = HtmlHelper(outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("kinematics").set(
        "href", "./")

    from binning import vtxlabels, ptbins, ptlabels, etalables

    helper_inputs = [{
        "file":
        infile,
        "dir":
        "background",
        "id":
        "background",
        "cat":
        vtx,
        "label":
        "PU %s < N_{vtx} < %s" % tuple(vtx.replace("_vtx", "").split("_")),
        "nostack":
        1
    } for vtx in vtxlabels] + [{
        "file":
        infile,
        "dir":
        "signal",
        "id":
        "signal",
        "cat":
        vtx,
        "label":
        "u,d,s %s < N_{vtx} < %s" % tuple(vtx.replace("_vtx", "").split("_")),
        "nostack":
        1
    } for vtx in vtxlabels]

    if mvas == "":
        mvas = "BDT_%s" % label
    print mvas.split(',')
    variables_to_plot = [
        ("dRMean", "dR2Mean", "beta", "betaStar", "nvtx"),
        (v for v in variables.split(':')
         if v != "" and v != "dRMean" and v != "dR2Mean"),
        ## ("Fisher_%s" % label,"BDT_%s" % label)
        tuple(v for v in mvas.split(',') if v != ""),
        ## ("mva",)
    ]
    etalables = ["TK", "HEin", "HEout", "HF"]
    helper, rochelper = plot_jet_id(
        infile,
        hth,
        variables_to_plot,
        helper_inputs=helper_inputs,
        vtxlabels=vtxlabels,
        ptbins=ptbins,
        etalables=etalables,
        ## etalables = ["central","endNOtk","fwd"]
    )

    ## done: create images and html
    hth.dump()

    save_rocs(rochelper, outdir)