All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
compareRootHistos Namespace Reference

Functions

def rec
 
def composition
 
def comparePaths
 
def compareHistos
 

Variables

list histos = ['TH1D', 'TH2D', 'TProfile']
 
string ser = 'SERIAL'
 
string par = 'PARALL'
 
list pFile = sys.argv[0]
 
list sFile = sys.argv[1]
 
tuple tfs = TFile( sFile, 'REC' )
 
tuple tfp = TFile( pFile, 'REC' )
 
tuple lser = rec(tfs)
 
tuple dserial = dict( [(n, o) for n, o in lser] )
 
tuple dparall = dict( [(n, o) for n, o in lpar] )
 
tuple ts = ( ser, dserial )
 
tuple state = comparePaths( ts, tp )
 

Function Documentation

def compareRootHistos.compareHistos (   t1,
  t2,
  state 
)

Definition at line 121 of file compareRootHistos.py.

122 def compareHistos(t1, t2, state) :
123 
124  ( ((serialObjects,serialHistos),(parallObjects, parallHistos)), (uniqueSerPaths,uniqueSerHistos), (uniqueParPaths,uniqueParHistos), mh ) = state
125 
126  # deduce which one is parallel, which serial
127  if t1[0] == ser : ds = t1[1] ; dp = t2[1]
128  elif t2[0] == ser : ds = t2[1] ; dp = t1[1]
129  else : print 'Neither tuple is Serial Root file reference?' ; return
130 
131  # histocount, objectcount for parallel/serial
132  hcp = 0 ; pHistos = []
133  hcs = 0 ; sHistos = []
134 
135  omit = ['/stat/Brunel/MemoryTool/Virtual mem, all entries',
136  '/stat/Brunel/MemoryTool/Virtual mem, downscaled']
137  omit = []
138 
139  # find the histos in the serial file
140  for k in ds.keys() :
141  if k not in omit :
142  if ds[k].__class__.__name__ in histos : hcs += 1 ; sHistos.append( k )
143  # same for parallel
144  for k in dp.keys() :
145  if k not in omit :
146  if dp[k].__class__.__name__ in histos : hcp += 1 ; pHistos.append( k )
147 
148 
149  cEntries = 0 ; xEntries = 0 ; diffEntries = []
150  cIntegrals = 0 ; xIntegrals = 0 ; diffIntegrals = []
151  passedKol = 0 ; failedKol = 0 ; diffKols = [] ; zeroIntegrals = 0
152  kTested = 0
153  notfound = 0 ; integralMatch = 0 ; otherTest = 0 ; zeroIntegralMatch = 0
154  for h in sHistos :
155  if h in pHistos :
156  # matching histos to check
157  cEntries += 1
158  sh = ds[h] ; ph = dp[h]
159  # first check entries
160  if sh.GetEntries() != ph.GetEntries() : diffEntries.append(h) ; xEntries += 1 ; continue
161  # check for (non-zero sum of bin error) && (non-zero integrals) for K-Test
162  sBinError = 0.0 ; pBinError = 0.0
163  for i in xrange(sh.GetNbinsX()) : sBinError += sh.GetBinError(i)
164  for i in xrange(ph.GetNbinsX()) : pBinError += ph.GetBinError(i)
165  sint = sh.Integral() ; pint = ph.Integral()
166  if (bool(sint) and bool(pint)) and ( sBinError>0 and pBinError>0 ) :
167  kTested += 1
168  kTest = sh.KolmogorovTest(ph)
169  if int(kTest) : passedKol += 1
170  else : failedKol += 1 ; diffKols.append(h) # ; print 'KTest result : ', kTest
171  else :
172  # try the integral test?
173  otherTest += 1
174  if all((sint, pint)) and (sint==pint) :
175  integralMatch += 1
176  elif (sint==pint) :
177  zeroIntegralMatch += 1
178  else :
179  diffIntegrals.append( h )
180  xIntegrals += 1
181  else :
182  notfound += 1 ; print 'not found? ', h
183 
184  # report on Failed Entry-Checks
185  print '\n\n'+'-'*80
186  print 'Summary of histos with different Entries'
187  print '-'*80
188  if diffEntries :
189  diffEntries.sort()
190  for e in diffEntries : print '\t\t\t%s:\t%i != %i'%( e, int(ds[e].GetEntries()), int(dp[e].GetEntries()) )
191  print '-'*80
192 
193  # report on Failed Kolmogorov Tests
194  print '\n\n'+'-'*60
195  print 'Summary of histos which failed Kolmogorov Test'
196  print '-'*60
197  if diffKols :
198  diffKols.sort()
199  for e in diffKols :
200  result = ds[e].KolmogorovTest(dp[e])
201  print '%s\t\t%s :\tK-Test Result :\t %5.16f'%( type(ds[e]), e, result )
202  print '-'*60
203 
204  # report on Failed Integral Checks
205  print '\n\n'+'-'*60
206  print 'Summary of histos which failed Integral Check'
207  print '-'*60
208  if diffIntegrals :
209  diffIntegrals.sort()
210  for e in diffIntegrals :
211  diff = dp[e].Integral()-ds[e].Integral()
212  pc = (diff*100)/ds[e].Integral()
213  print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Serial : %5.6f '%( type(ds[e]), e, diff, pc )
214  print '-'*60 + '\n'
215  print '='*80 + '\n'
216 
217  print '\n' + '='*80
218  print 'Comparison : Serial/Parallel ROOT Histo files'
219  print '\n\t\tSerial\tParall'
220  print '\tObjects : %i\t%i\t\t( p-s = %i )'%( serialObjects, parallObjects, parallObjects-serialObjects )
221  print '\tHistos : %i\t%i\t\t( p-s = %i )'%( serialHistos, parallHistos, parallHistos-serialHistos )
222  print '\t __________'
223  print '\tTotal : %i\t%i\n'%( serialHistos+serialObjects, parallHistos+parallObjects )
224  print 'Objects/Histos unique to Serial File : %i / %i'%( len(uniqueSerPaths)-uniqueSerHistos, uniqueSerHistos )
225  print 'Objects/Histos unique to Parall File : %i / %i'%( len(uniqueParPaths)-uniqueParHistos, uniqueParHistos )
226  print '\nMatching Histograms valid for Comparison : %i'%( mh )
227  print '\nOmissions : '
228  for entry in omit : print '\t%s'%( entry )
229  print '\nHistograms for Comparison (after Omissions) : %i'%( mh-len(omit) )
230  print '\n\tHISTOGRAM TESTS : '
231  print '\t\tKOLMOGOROV TEST : %i'%( kTested )
232  print '\t\tINTEGRAL TEST : %i'%( otherTest )
233  print '\t\tENTRIES TEST : %i'%( xEntries )
234  print '\t\t ____'
235  print '\t\tTested : %i'%( cEntries )
236 
237  print '\n\tDISCREPANCIES : '
238  print '\t\tK-Test : %i'%( failedKol )
239  print '\t\tIntegrals : %i'%( xIntegrals )
240  print '\t\tEntries : %i'%( xEntries )
241  print '\n'+'='*80
242 
243 # =================================================================================================
string type
Definition: gaudirun.py:126
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)
Definition: Integral.cpp:28
def compareRootHistos.comparePaths (   t1,
  t2 
)

