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 552 of file utilities.py.

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

Definition at line 545 of file utilities.py.

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

Definition at line 510 of file utilities.py.

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

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

Definition at line 426 of file utilities.py.

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

Definition at line 537 of file utilities.py.

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

538  return glob_magic_check.search(s) is not None
539 
540 # These 2 helper functions non-recursively glob inside a literal directory.
541 # They return a list of basenames. `_rootglob1` accepts a pattern while
542 # `_rootglob0` takes a literal basename (so it only has to check for its
543 # existence).
544 
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 575 of file utilities.py.

References python.rootplot.utilities.has_glob_magic().

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

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

Define additional helping functions.

Definition at line 433 of file utilities.py.

References join().

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

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

Definition at line 484 of file utilities.py.

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

Definition at line 422 of file utilities.py.

422 def pwd():
423  """Return ROOT's present working directory."""
424  return ROOT.gDirectory.GetPath()
425 
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 461 of file utilities.py.

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

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

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

557 def rootglob(tdirectory, pathname):
558  """Return a list of paths matching a pathname pattern.
559 
560  The pattern may contain simple shell-style wildcards a la fnmatch.
561 
562  >>> import rootplot.utilities
563  >>> f = rootplot.utilities.testfile()
564  >>> rootglob(f, '*')
565  ['dir1', 'dir2', 'dir3', 'dir4']
566  >>> rootglob(f, 'dir1/*')
567  ['dir1/hist1', 'dir1/hist2', 'dir1/hist3', 'dir1/hist4']
568  >>> rootglob(f, '*/hist1')
569  ['dir1/hist1', 'dir2/hist1', 'dir3/hist1', 'dir4/hist1']
570  >>> rootglob(f, 'dir1/hist[1-2]')
571  ['dir1/hist1', 'dir1/hist2']
572  """
573  return list(irootglob(tdirectory, pathname))
574 
def irootglob(tdirectory, pathname)
Definition: utilities.py:575
def rootglob(tdirectory, pathname)
Definition: utilities.py:557
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 521 of file utilities.py.

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

Definition at line 494 of file utilities.py.

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

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

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

Variable Documentation

python.rootplot.utilities.__license__
private

Definition at line 5 of file utilities.py.

python.rootplot.utilities.glob_magic_check

Functions for globbing within root files.

Definition at line 535 of file utilities.py.