Example #1
0
 def _initDefaultStyle(self):
     gROOT.Reset()
     gROOT.SetStyle("Plain")
     gStyle.SetOptStat(0)
     gStyle.SetOptFit(1111)
     gStyle.SetPadLeftMargin(0.12)
     gStyle.SetPadBottomMargin(0.12)
     gStyle.SetMarkerSize(1.)
     gStyle.SetHistLineWidth(1)
Example #2
0
def set_root_env():
    from ROOT import gStyle, gROOT
    gROOT.Reset()
    gROOT.SetStyle('Plain')
    gStyle.SetCanvasColor(10)
    gStyle.SetStatBorderSize(1)
    gStyle.SetFillColor(10)
    gStyle.SetOptStat(1)
    gStyle.SetStatX(0.46)
    gStyle.SetStatY(0.9)
    gStyle.SetTitleYOffset(1.4)
    gStyle.SetPalette(45)
    gStyle.SetMarkerSize(0.8)
    gStyle.SetLineColor(1)
    gStyle.SetLineWidth(1)
Example #3
0
 def _initDefaultStyle(self):
     gROOT.Reset()
     gROOT.SetStyle("Plain")
     #gStyle.SetOptStat(0)
     gStyle.SetOptFit(1111)
     gStyle.SetPadLeftMargin(0.1)
     gStyle.SetPadBottomMargin(0.1)
     gStyle.SetMarkerSize(1.5)
     gStyle.SetHistLineWidth(1)
     gStyle.SetStatFontSize(0.025)
     gStyle.SetTitleFontSize(0.05)
     gStyle.SetTitle(
         'CMS Preliminary tH, H#to#tau#tau, 19.7 fb^{-1} at 8 TeV')
     gStyle.SetTitleSize(0.06, "XYZ")
     gStyle.SetLabelSize(0.05, "XYZ")
     gStyle.SetNdivisions(510, "XYZ")
Example #4
0
def setStyle():
    gROOT.Reset()
    icol = 0
    # WHITE
    font = 42
    # Helvetica
    tsize = 0.05
    gStyle.SetFrameBorderMode(icol)
    gStyle.SetFrameFillColor(icol)
    gStyle.SetCanvasBorderMode(icol)
    gStyle.SetCanvasColor(icol)
    gStyle.SetPadBorderMode(icol)
    gStyle.SetPadColor(icol)
    gStyle.SetStatColor(icol)
    gStyle.SetPaperSize(20, 26)
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadBottomMargin(0.15)
    gStyle.SetPadLeftMargin(0.12)
    gStyle.SetTitleXOffset(1.05)
    gStyle.SetTitleYOffset(0.95)
    gStyle.SetTextFont(font)
    gStyle.SetTextSize(tsize)
    gStyle.SetLabelFont(font, "x")
    gStyle.SetTitleFont(font, "x")
    gStyle.SetLabelFont(font, "y")
    gStyle.SetTitleFont(font, "y")
    gStyle.SetLabelFont(font, "z")
    gStyle.SetTitleFont(font, "z")
    gStyle.SetLabelSize(tsize * 0.85, "x")
    gStyle.SetTitleSize(tsize * 1.10, "x")
    gStyle.SetLabelSize(tsize * 0.85, "y")
    gStyle.SetTitleSize(tsize * 1.10, "y")
    gStyle.SetLabelSize(tsize * 0.85, "z")
    gStyle.SetTitleSize(tsize * 1.10, "z")
    gStyle.SetMarkerStyle(20)
    gStyle.SetMarkerSize(1.)
    gStyle.SetHistLineWidth(2)
    gStyle.SetLineStyleString(2, "[12 12]")
    # postscript dashes
    gStyle.SetEndErrorSize(0.)
    # gStyle.SetOptTitle(0);
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    gStyle.SetPaintTextFormat("4.1f")
Example #5
0
def applyRootStyle():

    from ROOT import gROOT, gStyle, kWhite, kBlack, TColor

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

    # use bold lines and markers
    gStyle.SetLineWidth(lhcbWidth)
    gStyle.SetFrameLineWidth(lhcbWidth)
    gStyle.SetHistLineWidth(lhcbWidth)
    gStyle.SetFuncWidth(lhcbWidth)
    gStyle.SetGridWidth(lhcbWidth)
    gStyle.SetLineStyleString(2, "[12 12]")
    gStyle.SetMarkerStyle(lhcbMarkerType)
    gStyle.SetMarkerSize(lhcbMarkerSize)

    # Grid
    # gStyle.SetGridStyle(3)

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

    # put tick marks on top and RHS of plots
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Style for 2D zcol plots
    NRGBs = 5
    NCont = 255
    from array import array
    stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00])
    red = array('d', [0.00, 0.00, 0.87, 1.00, 0.51])
    green = array('d', [0.00, 0.81, 1.00, 0.20, 0.00])
    blue = array('d', [0.51, 1.00, 0.12, 0.00, 0.00])
    TColor().CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont)
    gStyle.SetNumberContours(NCont)

    # Force the style
    gROOT.ForceStyle()
Example #6
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."
Example #7
0
def rootStyle(batchMode=True):
    from ROOT import gROOT, gStyle, kWhite, kBlack

    # No info messages
    gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;")

    # Batch mode (no TCanvas)
    gROOT.SetBatch(batchMode)

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

    # use bold lines and markers
    gStyle.SetLineWidth(lhcbWidth)
    gStyle.SetFrameLineWidth(lhcbWidth)
    gStyle.SetHistLineWidth(lhcbWidth)
    gStyle.SetFuncWidth(lhcbWidth)
    gStyle.SetGridWidth(lhcbWidth)
    gStyle.SetLineStyleString(2, "[12 12]")
    gStyle.SetMarkerStyle(lhcbMarkerType)
    gStyle.SetMarkerSize(lhcbMarkerSize)

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

    # put tick marks on top and RHS of plots
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Force the style
    gROOT.ForceStyle()
print mpv
print bega

# fill histogram

gROOT.Reset()
gStyle.SetOptLogx()
c1 = TCanvas("c1", "Plot", 1024, 768)
c1.SetGridx()
c1.SetGridy()

h2 = TH2F("h2", "histo2", 2000, 0, 2000, 1000, 0., 500.)
n2xBins = h2.GetNbinsX()
n2yBins = h2.GetNbinsY()
for i in range(12):
    h2.Fill(float(bega[i - 1]), float(mpv[i - 1]) * 1000.)

gStyle.SetMarkerSize(6.)
h2.SetMarkerStyle(23)
h2.GetXaxis().SetTitle("#beta#gamma")
h2.GetYaxis().SetTitle("MPV/keV")

