Sorting an array in better way


_ROOT Version:6.13/01
Platform: Not Provided
Compiler: Not Provided


Dear Rooters,

I am using TClonesArray. Before filling the 2D histogram I am supposed to sort the contents (global bins and point coordinates) of the array for each event. So, simply I used function Sort() but when I increase the number of events O(1000) its performance is too slow.
First, I thought it is related to memory leaks, but it isn’t.
Now I want to know if there is a better or more elegant way to do this?
Actually, I found TMath::Sort but I am confused to use this function.
Any help would be gladly appreciated.

cheers,
Behdad

Hello,

Have you tried to use an ordered container, as a “map” or a “set”? (the elements are emplaced by order, so you dont have to sort them after inserting new elements)

http://www-sldnt.slac.stanford.edu/nld/root_proto_doc/IO/examples/example.cxx.html

https://root.cern.ch/doc/master/classTMap.html

http://www.cplusplus.com/reference/map/map/

Best regards,
atd

Hello,

Sorry for delay. No, I am not familiar with that. But, it also seems great to use.
Finally I found and solved my problem coming from a technical error in filling array.
Anyway, Thanks for your valuable time to reply. :slight_smile:

Regards,
Behdad

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.