from ROOT import *
import sys

gStyle.SetOptStat(0)


f1 = TFile("~/3DayLifetime/outplots_ttbarCSV.root")
f2 = TFile("~/3DayLifetime/outplots_ttbarCSV.root")
f3 = TFile("outplots_1.root")
f4 = TFile("outplots_2.root")
f5 = TFile("outplots_7.root")
f6 = TFile("outplots_7.root")
f7 = TFile("outplots_5.root")
f8 = TFile("outplots_6.root")
f9 = TFile("outplots_7.root")
f10 = TFile("outplots_7.root")

t1 = f1.Get("eventVars")
t2 = f2.Get("eventVars")
t3 = f3.Get("eventVars")
t4 = f4.Get("eventVars")
t5 = f5.Get("eventVars")
t6 = f6.Get("eventVars")
t7 = f7.Get("eventVars")
t8 = f8.Get("eventVars")
t9 = f9.Get("eventVars")
t10 = f10.Get("eventVars")

c1 = TCanvas()

c1_2 = TPad("c1_1", "newpad",0.01,0.01,0.99,0.25)
c1_2.Draw()
c1_1 = TPad("c1_2", "newpad",0.01,0.25,0.99,0.99)
c1_1.Draw()

c1_1.cd()

t1.Draw(sys.argv[1]+">>h1"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")")
t2.Draw(sys.argv[1]+">>h2"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t3.Draw(sys.argv[1]+">>h3"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t4.Draw(sys.argv[1]+">>h4"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t5.Draw(sys.argv[1]+">>h5"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t6.Draw(sys.argv[1]+">>h6"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t7.Draw(sys.argv[1]+">>h7"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t8.Draw(sys.argv[1]+">>h8"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t9.Draw(sys.argv[1]+">>h9"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")
t10.Draw(sys.argv[1]+">>h10"+"("+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4]+")", "csvEventWt")

h1.SetLineColor(kBlack)
h2.SetLineColor(kRed+1)
h3.SetLineColor(42)
h4.SetLineColor(43)
h5.SetLineColor(44)
h6.SetLineColor(45)
h7.SetLineColor(46)
h8.SetLineColor(47)
h9.SetLineColor(48)
h10.SetLineColor(49)
h1.SetLineWidth(2)
h2.SetLineWidth(2)

h1.SetMinimum(0.01)
h1.SetMaximum(200*h1.GetMaximum())
h1.SetTitle('')
h1.Draw()
h2.Draw("same")
#h3.Draw("same")
#h4.Draw("same")
#h5.Draw("same")
#h6.Draw("same")
#h7.Draw("same")
#h8.Draw("same")
#h9.Draw("same")
#h10.Draw("same")

leg = TLegend(0.5, 0.75, 0.89, 0.89)
leg.AddEntry(h1, "No Reshaping", "l")
leg.AddEntry(h2, "With Reshaping", "l")
leg.AddEntry(h2, sys.argv[5], "")
leg.SetFillColor(0)
leg.SetLineColor(0)
leg.Draw("same")

c1_2.cd()

r2 = h2.Clone("r2")
r3 = h3.Clone("r3")
r4 = h4.Clone("r4")
r5 = h5.Clone("r5")
r6 = h6.Clone("r6")
r7 = h7.Clone("r7")
r8 = h8.Clone("r8")
r9 = h9.Clone("r9")
r10 = h10.Clone("r10")
r2.Divide(h1)
r3.Divide(h1)
r4.Divide(h1)
r5.Divide(h1)
r6.Divide(h1)
r7.Divide(h1)
r8.Divide(h1)
r9.Divide(h1)
r10.Divide(h1)

r2.SetMinimum(0.8)
r2.SetMaximum(1.2)
r2.Draw("axis")
r2.GetYaxis().SetLabelSize(0.11)
r2.Draw("hist")
#r3.Draw("hist same")
#r4.Draw("hist same")
#r5.Draw("hist same")
#r6.Draw("hist same")
#r7.Draw("hist same")
#r8.Draw("hist same")
#r9.Draw("hist same")
#r10.Draw("hist same")

line = TF1("line", "1", 0, 10000);
line.SetLineColor(kBlack);
line.SetLineWidth(1);
line.Draw("same");


c1.SaveAs(sys.argv[1]+"_"+sys.argv[5]+".pdf")
c1_1.cd()
gPad.SetLogy(1)
c1.SaveAs(sys.argv[1]+"_"+sys.argv[5]+"_log.pdf")
