+ fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
+}
+
+ //__________________________________________________________________________
+void AliMUONVTrackReconstructor::RemoveBadTracks()
+{
+ /// Remove tracks for which a problem occured somewhere during the tracking
+
+ AliMUONTrack *track, *nextTrack;
+ Bool_t trackRemoved = kFALSE;
+
+ track = (AliMUONTrack*) fRecTracksPtr->First();
+ while (track) {
+
+ nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
+
+ if (track->GetGlobalChi2() >= AliMUONTrack::MaxChi2()) {
+ AliWarning("problem occured somewhere during the tracking --> discard track");
+ fRecTracksPtr->Remove(track);
+ fNRecTracks--;
+ trackRemoved = kTRUE;
+ }
+
+ track = nextTrack;
+
+ }
+
+ // compress array of tracks if needed
+ if (trackRemoved) fRecTracksPtr->Compress();
+
+}
+
+ //__________________________________________________________________________
+void AliMUONVTrackReconstructor::RemoveConnectedTracks(Int_t stMin, Int_t stMax, Bool_t all)
+{
+ /// Find and remove tracks sharing 1 cluster or more in station(s) [stMin, stMax].
+ /// For each couple of connected tracks, one removes the one with the smallest
+ /// number of clusters or with the highest chi2 value in case of equality.
+ /// If all=kTRUE: both tracks are removed.
+
+ // tag the tracks to be removed
+ TagConnectedTracks(stMin, stMax, all);
+
+ // remove them
+ Int_t nTracks = fRecTracksPtr->GetEntriesFast();
+ for (Int_t i = 0; i < nTracks; i++) {
+ if (((AliMUONTrack*) fRecTracksPtr->UncheckedAt(i))->IsConnected()) {
+ fRecTracksPtr->RemoveAt(i);
+ fNRecTracks--;
+ }
+ }
+
+ // remove holes in the array if any
+ fRecTracksPtr->Compress();
+}
+
+ //__________________________________________________________________________
+void AliMUONVTrackReconstructor::TagConnectedTracks(Int_t stMin, Int_t stMax, Bool_t all)
+{
+ /// Find and tag tracks sharing 1 cluster or more in station(s) [stMin, stMax].
+ /// For each couple of connected tracks, one tags the one with the smallest
+ /// number of clusters or with the highest chi2 value in case of equality.
+ /// If all=kTRUE: both tracks are tagged.
+
+ AliMUONTrack *track1, *track2;
+ Int_t nClusters1, nClusters2;
+ Int_t nTracks = fRecTracksPtr->GetEntriesFast();
+
+ // reset the tags
+ for (Int_t i = 0; i < nTracks; i++) ((AliMUONTrack*) fRecTracksPtr->UncheckedAt(i))->Connected(kFALSE);
+
+ // Loop over first track of the pair
+ for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
+ track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
+
+ // Loop over second track of the pair
+ for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
+ track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
+
+ // check for connected tracks and tag them
+ if (track1->ClustersInCommon(track2, stMin, stMax) > 0) {
+
+ if (all) {
+
+ // tag both tracks
+ track1->Connected();
+ track2->Connected();
+
+ } else {
+
+ // tag only the worst track
+ nClusters1 = track1->GetNClusters();
+ nClusters2 = track2->GetNClusters();
+ if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
+ track2->Connected();
+ } else {
+ track1->Connected();
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+