Exemplo n.º 1
0
def histogram_plot(hist, outFile):

    ###############################
    # initialisation 
    ###############################
    gROOT.SetStyle("Plain") ;
    gStyle.SetOptStat(0)
    gStyle.SetTitleXOffset (1.25);
    gStyle.SetTitleYOffset (1.5);

    c1 = TCanvas('title', 'name', 600, 500)
    c1.SetTicks(1,1);
    #c1.SetBottomMargin(0.3);
    c1.SetLeftMargin(0.2);   
    c1.SetLogy(1); 
    ###############################

    key_list = hist.keys()
    nhist = len(key_list)

    for i in range(nhist):
        key = key_list[i]
        fName = outFile
        if i == 0: fName = outFile + '('
        if i == nhist - 1: fName = outFile + ')'
        hist[key].Draw()
        c1.Print(fName)

    return
def makeMassRes(inputDATA,inputMC,output,weights,weights2,trackType,funct,mcIsData,dataIsMC):
	style = setTDRStyle()
	gStyle.SetTitleYOffset(1.45)
	gStyle.SetTitleXOffset(1.45)
	gStyle.SetOptFit(0)
	gStyle.SetStatX(.9)
	gStyle.SetStatY(.9)
	
	(data_B,mc_B,ptdaB,ptmcB) = loadHistos(inputDATA,inputMC,"BB",weights,weights2,trackType,mcIsData,dataIsMC)
	(data_E,mc_E,ptdaE,ptmcE) = loadHistos(inputDATA,inputMC,"BE",weights,weights2,trackType,mcIsData,dataIsMC)
	# ~ (data_E2,mc_E2,ptdaE2,ptmcE2) = loadHistos(inputDATA,inputMC,"BE_neweta",weights,weights2,trackType,mcIsData,dataIsMC)

	drawMassRes(data_B,mc_B,output,"BB",ptdaB,ptmcB,trackType,funct,mcIsData,dataIsMC,inputDATA)
	drawMassRes(data_E,mc_E,output,"BE",ptdaE,ptmcE,trackType,funct,mcIsData,dataIsMC,inputDATA)
Exemplo n.º 3
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)
Exemplo n.º 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")
Exemplo n.º 5
0
    def __init__(self):
        '''
        Set up PlotStyle, set gStyle for things we always want no matter what.
        '''
        # CMS-approved everything
        tdrstyle.setTDRStyle()

        ### Differences from TDR standard:

        # Big canvas (can always shrink later)
        gStyle.SetCanvasDefH(1200)
        gStyle.SetCanvasDefW(1200)

        # Tick marks on all sides
        gStyle.SetPadTickX(1)
        gStyle.SetPadTickY(1)

        # Everything has white backgrounds
        gStyle.SetLegendFillColor(0)

        # Colors that don't suck
        gStyle.SetPalette(1)

        # Make axis title and labels just a little smaller and (for Y) closer to the axis
        gStyle.SetTitleSize(0.044, "XYZ")
        gStyle.SetLabelSize(0.033, "XYZ")
        gStyle.SetTitleYOffset(1.15)
        gStyle.SetTitleXOffset(0.95)
        gStyle.SetPadLeftMargin(0.1)
        gStyle.SetPadRightMargin(0.025)
        gStyle.SetPadBottomMargin(0.095)
        gStyle.SetTitleAlign(12)

        # Apply changes
        gROOT.ForceStyle()

        # Force exponentials when axes are over 3 digits
        TGaxis.SetMaxDigits(3)
        TGaxis.SetExponentOffset(-0.060, 0.008, "y")
        TGaxis.SetExponentOffset(
            -0.055, -0.062,
            "x")  # will overlap with title unless title is centered
