コード例 #1
0
        c.SetBottomMargin(B / H)
        c.SetTickx(0)
        c.SetTicky(0)
        c.Draw()
        c.cd()

        pad1 = TPad("zxc_p1", "zxc_p1", 0, padRatio - padOverlap, 1, 1)
        pad2 = TPad("qwe_p2", "qwe_p2", 0, 0, 1, padRatio + padOverlap)
        pad1.SetLeftMargin(L / W)
        pad1.SetRightMargin(R / W)
        pad1.SetTopMargin(T / H / (1 - padRatio + padOverlap))
        pad1.SetBottomMargin(
            (padOverlap + padGap) / (1 - padRatio + padOverlap))
        pad1.SetFillColor(0)
        pad1.SetBorderMode(0)
        pad1.SetFrameFillStyle(0)
        pad1.SetFrameBorderMode(0)
        pad1.SetTickx(0)
        pad1.SetTicky(0)

        pad2.SetLeftMargin(L / W)
        pad2.SetRightMargin(R / W)
        pad2.SetTopMargin((padOverlap) / (padRatio + padOverlap))
        pad2.SetBottomMargin(B / H / (padRatio + padOverlap))
        pad2.SetFillColor(0)
        pad2.SetFillStyle(4000)
        pad2.SetBorderMode(0)
        pad2.SetFrameFillStyle(0)
        pad2.SetFrameBorderMode(0)
        pad2.SetTickx(0)
        pad2.SetTicky(0)
コード例 #2
0
			rm = c.GetRightMargin()
			to = c.GetTopMargin()
			x1 = p.GetXaxis().GetXmin()
			yf = p.GetYaxis().GetXmin()
			x2 = p.GetXaxis().GetXmax()
			y2 = p.GetYaxis().GetXmax()

			Xa = (x2-x1)/(1-lm-rm)-(x2-x1)
			Ya = (y2-yf)/(1-bm-to)-(y2-yf)
			LM = Xa*(lm/(lm+rm))
			RM = Xa*(rm/(lm+rm))
			BM = Ya*(bm/(bm+to))
			TM = Ya*(to/(bm+to))
			null2 = TPad("null2","",0,0,1,1)
			null2.SetFillStyle(0)
			null2.SetFrameFillStyle(0)
			null2.Draw()
			null2.cd()
			null2.Range(x1-LM,yf-BM,x2+RM,y2+TM)
			null2.SetRightMargin(0.20)
			null2.SetLeftMargin(margine)
			null2.SetTopMargin(0.10)
			null2.SetBottomMargin(margine)
			#exclusion.SetMinimum(the_minimum)
			#exclusion.SetMaximum(the_maximum)
			exclusion.GetXaxis().SetRangeUser(-0.05,1.05)
			exclusion.GetYaxis().SetRangeUser(-0.05,1.05)
			exclusion.GetXaxis().SetLabelOffset(100)
			exclusion.GetYaxis().SetLabelOffset(100)
			#exclusion.Draw('CONT3')
			#exclusion2.Draw()
