Dear experts,
I have a tree1 with an events number leaf. Then while I loop over tree2, I want to keep the event only if it’s number is in tree1. So basically do something like [1].
I saw a TList but I wonder if it is suitable in this context. Do you have a code which does what I want?
Regards
perhaps looping over tree2, keep in memory the event numbers (or ranges, if the memory required is too big for your application) and then run on tree1 may be a solution?
Dear dpiparo,
thank you for your answer. I 1st intention was to save all the tree1 event number in a file.txt, then for each evt in tree2, check if its number in the the file, but this is too much time consuming, as doing 2 loop… So I wonder if there is an elegant way to do that or if by any change there a tree method, which does such search?
Regards
I would create an std::unordered_set<Long64_t> eventsInTree1 of the event numbers and insert all event numbers from tree1. (assuming your event numbers are of type Long64_t)
Then loop over tree2 and add to your event loop: if (!eventsInTree1.count(event_number_from_tree2)) continue;
Just to be clear, by double loop I do not mean it nested but rather a loop onn tree1 to fill a collection of entries and a second one on tree2 cross checking the event numbers.
What will be slow is the check against the unordered collection. I’d rather get from the tree only the entries which are needed with the GetEntry method.