ant
A2 ant: class-based analysis framework
ant::WrapTTree Class Reference

The WrapTTree struct simplifies TTree handling in physics classes. More...

#include <WrapTTree.h>

+ Inheritance diagram for ant::WrapTTree:

Classes

struct  Branch_Opt_t
 
struct  Branch_t
 
struct  Exception
 
struct  ROOTArray
 
struct  ROOTArrayException
 
struct  ROOTArrayNotifier_t
 

Public Types

template<std::size_t N>
using ROOTArray_Float = ROOTArray< std::array< float, N > >
 
template<std::size_t N>
using ROOTArray_Double = ROOTArray< std::array< double, N > >
 
template<std::size_t N>
using ROOTArray_Int = ROOTArray< std::array< int, N > >
 
template<std::size_t N>
using ROOTArray_Long = ROOTArray< std::array< long, N > >
 

Public Member Functions

void CreateBranches (TTree *tree, bool skipOptional=false)
 CreateBranches prepares the instance for filling the TTree. More...
 
void LinkBranches (TTree *tree=nullptr, bool requireOptional=false)
 LinkBranches prepares the instance for reading the TTree. More...
 
void LinkBranches (bool requireOptional)
 
bool Matches (TTree *tree=nullptr, bool exact=true, bool nowarn=false) const
 Matches checks if the branch names are all available. More...
 
bool CopyFrom (const WrapTTree &src)
 CopyFrom copies contents in branches by name. More...
 
 operator bool () const
 operator bool returns true if Tree is not null More...
 

Public Attributes

TTree * Tree = nullptr
 Tree to be used as usual TTree. More...
 

Protected Member Functions

 WrapTTree (const std::string &branchNamePrefix_="")
 
 ~WrapTTree ()
 

Detailed Description

The WrapTTree struct simplifies TTree handling in physics classes.

Example usage:

struct treeTest_t : WrapTTree {
  ADD_BRANCH_T(bool,   IsSignal)
  ADD_BRANCH_T(double, KinFitChi2)
  // ... more branches using macro ADD_BRANCH_T
  // ... if reading, ADD_BRANCH_OPT_T specifies branches which may not be present
};

treeTest_t treeTest;

... in constructor, setup for "writing" ...

treeTest.CreateBranches(HistFac.makeTTree("test"));

... get/set branches via operator() ...

treeTest.IsSignal() = b_IsSignal;

... fill (or get entry) ...

treeTest.Tree->Fill();

In order to read the tree created above, LinkBranches() is used (using ant::WrapTFileInput):

WrapTFileInput inputfile("/some/path/to/filename");
treeTest_t treeTest;
if(inputfile.GetObject("test", treeTest.Tree))
  treeTest.LinkBranches(); // uses already set Tree

Note that WrapTTree even supports branches created with "branchname[sizebranch]" via WrapTTree::ROOTArray<T>, which wraps it into an conviniently usable std::vector<T>

Member Typedef Documentation

◆ ROOTArray_Double

template<std::size_t N>
using ant::WrapTTree::ROOTArray_Double = ROOTArray<std::array<double,N> >

◆ ROOTArray_Float

template<std::size_t N>
using ant::WrapTTree::ROOTArray_Float = ROOTArray<std::array<float,N> >

◆ ROOTArray_Int

template<std::size_t N>
using ant::WrapTTree::ROOTArray_Int = ROOTArray<std::array<int,N> >

◆ ROOTArray_Long

template<std::size_t N>
using ant::WrapTTree::ROOTArray_Long = ROOTArray<std::array<long,N> >

Constructor & Destructor Documentation

◆ WrapTTree()

WrapTTree::WrapTTree ( const std::string &  branchNamePrefix_ = "")
explicitprotected

◆ ~WrapTTree()

WrapTTree::~WrapTTree ( )
protected

Member Function Documentation

◆ CopyFrom()

bool WrapTTree::CopyFrom ( const WrapTTree src)

CopyFrom copies contents in branches by name.

Parameters
srcthe source of the contents to be copied
Returns
true if successful, false on mismatch

◆ CreateBranches()

void WrapTTree::CreateBranches ( TTree *  tree,
bool  skipOptional = false 
)

CreateBranches prepares the instance for filling the TTree.

Parameters
treethe tree to be filled
skipOptionalif true, do not create ADD_BRANCH_OPT_T branches

◆ LinkBranches() [1/2]

void WrapTTree::LinkBranches ( TTree *  tree = nullptr,
bool  requireOptional = false 
)

LinkBranches prepares the instance for reading the TTree.

Parameters
treethe tree to read from, or use already set Tree class member
requireOptionalif true, do not ignore ADD_BRANCH_OPT_T branches silently

◆ LinkBranches() [2/2]

void WrapTTree::LinkBranches ( bool  requireOptional)

◆ Matches()

bool WrapTTree::Matches ( TTree *  tree = nullptr,
bool  exact = true,
bool  nowarn = false 
) const

Matches checks if the branch names are all available.

Parameters
treethe tree to check
exactif false, the TTree may have additional branches
Returns
true if successful

◆ operator bool()

ant::WrapTTree::operator bool ( ) const
inlineexplicit

operator bool returns true if Tree is not null

Member Data Documentation

◆ Tree

TTree* ant::WrapTTree::Tree = nullptr

Tree to be used as usual TTree.


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