Ejemplo n.º 1
0
def singlePlot(h, same, legtext=[]):
    rt.gStyle.SetLegendFont(42)
    if same:
        c = rt.TCanvas('mycv' + h[0].GetName(), 'mycv' + h[0].GetName(), 5, 30,
                       W_ref, H_ref)
        SetupCanvas(c, 0)
        legend = rt.TLegend(x0_l - 0.3, y0_l, x1_l - 0.3, y1_l)

    for ihist in range(len(h)):
        #h[ihist].Scale(1.0/h[ihist].Integral())
        #h[ihist].GetYaxis().SetRangeUser(0,0.3)
        yAxis = h[ihist].GetYaxis()
        yAxis.SetNdivisions(6, 5, 0)
        yAxis.SetTitleOffset(1)
        yAxis.SetTitleSize(0.05)

        if not same:
            c = rt.TCanvas('mycv' + h[ihist].GetName(),
                           'mycv' + h[ihist].GetName(), 5, 30, W_ref, H_ref)
            SetupCanvas(c, 0)
            h[ihist].Draw('histx0')
            CMS_lumi.CMS_lumi(c, iPeriod, iPos)

            c.Update()
            c.RedrawAxis()

            if not os.path.exists(destination + "/" + addCut):
                os.makedirs(destination + "/" + addCut)
            else:
                print "WARNING: directory already exists. Will overwrite existing files..."
            c.SaveAs(destination + "/" + addCut + "/" + h[ihist].GetName() +
                     ".png")

        if same:
            c.cd()

            legend.AddEntry(
                h[ihist], vartitle[interestVar[ihist]][0]
                if len(legtext) == 0 else legtext[ihist], 'l')
            h[ihist].Draw("histsamex0")

    if same:
        legend.SetTextSize(0.03)
        legend.Draw('same')

        CMS_lumi.CMS_lumi(c, iPeriod, iPos)

        c.Update()
        c.RedrawAxis()

        if not os.path.exists(destination + "/" + addCut):
            os.makedirs(destination + "/" + addCut)
        else:
            print "WARNING: directory already exists. Will overwrite existing files..."
        c.SaveAs(destination + "/" + addCut + "/" + h[0].GetName() + ".png")
Ejemplo n.º 2
0
def draw2DHist(h,
               xlabel,
               ylabel,
               output,
               year,
               option="ETextColz",
               x_log=False,
               y_log=False):

    tdr.setTDRStyle()
    GeneralSettings("4.3f")
    gStyle.SetPalette(ROOT.kIsland)
    gStyle.SetPadRightMargin(0.15)

    #Create Canvas
    Canv = TCanvas("Canv" + output, "Canv" + output, 1000, 1000)
    if x_log:
        Canv.SetLogx()
    if y_log:
        Canv.SetLogy()

    h.SetTitle(';' + xlabel + ';' + ylabel)
    h.Draw(option)

    #Throw CMs lumi at it
    cl.CMS_lumi(Canv, 4, 0, year, 'Preliminary', True)

    #Save everything
    savePlots(Canv, output)

    ROOT.SetOwnership(
        Canv, False
    )  #https://root-forum.cern.ch/t/tlatex-crashing-in-pyroot-after-many-uses/21638/4
    return
Ejemplo n.º 3
0
def singlePlot(h, saveplots):
    rt.gStyle.SetLegendFont(42)
    c = rt.TCanvas('mycv' + h[0].GetName(), 'mycv' + h[0].GetName(), 5, 30,
                   W_ref, H_ref)
    SetupCanvas(c, 0)
    legend = rt.TLegend(x0_l, y0_l, x1_l, y1_l)
    # h[0].SetMarkerColor(8)
    # h[0].SetMarkerStyle(1)
    # h[0].SetMarkerSize(1)
    h[0].SetLineColor(8)
    h[0].SetLineWidth(1)

    h[0].SetMaximum(max(h[len(h) - 1].GetMaximum() * 2.0, 1.5))
    h[0].SetMinimum(0.0)
    if len(h) > 2:
        for i in range(len(shortcats)):
            h[0].GetXaxis().SetBinLabel(i + 1, shortcats[i])
    # xAxis = h.GetXaxis()
    # xAxis.SetNdivisions(6,5,0)
    yAxis = h[0].GetYaxis()
    yAxis.SetNdivisions(6, 5, 0)
    yAxis.SetTitleOffset(1)
    yAxis.SetTitleSize(0.05)
    if len(h) > 2:
        legend.AddEntry(h[0], cuttext[0], 'p')

    if len(h) == 2:
        legend.AddEntry(h[0], legtext[0], 'l')

    h[0].Draw('histsamex0')
    CMS_lumi.CMS_lumi(c, iPeriod, iPos)
    print 'lumi'
    for i in range(len(h) - 1):
        h[i + 1].SetMarkerSize(1)
        #h[i+1].SetMarkerStyle(24+i)
        #h[i+1].SetMarkerStyle(1)
        #h[i+1].SetMarkerColor(i+2)
        # legend.AddEntry(h[i+1],cuttext[i+1],'p')
        #h[i+1].Draw("histsamex0")

        h[i + 1].SetLineWidth(1)
        h[i + 1].SetLineColor(i + 2)
        if len(h) == 2: legend.AddEntry(h[i + 1], legtext[i + 1], 'l')
        h[i + 1].Draw("histsamex0")

    c.cd()
    if len(h) > 1: legend.Draw('same')
    else:
        h[0].SetMarkerSize(1)
        h[0].SetMarkerStyle(1)
        h[0].SetMarkerColor(1)

    c.Update()
    c.RedrawAxis()
    if saveplots:
        if not os.path.exists(destination + "/" + addCut):
            os.makedirs(destination + "/" + addCut)
        else:
            print "WARNING: directory already exists. Will overwrite existing files..."
        c.SaveAs(destination + "/" + addCut + "/" + h[0].GetName() + ".png")