Exemplo n.º 6
0
def main():

    output = argv[1]
    rap = argv[2]
    flavour = argv[3]
    trackType = argv[4]
    funct = argv[5]
    fit_min = int(argv[6])
    fit_max = int(argv[7])
    rebinFactor = int(argv[8])
    i = int(argv[9])

    if funct == "CB":
        DOCRYSTALBALL = True
        DOCRUIJFF = False
        DODOUBLECB = False

    elif funct == "cruijff":
        DOCRUIJFF = True
        DOCRYSTALBALL = False
        DODOUBLECB = False

    elif funct == "doubleCB":
        DODOUBLECB = True
        DOCRYSTALBALL = False
        DOCRUIJFF = False

    print("+++++++++++++++++++++++++++++++++++++++++")
    print("Fitting histogram for %d < pt_{l} <%d" % (ptbins[i], ptbins[i + 1]))
    print("+++++++++++++++++++++++++++++++++++++++++\n")

    wsFile = TFile("tmpWorkspace.root")
    ws = wsFile.Get("tempWS")
    # fit with a gaussian

    if DOCRYSTALBALL:
        funct = TF1("crystal", "crystalball", fit_min, fit_max)
        funct.SetLineColor(kRed)
        if ws.data("hist").sum(False) < 1500:
            nDOF = (fit_max - fit_min) * 2 / (rebinFactor * 4) - 3
        else:
            nDOF = (fit_max - fit_min) * 2 / rebinFactor - 3

        ws.factory(
            "RooCBShape::cb(mass, mean[0.0], sigma[2,0,10], alphaL[3,-25,25], nL[5,-25,25])"
        )
        ws.factory("BreitWigner::bw(mass,meanZ[91.187], width[2.495])")
        bw = ws.pdf("bw")
        cb = ws.pdf("cb")
        ws.var("mass").setBins(2000, "cache")
        ws.var("mass").setMin("cache", 0)
        ws.var("mass").setMax("cache", 1000)
        ## need to be adjusted to be higher than limit setting

        sigpdf = RooFFTConvPdf("sig", "sig", ws.var("mass"), bw, cb)
        getattr(ws, 'import')(sigpdf, RooCmdArg())

        fitResult = ws.pdf("sig").fitTo(ws.data("hist"), RooFit.Save(),
                                        RooFit.SumW2Error(kFALSE),
                                        RooFit.Minos(kFALSE))

    elif DOCRUIJFF:

        gSystem.Load("./RooCruijff_cxx.so")
        ws.factory(
            "RooCruijff::cb(mass, mean[0.0], sigma[2,0,20], sigma, alphaL[1,0,25], alphaR[1,0,25])"
        )

        if ws.data("hist").sum(False) < 1500:
            nDOF = (fit_max - fit_min) * 2 / (6) - 3
        elif ws.data("hist").sum(False) < 2500:
            nDOF = (fit_max - fit_min) * 2 / (4) - 3
        else:
            nDOF = (fit_max - fit_min) * 2 / rebinFactor - 3

        ws.factory("BreitWigner::bw(mass,meanZ[91.187], width[2.495])")
        bw = ws.pdf("bw")
        cb = ws.pdf("cb")
        ws.var("mass").setBins(2000, "cache")
        ws.var("mass").setMin("cache", 0)
        ws.var("mass").setMax("cache", 1000)
        ## need to be adjusted to be higher than limit setting

        sigpdf = RooFFTConvPdf("sig", "sig", ws.var("mass"), bw, cb)
        getattr(ws, 'import')(sigpdf, RooCmdArg())

        fitResult = ws.pdf("sig").fitTo(ws.data("hist"), RooFit.Save(),
                                        RooFit.SumW2Error(kFALSE),
                                        RooFit.Minos(kFALSE))

    elif DODOUBLECB:

        gSystem.Load("./RooDCBShape_cxx.so")

        ws.factory(
            "RooDCBShape::cb(mass, mean[0.0,-1.5,1.5], sigma[2,0,20], alphaL[2,0,25] , alphaR[2,0,25], nL[1.5,0,25], nR[1.5,0,25])"
        )
        if i == 0:
            ws.var("nL").setVal(1)
            ws.var("nR").setVal(1)
        ws.factory("BreitWigner::bw(mass,meanZ[91.187], width[2.495])")
        bw = ws.pdf("bw")
        cb = ws.pdf("cb")
        ws.var("mass").setBins(2000, "cache")
        ws.var("mass").setMin("cache", 0)
        ws.var("mass").setMax("cache", 1000)
        ## need to be adjusted to be higher than limit setting

        sigpdf = RooFFTConvPdf("sig", "sig", ws.var("mass"), bw, cb)
        getattr(ws, 'import')(sigpdf, RooCmdArg())

        fitResult = ws.pdf("sig").fitTo(ws.data("hist"), RooFit.Save(),
                                        RooFit.SumW2Error(kFALSE),
                                        RooFit.Minos(kFALSE))

        chi2 = RooChi2Var("bla", "blubb", ws.pdf("sig"),
                          ws.data("hist")).getVal()

        if ws.data("hist").sum(False) < 1500:
            nDOF = (fit_max - fit_min) * 2 / (6) - 5
        elif ws.data("hist").sum(False) < 2500:
            nDOF = (fit_max - fit_min) * 2 / (4) - 5
        else:
            nDOF = (fit_max - fit_min) * 2 / rebinFactor - 5

    chi2 = RooChi2Var("bla", "blubb", ws.pdf("sig"), ws.data("hist")).getVal()

    nDOFforWS = RooRealVar('nDOF', 'nDOF', nDOF)
    getattr(ws, 'import')(nDOFforWS, RooCmdArg())
    chi2forWS = RooRealVar('chi2', 'chi2', chi2)
    getattr(ws, 'import')(chi2forWS, RooCmdArg())

    mean = RooRealVar('Mean', 'Mean', ws.var("meanZ").getVal())
    getattr(ws, 'import')(mean, RooCmdArg())
    meane = RooRealVar('Meane', 'Meane', ws.var("meanZ").getError())
    getattr(ws, 'import')(meane, RooCmdArg())
    sig = RooRealVar('Sig', 'Sig', ws.var("sigma").getVal())
    getattr(ws, 'import')(sig, RooCmdArg())
    sige = RooRealVar('Sige', 'Sige', ws.var("sigma").getError())
    getattr(ws, 'import')(sige, RooCmdArg())

    c1 = TCanvas("c1", "c1", 700, 700)
    c1.cd()
    plotPad = TPad("plotPad", "plotPad", 0, 0, 1, 1)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetPadLeftMargin(0.2)
    gStyle.SetTitleYOffset(2)
    plotPad.UseCurrentStyle()
    plotPad.Draw()
    plotPad.cd()

    if DODOUBLECB or DOCRYSTALBALL or DOCRUIJFF:
        ws.var("mass").setBins(30)
        frame = ws.var('mass').frame(
            RooFit.Title('Invariant mass of dimuon pairs'))
        frame.GetXaxis().SetTitle('m_{#mu#mu} [GeV]')
        frame.GetYaxis().SetTitle("Events / 2 GeV")
        RooAbsData.plotOn(ws.data('hist'), frame, RooFit.Name("hist"))
        ws.pdf('sig').plotOn(frame, RooFit.Name("sig"))
        frame.Draw()

        #chi2 = frame.chiSquare("sig","hist",nDOF)
    else:

        h.GetXaxis().SetTitle("m_{ll} [GeV]")
        h.SetLineColor(kBlack)
        h.GetXaxis().SetRangeUser(fit_min, fit_max)
        h.SetMarkerStyle(20)
        h.SetMarkerSize(0.7)

        h.Draw("E")
        if DOCRYSTALBALL or DOCRUIJFF or DODOUBLECB:
            funct.Draw("SAME")
        else:
            gaus.Draw("SAME")

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "Preliminary"
    latexCMS.DrawLatex(0.78, 0.88, "CMS")
    yLabelPos = 0.84
    latexCMSExtra.DrawLatex(0.78, yLabelPos, "%s" % (cmsExtra))

    latexFit1 = TLatex()
    latexFit1.SetTextFont(42)
    latexFit1.SetTextSize(0.035)
    latexFit1.SetNDC(True)
    latexFit1.DrawLatex(0.25, 0.84,
                        "%d GeV < p_{T} < %d GeV" % (ptbins[i], ptbins[i + 1]))

    latexFit = TLatex()
    latexFit.SetTextFont(42)
    latexFit.SetTextSize(0.030)
    latexFit.SetNDC(True)
    latexFit.DrawLatex(
        0.25, 0.74, "%s = %5.3g #pm %5.3g GeV" %
        ("mean bias", ws.var("mean").getVal(), ws.var("mean").getError()))
    if funct == "CB":
        latexFit.DrawLatex(
            0.25, 0.7, "%s = %5.3g #pm %5.3g GeV" %
            ("#sigma", ws.var("sigma").getVal(), ws.var("sigma").getError()))
        latexFit.DrawLatex(
            0.25, 0.66, "%s = %5.3g #pm %5.3g" %
            ("alphaL", ws.var("alphaL").getVal(), ws.var("alphaL").getError()))
        latexFit.DrawLatex(
            0.25, 0.62, "%s = %5.3g #pm %5.3g" %
            ("nL", ws.var("nL").getVal(), ws.var("nL").getError()))
    if funct == "cruijff":
        latexFit.DrawLatex(
            0.25, 0.7, "%s = %5.3g #pm %5.3g GeV" %
            ("#sigma", ws.var("sigma").getVal(), ws.var("sigma").getError()))
        latexFit.DrawLatex(
            0.25, 0.66, "%s = %5.3g #pm %5.3g" %
            ("alphaL", ws.var("alphaL").getVal(), ws.var("alphaL").getError()))
        latexFit.DrawLatex(
            0.25, 0.62, "%s = %5.3g #pm %5.3g" %
            ("alphaR", ws.var("alphaR").getVal(), ws.var("alphaR").getError()))

    if funct == "doubleCB":
        latexFit.DrawLatex(
            0.25, 0.7, "%s = %5.3g #pm %5.3g GeV" %
            ("#sigma", ws.var("sigma").getVal(), ws.var("sigma").getError()))
        latexFit.DrawLatex(
            0.25, 0.66, "%s = %5.3g #pm %5.3g" %
            ("alphaL", ws.var("alphaL").getVal(), ws.var("alphaL").getError()))
        latexFit.DrawLatex(
            0.25, 0.62, "%s = %5.3g #pm %5.3g" %
            ("alphaR", ws.var("alphaR").getVal(), ws.var("alphaR").getError()))
        latexFit.DrawLatex(
            0.25, 0.58, "%s = %5.3g #pm %5.3g" %
            ("nL", ws.var("nL").getVal(), ws.var("nL").getError()))
        latexFit.DrawLatex(
            0.25, 0.54, "%s = %5.3g #pm %5.3g" %
            ("nR", ws.var("nR").getVal(), ws.var("nR").getError()))

    latexFit.DrawLatex(
        0.25, 0.5,
        "#chi^{2}/ndf = %5.1f / %2.0f = %4.2f" % (chi2, nDOF, chi2 / nDOF))

    saveas = "/MassRes_%s_%s_Pt%d_%d_%s" % (trackType, flavour, ptbins[i],
                                            ptbins[i + 1], rap)
    c1.SaveAs(output + saveas + ".root")
    c1.SaveAs(output + saveas + ".C")
    c1.SaveAs(output + saveas + ".png")
    c1.SaveAs(output + saveas + ".pdf")

    print("DONE Fitting...")
    ws.writeToFile("tmpWorkspaceReturn.root")
Exemplo n.º 7
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."
Exemplo n.º 8
0
## For the fit/function:
gStyle.SetFuncColor(2)
gStyle.SetFuncStyle(1)
gStyle.SetFuncWidth(1)

##  Margins:
gStyle.SetPadTopMargin(0.06)
gStyle.SetPadBottomMargin(0.15)
gStyle.SetPadLeftMargin(0.20)  ## was 0.16
gStyle.SetPadRightMargin(0.06)  ## was 0.02

gStyle.SetTitleColor(1, "XYZ")
gStyle.SetTitleFont(42, "XYZ")
gStyle.SetTitleSize(0.07, "XYZ")
gStyle.SetTitleXOffset(0.9)
gStyle.SetTitleYOffset(1.4)  ## was 1.25

##  For the axis labels:
gStyle.SetLabelColor(1, "XYZ")
gStyle.SetLabelFont(42, "XYZ")
gStyle.SetLabelOffset(0.007, "XYZ")
gStyle.SetLabelSize(0.06, "XYZ")
gStyle.SetNdivisions(505, "XYZ")

if (gSystem.DynamicPathName("libFWCoreFWLite.so", True)):
    gROOT.GetInterpreter().AddIncludePath(cmssw_base + '/src')
    gSystem.AddIncludePath('-I"' + cmssw_base + '/src"')
    if not RooFitInclude():
        workingdir = os.getcwd()
        print 'changing to', cmssw_base, 'directory'
        os.chdir(cmssw_base)
Exemplo n.º 9
0
def setStyle():

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBottomMargin(0.12)
    gStyle.SetPadLeftMargin(0.12)
    gStyle.SetCanvasColor(ROOT.kWhite)
    gStyle.SetCanvasDefH(600)
    #Height of canvas
    gStyle.SetCanvasDefW(600)
    #Width of canvas
    gStyle.SetCanvasDefX(0)
    #POsition on screen
    gStyle.SetCanvasDefY(0)
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadBottomMargin(0.15)
    #0.13);
    gStyle.SetPadLeftMargin(0.11)
    #0.16);
    gStyle.SetPadRightMargin(0.05)
    #0.02);

    # For the Pad:
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(ROOT.kWhite)
    gStyle.SetPadGridX(ROOT.kFALSE)
    gStyle.SetPadGridY(ROOT.kFALSE)
    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)

    gStyle.SetAxisColor(1, "XYZ")
    gStyle.SetStripDecimals(ROOT.kTRUE)
    gStyle.SetTickLength(0.03, "XYZ")
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetPadTickX(1)
    # To get tick marks on the opposite side of the frame
    gStyle.SetPadTickY(1)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

    gStyle.SetTitleColor(1, "XYZ")
    gStyle.SetTitleFont(42, "XYZ")
    gStyle.SetTitleSize(0.05, "XYZ")
    gStyle.SetTitleXOffset(1.15)
    #0.9);
    gStyle.SetTitleYOffset(1.3)
    # => 1.15 if exponents

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

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetTitleTextColor(1)
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)

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

    NRGBs = 5
    NCont = 255
    stops = [0.00, 0.34, 0.61, 0.84, 1.00]
    red = [0.00, 0.00, 0.87, 1.00, 0.51]
    green = [0.00, 0.81, 1.00, 0.20, 0.00]
    blue = [0.51, 1.00, 0.12, 0.00, 0.00]
    stopsArray = array('d', stops)
    redArray = array('d', red)
    greenArray = array('d', green)
    blueArray = array('d', blue)
    TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray,
                                    blueArray, NCont)
    gStyle.SetNumberContours(NCont)
