TTreeSetBranchAddress
TTreeSetBranchAddress refers to the operation of binding a branch in a ROOT TTree to a user-provided memory location so that data from each entry can be loaded directly into that memory. In ROOT, a TTree stores many branches, each corresponding to a data field for events. Setting the branch address connects the stored data to variables in your program, enabling subsequent calls to GetEntry to fill those variables automatically.
Usage typically involves calling SetBranchAddress on a TTree. The most common forms are:
- tree->SetBranchAddress("branchName", &variable);
- tree->SetBranchAddress("branchName", &variable, &branchPointer);
Here, branchName is the name of the branch, variable is a C++ variable (or a pointer to
When iterating over entries, you call GetEntry for each entry, and the bound variables are filled with
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
}
- The type of the bound variable must match the branch data type. For arrays or complex
- You may pass a pointer to a pointer to retrieve the TBranch object via branchPointer.
- If you bind multiple branches, each GetEntry fills all bound variables.
- Ensure the bound memory remains valid for the duration of reading from the tree.
Alternative reading approaches include the TTreeReader interface, which provides a different, typically safer way to access