ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/bm409/autoPlotter.py
(Generate patch)

Comparing UserCode/bm409/autoPlotter.py (file contents):
Revision 1.3 by bm409, Thu Aug 5 15:41:35 2010 UTC vs.
Revision 1.4 by bm409, Mon Aug 9 12:01:32 2010 UTC

# Line 15 | Line 15 | Root.gStyle.SetTitleW(0.7)
15   Root.gStyle.SetTitleH(0.07)
16   Root.gStyle.SetOptTitle(1)
17   Root.gStyle.SetOptStat(0)
18 + Root.gStyle.SetAxisColor(1, "XYZ");
19 + Root.gStyle.SetStripDecimals(Root.kTRUE);
20 + Root.gStyle.SetTickLength(0.03, "XYZ");
21 + Root.gStyle.SetNdivisions(510, "XYZ");
22 + Root.gStyle.SetPadTickX(1);
23 + Root.gStyle.SetPadTickY(1);
24 + Root.gStyle.SetLabelColor(1, "XYZ");
25 + Root.gStyle.SetLabelFont(42, "XYZ");
26 + Root.gStyle.SetLabelOffset(0.007, "XYZ");
27 + Root.gStyle.SetLabelSize(0.05, "XYZ");
28 + intlumi = 0.2683 #inv pico barns
29  
30 + #close list is a global variable that has the file name appended to it so at the end of each hist loop the open files are closed.
31  
32 < def DrawHist(H,col,norm):
33 <        Hist =
34 < def HistogramMaxYmum(H):
35 <        Nbins = H.GetNbinsX()
36 <        Entries = [H.GetBinContent(i) for i in range(1,Nbins+1)]
37 <        return max(Entries)
32 > def GetHist(DataSetName,col,norm,Legend):
33 >    a = Root.TFile.Open(DataSetName)
34 >    closeList.append(a)
35 >    b = a.Get(DirKeys[dir].GetTitle())
36 >    Hist = b.Get(hist)
37 >    leg.AddEntry(Hist,Legend,"LP")
38 >    Hist.SetLineWidth(3)
39 >    Hist.SetLineColor(col)
40 >    if norm != 0:
41 >       Hist.Scale(intlumi/100.)
42 >    return Hist
43 >
44 >
45 > def HistogramMaxY(H):
46 >   Nbins = H.GetNbinsX()
47 >   Entries = [H.GetBinContent(i) for i in range(1,Nbins+1)]
48 >   return max(Entries)
49  
50   def HistogramMinX(H):
51    Nbins = H.GetNbinsX()
# Line 39 | Line 62 | def HistogramMaxX(H):
62      if H.GetBinContent(x) != 0:
63        return H.GetBinLowEdge(x+1)
64  
65 < intlumi = 0.2683 #inv pico barns
65 >
66 >
67 >
68  
69  
70   time = strftime("%Y_%m_%d")
# Line 47 | Line 72 | resultsDir = " ../results/"
72   print time
73   mergedPlots = Root.TFile("StandardPlots.root", "RECREATE")
74  
50 tmp = commands.getstatusoutput("ls" + resultsDir + "*.root")
75  
76 < RootFileList = tmp[1].split('\n')
76 > #List of files from which you wish to plot
77 > RootFileList = ["../results/AK5Calo_JetMETTau_Run2010A_Compleate.root","../results/AK5Calo_ZJets-madgraph.root","../results/AK5Calo_Zinvisible_jets.root","../results/AK5Calo_WJets-madgraph.root","../results/AK5Calo_ttbarTauola.root","../results/AK5Calo_LM0.root","../results/AK5Calo_TotalBackgrounds.root","../results/AK5Calo_QCD_AllPtBins_7TeV_Pythia6.root"]
78  
79   Webpage = open("../pdfs/HadronicPlots"+time+".html",'w')
80   header = '''
# Line 67 | Line 92 | footer = '''  </table>
92    </body>'''
93   Webpage.write(header)
94  
70 temp = Root.TFile.Open(RootFileList[1])
71 DirKeys = temp.GetListOfKeys()
95  
96 + print RootFileList
97  
98 + temp = Root.TFile.Open(RootFileList[1])
99 + DirKeys = temp.GetListOfKeys()
100  
101   HistKeys = [ (dir.ReadObj()).GetListOfKeys() for dir in DirKeys]
102   HistNames = [ [k.GetName() for k in D] for D in HistKeys]
# Line 84 | Line 110 | for dir in range(0,len(DirKeys)):
110      leg.SetShadowColor(0)
111      leg.SetFillColor(0)
112      leg.SetLineColor(0)
113 <    if "PFMetVsMHT" in hist: continue
113 >    if "PFMetVsMHT" in hist: continue #This is the 2d Histogram in the file, dont want to plot this!
114      col=2
115      fileno = 1
116      MaxY = 1.0
117      MaxX = 1.0
118 <    XMin = 1000.
118 >    MinX = 1000.
119      c1 = Root.TCanvas("canvas"+hist,"canname"+hist,1200,1200)
120      # c1.Divide(1,2)#,0.4,0.4)
121      mainPad = Root.TPad("","",0.01,0.21,0.99,0.99);
122      mainPad.SetNumber(1);
123      mainPad.Draw();
98
124      ratioPad = Root.TPad("","",0.01,0.01,0.99,0.2);
125      ratioPad.SetNumber(2);
126      ratioPad.Draw();
127  
128 <    for file in RootFileList:
129 <      c1.cd(1)
130 <      a = Root.TFile.Open(file)
131 <      closeList.append(a)
132 <      b = a.Get(DirKeys[dir].GetTitle())
133 <      if "AK5Calo_JetMETTau_Run2010A_Compleate" in file :
134 <        c1.SetLogy()
135 <        c = b.Get(hist)
136 <        if c.IsA().InheritsFrom("TH2") : continue
137 <        c.SetMarkerStyle(20)
138 <        c.SetLineWidth(3)
139 <        RatioTop = c.Clone()
140 <        c.Draw("P")
141 <        if HistogramMinX(c) < XMin:
142 <          XMin = HistogramMinX(c)
143 <        if HistogramMaxX(c) > MaxX :
144 <          MaxX = HistogramMaxX(c)
145 <        title = Root.TLatex(0.2,0.95,(DirKeys[dir].GetTitle())+"_"+hist[0:-4])
146 <        title.SetNDC()
147 <        title.Draw()
148 <        leg.AddEntry(c,(RootFileList[0])[19:-5],"Pl")
149 <      if "JetMETTau" not in file :
150 <        d = b.Get(hist)
151 <        if d.IsA().InheritsFrom("TH2") : continue
152 <        if col == 10 or col == 9 : col+=1
153 <        d.SetLineColor(col)
154 <        d.SetLineWidth(3)
155 <        if d.Integral() > 0:
156 <          Norm = 100.
157 <          d.Scale(intlumi/Norm)
158 <          # d.Scale(c.Integral()/d.Integral())
159 <        if "QCD" in file:
160 <          d.SetFillColor(Root.kRed)
161 <          d.SetLineColor(Root.kRed)
162 <          d.SetFillStyle(3002)
163 <
164 <        if "AK5Calo_TotalBackgrounds" in file :
165 <          d.SetLineColor(Root.kAzure)
166 <          RatioBottom = d.Clone()
167 <        leg.AddEntry(d,(RootFileList[fileno])[19:-5],"lpf")
168 <        leg.Draw("same")
169 <        d.Draw("Sameh")
170 <        if HistogramMaxYmum(d) > MaxY :
171 <          MaxY = HistogramMaxYmum(d)
172 <        if HistogramMaxX(d) > MaxX :
173 <          MaxX = HistogramMaxX(d)
174 <        if HistogramMinX(d) < XMin:
175 <          XMin = HistogramMinX(d)
176 <        col+=1
177 <        fileno+=1
178 <    c.GetXaxis().SetRangeUser(XMin,MaxX)
179 <    c.GetYaxis().SetRangeUser(0.0001,1.2*MaxY)
128 >    c1.cd(1)
129 >    Data = GetHist("../results/AK5Calo_JetMETTau_Run2010A_Compleate.root",1,0,"Data")
130 >    Data.SetMarkerStyle(20)
131 >    Data.SetLineWidth(3)
132 >    Data.SetLineColor(1)
133 >    Data.SetFillColor(1)
134 >    ZJets  = GetHist("../results/AK5Calo_ZJets-madgraph.root",Root.kBlue,1,"Z+Jets (Madgraph)")
135 >    Zinv = GetHist("../results/AK5Calo_Zinvisible_jets.root",Root.kGray,1,"Z->Invisiable")
136 >    WJets = GetHist("../results/AK5Calo_WJets-madgraph.root",Root.kGreen,1,"W+Jets")
137 >    ttbar = GetHist("../results/AK5Calo_ttbarTauola.root",Root.kAzure,1,"TTBar")
138 >    LM0 = GetHist("../results/AK5Calo_LM0.root",Root.kRed,1,"LM0")
139 >    QCD = GetHist("../results/AK5Calo_QCD_AllPtBins_7TeV_Pythia6.root",Root.kGray,1,"QCD")
140 >    # Total = GetHist("../results/AK5Calo_TotalBackgrounds.root",Root.kGreen-3,1,"Standard Model Backgrounds")
141 >
142 >    Total = QCD.Clone()
143 >    Total.Add(Zinv)
144 >    Total.Add(ZJets)
145 >    Total.Add(WJets)
146 >    Total.Add(ttbar)
147 >    Total.SetLineWidth(2)
148 >    Total.SetLineColor(Root.kAzure-4)
149 >    leg.AddEntry(Total,"Standard Model Backgrounds","LPf")
150 >
151 >
152 >    if HistogramMinX(Total) < MinX :
153 >       MinX = HistogramMinX(Total)
154 >    if HistogramMaxX(Total) > MaxX :
155 >       MaxX = HistogramMaxX(Total)
156 >    if HistogramMaxY(Total) > MaxY :
157 >       MaxY = HistogramMaxY(Total)
158 >
159 >    if HistogramMinX(Data) < MinX :
160 >       MinX = HistogramMinX(Data)
161 >    if HistogramMaxX(Data) > MaxX :
162 >       MaxX = HistogramMaxX(Data)
163 >    if HistogramMaxY(Data) > MaxY :
164 >       MaxY = HistogramMaxY(Data)
165 >
166 >
167 >    Total.SetFillColor(Root.kAzure+10)
168 >    # Total.SetFillStyle(3001)
169 >    Total.GetXaxis().SetRangeUser(MinX,MaxX)
170 >    Total.GetYaxis().SetRangeUser(0.00001,MaxY*1.2)
171 >    Total.Draw("9HIST")
172 >    ZJets.Draw("9Sameh")
173 >    Zinv.Draw("9SAMEh")
174 >    WJets.Draw("9SAMEh")
175 >    ttbar.Draw("9SAMEh")
176 >    QCD.Draw("9SAMEh")
177 >    LM0.Draw("9SAMEh")
178 >    Data.Draw("9SAMEP")
179 >
180 >    title = Root.TLatex(0.2,0.95,(DirKeys[dir].GetTitle())+"_"+hist[0:-4])
181 >    title.SetNDC()
182 >    title.Draw()
183 >
184 >    RatioBottom = Total.Clone()
185 >    RatioTop = Data.Clone()
186      RatioTop.Divide(RatioBottom)
187 <    RatioTop.GetYaxis().SetRangeUser(0.,2.)
188 <    RatioTop.GetYaxis().SetTitle("data / sim")
189 <    RatioTop.GetXaxis().SetTitle(d.GetXaxis().GetTitle())
187 >    c1.cd(1).Update()
188 >    # c1.cd(1).SetLogy()
189 >    leg.Draw()
190 >
191 >    # c1.cd(1).Update()
192      c1.cd(2)
193 +    RatioTop.GetXaxis().SetRangeUser(MinX,MaxX)
194 +
195 +    RatioTop.GetYaxis().SetRangeUser(0.,2.0)
196 +    RatioTop.Draw()
197      unity = Root.TLine();
198      unity.SetLineWidth(2);
199      # unity.SetLineStyle(Root.kDashed);
200      unity.SetLineColor(2);
201 <    RatioTop.GetXaxis().SetRangeUser(XMin,MaxX)
202 <    RatioTop.Draw()
203 <    unity.DrawLine(XMin, 1,MaxX, 1);
201 >    unity.DrawLine(MinX, 1,MaxX, 1);
202 >
203 >
204 >
205  
206      if "all" in hist :
207  
# Line 205 | Line 243 | for dir in range(0,len(DirKeys)):
243        a.Close()
244      closeList = []
245   Webpage.write(footer)
208 # mergedPlots.write()
209 # mergedPlots.Close()
210
211
246  
213 #
214 #
215 #
216 #
217 #
218 # File = Root.TFile.Open(RootFileList[1])
219 #
220 #
221 # dirlist = File.GetListOfKeys()
222 # FileList = [dir.GetTitle() for dir in dirlist]
223 # histlist = (dirlist[1].ReadObj()).GetListOfKeys()
224 # histName = [hist.GetName() for hist in histlist]
225 #
226 #
227 #
228 # for Dirs in DirList:
229 #   for hist in histName:
230 #     for Sample in RootFileList:
231 #       Sample = Root.TFile.Open(Sample)
232 #       a = Sample.Get(File)
233 #       b = a.Get(hist)
234 #       b.Draw()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines