The "manual" way: calculate some "ordering value" from all events. Then sort a
vector<pair<event_number, order_value>>. Then loop over the sorted vector, read the event and write it to the sorted file. You can use
tree->LoadBaskets(large_value) to preload the data and increase speed.
If your tree is large/huge, then split it into smaller trees, for example a few 100 MB each (so that you can load the whole tree), sort them, and then merge the sorted subtrees.
The real question is: why do you need your tree to be sorted? Is there a different way to achieve what you really need?