h2.Draw("")
gPad.Update()
c1.Print("muons_IT_drays_off_ht.eps")

outfname = "muons_IT_drays_off_ht.root"
fout = TFile(outfname, "NEW")
h2.Write()
fout.Close()
Example #9
0
from ROOT import gROOT, gStyle, TCanvas, TColor, TF1, TFile, TLegend, THStack, TGraph, TText, TLatex, kTRUE
from array import array

gROOT.SetBatch(True)

gStyle.SetOptStat(0)
gStyle.SetOptFit(0)
gStyle.SetOptTitle(0)

gStyle.SetTitleOffset(1.4, "Y")
gStyle.SetPadLeftMargin(0.18)
gStyle.SetPadBottomMargin(0.15)
gStyle.SetPadTopMargin(0.08)
gStyle.SetPadRightMargin(0.08)
gStyle.SetMarkerSize(0.5)
gStyle.SetHistLineWidth(1)
gStyle.SetTitleSize(0.06, "XYZ")
gStyle.SetLabelSize(0.05, "XYZ")
gStyle.SetNdivisions(506, "XYZ")
gStyle.SetLegendBorderSize(0)

if (__name__ == "__main__"):
    SFile = TFile(
        "/nfs/dust/cms/user/albrechs/UHH2_Output/parameterscan/uhh2.AnalysisModuleRunner.MC.MC_aQGC_ZZjj_hadronic.root"
    )
    BFile = TFile(
        "/nfs/dust/cms/user/albrechs/UHH2_Output/parameterscan/uhh2.AnalysisModuleRunner.MC.MC_QCD.root"
    )

    #rebin stuff
Example #10
0
def CLICdpStyle():
    gROOT.SetStyle("Plain")
    gStyle.SetCanvasColor(root.kWhite)
    gStyle.SetFrameFillColor(root.kWhite)
    gStyle.SetStatColor(root.kWhite)
    gStyle.SetPadColor(root.kWhite)
    gStyle.SetFillColor(10)
    gStyle.SetTitleFillColor(root.kWhite)

    gStyle.SetPaperSize(20, 26)

    gStyle.SetDrawBorder(0)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetLegendBorderSize(0)

    gStyle.SetTextSize(0.05)
    gStyle.SetTitleSize(0.06, "xyz")
    gStyle.SetLabelSize(0.06, "xyz")

    gStyle.SetLabelOffset(0.015, "xyz")
    gStyle.SetTitleOffset(1.2, "yz")
    gStyle.SetTitleOffset(1.17, "x")

    font = 42
    gStyle.SetTitleFont(font)
    gStyle.SetTitleFontSize(0.06)
    gStyle.SetStatFont(font)
    gStyle.SetStatFontSize(0.07)
    gStyle.SetTextFont(font)
    gStyle.SetLabelFont(font, "xyz")
    gStyle.SetTitleFont(font, "xyz")
    gStyle.SetTitleBorderSize(0)
    gStyle.SetStatBorderSize(1)
    gStyle.SetMarkerStyle(1)
    gStyle.SetLineWidth(2)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetPalette(1)

    gStyle.SetOptTitle(0)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetEndErrorSize(5)

    gStyle.SetHistLineWidth(2)
    gStyle.SetFrameLineWidth(2)
    gStyle.SetFuncWidth(2)
    gStyle.SetHistLineColor(root.kBlack)
    gStyle.SetFuncColor(root.kBlack)
    gStyle.SetLabelColor(root.kBlack, "xyz")

    gStyle.SetPadBottomMargin(0.18)
    gStyle.SetPadTopMargin(0.11)
    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadLeftMargin(0.17)

    gStyle.SetNdivisions(506, "xy")

    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    gStyle.SetCanvasDefW(800)
    gStyle.SetCanvasDefH(700)

    gROOT.ForceStyle()
