TIMBER  beta
Tree Interface for Making Binned Events with RDataFrame
Public Member Functions | Public Attributes | List of all members
Node Class Reference

Class to represent nodes in the DataFrame processing graph. More...

Inheritance diagram for Node:
Inheritance graph
[legend]
Collaboration diagram for Node:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, name, DataFrame, action='', nodetype='', children=[], parent=None)
 Constructor. More...
 
def Close (self)
 Safely deletes Node instance and all descendants. More...
 
def __str__ (self)
 Call with print(<Node>) to print a nicely formatted description of the Node object for debugging. More...
 
def Clone (self, name='')
 Clones Node instance without child information and with new name if specified. More...
 
def SetChild (self, child, overwrite=False)
 Set one of child for the node. More...
 
def SetChildren (self, children, overwrite=False)
 Set multiple children for the node. More...
 
def Define (self, name, var, nodetype=None, silent=False)
 Produces a new Node with the provided variable/column added. More...
 
def Cut (self, name, cut, nodetype=None, silent=False)
 Produces a new Node with the provided cut/filter applied. More...
 
def Discriminate (self, name, discriminator)
 Produces a dictionary with two new Nodes made by forking this Node based upon a discriminator being True or False. More...
 
def Apply (self, actionGroupList)
 Applies a single CutGroup/VarGroup or an ordered list of Groups to this Node to produce a new final Node. More...
 
def Range (self, argv)
 Calls the RDataFrame Range method. More...
 
def Snapshot (self, columns, outfilename, treename, lazy=False, openOption='RECREATE')
 Takes a snapshot of the RDataFrame corresponding to this Node. More...
 
def GetBaseNode (self)
 Returns the top-most parent Node by climbing node tree until a Node with no parent is reached. More...
 

Public Attributes

 DataFrame
 DataFrame for the Node.
 
 name
 Name of the Node.
 
 action
 Action performed to create this Node.
 
 children
 List of child nodes.
 
 parent
 Parent node.
 
 type
 Either 'Cut' or 'Define' depending what generated the Node. More...
 

Detailed Description

Class to represent nodes in the DataFrame processing graph.

Can make new nodes via Define, Cut, and Discriminate and setup relations between nodes (done automatically via Define, Cut, Discriminate)

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name,
  DataFrame,
  action = '',
  nodetype = '',
  children = [],
  parent = None 
)

Constructor.

Holds the RDataFrame and other associated information for tracking in the analyzer.

Methods which act on the RDataFrame always return a new node since RDataFrame is not modified in place.

Parameters
name(str): Name for the node. Duplicate named nodes cannot be tracked simultaneously in the analyzer.
DataFrame(RDataFrame): Dataframe to track.
children([Node], optional): Child nodes if they exist. Defaults to [].
parent(Node, optional): Parent node if it exists. Defaults to None.
nodetype(str, optional): The type of the Node. Useful for organizing and grouping Nodes. Defaults to ''.
action(str, optional): Action performed (the C++ line). Default is '' but should only be used for a base RDataFrame.

Member Function Documentation

◆ __str__()

def __str__ (   self)

Call with print(<Node>) to print a nicely formatted description of the Node object for debugging.

Returns
str

◆ Apply()

def Apply (   self,
  actionGroupList 
)

Applies a single CutGroup/VarGroup or an ordered list of Groups to this Node to produce a new final Node.

Parameters
actionGroupList(Group, list(Group)): The CutGroup or VarGroup to act on node or a list of CutGroups or VarGroups to act (in order) on node.
Exceptions
TypeErrorIf argument type is not Node.
Returns
Node New Node with all actions applied.

◆ Clone()

def Clone (   self,
  name = '' 
)

Clones Node instance without child information and with new name if specified.

Parameters
name(str, optional): Name for clone. Defaults to current name.
Returns
Node Clone of current instance.

◆ Close()

def Close (   self)

Safely deletes Node instance and all descendants.

Returns
None

◆ Cut()

def Cut (   self,
  name,
  cut,
  nodetype = None,
  silent = False 
)

Produces a new Node with the provided cut/filter applied.

Parameters
name(str): Name for the cut for internal tracking and later reference.
cut(str): A one-line C++ string that evaluates as a boolean.
nodetype(str, optional): Defaults to None in which case the new Node will be type "Cut".
silent(bool, optional): If False, prints the definition action to the terminal. Defaults to False.
Returns
Node New Node object with cut applied.

◆ Define()

def Define (   self,
  name,
  var,
  nodetype = None,
  silent = False 
)

Produces a new Node with the provided variable/column added.

Parameters
name(str): Name for the column for internal tracking and later reference.
var(str): A one-line C++ string that evaluates to desired value to store.
nodetype(str, optional): Defaults to None in which case the new Node will be type "Define".
silent(bool, optional): If False, prints the definition action to the terminal. Defaults to False.
Returns
Node New Node object with new column added.

◆ Discriminate()

def Discriminate (   self,
  name,
  discriminator 
)

Produces a dictionary with two new Nodes made by forking this Node based upon a discriminator being True or False.

Parameters
name(str): Name for the discrimination for internal tracking and later reference.
discriminator(str): A one-line C++ string that evaluates as a bool to discriminate on.
Returns
dict Dictionary with keys "pass" and "fail" corresponding to the passing and failing Nodes stored as values.

◆ GetBaseNode()

def GetBaseNode (   self)

Returns the top-most parent Node by climbing node tree until a Node with no parent is reached.

Returns
Node Top-most parent Node.

◆ Range()

def Range (   self,
  argv 
)

Calls the RDataFrame Range method.

Follows the same syntax (ie. Range(begin, end, stride) or Range(end)).

Warning
Will not work with ROOT.EnableImplicitMT(). Please comment this out before using Range().
Returns
Node New node with specified range of entries selected.

◆ SetChild()

def SetChild (   self,
  child,
  overwrite = False 
)

Set one of child for the node.

Parameters
child(Node): Child node to add.
overwrite(bool, optional): Overwrites all current children stored. Defaults to False.
Exceptions
TypeErrorIf argument type is not Node.

◆ SetChildren()

def SetChildren (   self,
  children,
  overwrite = False 
)

Set multiple children for the node.

Parameters
children([Node], {str:Node}): List of children or dictionary of children.
overwrite(bool, optional): Overwrites all current children stored. Defaults to False.
Exceptions
TypeErrorIf argument type is not dict or list of Node.

◆ Snapshot()

def Snapshot (   self,
  columns,
  outfilename,
  treename,
  lazy = False,
  openOption = 'RECREATE' 
)

Takes a snapshot of the RDataFrame corresponding to this Node.

Compression algorithm set to 1 (ZLIB) and compression level are set to 1.

IMPORTANT When writing a variable size array through Snapshot, it is required that the column indicating its size is also written out and it appears before the array in the columns list. The columns argument should be "all" if you'd like to keep everything.

Parameters
columns([str] or str): List of columns to keep (str) with regex matching. Provide single string 'all' to include all columns.
outfilename(str): Name of the output file
treename([type]): Name of the output TTree
lazy(bool, optional): If False, the RDataFrame actions until this point will be executed here. Defaults to False.
openOption(str, optional): TFile opening options. Defaults to 'RECREATE'.
Returns
None

Member Data Documentation

◆ type

type

Either 'Cut' or 'Define' depending what generated the Node.

The "type" of Node.

Can be modified but by default will be either "Define", "Cut", "MergeDefine", "SubCollDefine", or "Correction".


The documentation for this class was generated from the following file: