RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
NodeBase Class Referenceabstract

Base class for the Node classes. More...

#include <NodeBase.h>

Inheritance diagram for NodeBase:
Node< Detail >

Data Structures

struct  NamerInitialiser
 Helper struct that forces the initialisation of the branch namer. More...
 

Public Member Functions

template<typename F >
enable_ifn_string_t< F, NodeBase * > Define (const std::string &name, F f, const ColumnNames_t &columns={})
 Define a new variable on this node. More...
 
NodeBaseDefine (const std::string &name, const std::string &expression)
 Define a new variable on this node. More...
 
NodeBaseDefine (const std::string &name, const std::string &expression, const ColumnNames_t &columns)
 Define a new variable on this node. More...
 
template<std::size_t N, typename F , typename Ret_t = typename ROOT::TTraits::CallableTraits<F>::ret_type>
std::enable_if_t< N==std::tuple_size< Ret_t >::value, NodeBase * > Define (const std::array< std::string, N > &names, F f, const ColumnNames_t &columns)
 Define several new variables on this node in a single statement. More...
 
const std::string & getWeight () const
 Get the name of the weight branch. More...
 
template<typename T >
SysResultPtr< T > Fill (const T &model, const ColumnNames_t &columns, const std::string &weight="", WeightStrategy strategy=WeightStrategy::Default)
 Fill an object on each event. More...
 
template<typename AccFun , typename MergeFun , typename ArgTypes = typename ROOT::TTraits::CallableTraits<AccFun>::arg_types, typename U = ROOT::TTraits::TakeFirstParameter_t<ArgTypes>>
SysResultPtr< U > Aggregate (AccFun aggregator, MergeFun merger, const std::string &columnName, const U &aggIdentity)
 Execute a user-defined accumulation function. More...
 
template<typename AccFun , typename MergeFun , typename ArgTypes = typename ROOT::TTraits::CallableTraits<AccFun>::arg_types, typename U = ROOT::TTraits::TakeFirstParameter_t<ArgTypes>>
SysResultPtr< U > Aggregate (AccFun aggregator, MergeFun merger, const std::string &columnName)
 Execute a user-defined accumulation function. More...
 
SysResultPtr< ULong64_t > Count ()
 Count the number of entries processed by this node. More...
 
template<typename... TrArgs, typename T , typename... Args>
std::map< std::string, T > Act (std::function< T(RNode &, TrArgs...)> f, const ColumnNames_t &columns, Args &&...args)
 Transmit a systematically varied action to the underlying ROOT::RNodes. More...
 
template<typename F , typename... Args, typename T = typename ROOT::TTraits::CallableTraits<F>::ret_type>
std::enable_if_t<!is_std_function< F >::value, std::map< std::string, T > > Act (F &&f, const ColumnNames_t &columns, Args &&...args)
 Transmit a systematically varied action to the underlying ROOT::RNodes. More...
 
template<typename T , typename... TrArgs, typename... Args>
std::map< std::string, T > Act (T(RNode::*f)(TrArgs...), const ColumnNames_t &columns, Args &&...args)
 Transmit a systematically varied action to the underlying ROOT::RNodes. More...
 
template<typename... TrArgs, typename T , typename... Args, typename U = typename T::Value_t>
SysResultPtr< U > ActResult (std::function< T(RNode &, TrArgs...)> f, const ColumnNames_t &columns, Args &&...args)
 Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr. More...
 
template<typename F , typename... Args, typename T = typename ROOT::TTraits::CallableTraits<F>::ret_type, typename U = typename T::Value_t>
std::enable_if_t<!is_std_function< F >::value, SysResultPtr< U > > ActResult (F &&f, const ColumnNames_t &columns, Args &&...args)
 Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr. More...
 
template<typename T , typename... TrArgs, typename... Args, typename U = typename T::Value_t>
SysResultPtr< U > ActResult (T(RNode::*f)(TrArgs...), const ColumnNames_t &columns, Args &&...args)
 Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr. More...
 
const std::string & name () const
 Get the name. More...
 
const std::string & cutflowName () const
 Get the name in a cutflow. More...
 
bool isAnonymous () const
 Is this anonymous? More...
 
bool isMC () const
 Was 'MC' mode activated? More...
 
const std::map< std::string, RNode > & rnodes () const
 Get the RNode objects. More...
 
std::map< std::string, RNode > & rnodes ()
 Get the RNode objects. More...
 
const IBranchNamernamer () const
 The namer. More...
 
auto objects ()
 Iterate over the objects defined on this. More...
 