コード例 #3
0
ファイル: tools.py プロジェクト: lopezzot/MMIntegration
def write_rootdategraph_plusatten(vectorx, vectory, vectory2, graphtitle,
                                  xtitle, ytitle, rootdirectory):
    '''plot graph current + source'''

    arrayx = array('d')
    arrayy = array('d')
    arrayy2 = array('d')

    for x in vectorx:
        arrayx.append(x.Convert())

    for y in vectory:
        arrayy.append(y)

    for y2 in vectory2:
        arrayy2.append(y2)

    if ytitle[0] == "i":
        ytitle = ytitle + " (uA) "
        color = 2
        offset = 1.
        minimum = -1
        maximum = int(np.max(vectory) + 1.5)
        if maximum > 10:
            maximum = int(10)

    if ytitle == "v":
        ytitle = ytitle + " (V)"
        color = 4
        offset = 0.9
        minimum = 400
        maximum = 600
    c = TCanvas(graphtitle + "_canvas")
    pad1 = TPad("pad1", "", 0, 0, 1, 1)
    pad2 = TPad("pad2", "", 0, 0, 1, 1)
    pad2.SetFillStyle(4000)
    pad2.SetFrameFillStyle(0)

    #How many graph points
    n = len(vectorx)

    MyTGraph = TGraph(n, arrayx, arrayy)
    MyTGraph.SetName(graphtitle)

    MyTGraph2 = TGraph(n, arrayx, arrayy2)

    #Draw + DrawOptions

    Style = gStyle
    Style.SetPadLeftMargin(2.0)
    XAxis = MyTGraph.GetXaxis()  #TGraphfasthescin
    XAxis.SetTimeDisplay(1)
    XAxis.SetTimeFormat("#splitline{%d/%m}{%H:%M}")
    XAxis.SetLabelOffset(0.025)
    MyTGraph.SetMarkerColor(color)
    MyTGraph.SetMarkerStyle(1)
    MyTGraph.SetMarkerSize(1)
    MyTGraph.SetLineColor(color)
    MyTGraph.SetTitle(graphtitle + " V")
    #XAxis.SetTitle(xtitle)
    YAxis = MyTGraph.GetYaxis()
    YAxis.SetTitleOffset(offset)
    YAxis.SetTitleOffset(offset)
    YAxis.SetTitleColor(2)
    YAxis.SetTitle(ytitle)
    MyTGraph.GetHistogram().SetMinimum(-1.)
    MyTGraph.GetHistogram().SetMaximum(
        23.)  #modified to have also attenuation 22 displayed
    #MyTGraph.Draw("APL")
    MyTGraph2.SetMarkerColor(4)
    MyTGraph2.SetMarkerStyle(1)
    MyTGraph2.SetMarkerSize(1)
    MyTGraph2.SetLineColor(4)
    MyTGraph2.SetLineStyle(7)
    MyTGraph2.GetHistogram().SetMinimum(-1.)
    MyTGraph2.GetHistogram().SetMaximum(23.)
    MyTGraph2.GetXaxis().SetLabelSize(0)
    MyTGraph2.GetXaxis().SetNdivisions(0)
    MyTGraph2.GetYaxis().SetTitle("Attenuation factor")
    MyTGraph2.GetYaxis().SetTitleOffset(offset)
    MyTGraph2.GetYaxis().SetTitleColor(4)
    MyTGraph2.SetTitle("")

    pad1.Draw()
    pad1.cd()
    MyTGraph.Draw("APL")

    pad2.Draw()
    pad2.cd()
    #MyTGraph2.SetMarkerColor(4)
    MyTGraph2.Draw("APLY+")
    #MyTGraph2.Draw("same")

    rootdirectory.WriteTObject(c)
    #MyTGraph.Write(graphtitle)
    #MyTGraph.Draw("APL")
    if "D" not in graphtitle:
        c.SaveAs("GIF-" + graphtitle[0:9] + ".pdf")
    gPad.Close()
