Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 256 of file difftuple.py.

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

◆ diff_dirs()

def python.difftuple.diff_dirs (   f1,
  f2 
)

Definition at line 371 of file difftuple.py.

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

◆ diff_objstrings()

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

Definition at line 362 of file difftuple.py.

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

◆ diff_trees()

def python.difftuple.diff_trees (   t1,
  t2 
)

Definition at line 299 of file difftuple.py.

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

◆ ignore_p()

def python.difftuple.ignore_p (   br)

Definition at line 229 of file difftuple.py.

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

◆ mc_eta_thresh()

def python.difftuple.mc_eta_thresh (   x)

Definition at line 290 of file difftuple.py.

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

◆ topy()

def python.difftuple.topy (   o)

Definition at line 246 of file difftuple.py.

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

Variable Documentation

◆ _ignore_branches

list python.difftuple._ignore_branches
private

Definition at line 190 of file difftuple.py.

◆ f1

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

Definition at line 402 of file difftuple.py.

◆ f2

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

Definition at line 403 of file difftuple.py.

◆ inttypes

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

Definition at line 255 of file difftuple.py.

◆ renames

dictionary python.difftuple.renames

Definition at line 23 of file difftuple.py.

python.difftuple.ignore_p
def ignore_p(br)
Definition: difftuple.py:229
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:36
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.difftuple.mc_eta_thresh
def mc_eta_thresh(x)
Definition: difftuple.py:290
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.difftuple.diff_dirs
def diff_dirs(f1, f2)
Definition: difftuple.py:371
python.difftuple.diff_trees
def diff_trees(t1, t2)
Definition: difftuple.py:299
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:256
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.difftuple.diff_objstrings
def diff_objstrings(k, s1, s2)
Definition: difftuple.py:362
python.difftuple.topy
def topy(o)
Definition: difftuple.py:246