How to permute events in root tree

Dear experts,
I have a tree t1, and I want to copy t1 into a new tree t2, but I want to change the event order by doing a permutation or something like that. Basically want that t1 and t2 have exactly the same events, but that their order differ. Do you know how I can do that in a simple way?
Regards

Why would you do that? I don’t see why that would be useful.

You could do it with code like this (untested and for sure SLOW because this is jumping around in the old tree):

[code]#include
#include

TTree *createShuffledTree(TTree *tree) {
std::vector<Long64_t> order(tree->GetEntries());
std::iota(order.begin(), order.end(), 0);
std::shuffle(order.begin(), order.end(), std::mt19937{std::random_device{}()});
auto newTree = tree->CloneTree(0);
for (auto eventNo : order) {
tree->GetEntry(eventNo);
newTree->Fill();
}
return newTree;
}[/code]

Dear Behrenhoff,
Ok, thank you very much for your answer.
Regards