コード例 #4
0
ファイル: part3.py プロジェクト: QuantumDancer/FP2
def makeTwoScalesGraph(file):
    print(file)
    ch1 = OPData.fromPath('../data/part3/%s' % file, 1)
    ch2 = OPData.fromPath('../data/part3/%s' % file, 2)

    print('make canvas + pad')
    c = TCanvas('c-%s' % file, '', 1280, 720)
    pad = TPad('pad-%s' % file, '', 0, 0, 1, 1)
    pad.Draw()
    pad.cd()

    print('frame')
    frame = pad.DrawFrame(0,
                          min(ch1.getY()) * 1.1, 0.051,
                          max(ch1.getY()) * 1.1)
    frame.SetXTitle('Zeit t / s')
    frame.GetXaxis().CenterTitle()
    frame.SetYTitle('Spannung Spule 2: U_{2} / V')
    frame.GetYaxis().CenterTitle()
    frame.GetYaxis().SetLabelColor(4)
    frame.GetYaxis().SetTitleColor(4)

    print('g1')
    g1 = ch1.makeGraph('g1-%s' % file)
    prepareGraph(g1)
    g1.Draw('PX')

    print('overlay')
    c.cd()
    overlay = TPad('overlay-%s' % file, '', 0, 0, 1, 1)
    overlay.SetFillStyle(4000)  # transparent
    overlay.SetFillColor(0)  # white
    overlay.SetFrameFillStyle(4000)  # transparent
    overlay.Draw()
    overlay.cd()

    print('g2')
    g2 = ch2.makeGraph('g2-%s' % file)
    prepareGraph(g2, 2)
    g2ymin = min(ch2.getY())
    xmin = pad.GetUxmin()
    xmax = pad.GetUxmax()
    ymin = 1.1 * g2ymin
    ymax = abs(ymin)
    if file == '07.tab':  # same scale like 06.tab
        ymin, ymax = -0.07128, 0.07128
    oframe = overlay.DrawFrame(xmin, ymin, xmax, ymax)
    oframe.GetXaxis().SetLabelOffset(99)
    oframe.GetYaxis().SetLabelOffset(99)
    oframe.GetYaxis().SetTickLength(0)
    g2.Draw('PX')

    print('axis')
    axis = TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 510, "+L")
    axis.SetTitle('Spannung Photodiode: U_{ph} / V')
    axis.CenterTitle()
    axis.SetTitleOffset(1.2)
    axis.Draw()

    print('print')
    c.Update()
    c.Print('../img/part3/%s.pdf' % file[:-4], 'pdf')
コード例 #5
0
def DrawOverlap(fileVec,
                histVec,
                titleVec,
                legendtext,
                pngname,
                logstatus=[0, 0],
                xRange=[-99999, 99999, 1]):

    gStyle.SetOptTitle(0)
    gStyle.SetOptStat(0)
    gStyle.SetTitleOffset(1.1, "Y")
    gStyle.SetTitleOffset(0.9, "X")
    gStyle.SetLineWidth(3)
    gStyle.SetFrameLineWidth(3)

    i = 0

    histList_ = []
    histList = []
    histList1 = []
    maximum = []

    ## Legend
    leg = TLegend(0.65, 0.650, 0.89, 0.85)  #,NULL,"brNDC");
    leg.SetBorderSize(0)
    #    leg.SetNColumns(3)
    leg.SetLineColor(1)
    leg.SetLineStyle(1)
    leg.SetLineWidth(1)
    leg.SetFillColor(0)
    leg.SetFillStyle(0)
    leg.SetTextFont(22)
    leg.SetTextSize(0.045)

    c = TCanvas("c1", "c1", 0, 0, 500, 500)
    #c.SetBottomMargin(0.15)
    #c.SetLeftMargin(0.15)
    #c.SetLogy(0)
    #c.SetLogx(0)
    c1_2 = TPad("c1_2", "newpad", 0., 0.30, 1, 0.994)
    c1_2.Draw()
    c1_1 = TPad("c1_1", "newpad1", 0, 0.02, 1, 0.30)
    c1_1.Draw()

    print("you have provided " + str(len(fileVec)) + " files and " +
          str(len(histVec)) + " histograms to make a overlapping plot")
    print "opening rootfiles"
    c.cd()
    c1_2.SetBottomMargin(0.013)
    c1_2.SetLogy(logstatus[1])
    c1_2.SetLogx(logstatus[0])

    c1_2.cd()
    ii = 0
    inputfile = {}
    print str(fileVec[(len(fileVec) - 1)])
    for ifile_ in range(len(fileVec)):
        print("opening file  " + fileVec[ifile_])
        inputfile[ifile_] = TFile(fileVec[ifile_])
        print "fetching histograms"
        for ihisto_ in range(len(histVec)):
            print("printing histo " + str(histVec[ihisto_]))
            histo = inputfile[ifile_].Get(histVec[ihisto_])
            #status_ = type(histo) is TGraphAsymmErrors
            histList.append(histo)
            # for ratio plot as they should nt be normalize
            histList1.append(histo)
            print histList[ii].Integral()
            histList[ii].Rebin(xRange[2])
            print('after', histList[ii].Integral(0, -1))
            histList[ii].Scale(1.0 / histList[ii].Integral(0, -1))
            maximum.append(histList[ii].GetMaximum())
            maximum.sort()
            ii = ii + 1

    print histList
    for ih in range(len(histList)):
        tt = type(histList[ih])
        if logstatus[1] is 1:
            histList[ih].SetMaximum(maximum[(len(maximum) - 1)] *
                                    25)  #1.4 for log
            histList[ih].SetMinimum(0.001)  #1.4 for log
        if logstatus[1] is 0:
            histList[ih].SetMaximum(maximum[(len(maximum) - 1)] *
                                    1.2)  #1.4 for log
            histList[ih].SetMinimum(0)  #1.4 for log


