2 from optparse
import OptionParser
6 backupArgv = sys.argv[:]
13 histos = [
'TH1D',
'TH1F',
'TH2D',
'TH2F',
'TProfile']
30 def rec(o, path=None, lst=None):
35 path = path +
'/' + o.GetName()
37 if 'GetListOfKeys' in dir(o):
38 keys = o.GetListOfKeys()
41 rec(o.Get(name), path, lst)
64 if d[k].__class__.__name__
in histos:
95 print 'Neither tuple is Reference Root file reference?' 107 print '\n' +
'=' * 80
108 print 'Comparison of Paths : Reference vs Test ROOT files' 110 print 'Number of paths in Reference file : %i (objects, histos) = ( %i, %i )' % (
112 print 'Number of paths in Test file : %i (objects, histos) = ( %i, %i )' % (
114 matching = sset.intersection(pset)
117 if ds[n].__class__.__name__
in histos:
119 print '\nMatching paths : %i' % (len(matching))
122 uniqueReferenceHistos = 0
124 if ds[n].__class__.__name__
in histos:
125 uniqueReferenceHistos += 1
126 print 'Paths unique to Reference file : %i ( %i Histos )' % (
127 len(uSer), uniqueReferenceHistos)
130 print '\t%s : \t%s' % (ds[n], n)
134 if dp[n].__class__.__name__
in histos:
135 uniqueTestHistos += 1
136 print 'Paths unique to Test file : %i ( %i Histos )' % (len(uPar),
140 print '\t%s : \t%s' % (dp[n], n)
141 print 'Matching Histos to test : %i' % (matchingHistos)
142 print '=' * 80 +
'\n' 143 return (((os, hs), (op, hp)), (uSer, uniqueReferenceHistos),
144 (uPar, uniqueTestHistos), matchingHistos)
164 return (h.GetNbinsX() + 1) * (biny) * (binz)
168 for ibin
in xrange(0, nbins):
169 h1bin = h1.GetBinContent(ibin)
170 h2bin = h2.GetBinContent(ibin)
171 diffbins += (h1bin != h2bin)
193 (((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
194 (uniqueSerPaths, uniqueSerHistos), (uniqueParPaths,
195 uniqueParHistos), mh) = state
205 print 'Neither tuple is Reference Root file reference?' 214 omit = [re.compile(regex)
for regex
in gRegexBlackList]
218 if not any(regex.search(k) !=
None for regex
in omit):
219 if ds[k].__class__.__name__
in histos:
224 if not any(regex.search(k) !=
None for regex
in omit):
225 if dp[k].__class__.__name__
in histos:
242 identityDiffBins = {}
248 zeroIntegralMatch = 0
256 if sh.GetEntries() != ph.GetEntries():
257 diffEntries.append(h)
263 for i
in xrange(sh.GetNbinsX()):
264 sBinError += sh.GetBinError(i)
265 for i
in xrange(ph.GetNbinsX()):
266 pBinError += ph.GetBinError(i)
269 doKS = (bool(sint)
and bool(pint))
and (sBinError > 0
271 if checkBin2BinIdentity
and doKS:
277 diffIdentity.append(h)
278 identityDiffBins[h] = diffBins
279 if (bool(sint)
and bool(pint))
and (sBinError > 0
282 kTest = sh.KolmogorovTest(ph)
283 kTestResults[h] = kTest
293 if all((sint, pint))
and (sint == pint):
296 zeroIntegralMatch += 1
298 diffIntegrals.append(h)
302 print 'not found? ', h
305 print '\n\n' +
'-' * 80
306 print 'Summary of histos with different Entries' 310 for e
in diffEntries:
311 print '\t\t\t%s:\t%i != %i' % (e, int(ds[e].GetEntries()),
312 int(dp[e].GetEntries()))
316 print '\n\n' +
'-' * 60
317 print 'Summary of histos which failed Kolmogorov Test' 322 result = kTestResults[e]
323 print '%s\t\t%s :\tK-Test Result :\t %5.16f' % (ds[e].ClassName(),
328 print '\n\n' +
'-' * 60
329 print 'Summary of histos which failed Integral Check' 333 for e
in diffIntegrals:
335 pc = (diff * 100) / ds[e].
Integral()
336 print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f ' % (
337 ds[e].ClassName(), e, diff, pc)
338 print '-' * 60 +
'\n' 339 print '=' * 80 +
'\n' 342 if checkBin2BinIdentity:
344 print '\n\n' +
'-' * 80
345 print 'Summary of histos with at least one bin with different Entries' 349 for e
in diffIdentity:
350 print '%s\t\t%s: %i different bins' % (ds[e].ClassName(), e,
354 print '\n' +
'=' * 80
355 print 'Comparison : Reference/Test ROOT Histo files' 356 print '\n\t\tReference\tTest' 357 print '\tObjects : %i\t%i\t\t( p-s = %i )' % (
358 referenceObjects, parallObjects, parallObjects - referenceObjects)
359 print '\tHistos : %i\t%i\t\t( p-s = %i )' % (
360 referenceHistos, parallHistos, parallHistos - referenceHistos)
361 print '\t __________' 362 print '\tTotal : %i\t%i\n' % (referenceHistos + referenceObjects,
363 parallHistos + parallObjects)
364 print 'Objects/Histos unique to Reference File : %i / %i' % (
365 len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos)
366 print 'Objects/Histos unique to Test File : %i / %i' % (
367 len(uniqueParPaths) - uniqueParHistos, uniqueParHistos)
368 print '\nMatching Histograms valid for Comparison : %i' % (mh)
369 print '\nOmissions\' patterns : ' 370 for entry
in gRegexBlackList:
371 print '\t%s' % (entry)
372 print '\nHistograms for Comparison (after Omissions) : %i' % (
373 mh - len(gRegexBlackList))
374 print '\n\tHISTOGRAM TESTS : ' 375 print '\t\tKOLMOGOROV TEST : %i' % (kTested)
376 print '\t\tINTEGRAL TEST : %i' % (otherTest)
377 print '\t\tENTRIES TEST : %i' % (xEntries)
378 if checkBin2BinIdentity:
379 print '\t\tBIN2BIN TEST : %i' % (passedIdentity)
381 print '\t\tTested : %i' % (cEntries)
383 print '\n\tDISCREPANCIES : ' 384 print '\t\tK-Test : %i' % (failedKol)
385 print '\t\tIntegrals : %i' % (xIntegrals)
386 print '\t\tEntries : %i' % (xEntries)
387 retval = failedKol + xIntegrals + xEntries + failedIdentity
389 print '\nThe two sets of histograms were not identical' 390 print '\n' +
'=' * 80
398 global gRegexBlackList
400 for blackRegexp
in listString.split(
","):
401 gRegexBlackList.append(blackRegexp)
408 if __name__ ==
'__main__':
409 usage =
"usage: %prog testFile.root referenceFile.root [options]" 410 parser = OptionParser()
415 'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")' 423 help=
"Check for bin to bin identity")
424 (options, args) = parser.parse_args()
427 print "Wrong number of rootfiles. Usage:" 433 testFile, referenceFile = args
435 tfs = TFile(testFile,
'REC')
436 print 'opening Test File : %s' % (testFile)
437 tfp = TFile(referenceFile,
'REC')
438 print 'opening Reference File : %s' % (referenceFile)
444 dref = dict([(n, o)
for n, o
in lref])
445 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)
GAUDI_API double Integral(const Genfun::AbsFunction &function, const double a, const double b, const GaudiMath::Integration::Type type=GaudiMath::Integration::Adaptive, const GaudiMath::Integration::KronrodRule rule=GaudiMath::Integration::Default, const double epsabs=1.e-10, const double epsrel=1.e-7, const size_t size=1000)