pyroot_zen package

Submodules

pyroot_zen.RooArgList module

Note: Natively, RooArgList has __getitem__ defined, taking int key as input.

pyroot_zen.RooArgList.__iter__(self)[source]
>>> list = getfixture('sample_RooArgList')
>>> for x in list:
...   print x
<ROOT.RooRealVar object ("x") at ...>
<ROOT.RooRealVar object ("y") at ...>
<ROOT.RooRealVar object ("z") at ...>

pyroot_zen.RooArgSet module

Make RooArgSet obeys the pythonic-set protocol, with additional non-ambigious dictionary protocol.

Note: Natively, RooArgSet has __getitem__ defined, taking string key as input.

pyroot_zen.RooArgSet.__iter__(self)[source]

Iterate over set objects, additionally ordered by their names.

>>> set = getfixture('sample_RooArgSet')
>>> for x in set:
...   print x
<ROOT.RooRealVar object ("x") at ...>
<ROOT.RooRealVar object ("y") at ...>
<ROOT.RooRealVar object ("z") at ...>
pyroot_zen.RooArgSet.iteritems(self)[source]

Provide the dict-iterable protocol, yield (key, obj) in this RooArgSet.

>>> set = getfixture('sample_RooArgSet')
>>> for key, val in set.iteritems():
...   print key, val
x <ROOT.RooRealVar object ("x") at ...>
y <ROOT.RooRealVar object ("y") at ...>
z <ROOT.RooRealVar object ("z") at ...>
pyroot_zen.RooArgSet.keys(self)[source]

Like dict.keys.

>>> set = getfixture('sample_RooArgSet')
>>> set.keys()
['x', 'y', 'z']

pyroot_zen.RooCategory module

pyroot_zen.RooCategory.__iter__(self)[source]

Loop over ordered labels.

>>> cat = getfixture('sample_RooCategory')
>>> for x in cat: print(x)
alpha
beta
gamma
pyroot_zen.RooCategory.__len__(self)[source]
>>> cat = getfixture('sample_RooCategory')
>>> len(cat)
3

pyroot_zen.RooWorkspace module

pyroot_zen.RooWorkspace.Import(self, *args, **kwargs)[source]

Workaround “import” keyword (which is a reserved keyword in python):

## Prepare
>>> w = ROOT.RooWorkspace()
>>> h = ROOT.TH1F('name', 'title', 100, 0, 100)

## Returns kTRUE if an error has occurred.
>>> w.Import(h)
False

## Support import arguments
>>> w.Import(h, "newname", True)
False

pyroot_zen.TH1 module

pyroot_zen.TH1.init(old_init)[source]

Provide additional constructor signature:

TH1( name, title, arr )

i.e., skip the argument for array’s length, where arr are bins edges. The number of bins is narr-1

>>> ROOT.TH1F('name', 'title', range(10))
<ROOT.TH1F object ("name") at ...>

pyroot_zen.TH2 module

pyroot_zen.TH2.init(old_init)[source]

Provide additional constructor signature:

TH2( name, title, xarr, yarr )

where xarr, yarr are bins edges. The number of bins are nx-1, ny-1:

>>> ROOT.TH2F('H2', 'H2', range(8), range(10))
<ROOT.TH2F object ("H2") at ...>

>>> ROOT.TProfile2D('P2', 'P2', range(8), range(10))
<ROOT.TProfile2D object ("P2") at ...>

## old signature still works
>>> ROOT.TH2F('H3', 'H3', 9, range(10), 9, range(10))
<ROOT.TH2F object ("H3") at ...>

pyroot_zen.TMultiGraph module

pyroot_zen.TMultiGraph.__getitem__(self, index)[source]

Delegate the GetListOfGraphs to __getitem__ protocol.

>>> g1 = ROOT.TGraph()
>>> g1.name = 'g1'
>>> gr = ROOT.TMultiGraph()
>>> gr.Add(g1)
>>> gr[0]
<ROOT.TGraph object ("g1") at ...>
pyroot_zen.TMultiGraph.__len__(self)[source]

Return the number of graphs in this TMultiGraph.

>>> gr = ROOT.TMultiGraph()
>>> gr.Add(ROOT.TGraph())
>>> gr.Add(ROOT.TGraph())
>>> len(gr)
2

pyroot_zen.TObject module

pyroot_zen.TObject.getattr(cls, func_default=None)[source]