#        print "graph_status =" ,(tt is TGraphAsymmErrors)
#        print "hist status =", (tt is TH1D) or (tt is TH1F)
        if ih == 0:
            if tt is TGraphAsymmErrors:
                histList[ih].Draw("AP")
            if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I):
                histList[ih].Draw("hist")
        if ih > 0:
            #histList[ih].SetLineWidth(2)
            if tt is TGraphAsymmErrors:
                histList[ih].Draw("P same")
            if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I):
                histList[ih].Draw("hist same")

        if tt is TGraphAsymmErrors:
            histList[ih].SetMaximum(1.4)
            histList[ih].SetMarkerColor(colors[ih])
            histList[ih].SetLineColor(colors[ih])
            histList[ih].SetMarkerStyle(markerStyle[ih])
            histList[ih].SetMarkerSize(1)
            leg.AddEntry(histList[ih], legendtext[ih], "PL")
        if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I):
            histList[ih].SetLineStyle(linestyle[ih])
            histList[ih].SetLineColor(colors[ih])
            histList[ih].SetLineWidth(3)
            leg.AddEntry(histList[ih], legendtext[ih], "L")
        histList[ih].GetYaxis().SetTitle(titleVec[1])
        histList[ih].GetYaxis().SetTitleSize(0.062)
        histList[ih].GetYaxis().SetTitleOffset(0.78)
        histList[ih].GetYaxis().SetTitleFont(22)
        histList[ih].GetYaxis().SetLabelFont(22)
        histList[ih].GetYaxis().SetLabelSize(.062)
        histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1])
        histList[ih].GetXaxis().SetLabelSize(0.0000)
        histList[ih].GetXaxis().SetTitle(titleVec[0])
        histList[ih].GetXaxis().SetLabelSize(0.052)
        histList[ih].GetXaxis().SetTitleSize(0.052)
        histList[ih].GetXaxis().SetTitleOffset(1.04)
        histList[ih].GetXaxis().SetTitleFont(22)
        histList[ih].GetXaxis().SetTickLength(0.07)
        histList[ih].GetXaxis().SetLabelFont(22)
        histList[ih].GetYaxis().SetLabelFont(22)
        # histList[ih].GetXaxis().SetNdivisions(508)
        #

        i = i + 1
    pt = TPaveText(0.0877181, 0.91, 0.9580537, 0.95, "brNDC")
    pt.SetBorderSize(0)
    pt.SetTextAlign(12)
    pt.SetFillStyle(0)
    pt.SetTextFont(22)
    pt.SetTextSize(0.046)
    #    text = pt.AddText(0.05,0.5,"ATLAS Internal ")
    text = pt.AddText(0.65, 1.0, "#sqrt{s} = 13 TeV (36fb^{-1})")
    pt.Draw()

    t2a = TPaveText(0.277181, 0.81, 0.6780537, 0.89, "brNDC")
    t2a.SetBorderSize(0)
    t2a.SetFillStyle(0)
    t2a.SetTextSize(0.046)
    t2a.SetTextAlign(12)
    t2a.SetTextFont(22)
    histolabel1 = str(fileVec[(len(fileVec) - 1)])
    text1 = t2a.AddText(0.065, 0.5, "ATLAS Internal")
    t2a.Draw()
    leg.Draw()
    #
    c.cd()

    h_inc = histList1[0].Clone()
    h_vbs = histList1[1].Clone()
    h_qcd = histList1[2].Clone()
    h_int = histList1[3].Clone()

    h_inc.Add(h_vbs, -1)
    h_inc.Add(h_qcd, -1)

    ## ratio plot
    hdivide_1 = h_int.Clone()
    hdivide_1.Divide(h_vbs)
    # hdivide_1.GetYaxis().SetTitle(str(legendtext[(len(legendtext)-1)]))
    hdivide_1.GetYaxis().SetTitleSize(0.11)
    hdivide_1.GetYaxis().SetTitle("ratio")

    hdivide_1.GetYaxis().SetTitleOffset(0.43)
    hdivide_1.GetYaxis().SetTitleFont(22)
    hdivide_1.GetYaxis().SetLabelSize(0.13)
    hdivide_1.GetYaxis().CenterTitle()

    hdivide_1.GetXaxis().SetTitleSize(0.14)
    hdivide_1.GetXaxis().SetTitleOffset(0.89)
    hdivide_1.GetXaxis().SetTitleFont(22)
    hdivide_1.GetXaxis().SetLabelSize(0.14)

    hdivide_1.GetYaxis().SetLabelFont(22)
    c.cd()
    c1_1.cd()

    #    c1_1.Range(-7.862408,-629.6193,53.07125,486.5489)
    c1_1.SetFillColor(0)
    c1_1.SetTicky(1)
    c1_1.SetTopMargin(0.0510)
    c1_1.SetBottomMargin(0.3006666678814)
    c1_1.SetFrameFillStyle(0)
    c1_1.SetFrameBorderMode(0)
    c1_1.SetFrameFillStyle(0)
    c1_1.SetFrameBorderMode(0)
    c1_1.SetLogy(0)
    hdivide_1.GetXaxis().SetRangeUser(xRange[0], xRange[1])
    hdivide_1.GetYaxis().SetNdivisions(505)
    c1_1.Draw()
    c1_1.SetGridy()

    hdivide_1.SetMarkerStyle(20)
    hdivide_1.SetMarkerColor(2)
    hdivide_1.SetMarkerSize(1)
    hdivide_1.Draw("P")

    hdivide_2 = h_int.Clone()
    hdivide_2.Divide(h_qcd)
    hdivide_2.SetMarkerStyle(21)
    hdivide_2.SetMarkerColor(4)
    hdivide_2.SetMarkerSize(1)
    hdivide_2.Draw("Psame")

    hdivide_3 = h_int.Clone()
    hdivide_3.Divide(h_inc)
    hdivide_3.SetMarkerStyle(22)
    hdivide_3.SetMarkerColor(1)
    hdivide_3.SetMarkerSize(1)
    hdivide_3.Draw("Psame")

    hdivide_1.SetMinimum(-1.01)
    hdivide_1.SetMaximum(3.20)

    c.cd()

    outputdirname = 'plots/'
    histname = outputdirname + pngname
    c.SaveAs(histname + '.png')
    c.SaveAs(histname + '.pdf')
    c.SaveAs(histname + '.root')
    c.SaveAs(histname + '.C')