Ejemplo n.º 4
0
def plotMaxPunzi(maxpunzi, masses):
    m = array('d', masses)
    g = TGraph(len(masses), m, maxpunzi)
    c2 = TCanvas("c2", "", 800, 800)
    c2.cd()
    c2.SetGridx()
    c2.SetGridy()
    g.GetXaxis().SetTitle('M_{X} (TeV)')
    g.GetYaxis().SetTitle("min cross section")
    g.SetMarkerStyle(22)
    g.SetMarkerSize(3)
    g.SetMarkerColor(kRed - 3)
    g.GetYaxis().SetRangeUser(0., 0.01)

    g.Draw("A*L")
    l1 = TLatex()
    l1.SetNDC()
    l1.SetFillColor(0)
    l1.SetTextAlign(12)
    l1.SetTextFont(42)
    l1.SetTextSize(0.031)
    l1.DrawLatex(0.6, 0.81, "0.8 #times M_{X} < M_{jj} < 1.2 #times M_{X}")
    l1.DrawLatex(0.6, 0.77, "65 GeV < M_{p} < 105 GeV")
    CMS_lumi.CMS_lumi(c2, iPeriod, iPos)
    c2.Update()

    time.sleep(10)
Ejemplo n.º 5
0
    def DrawText(self):
        #redraw axes
        self.c.RedrawAxis()
        # white background
        graphWhite = rt.TGraph(5)
        graphWhite.SetName("white")
        graphWhite.SetTitle("white")
        graphWhite.SetFillColor(rt.kWhite)
        graphWhite.SetFillStyle(1001)
        graphWhite.SetLineColor(rt.kBlack)
        graphWhite.SetLineStyle(1)
        graphWhite.SetLineWidth(3)
        graphWhite.SetPoint(0, self.model.Xmin, self.model.Ymax)
        graphWhite.SetPoint(1, self.model.Xmax, self.model.Ymax)
        graphWhite.SetPoint(2, self.model.Xmax, self.model.Ymax * 0.75)
        graphWhite.SetPoint(3, self.model.Xmin, self.model.Ymax * 0.75)
        #graphWhite.SetPoint(2,self.model.Xmax, self.model.Ymax*0.8)
        #graphWhite.SetPoint(3,self.model.Xmin, self.model.Ymax*0.8)
        graphWhite.SetPoint(4, self.model.Xmin, self.model.Ymax)
        graphWhite.Draw("FSAME")
        graphWhite.Draw("LSAME")
        self.c.graphWhite = graphWhite
        CMS_lumi.writeExtraText = 1
        CMS_lumi.extraText = "Preliminary"
        #CMS_lumi.lumi_13TeV="2.3 fb^{-1}"
        CMS_lumi.lumi_13TeV = "36.2 fb^{-1}"

        CMS_lumi.lumi_sqrtS = "13 TeV"
        iPos = 0
        CMS_lumi.CMS_lumi(self.c, 4, iPos)
        # CMS LABEL
        textCMS = rt.TLatex(0.25, 0.96, "  %s " % (self.preliminary))
        textCMS.SetNDC()
        textCMS.SetTextAlign(13)
        textCMS.SetTextFont(52)
        textCMS.SetTextSize(0.038)
        #textCMS.Draw()
        self.c.textCMS = textCMS
        # MODEL LABEL
        if self.model.extraText:
            textModelLabel = rt.TLatex(0.15, 0.915, "%s" % self.model.label)
        else:
            textModelLabel = rt.TLatex(
                0.15, 0.90, "%s   NLO+NLL exclusion" % self.model.label)
        textModelLabel.SetNDC()
        textModelLabel.SetTextAlign(13)
        textModelLabel.SetTextFont(42)
        textModelLabel.SetTextSize(0.035)
        #textModelLabel.SetTextSize(0.03)
        textModelLabel.Draw()
        self.c.textModelLabel = textModelLabel
        # NLO NLL XSEC
        textNLONLL = rt.TLatex(0.15, 0.8625, "NLO+NLL exclusion")
        textNLONLL.SetNDC()
        textNLONLL.SetTextAlign(13)
        textNLONLL.SetTextFont(42)
        textNLONLL.SetTextSize(0.035)
        if self.model.extraText:
            textNLONLL.Draw()
        self.c.textNLONLL = textNLONLL
Ejemplo n.º 6
0
    def drawRatio(self):
        hs = self.hs.Clone('%s_%s_s' % (self.plotname, self.name))
        hc = self.hc.Clone('%s_%s_c' % (self.plotname, self.name))

        cr = TCanvas('%s_%s_ratio' % (self.plotname, self.name), self.name,
                     self.xoff + 50, self.yoff + 50, 500, 500)
        self.cr = cr

        hs.SetMinimum(0)
        if hs.Integral() > 0:
            hs.Scale(1.0 / hs.Integral())
        if hc.Integral() > 0:
            hc.Scale(1.0 / hc.Integral())
        # --------------------------------------------------
        hratio = hs.Clone('%sratio' % self.name)
        hratio.Divide(hc)

        hratio.SetMarkerColor(kBlack)
        hratio.SetMarkerSize(0.6)
        hratio.SetMinimum(0)
        hratio.SetMaximum(self.ratioymax)

        hratio.GetXaxis().SetTitle(self.xtitle)
        hratio.GetXaxis().SetNdivisions(505)

        hratio.GetYaxis().SetTitle(self.ytitle)
        hratio.GetYaxis().SetNdivisions(505)

        cr.cd()
        cr.SetGridy()
        hratio.Draw('ep')
        CMS_lumi.CMS_lumi(cr, self.iPeriod, self.iPos)
        cr.Update()
        cr.SaveAs('.png')
        self.hratio = hratio
Ejemplo n.º 7
0
def cms_hist_format(hist, histname, draw_method):
    # Set plot style
    tdrstyle.setTDRStyle()
    CMS_lumi.lumi_7TeV = " "
    CMS_lumi.lumi_8TeV = " "
    CMS_lumi.writeExtraText = 1
    CMS_lumi.extraText = "Preliminary"
    W = 800
    H = 600
    iPos = 0
    iPeriod = 4
    if (iPos == 0): CMS_lumi.relPosX = 0.1
    gROOT.SetBatch(True)
    canvas = TCanvas("c_" + histname, "c_" + histname, 50, 50, W, H)
    gStyle.SetOptStat()
    canvas.SetFillColor(0)
    canvas.SetBorderMode(0)
    canvas.SetFrameFillStyle(0)
    canvas.SetFrameBorderMode(0)
    canvas.SetTickx(0)
    canvas.SetTicky(0)
    hist.Draw(draw_method)
    #draw the lumi text on the canvas
    CMS_lumi.CMS_lumi(canvas, iPeriod, iPos)
    canvas.cd()
    canvas.Update()
    canvas.RedrawAxis()
    frame = canvas.GetFrame()
    frame.Draw()
    canvas.Modified()
    canvas.Update()
    canvas.Print(histname + ".pdf", "pdf")
    gROOT.Reset()
