2 from optparse
import OptionParser
13 histos = [
'TH1D',
'TH1F',
'TH2D',
'TH2F',
'TProfile']
28 def rec( o, path=None, lst=None ) :
29 if not path : path =
'/stat' ; lst = []
30 else : path = path +
'/' + o.GetName()
31 lst.append( (path,o) )
32 if 'GetListOfKeys' in dir(o) :
33 keys = o.GetListOfKeys()
36 rec( o.Get(name), path, lst )
54 if d[k].__class__.__name__
in histos : hists += 1
72 if t1[0] == ref : ds = t1[1] ; dp = t2[1]
73 elif t2[0] == ref : ds = t2[1] ; dp = t1[1]
74 else :
print 'Neither tuple is Reference Root file reference?' ;
return 76 dsks = ds.keys() ; dpks = dp.keys()
77 dsks.sort() ; dpks.sort()
84 print 'Comparison of Paths : Reference vs Test ROOT files' 86 print 'Number of paths in Reference file : %i (objects, histos) = ( %i, %i )'%( len(dsks), os, hs )
87 print 'Number of paths in Test file : %i (objects, histos) = ( %i, %i )'%( len(dpks), op, hp )
88 matching = sset.intersection(pset)
91 if ds[n].__class__.__name__
in histos : matchingHistos += 1
92 print '\nMatching paths : %i'%( len(matching) )
95 uniqueReferenceHistos = 0
97 if ds[n].__class__.__name__
in histos : uniqueReferenceHistos += 1
98 print 'Paths unique to Reference file : %i ( %i Histos )'%( len(uSer), uniqueReferenceHistos )
100 for n
in uSer :
print '\t%s : \t%s'%( ds[n], n )
104 if dp[n].__class__.__name__
in histos : uniqueTestHistos += 1
105 print 'Paths unique to Test file : %i ( %i Histos )'%( len(uPar), uniqueTestHistos )
107 for n
in uPar :
print '\t%s : \t%s'%( dp[n], n )
108 print 'Matching Histos to test : %i'%( matchingHistos )
110 return ( ((os,hs),(op,hp)), (uSer, uniqueReferenceHistos), (uPar, uniqueTestHistos), matchingHistos )
125 return (h.GetNbinsX()+1)*(biny)*(binz)
129 for ibin
in xrange(0,nbins):
130 h1bin=h1.GetBinContent(ibin)
131 h2bin=h2.GetBinContent(ibin)
132 diffbins+= (h1bin!=h2bin)
154 ( ((referenceObjects,referenceHistos),(parallObjects, parallHistos)), (uniqueSerPaths,uniqueSerHistos), (uniqueParPaths,uniqueParHistos), mh ) = state
157 if t1[0] == ref : ds = t1[1] ; dp = t2[1]
158 elif t2[0] == ref : ds = t2[1] ; dp = t1[1]
159 else :
print 'Neither tuple is Reference Root file reference?' ;
return 162 hcp = 0 ; pHistos = []
163 hcs = 0 ; sHistos = []
165 omit = [re.compile(regex)
for regex
in gRegexBlackList]
169 if not any(regex.search(k)!=
None for regex
in omit):
170 if ds[k].__class__.__name__
in histos : hcs += 1 ; sHistos.append( k )
173 if not any(regex.search(k)!=
None for regex
in omit):
174 if dp[k].__class__.__name__
in histos : hcp += 1 ; pHistos.append( k )
177 cEntries = 0 ; xEntries = 0 ; diffEntries = []
178 cIntegrals = 0 ; xIntegrals = 0 ; diffIntegrals = []
179 passedKol = 0 ; failedKol = 0 ; diffKols = [] ; zeroIntegrals = 0
180 passedIdentity =0 ; failedIdentity=0; diffIdentity=[]; identityDiffBins={}
183 notfound = 0 ; integralMatch = 0 ; otherTest = 0 ; zeroIntegralMatch = 0
188 sh = ds[h] ; ph = dp[h]
190 if sh.GetEntries() != ph.GetEntries() : diffEntries.append(h) ; xEntries += 1 ;
continue 192 sBinError = 0.0 ; pBinError = 0.0
193 for i
in xrange(sh.GetNbinsX()) : sBinError += sh.GetBinError(i)
194 for i
in xrange(ph.GetNbinsX()) : pBinError += ph.GetBinError(i)
195 sint = sh.Integral() ; pint = ph.Integral()
196 doKS=(bool(sint)
and bool(pint))
and ( sBinError>0
and pBinError>0 )
197 if checkBin2BinIdentity
and doKS:
203 diffIdentity.append(h)
204 identityDiffBins[h]=diffBins
205 if (bool(sint)
and bool(pint))
and ( sBinError>0
and pBinError>0 ) :
207 kTest = sh.KolmogorovTest(ph)
208 kTestResults [h] = kTest
209 if int(kTest) : passedKol += 1
210 else : failedKol += 1 ; diffKols.append(h)
214 if all((sint, pint))
and (sint==pint) :
217 zeroIntegralMatch += 1
219 diffIntegrals.append( h )
222 notfound += 1 ;
print 'not found? ', h
226 print 'Summary of histos with different Entries' 230 for e
in diffEntries :
print '\t\t\t%s:\t%i != %i'%( e, int(ds[e].GetEntries()), int(dp[e].GetEntries()) )
235 print 'Summary of histos which failed Kolmogorov Test' 240 result = kTestResults[e]
241 print '%s\t\t%s :\tK-Test Result :\t %5.16f'%( ds[e].ClassName(), e, result )
246 print 'Summary of histos which failed Integral Check' 250 for e
in diffIntegrals :
253 print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f '%( ds[e].ClassName(), e, diff, pc )
258 if checkBin2BinIdentity:
261 print 'Summary of histos with at least one bin with different Entries' 265 for e
in diffIdentity:
266 print '%s\t\t%s: %i different bins'%( ds[e].ClassName(), e, identityDiffBins[e])
270 print 'Comparison : Reference/Test ROOT Histo files' 271 print '\n\t\tReference\tTest' 272 print '\tObjects : %i\t%i\t\t( p-s = %i )'%( referenceObjects, parallObjects, parallObjects-referenceObjects )
273 print '\tHistos : %i\t%i\t\t( p-s = %i )'%( referenceHistos, parallHistos, parallHistos-referenceHistos )
274 print '\t __________' 275 print '\tTotal : %i\t%i\n'%( referenceHistos+referenceObjects, parallHistos+parallObjects )
276 print 'Objects/Histos unique to Reference File : %i / %i'%( len(uniqueSerPaths)-uniqueSerHistos, uniqueSerHistos )
277 print 'Objects/Histos unique to Test File : %i / %i'%( len(uniqueParPaths)-uniqueParHistos, uniqueParHistos )
278 print '\nMatching Histograms valid for Comparison : %i'%( mh )
279 print '\nOmissions\' patterns : ' 280 for entry
in gRegexBlackList :
print '\t%s'%( entry )
281 print '\nHistograms for Comparison (after Omissions) : %i'%( mh-len(gRegexBlackList) )
282 print '\n\tHISTOGRAM TESTS : ' 283 print '\t\tKOLMOGOROV TEST : %i'%( kTested )
284 print '\t\tINTEGRAL TEST : %i'%( otherTest )
285 print '\t\tENTRIES TEST : %i'%( xEntries )
286 if checkBin2BinIdentity:
287 print '\t\tBIN2BIN TEST : %i'%( passedIdentity )
289 print '\t\tTested : %i'%( cEntries )
291 print '\n\tDISCREPANCIES : ' 292 print '\t\tK-Test : %i'%( failedKol )
293 print '\t\tIntegrals : %i'%( xIntegrals )
294 print '\t\tEntries : %i'%( xEntries )
295 retval = failedKol+xIntegrals+xEntries+failedIdentity
297 print '\nThe two sets of histograms were not identical' 304 global gRegexBlackList
306 for blackRegexp
in listString.split(
","):
307 gRegexBlackList.append(blackRegexp)
313 if __name__ ==
'__main__' :
314 usage =
"usage: %prog testFile.root referenceFile.root [options]" 315 parser = OptionParser()
316 parser.add_option(
"-b", dest=
"blacklist",
317 help=
'Comma separated list of regexps matching histograms to skip (for example -b"MemoryTool,ProcTime")')
319 parser.add_option(
"-i",
320 action=
"store_true", dest=
"bin2bin", default=
False,
321 help=
"Check for bin to bin identity")
322 (options, args) = parser.parse_args()
325 print "Wrong number of rootfiles. Usage:" 331 testFile,referenceFile=args
333 tfs = TFile( testFile,
'REC' ) ;
print 'opening Test File : %s'%( testFile )
334 tfp = TFile( referenceFile,
'REC' ) ;
print 'opening Reference File : %s'%( referenceFile )
339 dref = dict( [(n, o)
for n, o
in lref] )
340 dtest = dict( [(n, o)
for n, o
in ltest] )
342 ts = ( ref, dref ) ; tp = ( test, dtest )
351 retval =
compareHistos( ts, tp, state, checkBin2BinIdentity=options.bin2bin )
354 tfs.Close() ; tfp.Close()
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)