コード例 #6
0
def drawHisto(histlist,histoD,xTitle,yTitle,outName,uncHists=""):    
    legend = TLegend(0.35, 0.72, 0.85, 0.92,"") #,"brNDC"
    legend.SetFillStyle(0)

    legend.SetTextSize(0.045)
    legend.SetNColumns(2)

    myStack = THStack("myStack","")
    for hist in histlist:
        myStack.Add(hist,"hist")
    
    histoErr = histlist[0].Clone()
    for iHist in range(1,len(histlist)):
        histoErr.Add(histlist[iHist])
        
    MCCount = myStack.GetStack().Last().Integral()
    DataCount = histoD.Integral()
    MCNormFactor = DataCount/MCCount

#    myStack.Delete()
    myStack = THStack("myStack","")

    for hist in histlist:
        hist.Scale(MCNormFactor)
        myStack.Add(hist,"hist")
        

    histoErr.Scale(MCNormFactor)
    

    if uncHists!="":
        MCMean = myStack.GetStack().Last().Clone()
        MCErr = MCMean.Clone()
        MCErr.Reset()
        for ibin in range(1,MCMean.GetNbinsX()+1):
            thisbinunc = 0
            for ihist in uncHists:
                thisbinunc += ihist.GetBinContent(ibin)**2     #sum assuming correlated
            sfunc = thisbinunc**0.5*MCNormFactor
            if args.nostat:
                MCMean.SetBinError(ibin, sfunc)
                MCErr.SetBinContent(ibin, sfunc)
            else:
                MCMean.SetBinError(ibin, math.sqrt(sfunc**2 + histoErr.GetBinError(ibin)**2))
                MCErr.SetBinContent(ibin, math.sqrt(sfunc**2 + histoErr.GetBinError(ibin)**2))
        
    c = TCanvas("main","main",1200,1200)
    c.SetCanvasSize(1200,1200)
    
    upperCanvas = TPad("up","up",0,0.24,1,1)
    upperCanvas.SetBottomMargin(0.03)
    upperCanvas.SetLeftMargin(0.12)
    upperCanvas.SetTopMargin(0.06)
