ATLAS Offline Software
Functions | Variables
python.difftuple Namespace Reference

Functions

def ignore_p (br)
 
def topy (o)
 
def compare (o1, o2, thresh=1e-6, ithresh=None)
 
def mc_eta_thresh (x)
 
def diff_trees (t1, t2)
 
def diff_objstrings (k, s1, s2)
 
def diff_dirs (f1, f2)
 

Variables

dictionary renames
 
list _ignore_branches
 
list inttypes = [types.IntType, types.LongType]
 
 f1 = ROOT.TFile (sys.argv[1])
 
 f2 = ROOT.TFile (sys.argv[2])
 

Function Documentation

◆ compare()

def python.difftuple.compare (   o1,
  o2,
  thresh = 1e-6,
  ithresh = None 
)

Definition at line 258 of file difftuple.py.

258 def compare (o1, o2, thresh = 1e-6, ithresh = None):
259  # Allow comparing int/long int.
260  if type(o1) in inttypes and type(o2) in inttypes:
261  if o1 < 0: o1 = o1 + (1<<32)
262  if o2 < 0: o2 = o2 + (1<<32)
263  return o1 == o2
264  if type(o1) is not type(o2):
265  return False
266  if isinstance(o1,list):
267  if len(o1) != len(o2):
268  return False
269  for i in range(len(o1)):
270  if not compare (o1[i], o2[i],
271  thresh=thresh, ithresh=ithresh): return False
272  return True
273  if type(o1).__name__ in ['map<string,int>',
274  'map<string,float>',
275  'map<string,string>']:
276  return ROOT.D3PDTest.MapDumper.equal (o1, o2)
277  if isinstance(o1, float):
278  if ithresh and abs(o1) < ithresh and abs(o2) < ithresh:
279  return True
280  num = o1-o2
281  den = abs(o1)+abs(o2)
282  if den == 0: return True
283  x = abs(num / den)
284  if callable(thresh): thresh = thresh(den)
285  if x > thresh:
286  print ('fmismatch', o1, o2, x)
287  return False
288  return True
289  return o1 == o2
290 
291 

◆ diff_dirs()

def python.difftuple.diff_dirs (   f1,
  f2 
)

Definition at line 373 of file difftuple.py.

373 def diff_dirs (f1, f2):
374  k1 = [k.GetName() for k in f1.GetListOfKeys()]
375  k2 = [k.GetName() for k in f2.GetListOfKeys()]
376  k1.sort()
377  k2.sort()
378  if k1 != k2:
379  print ("Key list mismatch for", f1.GetName(), f2.GetName(), ":")
380  print (k1)
381  print (k2)
382  for k in k1:
383  if k not in k2: continue
384  o1 = f1.Get(k)
385  o2 = f2.Get(k)
386  if type(o1) is not type(o2):
387  print ('Type mismatch for ', k)
388  print (o1, o2)
389  if k == 'Schema':
390  pass
391  elif isinstance (o1, ROOT.TTree):
392  diff_trees (o1, o2)
393  elif isinstance (o1, ROOT.TDirectory):
394  diff_dirs (o1, o2)
395  elif isinstance (o1, ROOT.TObjString):
396  diff_objstrings (k, o1, o2)
397  else:
398  print (k, type(o1))
399  return
400 
401 

◆ diff_objstrings()

def python.difftuple.diff_objstrings (   k,
  s1,
  s2 
)

Definition at line 364 of file difftuple.py.

364 def diff_objstrings (k, s1, s2):
365  # nb. != not working correctly for TObjString in 5.26.00c_python2.6
366  if not (s1 == s2):
367  print ('Objstring', k, 'mismatch:')
368  print (repr(s1))
369  print (repr(s2))
370  return
371 
372 

◆ diff_trees()

def python.difftuple.diff_trees (   t1,
  t2 
)

Definition at line 301 of file difftuple.py.