Example #11
0
    def initStyle():
        gROOT.SetStyle("Plain")

        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(700)  #Height of canvas
        gStyle.SetCanvasDefW(700)  #Width of canvas
        gStyle.SetCanvasDefX(0)  #Position on screen
        gStyle.SetCanvasDefY(0)

        # For the line:
        gStyle.SetLineWidth(2)

        # For the Pad:
        gStyle.SetPadBorderMode(0)
        # gStyle.SetPadBorderSize(Width_t size = 1)
        gStyle.SetPadColor(kWhite)
        gStyle.SetPadGridX(True)
        gStyle.SetPadGridY(True)
        gStyle.SetGridColor(0)
        gStyle.SetGridStyle(3)
        gStyle.SetGridWidth(1)

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        gStyle.SetFrameFillColor(0)
        gStyle.SetFrameFillStyle(0)
        gStyle.SetFrameLineColor(1)
        gStyle.SetFrameLineStyle(1)
        gStyle.SetFrameLineWidth(1)

        # For the histo:
        # gStyle.SetHistFillColor(1)
        # gStyle.SetHistFillStyle(0)
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(2)
        # gStyle.SetLegoInnerR(Float_t rad = 0.5)
        # gStyle.SetNumberContours(Int_t number = 20)

        gStyle.SetEndErrorSize(2)
        #gStyle.SetErrorMarker(20)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(8)
        gStyle.SetMarkerSize(1)

        #For the fit/function:
        gStyle.SetOptFit(0)
        gStyle.SetFitFormat("5.4g")
        gStyle.SetFuncColor(2)
        gStyle.SetFuncStyle(1)
        gStyle.SetFuncWidth(1)

        #For the date:
        gStyle.SetOptDate(0)
        # gStyle.SetDateX(Float_t x = 0.01)
        # gStyle.SetDateY(Float_t y = 0.01)

        # For the statistics box:
        gStyle.SetOptFile(0)
        gStyle.SetOptStat(0)  # To display the mean and RMS:   SetOptStat("mr")
        gStyle.SetStatColor(kWhite)
        gStyle.SetStatFont(42)
        gStyle.SetStatFontSize(0.025)
        gStyle.SetStatTextColor(1)
        gStyle.SetStatFormat("6.4g")
        gStyle.SetStatBorderSize(1)
        gStyle.SetStatH(0.1)
        gStyle.SetStatW(0.15)
        # gStyle.SetStatStyle(Style_t style = 1001)
        # gStyle.SetStatX(Float_t x = 0)
        # gStyle.SetStatY(Float_t y = 0)

        # Margins:
        gStyle.SetPadTopMargin(0.11)
        gStyle.SetPadBottomMargin(0.13)
        gStyle.SetPadLeftMargin(0.17)
        gStyle.SetPadRightMargin(0.07)

        # For the Global title:
        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.04)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        #gStyle.SetTitleX(0.35) # Set the position of the title box
        #gStyle.SetTitleY(0.986) # Set the position of the title box
        # gStyle.SetTitleStyle(Style_t style = 1001)
        #gStyle.SetTitleBorderSize(0)

        # For the axis titles:
        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.05, "XYZ")
        # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
        # gStyle.SetTitleYSize(Float_t size = 0.02)
        gStyle.SetTitleXOffset(1.)
        gStyle.SetTitleYOffset(1.3)
        #gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.035, "XYZ")

        # For the axis:
        gStyle.SetAxisColor(1, "XYZ")
        gStyle.SetStripDecimals(True)
        gStyle.SetTickLength(0.03, "XYZ")
        gStyle.SetNdivisions(510, "XYZ")
        gStyle.SetPadTickX(
            1)  # To get tick marks on the opposite side of the frame
        gStyle.SetPadTickY(1)

        # Change for log plots:
        gStyle.SetOptLogx(0)
        gStyle.SetOptLogy(0)
        gStyle.SetOptLogz(0)

        gStyle.SetPalette(1)  #(1,0)

        # another top group addition
        gStyle.SetHatchesSpacing(1.0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
        #gStyle.SetPaperSize(TStyle.kA4)
        #gStyle.SetPaperSize(27., 29.7)
        #TGaxis.SetMaxDigits(3)
        # gStyle.SetLineScalePS(Float_t scale = 3)
        # gStyle.SetLineStyleString(Int_t i, const char* text)
        # gStyle.SetHeaderPS(const char* header)
        # gStyle.SetTitlePS(const char* pstitle)
        #gStyle.SetColorModelPS(1)

        # gStyle.SetBarOffset(Float_t baroff = 0.5)
        # gStyle.SetBarWidth(Float_t barwidth = 0.5)
        # gStyle.SetPaintTextFormat(const char* format = "g")
        # gStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0)
        # gStyle.SetTimeOffset(Double_t toffset)
        # gStyle.SetHistMinimumZero(kTRUE)

        #gStyle.cd()
        print "TDR Style initialized"
Example #12
0
from ROOT import TH1, gROOT, gStyle, TCanvas, TPad, TFile, TGraphAsymmErrors, TGraph, TColor, TColorWheel, TAttLine, kRed, kMagenta, kAzure, kOrange, TLegend, TH1D
import ROOT, array, os, sys
from math import sqrt
import pdb

gROOT.Reset()
gROOT.SetStyle("Plain")
gStyle.SetOptStat(0)
gStyle.SetOptFit(0)
gStyle.SetTitleOffset(1.2, "Y")
gStyle.SetPadLeftMargin(0.11)
gStyle.SetPadBottomMargin(0.1)
gStyle.SetPadTopMargin(0.02)
gStyle.SetPadRightMargin(0.02)
gStyle.SetMarkerSize(1.5)
gStyle.SetHistLineWidth(1)
gStyle.SetStatFontSize(0.020)
gStyle.SetTitleSize(0.06, "XYZ")
gStyle.SetLabelSize(0.05, "XYZ")
gStyle.SetNdivisions(510, "XYZ")
gStyle.SetLegendBorderSize(0)
gStyle.SetPadTickX(1)
gStyle.SetPadTickY(1)


def rebin(h1, nbins, binning):
    for b in range(h1.GetXaxis().GetNbins()):
        h1.SetBinContent(b + 1,
                         h1.GetBinContent(b + 1) * h1.GetBinWidth(b + 1))
        h1.SetBinError(b + 1, h1.GetBinError(b + 1) * h1.GetBinWidth(b + 1))
    h1 = h1.Rebin(nbins, h1.GetName() + "_rebin", binning)
Example #13
0
def tdrstyle():
    gROOT.SetStyle("Plain")
    
    gStyle.SetAxisColor(1, "XYZ")
    
    gStyle.SetCanvasColor(0)
    #gStyle.SetCanvasBorderSize(10)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasDefH(700)
    gStyle.SetCanvasDefW(700)
    gStyle.SetCanvasDefX(0)
    gStyle.SetCanvasDefY(0)
    
    gStyle.SetFitFormat("5.4g")
    gStyle.SetFuncColor(2)
    gStyle.SetFuncStyle(1)
    gStyle.SetFuncWidth(1)
    
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameBorderSize(1)
    gStyle.SetFrameFillStyle(0)
    gStyle.SetFrameFillColor(0)
    gStyle.SetFrameLineColor(1)
    gStyle.SetFrameLineStyle(1)  # 0?
    gStyle.SetFrameLineWidth(1)  # 1?
    
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)
    
    #gStyle.SetHistFillColor(1)
    #gStyle.SetHistFillStyle(0)
    gStyle.SetHistLineColor(1)
    gStyle.SetHistLineStyle(0)
    gStyle.SetHistLineWidth(1)
    
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42,"XYZ")
    gStyle.SetLabelOffset(0.007,"XYZ")  # 0.010?
    gStyle.SetLabelSize(0.05,"XYZ")  # 0.04?
    
    gStyle.SetLegendBorderSize(0)
    gStyle.SetLegendFillColor(0)
    gStyle.SetLegendFont(42)
    
    gStyle.SetMarkerSize(1.0)
    gStyle.SetMarkerStyle(20)
    
    gStyle.SetLineColor(1)
    gStyle.SetLineWidth(2)
    #gStyle.SetLineScalePS(2)
    
    gStyle.SetOptDate(0)
    gStyle.SetOptFile(0)
    gStyle.SetOptFit(1)
    gStyle.SetOptStat(0)
    gStyle.SetOptTitle(0)
    #gStyle.SetOptLogx(0)
    #gStyle.SetOptLogy(0)
    #gStyle.SetOptLogz(0)
    
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadBorderSize(10)
    gStyle.SetPadTopMargin(0.05)  # 0.08?
    gStyle.SetPadBottomMargin(0.13)
    gStyle.SetPadLeftMargin(0.16)
    gStyle.SetPadRightMargin(0.03)  # 0.05?
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    
    gStyle.SetStatColor(0)
    gStyle.SetStatFont(42)
    gStyle.SetStatFontSize(0.025)
    gStyle.SetStatTextColor(1)
    gStyle.SetStatFormat("6.4g")
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatH(0.1)
    gStyle.SetStatW(0.15)
    #gStyle.SetStatX(0)
    #gStyle.SetStatY(0)
    
    #gStyle.SetTextSize(0.055)
    gStyle.SetTextFont(42)
    
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleColor(1)
    gStyle.SetTitleFont(42)
    gStyle.SetTitleColor(1,"XYZ")
    gStyle.SetTitleFont(42,"XYZ")
    gStyle.SetTitleSize(0.06,"XYZ")  # 0.05?
    #gStyle.SetTitleOffset(1.4,"XYZ")
    gStyle.SetTitleOffset(0.9,"X")
    gStyle.SetTitleOffset(1.20,"Y")
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)
    gStyle.SetTitleTextColor(1)
    #gStyle.SetTitleH(0)
    #gStyle.SetTitleW(0)
    #gStyle.SetTitleX(0)
    #gStyle.SetTitleY(0.985)
    #gStyle.SetTitleStyle(1001)
    
    gStyle.SetPalette(1)
    #gStyle.SetNdivisions(510, "XYZ")  # 505?
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetEndErrorSize(2)  # 2?
    #gStyle.SetErrorMarker(20)
    #gStyle.SetErrorX(0.)
    #gStyle.SetPaperSize(20.,20.)
    gStyle.SetStripDecimals(1)
    gStyle.SetTickLength(0.03, "XYZ")
    return 1
