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 )' % (len(dsks), os, hs)
107 print 'Number of paths in Test file : %i (objects, histos) = ( %i, %i )' % (len(dpks), op, hp)
108 matching = sset.intersection(pset)
111 if ds[n].__class__.__name__
in histos:
113 print '\nMatching paths : %i' % (len(matching))
116 uniqueReferenceHistos = 0
118 if ds[n].__class__.__name__
in histos:
119 uniqueReferenceHistos += 1
120 print 'Paths unique to Reference file : %i ( %i Histos )' % (len(uSer), uniqueReferenceHistos)
123 print '\t%s : \t%s' % (ds[n], n)
127 if dp[n].__class__.__name__
in histos:
128 uniqueTestHistos += 1
129 print 'Paths unique to Test file : %i ( %i Histos )' % (len(uPar), uniqueTestHistos)
132 print '\t%s : \t%s' % (dp[n], n)
133 print 'Matching Histos to test : %i' % (matchingHistos)
134 print '=' * 80 +
'\n' 135 return (((os, hs), (op, hp)), (uSer, uniqueReferenceHistos), (uPar, uniqueTestHistos), matchingHistos)
153 return (h.GetNbinsX() + 1) * (biny) * (binz)
157 for ibin
in xrange(0, nbins):
158 h1bin = h1.GetBinContent(ibin)
159 h2bin = h2.GetBinContent(ibin)
160 diffbins += (h1bin != h2bin)
182 (((referenceObjects, referenceHistos), (parallObjects, parallHistos)),
183 (uniqueSerPaths, uniqueSerHistos), (uniqueParPaths, uniqueParHistos), mh) = state
193 print 'Neither tuple is Reference Root file reference?' 202 omit = [re.compile(regex)
for regex
in gRegexBlackList]
206 if not any(regex.search(k) !=
None for regex
in omit):
207 if ds[k].__class__.__name__
in histos:
212 if not any(regex.search(k) !=
None for regex
in omit):
213 if dp[k].__class__.__name__
in histos:
230 identityDiffBins = {}
236 zeroIntegralMatch = 0
244 if sh.GetEntries() != ph.GetEntries():
245 diffEntries.append(h)
251 for i
in xrange(sh.GetNbinsX()):
252 sBinError += sh.GetBinError(i)
253 for i
in xrange(ph.GetNbinsX()):
254 pBinError += ph.GetBinError(i)
257 doKS = (bool(sint)
and bool(pint))
and (
258 sBinError > 0
and pBinError > 0)
259 if checkBin2BinIdentity
and doKS:
265 diffIdentity.append(h)
266 identityDiffBins[h] = diffBins
267 if (bool(sint)
and bool(pint))
and (sBinError > 0
and pBinError > 0):
269 kTest = sh.KolmogorovTest(ph)
270 kTestResults[h] = kTest
280 if all((sint, pint))
and (sint == pint):
283 zeroIntegralMatch += 1
285 diffIntegrals.append(h)
289 print 'not found? ', h
292 print '\n\n' +
'-' * 80
293 print 'Summary of histos with different Entries' 297 for e
in diffEntries:
298 print '\t\t\t%s:\t%i != %i' % (e, int(ds[e].GetEntries()), int(dp[e].GetEntries()))
302 print '\n\n' +
'-' * 60
303 print 'Summary of histos which failed Kolmogorov Test' 308 result = kTestResults[e]
309 print '%s\t\t%s :\tK-Test Result :\t %5.16f' % (ds[e].ClassName(), e, result)
313 print '\n\n' +
'-' * 60
314 print 'Summary of histos which failed Integral Check' 318 for e
in diffIntegrals:
320 pc = (diff * 100) / ds[e].
Integral()
321 print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f ' % (ds[e].ClassName(), e, diff, pc)
322 print '-' * 60 +
'\n' 323 print '=' * 80 +
'\n' 326 if checkBin2BinIdentity:
328 print '\n\n' +
'-' * 80
329 print 'Summary of histos with at least one bin with different Entries' 333 for e
in diffIdentity:
334 print '%s\t\t%s: %i different bins' % (ds[e].ClassName(), e, identityDiffBins[e])
337 print '\n' +
'=' * 80
338 print 'Comparison : Reference/Test ROOT Histo files' 339 print '\n\t\tReference\tTest' 340 print '\tObjects : %i\t%i\t\t( p-s = %i )' % (referenceObjects, parallObjects, parallObjects - referenceObjects)
341 print '\tHistos : %i\t%i\t\t( p-s = %i )' % (referenceHistos, parallHistos, parallHistos - referenceHistos)
342 print '\t __________' 343 print '\tTotal : %i\t%i\n' % (referenceHistos + referenceObjects, parallHistos + parallObjects)
344 print 'Objects/Histos unique to Reference File : %i / %i' % (len(uniqueSerPaths) - uniqueSerHistos, uniqueSerHistos)
345 print 'Objects/Histos unique to Test File : %i / %i' % (len(uniqueParPaths) - uniqueParHistos, uniqueParHistos)
346 print '\nMatching Histograms valid for Comparison : %i' % (mh)
347 print '\nOmissions\' patterns : ' 348 for entry
in gRegexBlackList:
349 print '\t%s' % (entry)
350 print '\nHistograms for Comparison (after Omissions) : %i' % (mh - len(gRegexBlackList))
351 print '\n\tHISTOGRAM TESTS : ' 352 print '\t\tKOLMOGOROV TEST : %i' % (kTested)
353 print '\t\tINTEGRAL TEST : %i' % (otherTest)
354 print '\t\tENTRIES TEST : %i' % (xEntries)
355 if checkBin2BinIdentity:
356 print '\t\tBIN2BIN TEST : %i' % (passedIdentity)
358 print '\t\tTested : %i' % (cEntries)
360 print '\n\tDISCREPANCIES : ' 361 print '\t\tK-Test : %i' % (failedKol)
362 print '\t\tIntegrals : %i' % (xIntegrals)
363 print '\t\tEntries : %i' % (xEntries)
364 retval = failedKol + xIntegrals + xEntries + failedIdentity
366 print '\nThe two sets of histograms were not identical' 367 print '\n' +
'=' * 80
374 global gRegexBlackList
376 for blackRegexp
in listString.split(
","):
377 gRegexBlackList.append(blackRegexp)
384 if __name__ ==
'__main__':
385 usage =
"usage: %prog testFile.root referenceFile.root [options]" 386 parser = OptionParser()
387 parser.add_option(
"-b", dest=
"blacklist",
388 help=
'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")')
390 parser.add_option(
"-i",
391 action=
"store_true", dest=
"bin2bin", default=
False,
392 help=
"Check for bin to bin identity")
393 (options, args) = parser.parse_args()
396 print "Wrong number of rootfiles. Usage:" 402 testFile, referenceFile = args
404 tfs = TFile(testFile,
'REC');
print 'opening Test File : %s' % (testFile)
405 tfp = TFile(referenceFile,
'REC');
print 'opening Reference File : %s' % (referenceFile)
411 dref = dict([(n, o)
for n, o
in lref])
412 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)