2 from __future__
import print_function
3 from optparse
import OptionParser
7 backupArgv = sys.argv[:]
14 histos = [
'TH1D',
'TH1F',
'TH2D',
'TH2F',
'TProfile']
31 def rec(o, path=None, lst=None):
36 path = path +
'/' + o.GetName()
38 if 'GetListOfKeys' in dir(o):
39 keys = o.GetListOfKeys()
42 rec(o.Get(name), path, lst)
65 if d[k].__class__.__name__
in histos:
96 print(
'Neither tuple is Reference Root file reference?')
108 print(
'\n' +
'=' * 80)
109 print(
'Comparison of Paths : Reference vs Test ROOT files')
112 'Number of paths in Reference file : %i (objects, histos) = ( %i, %i )' 113 % (len(dsks), os, hs))
114 print(
'Number of paths in Test file : %i (objects, histos) = ( %i, %i )' %
116 matching = sset.intersection(pset)
119 if ds[n].__class__.__name__
in histos:
121 print(
'\nMatching paths : %i' % (len(matching)))
124 uniqueReferenceHistos = 0
126 if ds[n].__class__.__name__
in histos:
127 uniqueReferenceHistos += 1
128 print(
'Paths unique to Reference file : %i ( %i Histos )' %
129 (len(uSer), uniqueReferenceHistos))
132 print(
'\t%s : \t%s' % (ds[n], n))
136 if dp[n].__class__.__name__
in histos:
137 uniqueTestHistos += 1
138 print(
'Paths unique to Test file : %i ( %i Histos )' % (len(uPar),
142 print(
'\t%s : \t%s' % (dp[n], n))
143 print(
'Matching Histos to test : %i' % (matchingHistos))
144 print(
'=' * 80 +
'\n')
145 return (((os, hs), (op, hp)), (uSer, uniqueReferenceHistos),
146 (uPar, uniqueTestHistos), matchingHistos)
166 return (h.GetNbinsX() + 1) * (biny) * (binz)
170 for ibin
in range(0, nbins):
171 h1bin = h1.GetBinContent(ibin)
172 h2bin = h2.GetBinContent(ibin)
173 diffbins += (h1bin != h2bin)
195 (((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
196 (uniqueSerPaths, uniqueSerHistos), (uniqueParPaths,
197 uniqueParHistos), mh) = state
207 print(
'Neither tuple is Reference Root file reference?')
216 omit = [re.compile(regex)
for regex
in gRegexBlackList]
220 if not any(regex.search(k) !=
None for regex
in omit):
221 if ds[k].__class__.__name__
in histos:
226 if not any(regex.search(k) !=
None for regex
in omit):
227 if dp[k].__class__.__name__
in histos:
244 identityDiffBins = {}
250 zeroIntegralMatch = 0
258 if sh.GetEntries() != ph.GetEntries():
259 diffEntries.append(h)
265 for i
in range(sh.GetNbinsX()):
266 sBinError += sh.GetBinError(i)
267 for i
in range(ph.GetNbinsX()):
268 pBinError += ph.GetBinError(i)
271 doKS = (bool(sint)
and bool(pint))
and (sBinError > 0
273 if checkBin2BinIdentity
and doKS:
279 diffIdentity.append(h)
280 identityDiffBins[h] = diffBins
281 if (bool(sint)
and bool(pint))
and (sBinError > 0
284 kTest = sh.KolmogorovTest(ph)
285 kTestResults[h] = kTest
295 if all((sint, pint))
and (sint == pint):
298 zeroIntegralMatch += 1
300 diffIntegrals.append(h)
304 print(
'not found? ', h)
307 print(
'\n\n' +
'-' * 80)
308 print(
'Summary of histos with different Entries')
312 for e
in diffEntries:
313 print(
'\t\t\t%s:\t%i != %i' % (e, int(ds[e].GetEntries()),
314 int(dp[e].GetEntries())))
318 print(
'\n\n' +
'-' * 60)
319 print(
'Summary of histos which failed Kolmogorov Test')
324 result = kTestResults[e]
325 print(
'%s\t\t%s :\tK-Test Result :\t %5.16f' % (ds[e].ClassName(),
330 print(
'\n\n' +
'-' * 60)
331 print(
'Summary of histos which failed Integral Check')
335 for e
in diffIntegrals:
336 diff = dp[e].Integral() - ds[e].Integral()
337 pc = (diff * 100) / ds[e].Integral()
339 '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f ' 340 % (ds[e].ClassName(), e, diff, pc))
341 print(
'-' * 60 +
'\n')
342 print(
'=' * 80 +
'\n')
345 if checkBin2BinIdentity:
347 print(
'\n\n' +
'-' * 80)
348 print(
'Summary of histos with at least one bin with different Entries')
352 for e
in diffIdentity:
353 print(
'%s\t\t%s: %i different bins' % (ds[e].ClassName(), e,
354 identityDiffBins[e]))
357 print(
'\n' +
'=' * 80)
358 print(
'Comparison : Reference/Test ROOT Histo files')
359 print(
'\n\t\tReference\tTest')
360 print(
'\tObjects : %i\t%i\t\t( p-s = %i )' %
361 (referenceObjects, parallObjects, parallObjects - referenceObjects))
362 print(
'\tHistos : %i\t%i\t\t( p-s = %i )' %
363 (referenceHistos, parallHistos, parallHistos - referenceHistos))
364 print(
'\t __________')
365 print(
'\tTotal : %i\t%i\n' % (referenceHistos + referenceObjects,
366 parallHistos + parallObjects))
367 print(
'Objects/Histos unique to Reference File : %i / %i' %
368 (len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos))
369 print(
'Objects/Histos unique to Test File : %i / %i' %
370 (len(uniqueParPaths) - uniqueParHistos, uniqueParHistos))
371 print(
'\nMatching Histograms valid for Comparison : %i' % (mh))
372 print(
'\nOmissions\' patterns : ')
373 for entry
in gRegexBlackList:
374 print(
'\t%s' % (entry))
375 print(
'\nHistograms for Comparison (after Omissions) : %i' %
376 (mh - len(gRegexBlackList)))
377 print(
'\n\tHISTOGRAM TESTS : ')
378 print(
'\t\tKOLMOGOROV TEST : %i' % (kTested))
379 print(
'\t\tINTEGRAL TEST : %i' % (otherTest))
380 print(
'\t\tENTRIES TEST : %i' % (xEntries))
381 if checkBin2BinIdentity:
382 print(
'\t\tBIN2BIN TEST : %i' % (passedIdentity))
384 print(
'\t\tTested : %i' % (cEntries))
386 print(
'\n\tDISCREPANCIES : ')
387 print(
'\t\tK-Test : %i' % (failedKol))
388 print(
'\t\tIntegrals : %i' % (xIntegrals))
389 print(
'\t\tEntries : %i' % (xEntries))
390 retval = failedKol + xIntegrals + xEntries + failedIdentity
392 print(
'\nThe two sets of histograms were not identical')
393 print(
'\n' +
'=' * 80)
401 global gRegexBlackList
403 for blackRegexp
in listString.split(
","):
404 gRegexBlackList.append(blackRegexp)
411 if __name__ ==
'__main__':
412 usage =
"usage: %prog testFile.root referenceFile.root [options]" 413 parser = OptionParser()
418 'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")' 426 help=
"Check for bin to bin identity")
427 (options, args) = parser.parse_args()
430 print(
"Wrong number of rootfiles. Usage:")
436 testFile, referenceFile = args
438 tfs = TFile(testFile,
'REC')
439 print(
'opening Test File : %s' % (testFile))
440 tfp = TFile(referenceFile,
'REC')
441 print(
'opening Reference File : %s' % (referenceFile))
447 dref = dict([(n, o)
for n, o
in lref])
448 dtest = dict([(n, o)
for n, o
in ltest])
def rec(o, path=None, lst=None)
def compareHistos(t1, t2, state, checkBin2BinIdentity)
def extractBlacklist(listString)
def bin2binIdentity(h1, h2)
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.