Ejemplo n.º 8
0
    def DrawText(self):
        #redraw axes
        self.c.RedrawAxis()
        # white background
        graphWhite = rt.TGraph(5)
        graphWhite.SetName("white")
        graphWhite.SetTitle("white")
        graphWhite.SetFillColor(rt.kWhite)
        graphWhite.SetFillStyle(1001)
        graphWhite.SetLineColor(rt.kBlack)
        graphWhite.SetLineStyle(1)
        graphWhite.SetLineWidth(3)
        graphWhite.SetPoint(0, self.model.Xmin, self.model.Ymax)
        graphWhite.SetPoint(1, self.model.Xmax, self.model.Ymax)
        graphWhite.SetPoint(2, self.model.Xmax, self.model.Ymax * 0.75)
        graphWhite.SetPoint(3, self.model.Xmin, self.model.Ymax * 0.75)
        graphWhite.SetPoint(4, self.model.Xmin, self.model.Ymax)
        graphWhite.Draw("FSAME")
        graphWhite.Draw("LSAME")
        self.c.graphWhite = graphWhite
        CMS_lumi.writeExtraText = 0
        CMS_lumi.extraText = ""
        CMS_lumi.lumi_13TeV = "35.9 fb^{-1}"

        CMS_lumi.lumi_sqrtS = "13 TeV"
        iPos = 0
        CMS_lumi.CMS_lumi(self.c, 4, iPos)
        # CMS LABEL
        textCMS = rt.TLatex(0.25, 0.96, "  %s " % (self.preliminary))
        textCMS.SetNDC()
        textCMS.SetTextAlign(13)
        textCMS.SetTextFont(52)
        textCMS.SetTextSize(0.038)
        textCMS.Draw()
        self.c.textCMS = textCMS
        # MODEL LABEL
        textModelLabel = rt.TLatex(0.18, 0.90,
                                   "%s  NLO+NLL exclusion" % self.model.label)
        textModelLabel.SetNDC()
        textModelLabel.SetTextAlign(13)
        textModelLabel.SetTextFont(42)
        textModelLabel.SetTextSize(0.035)
        textModelLabel.Draw()
        self.c.textModelLabel = textModelLabel
        # NLO NLL XSEC
        textNLONLL = rt.TLatex(0.16, 0.32, "NLO-NLL exclusion")
        textNLONLL.SetNDC()
        textNLONLL.SetTextAlign(13)
        textNLONLL.SetTextFont(42)
        textNLONLL.SetTextSize(0.035)
        textNLONLL.Draw()
        #textChi= rt.TLatex(0.16,0.2,"m_{{#tilde{#chi}^{\pm}_1}/{#tilde{#chi}^{0}_2}}")
        textChi = rt.TLatex(
            0.16, 0.70,
            "m_{#tilde{#chi}_{1}^{#pm}/#tilde{#chi}_{2}^{0}}=0.5 (m_{#tilde{#chi}_{1}^{0}}+ m_{#tilde{g}} )"
        )
        textChi.SetNDC()
        textChi.SetTextAlign(13)
        textChi.SetTextFont(42)
        textChi.SetTextSize(0.035)
Ejemplo n.º 9
0
def singlePlot(h,name,legtext=[]):
    rt.gStyle.SetLegendFont(42)

    c = rt.TCanvas('mycv','mycv',5,30,W_ref,H_ref)
    SetupCanvas(c, 0)
    legend = rt.TLegend(x0_l,y0_l+0.1,x1_l, y1_l )

    for ihist in h:
        h[ihist].GetYaxis().SetRangeUser(0,30000)
        yAxis = h[ihist].GetYaxis()
        yAxis.SetNdivisions(6,5,0)
        yAxis.SetTitleOffset(1)
        yAxis.SetTitleSize(0.05)


        c.cd()

        legend.AddEntry(h[ihist],ihist,'l')
        h[ihist].Draw("histsamex0")


        legend.SetTextSize(0.03)
        legend.Draw('same')

        CMS_lumi.CMS_lumi(c, iPeriod, iPos)

        c.Update()
        c.RedrawAxis()

    if not os.path.exists(destination+ "/"+name):
        os.makedirs(destination+ "/"+name)
    else:
        print "WARNING: directory already exists. Will overwrite existing files..."
    c.SaveAs(destination+ "/"+name+"/cat.pdf")
Ejemplo n.º 10
0
def doPlots():

    num, den = makeHistos()
    turnOn = doRatio(num, den, "b")

    #function = ROOT.TF1("turnonPt","1-(0.5-0.5*erf( (x-[0])/[1]))*([3])-[2] ",functionMin,functionMax)
    #    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*[3]-[2] ",functionMin,functionMax)
    function = ROOT.TF1("turnonPt",
                        "1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*[3]-[2] ",
                        functionMin, functionMax)
    #    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/([1])*(x-[0]>[5]) + ((x-[0])/([1]+[4]) + [5]*(1/[1]+[4]-1/[1]))*(x-[0]<=[5]) ))*[3]-[2] ",functionMin,functionMax)
    #    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])*(1+[4]*x**2)/([1]+[5]*x**2)))*([3])-[2] ",functionMin,functionMax)
    #    function = ROOT.TF1("turnonPt","(0.5+0.5*TMath::Erf( (x-[0])*(x-[0]>[5])/[1] + (x-[0])*(x-[0]<[5])/[2] + [5]*(1/[1]-1/[2])*(x-[0]<[5]) ))*[4]+[3] ",functionMin,functionMax)
    #    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*([3])-(0.5-0.5*TMath::Erf( (x-[4])/[5]))*([6])-[2]  ",functionMin,functionMax)

    #    function = ROOT.TF1("turnonPt","TMath::Erf( (x-[0])/[1]*(([4]+[5]*x)) )*[2]-[3]",functionMin,functionMax)

    print "Using:", parametersTurnOn_funct
    function.SetParameters(*parametersTurnOn_funct)
    #    function.SetParLimits(1,0,100)
    function.SetParLimits(2, 0, 1)
    function.SetParLimits(3, -1, 2)
    #    function.SetParLimits(4,0,1)
    #    function.SetParLimits(5,0,1)
    function.SetLineWidth(2)

    TurnOn_funct = function.Clone("TurnOn_funct")

    c1 = ROOT.TCanvas("c1", "", 700, 700)

    TurnOn_funct, TurnOn_functUp, TurnOn_functDown = confidenceInterval(
        turnOn, TurnOn_funct)

    turnOn.SetMaximum(maxTurnOn_funct)
    turnOn.SetMinimum(minTurnOn_funct)
    turnOn.GetXaxis().SetTitle(title)
    turnOn.GetYaxis().SetTitle("Efficiency")

    turnOn.Draw("AP")
    TurnOn_funct.Draw("same")
    TurnOn_functUp.Draw("same")
    TurnOn_functDown.Draw("same")

    addInfo = getPavetext()
    #    addInfo.AddText("p_{T} > 400 GeV,")
    addInfo.AddText("p_{T} > 350 GeV, |#eta| < 2.5")
    addInfo.AddText("M_{SD} > 40 GeV")
    addInfo.Draw("same")

    #c1.SaveAs("turnOn_"+ped+".C")
    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.SaveAs("turnOn_" + ped + "_" + runName + fitName + ".pdf")
    #c1.SaveAs("turnOn_"+ped+".root")
    f.write(('TF1* %s = new TF1("%s","' % (ped, ped) +
             str(TurnOn_funct.GetExpFormula("P")) + '");\n'))
    f.write(('TF1* %sUp = new TF1("%sUp","' % (ped, ped) +
             str(TurnOn_functUp.GetExpFormula("P")) + '");\n'))
    f.write(('TF1* %sDown = new TF1("%sDown","' % (ped, ped) +
             str(TurnOn_functDown.GetExpFormula("P")) + '");\n'))
