from ROOT import *

gStyle.SetOptStat(0)

ofilename = "plots/test.pdf"

legend = TLegend(0.55,0.55,0.88,0.88)
canvas = TCanvas("c","",1100,850)
latex = TLatex()
latex.SetTextSize(0.05)
latex.SetTextFont(62)

pads = []
topPadL = TPad("topPadL","a",0.01,0.4,0.495,0.99)
topPadR = TPad("topPadR","b",0.505,0.4,0.99,0.99)
botPadL = TPad("botPadL","c",0.01,0.01,0.495,0.399)
botPadR = TPad("botPadR","d",0.505,0.01,0.99,0.399)

topPadL.SetBottomMargin(0.001)
botPadL.SetTopMargin(0.001)
topPadR.SetBottomMargin(0.001)
botPadR.SetTopMargin(0.001)

topPadL.SetRightMargin(0.001)
botPadL.SetRightMargin(0.001)
topPadR.SetRightMargin(0.001)
botPadR.SetRightMargin(0.001)

pads.append(topPadL)
pads.append(topPadR)
pads.append(botPadL)
pads.append(botPadR)

for pad in pads:
    pad.Draw()

testhisto = TH1F("h","",200,0,100)
for i in range(1,201):
    testhisto.Fill(i,i)


ratiobase = testhisto.Clone("ratiobase")
ratiobase.GetYaxis().SetRangeUser(0,2.1)

for jj in range(1,ratiobase.GetNbinsX()+1):
    bc = ratiobase.GetBinContent(jj)
    be = ratiobase.GetBinError(jj)
    ratiobase.SetBinContent(jj,1)
    if bc > 0:
        ratiobase.SetBinError(jj,be/bc)
    else:
        ratiobase.SetBinError(jj,0)
ratiobase.SetFillStyle(1001)
ratiobase.SetFillColor(33)
ratiobase.SetLineColor(kBlack)


for i in range(0,2):
    pad = pads[i]
    pad.cd()
    pad.SetLogy()
    testhisto.Draw()
    gPad.RedrawAxis()
    
    pad = pads[i+2]
    pad.cd()

    rb = ratiobase.Clone(str(i+1)+"_base")
    rb.Draw("e2")
    #ratiobase.Draw("e2")
    
canvas.Print(ofilename,"pdf")