Example #14
0
def setStyle():
    TColor.InitializeColors()
    stops = array('d', [
        0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000
    ])
    red = array('d', [
        0.9764, 0.9956, 0.8186, 0.5301, 0.1802, 0.0232, 0.0780, 0.0592, 0.2082
    ])
    green = array('d', [
        0.9832, 0.7862, 0.7328, 0.7492, 0.7178, 0.6419, 0.5041, 0.3599, 0.1664
    ])
    blue = array('d', [
        0.0539, 0.1968, 0.3499, 0.4662, 0.6425, 0.7914, 0.8385, 0.8684, 0.5293
    ])
    TColor.CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0)
    gStyle.SetHatchesLineWidth(1)
    gStyle.SetNumberContours(255)
    gStyle.SetNdivisions(505, "xyz")
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleColor(1)
    gStyle.SetTitleStyle(3013)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleX(0.05)
    gStyle.SetTitleW(0.4)
    gStyle.SetTitleY(0.965)
    gStyle.SetTitleH(0.065)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasBorderSize(3)
    gStyle.SetCanvasColor(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetFuncWidth(3)
    gStyle.SetPadGridY(False)
    gStyle.SetPadGridX(False)
    gStyle.SetFrameLineWidth(1)
    gStyle.SetMarkerSize(5)
    gStyle.SetPadTickX(True)
    gStyle.SetPadTickY(True)
    #gStyle.SetPalette(1)
    gStyle.SetHistLineWidth(3)
    gStyle.SetHistLineColor(1)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetStatW(0.25)
    gStyle.SetStatH(0.25)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatColor(0)
    gStyle.SetStatFormat("6.4g")
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadRightMargin(0.05)
    gStyle.SetPadBottomMargin(0.16)
    gStyle.SetPadLeftMargin(0.12)
    font = 42
    gStyle.SetTextSize(.055)

    gStyle.SetTextFont(font)
    gStyle.SetLabelFont(font, "x")
    gStyle.SetTitleFont(font, "x")
    gStyle.SetLabelFont(font, "y")
    gStyle.SetTitleFont(font, "y")
    gStyle.SetLabelFont(font, "z")
    gStyle.SetTitleFont(font, "z")

    gStyle.SetTitleSize(.055, "x")
    gStyle.SetTitleSize(.055, "y")
    gStyle.SetTitleSize(.05, "z")
    gStyle.SetLabelSize(.05, "x")
    gStyle.SetLabelSize(.05, "y")
    gStyle.SetLabelSize(.05, "z")
    gStyle.SetLabelOffset(0.014, "x")
    gStyle.SetLabelOffset(0.006, "y")
    gStyle.SetLabelOffset(0.008, "z")
    gStyle.SetTitleOffset(1, "y")
    gStyle.SetTitleXOffset(1.2)

    # use bold lines and markers
    gStyle.SetMarkerStyle(20)
    gStyle.SetMarkerColor(1)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetLineStyleString(2, "[12 12]")
    # postscript dashes

    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
Example #15
0
    def analyzeMeshes(self, dictOfMeshes, doCull=False, cullCut=0.90):
        """ analyzeMeshes takes a dictionary with meshes as input, and fits it to the references
        output dictionary includes a deepcopy of the input meshes
        note:
           this fits to zDiff = dictOfMeshes - interpolation of self.meshDict
           ie. the sign is defined as (other guy) - (me)
        """
        # deepcopy the meshes! no longer adjusts in place
        dictOfMeshesCopy = {}
        for key in list(dictOfMeshes.keys()):
            theMesh = copy.deepcopy(dictOfMeshes[key])
            dictOfMeshesCopy[key] = theMesh

        # then we analyze the Zernike polynomials by comparing them to stored references
        # analyzeDonuts returns a dictionary containing deltas and rotation angles for focus, astigmatism and coma
        # as well as the hexapod adjustments
        # it also makes a Canvas of plots for study

        dictOfResults = {}

        # loop over keys, fitting References
        for key in list(dictOfMeshesCopy.keys()):

            # some special cases
            resultsKeyName = "%sResultDict" % (key.replace("Mesh", ""))
            meshName = key
            if key == "z4Mesh":
                print("Python 3 debugging: %r" % self.meshDict)
                dictOfResults[resultsKeyName] = self.fitToRefMesh(
                    self.meshDict[meshName], dictOfMeshesCopy[meshName],
                    self.zangleconv)
            elif key == "rzeroMesh":
                dictOfResults[resultsKeyName] = self.analyzeRzero(
                    dictOfMeshesCopy["rzeroMesh"],
                    dictOfMeshesCopy["chi2Mesh"], dictOfMeshesCopy["neleMesh"])
            elif key == "chi2Mesh":
                continue
            elif key == "neleMesh":
                continue
            else:
                # check that meshDict has the appropriate mesh
                if meshName in self.meshDict:
                    dictOfResults[resultsKeyName] = self.fitToRefMesh(
                        self.meshDict[meshName], dictOfMeshesCopy[meshName])

        # if we want to cull, cull and refit!
        # use the fitted weight to cull - culltype="fit"
        if doCull:
            # this will take the wgt's from the fit and take their product
            # for each point, and cull at a product of cullCut
            self.cullAllMeshes(dictOfMeshesCopy, cullCut=cullCut)

            for key in list(dictOfMeshesCopy.keys()):

                # some special cases
                resultsKeyName = "%sResultDict" % (key.replace("Mesh", ""))
                meshName = key
                if key == "z4Mesh":
                    dictOfResults[resultsKeyName] = self.fitToRefMesh(
                        self.meshDict[meshName], dictOfMeshesCopy[meshName],
                        self.zangleconv)
                elif key == "rzeroMesh":
                    dictOfResults[resultsKeyName] = self.analyzeRzero(
                        dictOfMeshesCopy["rzeroMesh"],
                        dictOfMeshesCopy["chi2Mesh"],
                        dictOfMeshesCopy["neleMesh"])
                elif key == "chi2Mesh":
                    continue
                elif key == "neleMesh":
                    continue
                else:
                    # check that meshDict has the appropriate mesh
                    if meshName in self.meshDict:
                        dictOfResults[resultsKeyName] = self.fitToRefMesh(
                            self.meshDict[meshName],
                            dictOfMeshesCopy[meshName])

        # analyze this data and extract the hexapod coefficients
        donutDict = self.calcHexapod(dictOfResults)

        if len(donutDict) == 0:
            goodCalc = False
        else:
            goodCalc = True

        # add the individual fit results here too
        for key in list(dictOfResults.keys()):
            donutDict[key] = dictOfResults[key]

        # and add the meshes too
        for key in list(dictOfMeshesCopy.keys()):
            donutDict[key] = dictOfMeshesCopy[key]

        # cmr add X and Y coords
        keylist = list(dictOfResults.keys())
        key0 = keylist[0]
        dict0 = dictOfResults[key0]
        donutDict['deltaArrayX'] = dict0['deltaArrayX']
        donutDict['deltaArrayY'] = dict0['deltaArrayY']

        # make a Canvas of plots for this image
        # plot Histogram of Difference before fit, after fit, and after fit vs. X,Y position
        if self.paramDict["histFlag"] and "deltaArrayBefore" in dictOfResults[
                "z4ResultDict"] and goodCalc:

            # setup plots
            gStyle.SetStatH(0.32)
            gStyle.SetStatW(0.4)
            gStyle.SetOptStat(1111111)
            gStyle.SetMarkerStyle(20)
            gStyle.SetMarkerSize(0.5)
            gStyle.SetPalette(1)
            gROOT.ForceStyle()

            # loop over results, making plots for each
            nplots = 0
            plotDict = {}
            for key in list(dictOfResults.keys()):
                theResultDict = dictOfResults[key]

                keyId = key.replace("ResultDict", "")
                # special cases
                if keyId == "z4":
                    nWavesBefore = 200.0
                    nWavesAfter = 200.0
                else:
                    nWavesBefore = 2.0
                    nWavesAfter = 0.2

                if keyId != "rzero":
                    nplots = nplots + 1
                    hBefore = hfillhist(key + "Before",
                                        "Delta " + key + ", Before Fit",
                                        theResultDict["deltaArrayBefore"], 200,
                                        -nWavesBefore, nWavesBefore)
                    hAfter = hfillhist(key + "zAfter",
                                       "Delta " + key + ", After Fit",
                                       theResultDict["deltaArrayAfter"], 200,
                                       -nWavesAfter, nWavesAfter)
                    hBefore2D = TGraph2D(
                        key + "Before2D", "Delta " + key +
                        ", Before Fit, vs. Position;X[mm];Y[mm]",
                        theResultDict["deltaArrayBefore"].shape[0],
                        theResultDict["deltaArrayX"],
                        theResultDict["deltaArrayY"],
                        theResultDict["deltaArrayBefore"])
                    hAfter2D = TGraph2D(
                        key + "After2D", "Delta " + key +
                        ", After Fit, vs. Position;X[mm];Y[mm]",
                        theResultDict["deltaArrayAfter"].shape[0],
                        theResultDict["deltaArrayX"],
                        theResultDict["deltaArrayY"],
                        theResultDict["deltaArrayAfter"])

                    plotList = [hBefore, hAfter, hBefore2D, hAfter2D]
                    plotDict[keyId] = plotList

            # the Canvas

            # unique name for our canvas
            # might be that
            # gROOT.SetBatch(kTRUE)
            # will prevent the Canvas from appearing, but will still get made in output pickle
            tstr = "canvas" + str(time.time())

            canvas = TCanvas(tstr, tstr, 300 * nplots, 1000)
            canvas.Divide(nplots, 4)

            # plot em
            jZ = 0
            for iZ in range(4, 15 + 1):
                key = "z%d" % (iZ)
                if key in plotDict:
                    jZ = jZ + 1

                    plotList = plotDict[key]

                    icanvas = jZ + 0 * nplots
                    canvas.cd(icanvas)
                    plotList[0].Draw()
                    icanvas = jZ + 1 * nplots
                    canvas.cd(icanvas)
                    plotList[1].Draw()
                    icanvas = jZ + 2 * nplots
                    canvas.cd(icanvas)
                    plotList[2].Draw("zcolpcol")
                    icanvas = jZ + 3 * nplots
                    canvas.cd(icanvas)
                    plotList[3].Draw("zcolpcol")

            # set it so that python doesn't own these ROOT object
            for key in list(plotDict.keys()):
                for plot in plotDict[key]:
                    SetOwnership(plot, False)

            # save canvas in the output Dictionary
            donutDict["canvas"] = canvas

        # all done
        return donutDict
Example #16
0
def plot_map(out_file_path, hist):
    map_name = out_file_path if '/' not in out_file_path else out_file_path.split(
        '/')[-1]
    map_name = map_name.replace('.pdf', '')
    rho_min = -6.0
    rho_max = -2.6
    pt_min = 500.
    pt_max = 1200.
    # rho_min = -10
    # rho_max = 0
    # pt_min = 200
    # pt_max = 5000
    disc_min = 0.12
    disc_max = 0.3
    left_margin = 0.14
    right_margin = 0.16
    top_margin = 0.08
    bottom_margin = 0.12

    gStyle.SetPadTickY(1)
    gStyle.SetPadTickX(1)
    gStyle.SetLegendBorderSize(0)

    gROOT.SetBatch(True)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetTitleOffset(0.86, "X")
    gStyle.SetTitleOffset(1.6, "Y")
    gStyle.SetPadLeftMargin(left_margin)
    gStyle.SetPadBottomMargin(bottom_margin)
    gStyle.SetPadTopMargin(top_margin)
    gStyle.SetPadRightMargin(right_margin)

    gStyle.SetMarkerSize(0.5)
    gStyle.SetHistLineWidth(1)
    gStyle.SetTitleSize(0.05, "XYZ")
    gStyle.SetLabelSize(0.04, "XYZ")
    gStyle.SetNdivisions(506, "XYZ")
    gStyle.SetNumberContours(25)
    gStyle.SetLegendBorderSize(0)

    hist.GetXaxis().SetTitle("#rho")
    hist.GetYaxis().SetTitle("p_{T} [GeV]")
    if ('n2' in map_name.lower()):
        hist.GetZaxis().SetTitle("N2^{DDT} X% quantile")
    else:
        hist.GetZaxis().SetTitle("DeepBoosted WvsQCD X% quantile")
        disc_max = 1
    hist.GetXaxis().SetRangeUser(rho_min, rho_max)
    hist.GetYaxis().SetRangeUser(pt_min, pt_max)
    # if(disc_max>hist.GetMaximum()):
    #     hist.GetZaxis().SetRangeUser(disc_min, disc_max)

    Font = 43
    TitleSize = 24.0
    TitleOffset = 1.3
    LabelSize = 18.0
    hist.GetYaxis().SetTitleFont(Font)
    hist.GetYaxis().SetTitleSize(TitleSize)
    hist.GetYaxis().SetTitleOffset(TitleOffset)
    hist.GetYaxis().SetLabelFont(Font)
    hist.GetYaxis().SetLabelSize(LabelSize)

    hist.GetXaxis().SetTitleFont(Font)
    hist.GetXaxis().SetTitleSize(TitleSize)
    hist.GetXaxis().SetTitleOffset(TitleOffset)
    hist.GetXaxis().SetLabelFont(Font)
    hist.GetXaxis().SetLabelSize(LabelSize)

    hist.GetZaxis().SetTitleFont(Font)
    hist.GetZaxis().SetTitleSize(TitleSize)
    hist.GetZaxis().SetTitleOffset(TitleOffset)
    hist.GetZaxis().SetLabelFont(Font)
    hist.GetZaxis().SetLabelSize(LabelSize)

    # hist.GetZaxis().SetNdivisions(20)

    hist.SetTitle(map_name.replace('_', ' '))
    hist.SetTitleFont(43)
    hist.SetTitleSize(18.0)

    # isomasses = [20,55,80,120,200]
    # isomasses = [20,65,80,125,200]
    # isomasses = range(40,200,20)
    isomasses = [40, 80, 110, 120, 200]
    str_isomass = "%.2f*TMath::Exp(-x/2)"
    tf1_isomasses = []
    for i in range(len(isomasses)):
        msd = isomasses[i]
        new_isomass = TF1('isomass_%i' % int(msd), str_isomass % msd, rho_min,
                          rho_max)
        # new_isomass.SetLineColor(920+i)
        new_isomass.SetLineColorAlpha(1, 0.4)
        tf1_isomasses.append(new_isomass)

    c1 = TCanvas("c1", "c1", 700, 600)
    c1.cd()
    hist.Draw("colz")
    latex_border = TLatex()
    latex_border.SetNDC(1)
    latex_border.SetTextColor(1)
    latex_border.SetTextFont(43)
    latex_border.SetTextSize(15.5)
    latex_border.SetTextAngle(297)
    latex = TLatex()
    latex.SetNDC(1)
    latex.SetTextColor(920)
    latex.SetTextFont(43)
    latex.SetTextSize(15)
    # latex.SetTextAngle(297)
    for i in range(len(isomasses)):
        x_pitch = (1 - left_margin - right_margin) / (rho_max - rho_min)
        y_pitch = (1 - bottom_margin - top_margin) / (pt_max - pt_min)
        msd = isomasses[i]
        pt = msd * np.exp(-rho_min / 2)
        pt = 800 if pt > pt_max else pt
        angle = ((180 / np.pi) * np.arctan(2 * x_pitch / (pt * y_pitch))) + 272
        latex.SetTextAngle(angle)
        latex_border.SetTextAngle(angle)
        tf1_isomass = tf1_isomasses[i]
        tf1_isomass.Draw('SAME')
        x_pos = left_margin + (
            (2 * np.log(msd / pt) - rho_min)) * x_pitch + 0.01
        y_pos = bottom_margin + (pt - pt_min) * y_pitch + 0.01
        latex_border.DrawLatex(x_pos, y_pos, 'm_{SD} = %.1f GeV' % msd)
        # latex.DrawLatex(x_pos,y_pos,'m_{SD} = %.1f GeV'%msd)
    c1.SaveAs(out_file_path + ".pdf")
    c1.SaveAs(out_file_path + ".png")
    c1.SaveAs(out_file_path + ".C")
    del c1
Example #17
0
def plot_map_root(file_path, map_name, wp):
    from ROOT import gStyle, gROOT, TFile, TCanvas, TF1, TLatex
    import os
    # rho_min = -6.0
    # rho_max = -2.1
    # pt_min = 200
    # pt_max = 1200
    rho_min = -10
    rho_max = 0
    pt_min = 0
    pt_max = 1500
    disc_min = 0.12
    disc_max = 0.3
    left_margin = 0.14
    right_margin = 0.16
    top_margin = 0.08
    bottom_margin = 0.12
    out_dir = os.path.dirname(file_path)
    out_file_path = out_dir+("/" if len(out_dir)>0 else "")+map_name;
    gStyle.SetPadTickY(1)
    gStyle.SetPadTickX(1)
    gStyle.SetLegendBorderSize(0)
    
    gROOT.SetBatch(True)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetTitleOffset(0.86,"X")
    gStyle.SetTitleOffset(1.6,"Y")
    gStyle.SetPadLeftMargin(left_margin)
    gStyle.SetPadBottomMargin(bottom_margin)
    gStyle.SetPadTopMargin(top_margin)
    gStyle.SetPadRightMargin(right_margin)
    
    gStyle.SetMarkerSize(0.5)
    gStyle.SetHistLineWidth(1)
    gStyle.SetTitleSize(0.05, "XYZ")
    gStyle.SetLabelSize(0.04, "XYZ")
    gStyle.SetNdivisions(506, "XYZ")
    gStyle.SetNumberContours(25)
    gStyle.SetLegendBorderSize(0)
    f = TFile(file_path)
    hist = f.Get(map_name)
  
    hist.GetXaxis().SetTitle("#rho")
    hist.GetYaxis().SetTitle("p_{T} [GeV]")
    if('n2' in map_name.lower()):
        hist.GetZaxis().SetTitle("N2^{DDT} %.1f"%(wp*100)+"% quantile")
    else:
        hist.GetZaxis().SetTitle("DeepBoosted WvsQCD %.1f"%(wp*100)+"% quantile")
        disc_max=1
    hist.GetXaxis().SetRangeUser(rho_min, rho_max)
    hist.GetYaxis().SetRangeUser(pt_min, pt_max)
    if(disc_max>hist.GetMaximum()):
        hist.GetZaxis().SetRangeUser(disc_min, disc_max)

    Font=43
    TitleSize=24.0
    TitleOffset=1.3
    LabelSize=18.0
    hist.GetYaxis().SetTitleFont(Font)
    hist.GetYaxis().SetTitleSize(TitleSize)
    hist.GetYaxis().SetTitleOffset(TitleOffset)
    hist.GetYaxis().SetLabelFont(Font)
    hist.GetYaxis().SetLabelSize(LabelSize)

    hist.GetXaxis().SetTitleFont(Font)
    hist.GetXaxis().SetTitleSize(TitleSize)
    hist.GetXaxis().SetTitleOffset(TitleOffset)
    hist.GetXaxis().SetLabelFont(Font)
    hist.GetXaxis().SetLabelSize(LabelSize)
    
    hist.GetZaxis().SetTitleFont(Font)
    hist.GetZaxis().SetTitleSize(TitleSize)
    hist.GetZaxis().SetTitleOffset(TitleOffset)
    hist.GetZaxis().SetLabelFont(Font)
    hist.GetZaxis().SetLabelSize(LabelSize)
    
    hist.GetZaxis().SetNdivisions(510)
    
    hist.SetTitle(map_name.replace('_',' '))
    hist.SetTitleFont(43)
    hist.SetTitleSize(18.0)
	
    # isomasses = [20,55,80,120,200]
    # isomasses = [20,65,80,125,200]
    # isomasses = range(40,200,20)
    isomasses = [40,80,120,200]
    str_isomass = "%.2f*TMath::Exp(-x/2)"
    tf1_isomasses = []
    for i in range(len(isomasses)):
        msd = isomasses[i]
        new_isomass = TF1('isomass_%i'%int(msd),str_isomass%msd,rho_min,rho_max)
        # new_isomass.SetLineColor(920+i)
        new_isomass.SetLineColorAlpha(1,0.4)
        tf1_isomasses.append(new_isomass)


    c1 = TCanvas("c1","c1",700,600)
    c1.cd()
    hist.Draw("colz")
    latex = TLatex()
    latex.SetNDC(1)
    latex.SetTextColor(1)
    latex.SetTextFont(43)
    latex.SetTextSize(15.5)
    latex.SetTextAngle(297)
    for i in range(len(isomasses)):
        x_pitch = (1-left_margin-right_margin)/(rho_max-rho_min)
        y_pitch = (1-bottom_margin-top_margin)/(pt_max-pt_min)
        msd = isomasses[i]
        pt=msd*np.exp(-rho_min/2)
        pt = 0.5*(pt_max-pt_min)+pt_min if pt > pt_max else pt
        angle = ((180/np.pi)*np.arctan(2*x_pitch/(pt*y_pitch)))+272
        latex.SetTextAngle(angle)
        tf1_isomass = tf1_isomasses[i]
        tf1_isomass.Draw('SAME')
        x_pos = left_margin+((2*np.log(msd/pt)-rho_min))*x_pitch+0.01
        y_pos = bottom_margin+(pt-pt_min)*y_pitch +0.01
        latex.DrawLatex(x_pos,y_pos,'m_{SD} = %.1f GeV'%msd)
    c1.SaveAs(out_file_path+".pdf")
    del c1
Example #18
0
def setStyle():
    gStyle.SetCanvasColor(0)
    gStyle.SetCanvasBorderSize(10)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasDefH(700)
    gStyle.SetCanvasDefW(700)

    gStyle.SetPadColor(0)
    gStyle.SetPadBorderSize(10)
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadBottomMargin(0.13)
    gStyle.SetPadTopMargin(0.08)
    gStyle.SetPadLeftMargin(0.15)
    gStyle.SetPadRightMargin(0.05)
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    gStyle.SetFrameFillStyle(0)
    gStyle.SetFrameFillColor(0)
    gStyle.SetFrameLineColor(1)
    gStyle.SetFrameLineStyle(0)
    gStyle.SetFrameLineWidth(1)
    gStyle.SetFrameBorderSize(10)
    gStyle.SetFrameBorderMode(0)

    gStyle.SetNdivisions(505)

    gStyle.SetLineWidth(2)
    gStyle.SetHistLineWidth(2)
    gStyle.SetFrameLineWidth(2)
    gStyle.SetLegendFillColor(root.kWhite)
    gStyle.SetLegendFont(42)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetMarkerStyle(20)

    gStyle.SetLabelSize(0.040, "X")
    gStyle.SetLabelSize(0.040, "Y")

    gStyle.SetLabelOffset(0.010, "X")
    gStyle.SetLabelOffset(0.010, "Y")

    gStyle.SetLabelFont(42, "X")
    gStyle.SetLabelFont(42, "Y")

    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleFont(42)
    gStyle.SetTitleFont(42, "X")
    gStyle.SetTitleFont(42, "Y")

    gStyle.SetTitleSize(0.045, "X")
    gStyle.SetTitleSize(0.045, "Y")

    gStyle.SetTitleOffset(1.4, "X")
    gStyle.SetTitleOffset(1.4, "Y")

    gStyle.SetTextSize(0.055)
    gStyle.SetTextFont(42)

    gStyle.SetOptStat(0)
def set_root_env():
    #//TStyle* genieStyle = new TStyle("genieStyle", "GENIE Style")
    #//set the background color to white
    gStyle.SetFillColor(10)
    gStyle.SetFrameFillColor(10)
    gStyle.SetCanvasColor(10)
    gStyle.SetPadColor(10)
    gStyle.SetTitleFillColor(0)
    gStyle.SetStatColor(10)

    #dont put a colored frame around the plots
    gStyle.SetFrameBorderMode(0)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetLegendBorderSize(3)

    #use the primary color palette
    #gStyle.SetPalette(1,0)

    #set the default line color for a histogram to be black
    gStyle.SetHistLineColor(ROOT.kBlack)

    #set the default line color for a fit function to be red
    gStyle.SetFuncColor(ROOT.kRed)

    #make the axis labels black
    gStyle.SetLabelColor(ROOT.kBlack, "xyz")

    #set the default title color to be black
    gStyle.SetTitleColor(ROOT.kBlack)

    #set the margins
    gStyle.SetPadBottomMargin(0.18)
    gStyle.SetPadTopMargin(0.08)
    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadLeftMargin(0.17)

    #set axis label and title text sizes
    gStyle.SetLabelFont(42, "xyz")
    gStyle.SetLabelSize(0.04, "xyz")
    gStyle.SetLabelOffset(0.015, "xyz")
    gStyle.SetTitleFont(42, "xyz")
    gStyle.SetTitleSize(0.04, "xyz")
    gStyle.SetTitleOffset(1.4, "y")
    gStyle.SetTitleOffset(1.3, "x")
    gStyle.SetStatFont(42)
    gStyle.SetStatFontSize(0.07)
    gStyle.SetTitleBorderSize(1)
    gStyle.SetStatBorderSize(0)
    gStyle.SetTextFont(42)
    gStyle.SetTitleW(0.5)
    gStyle.SetTitleH(0.1)

    #set line widths
    gStyle.SetFrameLineWidth(2)
    gStyle.SetFuncWidth(2)
    gStyle.SetHistLineWidth(2)

    #set the number of divisions to show
    gStyle.SetNdivisions(506, "xy")
    #gStyle.SetPadTickX(-50202)

    #turn off xy grids
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    #set the tick mark style
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    #turn off stats
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)

    #marker/line settings
    #gStyle.SetMarkerStyle(20)
    gStyle.SetMarkerSize(.95)  #0.7
    gStyle.SetLineWidth(2)
    gStyle.SetErrorX(0)
    gStyle.SetHistLineStyle(0)  #It was 3 for a dotted line

    #done
    gStyle.cd()
    gROOT.ForceStyle()