Ejemplo n.º 11
0
 def stampPlot(self, canvas, lumiStr, labelText, cmsLocation, showLumi):
     iPeriod = 0
     if showLumi:
         iPeriod = 4
     iPos = 10
     CMS_lumi.extraText = labelText
     CMS_lumi.lumi_13TeV = lumiStr + " fb^{-1}"
     CMS_lumi.CMS_lumi(canvas, iPeriod, iPos)
Ejemplo n.º 12
0
def addPlotTitle(canvas):
    """
    Add CMS-style plot header
    """
    CMS_lumi.writeExtraText = True
    CMS_lumi.lumi_13TeV = ""
    CMS_lumi.lumi_sqrtS = "13 TeV"
    CMS_lumi.CMS_lumi(canvas, 4, 0)
Ejemplo n.º 13
0
def SaveRatio(hSS, hOS, process, output):

    idata = process.split('_')[0]
    suffix = process.split('_ss_')[-1]

    #print "hSS : " , hSS
    #print "hOS : " , hOS

    name = '%s_%s' % (idata, suffix)
    hratio = hSS.Clone('hratio_%s' % name)
    hratio.Divide(hOS)

    hratio.SetMarkerStyle(20)
    hratio.SetMarkerSize(1.25)
    hratio.SetFillColor(418)
    hratio.SetFillStyle(1001)
    hratio.SetLineColor(1)
    hratio.SetLineStyle(1)
    hratio.SetLineWidth(2)

    c1 = TCanvas('hratio_%s' % name, 'hratio_%s' % name, 800, 600)
    if suffix.split('_')[-1] == '2d':
        TGaxis.SetMaxDigits(2)
        #fout = TFile.Open( 'plots/%s/Object_studies/Ratio_%s_%s_%s.root' %(_token,_token,_isample,_ivar), 'RECREATE' )
        c1.SetRightMargin(0.2)
        hratio.SetAxisRange(0.00001, 0.01, "Z")
        hratio.SetTitle('')
        hratio.GetZaxis().SetTitle('N_SS/N_OS (%s)' % idata)
        hratio.GetXaxis().SetTitle('Lepton1 eta')
        hratio.GetYaxis().SetTitle('Lepton2 eta')
        hratio.Draw('colztextE')
    else:
        hratio.SetTitle('')
        hratio.GetYaxis().SetTitle('N_SS/N_OS Ratio (%s)' % idata)
        hratio.Draw('PE')

    c1.cd()
    if '2016' in output: CMS_lumi.lumi_13TeV = "35.87 fb^{-1}"
    elif '2017' in output: CMS_lumi.lumi_13TeV = "41.53 fb^{-1}"
    elif '2018' in output: CMS_lumi.lumi_13TeV = "59.74 fb^{-1}"
    CMS_lumi.writeExtraText = 1
    CMS_lumi.extraText = "Preliminary"
    CMS_lumi.CMS_lumi(c1, 4, 0)
    gPad.RedrawAxis()

    #c1.cd()
    #if '2016' in _token:
    #    drawCMS("35.87", "Object Study")
    #elif '2017' in _token:
    #    drawCMS("41.53", "Object Study")
    #elif '2018' in _token:
    #    drawCMS("59.74", "Object Study")

    c1.Print('%s/Ratio_%s.png' % (output, name))
    #c1.Print( '%s/Ratio_%s.pdf' %(output,name) )
    TGaxis.SetMaxDigits(5)
Ejemplo n.º 14
0
def makeProfile(histo2DName,
                etaRegion,
                inputfile,
                output_name,
                suff,
                ymin,
                ymax,
                yTitle,
                pfxRange,
                pfxMin,
                pfxMax,
                zoomY,
                yRangeMin,
                yRangeMax,
                xRangeMin,
                xRangeMax,
                xTitle="#eta",
                xbins=100,
                xmin=-4.,
                xmax=4.,
                saveCanvas=False):

    histo_vsEta = TH2D()
    inputfile.GetObject(str(histo2DName) + str(etaRegion), histo_vsEta)

    histo_vsEta_profile = TProfile(
        str(histo2DName) + str(etaRegion) + "_profile",
        str(histo2DName) + str(etaRegion) + "_profile", xbins, xmin, xmax,
        ymin, ymax)

    if pfxRange:
        histo_vsEta_profile = histo_vsEta.ProfileX("_pfx", pfxMin, pfxMax)
    else:
        histo_vsEta_profile = histo_vsEta.ProfileX()

    histo_vsEta_profile.GetXaxis().SetTitle(xTitle)
    histo_vsEta_profile.GetYaxis().SetTitle(yTitle)

    if zoomY:
        histo_vsEta_profile.GetYaxis().SetRangeUser(yRangeMin, yRangeMax)

    histo_vsEta_profile.GetXaxis().SetRangeUser(xRangeMin, xRangeMax)

    if saveCanvas:
        c = TCanvas(
            str(histo2DName) + str(etaRegion) + "_profile",
            str(histo2DName) + str(etaRegion) + "_profile")
        c.cd()
        CMS_lumi.CMS_lumi(c, 4, 33)
        histo_vsEta_profile.Draw()
        c.SaveAs(
            str(output_name) + str(suff) + "/" + str(histo2DName) +
            str(etaRegion) + "_profile" + str(sys.argv[4]) + ".png")

    histo_vsEta_profile.Write()