Definition at line 64 of file compareRootHistos.py.

64 
65 def comparePaths( t1, t2 ) :
66  if t1[0] == ser : ds = t1[1] ; dp = t2[1]
67  elif t2[0] == ser : ds = t2[1] ; dp = t1[1]
68  else : print 'Neither tuple is Serial Root file reference?' ; return
69 
70  dsks = ds.keys() ; dpks = dp.keys()
71  dsks.sort() ; dpks.sort()
72 
73  sset = sets.Set( dsks )
74  pset = sets.Set( dpks )
75  os, hs = composition( (ser, ds) )
76  op, hp = composition( (par, dp) )
77  print '\n' + '='*80
78  print 'Comparison of Paths : Serial vs Parallel ROOT files'
79  print '-'*80
80  print 'Number of paths in Serial file : %i (objects, histos) = ( %i, %i )'%( len(dsks), os, hs )
81  print 'Number of paths in Parall file : %i (objects, histos) = ( %i, %i )'%( len(dpks), op, hp )
82  matching = sset.intersection(pset)
83  matchingHistos = 0
84  for n in matching :
85  if ds[n].__class__.__name__ in histos : matchingHistos += 1
86  print '\nMatching paths : %i'%( len(matching) )
87  uSer = sset - pset
88  # work out histos unique to parallel file
89  uniqueSerialHistos = 0
90  for n in uSer :
91  if ds[n].__class__.__name__ in histos : uniqueSerialHistos += 1
92  print 'Paths unique to Serial file : %i ( %i Histos )'%( len(uSer), uniqueSerialHistos )
93  if uSer :
94  for n in uSer : print '\t%s : \t%s'%( ds[n], n )
95  uPar = pset - sset
96  uniqueParallHistos = 0
97  for n in uPar :
98  if dp[n].__class__.__name__ in histos : uniqueParallHistos += 1
99  print 'Paths unique to Parall file : %i ( %i Histos )'%( len(uPar), uniqueParallHistos )
100  if uPar :
101  for n in uPar : print '\t%s : \t%s'%( dp[n], n )
102  print 'Matching Histos to test : %i'%( matchingHistos )
103  print '='*80 + '\n'
104  return ( ((os,hs),(op,hp)), (uSer, uniqueSerialHistos), (uPar, uniqueParallHistos), matchingHistos )
105 # =================================================================================================
106 
107 # =================================================================================================
108 # Method : compareHistos( t1, t2 )
109 #
110 # @param t1, t2 : a tuple of ( type, d ) where type is either 'SERIAL' or 'PARALL'
111 # and d is a dictionary of ROOT objects, with each key = ROOT path
112 #
113 # function : compare the histograms in Serial/Parallel ROOT files. First, go through each
114 # dict to collect the histos (ignore TDirectory objects, etc). Then the histos
115 # in the parallel file (experimental) are compared to their equivalents in the
116 # serial file (definitely correct) using 3 methods.
117 # 1) The entries are checked, they should be equal
118 # 2) If entries are equal, check the Integral(); should be equal
119 # 3) If integrals are equal, check the KolmogorovTest() ; should be 1
120 # Arguments t1 and t2 are checked and the parallel/serial auto-detected
#
def compareRootHistos.composition (   t)