def comparePtRes(trackType):

    file2016B = open("default2016Pt/PtResolutionVsPt_%s_B.pkl" % trackType,
                     'rb')
    file2016O = open("default2016Pt/PtResolutionVsPt_%s_O.pkl" % trackType,
                     'rb')
    file2016E = open("default2016Pt/PtResolutionVsPt_%s_E.pkl" % trackType,
                     'rb')
    file2017B = open("defaultPtSplit/PtResolutionVsPt_%s_B.pkl" % trackType,
                     'rb')
    file2017O = open("defaultPtSplit/PtResolutionVsPt_%s_O.pkl" % trackType,
                     'rb')
    file2017E = open("defaultPtSplit/PtResolutionVsPt_%s_E.pkl" % trackType,
                     'rb')
    file2018B = open("default2018Pt/PtResolutionVsPt_%s_B.pkl" % trackType,
                     'rb')
    file2018O = open("default2018Pt/PtResolutionVsPt_%s_O.pkl" % trackType,
                     'rb')
    file2018E = open("default2018Pt/PtResolutionVsPt_%s_E.pkl" % trackType,
                     'rb')

    results2016B = pickle.load(file2016B)
    results2016O = pickle.load(file2016O)
    results2016E = pickle.load(file2016E)

    results2017B = pickle.load(file2017B)
    results2017O = pickle.load(file2017O)
    results2017E = pickle.load(file2017E)

    results2018B = pickle.load(file2018B)
    results2018O = pickle.load(file2018O)
    results2018E = pickle.load(file2018E)

    graph2016B = getGraph(results2016B, "2016B")
    graph2016O = getGraph(results2016O, "2016O")
    graph2016E = getGraph(results2016E, "2016E")

    graph2017B = getGraph(results2017B, "2017B")
    graph2017O = getGraph(results2017O, "2017O")
    graph2017E = getGraph(results2017E, "2017E")

    graph2018B = getGraph(results2018B, "2018B")
    graph2018O = getGraph(results2018O, "2018O")
    graph2018E = getGraph(results2018E, "2018E")

    canv = TCanvas("c1", "c1", 800, 1200)

    plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1)
    # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    # ~ ratioPad.UseCurrentStyle()
    plotPad.Draw()
    # ~ ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    xMax = 0.15
    if trackType == "Inner":
        xMax = 0.3
    if trackType == "Outer":
        xMax = 0.5

    plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]")

    graph2016B.Draw("samepe")
    # ~ graph2016O.Draw("samepe")
    graph2016E.Draw("samepe")
    graph2016B.SetLineColor(kRed)
    graph2016B.SetMarkerColor(kRed)
    graph2016O.SetLineColor(kGreen)
    graph2016O.SetMarkerColor(kGreen)
    graph2016E.SetLineColor(kBlue)
    graph2016E.SetMarkerColor(kBlue)

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "#splitline{Preliminary}{}"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2016" % trackType, "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graph2016B, "Barrel", "l")
    # ~ leg.AddEntry(graph2016O,"Overlap","l")
    leg.AddEntry(graph2016E, "Endcap", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    canv.Print("PtResolutionCompare_%s_2016.pdf" % trackType)
    canv.Print("PtResolutionCompare_%s_2016.root" % trackType)

    canv = TCanvas("c1", "c1", 800, 1200)

    plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1)
    # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    # ~ ratioPad.UseCurrentStyle()
    plotPad.Draw()
    # ~ ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    xMax = 0.15
    if trackType == "Inner":
        xMax = 0.3
    if trackType == "Outer":
        xMax = 0.5

    plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]")

    graph2017B.Draw("samepe")
    # ~ graph2017O.Draw("samepe")
    graph2017E.Draw("samepe")
    graph2017B.SetLineColor(kRed)
    graph2017B.SetMarkerColor(kRed)
    graph2017O.SetLineColor(kGreen)
    graph2017O.SetMarkerColor(kGreen)
    graph2017E.SetLineColor(kBlue)
    graph2017E.SetMarkerColor(kBlue)

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "#splitline{Preliminary}{}"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2017" % trackType, "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graph2017B, "Barrel", "l")
    # ~ leg.AddEntry(graph2017O,"Overlap","l")
    leg.AddEntry(graph2017E, "Endcap", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    canv.Print("PtResolutionCompare_%s_2017.pdf" % trackType)
    canv.Print("PtResolutionCompare_%s_2017.root" % trackType)

    canv = TCanvas("c1", "c1", 800, 1200)

    plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1)
    # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    # ~ ratioPad.UseCurrentStyle()
    plotPad.Draw()
    # ~ ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    xMax = 0.15
    if trackType == "Inner":
        xMax = 0.3
    if trackType == "Outer":
        xMax = 0.5

    plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]")

    graph2018B.Draw("samepe")
    # ~ graph2018O.Draw("samepe")
    graph2018E.Draw("samepe")
    graph2018B.SetLineColor(kRed)
    graph2018B.SetMarkerColor(kRed)
    graph2018O.SetLineColor(kGreen)
    graph2018O.SetMarkerColor(kGreen)
    graph2018E.SetLineColor(kBlue)
    graph2018E.SetMarkerColor(kBlue)

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "#splitline{Preliminary}{}"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2018" % trackType, "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graph2018B, "Barrel", "l")
    # ~ leg.AddEntry(graph2018O,"Overlap","l")
    leg.AddEntry(graph2018E, "Endcap", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    canv.Print("PtResolutionCompare_%s_2018.pdf" % trackType)
    canv.Print("PtResolutionCompare_%s_2018.root" % trackType)
Exemplo n.º 11
0
def initialization(batch=True, font=default_font):
    '''-- ROOT initialization --'''

    print "Initializing ROOT ..."

    # general
    gROOT.Reset()
    gROOT.SetBatch(batch)
    gROOT.SetStyle("Plain")

    # gStyle
    gStyle.SetFillColor(0)
    gStyle.SetCanvasColor(10)
    gStyle.SetLineWidth(1)
    gStyle.SetPalette(8)
    gStyle.SetTextFont(font)
    #gStyle.SetTextSize(30)

    # Frame
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameFillColor(0)

    # Pad
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBottomMargin(0.1)
    gStyle.SetPadTopMargin(0.01)
    gStyle.SetPadLeftMargin(0.1)
    gStyle.SetPadRightMargin(0.01)
    gStyle.SetPadTickX(1)  # make ticks be on all 4 sides.
    gStyle.SetPadTickY(1)
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    # histogram
    gStyle.SetHistFillStyle(0)
    gStyle.SetOptTitle(0)
    gStyle.SetTitleSize(0.22)
    gStyle.SetTitleFontSize(10)
    gStyle.SetTitleFont(font)
    gStyle.SetTitleFont(font, "xyz")
    gStyle.SetTitleYOffset(1.0)
    gStyle.SetTitleXOffset(1.0)
    gStyle.SetTitleXSize(0.04)
    gStyle.SetTitleYSize(0.04)
    gStyle.SetTitleX(.15)
    gStyle.SetTitleY(.98)
    gStyle.SetTitleW(.70)
    gStyle.SetTitleH(.05)

    # statistics box
    gStyle.SetOptStat(0)
    gStyle.SetStatFont(font)
    gStyle.SetStatFontSize(10)
    gStyle.SetStatX(.91)
    gStyle.SetStatY(.90)
    gStyle.SetStatW(.15)
    gStyle.SetStatH(.15)

    # axis labels
    gStyle.SetLabelFont(font)
    gStyle.SetLabelFont(font, "xyz")
    gStyle.SetLabelSize(10, "xyz")
    # gStyle.SetGridColor(1)
    gStyle.SetLegendBorderSize(1)
Exemplo n.º 12
0
gStyle.SetPadColor(0)
gStyle.SetCanvasColor(0)
gStyle.SetTextFont(42)
gStyle.SetCanvasDefH(600)
gStyle.SetCanvasDefW(600)
gStyle.SetCanvasDefX(0)
gStyle.SetCanvasDefY(0)
gStyle.SetPadTopMargin(0.07)
gStyle.SetPadBottomMargin(0.13)
gStyle.SetPadLeftMargin(0.15)
gStyle.SetPadRightMargin(0.05)
gStyle.SetTitleColor(1, "XYZ")
gStyle.SetTitleFont(42, "XYZ")
gStyle.SetTitleSize(0.04, "XYZ")
gStyle.SetTitleXOffset(1.1)
gStyle.SetTitleYOffset(2)
gStyle.SetTextAlign(12)
gStyle.SetLabelColor(1, "XYZ")
gStyle.SetLabelFont(42, "XYZ")
gStyle.SetLabelOffset(0.007, "XYZ")
gStyle.SetLabelSize(0.04, "XYZ")
gStyle.SetAxisColor(1, "XYZ")
gStyle.SetStripDecimals(True)
gStyle.SetTickLength(0.03, "XYZ")
gStyle.SetNdivisions(510, "XYZ")
gStyle.SetPadTickX(1)
gStyle.SetPadTickY(1)
gROOT.ForceStyle()

#set the text for the luminosity label
if (intLumi < 1000.):
Exemplo n.º 13
0
def setTDRStyle(force):

  gStyle.SetCanvasBorderMode(0)
  gStyle.SetCanvasColor(kWhite)
  gStyle.SetCanvasDefH(600)
  gStyle.SetCanvasDefW(600)
  gStyle.SetCanvasDefX(0)
  gStyle.SetCanvasDefY(0)

  gStyle.SetPadBorderMode(0)
  gStyle.SetPadColor(kWhite)
  gStyle.SetPadGridX(False)
  gStyle.SetPadGridY(False)
  gStyle.SetGridColor(0)
  gStyle.SetGridStyle(3)
  gStyle.SetGridWidth(1)

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

  if force:
      gStyle.SetHistLineColor(1)
      gStyle.SetHistLineStyle(0)
      gStyle.SetHistLineWidth(1)


  gStyle.SetEndErrorSize(2)
  gStyle.SetErrorX(0.)

  gStyle.SetMarkerStyle(20)

  gStyle.SetOptFit(1)
  gStyle.SetFitFormat("5.4g")
  gStyle.SetFuncColor(2)
  gStyle.SetFuncStyle(1)
  gStyle.SetFuncWidth(1)

  gStyle.SetOptDate(0)

  gStyle.SetOptFile(0)
  gStyle.SetOptStat(0)
  gStyle.SetStatColor(kWhite)
  gStyle.SetStatFont(42)
  gStyle.SetStatFontSize(0.04)
  gStyle.SetStatTextColor(1)
  gStyle.SetStatFormat("6.4g")
  gStyle.SetStatBorderSize(1)
  gStyle.SetStatH(0.1)
  gStyle.SetStatW(0.2)


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


  gStyle.SetOptTitle(0)
  gStyle.SetTitleFont(42)
  gStyle.SetTitleColor(1)
  gStyle.SetTitleTextColor(1)
  gStyle.SetTitleFillColor(10)
  gStyle.SetTitleFontSize(0.05)


  gStyle.SetTitleColor(1, "XYZ")
  gStyle.SetTitleFont(42, "XYZ")
  gStyle.SetTitleSize(0.06, "XYZ")
  gStyle.SetTitleXOffset(0.9)
  gStyle.SetTitleYOffset(1.25)


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


  gStyle.SetAxisColor(1, "XYZ")
  gStyle.SetStripDecimals(True)
  gStyle.SetTickLength(0.03, "XYZ")
  gStyle.SetNdivisions(510, "XYZ")
  gStyle.SetPadTickX(1)
  gStyle.SetPadTickY(1)

  gStyle.SetOptLogx(0)
  gStyle.SetOptLogy(0)
  gStyle.SetOptLogz(0)

  gStyle.SetPaperSize(20.,20.)


  gROOT.ForceStyle()
def make_template_plots(histograms, category, channel):
    global variable, translate_options, b_tag_bin, save_path
    ROOT.TH1.SetDefaultSumw2(False)
    ROOT.gROOT.SetBatch(True)
    ROOT.gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
    plotting.setStyle()
    gStyle.SetTitleYOffset(1.4)
    ROOT.gROOT.ForceStyle()

    for variable_bin in variable_bins_ROOT[variable]:
        path = save_path + '/' + variable + '/' + category + '/fit_templates/'
        make_folder_if_not_exists(path)
        plotname = path + channel + '_templates_bin_' + variable_bin + '.png'
        # check if template plots exist already
        if os.path.isfile(plotname):
            continue
        canvas = Canvas(width=700, height=500)
        canvas.SetLeftMargin(0.15)
        canvas.SetBottomMargin(0.15)
        canvas.SetTopMargin(0.05)
        canvas.SetRightMargin(0.05)
        legend = plotting.create_legend(x0=0.7, y1=0.8)
        h_signal = histograms[variable_bin]['signal']
        h_VJets = histograms[variable_bin]['V+Jets']
        h_QCD = histograms[variable_bin]['QCD']

        h_signal.GetXaxis().SetTitle('Lepton #eta')
        h_signal.GetYaxis().SetTitle('Normalised Events')
        h_signal.GetXaxis().SetTitleSize(0.05)
        h_signal.GetYaxis().SetTitleSize(0.05)
        h_signal.SetMinimum(0)
        h_signal.SetMaximum(0.2)
        h_signal.SetLineWidth(2)
        h_VJets.SetLineWidth(2)
        h_QCD.SetLineWidth(2)
        h_signal.SetLineColor(kRed + 1)
        h_VJets.SetLineColor(kBlue)
        h_QCD.SetLineColor(kYellow)
        h_signal.Draw('hist')
        h_VJets.Draw('hist same')
        h_QCD.Draw('hist same')
        legend.AddEntry(h_signal, 'signal', 'l')
        legend.AddEntry(h_VJets, 'V+Jets', 'l')
        legend.AddEntry(h_QCD, 'QCD', 'l')
        legend.Draw()

        mytext = TPaveText(0.5, 0.97, 1, 1.01, "NDC")
        channelLabel = TPaveText(0.18, 0.97, 0.5, 1.01, "NDC")
        if channel == 'electron':
            channelLabel.AddText("e, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        elif channel == 'muon':
            channelLabel.AddText("#mu, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        else:
            channelLabel.AddText("combined, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        mytext.AddText(
            "CMS Preliminary, L = %.1f fb^{-1} at #sqrt{s} = 8 TeV" % (5.8))

        mytext.SetFillStyle(0)
        mytext.SetBorderSize(0)
        mytext.SetTextFont(42)
        mytext.SetTextAlign(13)

        channelLabel.SetFillStyle(0)
        channelLabel.SetBorderSize(0)
        channelLabel.SetTextFont(42)
        channelLabel.SetTextAlign(13)
        mytext.Draw()
        channelLabel.Draw()

        canvas.Modified()
        canvas.Update()
        canvas.SaveAs(plotname)
        canvas.SaveAs(plotname.replace('png', 'pdf'))
Exemplo n.º 15
0
def rocPlotMacro():
	
	# load TDR-style plotting macro
	gROOT.LoadMacro("$CMSSW_BASE/src/TauAnalysisTools/TauAnalysisTools/macros/tdrstyle.C")
	ROOT.setTDRStyle()
	gStyle.SetFrameLineWidth(3)
	gStyle.SetLineWidth(3)
	gStyle.SetPadGridX(True)
	gStyle.SetPadGridY(True)
	gStyle.SetPadTopMargin(0.08)
	gStyle.SetPadBottomMargin(0.15)
	gStyle.SetPadLeftMargin(0.18)
	gStyle.SetPadRightMargin(0.05)
	gStyle.SetTitleFontSize(0.055)
	gStyle.SetTitleSize(0.055, "XYZ")
	gStyle.SetTitleXOffset(1.25)
	gStyle.SetTitleYOffset(1.60)
	gStyle.SetLabelSize(0.04, "XYZ")
	gStyle.SetLabelOffset(0.013, "XYZ")

	# list of trainings
	reference53X = {
		'folder' : 'forFabio',
		'color'  : ROOT.kGreen,
		'text'   : '53X'
	}
	reference74X = {
		'folder' : 'antiElectronDiscr74X_onlyZWTTjetsHiggsWZprimeSUSY_FullSkim',
		'color'  : ROOT.kMagenta,
		'text'   : '74X (Complete skim)'
	}

	inputFilePath = '/nfs/dust/cms/user/fcolombo/HiggsToTauTau/TauPOG/antiElectronDiscrMVATraining'

	trainingList = []
	trainingList.append(reference53X)
	trainingList.append(reference74X)

	# list of plots to produce
	roc_linear = {
		'file' : 'showROCcurvesAntiElectronDiscrMVA_all_linear.root',
		'name' : 'roc_linear',
		'y_range' : [0.4, 1.],
		'y_log' : False,
		'leg_loc' : [0.2, 0.2, 0.8, 0.35]
	}
	roc_log = {
		'file' : 'showROCcurvesAntiElectronDiscrMVA_all_log.root',
		'name' : 'roc_log',
		'y_range' : [0.001, 1.],
		'y_log' : True,
		'leg_loc' : [0.2, 0.75, 0.8, 0.9]
	}

	plotList = []
	plotList.append(roc_linear)
	plotList.append(roc_log)

	pTbinsList = ['','tauPtLt50_','tauPt50to100_','tauPt100to200_','tauPt200to400_','tauPt400to600_','tauPt600to900_','tauPt900to1200_','tauPtGt1200_']

	for iPlot, plotDict in enumerate(plotList):
		for ptBin in pTbinsList:

			filename = 'showROCcurvesAntiElectronDiscrMVA_all_'+ptBin+('log' if plotDict['y_log'] else 'linear')

			c1 = TCanvas()
			c1.SetTitle(plotDict['name'])

			legend = TLegend(plotDict['leg_loc'][0], plotDict['leg_loc'][1], plotDict['leg_loc'][2], plotDict['leg_loc'][3])
			legend.SetShadowColor(0)
			legend.SetFillColor(0)

			for iTrain, trainDict in enumerate(trainingList):

				file = TFile.Open(os.path.join(inputFilePath, trainDict['folder'], filename+'.root'))
				canvas = file.Get("canvas")
				histo = canvas.GetPrimitive("dummyHistogram")
				graph = canvas.GetPrimitive("mvaAntiElectronDiscr5_TestTree_"+ptBin+"cloned")

				legend.AddEntry(graph, trainDict['text'], 'l')
				c1.cd()
				if (iTrain == 0):
					histo.GetYaxis().SetRangeUser(plotDict['y_range'][0], plotDict['y_range'][1])
					histo.GetYaxis().SetTitleOffset(1.6)
					histo.Draw()

				graph.SetMarkerColor(trainDict['color'])
				graph.SetLineColor(trainDict['color'])
				graph.SetLineWidth(2)
				graph.Draw("LP SAME")

			if (plotDict['y_log'] == True):
				c1.SetLogy()

			legend.Draw()

			if 'plots' not in os.listdir(inputFilePath):
				os.mkdir(os.path.join(inputFilePath, 'plots'))

			c1.SaveAs(os.path.join(inputFilePath, 'plots', plotDict['name']+'_'+(ptBin[:-1] if ptBin != '' else 'all')+'.png'))
Exemplo n.º 16
0
def setStyle():

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBottomMargin(0.12)
    gStyle.SetPadLeftMargin(0.12)
    gStyle.SetCanvasColor(ROOT.kWhite)
    gStyle.SetCanvasDefH(600)
    #Height of canvas
    gStyle.SetCanvasDefW(600)
    #Width of canvas
    gStyle.SetCanvasDefX(0)
    #POsition on screen
    gStyle.SetCanvasDefY(0)

    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadBottomMargin(0.15)
    #0.13);
    gStyle.SetPadLeftMargin(0.15)
    #0.16);
    gStyle.SetPadRightMargin(0.05)
    #0.02);

    # For the Pad:
    gStyle.SetPadBorderMode(0)
    # gStyle.SetPadBorderSize(Width_t size = 1);
    gStyle.SetPadColor(ROOT.kWhite)
    gStyle.SetPadGridX(ROOT.kFALSE)
    gStyle.SetPadGridY(ROOT.kFALSE)
    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)

    gStyle.SetAxisColor(1, "XYZ")
    gStyle.SetStripDecimals(ROOT.kTRUE)
    gStyle.SetTickLength(0.03, "XYZ")
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetPadTickX(1)
    # To get tick marks on the opposite side of the frame
    gStyle.SetPadTickY(1)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

    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.15)
    #0.9);
    gStyle.SetTitleYOffset(1.3)
    # => 1.15 if exponents
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42, "XYZ")
    gStyle.SetLabelOffset(0.007, "XYZ")
    gStyle.SetLabelSize(0.045, "XYZ")

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetTitleTextColor(1)
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)
Exemplo n.º 17
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"
Exemplo n.º 18
0
    def initialize(fitresults=True, grid=False):
        gROOT.SetStyle("Plain")
        gStyle.SetOptFit()
        gStyle.SetOptStat(0)
        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(600) #Height of canvas
        gStyle.SetCanvasDefW(600) #Width of canvas
        gStyle.SetCanvasDefX(0)   #POsition on screen
        gStyle.SetCanvasDefY(0)

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

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

        # For the histo:
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(2)

        gStyle.SetEndErrorSize(2)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(20)

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

        #For the date:
        gStyle.SetOptDate(0)

        # 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)

        # Margins:
        gStyle.SetPadTopMargin(0.05)
        gStyle.SetPadLeftMargin(0.16)
        gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02
        gStyle.SetPadBottomMargin(0.13)

        # For the Global title:

        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.05)

        # For the axis titles:
        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.06, "XYZ")
        gStyle.SetTitleXOffset(0.9)
        gStyle.SetTitleYOffset(1.25)

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.05, "XYZ")
        #gStyle.SetLabelSize(0.04, "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.)
        # For graphs
        gStyle.SetErrorX(0)  # suppress error along x

        if grid:
          gStyle.SetPadGridX(gridOn)
          gStyle.SetPadGridY(gridOn)
          gStyle.SetGridColor(kGray)