Ejemplo n.º 15
0
def makeSFplot_nosyst(info, name, title, ymin=0.6, ymax=1.4):
    c = TCanvas("c_" + name, "", 800, 600)
    c.cd()

    CMS_lumi.lumi_8TeV = "19.7 fb^{-1}"
    CMS_lumi.writeExtraText = 0
    CMS_lumi.extraText = " Preliminary"
    CMS_lumi.cmsText = ""

    iPos = 0  #11
    if (iPos == 0): CMS_lumi.relPosX = 0.12
    iPeriod = 2
    H_ref = 600
    W_ref = 800
    W = W_ref
    H = H_ref

    # references for T, B, L, R
    T = 0.08 * H_ref
    B = 0.15 * H_ref
    L = 0.14 * W_ref
    R = 0.06 * W_ref

    c.SetLeftMargin(L / W)
    c.SetRightMargin(R / W)
    c.SetTopMargin(T / H)
    c.SetBottomMargin(B / H)

    g_stat = TGraphErrors()

    for i, p in enumerate(info):
        x = p[0] + 0.5 * (p[1] - p[0])
        g_stat.SetPoint(i, x, p[2])
        g_stat.SetPointError(i, 0.5 * (p[1] - p[0]), p[3])

    g_stat.GetXaxis().SetTitle("p_{T} (CA8 jet) (GeV)")
    g_stat.GetXaxis().SetTitleOffset(1.1)
    g_stat.GetXaxis().SetRangeUser(100, 1000)
    g_stat.GetYaxis().SetTitle(title)
    g_stat.GetYaxis().SetTitleOffset(1.05)
    g_stat.GetYaxis().SetRangeUser(ymin, ymax)
    g_stat.SetLineColor(kBlack)
    g_stat.Draw("aZpsame")

    leg = TLegend(0.55, 0.25, 0.8, 0.4, "")
    leg.SetFillStyle(0)
    leg.SetBorderSize(0)
    leg.AddEntry(g_stat, "stat only", "lep")
    leg.Draw()

    c.cd()
    CMS_lumi.CMS_lumi(c, iPeriod, iPos)

    c.SaveAs("SF_%s_Thesis.pdf" % (name))
Ejemplo n.º 16
0
    def PadRedraw(self, pad, kw):
        addlatex = kw.get('addlatex', ())
        addline = kw.get('addline', ())
        norm = kw.get('norm', None)
        pad.cd()
        pad.Update()
        if hasattr(pad, "ratio"):
            addlatex = kw.get('Ratioaddlatex', ())
            addline = kw.get('Ratioaddline', ())
            norm = "No"
            pad.SetLogx(kw.get("RatioLogx", False))
            pad.SetLogy(kw.get("RatioLogy", False))
            pad.SetTickx(kw.get("RatioTickx", False))
            pad.SetTicky(kw.get("RatioTicky", False))
            pad.SetGridx(kw.get("RatioGridx", False))
            pad.SetGridy(kw.get("RatioGridy", False))
        else:
            pad.SetLogx(kw.get("Logx", False))
            try:
                pad.SetLogy(kw.get("Logy", False))
            except:
                pad.SetLogy(False)
            pad.SetTickx(kw.get("Tickx", False))
            pad.SetTicky(kw.get("Ticky", False))
            pad.SetGridx(kw.get("Gridx", False))
            pad.SetGridy(kw.get("Gridy", False))

        if norm != "No":
            if norm is None or norm == "None" or norm == "Unit":
                CMS_lumi.CMS_lumi(pad, 23, 11, self.lumi)
            else:
                CMS_lumi.CMS_lumi(pad, 13, 11, self.lumi)

        if len(addlatex) != 0:
            self.DrawTLatex(addlatex)
        if len(addline) != 0:
            self.DrawTLine(pad, addline)

        pad.Update()
        pad.Modified()
        pad.RedrawAxis()
Ejemplo n.º 17
0
    def plot_1d_eff(savename,
                    graphs,
                    labels=['Data', 'Simulation'],
                    colors=colors,
                    xlabel='',
                    ylabel='Efficiency',
                    xRange=[],
                    additional_text=[]):
        ng = len(graphs)
        mg = ROOT.TMultiGraph()
        for gi in range(ng):
            graphs[gi].SetLineColor(colors[gi])
            graphs[gi].SetMarkerColor(colors[gi])
            mg.Add(graphs[gi])

        canvas = ROOT.TCanvas(savename, savename, 800, 800)
        mg.Draw('AP0')
        mg.GetXaxis().SetTitle(xlabel)
        if xRange:
            mg.GetXaxis().SetRangeUser(*xRange)
        mg.GetYaxis().SetTitle(ylabel)
        mg.GetYaxis().SetRangeUser(0.8, 1.10)
        legend = ROOT.TLegend(0.5, 0.70, 0.92, 0.92)
        legend.SetTextFont(42)
        legend.SetBorderSize(0)
        legend.SetFillColor(0)
        for gi in range(ng):
            legend.AddEntry(graphs[gi], labels[gi], 'l')
        legend.SetHeader('{} / {}'.format(num, denom))
        legend.Draw()

        if additional_text:
            nother = len(additional_text)
            dims = [0.18, 0.84 - nother * 0.04 - 0.02, 0.35, 0.84]
            text = ROOT.TPaveText(*dims + ['NB NDC'])
            text.SetTextFont(42)
            text.SetBorderSize(0)
            text.SetFillColor(0)
            text.SetTextAlign(11)
            text.SetTextSize(0.03)
            for rtext in additional_text:
                text.AddText(rtext)
            text.Draw()

        CMS_lumi.cmsText = 'CMS'
        CMS_lumi.writeExtraText = True
        CMS_lumi.extraText = 'Preliminary'
        CMS_lumi.lumi_13TeV = "%0.1f fb^{-1}" % (lumi)
        CMS_lumi.CMS_lumi(canvas, 4, 11)

        canvas.Print('{}.png'.format(savename))
        canvas.Print('{}.pdf'.format(savename))
        canvas.Print('{}.root'.format(savename))