auto objects () const
 (Const) iterate over all the objects defined on this More...
 
virtual bool isRoot () const =0
 Is the node the root? More...
 

Protected Member Functions

template<std::size_t I, std::size_t N, typename... Elements>
std::enable_if_t< I!=0, void > unwindDefine (const std::array< std::string, N > &names, const std::string &fullName, const std::tuple< Elements... > *)
 Base case for unwinding multiple define calls. More...
 
template<std::size_t I, std::size_t N, typename... Elements>
std::enable_if_t< I==0, void > unwindDefine (const std::array< std::string, N > &names, const std::string &fullName, const std::tuple< Elements... > *)
 Unwind multiple define calls. More...
 
template<typename F >
enable_ifn_string_t< F, std::map< std::string, RNode > > makeChildRNodes (F f, const ColumnNames_t &columns={}, const std::string &cutflowName="")
 Create child RNodes to be used for a filter from this node. More...
 
std::map< std::string, RNodemakeChildRNodes (const std::string &expression, const std::string &cutflowName="")
 Create child RNodes to be used for a filter from this node. More...
 
std::map< std::string, RNodemakeChildRNodes (const std::string &expression, const ColumnNames_t &columns, const std::string &cutflowName="")
 Create child RNodes to be used for a filter from this node. More...
 
 NodeBase (const RNode &rnode, std::unique_ptr< IBranchNamer > &&namer, bool isMC, const std::string &name="ROOT", const std::string &cutflowName="Number of events", const std::string &weight="", WeightStrategy strategy=WeightStrategy::Default)
 Create the root node of the tree. More...
 
template<typename W >
 NodeBase (const RNode &rnode, std::unique_ptr< IBranchNamer > &&namer, bool isMC, const std::string &name, const std::string &cutflowName, W w, const ColumnNames_t &columns, WeightStrategy strategy=WeightStrategy::Default)
 Create the root node of the tree. More...
 
 NodeBase (NodeBase &parent, std::map< std::string, RNode > &&rnodes, const std::string &name, const std::string &cutflowName, const std::string &weight, WeightStrategy strategy=WeightStrategy::Default)
 Create a child node. More...
 
template<typename W >
 NodeBase (NodeBase &parent, std::map< std::string, RNode > &&rnodes, const std::string &name, const std::string &cutflowName, W w, const ColumnNames_t &columns, WeightStrategy strategy=WeightStrategy::Default)
 Create a child node. More...
 
template<typename F >
enable_ifn_string_t< F, std::string > setWeight (F f, const ColumnNames_t &columns, NodeBase *parent, WeightStrategy strategy)
 Set the weight on this node. More...
 
std::string setWeight (const std::string &expression, NodeBase *parent, WeightStrategy strategy)
 Set the weight on this node. More...
 
std::string nameWeight ()
 Internal function to name the weight branch. More...
 

Protected Attributes

std::map< std::string, RNodem_rnodes
 The RNode objects, keyed by systematic. More...
 
std::unique_ptr< IBranchNamerm_namer
 The branch namer. More...
 
NamerInitialiser m_namerInit
 Helper struct to force early initialisation of the namer. More...
 
bool m_isMC
 Whether or not 'MC' mode was activated. More...
 
std::string m_name
 The Node's name. More...
 
std::string m_cutflowName
 The name in the cutflow. More...
 
RNodem_rootRNode = nullptr
 Keep a pointer to the ROOT RNode of the whole chain. More...
 
std::string m_weight
 The weight on this node. More...
 
std::vector< SysResultPtr< TObject > > m_objects
 Any TObject pointers declared on this. More...
 

Detailed Description

Base class for the Node classes.

This class contains everything that does not depend on the Detail parameter of the Node class. Many functions merely forward their calls onto the underlying ROOT::RNode objects, performing the necessary steps to allow for weights and systematics so you should consult the RDataFrame documentation for explanations of those functions.

Constructor & Destructor Documentation

NodeBase ( const RNode rnode,
std::unique_ptr< IBranchNamer > &&  namer,
bool  isMC,
const std::string &  name = "ROOT",
const std::string &  cutflowName = "Number of events",
const std::string &  weight = "",
WeightStrategy  strategy = WeightStrategy::Default 
)
protected

Create the root node of the tree.

