12 from __future__
import print_function
13 from optparse
import OptionParser
17 backupArgv = sys.argv[:]
19 from ROOT
import TFile
24 histos = [
'TH1D',
'TH1F',
'TH2D',
'TH2F',
'TProfile']
41 def rec(o, path=None, lst=None):
46 path = path +
'/' + o.GetName()
48 if 'GetListOfKeys' in dir(o):
49 keys = o.GetListOfKeys()
52 rec(o.Get(name), path, lst)
75 if d[k].__class__.__name__
in histos:
106 print(
'Neither tuple is Reference Root file reference?')
118 print(
'\n' +
'=' * 80)
119 print(
'Comparison of Paths : Reference vs Test ROOT files')
122 'Number of paths in Reference file : %i (objects, histos) = ( %i, %i )'
123 % (len(dsks), os, hs))
124 print(
'Number of paths in Test file : %i (objects, histos) = ( %i, %i )' %
126 matching = sset.intersection(pset)
129 if ds[n].__class__.__name__
in histos:
131 print(
'\nMatching paths : %i' % (len(matching)))
134 uniqueReferenceHistos = 0
136 if ds[n].__class__.__name__
in histos:
137 uniqueReferenceHistos += 1
138 print(
'Paths unique to Reference file : %i ( %i Histos )' %
139 (len(uSer), uniqueReferenceHistos))
142 print(
'\t%s : \t%s' % (ds[n], n))
146 if dp[n].__class__.__name__
in histos:
147 uniqueTestHistos += 1
148 print(
'Paths unique to Test file : %i ( %i Histos )' % (len(uPar),
152 print(
'\t%s : \t%s' % (dp[n], n))
153 print(
'Matching Histos to test : %i' % (matchingHistos))
154 print(
'=' * 80 +
'\n')
155 return (((os, hs), (op, hp)), (uSer, uniqueReferenceHistos),
156 (uPar, uniqueTestHistos), matchingHistos)
176 return (h.GetNbinsX() + 1) * (biny) * (binz)
180 for ibin
in range(0, nbins):
181 h1bin = h1.GetBinContent(ibin)
182 h2bin = h2.GetBinContent(ibin)
183 diffbins += (h1bin != h2bin)
205 (((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
206 (uniqueSerPaths, uniqueSerHistos), (uniqueParPaths,
207 uniqueParHistos), mh) = state
217 print(
'Neither tuple is Reference Root file reference?')
226 omit = [re.compile(regex)
for regex
in gRegexBlackList]
230 if not any(regex.search(k) !=
None for regex
in omit):
231 if ds[k].__class__.__name__
in histos:
236 if not any(regex.search(k) !=
None for regex
in omit):
237 if dp[k].__class__.__name__
in histos:
254 identityDiffBins = {}
260 zeroIntegralMatch = 0
268 if sh.GetEntries() != ph.GetEntries():
269 diffEntries.append(h)
275 for i
in range(sh.GetNbinsX()):
276 sBinError += sh.GetBinError(i)
277 for i
in range(ph.GetNbinsX()):
278 pBinError += ph.GetBinError(i)
281 doKS = (bool(sint)
and bool(pint))
and (sBinError > 0
283 if checkBin2BinIdentity
and doKS:
289 diffIdentity.append(h)
290 identityDiffBins[h] = diffBins
291 if (bool(sint)
and bool(pint))
and (sBinError > 0
294 kTest = sh.KolmogorovTest(ph)
295 kTestResults[h] = kTest
305 if all((sint, pint))
and (sint == pint):
308 zeroIntegralMatch += 1
310 diffIntegrals.append(h)
314 print(
'not found? ', h)
317 print(
'\n\n' +
'-' * 80)
318 print(
'Summary of histos with different Entries')
322 for e
in diffEntries:
323 print(
'\t\t\t%s:\t%i != %i' % (e, int(ds[e].GetEntries()),
324 int(dp[e].GetEntries())))
328 print(
'\n\n' +
'-' * 60)
329 print(
'Summary of histos which failed Kolmogorov Test')
334 result = kTestResults[e]
335 print(
'%s\t\t%s :\tK-Test Result :\t %5.16f' % (ds[e].ClassName(),
340 print(
'\n\n' +
'-' * 60)
341 print(
'Summary of histos which failed Integral Check')
345 for e
in diffIntegrals:
346 diff = dp[e].Integral() - ds[e].Integral()
347 pc = (diff * 100) / ds[e].Integral()
349 '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f '
350 % (ds[e].ClassName(), e, diff, pc))
351 print(
'-' * 60 +
'\n')
352 print(
'=' * 80 +
'\n')
355 if checkBin2BinIdentity:
357 print(
'\n\n' +
'-' * 80)
358 print(
'Summary of histos with at least one bin with different Entries')
362 for e
in diffIdentity:
363 print(
'%s\t\t%s: %i different bins' % (ds[e].ClassName(), e,
364 identityDiffBins[e]))
367 print(
'\n' +
'=' * 80)
368 print(
'Comparison : Reference/Test ROOT Histo files')
369 print(
'\n\t\tReference\tTest')
370 print(
'\tObjects : %i\t%i\t\t( p-s = %i )' %
371 (referenceObjects, parallObjects, parallObjects - referenceObjects))
372 print(
'\tHistos : %i\t%i\t\t( p-s = %i )' %
373 (referenceHistos, parallHistos, parallHistos - referenceHistos))
374 print(
'\t __________')
375 print(
'\tTotal : %i\t%i\n' % (referenceHistos + referenceObjects,
376 parallHistos + parallObjects))
377 print(
'Objects/Histos unique to Reference File : %i / %i' %
378 (len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos))
379 print(
'Objects/Histos unique to Test File : %i / %i' %
380 (len(uniqueParPaths) - uniqueParHistos, uniqueParHistos))
381 print(
'\nMatching Histograms valid for Comparison : %i' % (mh))
382 print(
'\nOmissions\' patterns : ')
383 for entry
in gRegexBlackList:
384 print(
'\t%s' % (entry))
385 print(
'\nHistograms for Comparison (after Omissions) : %i' %
386 (mh - len(gRegexBlackList)))
387 print(
'\n\tHISTOGRAM TESTS : ')
388 print(
'\t\tKOLMOGOROV TEST : %i' % (kTested))
389 print(
'\t\tINTEGRAL TEST : %i' % (otherTest))
390 print(
'\t\tENTRIES TEST : %i' % (xEntries))
391 if checkBin2BinIdentity:
392 print(
'\t\tBIN2BIN TEST : %i' % (passedIdentity))
394 print(
'\t\tTested : %i' % (cEntries))
396 print(
'\n\tDISCREPANCIES : ')
397 print(
'\t\tK-Test : %i' % (failedKol))
398 print(
'\t\tIntegrals : %i' % (xIntegrals))
399 print(
'\t\tEntries : %i' % (xEntries))
400 retval = failedKol + xIntegrals + xEntries + failedIdentity
402 print(
'\nThe two sets of histograms were not identical')
403 print(
'\n' +
'=' * 80)
411 global gRegexBlackList
413 for blackRegexp
in listString.split(
","):
414 gRegexBlackList.append(blackRegexp)
421 if __name__ ==
'__main__':
422 usage =
"usage: %prog testFile.root referenceFile.root [options]"
423 parser = OptionParser()
428 'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")'
436 help=
"Check for bin to bin identity")
437 (options, args) = parser.parse_args()
440 print(
"Wrong number of rootfiles. Usage:")
446 testFile, referenceFile = args
448 tfs = TFile(testFile,
'REC')
449 print(
'opening Test File : %s' % (testFile))
450 tfp = TFile(referenceFile,
'REC')
451 print(
'opening Reference File : %s' % (referenceFile))
457 dref = dict([(n, o)
for n, o
in lref])
458 dtest = dict([(n, o)
for n, o
in ltest])