Ejemplo n.º 18
0
def setTDRStyle(canvas, luminosity, energy, printCMS):
    tdrstyle.setTDRStyle() 
    if printCMS == "right" or printCMS == "left":
        if energy == 13:
            CMS_lumi.lumi_13TeV = "%s fb^{-1}" % luminosity
            if printCMS == "left":
                iPos = 11
            else:
                iPos = 13
            CMS_lumi.writeExtraText = 1
            CMS_lumi.extraText = "Preliminary"
            CMS_lumi.CMS_lumi(canvas, 4, iPos)
Ejemplo n.º 19
0
def doPlots():

    num,den =  makeHistos()
    turnOn = doRatio(num,den,"b")

    #function = ROOT.TF1("turnonPt","1-(0.5-0.5*erf( (x-[0])/[1]))*([3])-[2] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*[3]-[2] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*[3]-[2] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/([1])*(x-[0]>[5]) + ((x-[0])/([1]+[4]) + [5]*(1/[1]+[4]-1/[1]))*(x-[0]<=[5]) ))*[3]-[2] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])*(1+[4]*x**2)/([1]+[5]*x**2)))*([3])-[2] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","(0.5+0.5*TMath::Erf( (x-[0])*(x-[0]>[5])/[1] + (x-[0])*(x-[0]<[5])/[2] + [5]*(1/[1]-1/[2])*(x-[0]<[5]) ))*[4]+[3] ",functionMin,functionMax)
#    function = ROOT.TF1("turnonPt","1-(0.5-0.5*TMath::Erf( (x-[0])/[1]))*([3])-(0.5-0.5*TMath::Erf( (x-[4])/[5]))*([6])-[2]  ",functionMin,functionMax)

#    function = ROOT.TF1("turnonPt","TMath::Erf( (x-[0])/[1]*(([4]+[5]*x)) )*[2]-[3]",functionMin,functionMax)

#    print "Using:",parametersTurnOn_funct
#    function.SetParameters(*parametersTurnOn_funct)
#    function.SetParLimits(1,0,100)
#    function.SetParLimits(2,0,1)
#    function.SetParLimits(3,-1,2)
#    function.SetParLimits(4,0,1)
#    function.SetParLimits(5,0,1)
#    function.SetLineWidth(2)


#    TurnOn_funct = function.Clone("TurnOn_funct")

    c1 = ROOT.TCanvas("c1","",800,600)
    c1.cd()
#    TurnOn_funct,TurnOn_functUp,TurnOn_functDown = confidenceInterval(turnOn,TurnOn_funct)
#
    turnOn.SetMaximum(maxTurnOn_funct)
    turnOn.SetMinimum(minTurnOn_funct)
    turnOn.GetXaxis().SetTitle(xtitle)
    turnOn.GetYaxis().SetTitle(ytitle)
#    turnOn.GetZaxis().SetTitle("Efficiency")
#    turnOn.GetZaxis().SetRangeUser(0.65,1)

#    turnOn.Draw("AP")
    turnOn.Draw("COLZ")
#    TurnOn_funct.Draw("same")
#    TurnOn_functUp.Draw("same")
#    TurnOn_functDown.Draw("same")

    addInfo = getPavetext()
#    addInfo.AddText("p_{T} > 400 GeV,")
    addInfo.AddText("p_{T} > 400 GeV, |#eta| < 2.5")
    addInfo.AddText("M_{SD} > 40 GeV")
    addInfo.Draw("same")

    #c1.SaveAs("turnOn_"+ped+".C")
    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.SaveAs("turnOn2D_"+ped+"_"+runName+fitName+".pdf")
Ejemplo n.º 20
0
 def draw(self, save=False):
     self.c.cd()
     if self.hs.Integral() > 0:
         self.hs.DrawNormalized('hist')
         if self.hc.Integral() > 0:
             self.hc.DrawNormalized('histsame')
     if save:
         CMS_lumi.CMS_lumi(self.c, self.iPeriod, self.iPos)
     self.c.Update()
     if save:
         if self.hs.Integral() > 0:
             self.c.SaveAs('.png')
Ejemplo n.º 21
0
def printLumiOut(canvas, lumitext="13 TeV"):
    #change the CMS_lumi variables (see CMS_lumi.py)
    CMS_lumi.writeExtraText = 0
    CMS_lumi.extraText = ""
    CMS_lumi.lumi_sqrtS = lumitext  # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)

    iPos = 0  # outside frame left

    if (iPos == 0): CMS_lumi.relPosX = 0.12
    iPeriod = 4

    CMS_lumi.CMS_lumi(canvas, iPeriod, iPos)
Ejemplo n.º 22
0
def plotSignificance(mass, model, cat="all"):

    xcentral = array("d")  # masses
    ycentral = array("d")  # limits
    xerr = array("d")

    for m in masses:

        if cat == "all":
            #fitfile = "/afs/cern.ch/work/l/lviliani/LatinosFramework13TeV_clean/CMSSW_7_6_3/src/LatinoAnalysis/ShapeAnalysis/PlotsConfigurations/Configurations/EXO/WWlvlv_VBF/combineLSF/Significance.ICHEP2016.mH"+m+"_"+model+".txt"
            fitfile = "/afs/cern.ch/work/l/lviliani/LatinosFramework13TeV_clean/CMSSW_7_6_3/src/LatinoAnalysis/ShapeAnalysis/PlotsConfigurations/Configurations/EXO/WWlvlv_VBF/combineFrozen_newbins/Significance.ICHEP2016.mH" + m + "_" + model + ".txt"
            CMS_lumi.extraText2 = "0+1+2 jets "
        else:
            #fitfile = "/afs/cern.ch/work/l/lviliani/LatinosFramework13TeV_clean/CMSSW_7_6_3/src/LatinoAnalysis/ShapeAnalysis/PlotsConfigurations/Configurations/EXO/WWlvlv_VBF/combineLSF/Significance."+cat+".ICHEP2016.mH"+m+"_"+model+".txt"
            fitfile = "/afs/cern.ch/work/l/lviliani/LatinosFramework13TeV_clean/CMSSW_7_6_3/src/LatinoAnalysis/ShapeAnalysis/PlotsConfigurations/Configurations/EXO/WWlvlv_VBF/combineFrozen_newbins/Significance." + cat + ".ICHEP2016.mH" + m + "_" + model + ".txt"

            CMS_lumi.extraText2 = cat.replace("jet", " jet ")

        fitFile = open(
            fitfile
        )  #"/afs/cern.ch/work/l/lviliani/LatinosFramework13TeV_clean/CMSSW_7_6_3/src/LatinoAnalysis/ShapeAnalysis/PlotsConfigurations/Configurations/EXO/WWlvlv_VBF/combine/Limit.Moriond2016.2jet.mH"+m+".txt")
        sig = extract(fitFile)

        xcentral.append(float(m))
        xerr.append(0)
        ycentral.append(float(sig))

    c1 = makeCanvas("c1")

    CMS_lumi.extraText2 += model.replace("c", "\nc'= ").replace(
        "0",
        "0.").replace("brn",
                      " BR_{new} = ").replace("0.0.",
                                              "0.0").replace("10.", "1.0")

    graphcentral_mu = TGraph(len(xcentral), xcentral, ycentral)
    graphcentral_mu.SetLineStyle(1)
    graphcentral_mu.SetLineColor(kBlue)
    graphcentral_mu.SetMarkerStyle(20)
    graphcentral_mu.SetMarkerColor(kBlue)

    graphcentral_mu.SetTitle("")
    graphcentral_mu.GetYaxis().SetTitle("Significance (standard deviations)")
    graphcentral_mu.GetXaxis().SetTitle("M_{X} [GeV]")
    graphcentral_mu.GetXaxis().SetRangeUser(200, 1000)
    graphcentral_mu.GetYaxis().SetRangeUser(0, 5)

    graphcentral_mu.Draw("ALP")
    CMS_lumi.CMS_lumi(c1, 4, iPos)
    gPad.RedrawAxis()

    a = raw_input()
