Hi Bernhard, Thanks for reporting this problem with TClonesArray::Sort. I have fixed it in the development version in CVS. Meanwhile, you can circumvent the problem by calling: fTracks->Sort(fTracks->GetEntriesFast()); instead of the default: fTracks->Sort(); Rene Brun On Sun, 2 Dec 2001, Bernhard KETZER wrote: > Hi Rooters! > > When trying to sort a TClonesArray by one of its elements, e.g. the > Tracks TClonesArray in the Event class, the entries seem to be screwed > up after the sorting. I added the following two methods to the Event > class to illustrate the problem: > > void Event::SortTracks() > { > // Sort TClonesArray > fTracks->Sort(); > } > > Int_t Track::Compare(const TObject *obj) const > { > if (fNpoint == ((Track *)obj)->GetNpoint()) return 0; > else if (fNpoint < ((Track *)obj)->GetNpoint()) return -1; > else return 1; > } > > Then, looping through the tracks, sorting them, and looping again, I > find that > the sorted values differ slightly from the original ones. Clearing the > TClonesArray and re-reading the event from the tree before sorting cures > the problem: > > nb += tree->GetEntry(ev); //read complete event in > memory > for (int j =0; j<event->GetNtrack(); j++) { > ... > } > > // Uncommenting the following 2 lines cures the problem > // event->Clear(); > // nb += tree->GetEntry(ev); > > event->SortTracks(); > for (int j =0; j<event->GetNtrack(); j++) { > ... > } > > > Any hint as to what is going wrong when the array is not cleared before > the sorting? > > Thanks for your help! > > Bernhard > > P.S. I am using ROOT v3.02/04. The modified versions of Event.cxx, > Event.h, MainEvent.cxx are on /afs/cern.ch/user/k/ketzer/public/root/
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET