the TTree iteration happens over the entries, not over the entry list.
Cheers,
Wim[/quote]
Yes, this is obvious, but I think this is not the best way and not what people want. If I want to iterate only the selected events I need to do something like this:
data = TTree(...)
entry = TEntryList(...)
for i in range(0,entry.GetN()):
n = entry.Next()
data.GetEntry(n)
I think that this solution is terrible. python is a very powerfull language, please use its power. In my opinion the best way to iterate over the selected events is using generators docs.python.org/tutorial/classes.html#generators
PyROOT does internally use a generator for TTrees. That’s what TTree.iter is, when you do “for event in tree”, you are calling that function which creates a generator. See TTree__iter_ in ROOT.py (the thing you import when you write “import ROOT”.)
You could write your own generator, if you wanted.
[code]def _TTree_MyIterator( tree ):
for i in xrange( tree.GetEntries() ):
tree.GetEntry( tree.GetEntryNumber( i ) )
yield tree
TTree.iter = _TTree_MyIterator # Maybe a bit hackish
for event in _TTree_MyIterator( tree ):
print tree.px