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
219 ((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
220 (uniqueSerPaths, uniqueSerHistos),
221 (uniqueParPaths, uniqueParHistos),
233 print(
"Neither tuple is Reference Root file reference?")
242 omit = [re.compile(regex)
for regex
in gRegexBlackList]
246 if not any(regex.search(k)
is not None for regex
in omit):
247 if ds[k].__class__.__name__
in histos:
252 if not any(regex.search(k)
is not None for regex
in omit):
253 if dp[k].__class__.__name__
in histos:
268 identityDiffBins = {}
274 zeroIntegralMatch = 0
282 if sh.GetEntries() != ph.GetEntries():
283 diffEntries.append(h)
289 for i
in range(sh.GetNbinsX()):
290 sBinError += sh.GetBinError(i)
291 for i
in range(ph.GetNbinsX()):
292 pBinError += ph.GetBinError(i)
295 doKS = (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0)
296 if checkBin2BinIdentity
and doKS:
302 diffIdentity.append(h)
303 identityDiffBins[h] = diffBins
304 if (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0):
306 kTest = sh.KolmogorovTest(ph)
307 kTestResults[h] = kTest
317 if all((sint, pint))
and (sint == pint):
320 zeroIntegralMatch += 1
322 diffIntegrals.append(h)
326 print(
"not found? ", h)
329 print(
"\n\n" +
"-" * 80)
330 print(
"Summary of histos with different Entries")
334 for e
in diffEntries:
336 "\t\t\t%s:\t%i != %i"
337 % (e, int(ds[e].GetEntries()), int(dp[e].GetEntries()))
342 print(
"\n\n" +
"-" * 60)
343 print(
"Summary of histos which failed Kolmogorov Test")
348 result = kTestResults[e]
350 "%s\t\t%s :\tK-Test Result :\t %5.16f" % (ds[e].ClassName(), e, result)
355 print(
"\n\n" +
"-" * 60)
356 print(
"Summary of histos which failed Integral Check")
360 for e
in diffIntegrals:
361 diff = dp[e].Integral() - ds[e].Integral()
362 pc = (diff * 100) / ds[e].Integral()
364 "%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f "
365 % (ds[e].ClassName(), e, diff, pc)
367 print(
"-" * 60 +
"\n")
368 print(
"=" * 80 +
"\n")
371 if checkBin2BinIdentity:
373 print(
"\n\n" +
"-" * 80)
374 print(
"Summary of histos with at least one bin with different Entries")
378 for e
in diffIdentity:
380 "%s\t\t%s: %i different bins"
381 % (ds[e].ClassName(), e, identityDiffBins[e])
385 print(
"\n" +
"=" * 80)
386 print(
"Comparison : Reference/Test ROOT Histo files")
387 print(
"\n\t\tReference\tTest")
389 "\tObjects : %i\t%i\t\t( p-s = %i )"
390 % (referenceObjects, parallObjects, parallObjects - referenceObjects)
393 "\tHistos : %i\t%i\t\t( p-s = %i )"
394 % (referenceHistos, parallHistos, parallHistos - referenceHistos)
396 print(
"\t __________")
399 % (referenceHistos + referenceObjects, parallHistos + parallObjects)
402 "Objects/Histos unique to Reference File : %i / %i"
403 % (len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos)
406 "Objects/Histos unique to Test File : %i / %i"
407 % (len(uniqueParPaths) - uniqueParHistos, uniqueParHistos)
409 print(
"\nMatching Histograms valid for Comparison : %i" % (mh))
410 print(
"\nOmissions' patterns : ")
411 for entry
in gRegexBlackList:
412 print(
"\t%s" % (entry))
414 "\nHistograms for Comparison (after Omissions) : %i"
415 % (mh - len(gRegexBlackList))
417 print(
"\n\tHISTOGRAM TESTS : ")
418 print(
"\t\tKOLMOGOROV TEST : %i" % (kTested))
419 print(
"\t\tINTEGRAL TEST : %i" % (otherTest))
420 print(
"\t\tENTRIES TEST : %i" % (xEntries))
421 if checkBin2BinIdentity:
422 print(
"\t\tBIN2BIN TEST : %i" % (passedIdentity))
424 print(
"\t\tTested : %i" % (cEntries))
426 print(
"\n\tDISCREPANCIES : ")
427 print(
"\t\tK-Test : %i" % (failedKol))
428 print(
"\t\tIntegrals : %i" % (xIntegrals))
429 print(
"\t\tEntries : %i" % (xEntries))
430 retval = failedKol + xIntegrals + xEntries + failedIdentity
432 print(
"\nThe two sets of histograms were not identical")
433 print(
"\n" +
"=" * 80)
441 global gRegexBlackList
443 for blackRegexp
in listString.split(
","):
444 gRegexBlackList.append(blackRegexp)
451 if __name__ ==
"__main__":
452 usage =
"usage: %prog testFile.root referenceFile.root [options]"
453 parser = OptionParser()
457 help=
'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")',
465 help=
"Check for bin to bin identity",
467 (options, args) = parser.parse_args()
470 print(
"Wrong number of rootfiles. Usage:")
476 testFile, referenceFile = args
478 tfs = TFile(testFile,
"REC")
479 print(
"opening Test File : %s" % (testFile))
480 tfp = TFile(referenceFile,
"REC")
481 print(
"opening Reference File : %s" % (referenceFile))
487 dref = dict([(n, o)
for n, o
in lref])
488 dtest = dict([(n, o)
for n, o
in ltest])