CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
python.rootplot.utilities Namespace Reference

Classes

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

Functions

def _rootglob0
 
def _rootglob1
 
def find_num_processors
 
def get
 
def has_glob_magic
 
def irootglob
 
def loadROOT
 Define additional helping functions. More...
 
def ls
 
def process_bin_labels
 
def pwd
 
def replace
 
def rootglob
 
def testfile
 
def wilson_interval
 

Variables

string __license__
 
tuple glob_magic_check = re.compile('[*?[]')
 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.

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

Definition at line 545 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)
def python.rootplot.utilities.find_num_processors ( )

Definition at line 510 of file utilities.py.

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

511 def find_num_processors():
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
def python.rootplot.utilities.get (   object_name)
Return a Hist object with the given name.

Definition at line 426 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 
def python.rootplot.utilities.has_glob_magic (   s)

Definition at line 537 of file utilities.py.

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

538 def has_glob_magic(s):
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).
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().

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)
def python.rootplot.utilities.loadROOT (   batch = True)

Define additional helping functions.

Definition at line 433 of file utilities.py.

References join().

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
def loadROOT
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.

Referenced by HcalLaserEventFilter2012.addEventString(), EventFilterFromListStandAlone.addEventString(), FWBeamSpotProxyBuilder.build(), FWPFClusterRPZProxyBuilder.build(), FWPFClusterRPZUtils.buildRhoPhiClusterLineSet(), FWPFClusterRPZUtils.buildRhoZClusterLineSet(), L1TSync.certifyLSBlock(), CompositeLogicalTrajectoryFilter.CompositeLogicalTrajectoryFilter(), L1TSync.doFractionInSync(), L1TRate.endLuminosityBlock(), FUShmReader.fillRawData(), IdealZDCTrapezoid.getCorners(), IdealCastorTrapezoid.getCorners(), BeamSpotWorkflow.getNewRunList(), evf::FWEPWrapper.getTriggerReport(), FWBeamSpotProxyBuilder.localModelChanges(), ls_cert_type(), lsbs_cert(), copyAndRename.main(), copyFromCastor.main(), rename.main(), copyFiles.main(), main(), splitter.main(), checkRuns.main(), nlumis(), FastTimerService.postProcessEvent(), AlpgenSource.readAlpgenEvent(), lumi::TRGScalers2DB.retrieveData(), BeamHaloPairGenerator.run(), GenericPairGenerator.run(), GenericTripletGenerator.run(), evf::FUShmRawCell.setLumiSection(), DIPLumiDetail.setOrigin(), DIPLumiSummary.setOrigin(), FWPFClusterRPZProxyBuilder.sharedBuild(), TT6CMNSubtractor.subtract_(), IteratedMedianCMNSubtractor.subtract_(), evf::FUEventProcessor.supervisor(), evf::fuep::TriggerReportHelpers.triggerReportUpdate(), SimpleCosmicBONSeeder.triplets(), stor::StreamsMonitorCollection::EndOfRunReport.updateLatestWrittenLumiSection(), and DTTimeEvolutionHisto.updateTimeSlot().

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
def python.rootplot.utilities.process_bin_labels (   binlabels)

Definition at line 484 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
def python.rootplot.utilities.pwd ( )
Return ROOT's present working directory.

Definition at line 422 of file utilities.py.

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

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
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().

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))
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.

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
def python.rootplot.utilities.wilson_interval (   numerator_array,
  denominator_array 
)

Definition at line 494 of file utilities.py.

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

Variable Documentation

string python.rootplot.utilities.__license__
Initial value:
1 = '''\
2 Copyright (c) 2009-2010 Jeff Klukas <klukas@wisc.edu>
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 '''

Definition at line 5 of file utilities.py.

tuple python.rootplot.utilities.glob_magic_check = re.compile('[*?[]')

Functions for globbing within root files.

Definition at line 535 of file utilities.py.