Sort a TClonesArray

I would like to sort a TClonesArray TCA containing elements of the class MyClass according to a member of MyClass. I added the methods IsSortable, Compare and IsEqual to MyClass, and call TCA->Sort() in my code, but nothing happens. Any suggestions?
Thanks in advance,

Humm … that should have been enough (assuming the correct signature for IsSortable and Compare). When TCA->Sort is called, does it calling the IsSortable and Compare routine?

It looks like (I inserted printout messages which appears).
Just to be sure, what I did is:

  1. insert the line below in the class and recompile
Bool_t IsEqual(TObject *obj) const {return fEloss==((R3BTraPoint*)obj)->fEloss;}
Bool_t IsSortable() const {return kTRUE;}
Int_t Compare(const TObject *obj) const{
                      std::cout<<"Eloss "<<Eloss<<std::endl;  
                      if(fEloss<((R3BTraPoint*)obj)->fEloss) return -1;
                        else if(fEloss<((R3BTraPoint*)obj)->fEloss) return 1;
                        else return 0;
  1. call the method sort on the TCA in my analysis macro
                if(trackerPointsPerEvent>0) {
                        trackerPoint = new R3BTraPoint*[trackerPointsPerEvent];
                        for(Int_t j=0;j<trackerPointsPerEvent;j++){
                                trackerPoint[trackerRealPointsPerEvent] = new R3BTraPoint;
                                trackerPoint[trackerRealPointsPerEvent] = (R3BTraPoint*) trackerPointCA->At(j);
                                        cout<<j<<" "<<trackerPoint[trackerRealPointsPerEvent]->GetEloss()<<endl;


I think I found out, the sign should be > in the line above!

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