Hi all,
Imagine I would like to get the content of 42nd event from the TTree:
I would distinguish three main approaches:
Method 1: using C++
int secret;
tree->SetBranchAddress("secret", &secret);
tree->GetEntry(42);
std::cout<<secret<<std::endl;
Method 2: C++ copy, but using pyROOT with array package
from array import array
secret = array('i', [0]);
tree.SetBranchAddress("secret", secret)
tree.GetEntry(42)
print(secret[0])
Method 3: Using pyROOT loop
for i, event in enumerate(tree):
if i == 42:
print(event.secret)
break
Question 1:
Is there more pythonic way of extracting data content, without unnecessary loop in method 3 and avoiding array as in method 2?
Something like:
print( tree.GetEventAtIndex(42).secret ) # or even...
print( tree[42].secret )
Question 2:
Can I read somewhere what is actually variable event in the for event in tree ?
As a newbie, I would naively assume it is just an “item” in a “tree” iterable object, but it seems more complicated…
items = [ MyClass() ]
type(items[0]) # obviously MyClass
for event in tree:
type(event) # not obviously, still TTree: <class cppyy.gbl.TTree at 0x58028e0>
Question 3:
Do I miss some other more aesthetic methods of extracting TTree content into variables than listed in the three methods above? Please share!
cheers,
Bohdan