CMS 3D CMS Logo

Classes | Functions | Variables
python.rootplot.utilities Namespace Reference

Classes

class  Hist
 
class  Hist2D
 Define classes. More...
 
class  HistStack
 
class  RootFile
 

Functions

def _rootglob0 (tdirectory, dirname, basename)
 
def _rootglob1 (tdirectory, dirname, pattern)
 
def find_num_processors ()
 
def get (object_name)
 
def has_glob_magic (s)
 
def irootglob (tdirectory, pathname)
 
def loadROOT (batch=True)
 Define additional helping functions. More...
 
def ls (directory=None)
 
def process_bin_labels (binlabels)
 
def pwd ()
 
def replace (string, replacements)
 
def rootglob (tdirectory, pathname)
 
def testfile ()
 
def wilson_interval (numerator_array, denominator_array)
 

Variables

 __license__
 
 glob_magic_check
 Functions for globbing within root files. More...
 

Detailed Description

Utilities for rootplot including histogram classes.

Function Documentation

def python.rootplot.utilities._rootglob0 (   tdirectory,
  dirname,
  basename 
)
private

Definition at line 553 of file utilities.py.

553 def _rootglob0(tdirectory, dirname, basename):
554  if tdirectory.Get(os.path.join(dirname, basename)):
555  return [basename]
556  return []
557 
def _rootglob0(tdirectory, dirname, basename)
Definition: utilities.py:553
def python.rootplot.utilities._rootglob1 (   tdirectory,
  dirname,
  pattern 
)
private

Definition at line 546 of file utilities.py.

546 def _rootglob1(tdirectory, dirname, pattern):
547  if not tdirectory.GetDirectory(dirname):
548  return []
549  names = [key.GetName() for key in
550  tdirectory.GetDirectory(dirname).GetListOfKeys()]
551  return fnmatch.filter(names, pattern)
552 
def _rootglob1(tdirectory, dirname, pattern)
Definition: utilities.py:546
def python.rootplot.utilities.find_num_processors ( )

Definition at line 511 of file utilities.py.

Referenced by python.rootplot.core.parse_arguments().

512  import os
513  try:
514  num_processors = os.sysconf('SC_NPROCESSORS_ONLN')
515  except:
516  try:
517  num_processors = os.environ['NUMBER_OF_PROCESSORS']
518  except:
519  num_processors = 1
520  return num_processors
521 
def python.rootplot.utilities.get (   object_name)
Return a Hist object with the given name.

Definition at line 427 of file utilities.py.

427 def get(object_name):
428  """Return a Hist object with the given name."""
429  return Hist(ROOT.gDirectory.Get(object_name))
430 
431 
def get(object_name)
Definition: utilities.py:427
def python.rootplot.utilities.has_glob_magic (   s)

Definition at line 538 of file utilities.py.

Referenced by python.rootplot.utilities.irootglob().

539  return glob_magic_check.search(s) is not None
540 
541 # These 2 helper functions non-recursively glob inside a literal directory.
542 # They return a list of basenames. `_rootglob1` accepts a pattern while
543 # `_rootglob0` takes a literal basename (so it only has to check for its
544 # existence).
545 
def python.rootplot.utilities.irootglob (   tdirectory,
  pathname 
)
Return an iterator which yields the paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la fnmatch.

Definition at line 576 of file utilities.py.

References python.rootplot.utilities.has_glob_magic().

Referenced by python.rootplot.utilities.rootglob().

576 def irootglob(tdirectory, pathname):
577  """Return an iterator which yields the paths matching a pathname pattern.
578 
579  The pattern may contain simple shell-style wildcards a la fnmatch.
580 
581  """
582  if not has_glob_magic(pathname):
583  if tdirectory.Get(pathname):
584  yield pathname
585  return
586  dirname, basename = os.path.split(pathname)
587  if has_glob_magic(dirname):
588  dirs = irootglob(tdirectory, dirname)
589  else:
590  dirs = [dirname]
591  if has_glob_magic(basename):
592  glob_in_dir = _rootglob1
593  else:
594  glob_in_dir = _rootglob0
595  for dirname in dirs:
596  for name in glob_in_dir(tdirectory, dirname, basename):
597  yield os.path.join(dirname, name)
598 
def irootglob(tdirectory, pathname)
Definition: utilities.py:576
def python.rootplot.utilities.loadROOT (   batch = True)

