+ /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, 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 FollowLinearTrackInStation(1..) %d", nextStation+1));
+
+ // Order the chamber according to the propagation direction (tracking starts with chamber 2):
+ // - nextStation == station(1...) 5 => forward propagation
+ // - nextStation < station(1...) 5 => backward propagation
+ Int_t ch1, ch2;
+ if (nextStation==4) {
+ ch1 = 2*nextStation+1;
+ ch2 = 2*nextStation;
+ } else {
+ ch1 = 2*nextStation;
+ ch2 = 2*nextStation+1;
+ }
+
+ Double_t chi2WithOneCluster = 1.e10;
+ Double_t chi2WithTwoClusters = 1.e10;
+ Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+ Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
+ Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
+ Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
+ Bool_t foundOneCluster = kFALSE;
+ Bool_t foundTwoClusters = kFALSE;
+ AliMUONTrack *newTrack = 0x0;
+ AliMUONVCluster *clusterCh1, *clusterCh2;
+ AliMUONTrackParam trackParam;
+ AliMUONTrackParam extrapTrackParamAtCluster1;
+ AliMUONTrackParam extrapTrackParamAtCluster2;
+ AliMUONTrackParam bestTrackParamAtCluster1;
+ AliMUONTrackParam bestTrackParamAtCluster2;
+
+ Int_t nClusters = clusterStore.GetSize();
+ Bool_t *clusterCh1Used = new Bool_t[nClusters];
+ for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
+ Int_t iCluster1;
+
+ // Get track parameters according to the propagation direction
+ if (nextStation==4) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
+ else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
+ trackParam.GetParameters().Print();
+ trackParam.GetCovariances().Print();
+ }
+
+ // Add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
+ }
+
+ // Create iterators to loop over clusters in both chambers
+ TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
+ TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
+
+ // look for candidates in chamber 2
+ while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
+
+ // try to add the current cluster accuratly
+ extrapTrackParamAtCluster2 = trackParam;
+ AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
+ chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
+
+ // if good chi2 then try to attach a cluster in the other chamber too
+ if (chi2WithOneCluster < maxChi2WithOneCluster) {
+ Bool_t foundSecondCluster = kFALSE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
+ << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
+ clusterCh2->Print();
+ cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
+ }
+
+ // add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
+
+ // reset cluster iterator of chamber 1
+ nextInCh1.Reset();
+ iCluster1 = -1;
+
+ // look for second candidates in chamber 1
+ while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
+ iCluster1++;
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
+
+ // try to add the current cluster in addition to the one found in the previous chamber
+ chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
+
+ // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
+ if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
+ foundSecondCluster = kTRUE;
+ foundTwoClusters = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
+ << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
+ clusterCh1->Print();
+ }
+
+ if (GetRecoParam()->TrackAllTracks()) {
+ // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
+ newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
+ extrapTrackParamAtCluster1.SetRemovable(kTRUE);
+ newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
+ extrapTrackParamAtCluster2.SetRemovable(kTRUE);
+ newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
+ fNRecTracks++;
+
+ // Tag clusterCh1 as used
+ clusterCh1Used[iCluster1] = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
+ // keep track of the best couple of clusters
+ bestChi2WithTwoClusters = chi2WithTwoClusters;
+ bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
+ bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
+ }
+
+ }
+
+ }
+
+ // if no cluster found in chamber1 then consider to add clusterCh2 only
+ if (!foundSecondCluster) {
+ foundOneCluster = kTRUE;
+
+ 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);
+ if (GetRecoParam()->RequestStation(nextStation))
+ extrapTrackParamAtCluster2.SetRemovable(kFALSE);
+ else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
+ newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
+ fNRecTracks++;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
+ // keep track of the best cluster except if a couple of clusters has already been found
+ bestChi2WithOneCluster = chi2WithOneCluster;
+ bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
+ }
+
+ }
+
+ }
+
+ }
+
+ // look for candidates in chamber 1 not already attached to a track
+ // if we want to keep all possible tracks or if no good couple of clusters has been found
+ if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
+ }
+
+ //Extrapolate trackCandidate to chamber "ch2"
+ AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
+
+ // add MCS effect for next step
+ AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
+
+ // reset cluster iterator of chamber 1
+ nextInCh1.Reset();
+ iCluster1 = -1;
+
+ // look for second candidates in chamber 1
+ while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
+ iCluster1++;
+
+ if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
+
+ // try to add the current cluster accuratly
+ extrapTrackParamAtCluster1 = trackParam;
+ AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
+ chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
+
+ // if good chi2 then consider to add clusterCh1
+ // We do not try to attach a cluster in the other chamber too since it has already been done above
+ if (chi2WithOneCluster < maxChi2WithOneCluster) {
+ foundOneCluster = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
+ << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
+ clusterCh1->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);
+ if (GetRecoParam()->RequestStation(nextStation))
+ extrapTrackParamAtCluster1.SetRemovable(kFALSE);
+ else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
+ newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
+ fNRecTracks++;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
+ // keep track of the best cluster except if a couple of clusters has already been found
+ bestChi2WithOneCluster = chi2WithOneCluster;
+ bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
+ }
+
+ }
+
+ }
+
+ }
+
+ // fill out the best track if required else clean up the fRecTracksPtr array
+ if (!GetRecoParam()->TrackAllTracks()) {
+ if (foundTwoClusters) {
+ bestTrackParamAtCluster1.SetRemovable(kTRUE);
+ trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
+ bestTrackParamAtCluster2.SetRemovable(kTRUE);
+ trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (foundOneCluster) {
+ if (GetRecoParam()->RequestStation(nextStation))
+ bestTrackParamAtCluster1.SetRemovable(kFALSE);
+ else bestTrackParamAtCluster1.SetRemovable(kTRUE);
+ trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else {
+ delete [] clusterCh1Used;
+ return kFALSE;
+ }
+
+ } else if (foundOneCluster || foundTwoClusters) {
+
+ // remove obsolete track
+ fRecTracksPtr->Remove(&trackCandidate);
+ fNRecTracks--;
+
+ } else {
+ delete [] clusterCh1Used;
+ return kFALSE;
+ }
+
+ delete [] clusterCh1Used;
+ return kTRUE;
+