Example #20
0
def efficiencytracking(var):
    # plots the efficiency vs pT, eta and phi for all the species(it extracts the
    # Efficiency from qa - tracking - efficiency if you have ran with-- make - eff)
    hadron_list = [
        "pion",
        "proton",
        "kaon",
        "electron",
        "muon",
    ]
    color_list = [1, 2, 4, 6, 8]
    marker_list = [20, 21, 22, 34, 45]
    fileo2 = TFile("../codeHF/AnalysisResults_O2.root")

    c1 = TCanvas("c1", "Efficiency")
    gStyle.SetOptStat(0)
    gStyle.SetErrorX(0)
    gStyle.SetFrameLineWidth(2)
    gStyle.SetTitleSize(0.045, "x")
    gStyle.SetTitleSize(0.045, "y")
    gStyle.SetMarkerSize(1)
    gStyle.SetLabelOffset(0.015, "x")
    gStyle.SetLabelOffset(0.02, "y")
    gStyle.SetTickLength(-0.02, "x")
    gStyle.SetTickLength(-0.02, "y")
    gStyle.SetTitleOffset(1.1, "x")
    gStyle.SetTitleOffset(1.0, "y")

    c1.SetCanvasSize(800, 600)
    c1.cd()
    c1.SetGridy()
    c1.SetGridx()
    eff_list = []

    if var == "Pt":
        hempty = TH1F("hempty", ";Transverse Momentum(GeV/c);Efficiency", 100,
                      0.05, 10)
        gPad.SetLogx()
    elif var == "Eta":
        hempty = TH1F("hempty", ";Pseudorapidity;Efficiency", 100, -4.0, 4.0)
    elif var == "Phi":
        hempty = TH1F("hempty", ";Azimuthal angle(rad);Efficiency", 100, 0.0,
                      6.0)

    hempty.GetYaxis().CenterTitle()
    hempty.GetXaxis().CenterTitle()
    hempty.GetXaxis().SetNoExponent()
    hempty.GetXaxis().SetMoreLogLabels(1)
    hempty.Draw()
    leg = TLegend(0.55, 0.15, 0.89, 0.35, "P")
    leg.SetNColumns(2)
    leg.SetHeader("Minimum bias KrKr #sqrt{s} = 6.46TeV", "C")
    leg.SetFillColor(0)

    for i, had in enumerate(hadron_list):
        leff = fileo2.Get("qa-tracking-efficiency-%s/Efficiency" % had)
        if var == "Pt":
            eff = leff.At(0)
        elif var == "Eta":
            eff = leff.At(1)
        elif var == "Phi":
            eff = leff.At(2)
        gPad.Update()
        eff.Paint("p")
        gr = eff.GetPaintedGraph().Clone()
        for j in range(0, gr.GetN()):
            gr.GetEXlow()[j] = 0
            gr.GetEXhigh()[j] = 0

        gr.SetLineColor(color_list[i])
        gr.SetMarkerColor(color_list[i])
        gr.SetMarkerStyle(marker_list[i])
        eff_list.append(gr)
        gr.Draw(" same p")
        leg.AddEntry(eff_list[i], had, "p")
    leg.Draw()
    saveCanvas(c1, "efficiency_tracking_%s" % var)
