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 255 of file difftuple.py.

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

◆ diff_dirs()

def python.difftuple.diff_dirs (   f1,
  f2 
)

Definition at line 370 of file difftuple.py.

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

◆ diff_objstrings()

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

Definition at line 361 of file difftuple.py.

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

◆ diff_trees()

def python.difftuple.diff_trees (   t1,
  t2 
)

Definition at line 298 of file difftuple.py.

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

◆ ignore_p()

def python.difftuple.ignore_p (   br)

Definition at line 228 of file difftuple.py.

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

◆ mc_eta_thresh()

def python.difftuple.mc_eta_thresh (   x)

Definition at line 289 of file difftuple.py.

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

◆ topy()

def python.difftuple.topy (   o)

Definition at line 245 of file difftuple.py.

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

Variable Documentation

◆ _ignore_branches

list python.difftuple._ignore_branches
private

Definition at line 189 of file difftuple.py.

◆ f1

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

Definition at line 401 of file difftuple.py.

◆ f2

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

Definition at line 402 of file difftuple.py.

◆ inttypes

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

Definition at line 254 of file difftuple.py.

◆ renames

dictionary python.difftuple.renames

Definition at line 22 of file difftuple.py.

python.difftuple.ignore_p
def ignore_p(br)
Definition: difftuple.py:228
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.difftuple.mc_eta_thresh
def mc_eta_thresh(x)
Definition: difftuple.py:289
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.difftuple.diff_dirs
def diff_dirs(f1, f2)
Definition: difftuple.py:370
python.difftuple.diff_trees
def diff_trees(t1, t2)
Definition: difftuple.py:298
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
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:255
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.difftuple.diff_objstrings
def diff_objstrings(k, s1, s2)
Definition: difftuple.py:361
python.difftuple.topy
def topy(o)
Definition: difftuple.py:245