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. | |
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. |
Utilities for rootplot including histogram classes.
def python::rootplot::utilities::_rootglob0 | ( | tdirectory, | |
dirname, | |||
basename | |||
) | [private] |
Definition at line 552 of file utilities.py.
def python::rootplot::utilities::_rootglob1 | ( | tdirectory, | |
dirname, | |||
pattern | |||
) | [private] |
Definition at line 545 of file utilities.py.
def python::rootplot::utilities::find_num_processors | ( | ) |
Definition at line 510 of file utilities.py.
def python::rootplot::utilities::get | ( | object_name | ) |
Return a Hist object with the given name.
Definition at line 426 of file utilities.py.
def python::rootplot::utilities::has_glob_magic | ( | s | ) |
Definition at line 537 of file utilities.py.
00538 : 00539 return glob_magic_check.search(s) is not None 00540 00541 # These 2 helper functions non-recursively glob inside a literal directory. 00542 # They return a list of basenames. `_rootglob1` accepts a pattern while 00543 # `_rootglob0` takes a literal basename (so it only has to check for its 00544 # 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.
00576 : 00577 """Return an iterator which yields the paths matching a pathname pattern. 00578 00579 The pattern may contain simple shell-style wildcards a la fnmatch. 00580 00581 """ 00582 if not has_glob_magic(pathname): 00583 if tdirectory.Get(pathname): 00584 yield pathname 00585 return 00586 dirname, basename = os.path.split(pathname) 00587 if has_glob_magic(dirname): 00588 dirs = irootglob(tdirectory, dirname) 00589 else: 00590 dirs = [dirname] 00591 if has_glob_magic(basename): 00592 glob_in_dir = _rootglob1 00593 else: 00594 glob_in_dir = _rootglob0 00595 for dirname in dirs: 00596 for name in glob_in_dir(tdirectory, dirname, basename): 00597 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.
00434 : 00435 ## We need to temporarily change sys.argv so that ROOT doesn't intercept 00436 ## options from the command-line 00437 saved_argv = sys.argv[:] 00438 argstring = ' '.join(sys.argv) 00439 sys.argv = [sys.argv[0]] 00440 try: 00441 import ROOT 00442 except ImportError: 00443 print """\ 00444 The program was unable to access PyROOT. Usually, this just requires switching 00445 to the same major version of python that used when compiling ROOT. To 00446 determine which version that is, try the following command: 00447 root -config 2>&1 | tr ' ' '\\n' | egrep 'python|PYTHON' 00448 If this is different from the python version you are currently using, try 00449 changing your PATH to point to the new one.""" 00450 sys.exit(1) 00451 ## Enter batch mode, unless outputting to C macros 00452 ## There is a bug in pyROOT that fails to export colors in batch mode 00453 if batch: 00454 ROOT.gROOT.SetBatch() 00455 ROOT.gErrorIgnoreLevel = ROOT.kWarning 00456 ## PyROOT picks up ~/.rootlogon if it exists, but not ./rootlogon.C 00457 if os.path.exists('rootlogon.C'): 00458 ROOT.gROOT.Macro('rootlogon.C') 00459 sys.argv = saved_argv[:] 00460 return ROOT
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 FWPFClusterRPZProxyBuilder::build(), FWBeamSpotProxyBuilder::build(), FWPFClusterRPZUtils::buildRhoPhiClusterLineSet(), FWPFClusterRPZUtils::buildRhoZClusterLineSet(), L1TSync::certifyLSBlock(), CompositeLogicalTrajectoryFilter::CompositeLogicalTrajectoryFilter(), L1TSync::doFractionInSync(), L1TRate::endLuminosityBlock(), FUShmReader::fillRawData(), IdealCastorTrapezoid::getCorners(), IdealZDCTrapezoid::getCorners(), evf::FWEPWrapper::getTriggerReport(), FWBeamSpotProxyBuilder::localModelChanges(), ls_cert_type(), lsbs_cert(), main(), nlumis(), AlpgenSource::readAlpgenEvent(), lumi::TRGScalers2DB::retrieveData(), BeamHaloPairGenerator::run(), GenericPairGenerator::run(), GenericTripletGenerator::run(), evf::FUShmRawCell::setLumiSection(), DIPLumiSummary::setOrigin(), DIPLumiDetail::setOrigin(), FWPFClusterRPZProxyBuilder::sharedBuild(), TT6CMNSubtractor::subtract_(), IteratedMedianCMNSubtractor::subtract_(), evf::FUEventProcessor::supervisor(), evf::fuep::TriggerReportHelpers::triggerReportUpdate(), SimpleCosmicBONSeeder::triplets(), stor::StreamsMonitorCollection::EndOfRunReport::updateLatestWrittenLumiSection(), and DTTimeEvolutionHisto::updateTimeSlot().
00409 : 00410 """Return a python list of ROOT object names from the given directory.""" 00411 if directory == None: 00412 keys = ROOT.gDirectory.GetListOfKeys() 00413 else: 00414 keys = ROOT.gDirectory.GetDirectory(directory).GetListOfKeys() 00415 key = keys[0] 00416 names = [] 00417 while key: 00418 obj = key.ReadObj() 00419 key = keys.After(key) 00420 names.append(obj.GetName()) 00421 return names
def python::rootplot::utilities::process_bin_labels | ( | binlabels | ) |
Definition at line 484 of file utilities.py.
def python::rootplot::utilities::pwd | ( | ) |
Return ROOT's present working directory.
Definition at line 422 of file utilities.py.
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.
00462 : 00463 """ 00464 Modify a string based on a list of patterns and substitutions. 00465 00466 replacements should be a list of two-entry tuples, the first entry giving 00467 a string to search for and the second entry giving the string with which 00468 to replace it. If replacements includes a pattern entry containing 00469 'use_regexp', then all patterns will be treated as regular expressions 00470 using re.sub. 00471 """ 00472 if not replacements: 00473 return string 00474 if 'use_regexp' in [x for x,y in replacements]: 00475 for pattern, repl in [x for x in replacements 00476 if x[0] != 'use_regexp']: 00477 string = re.sub(pattern, repl, string) 00478 else: 00479 for pattern, repl in replacements: 00480 string = string.replace(pattern, repl) 00481 if re.match(_all_whitespace_string, string): 00482 return "" 00483 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.
00558 : 00559 """Return a list of paths matching a pathname pattern. 00560 00561 The pattern may contain simple shell-style wildcards a la fnmatch. 00562 00563 >>> import rootplot.utilities 00564 >>> f = rootplot.utilities.testfile() 00565 >>> rootglob(f, '*') 00566 ['dir1', 'dir2', 'dir3', 'dir4'] 00567 >>> rootglob(f, 'dir1/*') 00568 ['dir1/hist1', 'dir1/hist2', 'dir1/hist3', 'dir1/hist4'] 00569 >>> rootglob(f, '*/hist1') 00570 ['dir1/hist1', 'dir2/hist1', 'dir3/hist1', 'dir4/hist1'] 00571 >>> rootglob(f, 'dir1/hist[1-2]') 00572 ['dir1/hist1', 'dir1/hist2'] 00573 """ 00574 return list(irootglob(tdirectory, pathname))
def python::rootplot::utilities::testfile | ( | ) |
Definition at line 521 of file utilities.py.
00522 : 00523 outfile = ROOT.TFile("test.root", "recreate") 00524 for i in range(4): 00525 d = outfile.mkdir("dir%i" % (i + 1)) 00526 d.cd() 00527 for j in range(4): 00528 hist = ROOT.TH1F("hist%i" % (j + 1), "A Histogram", 10, 0, 10) 00529 hist.Fill(j) 00530 hist.Write() 00531 outfile.Write() 00532 return outfile
def python::rootplot::utilities::wilson_interval | ( | numerator_array, | |
denominator_array | |||
) |
Definition at line 494 of file utilities.py.
00495 : 00496 eff, upper_err, lower_err = [], [], [] 00497 for n, d in zip(numerator_array, denominator_array): 00498 try: 00499 p = float(n) / d 00500 s = math.sqrt(p * (1 - p) / d + 1 / (4 * d * d)) 00501 t = p + 1 / (2 * d) 00502 eff.append(p) 00503 upper_err.append(-p + 1/(1 + 1/d) * (t + s)) 00504 lower_err.append(+p - 1/(1 + 1/d) * (t - s)) 00505 except ZeroDivisionError: 00506 eff.append(0) 00507 upper_err.append(0) 00508 lower_err.append(0) 00509 return eff, upper_err, lower_err
00001 '''\ 00002 Copyright (c) 2009-2010 Jeff Klukas <klukas@wisc.edu> 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 '''
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.