Definition at line 42 of file compareRootHistos.py.

42 
43 def composition( t ) :
44  typ, d = t
45  hists = 0 ; objs = 0
46  for k in d.keys() :
47  if d[k].__class__.__name__ in histos : hists += 1
48  else : objs += 1
49  return objs, hists
50 # =================================================================================================
51 
52 # =================================================================================================
53 # Method : comparePaths( t1, t2 )
54 #
55 # @param t1, t2 : a tuple of ( type, d ) where type is either 'SERIAL' or 'PARALL'
56 # and d is a dictionary of ROOT objects, with each key = ROOT path
57 #
58 # function : compare the paths between the two histo files. If the files are identical, they
59 # should have the same set of paths. The Parallel file should definitely have the
60 # same paths as the Serial. Perhaps the Serial file will have some more paths due
61 # to extra histos added as part of Application Sequencer finalisation
62 # Arguments t1 and t2 are checked and the parallel/serial auto-detected
63 # Uses sets module for intersections/unions, etc.
#
def compareRootHistos.rec (   o,
  path = None,
  lst = None 
)

Definition at line 20 of file compareRootHistos.py.

20 
21 def rec( o, path=None, lst=None ) :
22  if not path : path = '/stat' ; lst = []
23  else : path = path + '/' + o.GetName()
24  lst.append( (path,o) )
25  if 'GetListOfKeys' in dir(o) :
26  keys = o.GetListOfKeys()
27  for k in keys :
28  name = k.GetName()
29  rec( o.Get(name), path, lst )
30  else :
31  pass
32  return lst
33 # =================================================================================================
34 
35 # =================================================================================================
36 # Method : composition( t )
37 #
38 # @param t : a tuple of ( type, d ) where type is either 'SERIAL' or 'PARALL'
39 # and d is a dictionary of ROOT objects, with each key = ROOT path
40 #
41 # function : deduce the composition, (objects/histos) counts
#

Variable Documentation

tuple compareRootHistos.dparall = dict( [(n, o) for n, o in lpar] )

Definition at line 261 of file compareRootHistos.py.

tuple compareRootHistos.dserial = dict( [(n, o) for n, o in lser] )

Definition at line 260 of file compareRootHistos.py.

list compareRootHistos.histos = ['TH1D', 'TH2D', 'TProfile']

Definition at line 5 of file compareRootHistos.py.

tuple compareRootHistos.lser = rec(tfs)

Definition at line 258 of file compareRootHistos.py.

string compareRootHistos.par = 'PARALL'

Definition at line 7 of file compareRootHistos.py.

list compareRootHistos.pFile = sys.argv[0]

Definition at line 247 of file compareRootHistos.py.

string compareRootHistos.ser = 'SERIAL'

Definition at line 6 of file compareRootHistos.py.

list compareRootHistos.sFile = sys.argv[1]

Definition at line 248 of file compareRootHistos.py.

tuple compareRootHistos.state = comparePaths( ts, tp )

Definition at line 269 of file compareRootHistos.py.

tuple compareRootHistos.tfp = TFile( pFile, 'REC' )

Definition at line 255 of file compareRootHistos.py.

tuple compareRootHistos.tfs = TFile( sFile, 'REC' )

Definition at line 254 of file compareRootHistos.py.

tuple compareRootHistos.ts = ( ser, dserial )

Definition at line 263 of file compareRootHistos.py.