#    upperCanvas.SetLogy(isLog)
    upperCanvas.Draw()
    upperCanvas.cd()
    
    myStack.Draw()
    myStack.GetYaxis().SetTitle(yTitle)
    myStack.GetHistogram().GetZaxis().SetTitle()

    myStack.GetYaxis().SetLabelSize(0.048)
    myStack.GetYaxis().SetTitleSize(0.07)
    myStack.GetYaxis().SetTitleOffset(0.78)
    myStack.GetYaxis().SetTitleFont(42)
    legend.Draw("same")

    if uncHists!="":
        MCMean.Draw("e2 same")
        MCMean.SetFillColor(kGreen)
        MCMean.SetLineColor(kGreen)
        MCMean.SetMarkerSize(0)
        MCMean.SetFillStyle(3013)
        
    if not args.nostat:
        histoErr.Draw("e2 same")
        # histoErr.Sumw2()
        histoErr.SetFillColor(kGray+3)
        histoErr.SetLineColor(kGray+3)
        histoErr.SetMarkerSize(0)
        histoErr.SetFillStyle(3013)       

    histoMC = myStack.GetStack().Last()
    histoBkg= myStack.GetStack().Before(histoMC)

    print "Total MC:", histoMC.Integral(), ", Data:",histoD.Integral()


    histoD.Draw("same p e")
    legend.AddEntry(histoD,"Data","PE")
    
    for hist in histlist:
        legend.AddEntry(hist,hist.GetName().replace('uds','udsg').replace('b','bottom').replace('c','charm'),'f')
    legend.AddEntry(histoErr,"MC Stat. Unc.",'f')
    if uncHists!="": legend.AddEntry(MCMean,"SF Unc.",'f')
    maxY = histoD.GetMaximum()
    
    #if myStack.GetMinimum() >= 0:
    myStack.SetMinimum(1e-3)
    myStack.SetMaximum(maxY*1.35)


    c.cd()
    lowerCanvas = TPad("down","down",0,0,1,0.26)
    lowerCanvas.Draw()
    lowerCanvas.cd()
    lowerCanvas.SetTicky(1)
    lowerCanvas.SetLeftMargin(0.1)
    lowerCanvas.SetRightMargin(0.1)
    lowerCanvas.SetTopMargin(0.0)
    lowerCanvas.SetBottomMargin(0.4)
    lowerCanvas.SetLeftMargin(0.12)
    lowerCanvas.SetFrameFillStyle(0)
    lowerCanvas.SetFrameBorderMode(0)
    lowerCanvas.SetGridy()

    histoRatio = histoD.Clone()
    histoRatio.Divide(histoMC)
    for ib in range(1,histoRatio.GetNbinsX()+1):
        if histoD.GetBinContent(ib) != 0:
            histoRatio.SetBinError(ib, histoD.GetBinError(ib)/histoD.GetBinContent(ib)*histoRatio.GetBinContent(ib))
        else:
            histoRatio.SetBinError(ib,0.)

    histoRatio.GetYaxis().SetTitle("Data/MC")
    histoRatio.GetYaxis().SetTitleSize(0.15)
    histoRatio.GetYaxis().SetTitleOffset(0.38)
    histoRatio.GetYaxis().SetTitleFont(42)
    histoRatio.GetYaxis().SetLabelSize(0.14)
    histoRatio.GetYaxis().CenterTitle()
    histoRatio.GetYaxis().SetLabelFont(42)
    histoRatio.GetYaxis().SetNdivisions(5)

    histoRatio.GetXaxis().SetTitle(xTitle)
    histoRatio.GetXaxis().SetLabelSize(0.14)
    histoRatio.GetXaxis().SetTitleSize(0.19)
    histoRatio.GetXaxis().SetTitleOffset(0.88)
    histoRatio.GetXaxis().SetTitleFont(42)
    histoRatio.GetXaxis().SetTickLength(0.07)
    histoRatio.GetXaxis().SetLabelFont(42)
    histoRatio.SetTitle("")

    histoRatio.Draw("P e")
    histoRatio.SetMaximum(1.49)
    histoRatio.SetMinimum(0.51)

    if uncHists!="":
        RatioErr = MCErr.Clone()
        RatioErr.Divide(histoMC)
        RatioErrVals = RatioErr.Clone()
        for ibin in range(1,RatioErr.GetNbinsX()+1):
            RatioErrVals.SetBinContent(ibin,1.)
            RatioErrVals.SetBinError(ibin,RatioErr.GetBinContent(ibin))

        RatioErrVals.Draw("e2 same")
        RatioErrVals.SetFillColor(kGreen)
        RatioErrVals.SetLineColor(kGreen)
        RatioErrVals.SetMarkerSize(0)
        RatioErrVals.SetFillStyle(3013)

    if not args.nostat:
        RatioStatUnc = histoMC.Clone()
        for ibin in range(1,RatioStatUnc.GetNbinsX()+1):
            RatioStatUnc.SetBinContent(ibin,1)
            if histoMC.GetBinContent(ibin) != 0:
                RatioStatUnc.SetBinError(ibin,histoMC.GetBinError(ibin)/histoMC.GetBinContent(ibin))
            else:
                RatioStatUnc.SetBinError(ibin,0)

        RatioStatUnc.Draw("e2 same")
        RatioStatUnc.SetFillColor(kGray+3)
        RatioStatUnc.SetLineColor(kGray+3)
        RatioStatUnc.SetMarkerSize(0)
        RatioStatUnc.SetFillStyle(3013) 
    
    histoRatio.Draw("P e same")  # To bring on top

    hLine = TLine(-0.2,1,1,1)
    hLine.SetLineColor(kRed)
    hLine.Draw()