Example #21
0
def setgstyle():
    # Zero horizontal error bars
    gStyle.SetErrorX(0)

    # For the canvas
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasColor(0)
    gStyle.SetCanvasDefH(800)  # Height of canvas
    gStyle.SetCanvasDefW(800)  # Width of canvas
    gStyle.SetCanvasDefX(0)  # Position on screen
    gStyle.SetCanvasDefY(0)

    # For the frame
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameBorderSize(1)
    gStyle.SetFrameFillColor(1)
    gStyle.SetFrameFillStyle(0)
    gStyle.SetFrameLineColor(1)
    gStyle.SetFrameLineStyle(0)
    gStyle.SetFrameLineWidth(1)

    # For the Pad
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadGridX(False)
    gStyle.SetPadGridY(False)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

    # Margins
    gStyle.SetPadTopMargin(0.08)
    gStyle.SetPadBottomMargin(0.19)
    gStyle.SetPadLeftMargin(0.17)
    #gStyle.SetPadRightMargin(0.07)

    # For the histo:
    gStyle.SetHistLineColor(1)
    gStyle.SetHistLineStyle(0)
    gStyle.SetHistLineWidth(2)
    gStyle.SetMarkerSize(1.4)
    gStyle.SetEndErrorSize(4)

    # For the statistics box:
    gStyle.SetOptStat(0)

    # For the axis
    gStyle.SetAxisColor(1, "XYZ")
    gStyle.SetTickLength(0.03, "XYZ")
    gStyle.SetNdivisions(510, "XYZ")
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    gStyle.SetStripDecimals(False)

    # For the axis labels and titles
    gStyle.SetTitleColor(1, "XYZ")
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42, "XYZ")
    gStyle.SetLabelOffset(0.007, "XYZ")
    gStyle.SetLabelSize(0.045, "XYZ")
    gStyle.SetTitleFont(42, "XYZ")
    gStyle.SetTitleSize(0.06, "XYZ")

    # For the legend
    gStyle.SetLegendBorderSize(0)