BinarySearch in a TTree?

Hi,
i’m creating a program that opens two file each of them having a TTree with 9 branches. Since for each signal of the first TTree i have to cycle over all the entries of the other TTree until a certain condition is met, first of all i’ve realized a loop that cycle over all the events; however this method is really very very slow. Since the condition has to be searched in a branch that is, my his own, sorted, is there a way to implement the TMath::BinarySearch function in this case?

Thanks in advance,
Marco

Where do you want to call TMath::BinarySearch ? on the branch values?
You can store in memory the values of one or more branch, eg
Long64_t n = tree.Draw(“var1:var2”,"",“goff”);
then pick the arrays of values of var1 and var2 via
tree.GetV1(), tree.GetV2();
then sort the array via TMath::Binarysearch.
You should copy the arrays if you call again tree.Draw.
For more info, see section "How to obtain more info from TTree::Draw"
at root.cern.ch/root/htmldoc/TTreeP … DrawSelect

Rene