Parameters
rnodeThe RDataFrame that forms the base of the tree
namerThe branch namer
isMCIf true, set the 'MC' mode, otherwise the 'data' mode
nameThe name of the root node
cutflowNameHow the root node appears in the cutflow
weightExpression to calculate a weight.
strategyWeighting strategy for this weight
NodeBase ( const RNode rnode,
std::unique_ptr< IBranchNamer > &&  namer,
bool  isMC,
const std::string &  name,
const std::string &  cutflowName,
w,
const ColumnNames_t columns,
WeightStrategy  strategy = WeightStrategy::Default 
)
protected

Create the root node of the tree.

Template Parameters
WThe functor used to calculate the weight
Parameters
rnodeThe RDataFrame that forms the base of the tree
namerThe branch namer
isMCIf true, set the 'MC' mode, otherwise the 'data' mode
nameThe name of the root node
cutflowNameHow the root node appears in the cutflow
wFunctor used to calculate the weight
columnsThe input columns for the weight
strategyWeighting strategy for this weight
NodeBase ( NodeBase parent,
std::map< std::string, RNode > &&  rnodes,
const std::string &  name,
const std::string &  cutflowName,
const std::string &  weight,
WeightStrategy  strategy = WeightStrategy::Default 
)
protected

Create a child node.

Parameters
parentThe parent of this node
rnodesThis node's RNodes
nameThe name of this node
cutflowNameHow this node appears in cutflows
weightExpression to calculate the node weight
strategyWeighting strategy for this weight
NodeBase ( NodeBase parent,
std::map< std::string, RNode > &&  rnodes,
const std::string &  name,
const std::string &  cutflowName,
w,
const ColumnNames_t columns,
WeightStrategy  strategy = WeightStrategy::Default 
)
protected

Create a child node.

Template Parameters
WThe functor used to calculate the weight
Parameters
parentThe parent of this node
rnodesThis node's RNodes
nameThe name of this node
cutflowNameHow this node appears in cutflows
wFunctor used to calculate the weight
columnsThe input columns for the weight
strategyWeighting strategy for this weight

Member Function Documentation

std::map<std::string, T> Act ( std::function< T(RNode &, TrArgs...)>  f,
const ColumnNames_t columns,
Args &&...  args 
)

Transmit a systematically varied action to the underlying ROOT::RNodes.

Template Parameters
TrArgsThe types of the action's arguments
TThe return type of the action
ArgsThe types of the arguments before translation
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
A map of systematic name to action return type

Most functions on the Node classes get routed through this or one of its overloads. It carries out the following operations:

  1. Use columns to determine which systematics affect this action
  2. Apply the action to each underlying systematic-specific RNode, even those not in the list found in the previous step
  3. For each remaining systematic from step 1 apply the action to the nominal RNode. When applying an action for a specific systematic any arguments that can be translated are. For information on argument translation see SysVar.h

The first parameter of f should be a ROOT::RNode&, this will be provided by this function and should not be included in args, as it will provide each systematically varied ROOT::RNode in turn.

std::enable_if_t<!is_std_function<F>::value, std::map<std::string, T> > Act ( F &&  f,
const ColumnNames_t columns,
Args &&...  args 
)
inline

Transmit a systematically varied action to the underlying ROOT::RNodes.

Template Parameters
FThe function type
ArgsThe argument types
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
A map of systematic name to action return type

Overload for non-member functions, will forward the call to Node::Act<TrArgs, T, Args>.

std::map<std::string, T> Act ( T(RNode::*)(TrArgs...)  f,
const ColumnNames_t columns,
Args &&...  args 
)

Transmit a systematically varied action to the underlying ROOT::RNodes.

Template Parameters
TrArgsThe types of the action's arguments
TThe return type of the action
ArgsThe types of the arguments before translation
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
A map of systematic name to action return type

Most functions on the Node classes get routed through this or one of its overloads. It carries out the following operations:

  1. Use columns to determine which systematics affect this action
  2. Apply the action to each underlying systematic-specific RNode, even those not in the list found in the previous step
  3. For each remaining systematic from step 1 apply the action to the nominal RNode. When applying an action for a specific systematic any arguments that can be translated are. For information on argument translation see SysVar.h

This overload is selected when f is a member function of ROOT::RNode. In this case is usually necessary to specify T and TrArgs in the call.

SysResultPtr<U> ActResult ( std::function< T(RNode &, TrArgs...)>  f,
const ColumnNames_t columns,
Args &&...  args 
)
inline

Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr.

Template Parameters
TrArgsThe types of the action's arguments
TThe return type of the action, should be a ROOT::RDF::RResultPtr
ArgsThe types of the arguments before translation
UThe type wrapped by T
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
The SysResultPtr generated by the action

This function wraps Act for cases where it returns an RResultPtr and wraps that return value in a SysResultPtr.

