|
ant
A2 ant: class-based analysis framework
|
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 () | |
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>
| using ant::WrapTTree::ROOTArray_Double = ROOTArray<std::array<double,N> > |
| using ant::WrapTTree::ROOTArray_Float = ROOTArray<std::array<float,N> > |
| using ant::WrapTTree::ROOTArray_Int = ROOTArray<std::array<int,N> > |
| using ant::WrapTTree::ROOTArray_Long = ROOTArray<std::array<long,N> > |
|
explicitprotected |
|
protected |
| bool WrapTTree::CopyFrom | ( | const WrapTTree & | src | ) |
CopyFrom copies contents in branches by name.
| src | the source of the contents to be copied |
| void WrapTTree::CreateBranches | ( | TTree * | tree, |
| bool | skipOptional = false |
||
| ) |
CreateBranches prepares the instance for filling the TTree.
| tree | the tree to be filled |
| skipOptional | if true, do not create ADD_BRANCH_OPT_T branches |
| void WrapTTree::LinkBranches | ( | TTree * | tree = nullptr, |
| bool | requireOptional = false |
||
| ) |
LinkBranches prepares the instance for reading the TTree.
| tree | the tree to read from, or use already set Tree class member |
| requireOptional | if true, do not ignore ADD_BRANCH_OPT_T branches silently |
| void WrapTTree::LinkBranches | ( | bool | requireOptional | ) |
| bool WrapTTree::Matches | ( | TTree * | tree = nullptr, |
| bool | exact = true, |
||
| bool | nowarn = false |
||
| ) | const |
Matches checks if the branch names are all available.
| tree | the tree to check |
| exact | if false, the TTree may have additional branches |
|
inlineexplicit |
operator bool returns true if Tree is not null
| TTree* ant::WrapTTree::Tree = nullptr |
Tree to be used as usual TTree.