12 from __future__
import print_function
16 from optparse
import OptionParser
19 backupArgv = sys.argv[:]
21 from ROOT
import TFile
27 histos = [
"TH1D",
"TH1F",
"TH2D",
"TH2F",
"TProfile"]
44 def rec(o, path=None, lst=None):
49 path = path +
"/" + o.GetName()
51 if "GetListOfKeys" in dir(o):
52 keys = o.GetListOfKeys()
55 rec(o.Get(name), path, lst)
78 if d[k].__class__.__name__
in histos:
109 print(
"Neither tuple is Reference Root file reference?")
121 print(
"\n" +
"=" * 80)
122 print(
"Comparison of Paths : Reference vs Test ROOT files")
125 "Number of paths in Reference file : %i (objects, histos) = ( %i, %i )"
126 % (len(dsks), os, hs)
129 "Number of paths in Test file : %i (objects, histos) = ( %i, %i )"
130 % (len(dpks), op, hp)
132 matching = sset.intersection(pset)
135 if ds[n].__class__.__name__
in histos:
137 print(
"\nMatching paths : %i" % (len(matching)))
140 uniqueReferenceHistos = 0
142 if ds[n].__class__.__name__
in histos:
143 uniqueReferenceHistos += 1
145 "Paths unique to Reference file : %i ( %i Histos )"
146 % (len(uSer), uniqueReferenceHistos)
150 print(
"\t%s : \t%s" % (ds[n], n))
154 if dp[n].__class__.__name__
in histos:
155 uniqueTestHistos += 1
157 "Paths unique to Test file : %i ( %i Histos )" % (len(uPar), uniqueTestHistos)
161 print(
"\t%s : \t%s" % (dp[n], n))
162 print(
"Matching Histos to test : %i" % (matchingHistos))
163 print(
"=" * 80 +
"\n")
165 ((os, hs), (op, hp)),
166 (uSer, uniqueReferenceHistos),
167 (uPar, uniqueTestHistos),
189 return (h.GetNbinsX() + 1) * (biny) * (binz)
193 for ibin
in range(0, nbins):
194 h1bin = h1.GetBinContent(ibin)
195 h2bin = h2.GetBinContent(ibin)
196 diffbins += h1bin != h2bin
218 ((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
219 (uniqueSerPaths, uniqueSerHistos),
220 (uniqueParPaths, uniqueParHistos),
232 print(
"Neither tuple is Reference Root file reference?")
241 omit = [re.compile(regex)
for regex
in gRegexBlackList]
245 if not any(regex.search(k)
is not None for regex
in omit):
246 if ds[k].__class__.__name__
in histos:
251 if not any(regex.search(k)
is not None for regex
in omit):
252 if dp[k].__class__.__name__
in histos:
267 identityDiffBins = {}
273 zeroIntegralMatch = 0
281 if sh.GetEntries() != ph.GetEntries():
282 diffEntries.append(h)
288 for i
in range(sh.GetNbinsX()):
289 sBinError += sh.GetBinError(i)
290 for i
in range(ph.GetNbinsX()):
291 pBinError += ph.GetBinError(i)
294 doKS = (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0)
295 if checkBin2BinIdentity
and doKS:
301 diffIdentity.append(h)
302 identityDiffBins[h] = diffBins
303 if (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0):
305 kTest = sh.KolmogorovTest(ph)
306 kTestResults[h] = kTest
316 if all((sint, pint))
and (sint == pint):
319 zeroIntegralMatch += 1
321 diffIntegrals.append(h)
325 print(
"not found? ", h)
328 print(
"\n\n" +
"-" * 80)
329 print(
"Summary of histos with different Entries")
333 for e
in diffEntries:
335 "\t\t\t%s:\t%i != %i"
336 % (e, int(ds[e].GetEntries()), int(dp[e].GetEntries()))
341 print(
"\n\n" +
"-" * 60)
342 print(
"Summary of histos which failed Kolmogorov Test")
347 result = kTestResults[e]
349 "%s\t\t%s :\tK-Test Result :\t %5.16f" % (ds[e].ClassName(), e, result)
354 print(
"\n\n" +
"-" * 60)
355 print(
"Summary of histos which failed Integral Check")
359 for e
in diffIntegrals:
360 diff = dp[e].Integral() - ds[e].Integral()
361 pc = (diff * 100) / ds[e].Integral()
363 "%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f "
364 % (ds[e].ClassName(), e, diff, pc)
366 print(
"-" * 60 +
"\n")
367 print(
"=" * 80 +
"\n")
370 if checkBin2BinIdentity:
372 print(
"\n\n" +
"-" * 80)
373 print(
"Summary of histos with at least one bin with different Entries")
377 for e
in diffIdentity:
379 "%s\t\t%s: %i different bins"
380 % (ds[e].ClassName(), e, identityDiffBins[e])
384 print(
"\n" +
"=" * 80)
385 print(
"Comparison : Reference/Test ROOT Histo files")
386 print(
"\n\t\tReference\tTest")
388 "\tObjects : %i\t%i\t\t( p-s = %i )"
389 % (referenceObjects, parallObjects, parallObjects - referenceObjects)
392 "\tHistos : %i\t%i\t\t( p-s = %i )"
393 % (referenceHistos, parallHistos, parallHistos - referenceHistos)
395 print(
"\t __________")
398 % (referenceHistos + referenceObjects, parallHistos + parallObjects)
401 "Objects/Histos unique to Reference File : %i / %i"
402 % (len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos)
405 "Objects/Histos unique to Test File : %i / %i"
406 % (len(uniqueParPaths) - uniqueParHistos, uniqueParHistos)
408 print(
"\nMatching Histograms valid for Comparison : %i" % (mh))
409 print(
"\nOmissions' patterns : ")
410 for entry
in gRegexBlackList:
411 print(
"\t%s" % (entry))
413 "\nHistograms for Comparison (after Omissions) : %i"
414 % (mh - len(gRegexBlackList))
416 print(
"\n\tHISTOGRAM TESTS : ")
417 print(
"\t\tKOLMOGOROV TEST : %i" % (kTested))
418 print(
"\t\tINTEGRAL TEST : %i" % (otherTest))
419 print(
"\t\tENTRIES TEST : %i" % (xEntries))
420 if checkBin2BinIdentity:
421 print(
"\t\tBIN2BIN TEST : %i" % (passedIdentity))
423 print(
"\t\tTested : %i" % (cEntries))
425 print(
"\n\tDISCREPANCIES : ")
426 print(
"\t\tK-Test : %i" % (failedKol))
427 print(
"\t\tIntegrals : %i" % (xIntegrals))
428 print(
"\t\tEntries : %i" % (xEntries))
429 retval = failedKol + xIntegrals + xEntries + failedIdentity
431 print(
"\nThe two sets of histograms were not identical")
432 print(
"\n" +
"=" * 80)
440 global gRegexBlackList
442 for blackRegexp
in listString.split(
","):
443 gRegexBlackList.append(blackRegexp)
450 if __name__ ==
"__main__":
451 usage =
"usage: %prog testFile.root referenceFile.root [options]"
452 parser = OptionParser()
456 help=
'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")',
464 help=
"Check for bin to bin identity",
466 (options, args) = parser.parse_args()
469 print(
"Wrong number of rootfiles. Usage:")
475 testFile, referenceFile = args
477 tfs = TFile(testFile,
"REC")
478 print(
"opening Test File : %s" % (testFile))
479 tfp = TFile(referenceFile,
"REC")
480 print(
"opening Reference File : %s" % (referenceFile))
486 dref = dict([(n, o)
for n, o
in lref])
487 dtest = dict([(n, o)
for n, o
in ltest])