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)
62 if d[k].__class__.__name__
in histos:
91 print 'Neither tuple is Reference Root file reference?' 103 print '\n' +
'=' * 80
104 print 'Comparison of Paths : Reference vs Test ROOT files' 106 print 'Number of paths in Reference file : %i (objects, histos) = ( %i, %i )' % (
108 print 'Number of paths in Test file : %i (objects, histos) = ( %i, %i )' % (
110 matching = sset.intersection(pset)
113 if ds[n].__class__.__name__
in histos:
115 print '\nMatching paths : %i' % (len(matching))
118 uniqueReferenceHistos = 0
120 if ds[n].__class__.__name__
in histos:
121 uniqueReferenceHistos += 1
122 print 'Paths unique to Reference file : %i ( %i Histos )' % (
123 len(uSer), uniqueReferenceHistos)
126 print '\t%s : \t%s' % (ds[n], n)
130 if dp[n].__class__.__name__
in histos:
131 uniqueTestHistos += 1
132 print 'Paths unique to Test file : %i ( %i Histos )' % (
133 len(uPar), uniqueTestHistos)
136 print '\t%s : \t%s' % (dp[n], n)
137 print 'Matching Histos to test : %i' % (matchingHistos)
138 print '=' * 80 +
'\n' 139 return (((os, hs), (op, hp)), (uSer, uniqueReferenceHistos), (uPar, uniqueTestHistos), matchingHistos)
157 return (h.GetNbinsX() + 1) * (biny) * (binz)
161 for ibin
in xrange(0, nbins):
162 h1bin = h1.GetBinContent(ibin)
163 h2bin = h2.GetBinContent(ibin)
164 diffbins += (h1bin != h2bin)
186 (((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
187 (uniqueSerPaths, uniqueSerHistos), (uniqueParPaths, uniqueParHistos), mh) = state
197 print 'Neither tuple is Reference Root file reference?' 206 omit = [re.compile(regex)
for regex
in gRegexBlackList]
210 if not any(regex.search(k) !=
None for regex
in omit):
211 if ds[k].__class__.__name__
in histos:
216 if not any(regex.search(k) !=
None for regex
in omit):
217 if dp[k].__class__.__name__
in histos:
234 identityDiffBins = {}
240 zeroIntegralMatch = 0
248 if sh.GetEntries() != ph.GetEntries():
249 diffEntries.append(h)
255 for i
in xrange(sh.GetNbinsX()):
256 sBinError += sh.GetBinError(i)
257 for i
in xrange(ph.GetNbinsX()):
258 pBinError += ph.GetBinError(i)
261 doKS = (bool(sint)
and bool(pint))
and (
262 sBinError > 0
and pBinError > 0)
263 if checkBin2BinIdentity
and doKS:
269 diffIdentity.append(h)
270 identityDiffBins[h] = diffBins
271 if (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0):
273 kTest = sh.KolmogorovTest(ph)
274 kTestResults[h] = kTest
284 if all((sint, pint))
and (sint == pint):
287 zeroIntegralMatch += 1
289 diffIntegrals.append(h)
293 print 'not found? ', h
296 print '\n\n' +
'-' * 80
297 print 'Summary of histos with different Entries' 301 for e
in diffEntries:
302 print '\t\t\t%s:\t%i != %i' % (
303 e, int(ds[e].GetEntries()), int(dp[e].GetEntries()))
307 print '\n\n' +
'-' * 60
308 print 'Summary of histos which failed Kolmogorov Test' 313 result = kTestResults[e]
314 print '%s\t\t%s :\tK-Test Result :\t %5.16f' % (
315 ds[e].ClassName(), e, result)
319 print '\n\n' +
'-' * 60
320 print 'Summary of histos which failed Integral Check' 324 for e
in diffIntegrals:
326 pc = (diff * 100) / ds[e].
Integral()
327 print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f ' % (
328 ds[e].ClassName(), e, diff, pc)
329 print '-' * 60 +
'\n' 330 print '=' * 80 +
'\n' 333 if checkBin2BinIdentity:
335 print '\n\n' +
'-' * 80
336 print 'Summary of histos with at least one bin with different Entries' 340 for e
in diffIdentity:
341 print '%s\t\t%s: %i different bins' % (
342 ds[e].ClassName(), e, identityDiffBins[e])
345 print '\n' +
'=' * 80
346 print 'Comparison : Reference/Test ROOT Histo files' 347 print '\n\t\tReference\tTest' 348 print '\tObjects : %i\t%i\t\t( p-s = %i )' % (referenceObjects,
349 parallObjects, parallObjects - referenceObjects)
350 print '\tHistos : %i\t%i\t\t( p-s = %i )' % (referenceHistos,
351 parallHistos, parallHistos - referenceHistos)
352 print '\t __________' 353 print '\tTotal : %i\t%i\n' % (
354 referenceHistos + referenceObjects, parallHistos + parallObjects)
355 print 'Objects/Histos unique to Reference File : %i / %i' % (
356 len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos)
357 print 'Objects/Histos unique to Test File : %i / %i' % (
358 len(uniqueParPaths) - uniqueParHistos, uniqueParHistos)
359 print '\nMatching Histograms valid for Comparison : %i' % (mh)
360 print '\nOmissions\' patterns : ' 361 for entry
in gRegexBlackList:
362 print '\t%s' % (entry)
363 print '\nHistograms for Comparison (after Omissions) : %i' % (
364 mh - len(gRegexBlackList))
365 print '\n\tHISTOGRAM TESTS : ' 366 print '\t\tKOLMOGOROV TEST : %i' % (kTested)
367 print '\t\tINTEGRAL TEST : %i' % (otherTest)
368 print '\t\tENTRIES TEST : %i' % (xEntries)
369 if checkBin2BinIdentity:
370 print '\t\tBIN2BIN TEST : %i' % (passedIdentity)
372 print '\t\tTested : %i' % (cEntries)
374 print '\n\tDISCREPANCIES : ' 375 print '\t\tK-Test : %i' % (failedKol)
376 print '\t\tIntegrals : %i' % (xIntegrals)
377 print '\t\tEntries : %i' % (xEntries)
378 retval = failedKol + xIntegrals + xEntries + failedIdentity
380 print '\nThe two sets of histograms were not identical' 381 print '\n' +
'=' * 80
388 global gRegexBlackList
390 for blackRegexp
in listString.split(
","):
391 gRegexBlackList.append(blackRegexp)
398 if __name__ ==
'__main__':
399 usage =
"usage: %prog testFile.root referenceFile.root [options]" 400 parser = OptionParser()
401 parser.add_option(
"-b", dest=
"blacklist",
402 help=
'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")')
404 parser.add_option(
"-i",
405 action=
"store_true", dest=
"bin2bin", default=
False,
406 help=
"Check for bin to bin identity")
407 (options, args) = parser.parse_args()
410 print "Wrong number of rootfiles. Usage:" 416 testFile, referenceFile = args
418 tfs = TFile(testFile,
'REC')
419 print 'opening Test File : %s' % (testFile)
420 tfp = TFile(referenceFile,
'REC')
421 print 'opening Reference File : %s' % (referenceFile)
427 dref = dict([(n, o)
for n, o
in lref])
428 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)