Problem while ordering entries in a TTree

Dear ROOT experts,

I have found the following example (from Rene Brun):

void sort() {
TFile f(“hsimple.root”);
TTree tree = (TTree)f.Get(“ntuple”);
Int_t nentries = (Int_t)tree->GetEntries();
//Drawing variable pz with no graphics option.
//variable pz stored in array fV1 (see TTree::Draw)
Int_t *index = new Int_t[nentries];
//sort array containing pz in decreasing order
//The array index contains the entry numbers in decreasing order
of pz

//open new file to store the sorted Tree
TFile f2("hsimple_sorted.root","recreate");
//Create an empty clone of the original tree
TTree *tsorted = (TTree*)tree->CloneTree(0);
for (Int_t i=0;i<nentries;i++) {
delete [] index;


Which works fine, until the number of events is too large … It crashes around the entry number 1 200 000 (I have about 1 600 000 entries or particles), with the following error:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff1b29b5f in TTree::OptimizeBaskets(unsigned long long, float, char const*) ()

I have ROOT 5.34. This probably has to do with memory consumption and cash size, but I don’t know much more. Would you please have an idea?

Best regards, Selim

Dear ROOT experts,

I have a (maybe) related question: Can we declare TTree objets as member data in a class and then declare them explicitly resident-memory in the init function? Because my class has several member functions and “modes”, where TFile may or may not be called.

Would it be better to call (or not, depending of the mode) TFile in the init and keep my TTree’s non resident-memory?

With my best regards, Selim

Something like this also affects me while I’m trying to filter nearly 1 300 000 events.

		local_file = new TFile("BCut.root");
		new_tree = (TTree*)fChain->CloneTree(0);
		new_tree->SetAutoSave(100*1024*1024); //100 MB

I get [code]===========================================================
#12 0x02223892 in TTree::OptimizeBaskets(unsigned long long, float, char const*) () from /usr/lib/root/
#13 0x02220fec in TTree::Fill() () from /usr/lib/root/
#14 0x00645723 in EventsSelector::Process (this=0xb6ed4008, entry=9797) at EventsSelector.C:183
#15 0x010bb07e in TTreePlayer::Process(TSelector*, char const*, long long, long long) () from /usr/lib/root/
#16 0x0221d097 in TTree::Process(TSelector*, char const*, long long, long long) () from /usr/lib/root/
#17 0x021f6c0a in TChain::Process(TSelector*, char const*, long long, long long) () from /usr/lib/root/
#18 0x021c61f9 in ?? () from /usr/lib/root/

where EventsSelector.C:183
looks like new_tree->Fill();

Update: trying here and there I’ve found, that


helps. Have no idea, why:)