TTree index: Used by Draw()?

Hi,

Let’s say I have a TTree with an index, for example based on run and event number. I know that I can then get entries based on run and events numbers via GetEntryWithIndex().

If I use

Draw("some_quantity", "eventNumber == 12345"); // or some other condition on event or run numbers

… will the index help speed up the Draw (or Scan) process? Or are indices only used for the GetEntry…Index() functions?

Thanks,
Peter

If you use the selection argument as you show (“eventNumber == 12345”) then I think it checks every event, because it doesn’t know that eventNumber is a unique index. Even if you use the built-in Entry$ variable, I don’t think it’s smart enough to avoid looping over the whole TTree.

If you are actually only interested in single entries, and if they match with the built-in Entry$ variable, you can use the nentries and firstentry arguments of TTree::Draw: http://root.cern.ch/root/html/TTree.html#TTree:Draw@1. These will indeed skip all entries before “firstentry”, then only read nentries, then break out of the loop. Unfortunately these entry indexes are equivalent to Entry$, not some custom index that you wrote as a branch.

t->Draw("foo","","",1,12345); t->Draw("foo","Entry$ == 12345");
should both draw the same data as , but the first one will be much faster.

Another way to speed things up is if you use an EventList or EntryList, where you have to build the list by first looping over the whole TTree, but then once the list of entries is built, you can loop over just those entries.

I hope that helps,
Jean-François