Is there a way to sort the TTree entries given the values stored in one branch?
For example, I have a TTree with events. One branch contains the signal-to-noise ratio (SNR) of each events. I’d like to loop over the entries (with tree->GetEntry(t)) and read the TTree by decreasing order of SNR.
You can do something like:tree->BuildIndex("SNR");
TTreeIndex *index = (TTreeIndex*)tree->GetTreeIndex();
for( int i = index->GetN() - 1; i >=0 ; --i ) {
Long64_t local = tree->LoadTree( index->GetIndex()[i] );
branch->GetEntry(local);
....
}
This looks interesting. I’m not so familiar with the TTreeIndex class. Where is the SNR-sorting actually performed? is it at the level of the BuildIndex function?