8 pad1 = ROOT.TPad(
"pad1",
"pad1", 0, 0.2, 1, 1)
9 pad1.SetBottomMargin(0.15)
15 pad2 = ROOT.TPad(
"pad2",
"pad2", 0, 0, 1, 0.21)
16 pad2.SetTopMargin(0.05)
17 pad2.SetBottomMargin(0.1)
21 h2_axes_ratio = ROOT.TH2D(
"axes_ratio",
"", 10, xMin, xMax, 10, yMin, yMax )
22 h2_axes_ratio.SetStats(0)
23 h2_axes_ratio.GetXaxis().SetLabelSize(0.00)
24 h2_axes_ratio.GetXaxis().SetTickLength(0.09)
25 h2_axes_ratio.GetYaxis().SetNdivisions(5,5,0)
26 h2_axes_ratio.GetYaxis().SetTitleSize(0.13)
27 h2_axes_ratio.GetYaxis().SetTitleOffset(0.37)
28 h2_axes_ratio.GetYaxis().SetLabelSize(0.13)
29 h2_axes_ratio.GetYaxis().SetTitle(
"Ratio")
34 dirnames.append(sys.argv[1])
35 dirnames.append(sys.argv[2])
38 if not os.path.exists(outdir):
40 os.system(
"cp web/index.php %s"%(outdir))
42 names = [
"Reference",
"Other"]
43 if len(sys.argv)==5
and sys.argv[4]==
"vsCMSSW":
44 names = [
"CMSSW",
"mkFit"]
47 names = [sys.argv[4], sys.argv[5]]
53 for d
in range(0, len(dirnames)):
54 fnames.append(dirnames[d]+
"/plots.root")
55 fs.append(ROOT.TFile.Open(fnames[d]))
69 for d
in range(0, len(fnames)):
73 for dkey
in ROOT.gDirectory.GetListOfKeys():
74 if not dkey.IsFolder():
77 subdirs.append(dkey.GetName())
89 for subdir
in subdirs:
90 print "In subdir %s:"%subdir
103 for key
in ROOT.gDirectory.GetListOfKeys():
105 if obj.IsA().InheritsFrom(
"TH1"):
111 thishist[nh].SetLineColor(colors[d])
112 thishist[nh].SetMarkerColor(colors[d])
113 thishist[nh].SetMarkerSize(0.3)
114 thishist[nh].SetMarkerStyle(20)
115 thishist[nh].SetStats(0)
119 if obj.IsA().InheritsFrom(
"TEfficiency"):
124 thiseff_obj[ne].SetLineColor(colors[d])
125 thiseff_obj[ne].SetMarkerColor(colors[d])
126 thiseff_obj[ne].SetMarkerSize(0.3)
127 thiseff_obj[ne].SetMarkerStyle(20)
128 thiseff_pass.append(e.GetPassedHistogram())
129 thiseff_tot .
append(e.GetTotalHistogram())
130 thiseff_pass[ne].Sumw2()
131 thiseff_tot[ne] .Sumw2()
132 effname =
"%s_rate"%(thiseff_pass[ne].GetName())
133 auxeff = thiseff_pass[ne].Clone(effname)
134 auxeff.Divide(thiseff_pass[ne],thiseff_tot[ne],1.0,1.0,
"B")
135 thiseff.append(auxeff)
136 thiseff[ne].SetLineColor(colors[d])
137 thiseff[ne].SetMarkerColor(colors[d])
138 thiseff[ne].SetMarkerSize(0.3)
139 thiseff[ne].SetMarkerStyle(20)
140 thiseff[ne].SetStats(0)
146 eff_ratio_s.append(thiseff)
147 eff_pass_s .
append(thiseff_pass)
148 eff_tot_s .
append(thiseff_tot)
149 eff_obj_s .
append(thiseff_obj)
152 hist_xratio.append(hist_s)
154 eff_ratio .
append(eff_ratio_s)
155 eff_xratio.append(eff_ratio_s)
156 eff_pass .
append(eff_pass_s)
157 eff_tot .
append(eff_tot_s)
158 eff_obj .
append(eff_obj_s)
162 for dd
in range(len(subdirs)):
165 for r
in range(len(hist_xratio[0][dd])):
166 auxratio = hist_xratio[1][dd][r].Clone(
"num")
167 auxden = hist_xratio[0][dd][r].Clone(
"den")
168 intnum = auxratio.Integral(0,-1)
169 intden = auxden .Integral(0,-1)
171 auxratio.Scale(1.0/intnum)
173 auxden.Scale(1.0/intden)
174 auxratio.Divide(auxden)
175 auxratio.SetName(
"ratio")
176 thisratio.append(auxratio)
177 thisratio[r].GetYaxis().SetTitle(
"Ratio")
178 thisratio[r].SetLineColor(colors[1])
179 thisratio[r].SetMarkerColor(colors[1])
180 thisratio[r].SetMarkerSize(0)
181 thisratio[r].SetStats(0)
182 ratios_hist.append(thisratio)
185 for r
in range(len(eff_xratio[0][dd])):
186 auxratio = eff_xratio[1][dd][r].Clone(
"numerator")
187 auxden = eff_xratio[0][dd][r].Clone(
"denominator")
188 auxratio.Divide(auxden)
189 auxratio.SetName(
"ratio")
190 thisratio.append(auxratio)
191 thisratio[r].GetYaxis().SetTitle(
"Ratio")
192 thisratio[r].SetLineColor(colors[1])
193 thisratio[r].SetMarkerColor(colors[1])
194 thisratio[r].SetMarkerSize(0)
195 thisratio[r].SetStats(0)
196 ratios_eff.append(thisratio)
199 ROOT.gStyle.SetOptStat(0)
202 for ns,subdir
in enumerate(subdirs):
203 thisdir =
"%s/%s"%(outdir,subdir)
204 outsubdir.append(thisdir)
205 if not os.path.exists(thisdir):
207 os.system(
"cp web/index.php %s"%(thisdir))
209 for r
in range(len(eff_xratio[0][ns])):
211 outname = eff_obj[0][ns][r].GetName()
213 can = ROOT.TCanvas(
"can_%s"%outname,
"", 600, 600)
228 ttitle = eff_obj[0][ns][r].GetTitle()
229 xmin = ratios_eff[ns][r].GetXaxis().GetBinLowEdge(1)
230 xmax = ratios_eff[ns][r].GetXaxis().GetBinUpEdge(ratios_eff[ns][r].GetNbinsX())
235 xtitle = ratios_eff[ns][r].GetXaxis().GetTitle()
236 ytitle =
"Efficiency" 238 ytitle =
"Duplicate rate" 239 elif "fr" in outname:
241 elif "ineff" in outname:
242 ytitle =
"Inefficiency" 244 haxisMain = ROOT.TH2D(
"haxisMain" ,ttitle,1,xmin ,xmax,1,yminM,ymaxM)
246 haxisMain.GetXaxis().SetTitle(xtitle)
247 haxisMain.GetXaxis().SetTitleOffset(1.2)
248 haxisMain.GetYaxis().SetTitle(ytitle)
249 haxisMain.GetYaxis().SetTitleOffset(1.4)
252 eff_obj[0][ns][r].Draw(
"PE,same")
253 eff_obj[1][ns][r].Draw(
"PE,same")
255 legend = ROOT.TLegend(0.7,0.7, 0.87, 0.87);
256 legend.SetLineColor(0)
257 legend.SetFillColor(0)
258 legend.AddEntry(eff_obj[0][ns][r], names[0],
"PL")
259 legend.AddEntry(eff_obj[1][ns][r], names[1],
"PL")
266 ymin = 0.9*ratios_eff[ns][r].GetMinimum()
267 ymax = 1.1*ratios_eff[ns][r].GetMaximum()
281 line = ROOT.TLine(xmin,1.0,xmax,1.0)
286 ratios_eff[ns][r].Draw(
"PE,same")
293 can.SaveAs(
"%s/%s.png"%(thisdir,outname));
294 can.SaveAs(
"%s/%s.pdf"%(thisdir,outname));
299 tot = [eff_tot[0][ns][r].Integral(), eff_tot[1][ns][r].Integral()]
300 passing = [eff_pass[0][ns][r].Integral(), eff_pass[1][ns][r].Integral()]
303 for d
in range(0,len(tot)):
305 efficiency.append(passing[d]/tot[d])
307 efficiency.append(0.0)
309 reldiff.append(efficiency[d]/efficiency[0])
313 fo = open(
"%s/%s.log"%(thisdir,outname),
"w+")
314 fo.write(
"Totals:" )
315 for d
in range(0,len(tot)):
316 fo.write(
" %d " %
int(tot[d]) ),
317 fo.write(
"\nPassing:" )
318 for d
in range(0,len(tot)):
319 fo.write(
" %d " %
int(passing[d]) ),
320 fo.write(
"\nRate:" )
321 for d
in range(0,len(tot)):
322 fo.write(
" %0.4f " % efficiency[d] ),
323 fo.write(
"\nRatio(/reference):" )
324 for d
in range(0,len(tot)):
325 fo.write(
" %0.4f " % reldiff[d] ),
329 if "_pt_" in outname:
330 outname = outname+
"_logx" 332 can = ROOT.TCanvas(
"can_%s"%outname,
"", 600, 600)
349 ttitle = eff_obj[0][ns][r].GetTitle()
351 xmax = ratios_eff[ns][r].GetXaxis().GetBinUpEdge(ratios_eff[ns][r].GetNbinsX())
356 xtitle = ratios_eff[ns][r].GetXaxis().GetTitle()
357 ytitle =
"Efficiency" 359 ytitle =
"Duplicate rate" 360 elif "fr" in outname:
362 elif "ineff" in outname:
363 ytitle =
"Inefficiency" 365 haxisMain = ROOT.TH2D(
"haxisMain" ,ttitle,1,xmin,xmax,1,yminM,ymaxM)
367 haxisMain.GetXaxis().SetTitle(xtitle)
368 haxisMain.GetXaxis().SetTitleOffset(1.2)
369 haxisMain.GetYaxis().SetTitle(ytitle)
370 haxisMain.GetYaxis().SetTitleOffset(1.4)
373 eff_obj[0][ns][r].Draw(
"PE,same")
374 eff_obj[1][ns][r].Draw(
"PE,same")
376 legend = ROOT.TLegend(0.7, 0.7, 0.87, 0.87);
377 legend.SetLineColor(0)
378 legend.SetFillColor(0)
379 legend.AddEntry(eff_obj[0][ns][r], names[0],
"PL")
380 legend.AddEntry(eff_obj[1][ns][r], names[1],
"PL")
387 ymin = 0.9*ratios_eff[ns][r].GetMinimum()
388 ymax = 1.1*ratios_eff[ns][r].GetMaximum()
402 line = ROOT.TLine(xmin,1.0,xmax,1.0)
407 ratios_eff[ns][r].Draw(
"PE,same")
414 can.SaveAs(
"%s/%s.png"%(thisdir,outname));
415 can.SaveAs(
"%s/%s.pdf"%(thisdir,outname));
428 for r
in range(len(hist_xratio[0][ns])):
430 outname = hist[0][ns][r].GetName()
432 can = ROOT.TCanvas(
"can_%s"%outname,
"", 600, 600)
447 int0 = hist[0][ns][r].Integral(0,-1)
448 int1 = hist[1][ns][r].Integral(0,-1)
449 if int0>0
and doNorm:
450 hist[0][ns][r].Scale(1.0/int0)
451 if int1>0
and doNorm:
452 hist[1][ns][r].Scale(1.0/int1)
454 means = [hist[0][ns][r].GetMean(),hist[1][ns][r].GetMean()]
456 ttitle = hist[0][ns][r].GetTitle()
457 xmin = ratios_hist[ns][r].GetXaxis().GetBinLowEdge(1)
458 xmax = ratios_hist[ns][r].GetXaxis().GetBinUpEdge(ratios_hist[ns][r].GetNbinsX())
460 ymaxM = hist[0][ns][r].GetMaximum()
461 if hist[1][ns][r].GetMaximum() > ymaxM:
462 ymaxM = hist[1][ns][r].GetMaximum()
466 xtitle = hist[0][ns][r].GetXaxis().GetTitle()
467 ytitle =
"Fraction of tracks" 469 ytitle =
"Number of tracks" 471 haxisMain = ROOT.TH2D(
"haxisMain" ,ttitle,1,xmin ,xmax,1,yminM,ymaxM)
473 haxisMain.GetXaxis().SetTitle(xtitle)
474 haxisMain.GetXaxis().SetTitleOffset(1.2)
475 haxisMain.GetYaxis().SetTitle(ytitle)
476 haxisMain.GetYaxis().SetTitleOffset(1.4)
479 hist[0][ns][r].Draw(
"PE,same")
480 hist[1][ns][r].Draw(
"PE,same")
482 legend = ROOT.TLegend(0.6, 0.7, 0.87, 0.87);
483 legend.SetLineColor(0)
484 legend.SetFillColor(0)
485 legend.AddEntry(hist[0][ns][r],
"%s [#mu=%.2f]"%(names[0],means[0]),
"PL")
486 legend.AddEntry(hist[1][ns][r],
"%s [#mu=%.2f]"%(names[1],means[1]),
"PL")
493 ymin = 0.9*ratios_hist[ns][r].GetMinimum()
494 ymax = 1.1*ratios_hist[ns][r].GetMaximum()
508 line = ROOT.TLine(xmin,1.0,xmax,1.0)
513 ratios_hist[ns][r].Draw(
"PE,same")
520 can.SaveAs(
"%s/%s.png"%(thisdir,outname));
521 can.SaveAs(
"%s/%s.pdf"%(thisdir,outname));
def getRatioAxes(xMin, xMax, yMin, yMax)
def getCanvasMainPad(logY)
def getCanvasRatioPad(logY)