106 def MakeComparisonPlot(self, hists, path):
107 def SetBounds(hists, ymin=0, ymax=0):
108 if (ymin==0 and ymax==0):
109 ymin =
min( [ h.GetMinimum()
for h
in hists ] )
110 ymax =
min( [ h.GetMaximum()
for h
in hists ] )
111 if ymin>0 and ymax>0:
112 ymin = 0
113 else:
114 ymin = ymin - 0.15*abs(ymin)
115 ymax = ymax+ 0.15*ymax
116
117
118
119 hists[0].SetMinimum(ymin)
120 hists[0].SetMaximum(ymax)
121 return hists[0]
122
123
124
125
126
127
128
129 canvas = ROOT.TCanvas( "", "", 900, 900 )
130 padMain = ROOT.TPad( 'padMain', 'padMain', 0, 0.3, 1, 1 )
131 padMain.SetBottomMargin( 0.02 )
132 padMain.Draw()
133
134 padRatio = ROOT.TPad( 'padRatio', 'padRatio', 0, 0, 1, 0.3 )
135 padRatio.SetTopMargin( 0.01 )
136 padRatio.SetBottomMargin( 0.25 )
137 padRatio.Draw()
138 ROOT.TLine()
139 padMain.cd()
140
141 leg = ROOT.TLegend(0.82,0.78,0.96,0.94)
142
143
144 leg.SetFillStyle(0)
145 leg.SetBorderSize(0)
146 leg.SetTextFont(43)
147 leg.SetTextSizePixels(32)
148
149 refHist = hists[0]
150 refHist.SetLineColor(17)
151
152
153
159 for i in range(0,len(hists)):
160 leg.AddEntry(hists[i], LABELS[i], 'lp')
161
162 if self.DoNormalization and not "_Eff_" in refHist.GetName() and not "_eff" in refHist.GetName() and not "_Eff" in refHist.GetName():
163 for h in hists:
164 n = h.Integral()
165 if n>0:
166 h.Scale(1./n)
167
168 refHist = SetBounds(hists)
169
170 ref_textsize = 32./(padMain.GetWh()*padMain.GetAbsHNDC())
171 refHist.GetYaxis().SetLabelSize( ref_textsize )
172 refHist.GetXaxis().SetLabelSize( 0 )
173 refHist.GetXaxis().SetTitleSize( 0 )
174 refHist.GetYaxis().SetTitleSize( 1.3*ref_textsize )
175 refHist.GetYaxis().SetTitleOffset(1)
176 refHist.GetYaxis().SetTitleColor( kAzure )
177
178
179
180 refHist.SetMarkerSize(0)
181 refHist.SetLineColor(ROOT.kRed)
182
183
184
185
186 histmax = refHist
187 histmax.DrawCopy('e')
188
189
190
191
192
193
194
195 nh=0
196 for h in hists:
197 if h is not histmax:
198 if h==refHist:
199 h.DrawCopy('histsame')
200 else:
201 nh=nh+1
202 if nh>1:
203 h.SetMarkerStyle(0)
204 h.SetMarkerColor(0)
205 h.SetLineColor(8)
206 h.SetLineStyle(ROOT.kDashed)
207 h.DrawCopy('ehistsame')
208
209
210
211
212
213
214
215
216 leg.Draw()
217 padRatio.cd()
218
219 for h in hists:
220 if h is refHist: continue
221 ratioHist = h.Clone()
222 ratioHist.Divide(refHist)
223 ratioHist = SetBounds( [ratioHist, ratioHist], 0.84,1.16)
224 for i in range(ratioHist.GetNbinsX()):
225 nref = refHist.GetBinContent(i)
226 ntest = h.GetBinContent(i)
227 if nref == 0 or ntest == 0:
228 ratioHist.SetBinError(i, 0)
229 else:
230
231 error = nref/ntest*
max(refHist.GetBinError(i)/nref, h.GetBinError(i)/ntest)
232 ratioHist.SetBinError(i, error)
233
234 ratioHist_textsize = 32./(padRatio.GetWh()*padRatio.GetAbsHNDC())
235 ratioHist.GetYaxis().SetLabelSize( ratioHist_textsize )
236 ratioHist.GetXaxis().SetLabelSize( ratioHist_textsize )
237 ratioHist.GetXaxis().SetTitleSize( 1.2*ratioHist_textsize )
238 ratioHist.GetXaxis().SetTitleOffset(0.75)
239 ratioHist.GetXaxis().SetTitleColor(kAzure)
240 ratioHist.GetYaxis().SetTitleSize( ratioHist_textsize )
241 ratioHist.GetYaxis().SetTitleOffset(0.6)
242
243
244 ratioHist.SetLineColor(ROOT.kBlack)
245 ratioHist.SetMarkerStyle(24)
246 ratioHist.SetYTitle("test / ref")
247 if h == hists[1]:
248 ratioHist.DrawCopy("p")
249 lineRatio = ROOT.TLine( ratioHist.GetXaxis().GetXmin(), 1,
250 ratioHist.GetXaxis().GetXmax(), 1 )
251 lineRatio.SetLineColor( ROOT.kRed )
252 lineRatio.SetLineWidth( 2 )
253 lineRatio.Draw("same")
254 else:
255 ratioHist.SetMarkerStyle(25)
256 ratioHist.SetMarkerColor(8)
257 ratioHist.SetLineColor(8)
258 ratioHist.DrawCopy("psame")
259
260 npath = ""
261 if not self.structDirs:
262 npath = path[path.find(":/")+2:] + "/"
263 npath = re.sub(r"[:,./]", "_", npath+"/")
264
265 canvas.cd()
266 t = ROOT.TLatex();
267 t.SetNDC()
268 t.SetTextColor(1)
269 t.SetTextSize(0.03);
270 t.DrawLatex(0.,0.97,refHist.GetName())
271
272 canvas.SaveAs(npath + refHist.GetName() + ".pdf")
273 canvas.Close()
274
275