X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONTrackReconstructorK.cxx;h=cb3bcc1720e9fc06d0b8c6dc3fb62cdbd326b0fb;hb=c8b7b5d3a7d8e15d605e34af228fd41ff6e55331;hp=cd3b877261999529bde9857fb29a44c820d1a2f1;hpb=1fef78c84fe0b8ed1b9aa8b74a89402aa9b06e94;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONTrackReconstructorK.cxx b/MUON/AliMUONTrackReconstructorK.cxx index cd3b8772619..cb3bcc1720e 100644 --- a/MUON/AliMUONTrackReconstructorK.cxx +++ b/MUON/AliMUONTrackReconstructorK.cxx @@ -51,8 +51,8 @@ ClassImp(AliMUONTrackReconstructorK) // Class implementation in ROOT context /// \endcond //__________________________________________________________________________ -AliMUONTrackReconstructorK::AliMUONTrackReconstructorK(AliMUONVClusterServer& clusterServer) - : AliMUONVTrackReconstructor(clusterServer) +AliMUONTrackReconstructorK::AliMUONTrackReconstructorK(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer) + : AliMUONVTrackReconstructor(recoParam, clusterServer) { /// Constructor } @@ -68,7 +68,7 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust { /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE): /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4. - /// Good candidates are made of at least three clusters. + /// Good candidates are made of at least three clusters if both station are requested (two otherwise). /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks. TClonesArray *segments; @@ -82,7 +82,7 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust Int_t firstChamber(0); Int_t lastChamber(9); - if (AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco()) { + if (GetRecoParam()->CombineClusterTrackReco()) { // ... Here's the exception : ask the clustering to reconstruct // clusters *only* in station 4 and 5 for combined tracking firstChamber = 6; @@ -90,43 +90,42 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust for (Int_t i = firstChamber; i <= lastChamber; ++i ) { - fClusterServer.Clusterize(i, clusterStore, AliMpArea()); + if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam()); } // Loop over stations(1..) 5 and 4 and make track candidates for (Int_t istat=4; istat>=3; istat--) { // Make segments in the station - segments = MakeSegmentsInStation(clusterStore, istat); + segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1); // Loop over segments for (Int_t iseg=0; isegGetEntriesFast(); iseg++) { AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate)); // Transform segments to tracks and put them at the end of fRecTracksPtr - track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg])); + track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]),GetRecoParam()->GetBendingVertexDispersion()); fNRecTracks++; - // Printout for debuging - if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { - cout<GetTrackParamAtCluster()->First()))->GetCovariances().Print(); - } - // Look for compatible cluster(s) in the other station - if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast()) + if (GetRecoParam()->MakeTrackCandidatesFast()) clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat); else { // First recompute track parameters and covariances on station(1..) 5 using Kalman filter // (to make sure all tracks are treated in the same way) - if (istat == 4) RetraceTrack(*track, kFALSE); + if (istat == 4) RetraceTrack(*track, kTRUE); clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat); } - // Remove track if no cluster found + // Remove track if no cluster found on a requested station if (!clusterFound) { - fRecTracksPtr->Remove(track); - fNRecTracks--; + if (GetRecoParam()->RequestStation(7-istat)) { + fRecTracksPtr->Remove(track); + fNRecTracks--; + } else if (istat == 3 && !GetRecoParam()->MakeTrackCandidatesFast()) { + // update track parameters and covariances using Kalman filter + RetraceTrack(*track, kTRUE); + } } } @@ -136,7 +135,7 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust // Retrace tracks using Kalman filter and remove bad ones - if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast()) { + if (GetRecoParam()->MakeTrackCandidatesFast()) { fRecTracksPtr->Compress(); // this is essential before checking tracks Int_t currentNRecTracks = fNRecTracks; @@ -147,8 +146,8 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust RetraceTrack(*track,kTRUE); // Remove the track if the normalized chi2 is too high - if (track->GetNormalizedChi2() > AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * - AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking()) { + if (track->GetNormalizedChi2() > GetRecoParam()->GetSigmaCutForTracking() * + GetRecoParam()->GetSigmaCutForTracking()) { fRecTracksPtr->Remove(track); fNRecTracks--; } @@ -160,7 +159,99 @@ void AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clust fRecTracksPtr->Compress(); // this is essential before checking tracks // Keep all different tracks or only the best ones as required - if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks(); + if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks(); + else RemoveDoubleTracks(); + + AliDebug(1,Form("Number of good candidates = %d",fNRecTracks)); + +} + + //__________________________________________________________________________ +void AliMUONTrackReconstructorK::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore) +{ + /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE): + /// clustering is supposed to be already done + /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers. + /// Good candidates are made of at least three clusters if both station are requested (two otherwise). + /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks. + + TClonesArray *segments; + AliMUONTrack *track; + Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks; + Int_t initialNRecTracks = fNRecTracks; + Bool_t clusterFound; + + AliDebug(1,"Enter MakeMoreTrackCandidates"); + + // Double loop over chambers in stations(1..) 4 and 5 to make track candidates + for (Int_t ich1 = 6; ich1 <= 7; ich1++) { + for (Int_t ich2 = 8; ich2 <= 9; ich2++) { + + // Make segments between ch1 and ch2 + segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2); + + // Loop over segments + for (Int_t iseg=0; isegGetEntriesFast(); iseg++) { + AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate)); + + // Transform segments to tracks and put them at the end of fRecTracksPtr + iCurrentTrack = fRecTracksPtr->GetLast()+1; + track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]),GetRecoParam()->GetBendingVertexDispersion()); + fNRecTracks++; + + // Look for compatible cluster(s) in the second chamber of station 5 + if (GetRecoParam()->MakeTrackCandidatesFast()) + clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2); + else clusterFound = FollowTrackInChamber(*track, clusterStore, 17-ich2); + + // skip the original track in case it has been removed + if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++; + + // loop over every new tracks + nCurrentTracks = fRecTracksPtr->GetLast()+1; + while (iCurrentTrack < nCurrentTracks) { + track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack); + + // Look for compatible cluster(s) in the second chamber of station 4 + if (GetRecoParam()->MakeTrackCandidatesFast()) + FollowLinearTrackInChamber(*track, clusterStore, 13-ich1); + else FollowTrackInChamber(*track, clusterStore, 13-ich1); + + iCurrentTrack++; + } + + } + + // delete the array of segments + delete segments; + } + } + + fRecTracksPtr->Compress(); // this is essential before checking tracks + + // Retrace tracks using Kalman filter + for (Int_t iRecTrack = initialNRecTracks; iRecTrack < fNRecTracks; iRecTrack++) { + track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack); + + // Recompute track parameters and covariances using Kalman filter + RetraceTrack(*track,kTRUE); + + // Remove the track if the normalized chi2 is too high + // (only if the tracking has been done without magnetic field) + if (GetRecoParam()->MakeTrackCandidatesFast() && + track->GetNormalizedChi2() > GetRecoParam()->GetSigmaCutForTracking() * + GetRecoParam()->GetSigmaCutForTracking()) { + fRecTracksPtr->Remove(track); + fNRecTracks--; + } + + } + + // this is essential before checking tracks + if (GetRecoParam()->MakeTrackCandidatesFast()) fRecTracksPtr->Compress(); + + // Keep all different tracks or only the best ones as required + if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks(); else RemoveDoubleTracks(); AliDebug(1,Form("Number of good candidates = %d",fNRecTracks)); @@ -173,36 +264,63 @@ void AliMUONTrackReconstructorK::RetraceTrack(AliMUONTrack &trackCandidate, Bool /// Re-run the kalman filter from the most downstream cluster to the most uptream one AliDebug(1,"Enter RetraceTrack"); - AliMUONTrackParam* startingTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Last(); + AliMUONTrackParam* lastTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Last(); // Reset the "seed" (= track parameters and their covariances at last cluster) if required if (resetSeed) { - // => Shift track parameters at the position of the last cluster - AliMUONVCluster* cluster = startingTrackParam->GetClusterPtr(); - startingTrackParam->SetNonBendingCoor(cluster->GetX()); - startingTrackParam->SetBendingCoor(cluster->GetY()); - - // => Re-compute and reset track parameters covariances at last cluster (as if the other clusters did not exist) - const TMatrixD& kParamCov = startingTrackParam->GetCovariances(); - TMatrixD newParamCov(5,5); - newParamCov.Zero(); + + // parameters at last cluster + AliMUONVCluster* cluster2 = lastTrackParam->GetClusterPtr(); + Double_t x2 = cluster2->GetX(); + Double_t y2 = cluster2->GetY(); + Double_t z2 = cluster2->GetZ(); + + // parameters at last but one cluster + AliMUONTrackParam* previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(lastTrackParam); + AliMUONVCluster* cluster1 = previousTrackParam->GetClusterPtr(); + // make sure it is on the previous chamber (can have 2 clusters in the same chamber after "ComplementTrack") + if (cluster2->GetChamberId() == cluster1->GetChamberId()) { + previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(previousTrackParam); + cluster1 = previousTrackParam->GetClusterPtr(); + } + Double_t x1 = cluster1->GetX(); + Double_t y1 = cluster1->GetY(); + Double_t z1 = cluster1->GetZ(); + + // reset track parameters + Double_t dZ = z1 - z2; + lastTrackParam->SetNonBendingCoor(x2); + lastTrackParam->SetBendingCoor(y2); + lastTrackParam->SetZ(z2); + lastTrackParam->SetNonBendingSlope((x1 - x2) / dZ); + lastTrackParam->SetBendingSlope((y1 - y2) / dZ); + Double_t bendingImpact = y2 - z2 * lastTrackParam->GetBendingSlope(); + Double_t inverseBendingMomentum = 1. / AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpact); + lastTrackParam->SetInverseBendingMomentum(inverseBendingMomentum); + + // => Reset track parameter covariances at last cluster (as if the other clusters did not exist) + TMatrixD lastParamCov(5,5); + lastParamCov.Zero(); // Non bending plane - newParamCov(0,0) = cluster->GetErrX2(); - newParamCov(1,1) = 100.*kParamCov(1,1); + lastParamCov(0,0) = cluster2->GetErrX2(); + lastParamCov(1,1) = 100. * ( cluster1->GetErrX2() + cluster2->GetErrX2() ) / dZ / dZ; // Bending plane - newParamCov(2,2) = cluster->GetErrY2(); - newParamCov(3,3) = 100.*kParamCov(3,3); - // Inverse bending momentum - newParamCov(4,4) = 0.5*startingTrackParam->GetInverseBendingMomentum() * 0.5*startingTrackParam->GetInverseBendingMomentum(); - startingTrackParam->SetCovariances(newParamCov); + lastParamCov(2,2) = cluster2->GetErrY2(); + lastParamCov(3,3) = 100. * ( cluster1->GetErrY2() + cluster2->GetErrY2() ) / dZ / dZ; + // Inverse bending momentum (vertex resolution + bending slope resolution + 10% error on dipole parameters+field) + lastParamCov(4,4) = ((GetRecoParam()->GetBendingVertexDispersion() * + GetRecoParam()->GetBendingVertexDispersion() + + (z1 * z1 * cluster2->GetErrY2() + z2 * z2 * cluster1->GetErrY2()) / dZ / dZ) / + bendingImpact / bendingImpact + 0.1 * 0.1) * inverseBendingMomentum * inverseBendingMomentum; + lastTrackParam->SetCovariances(lastParamCov); // Reset the track chi2 - startingTrackParam->SetTrackChi2(0.); + lastTrackParam->SetTrackChi2(0.); } // Redo the tracking - RetracePartialTrack(trackCandidate, startingTrackParam); + RetracePartialTrack(trackCandidate, lastTrackParam); } @@ -236,14 +354,14 @@ void AliMUONTrackReconstructorK::RetracePartialTrack(AliMUONTrack &trackCandidat AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.); // reset propagator for smoother - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) trackParamAtCluster->ResetPropagator(); + if (GetRecoParam()->UseSmoother()) trackParamAtCluster->ResetPropagator(); - // add MCS in missing chambers if any (at most 2 chambers can be missing according to tracking criteria) + // add MCS in missing chambers if any currentChamber = trackParamAtCluster->GetClusterPtr()->GetChamberId(); while (currentChamber < expectedChamber) { // extrapolation to the missing chamber (update the propagator) AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, AliMUONConstants::DefaultChamberZ(expectedChamber), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // add MCS effect AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.); expectedChamber--; @@ -251,9 +369,9 @@ void AliMUONTrackReconstructorK::RetracePartialTrack(AliMUONTrack &trackCandidat // extrapolation to the plane of the cluster attached to the current trackParamAtCluster (update the propagator) AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, trackParamAtCluster->GetClusterPtr()->GetZ(), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) { + if (GetRecoParam()->UseSmoother()) { // save extrapolated parameters for smoother trackParamAtCluster->SetExtrapParameters(trackParamAtCluster->GetParameters()); @@ -261,7 +379,7 @@ void AliMUONTrackReconstructorK::RetracePartialTrack(AliMUONTrack &trackCandidat trackParamAtCluster->SetExtrapCovariances(trackParamAtCluster->GetCovariances()); } - // Compute new track parameters including "clusterCh2" using kalman filter + // Compute new track parameters using kalman filter addChi2TrackAtCluster = RunKalmanFilter(*trackParamAtCluster); // Update the track chi2 @@ -289,7 +407,6 @@ void AliMUONTrackReconstructorK::FollowTracks(AliMUONVClusterStore& clusterStore AliMUONTrack *track; Int_t currentNRecTracks; - Bool_t clusterFound; for (Int_t station = 2; station >= 0; station--) { @@ -303,33 +420,204 @@ void AliMUONTrackReconstructorK::FollowTracks(AliMUONVClusterStore& clusterStore track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack); + // Look for compatible cluster(s) in station(0..) "station" + if (!FollowTrackInStation(*track, clusterStore, station)) { + + // Try to recover track if required + if (GetRecoParam()->RecoverTracks()) { + + // work on a copy of the track if this station is not required + // to keep the case where no cluster is reconstructed as a possible candidate + if (!GetRecoParam()->RequestStation(station)) { + track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track); + fNRecTracks++; + } + + // try to recover + if (!RecoverTrack(*track, clusterStore, station)) { + // remove track if no cluster found + fRecTracksPtr->Remove(track); + fNRecTracks--; + } + + } else if (GetRecoParam()->RequestStation(station)) { + // remove track if no cluster found + fRecTracksPtr->Remove(track); + fNRecTracks--; + } + + } + + } + + fRecTracksPtr->Compress(); // this is essential before checking tracks + + // Keep only the best tracks if required + if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks(); + + } + +} + + //__________________________________________________________________________ +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 bendingMomentum; + Double_t chi2OfCluster; + Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() * + GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2 + Double_t addChi2TrackAtCluster; + Double_t bestAddChi2TrackAtCluster = 1.e10; + 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<UseSmoother()) extrapTrackParamAtCh.ResetPropagator(); + + // 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), + GetRecoParam()->UseSmoother()); + // add MCS effect + AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); + } + + //Extrapolate trackCandidate to chamber + AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber), + GetRecoParam()->UseSmoother()); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { + cout<= 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(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) { + foundOneCluster = kTRUE; + // Printout for debuging - if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { - cout<GetTrackParamAtCluster()->First()))->GetCovariances().Print(); + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { + cout << "FollowTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1 + << " (Chi2 = " << chi2OfCluster << ")" << endl; + cluster->Print(); } - // Look for compatible cluster(s) in station(0..) "station" - clusterFound = FollowTrackInStation(*track, clusterStore, station); + if (GetRecoParam()->UseSmoother()) { + // save extrapolated parameters for smoother + extrapTrackParamAtCluster.SetExtrapParameters(extrapTrackParamAtCluster.GetParameters()); + + // save extrapolated covariance matrix for smoother + extrapTrackParamAtCluster.SetExtrapCovariances(extrapTrackParamAtCluster.GetCovariances()); + } - // Try to recover track if required - if (!clusterFound && AliMUONReconstructor::GetRecoParam()->RecoverTracks()) - clusterFound = RecoverTrack(*track, clusterStore, station); + // Compute new track parameters including new cluster using kalman filter + addChi2TrackAtCluster = RunKalmanFilter(extrapTrackParamAtCluster); - // remove track if no cluster found - if (!clusterFound) { - fRecTracksPtr->Remove(track); - fNRecTracks--; + // skip track with absolute bending momentum out of limits + bendingMomentum = TMath::Abs(1. / extrapTrackParamAtCluster.GetInverseBendingMomentum()); + if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() || + bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue; + + 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; } } - fRecTracksPtr->Compress(); // this is essential before checking tracks + } + + // fill out the best track if required else clean up the fRecTracksPtr array + if (!GetRecoParam()->TrackAllTracks()) { + if (foundOneCluster) { + UpdateTrack(trackCandidate,bestTrackParamAtCluster,bestAddChi2TrackAtCluster); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { + cout << "FollowTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl; + if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); + } + + } else return kFALSE; - // Keep only the best tracks if required - if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks(); + } else if (foundOneCluster) { - } + // remove obsolete track + fRecTracksPtr->Remove(&trackCandidate); + fNRecTracks--; + + } else return kFALSE; + + return kTRUE; } @@ -357,9 +645,10 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi ch2 = 2*nextStation+1; } + Double_t bendingMomentum; Double_t chi2OfCluster; - Double_t maxChi2OfCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * - AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2 + Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() * + GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2 Double_t addChi2TrackAtCluster1; Double_t addChi2TrackAtCluster2; Double_t bestAddChi2TrackAtCluster1 = 1.e10; @@ -369,6 +658,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi AliMUONTrack *newTrack = 0x0; AliMUONVCluster *clusterCh1, *clusterCh2; AliMUONTrackParam extrapTrackParam; + AliMUONTrackParam extrapTrackParamAtCh; AliMUONTrackParam extrapTrackParamAtCluster1; AliMUONTrackParam extrapTrackParamAtCluster2; AliMUONTrackParam bestTrackParamAtCluster1; @@ -379,31 +669,43 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE; Int_t iCluster1; - // Get track parameters - AliMUONTrackParam extrapTrackParamAtCh(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()); + // Get track parameters according to the propagation direction + + if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last(); + else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First(); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { + cout<UseSmoother()) extrapTrackParamAtCh.ResetPropagator(); + if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator(); - // Add MCS in the missing chamber if any (only 1 chamber can be missing according to tracking criteria) - if (ch1 < ch2 && extrapTrackParamAtCh.GetClusterPtr()->GetChamberId() > ch2 + 1) { + // Add MCS in the missing chamber(s) if any + Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId(); + while (ch1 < ch2 && currentChamber > ch2 + 1) { // extrapolation to the missing chamber - AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2 + 1), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + currentChamber--; + AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber), + GetRecoParam()->UseSmoother()); // add MCS effect AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); } //Extrapolate trackCandidate to chamber "ch2" AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // Printout for debuging if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { - cout<CombineClusterTrackReco()) { + if (GetRecoParam()->CombineClusterTrackReco()) { if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation); } @@ -430,7 +732,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // try to add the current cluster accuratly chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2, - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // if good chi2 then try to attach a cluster in the other chamber too if (chi2OfCluster < maxChi2OfCluster) { @@ -440,10 +742,11 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1 << " (Chi2 = " << chi2OfCluster << ")" << endl; + clusterCh2->Print(); cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl; } - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) { + if (GetRecoParam()->UseSmoother()) { // save extrapolated parameters for smoother extrapTrackParamAtCluster2.SetExtrapParameters(extrapTrackParamAtCluster2.GetParameters()); @@ -454,6 +757,11 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // Compute new track parameters including "clusterCh2" using kalman filter addChi2TrackAtCluster2 = RunKalmanFilter(extrapTrackParamAtCluster2); + // skip track with absolute bending momentum out of limits + bendingMomentum = TMath::Abs(1. / extrapTrackParamAtCluster2.GetInverseBendingMomentum()); + if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() || + bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue; + // copy new track parameters for next step extrapTrackParam = extrapTrackParamAtCluster2; @@ -461,11 +769,11 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParam,AliMUONConstants::ChamberThicknessInX0(),1.); // reset propagator for smoother - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) extrapTrackParam.ResetPropagator(); + if (GetRecoParam()->UseSmoother()) extrapTrackParam.ResetPropagator(); //Extrapolate track parameters to chamber "ch1" AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // reset cluster iterator of chamber 1 nextInCh1.Reset(); @@ -480,7 +788,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // try to add the current cluster accuratly chi2OfCluster = TryOneCluster(extrapTrackParam, clusterCh1, extrapTrackParamAtCluster1, - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // if good chi2 then consider to add the 2 clusters to the "trackCandidate" if (chi2OfCluster < maxChi2OfCluster) { @@ -490,10 +798,11 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // Printout for debuging if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1 - << " (Chi2 = " << chi2OfCluster << ")" << endl; + << " (Chi2 = " << chi2OfCluster << ")" << endl; + clusterCh1->Print(); } - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) { + if (GetRecoParam()->UseSmoother()) { // save extrapolated parameters for smoother extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters()); @@ -504,7 +813,12 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // Compute new track parameters including "clusterCh1" using kalman filter addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1); - if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) { + // skip track with absolute bending momentum out of limits + bendingMomentum = TMath::Abs(1. / extrapTrackParamAtCluster1.GetInverseBendingMomentum()); + if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() || + bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue; + + 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); UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2,addChi2TrackAtCluster1,addChi2TrackAtCluster2); @@ -539,7 +853,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi if (!foundSecondCluster) { foundOneCluster = kTRUE; - if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) { + 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,extrapTrackParamAtCluster2,addChi2TrackAtCluster2); @@ -569,19 +883,26 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // 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 (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) { - - // Printout for debuging - if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { - cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl; - } + if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) { // add MCS effect for next step AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); //Extrapolate trackCandidate to chamber "ch1" AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1), - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { + cout<= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { + cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl; + } // reset cluster iterator of chamber 1 nextInCh1.Reset(); @@ -598,7 +919,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // try to add the current cluster accuratly chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1, - AliMUONReconstructor::GetRecoParam()->UseSmoother()); + GetRecoParam()->UseSmoother()); // 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 @@ -609,9 +930,10 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1 << " (Chi2 = " << chi2OfCluster << ")" << endl; + clusterCh1->Print(); } - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) { + if (GetRecoParam()->UseSmoother()) { // save extrapolated parameters for smoother extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters()); @@ -622,7 +944,12 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // Compute new track parameters including "clusterCh1" using kalman filter addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1); - if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) { + // skip track with absolute bending momentum out of limits + bendingMomentum = TMath::Abs(1. / extrapTrackParamAtCluster1.GetInverseBendingMomentum()); + if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() || + bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue; + + 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,extrapTrackParamAtCluster1,addChi2TrackAtCluster1); @@ -651,14 +978,14 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi } // fill out the best track if required else clean up the fRecTracksPtr array - if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) { + if (!GetRecoParam()->TrackAllTracks()) { if (foundTwoClusters) { UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2,bestAddChi2TrackAtCluster1,bestAddChi2TrackAtCluster2); // if we are arrived on station(1..) 5, recompute track parameters and covariances starting from this station // (going in the right direction) if (nextStation == 4) RetraceTrack(trackCandidate,kTRUE); - + // Printout for debuging if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl; @@ -671,7 +998,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi // if we are arrived on station(1..) 5, recompute track parameters and covariances starting from this station // (going in the right direction) if (nextStation == 4) RetraceTrack(trackCandidate,kTRUE); - + // Printout for debuging if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl; @@ -682,6 +1009,7 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi delete [] clusterCh1Used; return kFALSE; } + } else if (foundOneCluster || foundTwoClusters) { // remove obsolete track @@ -691,7 +1019,8 @@ Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandi } else { delete [] clusterCh1Used; return kFALSE; - } + } + delete [] clusterCh1Used; return kTRUE; @@ -770,8 +1099,10 @@ void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackPa /// Add 1 cluster to the track candidate /// Update chi2 of the track - // Flag cluster as being not removable - trackParamAtCluster.SetRemovable(kFALSE); + // Flag cluster as being (not) removable + if (GetRecoParam()->RequestStation(trackParamAtCluster.GetClusterPtr()->GetChamberId()/2)) + trackParamAtCluster.SetRemovable(kFALSE); + else trackParamAtCluster.SetRemovable(kTRUE); trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used // Update the track chi2 into trackParamAtCluster @@ -782,7 +1113,6 @@ void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackPa // Update array of TrackParamAtCluster track.AddTrackParamAtCluster(trackParamAtCluster,*(trackParamAtCluster.GetClusterPtr())); - track.GetTrackParamAtCluster()->Sort(); } @@ -829,7 +1159,6 @@ void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackPa // Update array of trackParamAtCluster track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1); track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2); - track.GetTrackParamAtCluster()->Sort(); } @@ -845,15 +1174,21 @@ Bool_t AliMUONTrackReconstructorK::RecoverTrack(AliMUONTrack &trackCandidate, Al if (nextStation > 1) return kFALSE; Int_t worstClusterNumber = -1; - Double_t localChi2, worstLocalChi2 = 0.; + Double_t localChi2, worstLocalChi2 = -1.; // Look for the cluster to remove for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) { AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber); + // check if current cluster is in the previous station + if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break; + // check if current cluster is removable if (!trackParamAtCluster->IsRemovable()) return kFALSE; + // reset the current cluster as being not removable if it is on a required station + if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE); + // Pick up cluster with the worst chi2 localChi2 = trackParamAtCluster->GetLocalChi2(); if (localChi2 > worstLocalChi2) { @@ -862,8 +1197,8 @@ Bool_t AliMUONTrackReconstructorK::RecoverTrack(AliMUONTrack &trackCandidate, Al } } - // Reset best cluster as being NOT removable - ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt((worstClusterNumber+1)%2))->SetRemovable(kFALSE); + // check if worst cluster found + if (worstClusterNumber < 0) return kFALSE; // Remove the worst cluster trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber)); @@ -871,6 +1206,11 @@ Bool_t AliMUONTrackReconstructorK::RecoverTrack(AliMUONTrack &trackCandidate, Al // Re-calculate track parameters at the (new) first cluster RetracePartialTrack(trackCandidate,(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(1)); + // skip track with absolute bending momentum out of limits + Double_t bendingMomentum = TMath::Abs(1. / ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First())->GetInverseBendingMomentum()); + if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() || + bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) return kFALSE; + // Look for new cluster(s) in next station return FollowTrackInStation(trackCandidate, clusterStore, nextStation); @@ -892,10 +1232,10 @@ Bool_t AliMUONTrackReconstructorK::RunSmoother(AliMUONTrack &track) AliMUONVCluster *cluster = previousTrackParam->GetClusterPtr(); Double_t dX = cluster->GetX() - previousTrackParam->GetNonBendingCoor(); Double_t dY = cluster->GetY() - previousTrackParam->GetBendingCoor(); - Double_t localChi2 = dX * dX / cluster->GetErrX2() + dY * dY / cluster->GetErrY2(); + Double_t chi2 = dX * dX / cluster->GetErrX2() + dY * dY / cluster->GetErrY2(); // Save local chi2 at first cluster - previousTrackParam->SetLocalChi2(localChi2); + previousTrackParam->SetLocalChi2(chi2); AliMUONTrackParam *currentTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(previousTrackParam); while (currentTrackParam) { @@ -982,15 +1322,12 @@ void AliMUONTrackReconstructorK::ComplementTracks(const AliMUONVClusterStore& cl Int_t chamberId, detElemId; Double_t chi2OfCluster, addChi2TrackAtCluster, bestAddChi2TrackAtCluster; - Double_t maxChi2OfCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() * - AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2 + Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() * + GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2 Bool_t foundOneCluster, trackModified; AliMUONVCluster *cluster; AliMUONTrackParam *trackParam, *previousTrackParam, *nextTrackParam, trackParamAtCluster, bestTrackParamAtCluster; - // Remove double track to complete only "good" tracks - RemoveDoubleTracks(); - AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First(); while (track) { trackModified = kFALSE; @@ -1042,9 +1379,21 @@ void AliMUONTrackReconstructorK::ComplementTracks(const AliMUONVClusterStore& cl // add new cluster if any if (foundOneCluster) { - UpdateTrack(*track,bestTrackParamAtCluster,bestAddChi2TrackAtCluster); - bestTrackParamAtCluster.SetAloneInChamber(kFALSE); - trackParam->SetAloneInChamber(kFALSE); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { + cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl; + bestTrackParamAtCluster.GetClusterPtr()->Print(); + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { + cout<SetRemovable(kTRUE); + bestTrackParamAtCluster.SetRemovable(kTRUE); + track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr())); trackModified = kTRUE; } @@ -1061,188 +1410,151 @@ void AliMUONTrackReconstructorK::ComplementTracks(const AliMUONVClusterStore& cl } //__________________________________________________________________________ -void AliMUONTrackReconstructorK::ImproveTracks() +void AliMUONTrackReconstructorK::ImproveTrack(AliMUONTrack &track) { - /// Improve tracks by removing clusters with local chi2 highter than the defined cut + /// Improve the given track by removing removable clusters with local chi2 highter than the defined cut + /// Removable clusters are identified by the method AliMUONTrack::TagRemovableClusters() /// Recompute track parameters and covariances at the remaining clusters - AliDebug(1,"Enter ImproveTracks"); + AliDebug(1,"Enter ImproveTrack"); Double_t localChi2, worstLocalChi2; - Int_t worstChamber, previousChamber; - AliMUONTrack *track, *nextTrack; - AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster, *previousTrackParam, *nextTrackParam; + AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster, *nextTrackParam; Bool_t smoothed; - Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement() * - AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement(); - - // Remove double track to improve only "good" tracks - RemoveDoubleTracks(); + Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() * + GetRecoParam()->GetSigmaCutForImprovement(); - track = (AliMUONTrack*) fRecTracksPtr->First(); - while (track) { + while (!track.IsImproved()) { - // prepare next track in case the actual track is suppressed - nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); + // identify removable clusters + track.TagRemovableClusters(GetRecoParam()->RequestedStationMask()); - while (!track->IsImproved()) { - - // Run smoother if required - smoothed = kFALSE; - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) smoothed = RunSmoother(*track); - - // Use standard procedure to compute local chi2 if smoother not required or not working - if (!smoothed) { - - // Update track parameters and covariances - track->UpdateCovTrackParamAtCluster(); - - // Compute local chi2 of each clusters - track->ComputeLocalChi2(kTRUE); - } - - // Look for the cluster to remove - worstTrackParamAtCluster = NULL; - worstLocalChi2 = 0.; - trackParamAtCluster = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First(); - while (trackParamAtCluster) { - - // save parameters into smooth parameters in case of smoother did not work properly - if (AliMUONReconstructor::GetRecoParam()->UseSmoother() && !smoothed) { - trackParamAtCluster->SetSmoothParameters(trackParamAtCluster->GetParameters()); - trackParamAtCluster->SetSmoothCovariances(trackParamAtCluster->GetCovariances()); - } - - // Pick up cluster with the worst chi2 - localChi2 = trackParamAtCluster->GetLocalChi2(); - if (localChi2 > worstLocalChi2) { - worstLocalChi2 = localChi2; - worstTrackParamAtCluster = trackParamAtCluster; - } - - trackParamAtCluster = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParamAtCluster); - } - - // Check if bad removable cluster found - if (!worstTrackParamAtCluster) { - track->SetImproved(kTRUE); - break; - } + // Run smoother if required + smoothed = kFALSE; + if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track); + + // Use standard procedure to compute local chi2 if smoother not required or not working + if (!smoothed) { - // Check whether the worst chi2 is under requirement or not - if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2 - track->SetImproved(kTRUE); - break; - } + // Update track parameters and covariances + track.UpdateCovTrackParamAtCluster(); - // if the worst cluster is not removable then remove the entire track - if (!worstTrackParamAtCluster->IsRemovable() && worstTrackParamAtCluster->IsAloneInChamber()) { - fRecTracksPtr->Remove(track); - fNRecTracks--; - break; - } + // Compute local chi2 of each clusters + track.ComputeLocalChi2(kTRUE); + } + + // Look for the cluster to remove + worstTrackParamAtCluster = 0x0; + worstLocalChi2 = 0.; + trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->First(); + while (trackParamAtCluster) { - // Reset the second cluster in the same station as being not removable - // or reset the second cluster in the same chamber as being alone - worstChamber = worstTrackParamAtCluster->GetClusterPtr()->GetChamberId(); - previousTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->Before(worstTrackParamAtCluster); - nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(worstTrackParamAtCluster); - if (worstTrackParamAtCluster->IsAloneInChamber()) { // Worst cluster removable and alone in chamber - - if (worstChamber%2 == 0) { // Modify flags in next chamber - - nextTrackParam->SetRemovable(kFALSE); - if (!nextTrackParam->IsAloneInChamber()) // Make sure both clusters in second chamber are not removable anymore - ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(nextTrackParam))->SetRemovable(kFALSE); - - } else { // Modify flags in previous chamber - - previousTrackParam->SetRemovable(kFALSE); - if (!previousTrackParam->IsAloneInChamber()) // Make sure both clusters in second chamber are not removable anymore - ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->Before(previousTrackParam))->SetRemovable(kFALSE); - - } - - } else { // Worst cluster not alone in its chamber - - if (previousTrackParam) previousChamber = previousTrackParam->GetClusterPtr()->GetChamberId(); - else previousChamber = -1; - - if (previousChamber == worstChamber) { // the second cluster on the same chamber is the previous one - - previousTrackParam->SetAloneInChamber(kTRUE); - // transfert the removability to the second cluster - if (worstTrackParamAtCluster->IsRemovable()) previousTrackParam->SetRemovable(kTRUE); - - } else { // the second cluster on the same chamber is the next one - - nextTrackParam->SetAloneInChamber(kTRUE); - // transfert the removability to the second cluster - if (worstTrackParamAtCluster->IsRemovable()) nextTrackParam->SetRemovable(kTRUE); - - } - + // save parameters into smooth parameters in case of smoother did not work properly + if (GetRecoParam()->UseSmoother() && !smoothed) { + trackParamAtCluster->SetSmoothParameters(trackParamAtCluster->GetParameters()); + trackParamAtCluster->SetSmoothCovariances(trackParamAtCluster->GetCovariances()); } - // Remove the worst cluster - track->RemoveTrackParamAtCluster(worstTrackParamAtCluster); - - // Re-calculate track parameters - // - from the cluster immediately downstream the one suppressed - // - or from the begining - if parameters have been re-computed using the standard method (kalman parameters have been lost) - // - or if the removed cluster was the last one - if (smoothed && nextTrackParam) RetracePartialTrack(*track,nextTrackParam); - else RetraceTrack(*track,kTRUE); - - // Printout for debuging - if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { - cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(track)+1 << " improved " << endl; + // Pick up cluster with the worst chi2 + localChi2 = trackParamAtCluster->GetLocalChi2(); + if (localChi2 > worstLocalChi2) { + worstLocalChi2 = localChi2; + worstTrackParamAtCluster = trackParamAtCluster; } + trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->After(trackParamAtCluster); + } + + // Check if worst cluster found + if (!worstTrackParamAtCluster) { + AliWarning("Bad local chi2 values?"); + break; + } + + // Check whether the worst chi2 is under requirement or not + if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2 + track.SetImproved(kTRUE); + break; + } + + // if the worst cluster is not removable then stop improvement + if (!worstTrackParamAtCluster->IsRemovable()) break; + + // get track parameters at cluster next to the one to be removed + nextTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(worstTrackParamAtCluster); + + // Remove the worst cluster + track.RemoveTrackParamAtCluster(worstTrackParamAtCluster); + + // Re-calculate track parameters + // - from the cluster immediately downstream the one suppressed + // - or from the begining - if parameters have been re-computed using the standard method (kalman parameters have been lost) + // - or if the removed cluster was the last one + if (smoothed && nextTrackParam) RetracePartialTrack(track,nextTrackParam); + else RetraceTrack(track,kTRUE); + + // Printout for debuging + if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { + cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl; } - track = nextTrack; } - // compress the array in case of some tracks have been removed - fRecTracksPtr->Compress(); - } - //__________________________________________________________________________ -void AliMUONTrackReconstructorK::Finalize() +//__________________________________________________________________________ +void AliMUONTrackReconstructorK::FinalizeTrack(AliMUONTrack &track) { /// Update track parameters and covariances at each attached cluster + /// using smoother if required, if not already done - AliMUONTrack *track; AliMUONTrackParam *trackParamAtCluster; Bool_t smoothed = kFALSE; - track = (AliMUONTrack*) fRecTracksPtr->First(); - while (track) { - - // update track parameters (using smoother if required) if not already done - if (!track->IsImproved()) { - smoothed = kFALSE; - if (AliMUONReconstructor::GetRecoParam()->UseSmoother()) smoothed = RunSmoother(*track); - if (!smoothed) track->UpdateCovTrackParamAtCluster(); - } else smoothed = AliMUONReconstructor::GetRecoParam()->UseSmoother(); + // update track parameters (using smoother if required) if not already done + if (!track.IsImproved()) { + smoothed = kFALSE; + if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track); + if (!smoothed) track.UpdateCovTrackParamAtCluster(); + } else smoothed = GetRecoParam()->UseSmoother(); + + // copy smoothed parameters and covariances if any + if (smoothed) { - // copy smoothed parameters and covariances if any - if (smoothed) { + trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First()); + while (trackParamAtCluster) { - trackParamAtCluster = (AliMUONTrackParam*) (track->GetTrackParamAtCluster()->First()); - while (trackParamAtCluster) { - - trackParamAtCluster->SetParameters(trackParamAtCluster->GetSmoothParameters()); - trackParamAtCluster->SetCovariances(trackParamAtCluster->GetSmoothCovariances()); - - trackParamAtCluster = (AliMUONTrackParam*) (track->GetTrackParamAtCluster()->After(trackParamAtCluster)); - } + trackParamAtCluster->SetParameters(trackParamAtCluster->GetSmoothParameters()); + trackParamAtCluster->SetCovariances(trackParamAtCluster->GetSmoothCovariances()); + trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->After(trackParamAtCluster)); } - track = (AliMUONTrack*) fRecTracksPtr->After(track); } - + +} + + //__________________________________________________________________________ +Bool_t AliMUONTrackReconstructorK::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement) +{ + /// re-fit the given track + + // check validity of the track + if (track.GetNClusters() < 3) { + AliWarning("the track does not contain enough clusters --> unable to refit"); + return kFALSE; + } + + // re-compute track parameters and covariances using Kalman filter + RetraceTrack(track,kTRUE); + + // Improve the reconstructed tracks if required + track.SetImproved(kFALSE); + if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track); + + // Fill AliMUONTrack data members + FinalizeTrack(track); + + return kTRUE; + }