#    if drawDataMCRatioLine:
#        MCCount = histoMC.Integral()
#        if MCCount > 0.:
#            DataCount = histoD.Integral()
#            MCNormFactor = DataCount/MCCount
#            hLine2 = TLine(start,MCNormFactor,end,MCNormFactor)
#            hLine2.SetLineColor(kBlue)
#            hLine2.Draw()

    # ----------------------------------------------------------

    # ======================== LaTeX ==========================
    texTL = TLatex()
    texTL.SetTextSize(0.07)
    texTL.SetTextAlign(13)

    texTR = TLatex()
    texTR.SetTextSize(0.05)
    texTR.SetTextAlign(31)

#    if dataset=="" or noRatio:
#        texTL.DrawLatexNDC(0.13,0.87, "CMS #it{#bf{Preliminary}}")
#        texTR.DrawLatexNDC(0.89,0.91, "#bf{"+str(lumi/1000.)+" fb^{-1} (13 TeV)}")
#    else:
    upperCanvas.cd()
    
    texTL.DrawLatexNDC(0.16,0.92, "CMS") # #it{#bf{Preliminary}}")
    if args.prelim:
        texTL2 = TLatex()
        texTL2.SetTextSize(0.05)
        texTL2.SetTextAlign(13)
        suff = "#it{#bf{Preliminary}}"
        texTL2.DrawLatexNDC(0.16,0.85, suff)

    texTR.DrawLatexNDC(0.89,0.95, "#bf{"+str(lumi/1000.)+" fb^{-1} (13 TeV)}")
    # ----------------------------------------------------------

    c.SaveAs(outName+".pdf")
    c.SaveAs(outName+".png")