std::enable_if_t<!is_std_function<F>::value, SysResultPtr<U> > ActResult ( F &&  f,
const ColumnNames_t columns,
Args &&...  args 
)
inline

Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr.

Template Parameters
FThe type of the action
TThe return type of the action, should be a ROOT::RDF::RResultPtr
ArgsThe types of the arguments before translation
UThe type wrapped by T
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
The SysResultPtr generated by the action

This function wraps Act for cases where it returns an RResultPtr and wraps that return value in a SysResultPtr.

SysResultPtr<U> ActResult ( T(RNode::*)(TrArgs...)  f,
const ColumnNames_t columns,
Args &&...  args 
)
inline

Specialised version of Node::Act for functions returning a ROOT::RDF::RResultPtr.

Template Parameters
TrArgsThe types of the action's arguments
TThe return type of the action, should be a ROOT::RDF::RResultPtr
ArgsThe types of the arguments before translation
UThe type wrapped by T
Parameters
fThe action
columnsThe columns affected by the action
argsThe arguments to the action
Returns
The SysResultPtr generated by the action

This function wraps Act for cases where it returns an RResultPtr and wraps that return value in a SysResultPtr. This overload is selected when the action is a member function of ROOT::RNode.

SysResultPtr<U> Aggregate ( AccFun  aggregator,
MergeFun  merger,
const std::string &  columnName,
const U &  aggIdentity 
)
inline

Execute a user-defined accumulation function.

Template Parameters
AccFunThe type of the accumulation function
MergeFunThe type of the merging function
UThe return type of the accumulation function
Parameters
aggregatorThe accumulation function
mergerThe merging function
columnNameThe column for the funtion to act on
aggIdentityThe identity
See also
https://root.cern.ch/doc/v614/classROOT_1_1RDF_1_1RInterface.html#ae540b00addc441f9b504cbae0ef0a24d
SysResultPtr<U> Aggregate ( AccFun  aggregator,
MergeFun  merger,
const std::string &  columnName 
)
inline

Execute a user-defined accumulation function.

Template Parameters
AccFunThe type of the accumulation function
MergeFunThe type of the merging function
UThe return type of the accumulation function
Parameters
aggregatorThe accumulation function
mergerThe merging function
columnNameThe column for the funtion to act on
See also
https://root.cern.ch/doc/v614/classROOT_1_1RDF_1_1RInterface.html#a7d82cb96013d9fe75cf4cc4a57f6d692
SysResultPtr<ULong64_t> Count ( )
inline
const std::string& cutflowName ( ) const
inline

Get the name in a cutflow.

enable_ifn_string_t<F, NodeBase*> Define ( const std::string &  name,
f,
const ColumnNames_t columns = {} 
)

Define a new variable on this node.

Template Parameters
FThe functor type
Parameters
nameThe name of the column to define
fThe functor
columnsThe input variables (if any) to the functor
Returns
A non-owning pointer to this object.

The new column's data type will be the return type of the functor

NodeBase * Define ( const std::string &  name,
const std::string &  expression 
)

Define a new variable on this node.

Parameters
nameThe name of the column to define
expressionThe string expression to interpret
Returns
A non-owning pointer to this object.

The new column's data type will be the return type of the JITted function

NodeBase * Define ( const std::string &  name,
const std::string &  expression,
const ColumnNames_t columns 
)

Define a new variable on this node.

Parameters
nameThe name of the column to define
expressionThe string expression to interpret
columnsThe input variables to the expression
Returns
A non-owning pointer to this object.

The new column's data type will be the return type of the JITted function. The expression should have the column names replaced by placeholders like {idx} (where idx is the index of the branch in the columns vector).

std::enable_if_t<N==std::tuple_size<Ret_t>::value, NodeBase*> Define ( const std::array< std::string, N > &  names,
f,
const ColumnNames_t columns 
)

Define several new variables on this node in a single statement.

Template Parameters
FThe functor type
Ret_tThe return type of the functor - must be a tuple
NThe number of defined arguments
Parameters
namesThe names of the defined variables
fThe functor
columnsThe inputs to the functor
Returns
a non-owning pointer to this object.

Use this function where you need to return multiple variables from a single function. Note that the affecting systematics will be the same for all of the returned objects so make sure that this is appropriate. The functor should return a std::tuple with N different types and the names parameter should have exactly the same number of entries (else the code will not compile).

SysResultPtr<T> Fill ( const T &  model,
const ColumnNames_t columns,
const std::string &  weight = "",
WeightStrategy  strategy = WeightStrategy::Default 
)