Ejemplo n.º 23
0
def formatGraph(c, mg, label, bin1, bin2):
    mg.SetMinimum(0.)
    mg.SetMaximum(1.2)
    mg.GetXaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetTitleOffset(0.95)
    mg.GetXaxis().SetLabelSize(0.05)
    mg.GetYaxis().SetTitleSize(0.06)
    mg.GetYaxis().SetLabelSize(0.05)
    mg.GetXaxis().SetTitle(label)
    mg.GetYaxis().SetTitle("Efficiency")
    mg.GetXaxis().SetRangeUser(bin1, bin2)
    mg.GetYaxis().SetNdivisions(408)
    CMS_lumi.CMS_lumi(c, iPeriod, iPos)
    c.Update()
Ejemplo n.º 24
0
def adjustSettings_CMS_lumi():

    ## dummy function to be called before using any other fucntion calling CMS_lumi
    ## for some reason, the settings of the very first plot are screwed up.
    ## To fix this issue, it is enough to call it to a dummy plot
    dummy = ROOT.TH1D("dummy","",10,0,10)
    for i in range(1,1+dummy.GetNbinsX()):
        dummy.SetBinContent(i,i)
    dummy.GetXaxis().SetTitle("x axis")
    dummy.GetYaxis().SetTitle("y axis")
    cdummy = ROOT.TCanvas("cdummy","",600,600)
    dummy.Draw("HE")
    CMS_lumi(cdummy,"",True,False)
    setTDRStyle()        
Ejemplo n.º 25
0
def plotFratios(resList, isClosure=False):

    nbins = len(resList)

    if not isClosure:
        hist = TH1F('hRatios', 'F-Ratios', nbins, 0, nbins)
    else:
        hist = TH1F('hClosure', 'MC/Fit ratios', nbins, 0, nbins)

    for i, (bin, val, err) in enumerate(resList):
        #print bin, val
        #binName = bin[:bin.find("_NJ")]
        binName = bin
        hist.GetXaxis().SetBinLabel(i + 1, decryptBinName(binName))
        hist.SetBinContent(i + 1, val)
        hist.SetBinError(i + 1, err)

    _hStore[hist.GetName()] = hist
    hist.SetStats(0)

    canv = TCanvas(hist.GetName(), hist.GetTitle(), cwidth, cheigth)

    # style
    hist.SetMarkerStyle(20)
    hist.Draw('E1p')
    hist.GetYaxis().SetTitleOffset(1.4)

    if not isClosure:
        hist.GetYaxis().SetTitle("F_{sel-to-anti} QCD")

        #hist.GetYaxis().SetRangeUser(0.,0.8)
    else:
        hist.GetYaxis().SetTitle("F_{fit-to-mc} QCD_{selected}")
        #hist.GetYaxis().SetRangeUser(0.4,1.3)

        # unity line
        line = TLine(0, 1, hist.GetNbinsX(), 1)
        line.SetLineStyle(2)
        line.Draw('same')
        SetOwnership(line, 0)

    # Draw CMS Lumi
    CMS_lumi.CMS_lumi(canv, 4, iPos)

    gPad.Update()

    _canvStore[canv.GetName()] = canv

    return hist
Ejemplo n.º 26
0
def ratioOnly(ratio_h, thred, name):
    c = r.TCanvas(name, name, 800, 800)
    ratio = ratio_h.Clone(name)
    #    ratio = ratio_h.DrawCopy(name)
    r.gPad.SetGridx()
    r.gPad.SetGridy()

    ratio.SetTitle("")
    ratio.SetMarkerStyle(20)
    ratio.SetMarkerSize(1.1)
    ratio.GetYaxis().SetTitle("Correction")
    ratio.GetYaxis().SetTitleSize(35)
    ratio.GetYaxis().SetTitleFont(43)
    ratio.GetYaxis().SetTitleOffset(1.1)
    ratio.GetYaxis().SetLabelFont(43)
    ratio.GetYaxis().SetLabelSize(30)
    ratio.GetXaxis().SetTitle("#Delta R (bb)^{ave}")
    ratio.GetXaxis().SetTitleOffset(1.0)
    ratio.GetXaxis().SetTitleSize(35)
    ratio.GetXaxis().SetTitleFont(43)
    ratio.GetXaxis().SetLabelFont(43)
    ratio.GetXaxis().SetLabelSize(30)

    fitf = r.TF1(name + "_f", "[0]", thred, 5)
    #    fitf.SetLineColor(r.kBlack)
    fitf.SetLineWidth(2)
    #    res = ratio.Fit(fitf, "R S")
    ratio.GetYaxis().SetRangeUser(0, 2)
    ratio.Draw("E0")

    leg = r.TLegend(0.6, 0.79, 0.89, 0.89)
    leg.AddEntry(ratio, "Measured")
    leg.AddEntry(fitf, "Flattened")
    #    text = "#splitline{Flatterning(95% CL)}{#chi^{2} = " + "{:.2f}".format(fitf.GetChisquare())  + " }"
    #    leg.AddEntry(interval, text)
    leg.SetBorderSize(0)
    leg.Draw("same")

    line = r.TLine(0, 1, 5, 1)
    line.SetLineWidth(2)
    line.Draw("same")
    SetOwnership(line, 0)

    CMS_lumi.CMS_lumi(c, iPeriod, iPos)
    c.cd()
    c.Update()
    c.SaveAs(outdir + "/" + name + "_Fit.pdf")
    return c