Exemplo n.º 19
0
def compareMassRes(trackType):

    fileEOYBB = open("MassResolutionVsMass_TunePNew_BB_EOY.pkl", "rb")
    fileEOYBE = open("MassResolutionVsMass_TunePNew_BE_EOY.pkl", "rb")
    fileULBB = open("default/MassResolutionVsMass_TunePNew_BB.pkl", "rb")
    fileULBE = open("default/MassResolutionVsMass_TunePNew_BE.pkl", "rb")

    resultsEOYBB = pickle.load(fileEOYBB)
    resultsEOYBE = pickle.load(fileEOYBE)
    resultsULBB = pickle.load(fileULBB)
    resultsULBE = pickle.load(fileULBE)

    graphEOYBB = getGraph(resultsEOYBB, "EOYBB")
    graphEOYBE = getGraph(resultsEOYBE, "EOYBE")
    graphULBB = getGraph(resultsULBB, "ULBB")
    graphULBE = getGraph(resultsULBE, "ULBE")

    ratioBB = getRatio(resultsEOYBB, resultsULBB, "ratioBB")
    ratioBE = getRatio(resultsEOYBE, resultsULBE, "ratioBE")

    canv = TCanvas("c1", "c1", 800, 800)

    plotPad = TPad("plotPad", "plotPad", 0.01, 0.01, 0.99, 0.99)

    ratioPad = TPad("ratioPad", "ratioPad", 0.01, 0.01, 0.99, 0.29)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    # ~ plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    plotPad.SetTopMargin(0.05)
    plotPad.SetLeftMargin(0.13)
    plotPad.SetRightMargin(0.045)
    plotPad.SetBottomMargin(0.3)

    ratioPad.SetTopMargin(0)
    ratioPad.SetTopMargin(0.05)
    ratioPad.SetLeftMargin(0.13)
    ratioPad.SetRightMargin(0.045)
    ratioPad.SetBottomMargin(0.4)

    #~ xMax = 0.08
    #~ if trackType == "Inner":
    #~ xMax = 0.2
    #~ if trackType == "Outer":
    #~ xMax = 0.4

    graphEOYBB.SetMarkerStyle(22)
    graphEOYBB.SetMarkerSize(2)
    graphEOYBB.SetMarkerColor(kBlack)
    graphEOYBB.SetLineColor(kBlack)
    graphEOYBB.SetLineWidth(2)
    graphEOYBB.SetFillColor(0)
    graphEOYBB.SetTitle("Dimuon mass resolution vs pT for %s tracks" %
                        trackType)
    graphEOYBB.GetYaxis().SetTitle("Mass resolution")
    # ~ res_data.GetXaxis().SetTitle("p_{T} (#mu^{#pm}) [GeV]")
    graphEOYBB.GetYaxis().SetTitleFont(42)
    graphEOYBB.GetYaxis().SetTitleSize(0.05)
    graphEOYBB.GetYaxis().SetTitleOffset(1.35)
    graphEOYBB.GetYaxis().SetLabelFont(42)
    graphEOYBB.GetYaxis().SetLabelSize(0.038)
    graphEOYBB.GetYaxis().SetRangeUser(0, 0.1)
    graphEOYBB.GetXaxis().SetTitleSize(0.0)
    graphEOYBB.GetXaxis().SetLabelSize(0.0)

    graphEOYBB.GetXaxis().SetRangeUser(0, 6500)
    graphEOYBB.Draw("AP E0")

    graphULBB.Draw("samepe")
    graphEOYBB.SetMarkerSize(2)
    graphULBB.SetMarkerSize(2)
    graphEOYBB.SetLineWidth(2)
    graphULBB.SetLineWidth(2)
    graphEOYBB.SetMarkerStyle(20)
    graphULBB.SetMarkerStyle(21)
    graphULBB.SetLineColor(kRed)
    graphULBB.SetMarkerColor(kRed)

    latex = TLatex()
    # ~ latex.SetTextFont(42)
    # ~ latex.SetTextAlign(31)
    # ~ latex.SetTextSize(0.04)
    # ~ latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(.03 / 0.7)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatexNDC(
        0.50, 0.96,
        "#scale[0.8]{#font[42]{       2017, 42.1 fb^{-1} (13 TeV)}}")

    cmsExtra = "Preliminary"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.5, 0.65, 0.95, 0.90, "Both muons |#eta| < 1.2", "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graphEOYBB, "EOY ReReco", "l")
    leg.AddEntry(graphULBB, "Legacy ReReco", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    ratioPad.cd()

    ratioBB.GetYaxis().SetTitle("#splitline{EOY ReReco/}{Legacy ReReco}")
    ratioBB.GetXaxis().SetNoExponent(0)
    ratioBB.GetXaxis().SetTitleFont(42)
    ratioBB.GetXaxis().SetTitleOffset(0.85)
    ratioBB.GetXaxis().SetTitleSize(0.2)
    ratioBB.GetXaxis().SetLabelColor(1)
    ratioBB.GetXaxis().SetLabelOffset(0.01)
    ratioBB.GetXaxis().SetLabelFont(42)
    ratioBB.GetXaxis().SetLabelSize(0.17)
    ratioBB.GetXaxis().SetTitle("GEN dimuon mass (GeV)")
    ratioBB.GetYaxis().SetRangeUser(0.5, 1.5)
    ratioBB.GetXaxis().SetRangeUser(0, 6500)
    ratioBB.GetYaxis().SetTitleOffset(0.475)
    ratioBB.GetYaxis().SetTitleSize(0.12)
    ratioBB.GetYaxis().SetTitleFont(42)
    ratioBB.GetYaxis().SetLabelSize(0.14)
    ratioBB.GetYaxis().SetLabelOffset(0.007)
    ratioBB.GetYaxis().SetLabelFont(42)
    ratioBB.GetYaxis().SetNdivisions(505)

    ratioBB.SetMarkerColor(kRed)
    ratioBB.SetLineColor(kRed)
    ratioBB.SetLineWidth(2)
    ratioBB.SetMarkerStyle(20)
    ratioBB.SetMarkerSize(2)

    line = TLine(10, 1, 6500, 1)

    line.SetLineColor(kBlack)
    line.SetLineStyle(kDashed)
    line.SetLineWidth(2)

    ratioBB.Draw("A P E")
    ratioBB.GetXaxis().SetRangeUser(0, 6500)

    line.Draw()
    ratioBB.Draw("samePE")
    ratioPad.RedrawAxis()

    canv.Print("massResolutionCompareUL_%s_BB.pdf" % trackType)

    canv = TCanvas("c1", "c1", 800, 800)

    plotPad = TPad("plotPad", "plotPad", 0.01, 0.01, 0.99, 0.99)

    ratioPad = TPad("ratioPad", "ratioPad", 0.01, 0.01, 0.99, 0.29)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    # ~ plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    plotPad.SetTopMargin(0.05)
    plotPad.SetLeftMargin(0.13)
    plotPad.SetRightMargin(0.045)
    plotPad.SetBottomMargin(0.3)

    ratioPad.SetTopMargin(0)
    ratioPad.SetTopMargin(0.05)
    ratioPad.SetLeftMargin(0.13)
    ratioPad.SetRightMargin(0.045)
    ratioPad.SetBottomMargin(0.4)

    #~ xMax = 0.08
    #~ if trackType == "Inner":
    #~ xMax = 0.2
    #~ if trackType == "Outer":
    #~ xMax = 0.4

    graphEOYBE.SetMarkerStyle(22)
    graphEOYBE.SetMarkerSize(2)
    graphEOYBE.SetMarkerColor(kBlack)
    graphEOYBE.SetLineColor(kBlack)
    graphEOYBE.SetLineWidth(2)
    graphEOYBE.SetFillColor(0)
    graphEOYBE.SetTitle("Dimuon mass resolution vs pT for %s tracks" %
                        trackType)
    graphEOYBE.GetYaxis().SetTitle("Mass resolution")
    # ~ res_data.GetXaxis().SetTitle("p_{T} (#mu^{#pm}) [GeV]")
    graphEOYBE.GetYaxis().SetTitleFont(42)
    graphEOYBE.GetYaxis().SetTitleSize(0.05)
    graphEOYBE.GetYaxis().SetTitleOffset(1.35)
    graphEOYBE.GetYaxis().SetLabelFont(42)
    graphEOYBE.GetYaxis().SetLabelSize(0.038)
    graphEOYBE.GetYaxis().SetRangeUser(0, .2)
    graphEOYBE.GetXaxis().SetTitleSize(0.0)
    graphEOYBE.GetXaxis().SetLabelSize(0.0)

    graphEOYBE.GetXaxis().SetRangeUser(0, 6500)
    graphEOYBE.Draw("AP E0")

    graphULBE.Draw("samepe")
    graphEOYBE.SetMarkerSize(2)
    graphULBE.SetMarkerSize(2)
    graphEOYBE.SetLineWidth(2)
    graphULBE.SetLineWidth(2)
    graphEOYBE.SetMarkerStyle(20)
    graphULBE.SetMarkerStyle(21)
    graphULBE.SetLineColor(kRed)
    graphULBE.SetMarkerColor(kRed)

    latex = TLatex()
    # ~ latex.SetTextFont(42)
    # ~ latex.SetTextAlign(31)
    # ~ latex.SetTextSize(0.04)
    # ~ latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(.03 / 0.7)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatexNDC(
        0.50, 0.96,
        "#scale[0.8]{#font[42]{       2017, 42.1 fb^{-1} (13 TeV)}}")

    cmsExtra = "Preliminary"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.5, 0.65, 0.95, 0.90, "At least one muon |#eta| > 1.2",
                  "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graphEOYBE, "EOY ReReco", "lp")
    leg.AddEntry(graphULBE, "Legacy  ReReco", "lp")

    leg.Draw()

    plotPad.RedrawAxis()

    ratioPad.cd()

    ratioBE.GetYaxis().SetTitle("#splitline{EOY ReReco/}{Legacy ReReco}")
    ratioBE.GetXaxis().SetNoExponent(0)
    ratioBE.GetXaxis().SetTitleFont(42)
    ratioBE.GetXaxis().SetTitleOffset(0.85)
    ratioBE.GetXaxis().SetTitleSize(0.2)
    ratioBE.GetXaxis().SetLabelColor(1)
    ratioBE.GetXaxis().SetLabelOffset(0.01)
    ratioBE.GetXaxis().SetLabelFont(42)
    ratioBE.GetXaxis().SetLabelSize(0.17)
    ratioBE.GetXaxis().SetTitle("GEN dimuon mass (GeV)")
    ratioBE.GetYaxis().SetRangeUser(0.5, 1.5)
    ratioBE.GetXaxis().SetRangeUser(0, 6500)
    ratioBE.GetYaxis().SetTitleOffset(0.475)
    ratioBE.GetYaxis().SetTitleSize(0.12)
    ratioBE.GetYaxis().SetTitleFont(42)
    ratioBE.GetYaxis().SetLabelSize(0.14)
    ratioBE.GetYaxis().SetLabelOffset(0.007)
    ratioBE.GetYaxis().SetLabelFont(42)
    ratioBE.GetYaxis().SetNdivisions(505)

    ratioBE.SetMarkerColor(kRed)
    ratioBE.SetLineColor(kRed)
    ratioBE.SetLineWidth(2)
    ratioBE.SetMarkerStyle(20)
    ratioBE.SetMarkerSize(2)

    line = TLine(10, 1, 6500, 1)

    line.SetLineColor(kBlack)
    line.SetLineStyle(kDashed)
    line.SetLineWidth(2)

    ratioBE.Draw("A P E")
    ratioBE.GetXaxis().SetRangeUser(0, 6500)

    line.Draw()
    ratioBE.Draw("samePE")
    ratioPad.RedrawAxis()
    ratioBE.Draw("samepe")

    canv.Print("massResolutionCompareUL_%s_BE.pdf" % trackType)