Fill an object on each event.

Template Parameters
TThe type of object to be filled.
Parameters
modelThe 'model' object to fill.
columnsThe columns to use for the object's Fill method.
weightThe column containing the weight information
strategyThe weight strategy to use

Note that right now this won't work if T doesn't inherit from TH1. TODO fix this! The method also assumes that the weight is always provided as the last input column for the RDF Fill Action. This is always true for types inheriting from TH1 but other objects (particularly user-defined ones) will behave differently. For these cases I will need to specialise the 'Book' action.

const std::string& getWeight ( ) const
inline

Get the name of the weight branch.

The name returned will be the base name, not resolved for any systematic variation. If there is no weight set the empty string will be returned.

bool isAnonymous ( ) const
inline

Is this anonymous?

bool isMC ( ) const
inline

Was 'MC' mode activated?

virtual bool isRoot ( ) const
pure virtual

Is the node the root?

Implemented in Node< Detail >.

enable_ifn_string_t<F, std::map<std::string, RNode> > makeChildRNodes ( f,
const ColumnNames_t columns = {},
const std::string &  cutflowName = "" 
)
protected

Create child RNodes to be used for a filter from this node.

Template Parameters
FThe functor type
Parameters
fThe functor
columnsThe input variables to the functor
cutflowNameThe cutflow name of these nodes
std::map< std::string, RNode > makeChildRNodes ( const std::string &  expression,
const std::string &  cutflowName = "" 
)
protected

Create child RNodes to be used for a filter from this node.

Parameters
expressionThe expression to describe the filter
cutflowNameThe cutflow name of these nodes
std::map< std::string, RNode > makeChildRNodes ( const std::string &  expression,
const ColumnNames_t columns,
const std::string &  cutflowName = "" 
)
protected

Create child RNodes to be used for a filter from this node.

Parameters
expressionThe expression to describe the filter
columnsThe input variables to the expression
cutflowNameThe cutflow name of these nodes

The expression should have the column names replaced by placeholders like {idx} (where idx is the index of the branch in the columns vector).

const std::string& name ( ) const
inline

Get the name.

const IBranchNamer& namer ( ) const
inline

The namer.

std::string nameWeight ( )
protected

Internal function to name the weight branch.

auto objects ( )
inline

Iterate over the objects defined on this.

auto objects ( ) const
inline

(Const) iterate over all the objects defined on this

const std::map<std::string, RNode>& rnodes ( ) const
inline

Get the RNode objects.

std::map<std::string, RNode>& rnodes ( )
inline

Get the RNode objects.

enable_ifn_string_t<F, std::string> setWeight ( f,
const ColumnNames_t columns,
NodeBase parent,
WeightStrategy  strategy 
)
protected

Set the weight on this node.

Template Parameters
Fthe functor type
Parameters
fThe functor
columnsThe input columns to f (if any)
parentThe parent (if any) of this node
strategyThe weighting strategy to apply
Returns
The name of the new weight The new weight will be calculated and stored in a new branch.
std::string setWeight ( const std::string &  expression,
NodeBase parent,
WeightStrategy  strategy 
)
protected

Set the weight on this node.

Parameters
expressionThe expression to calculate the weight
parentThe parent (if any) of this node
strategyThe weighting strategy to apply
Returns
The name of the new weight The new weight will be calculated and stored in a new branch.
std::enable_if_t<I!=0, void> unwindDefine ( const std::array< std::string, N > &  names,
const std::string &  fullName,
const std::tuple< Elements... > *   
)
protected

Base case for unwinding multiple define calls.

std::enable_if_t<I == 0, void> unwindDefine ( const std::array< std::string, N > &  names,
const std::string &  fullName,
const std::tuple< Elements... > *   
)
protected

Unwind multiple define calls.

Field Documentation

std::string m_cutflowName
protected

The name in the cutflow.

bool m_isMC
protected

Whether or not 'MC' mode was activated.

std::string m_name
protected

The Node's name.

std::unique_ptr<IBranchNamer> m_namer
protected

The branch namer.

NamerInitialiser m_namerInit
protected

Helper struct to force early initialisation of the namer.

std::vector<SysResultPtr<TObject> > m_objects
protected

Any TObject pointers declared on this.

std::map<std::string, RNode> m_rnodes
protected

The RNode objects, keyed by systematic.

RNode* m_rootRNode = nullptr
protected

Keep a pointer to the ROOT RNode of the whole chain.

std::string m_weight
protected

The weight on this node.


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