Ejemplo n.º 27
0
def DrawHist(hist, xlabel, ylabel, legendNames, destination, year, ylog=False):
    GeneralSettings()

    #Create Canvas
    Canv = TCanvas("Canv" + destination, "Canv" + destination, 1000, 1000)

    tdr.setTDRStyle()

    #Set Histogram Styles
    for h in hist:
        h.SetLineColor(TColor.GetColor(GetHistColor(hist.index(h))))
    title = " ;" + xlabel + " ; " + ylabel + " / " + str(
        hist[0].GetBinWidth(1)) + " GeV"
    hist[0].SetTitle(title)

    OverallMax = GetOverallMaximum(hist)
    OverallMin = GetOverallMinimum(hist)

    if ylog:
        Canv.SetLogy()
        hist[0].GetYaxis().SetRangeUser(0.3 * OverallMin, 30 * OverallMax)
    else:
        hist[0].GetYaxis().SetRangeUser(0.7 * OverallMin, 1.3 * OverallMax)

    #Start Drawing
    for h in hist:
        if (hist.index(h) == 0):
            h.Draw("HIST")
        else:
            h.Draw("HISTSAME")
    #Create Legend
    if legendNames:
        legend = TLegend(0.7, .7, .9, .9)
        for h, n in zip(hist, legendNames):
            legend.AddEntry(h, n)
        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        legend.Draw()

    #CMS lumi
    cl.CMS_lumi(Canv, 4, 11, year, 'Simulation', False)

    #Save everything
    savePlots(Canv, destination)
Ejemplo n.º 28
0
def singlePlot(h,var,name,legtext=[]):
    rt.gStyle.SetLegendFont(42)

    c = rt.TCanvas('mycv'+h[0].GetName(),'mycv'+h[0].GetName(),5,30,W_ref,H_ref)
    SetupCanvas(c, 0)
    legend = rt.TLegend(x0_l-0.2,y0_l+0.1,x1_l-0.2, y1_l )

    for ihist in range(len(h)):
        #h[ihist].GetYaxis().SetRangeUser(0,0.3)
        yAxis = h[ihist].GetYaxis()
        xAxis = h[ihist].GetXaxis()
        yAxis.SetNdivisions(6,5,0)
        yAxis.SetTitleOffset(1.3)
        yAxis.SetTitleSize(0.05)
        yAxis.SetLabelSize(0.05)
        yAxis.SetTitle("Normalized events")
        xAxis.SetTitle(vartitle[var][0])

        c.cd()

        legend.AddEntry(h[ihist],vartitle[var][0] if len(legtext)==0 else legtext[ihist],'l')
        h[ihist].Draw("histsamex0")


        legend.SetTextSize(0.05)
        legend.Draw('same')

        CMS_lumi.CMS_lumi(c, iPeriod, iPos)

        c.Update()
        c.RedrawAxis()

    if not os.path.exists(destination+ "/"+name):
        os.makedirs(destination+ "/"+name)
    else:
        print "WARNING: directory already exists. Will overwrite existing files..."
    c.SaveAs(destination+ "/"+name+"/"+h[0].GetName()+".pdf")
    if save_root:
        fout = rt.TFile(destination+ "/"+name+"/"+h[0].GetName()+".root","UPDATE")
        for ih in h:
            ih.Write()
def singlePlot(h, name, axistext=[]):

    rt.gStyle.SetPalette(55)
    c = rt.TCanvas('mycv' + h.GetName(), 'mycv' + h.GetName(), 5, 30, W_ref,
                   H_ref)
    SetupCanvas(c, 0)

    #h[ihist].GetYaxis().SetRangeUser(0,0.3)
    yAxis = h.GetYaxis()
    xAxis = h.GetXaxis()
    xAxis.SetTitle(axistext[0])
    yAxis.SetNdivisions(6, 5, 0)
    yAxis.SetTitle(axistext[1])
    xAxis.SetNdivisions(6, 5, 0)

    yAxis.SetTitleOffset(1)
    yAxis.SetTitleSize(0.05)

    c.cd()
    pt = rt.TLatex(0.4, 0.2,
                   ' Correlation: ' + str(round(h.GetCorrelationFactor(), 2)))
    h.SetMarkerColor(rt.TColor.GetColor(histFillColor[1]))
    h.Draw("histsamex0colz")
    pt.Draw("same")
    c.SetLogz()
    #c.SetLogy()

    CMS_lumi.CMS_lumi(c, iPeriod, iPos)

    c.Update()
    c.RedrawAxis()
    if not os.path.exists(destination + "/" + name):
        os.makedirs(destination + "/" + name)
    else:
        print "WARNING: directory already exists. Will overwrite existing files..."
    c.SaveAs(destination + "/" + name + "/" + h.GetName() + ".pdf")
    if save_root:
        fout = rt.TFile(destination + "/" + name + "/" + h.GetName() + ".root",
                        "UPDATE")
        h.SetName(var[0] + '_' + var[1])
        h.Write()
Ejemplo n.º 30
0
 def _setStyle(self,
               pad,
               position=11,
               preliminary=True,
               period_int=4,
               simulation=False):
     '''Set style for plots based on the CMS TDR style guidelines.
        https://twiki.cern.ch/twiki/bin/view/CMS/Internal/PubGuidelines#Figures_and_tables
        https://ghm.web.cern.ch/ghm/plots/'''
     # set period (used in CMS_lumi)
     # period : sqrts
     # 1 : 7, 2 : 8, 3 : 7+8, 4 : 13, ... 7 : 7+8+13
     # set position
     # 11: upper left, 33 upper right
     CMS_lumi.cmsText = 'CMS'
     CMS_lumi.writeExtraText = preliminary
     CMS_lumi.extraText = "Simulation Preliminary" if simulation else 'Preliminary'
     CMS_lumi.lumi_13TeV = "%0.1f fb^{-1}" % (self.intLumi / 1000.)
     if self.intLumi < 1000:
         CMS_lumi.lumi_13TeV = "%0.1f pb^{-1}" % (self.intLumi)
     CMS_lumi.CMS_lumi(pad, period_int, position)