Define additional helping functions.

Definition at line 434 of file utilities.py.

References join(), and edm.print().

434 def loadROOT(batch=True):
435  ## We need to temporarily change sys.argv so that ROOT doesn't intercept
436  ## options from the command-line
437  saved_argv = sys.argv[:]
438  argstring = ' '.join(sys.argv)
439  sys.argv = [sys.argv[0]]
440  try:
441  import ROOT
442  except ImportError:
443  print("""\
444 The program was unable to access PyROOT. Usually, this just requires switching
445 to the same major version of python that used when compiling ROOT. To
446 determine which version that is, try the following command:
447  root -config 2>&1 | tr ' ' '\\n' | egrep 'python|PYTHON'
448 If this is different from the python version you are currently using, try
449 changing your PATH to point to the new one.""")
450  sys.exit(1)
451  ## Enter batch mode, unless outputting to C macros
452  ## There is a bug in pyROOT that fails to export colors in batch mode
453  if batch:
454  ROOT.gROOT.SetBatch()
455  ROOT.gErrorIgnoreLevel = ROOT.kWarning
456  ## PyROOT picks up ~/.rootlogon if it exists, but not ./rootlogon.C
457  if os.path.exists('rootlogon.C'):
458  ROOT.gROOT.Macro('rootlogon.C')
459  sys.argv = saved_argv[:]
460  return ROOT
461 
def loadROOT(batch=True)
Define additional helping functions.
Definition: utilities.py:434
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def python.rootplot.utilities.ls (   directory = None)
Return a python list of ROOT object names from the given directory.

Definition at line 409 of file utilities.py.

409 def ls(directory=None):
410  """Return a python list of ROOT object names from the given directory."""
411  if directory == None:
412  keys = ROOT.gDirectory.GetListOfKeys()
413  else:
414  keys = ROOT.gDirectory.GetDirectory(directory).GetListOfKeys()
415  key = keys[0]
416  names = []
417  while key:
418  obj = key.ReadObj()
419  key = keys.After(key)
420  names.append(obj.GetName())
421  return names
422 
def ls(directory=None)
Definition: utilities.py:409
def python.rootplot.utilities.process_bin_labels (   binlabels)

Definition at line 485 of file utilities.py.

485 def process_bin_labels(binlabels):
486  has_labels = False
487  for binlabel in binlabels:
488  if binlabel:
489  has_labels = True
490  if has_labels:
491  return binlabels
492  else:
493  return None
494 
def process_bin_labels(binlabels)
Definition: utilities.py:485
def python.rootplot.utilities.pwd ( )
Return ROOT's present working directory.

Definition at line 423 of file utilities.py.

423 def pwd():
424  """Return ROOT's present working directory."""
425  return ROOT.gDirectory.GetPath()
426 
def python.rootplot.utilities.replace (   string,
  replacements 
)
Modify a string based on a list of patterns and substitutions.

replacements should be a list of two-entry tuples, the first entry giving
a string to search for and the second entry giving the string with which
to replace it.  If replacements includes a pattern entry containing
'use_regexp', then all patterns will be treated as regular expressions
using re.sub.

Definition at line 462 of file utilities.py.

462 def replace(string, replacements):
463  """
464  Modify a string based on a list of patterns and substitutions.
465 
466  replacements should be a list of two-entry tuples, the first entry giving
467  a string to search for and the second entry giving the string with which
468  to replace it. If replacements includes a pattern entry containing
469  'use_regexp', then all patterns will be treated as regular expressions
470  using re.sub.
471  """
472  if not replacements:
473  return string
474  if 'use_regexp' in [x for x,y in replacements]:
475  for pattern, repl in [x for x in replacements
476  if x[0] != 'use_regexp']:
477  string = re.sub(pattern, repl, string)
478  else:
479  for pattern, repl in replacements:
480  string = string.replace(pattern, repl)
481  if re.match(_all_whitespace_string, string):
482  return ""
483  return string
484 
def replace(string, replacements)
Definition: utilities.py:462
def python.rootplot.utilities.rootglob (   tdirectory,
  pathname 
)
Return a list of paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la fnmatch.

