+Bool_t AliMUONTrackReconstructor::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.
+ AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
+
+ Double_t chi2WithOneCluster = 1.e10;
+ Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+ Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
+ Bool_t foundOneCluster = kFALSE;
+ AliMUONTrack *newTrack = 0x0;
+ AliMUONVCluster *cluster;
+ AliMUONTrackParam extrapTrackParam;
+ 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","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
+ extrapTrackParamAtCh.GetParameters().Print();
+ extrapTrackParamAtCh.GetCovariances().Print();
+ }
+
+ // Add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
+
+ // Add MCS in the missing chamber(s) if any
+ Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
+ while (currentChamber > nextChamber + 1) {
+ // extrapolation to the missing chamber
+ currentChamber--;
+ AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber));
+ // add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
+ }
+
+ //Extrapolate trackCandidate to chamber
+ AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber));
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 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","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: 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 cluster 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
+ chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
+
+ // if good chi2 then consider to add cluster
+ if (chi2WithOneCluster < maxChi2WithOneCluster) {
+ foundOneCluster = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
+ << " (Chi2 = " << chi2WithOneCluster << ")" << 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);
+ fNRecTracks++;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
+ // keep track of the best single cluster except if a couple of clusters has already been found
+ bestChi2WithOneCluster = chi2WithOneCluster;
+ bestTrackParamAtCluster = extrapTrackParamAtCluster;
+ }
+
+ }
+
+ }
+
+ // fill out the best track if required else clean up the fRecTracksPtr array
+ if (!GetRecoParam()->TrackAllTracks()) {
+ if (foundOneCluster) {
+ UpdateTrack(trackCandidate,bestTrackParamAtCluster);
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else return kFALSE;
+
+ } else if (foundOneCluster) {
+
+ // remove obsolete track
+ fRecTracksPtr->Remove(&trackCandidate);
+ fNRecTracks--;
+
+ } else return kFALSE;
+
+ return kTRUE;
+
+}
+
+ //__________________________________________________________________________
+Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)