KaliVeda
Toolkit for HIC analysis
KVTreeVectorBranchHandler Class Reference

Detailed Description

Facilitate use of std::vector branches in data analysis.

To add an STL vector to a TTree branch, use the methods:

TTree* aTree;
AddVectorBranch<int>(aTree, "Z");
AddVectorBranch<double>(aTree, "E");

Variable types bool, std::string, int, float and double are supported.

To fill the vectors, do the following:

ClearVectorBranches(); // VERY important - do not forget!
for(auto& nuc : [iteration over an event])
{
FillVectorBranch("Z", nuc.GetZ());
FillVectorBranch("E", nuc.GetE());
}
void FillVectorBranch(const std::string &var, VarType val)
Note
when using vectors of std::string, a cast is required if the 2nd argument is 'const char*', e.g.
AddVectorBranch<std::string>(aTree, "Symbol");
...
FillVectorBranch("Name", (std::string)nuc.GetSymbol());

Definition at line 42 of file KVTreeVectorBranchHandler.h.

#include <KVTreeVectorBranchHandler.h>

Inheritance diagram for KVTreeVectorBranchHandler:

Public Member Functions

template<typename VarType >
void AddVectorBranch (TTree *t, const std::string &var)
 
void ClearVectorBranches ()
 
template<typename VarType >
void FillVectorBranch (const std::string &var, VarType val)
 

Member Function Documentation

◆ AddVectorBranch()

template<typename VarType >
void KVTreeVectorBranchHandler::AddVectorBranch ( TTree *  t,
const std::string &  var 
)
inline

Add a branch to the tree in order to store a vector of values

Template Parameters
VarTypetype of variable in vector (bool, std::string, int, float and double can be used)
Parameters
[in]tpointer to the TTree
[in]varname to be used for the new branch

Example of use:

AddVectorBranch<int>(t, "Z");
AddVectorBranch<double>(t, "E");

Definition at line 97 of file KVTreeVectorBranchHandler.h.

◆ ClearVectorBranches()

void KVTreeVectorBranchHandler::ClearVectorBranches ( )
inline

Clear all vectors contained in branches, ready to treat a new event

Definition at line 105 of file KVTreeVectorBranchHandler.h.

◆ FillVectorBranch()

template<typename VarType >
void KVTreeVectorBranchHandler::FillVectorBranch ( const std::string &  var,
VarType  val 
)
inline

Add a value to the vector contained in the named branch

Template Parameters
VarTypetype of variable in vector (bool, std::string, int, float and double can be used)
Parameters
[in]varname of branch
[in]valvalue to add to vector

Example of use:

KVNucleus& nuc; // reference to a nucleus in an event
FillVectorBranch("Z", nuc.GetZ());
FillVectorBranch("E", nuc.GetE());
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:108
Int_t GetZ() const
Return the number of proton / atomic number.
Definition: KVNucleus.cpp:776
Double_t GetE() const
Definition: KVParticle.h:655

Definition at line 128 of file KVTreeVectorBranchHandler.h.