301 def diff_trees (t1, t2):
302  n1 = t1.GetEntries()
303  n2 = t2.GetEntries()
304  if n1 != n2:
305  print ('Different nentries for tree', t1.GetName(), ': ', n1, n2)
306  n1 = min(n1, n2)
307  b1 = [b.GetName() for b in t1.GetListOfBranches()]
308  b2 = [b.GetName() for b in t2.GetListOfBranches()]
309  b1.sort()
310  b2.sort()
311  branchmap = renames.copy()
312  for b in b1:
313  if b not in b2:
314  bb = branchmap.get (b)
315  if not bb or bb not in b2:
316  if not ignore_p(b):
317  print ('Branch', b, 'in first tree but not in second.')
318  if bb: del branchmap[b]
319  else:
320  b2.remove (bb)
321  else:
322  b2.remove (b)
323  branchmap[b] = b
324  for b in b2:
325  if not ignore_p(b):
326  print ('Branch', b, 'in second tree but not in first.')
327 
328  for i in range (n1):
329  t1.GetEntry(i)
330  t2.GetEntry(i)
331  for b in b1:
332  if ignore_p(b): continue
333  bb = branchmap.get(b)
334  if not bb: continue
335  o1 = topy (getattr(t1, b))
336  o2 = topy (getattr(t2, bb))
337 
338  ithresh = None
339  thresh = 1e-6
340  if b.find('jet_')>=0 and b.endswith ('_m'): ithresh = 0.1
341  if b == 'mc_m': ithresh = 0.1
342  if b.find ('_rawcl_etas') >= 0: thresh = 2e-4
343  if b.endswith ('_convIP'): thresh = 3e-5
344  if b.endswith ('_emscale_E'): thresh = 9e-5
345  if b.endswith ('_emscale_eta'): thresh = 9e-5
346  if b.endswith ('_emscale_m'): ithresh = 0.1
347  if b.endswith ('_constscale_E'): thresh = 9e-5
348  if b.endswith ('_constscale_eta'): thresh = 9e-5
349  if b == 'mc_eta': thresh = mc_eta_thresh
350  if b.endswith ('_seg_locX'): ithresh = 2e-12
351  if b.endswith ('_seg_locY'): ithresh = 2e-12
352  if b == 'MET_Goodness_DeltaEt_JetAlgs_Jet': ithresh = 2e-11
353  if b == 'MET_Goodness_EEM_Jet': thresh = 2e-5
354  if b == 'MET_Goodness_HECf_Jet': thresh = 3e-6
355  if b.find ('_blayerPrediction') >= 0: thresh = 4e-4
356  if not compare (o1, o2, thresh = thresh, ithresh = ithresh):
357  print ('Branch mismatch', b, 'entry', i, ':', ithresh)
358  print (o1)
359  print (o2)
360 
361  return
362 
363 

◆ ignore_p()

def python.difftuple.ignore_p (   br)

Definition at line 231 of file difftuple.py.

231 def ignore_p (br):
232  ver = os.environ.get ('CMTPATH')
233 
234  for vlist in _ignore_branches:
235  for v in vlist[:-1]:
236  found = False
237  if ver and ver.find (v) >= 0:
238  found = True
239  break
240  if found: continue
241  for b in vlist[-1]:
242  if fnmatch (br, b):
243  return True
244  return False
245 
246 
247 

◆ mc_eta_thresh()

def python.difftuple.mc_eta_thresh (   x)

Definition at line 292 of file difftuple.py.

292 def mc_eta_thresh (x):
293  if x > 36: return 1e-2
294  if x > 34: return 2e-3
295  if x > 32: return 2e-4
296  if x > 30: return 1e-4
297  if x > 28: return 1e-5
298  return 1e-6
299 
300 

◆ topy()

def python.difftuple.topy (   o)

Definition at line 248 of file difftuple.py.

248 def topy (o):
249  if type(o).__name__.startswith ('vector<'):
250  ll = list(o)
251  if ll and type(ll[0]).__name__.startswith ('vector<'):
252  ll = [list(l) for l in ll]
253  return ll
254  return o
255 
256 

Variable Documentation

◆ _ignore_branches

list python.difftuple._ignore_branches
private

Definition at line 192 of file difftuple.py.

◆ f1

python.difftuple.f1 = ROOT.TFile (sys.argv[1])

Definition at line 404 of file difftuple.py.

◆ f2

python.difftuple.f2 = ROOT.TFile (sys.argv[2])

Definition at line 405 of file difftuple.py.

◆ inttypes

list python.difftuple.inttypes = [types.IntType, types.LongType]

Definition at line 257 of file difftuple.py.

◆ renames

dictionary python.difftuple.renames

Definition at line 25 of file difftuple.py.

python.difftuple.ignore_p
def ignore_p(br)
Definition: difftuple.py:231
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
python.difftuple.mc_eta_thresh
def mc_eta_thresh(x)
Definition: difftuple.py:292
python.difftuple.diff_dirs
def diff_dirs(f1, f2)
Definition: difftuple.py:373
python.difftuple.diff_trees
def diff_trees(t1, t2)
Definition: difftuple.py:301
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.difftuple.compare
def compare(o1, o2, thresh=1e-6, ithresh=None)
Definition: difftuple.py:258
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
min
#define min(a, b)
Definition: cfImp.cxx:40
python.difftuple.diff_objstrings
def diff_objstrings(k, s1, s2)
Definition: difftuple.py:364
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.difftuple.topy
def topy(o)
Definition: difftuple.py:248