+ if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
+
+ }
+
+ return kTRUE;
+
+}
+
+ //__________________________________________________________________________
+Bool_t AliMUONTrackReconstructorK::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
+{
+ /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
+ /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
+ /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
+ /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
+ /// Remove the obsolete "trackCandidate" at the end.
+ /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
+ /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
+ AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
+
+ Double_t chi2OfCluster;
+ Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+ Double_t addChi2TrackAtCluster;
+ Double_t bestAddChi2TrackAtCluster = AliMUONTrack::MaxChi2();
+ Bool_t foundOneCluster = kFALSE;
+ AliMUONTrack *newTrack = 0x0;
+ AliMUONVCluster *cluster;
+ AliMUONTrackParam extrapTrackParamAtCh;
+ AliMUONTrackParam extrapTrackParamAtCluster;
+ AliMUONTrackParam bestTrackParamAtCluster;
+
+ // Get track parameters according to the propagation direction
+ if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
+ else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
+ extrapTrackParamAtCh.GetParameters().Print();
+ extrapTrackParamAtCh.GetCovariances().Print();
+ }
+
+ // Add MCS effect
+ Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
+
+ // reset propagator for smoother
+ if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator();
+
+ // Add MCS in the missing chamber(s) if any
+ while (currentChamber > nextChamber + 1) {
+ // extrapolation to the missing chamber
+ currentChamber--;
+ if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber),
+ GetRecoParam()->UseSmoother())) return kFALSE;
+ // add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
+ }
+
+ //Extrapolate trackCandidate to chamber
+ if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber),
+ GetRecoParam()->UseSmoother())) return kFALSE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
+ extrapTrackParamAtCh.GetParameters().Print();
+ extrapTrackParamAtCh.GetCovariances().Print();
+ }
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInChamber: look for clusters in chamber(1..): " << nextChamber+1 << endl;
+ }
+
+ // Ask the clustering to reconstruct new clusters around the track position in the current chamber
+ // except for station 4 and 5 that are already entirely clusterized
+ if (GetRecoParam()->CombineClusterTrackReco()) {
+ if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
+ }
+
+ // Create iterators to loop over clusters in both chambers
+ TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
+
+ // look for candidates in chamber
+ while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
+
+ // try to add the current cluster accuratly
+ chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster,
+ GetRecoParam()->UseSmoother());
+
+ // if good chi2 then consider to add cluster
+ if (chi2OfCluster < maxChi2OfCluster) {
+
+ if (GetRecoParam()->UseSmoother()) {
+ // save extrapolated parameters for smoother
+ extrapTrackParamAtCluster.SetExtrapParameters(extrapTrackParamAtCluster.GetParameters());
+
+ // save extrapolated covariance matrix for smoother
+ extrapTrackParamAtCluster.SetExtrapCovariances(extrapTrackParamAtCluster.GetCovariances());
+ }
+
+ // Compute new track parameters including new cluster using kalman filter
+ addChi2TrackAtCluster = RunKalmanFilter(extrapTrackParamAtCluster);
+
+ // skip track out of limits
+ if (!IsAcceptable(extrapTrackParamAtCluster)) continue;
+
+ // remember a cluster was found
+ foundOneCluster = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
+ << " (Chi2 = " << chi2OfCluster << ")" << endl;
+ cluster->Print();
+ }
+
+ if (GetRecoParam()->TrackAllTracks()) {
+ // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
+ newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
+ UpdateTrack(*newTrack,extrapTrackParamAtCluster,addChi2TrackAtCluster);
+ fNRecTracks++;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (addChi2TrackAtCluster < bestAddChi2TrackAtCluster) {
+ // keep track of the best cluster
+ bestAddChi2TrackAtCluster = addChi2TrackAtCluster;
+ bestTrackParamAtCluster = extrapTrackParamAtCluster;
+ }
+
+ }