Get tree Branch by number

I have root files with a tree. I need the variable nHits.
When I do


it shows several branches with one name:

*Br 10 :nHits : Int_t

*Br 15 :nHits : Int_t

with different compression level. The first branch is filled with 0-s, and when I try to get nHits from a compiled program, I get only zeroes. However, I can plot the variable using the tree viewer.

Root generated this script from the root file (there were two lines with nHits, I had to comment out one of them to have no errors),

fChain->SetBranchAddress(“nHits”, &nHits, &b_RecoBAMAInfoBranch_nHits);

but I can’t get such branch or get nHits from branch like that.

Can I get Branch 15 from the tree?
(there is no such method in TTree documentation)

I also tried to TTree::Scan this variable, but this gives only part of events (I want all data be processed from the script or better from a C++ program).

I can’t regenerate root files. They are read-only and there are many of them.

ROOT Version: 6.12/06
Platform: Linux
Compiler: gcc

I found how to Scan to a file,


(this method from 2008 doesn’t work):

tree.Scan(…); >scan.log

Anyway I’d like to know how to do that with Branches.



Thank you. Unfortunately, this doesn’t work:

Trying to dereference null pointer
root [7] ((TBranch*)(tv__tree->GetListOfBranches()->At(15)))->Print();
 Generating stack trace...
 0x00007f9b8b929489 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x1d9 from /usr/lib64/root/
 0x00007f9b8b929a0f in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) + 0x13f from /usr/lib64/root/
 0x00007f9b8b9cfa4d in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x1ed from /usr/lib64/root/
 0x00007f9b8b88e9be in <unknown> from /usr/lib64/root/
 0x00007f9b8b8a051f in <unknown> from /usr/lib64/root/
 0x00007f9b91dc56f4 in TApplication::ProcessLine(char const*, bool, int*) + 0x594 from /usr/lib64/root/
 0x00007f9b922251b2 in TRint::ProcessLineNr(char const*, char const*, int*) + 0xe2 from /usr/lib64/root/
 0x00007f9b92225524 in TRint::HandleTermInput() + 0x214 from /usr/lib64/root/
 0x00007f9b91f02a40 in TUnixSystem::CheckDescriptors() + 0x1c0 from /usr/lib64/root/
 0x00007f9b91f042f8 in TUnixSystem::DispatchOneEvent(bool) + 0x508 from /usr/lib64/root/
 0x00007f9b91e2e604 in TSystem::InnerLoop() + 0x44 from /usr/lib64/root/
 0x00007f9b91e2d2ef in TSystem::Run() + 0x6f from /usr/lib64/root/
 0x00007f9b91dc1f0f in TApplication::Run(bool) + 0x1f from /usr/lib64/root/
 0x00007f9b92226a33 in TRint::Run(bool) + 0x3b3 from /usr/lib64/root/
 0x0000562648cb2eec in <unknown> from /usr/bin/root.exe
 0x00007f9b912a6f2a in __libc_start_main + 0xea from /usr/lib64/
 0x0000562648cb2f4a in _start + 0x2a from /usr/bin/root.exe
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_7:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]

I tried to get Branch 10, that didn’t help. It seems there is only one object in TObjArray:

root [11]  tv__tree->GetListOfBranches()
(TObjArray *) 0x56264a59e0e8
root [15] tv__tree->GetListOfBranches()->GetEntries()
(int) 1

I don’t know why.

Try to execute first: tv__tree->SetMakeClass(1);
If it doesn’t help, post here the full output from: tv__tree->Print();

In v6 you need:

root [] .> filename.extension

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.