>>> import rootplot.utilities
>>> f = rootplot.utilities.testfile()
>>> rootglob(f, '*')
['dir1', 'dir2', 'dir3', 'dir4']
>>> rootglob(f, 'dir1/*')
['dir1/hist1', 'dir1/hist2', 'dir1/hist3', 'dir1/hist4']
>>> rootglob(f, '*/hist1')
['dir1/hist1', 'dir2/hist1', 'dir3/hist1', 'dir4/hist1']
>>> rootglob(f, 'dir1/hist[1-2]')
['dir1/hist1', 'dir1/hist2']

Definition at line 558 of file utilities.py.

References python.rootplot.utilities.irootglob(), and list().

Referenced by python.rootplot.rootmath.main(), and python.rootplot.rootmath.newadd().

558 def rootglob(tdirectory, pathname):
559  """Return a list of paths matching a pathname pattern.
560 
561  The pattern may contain simple shell-style wildcards a la fnmatch.
562 
563  >>> import rootplot.utilities
564  >>> f = rootplot.utilities.testfile()
565  >>> rootglob(f, '*')
566  ['dir1', 'dir2', 'dir3', 'dir4']
567  >>> rootglob(f, 'dir1/*')
568  ['dir1/hist1', 'dir1/hist2', 'dir1/hist3', 'dir1/hist4']
569  >>> rootglob(f, '*/hist1')
570  ['dir1/hist1', 'dir2/hist1', 'dir3/hist1', 'dir4/hist1']
571  >>> rootglob(f, 'dir1/hist[1-2]')
572  ['dir1/hist1', 'dir1/hist2']
573  """
574  return list(irootglob(tdirectory, pathname))
575 
def irootglob(tdirectory, pathname)
Definition: utilities.py:576
def rootglob(tdirectory, pathname)
Definition: utilities.py:558
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def python.rootplot.utilities.testfile ( )

Definition at line 522 of file utilities.py.

522 def testfile():
523  outfile = ROOT.TFile("test.root", "recreate")
524  for i in range(4):
525  d = outfile.mkdir("dir%i" % (i + 1))
526  d.cd()
527  for j in range(4):
528  hist = ROOT.TH1F("hist%i" % (j + 1), "A Histogram", 10, 0, 10)
529  hist.Fill(j)
530  hist.Write()
531  outfile.Write()
532  return outfile
533 
def python.rootplot.utilities.wilson_interval (   numerator_array,
  denominator_array 
)

Definition at line 495 of file utilities.py.

References objects.autophobj.float, and ComparisonHelper.zip().

Referenced by python.rootplot.utilities.Hist.divide_wilson().

495 def wilson_interval(numerator_array, denominator_array):
496  eff, upper_err, lower_err = [], [], []
497  for n, d in zip(numerator_array, denominator_array):
498  try:
499  p = float(n) / d
500  s = math.sqrt(p * (1 - p) / d + 1 / (4 * d * d))
501  t = p + 1 / (2 * d)
502  eff.append(p)
503  upper_err.append(-p + 1/(1 + 1/d) * (t + s))
504  lower_err.append(+p - 1/(1 + 1/d) * (t - s))
505  except ZeroDivisionError:
506  eff.append(0)
507  upper_err.append(0)
508  lower_err.append(0)
509  return eff, upper_err, lower_err
510 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def wilson_interval(numerator_array, denominator_array)
Definition: utilities.py:495

Variable Documentation

python.rootplot.utilities.__license__
private

Definition at line 6 of file utilities.py.

python.rootplot.utilities.glob_magic_check

Functions for globbing within root files.

Definition at line 536 of file utilities.py.