Shorten the getter to pythonic-descriptor, valid only for getter with no arguments:

## Simple class
>>> obj = ROOT.TH1F('htemp1', 'htemp1', 100, 0, 100)
>>> obj.name            # Instead of obj.GetName()
'htemp1'
>>> ROOT.gROOT.files    # Instead of gROOT.GetListOfFiles()
<ROOT.TList object ("Files") at ...>

## Some class has innate getattr, so it'll be decorated
>>> ROOT.TTree.__getattr__
<unbound method TTree.__getattr__>
>>> obj = ROOT.TTree('some_name', 'some_title')
>>> obj.title           # Instead of obj.GetTitle()
'some_title'

## This should not interfere with existing facility, as it's only a fallback.
>>

## If missing, raise exception
>>> obj.unknown_attr
Traceback (most recent call last):
  ...
AttributeError: 'TTree' object has no attribute 'unknown_attr'
pyroot_zen.TObject.getitem(self, key)[source]

Shorten obj.FindObject('name') to obj['name']:

>>> h = ROOT.TH1F('htemp2', 'htemp2', 100, 0, 100)

>>> ROOT.gROOT['htemp2']
<ROOT.TH1F object ("htemp2") at ...>

>>> ROOT.gROOT['bad_item']
Traceback (most recent call last):
  ...
KeyError: 'bad_item'

pyroot_zen.utils module

Provide utils use for patcher.

pyroot_zen.utils.DoubleArray(arg)[source]

Try to cast arg of correct type to array('d'). If it’s not the right type, return the original:

>>> DoubleArray([2, 3, 4])
array('d', [2.0, 3.0, 4.0])

>>> DoubleArray('string')
'string'

>>> DoubleArray(42)
42
pyroot_zen.utils.RooArgList(arg)[source]

Try to cast arg of correct type to RooArgList. If it’s not the right type, return the original:

>>> RooArgList([1, 2, 3])  # need RooAbsArg, do nothing
[1, 2, 3]
pyroot_zen.utils.RooArgSet(arg)[source]

Try to cast arg of correct type to RooArgSet. If it’s not the right type, return the original:

>>> RooArgSet({1, 2, 3})  # need RooAbsArg, do nothing
set([1, 2, 3])
pyroot_zen.utils.RooCmdArg(*args)[source]

Caster for RooCmdArg from keyword-arguments:

>>> RooCmdArg('Name', 'somename')
<ROOT.RooCmdArg object ("Name") at ...>
pyroot_zen.utils.StdMap_string_RooDataSet(arg)[source]

For RooFit.Import(std::map<string, RooDataSet*>) signature:

>>> ds1 = ROOT.RooDataSet()
>>> ds2 = ROOT.RooDataSet()
>>> map = StdMap_string_RooDataSet({'signal': ds1, 'bkg': ds2})
>>> map
<ROOT.map<string,RooDataSet*> object at ...>
>>> map.size()
2L
>>> len(map)
2
>>> map['signal']
<ROOT.RooDataSet object at ...>

## For incorrect type
>>> StdMap_string_RooDataSet('not_a_dict')
'not_a_dict'
pyroot_zen.utils.capfirst(s)[source]
>>> capfirst('aaa')
'Aaa'
>>> capfirst('aaaBbbCcc')
'AaaBbbCcc'
pyroot_zen.utils.new_signature_patcher(*args_casters, **kwargs_casters)[source]

This function return the patcher (decotator), ready to be applied to the target object, such that everytime the object makes a call:

obj(*args, **kwargs)

The args and kwargs will go through the given list of args_casters, kwargs_casters respectively.

Example:

>> patcher = utils.new_signature_patcher(utils.RooArgSet, utils.RooArgList, kw=utils.RooCmdArg)
pyroot_zen.utils.pythoncase_to_camelcase(s)[source]
>>> pythoncase_to_camelcase("line_color")
'LineColor'
>>> pythoncase_to_camelcase('AlreadyCamelCase')
'AlreadyCamelCase'
>>> pythoncase_to_camelcase('lowerCamelCase')
'LowerCamelCase'
pyroot_zen.utils.tuple_last_arg(func)[source]

Make sure the last argument of the function is wrapped into tuple, useful when it’s a setter-style class, ready to be unpacked. Only valid for non-kwargs function

>>> @tuple_last_arg
... def foo(key, val):
...   print key, val
>>> foo('key', 'val')
key ('val',)

Module contents

pyroot_zen package.