Exemplo n.º 20
0
  args.mc = True
  args.data = True
  args.ctrl = True

import sys
import os
os.system('mkdir -p plots')
os.system('mkdir -p files')

from ROOT import gROOT, gStyle
gROOT.SetBatch()
gROOT.ProcessLine(".x lhcbStyle.C")
gStyle.SetTitleXSize(-1.07);
gStyle.SetTitleYSize(0.07);
gStyle.SetTitleXOffset(0.9);
gStyle.SetTitleYOffset(0.9);
gStyle.SetPadLeftMargin(0.15);

from mc_shapes import *

if args.mc:

  ### Signal Shapes ###
  SignalShape()
  ### MisRec Shapes ###
  MisRecShape()
  ### MisID Shapes
  BDstPPShape()
  BDstKKShape()
  ### Part Comb Shapes ###
  BDKPShape(False)
Exemplo n.º 21
0
gStyle.SetStatH(0.15)

gStyle.SetCanvasDefH(150)
gStyle.SetCanvasDefW(150)

gStyle.SetAxisColor(1, "XYZ")
gStyle.SetStripDecimals(1)
gStyle.SetTickLength(0.03, "XYZ")
gStyle.SetNdivisions(510, "XYZ")
gStyle.SetPadTickX(1)
gStyle.SetPadTickY(1)

