alphatwirl.roottree package

Submodules

alphatwirl.roottree.BEventBuilder module

alphatwirl.roottree.BEvents module

alphatwirl.roottree.Branch module

class alphatwirl.roottree.Branch.Branch(name, array, countarray)[source]

Bases: object

This class encloses an array.array object, which is typically used to set the address of a branch of a ROOT TTree. This class is useful for fast access to contents of TTree.

While TTree can hold many types of data, including objects of user defined classes, this class can be used only for objects of simple types, such as Int_t, Double_t, and arrays of simple types.

Examples

Suppose jet_pt is an instance of this class and the corresponding object in TTree is an array.

>>> len(jet_pt)
3
>>> [v for v in jet_pt]
[127.16558074951172, 68.16969299316406, 53.75463104248047]

When the corresponding object in TTree is not an array but a simple type, the length is 1 and the only element is the value.

>>> len(mht)
1
>>> mht[0]
73.7677

alphatwirl.roottree.BranchAddressManager module

class alphatwirl.roottree.BranchAddressManager.BranchAddressManager[source]

Bases: object

The branch address manager for ROOT TTree

This class manages array.array objects used for branch addresses of ROOT TTree. The main purpose of this class is to prevent multiple arrays from being created for the same branch.

All instances of this class share the data.

arrayDict = {}
counterArrayDict = {}
getArrays(tree, branchName)[source]

return the array.array objects for the branch and its counter branch

This method returns a pair of the array.array objects. The first one is for the given tree and branch name. The second one is for its counter branch. The second one will be None when the branch does not have a counter. A pair of None will be returned when the tree does not have the branch.

alphatwirl.roottree.BranchAddressManager.inspectLeaf(tree, bname)[source]
alphatwirl.roottree.BranchAddressManager.IsROOTNullPointer(tobject)[source]

alphatwirl.roottree.BranchAddressManagerForVector module

alphatwirl.roottree.BranchBuilder module

alphatwirl.roottree.EventBuilder module

alphatwirl.roottree.EventBuilderConfig module

class alphatwirl.roottree.EventBuilderConfig.EventBuilderConfig(inputPaths, treeName, maxEvents, start, name)

Bases: tuple

inputPaths

Alias for field number 0

maxEvents

Alias for field number 2

name

Alias for field number 4

start

Alias for field number 3

treeName

Alias for field number 1

alphatwirl.roottree.Events module

class alphatwirl.roottree.Events.Events(tree, maxEvents=-1, start=0)[source]

Bases: object

An iterative object for events.

You can use this class to iterate over entries in a ROOT TTree.

You can instantiate this class with a TTree object and an optionally a maximum number of entries to loop over:

inputFile = ROOT.TFile.Open(inputPath)
tree = inputFile.Get(treeName)
events = Events(tree)

Then, the “for” loop for the tree entries can be:

for event in events:

Note: “event” and “events” are the same object. In each iteration, “event” (and “events”) is loaded with the next entry in the tree.

A content of the tree, e.g., a branch, can be accessed as an attribute of “event”:

event.jet_pt

In order to access to a particular entry, you can use an index. For example, to get 11th entry (the index for the first entry is 0):

event = events[10]

Note: Again “event” and “events” are the same object.

alphatwirl.roottree.inspect module

alphatwirl.roottree.inspect.IsROOTNullPointer(tobject)[source]
alphatwirl.roottree.inspect.inspect_tree(tree)[source]
alphatwirl.roottree.inspect.inspect_leaf(leaf)[source]
alphatwirl.roottree.inspect.inspect_leaf_definition(leaf)[source]
alphatwirl.roottree.inspect.inspect_leaf_size(leaf)[source]

Module contents