gStyle.SetPadTopMargin(0.1)
gStyle.SetPadBottomMargin(0.13)
gStyle.SetPadLeftMargin(0.13)
gStyle.SetPadRightMargin(0.1)

gStyle.SetTitleColor(1, "XYZ")
gStyle.SetTitleFont(42, "XYZ")
gStyle.SetTitleSize(0.1, "XYZ")
gStyle.SetTitleXOffset(0.9)
gStyle.SetTitleYOffset(1.4)

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

gStyle.SetErrorX(0)
gROOT.ForceStyle()
def compareMassRes(trackType):

    file2016BB = open("default/MassResolutionVsMass_%s_BB.pkl" % trackType,
                      "rb")
    file2016BE = open("default/MassResolutionVsMass_%s_BE.pkl" % trackType,
                      "rb")
    file2017BB = open("cruijff/MassResolutionVsMass_%s_BB.pkl" % trackType,
                      "rb")
    file2017BE = open("cruijff/MassResolutionVsMass_%s_BE.pkl" % trackType,
                      "rb")
    fileCBB = open("crystal/MassResolutionVsMass_%s_BB.pkl" % trackType, "rb")
    fileCBE = open("crystal/MassResolutionVsMass_%s_BE.pkl" % trackType, "rb")

    results2016BB = pickle.load(file2016BB)
    results2016BE = pickle.load(file2016BE)
    results2017BB = pickle.load(file2017BB)
    results2017BE = pickle.load(file2017BE)
    resultsCBB = pickle.load(fileCBB)
    resultsCBE = pickle.load(fileCBE)

    graph2016BB = getGraph(results2016BB, "DCBBB")
    graph2016BE = getGraph(results2016BE, "DCBBE")
    graph2017BB = getGraph(results2017BB, "CruijffBB")
    graph2017BE = getGraph(results2017BE, "CruijffBE")
    graphCBB = getGraph(resultsCBB, "CBB")
    graphCBE = getGraph(resultsCBE, "CBE")

    ratioBB = getRatio(results2016BB, results2017BB, "ratioBB")
    ratioBE = getRatio(results2016BE, results2017BE, "ratioBE")
    ratioCBB = getRatio(results2016BB, resultsCBB, "ratioCBB")
    ratioCBE = getRatio(results2016BE, resultsCBE, "ratioCBE")

    canv = TCanvas("c1", "c1", 800, 1200)

    plotPad = TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    xMax = 0.08
    if trackType == "Inner":
        xMax = 0.2
    if trackType == "Outer":
        xMax = 0.4

    plotPad.DrawFrame(0, 0, 6000, xMax, ";M [GeV]; mass resolution")

    graph2016BB.Draw("samepe")
    graph2017BB.Draw("samepe")
    graphCBB.Draw("samepe")
    graph2017BB.SetLineColor(kRed)
    graph2017BB.SetMarkerColor(kRed)
    graphCBB.SetLineColor(kBlue)
    graphCBB.SetMarkerColor(kBlue)

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "#splitline{Preliminary}{}"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s BB" % trackType, "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graph2016BB, "Cruijff", "l")
    leg.AddEntry(graph2017BB, "Double CB", "l")
    leg.AddEntry(graphCBB, "Crystal Ball", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    ratioPad.cd()

    ratioBB.SetLineColor(kRed)
    ratioCBB.SetLineColor(kBlue)

    ratioPad.DrawFrame(0, 0.5, 6000, 1.5, ";ratio")

    ratioBB.Draw("samepe")
    ratioCBB.Draw("samepe")

    canv.Print("massResolutionCompareFunc_%s_BB.pdf" % trackType)

    canv = TCanvas("c1", "c1", 800, 1200)

    plotPad = TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    style = setTDRStyle()
    gStyle.SetOptStat(0)
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()
    plotPad.cd()
    plotPad.SetGrid()
    gStyle.SetTitleXOffset(1.45)
    gStyle.SetTitleYOffset(1.55)

    xMax = 0.08
    if trackType == "Inner":
        xMax = 0.2
    if trackType == "Outer":
        xMax = 0.4

    plotPad.DrawFrame(0, 0, 6000, xMax, ";M [GeV]; mass resolution")

    graph2016BE.Draw("samepe")
    graph2017BE.Draw("samepe")
    graphCBE.Draw("samepe")
    graph2017BE.SetLineColor(kRed)
    graph2017BE.SetMarkerColor(kRed)
    graphCBE.SetLineColor(kBlue)
    graphCBE.SetMarkerColor(kBlue)

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.95, 0.96, "(13 TeV)")

    cmsExtra = "#splitline{Preliminary}{}"
    latexCMS.DrawLatex(0.19, 0.88, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.84

    latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

    leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s BE" % trackType, "brNDC")
    leg.SetFillColor(10)
    leg.SetFillStyle(0)
    leg.SetLineColor(10)
    leg.SetShadowColor(0)
    leg.SetBorderSize(1)
    leg.AddEntry(graph2016BE, "Cruijff", "l")
    leg.AddEntry(graph2017BE, "Double CB", "l")
    leg.AddEntry(graphCBE, "Crystal Ball", "l")

    leg.Draw()

    plotPad.RedrawAxis()

    ratioPad.cd()

    ratioBE.SetLineColor(kRed)
    ratioCBE.SetLineColor(kBlue)

    ratioPad.DrawFrame(0, 0.5, 6000, 1.5, ";;ratio")

    ratioBE.Draw("samepe")
    ratioCBE.Draw("samepe")

    canv.Print("massResolutionCompareFunc_%s_BE.pdf" % trackType)
def plot_fit_results(histograms, category, channel):
    global variable, translate_options, b_tag_bin, save_path
    #ROOT.TH1.SetDefaultSumw2(False)
    ROOT.gROOT.SetBatch(True)
    ROOT.gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
    plotting.setStyle()
    gStyle.SetTitleYOffset(1.4)
    ROOT.gROOT.ForceStyle()

    for variable_bin in variable_bins_ROOT[variable]:
        path = save_path + '/' + variable + '/' + category + '/fit_results/'
        make_folder_if_not_exists(path)
        plotname = path + channel + '_bin_' + variable_bin + '.png'
        # check if template plots exist already
        if os.path.isfile(plotname):
            continue
        canvas = Canvas(width=700, height=500)
        canvas.SetLeftMargin(0.15)
        canvas.SetBottomMargin(0.15)
        canvas.SetTopMargin(0.05)
        canvas.SetRightMargin(0.05)
        legend = plotting.create_legend(x0=0.7, y1=0.8)
        h_data = histograms[variable_bin]['data']
        h_signal = histograms[variable_bin]['signal']
        h_background = histograms[variable_bin]['background']

        h_data.GetXaxis().SetTitle('Lepton #eta')
        h_data.GetYaxis().SetTitle('Number of Events')
        h_data.GetXaxis().SetTitleSize(0.05)
        h_data.GetYaxis().SetTitleSize(0.05)
        h_data.SetMinimum(0)
        h_data.SetMarkerSize(1)
        h_data.SetMarkerStyle(20)
        gStyle.SetEndErrorSize(20)
        h_data.Draw('P')

        h_signal.SetFillColor(kRed + 1)
        h_background.SetFillColor(kGreen - 3)
        h_signal.SetLineWidth(2)
        h_background.SetLineWidth(2)
        h_signal.SetFillStyle(1001)
        h_background.SetFillStyle(1001)

        mcStack = THStack("MC", "MC")
        mcStack.Add(h_background)
        mcStack.Add(h_signal)

        mcStack.Draw('hist same')
        h_data.Draw('error P same')
        legend.AddEntry(h_data, 'data', 'P')
        legend.AddEntry(h_signal, 'signal', 'F')
        legend.AddEntry(h_background, 'background', 'F')
        legend.Draw()

        mytext = TPaveText(0.5, 0.97, 1, 1.01, "NDC")
        channelLabel = TPaveText(0.18, 0.97, 0.5, 1.01, "NDC")
        if channel == 'electron':
            channelLabel.AddText("e, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        elif channel == 'muon':
            channelLabel.AddText("#mu, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        else:
            channelLabel.AddText("combined, %s, %s" %
                                 ("#geq 4 jets", b_tag_bins_latex[b_tag_bin]))
        mytext.AddText(
            "CMS Preliminary, L = %.1f fb^{-1} at #sqrt{s} = 8 TeV" % (5.8))

        mytext.SetFillStyle(0)
        mytext.SetBorderSize(0)
        mytext.SetTextFont(42)
        mytext.SetTextAlign(13)

        channelLabel.SetFillStyle(0)
        channelLabel.SetBorderSize(0)
        channelLabel.SetTextFont(42)
        channelLabel.SetTextAlign(13)
        mytext.Draw()
        channelLabel.Draw()

        canvas.Modified()
        canvas.Update()
        canvas.SaveAs(plotname)
        canvas.SaveAs(plotname.replace('png', 'pdf'))
def plot_central_and_systematics(channel):
    global variable, translate_options, k_value, b_tag_bin, maximum, categories
    ROOT.TH1.SetDefaultSumw2(False)
    ROOT.gROOT.SetBatch(True)
    ROOT.gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
    plotting.setStyle()
    gStyle.SetTitleYOffset(1.4)
    ROOT.gROOT.ForceStyle()
    canvas = Canvas(width=700, height=500)
    canvas.SetLeftMargin(0.15)
    canvas.SetBottomMargin(0.15)
    canvas.SetTopMargin(0.05)
    canvas.SetRightMargin(0.05)
    legend = plotting.create_legend(x0=0.6, y1=0.5)

    hist_data_central = read_xsection_measurement_results(
        'central', channel)[0]['unfolded']

    hist_data_central.GetXaxis().SetTitle(translate_options[variable] +
                                          ' [GeV]')
    hist_data_central.GetYaxis().SetTitle('#frac{1}{#sigma} #frac{d#sigma}{d' +
                                          translate_options[variable] +
                                          '} [GeV^{-1}]')
    hist_data_central.GetXaxis().SetTitleSize(0.05)
    hist_data_central.GetYaxis().SetTitleSize(0.05)
    hist_data_central.SetMinimum(0)
    hist_data_central.SetMaximum(maximum[variable])
    hist_data_central.SetMarkerSize(1)
    hist_data_central.SetMarkerStyle(20)
    #    plotAsym = TGraphAsymmErrors(hist_data)
    #    plotStatErr = TGraphAsymmErrors(hist_data)
    gStyle.SetEndErrorSize(20)
    hist_data_central.Draw('P')
    #    plotStatErr.Draw('same P')
    #    plotAsym.Draw('same P Z')
    legend.AddEntry(hist_data_central, 'measured (unfolded)', 'P')

    for systematic in categories:
        if systematic != 'central':
            hist_data_systematic = read_xsection_measurement_results(
                systematic, channel)[0]['unfolded']
            hist_data_systematic.SetMarkerSize(0.5)
            hist_data_systematic.SetMarkerStyle(20)
            colour_number = categories.index(systematic) + 1
            if colour_number == 10:
                colour_number = 42
            hist_data_systematic.SetMarkerColor(colour_number)
            hist_data_systematic.Draw('same P')
            legend.AddEntry(hist_data_systematic, systematic, 'P')


#    for central_generator in ['MADGRAPH', 'POWHEG', 'MCATNLO']:
#        hist_MC = read_xsection_measurement_results('central', channel)[0][central_generator]
#        hist_MC.SetLineStyle(7)
#        hist_MC.SetLineWidth(2)
#        #setting colours
#        if central_generator == 'POWHEG':
#            hist_MC.SetLineColor(kBlue)
#        elif central_generator == 'MADGRAPH':
#            hist_MC.SetLineColor(kRed + 1)
#        elif central_generator == 'MCATNLO':
#            hist_MC.SetLineColor(kMagenta + 3)
#        hist_MC.Draw('hist same')
#legend.AddEntry(hist_MC, translate_options[central_generator], 'l')

    legend.Draw()

    mytext = TPaveText(0.5, 0.97, 1, 1.01, "NDC")
    channelLabel = TPaveText(0.18, 0.97, 0.5, 1.01, "NDC")
    if channel == 'electron':
        channelLabel.AddText(
            "e, %s, %s, k_v = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    elif channel == 'muon':
        channelLabel.AddText(
            "#mu, %s, %s, k_v = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    else:
        channelLabel.AddText(
            "combined, %s, %s, k_v = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    mytext.AddText("CMS Preliminary, L = %.1f fb^{-1} at #sqrt{s} = 8 TeV" %
                   (5.8))

    mytext.SetFillStyle(0)
    mytext.SetBorderSize(0)
    mytext.SetTextFont(42)
    mytext.SetTextAlign(13)

    channelLabel.SetFillStyle(0)
    channelLabel.SetBorderSize(0)
    channelLabel.SetTextFont(42)
    channelLabel.SetTextAlign(13)
    mytext.Draw()
    if not channel == 'combination':
        channelLabel.Draw()

    canvas.Modified()
    canvas.Update()

    path = save_path + '/' + variable
    make_folder_if_not_exists(path)
    canvas.SaveAs(path + '/normalised_xsection_' + channel + '_altogether_kv' +
                  str(k_value) + '.png')
    canvas.SaveAs(path + '/normalised_xsection_' + channel + '_altogether_kv' +
                  str(k_value) + '.pdf')
Exemplo n.º 25
0
    def initialize2(self):
        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(600)  #Height of canvas
        gStyle.SetCanvasDefW(600)  #Width of canvas
        gStyle.SetCanvasDefX(0)  #POsition on screen
        gStyle.SetCanvasDefY(0)

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

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        gStyle.SetFrameFillStyle(1000)
        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(1)
        # gStyle.SetLegoInnerR(Float_t rad = 0.5)
        # gStyle.SetNumberContours(Int_t number = 20)

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

        gStyle.SetMarkerStyle(20)

        #For the fit/function:
        gStyle.SetOptFit(1)
        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.05)
        gStyle.SetPadBottomMargin(0.13)
        gStyle.SetPadLeftMargin(0.16)
        gStyle.SetPadRightMargin(0.02)

        # For the Global title:

        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.05)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        # gStyle.SetTitleX(0) # Set the position of the title box
        # gStyle.SetTitleY(0.985) # Set the position of the title box
        # gStyle.SetTitleStyle(Style_t style = 1001)
        # gStyle.SetTitleBorderSize(2)

        # For the axis titles:

        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.06, "XYZ")
        # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
        # gStyle.SetTitleYSize(Float_t size = 0.02)
        gStyle.SetTitleXOffset(0.9)
        gStyle.SetTitleYOffset(1.25)
        # 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.05, "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)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
def make_plots_ROOT(histograms, category, save_path, histname, channel):
    global variable, translateOptions, k_value, b_tag_bin, maximum
    ROOT.TH1.SetDefaultSumw2(False)
    ROOT.gROOT.SetBatch(True)
    ROOT.gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
    plotting.setStyle()
    gStyle.SetTitleYOffset(2.)
    ROOT.gROOT.ForceStyle()
    canvas = Canvas(width=700, height=500)
    canvas.SetLeftMargin(0.18)
    canvas.SetBottomMargin(0.15)
    canvas.SetTopMargin(0.05)
    canvas.SetRightMargin(0.05)
    legend = plotting.create_legend(x0=0.6, y1=0.5)

    hist_data = histograms['unfolded']
    hist_data.GetXaxis().SetTitle(translate_options[variable] + ' [GeV]')
    hist_data.GetYaxis().SetTitle('#frac{1}{#sigma} #frac{d#sigma}{d' +
                                  translate_options[variable] + '} [GeV^{-1}]')
    hist_data.GetXaxis().SetTitleSize(0.05)
    hist_data.GetYaxis().SetTitleSize(0.05)
    hist_data.SetMinimum(0)
    hist_data.SetMaximum(maximum[variable])
    hist_data.SetMarkerSize(1)
    hist_data.SetMarkerStyle(8)
    plotAsym = TGraphAsymmErrors(hist_data)
    plotStatErr = TGraphAsymmErrors(hist_data)

    xsections = read_unfolded_xsections(channel)
    bins = variable_bins_ROOT[variable]
    assert (len(bins) == len(xsections['central']))

    for bin_i in range(len(bins)):
        scale = 1  # / width
        centralresult = xsections['central'][bin_i]
        fit_error = centralresult[1]
        uncertainty = calculateTotalUncertainty(xsections, bin_i)
        uncertainty_total_plus = uncertainty['Total+'][0]
        uncertainty_total_minus = uncertainty['Total-'][0]
        uncertainty_total_plus, uncertainty_total_minus = symmetriseErrors(
            uncertainty_total_plus, uncertainty_total_minus)
        error_up = sqrt(fit_error**2 + uncertainty_total_plus**2) * scale
        error_down = sqrt(fit_error**2 + uncertainty_total_minus**2) * scale
        plotStatErr.SetPointEYhigh(bin_i, fit_error * scale)
        plotStatErr.SetPointEYlow(bin_i, fit_error * scale)
        plotAsym.SetPointEYhigh(bin_i, error_up)
        plotAsym.SetPointEYlow(bin_i, error_down)

    gStyle.SetEndErrorSize(20)
    plotAsym.SetLineWidth(2)
    plotStatErr.SetLineWidth(2)
    hist_data.Draw('P')
    plotStatErr.Draw('same P')
    plotAsym.Draw('same P Z')
    legend.AddEntry(hist_data, 'unfolded', 'P')

    hist_measured = histograms['measured']
    hist_measured.SetMarkerSize(1)
    hist_measured.SetMarkerStyle(20)
    hist_measured.SetMarkerColor(2)
    #hist_measured.Draw('same P')
    #legend.AddEntry(hist_measured, 'measured', 'P')

    for key, hist in sorted(histograms.iteritems()):
        if not 'unfolded' in key and not 'measured' in key:
            hist.SetLineStyle(7)
            hist.SetLineWidth(2)
            # setting colours
            if 'POWHEG' in key or 'matchingdown' in key:
                hist.SetLineColor(kBlue)
            elif 'MADGRAPH' in key or 'matchingup' in key:
                hist.SetLineColor(kRed + 1)
            elif 'MCATNLO' in key or 'scaleup' in key:
                hist.SetLineColor(kGreen - 3)
            elif 'scaledown' in key:
                hist.SetLineColor(kMagenta + 3)
            hist.Draw('hist same')
            legend.AddEntry(hist, translate_options[key], 'l')

    legend.Draw()

    mytext = TPaveText(0.5, 0.97, 1, 1.01, "NDC")
    channelLabel = TPaveText(0.18, 0.97, 0.5, 1.01, "NDC")
    if 'electron' in histname:
        channelLabel.AddText(
            "e, %s, %s, k = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    elif 'muon' in histname:
        channelLabel.AddText(
            "#mu, %s, %s, k = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    else:
        channelLabel.AddText(
            "combined, %s, %s, k = %s" %
            ("#geq 4 jets", b_tag_bins_latex[b_tag_bin], k_value))
    mytext.AddText("CMS Preliminary, L = %.1f fb^{-1} at #sqrt{s} = 8 TeV" %
                   (5.8))

    mytext.SetFillStyle(0)
    mytext.SetBorderSize(0)
    mytext.SetTextFont(42)
    mytext.SetTextAlign(13)

    channelLabel.SetFillStyle(0)
    channelLabel.SetBorderSize(0)
    channelLabel.SetTextFont(42)
    channelLabel.SetTextAlign(13)
    mytext.Draw()
    channelLabel.Draw()

    canvas.Modified()
    canvas.Update()

    path = save_path + '/' + variable + '/' + category
    make_folder_if_not_exists(path)
    canvas.SaveAs(path + '/' + histname + '_kv' + str(k_value) + '.png')
    canvas.SaveAs(path + '/' + histname + '_kv' + str(k_value) + '.pdf')