1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONTrackReconstructorK
21 /// MUON track reconstructor using the kalman method
23 /// This class contains as data:
24 /// - the parameters for the track reconstruction
26 /// It contains as methods, among others:
27 /// - MakeTracks to build the tracks
29 //-----------------------------------------------------------------------------
31 #include "AliMUONTrackReconstructorK.h"
33 #include "AliMUONConstants.h"
34 #include "AliMUONVCluster.h"
35 #include "AliMUONVClusterServer.h"
36 #include "AliMUONVClusterStore.h"
37 #include "AliMUONTrack.h"
38 #include "AliMUONTrackParam.h"
39 #include "AliMUONTrackExtrap.h"
40 #include "AliMUONRecoParam.h"
42 #include "AliMpArea.h"
46 #include <Riostream.h>
49 #include <TClonesArray.h>
52 ClassImp(AliMUONTrackReconstructorK) // Class implementation in ROOT context
55 //__________________________________________________________________________
56 AliMUONTrackReconstructorK::AliMUONTrackReconstructorK(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
57 : AliMUONVTrackReconstructor(recoParam, clusterServer)
62 //__________________________________________________________________________
63 AliMUONTrackReconstructorK::~AliMUONTrackReconstructorK()
68 //__________________________________________________________________________
69 Bool_t AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
71 /// To make track candidates (assuming linear propagation if AliMUONRecoParam::MakeTrackCandidatesFast() return kTRUE):
72 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
73 /// Good candidates are made of at least three clusters if both stations are requested (two otherwise).
74 /// Keep only best candidates or all of them according to the flag AliMUONRecoParam::TrackAllTracks().
76 TClonesArray *segments;
77 AliMUONObjectPair *segment;
82 AliDebug(1,"Enter MakeTrackCandidates");
84 // Unless we're doing combined tracking, we'll clusterize all stations at once
85 Int_t firstChamber(0);
88 if (GetRecoParam()->CombineClusterTrackReco()) {
89 // ... Here's the exception : ask the clustering to reconstruct
90 // clusters *only* in station 4 and 5 for combined tracking
94 for (Int_t i = firstChamber; i <= lastChamber; ++i )
96 if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam());
99 // Loop over stations(1..) 5 and 4 and make track candidates
100 for (Int_t istat=4; istat>=3; istat--) {
102 // Make segments in the station
103 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
105 // Loop over segments
106 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++) {
107 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
108 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
110 // Transform segments to tracks and put them at the end of fRecTracksPtr
111 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
114 // Look for compatible cluster(s) in the other station
115 if (GetRecoParam()->MakeTrackCandidatesFast()) clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
116 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
118 // Remove track if no cluster found on a requested station
119 // or abort tracking if there are too many candidates
120 if (GetRecoParam()->RequestStation(7-istat)) {
122 fRecTracksPtr->Remove(track);
124 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
125 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
129 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
130 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
139 // Keep all different tracks if required
140 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
142 // Retrace tracks using Kalman filter and select them if needed
143 Int_t nCurrentTracks = fRecTracksPtr->GetLast()+1;
144 for (Int_t iRecTrack = 0; iRecTrack < nCurrentTracks; iRecTrack++) {
145 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
150 // retrace tracks using Kalman filter and remove the ones for which extrap failed or that are out of limits
151 if (!RetraceTrack(*track,kTRUE) || !IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
152 fRecTracksPtr->Remove(track);
158 // Keep only the best tracks if required
159 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
160 else fRecTracksPtr->Compress();
162 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
168 //__________________________________________________________________________
169 Bool_t AliMUONTrackReconstructorK::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
171 /// To make extra track candidates assuming linear propagation:
172 /// clustering is supposed to be already done
173 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
174 /// Good candidates are made of at least three clusters if both stations are requested (two otherwise).
175 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
177 TClonesArray *segments;
178 AliMUONObjectPair *segment;
180 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
181 Int_t initialNRecTracks = fNRecTracks;
184 AliDebug(1,"Enter MakeMoreTrackCandidates");
186 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
187 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
188 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
190 // Make segments between ch1 and ch2
191 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
193 /// Remove segments already attached to a track
194 RemoveUsedSegments(*segments);
196 // Loop over segments
197 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++) {
198 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
199 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
201 // Transform segments to tracks and put them at the end of fRecTracksPtr
202 iCurrentTrack = fRecTracksPtr->GetLast()+1;
203 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
206 // Look for compatible cluster(s) in the second chamber of station 5
207 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
209 // skip the original track in case it has been removed
210 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
212 // loop over every new tracks
213 nCurrentTracks = fRecTracksPtr->GetLast()+1;
214 while (iCurrentTrack < nCurrentTracks) {
215 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
217 // Look for compatible cluster(s) in the second chamber of station 4
218 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
223 // abort tracking if there are too many candidates
224 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
225 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
234 // Retrace tracks using Kalman filter (also compute track chi2) and select them
235 nCurrentTracks = fRecTracksPtr->GetLast()+1;
236 for (Int_t iRecTrack = initialNRecTracks; iRecTrack < nCurrentTracks; iRecTrack++) {
237 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
242 // retrace tracks using Kalman filter and remove the ones for which extrap failed or that are out of limits
243 if (!RetraceTrack(*track,kTRUE) || !IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
244 fRecTracksPtr->Remove(track);
250 // Keep only the best tracks if required
251 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
252 else fRecTracksPtr->Compress();
254 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
260 //__________________________________________________________________________
261 Bool_t AliMUONTrackReconstructorK::RetraceTrack(AliMUONTrack &trackCandidate, Bool_t resetSeed)
263 /// Re-run the kalman filter from the most downstream cluster to the most uptream one
264 /// Return kFALSE in case of failure (i.e. extrapolation problem)
265 AliDebug(1,"Enter RetraceTrack");
267 AliMUONTrackParam* lastTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Last();
269 // Reset the "seed" (= track parameters and their covariances at last cluster) if required
272 // parameters at last cluster
273 AliMUONVCluster* cluster2 = lastTrackParam->GetClusterPtr();
274 Double_t x2 = cluster2->GetX();
275 Double_t y2 = cluster2->GetY();
276 Double_t z2 = cluster2->GetZ();
278 // parameters at last but one cluster
279 AliMUONTrackParam* previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(lastTrackParam);
280 AliMUONVCluster* cluster1 = previousTrackParam->GetClusterPtr();
281 // make sure it is on the previous chamber (can have 2 clusters in the same chamber after "ComplementTrack")
282 if (cluster2->GetChamberId() == cluster1->GetChamberId()) {
283 previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(previousTrackParam);
284 cluster1 = previousTrackParam->GetClusterPtr();
286 Double_t x1 = cluster1->GetX();
287 Double_t y1 = cluster1->GetY();
288 Double_t z1 = cluster1->GetZ();
290 // reset track parameters
291 Double_t dZ = z1 - z2;
292 lastTrackParam->SetNonBendingCoor(x2);
293 lastTrackParam->SetBendingCoor(y2);
294 lastTrackParam->SetZ(z2);
295 lastTrackParam->SetNonBendingSlope((x1 - x2) / dZ);
296 lastTrackParam->SetBendingSlope((y1 - y2) / dZ);
297 Double_t bendingImpact = y2 - z2 * lastTrackParam->GetBendingSlope();
298 Double_t inverseBendingMomentum = 1. / AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpact);
299 lastTrackParam->SetInverseBendingMomentum(inverseBendingMomentum);
301 // => Reset track parameter covariances at last cluster (as if the other clusters did not exist)
302 TMatrixD lastParamCov(5,5);
305 lastParamCov(0,0) = cluster2->GetErrX2();
306 lastParamCov(0,1) = - cluster2->GetErrX2() / dZ;
307 lastParamCov(1,0) = lastParamCov(0,1);
308 lastParamCov(1,1) = ( 1000. * cluster1->GetErrX2() + cluster2->GetErrX2() ) / dZ / dZ;
310 lastParamCov(2,2) = cluster2->GetErrY2();
311 lastParamCov(2,3) = - cluster2->GetErrY2() / dZ;
312 lastParamCov(3,2) = lastParamCov(2,3);
313 lastParamCov(3,3) = ( 1000. * cluster1->GetErrY2() + cluster2->GetErrY2() ) / dZ / dZ;
314 // Inverse bending momentum (vertex resolution + bending slope resolution + 10% error on dipole parameters+field)
315 if (AliMUONTrackExtrap::IsFieldON()) {
316 lastParamCov(4,4) = ((GetRecoParam()->GetBendingVertexDispersion() *
317 GetRecoParam()->GetBendingVertexDispersion() +
318 (z1 * z1 * cluster2->GetErrY2() + z2 * z2 * 1000. * cluster1->GetErrY2()) / dZ / dZ) /
319 bendingImpact / bendingImpact + 0.1 * 0.1) * inverseBendingMomentum * inverseBendingMomentum;
320 lastParamCov(2,4) = z1 * cluster2->GetErrY2() * inverseBendingMomentum / bendingImpact / dZ;
321 lastParamCov(4,2) = lastParamCov(2,4);
322 lastParamCov(3,4) = - (z1 * cluster2->GetErrY2() + z2 * 1000. * cluster1->GetErrY2()) *
323 inverseBendingMomentum / bendingImpact / dZ / dZ;
324 lastParamCov(4,3) = lastParamCov(3,4);
325 } else lastParamCov(4,4) = inverseBendingMomentum*inverseBendingMomentum;
326 lastTrackParam->SetCovariances(lastParamCov);
328 // Reset the track chi2
329 lastTrackParam->SetTrackChi2(0.);
334 return RetracePartialTrack(trackCandidate, lastTrackParam);
338 //__________________________________________________________________________
339 Bool_t AliMUONTrackReconstructorK::RetracePartialTrack(AliMUONTrack &trackCandidate, const AliMUONTrackParam* startingTrackParam)
341 /// Re-run the kalman filter from the cluster attached to startingTrackParam to the most uptream cluster
342 /// Return kFALSE in case of failure (i.e. extrapolation problem)
343 AliDebug(1,"Enter RetracePartialTrack");
345 // Printout for debuging
346 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
347 cout << "RetracePartialTrack: track chi2 before re-tracking: " << trackCandidate.GetGlobalChi2() << endl;
350 // Reset the track chi2
351 trackCandidate.SetGlobalChi2(startingTrackParam->GetTrackChi2());
353 // loop over attached clusters until the first one and recompute track parameters and covariances using kalman filter
354 Bool_t extrapStatus = kTRUE;
355 Int_t expectedChamber = startingTrackParam->GetClusterPtr()->GetChamberId() - 1;
356 Int_t currentChamber;
357 Double_t addChi2TrackAtCluster;
358 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(startingTrackParam);
359 while (trackParamAtCluster) {
361 // reset track parameters and their covariances
362 trackParamAtCluster->SetParameters(startingTrackParam->GetParameters());
363 trackParamAtCluster->SetZ(startingTrackParam->GetZ());
364 trackParamAtCluster->SetCovariances(startingTrackParam->GetCovariances());
367 AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(expectedChamber+1),-1.);
369 // reset propagator for smoother
370 if (GetRecoParam()->UseSmoother()) trackParamAtCluster->ResetPropagator();
372 // add MCS in missing chambers if any
373 currentChamber = trackParamAtCluster->GetClusterPtr()->GetChamberId();
374 while (currentChamber < expectedChamber) {
375 // extrapolation to the missing chamber (update the propagator)
376 if (!AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, AliMUONConstants::DefaultChamberZ(expectedChamber),
377 GetRecoParam()->UseSmoother())) extrapStatus = kFALSE;
379 AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(expectedChamber),-1.);
383 // extrapolation to the plane of the cluster attached to the current trackParamAtCluster (update the propagator)
384 if (!AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, trackParamAtCluster->GetClusterPtr()->GetZ(),
385 GetRecoParam()->UseSmoother())) extrapStatus = kFALSE;
387 if (GetRecoParam()->UseSmoother()) {
388 // save extrapolated parameters for smoother
389 trackParamAtCluster->SetExtrapParameters(trackParamAtCluster->GetParameters());
391 // save extrapolated covariance matrix for smoother
392 trackParamAtCluster->SetExtrapCovariances(trackParamAtCluster->GetCovariances());
395 // Compute new track parameters using kalman filter
396 addChi2TrackAtCluster = RunKalmanFilter(*trackParamAtCluster);
398 // Update the track chi2
399 trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2() + addChi2TrackAtCluster);
400 trackParamAtCluster->SetTrackChi2(trackCandidate.GetGlobalChi2());
403 expectedChamber = currentChamber - 1;
404 startingTrackParam = trackParamAtCluster;
405 trackParamAtCluster = (AliMUONTrackParam*) (trackCandidate.GetTrackParamAtCluster()->Before(startingTrackParam));
408 // Printout for debuging
409 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
410 cout << "RetracePartialTrack: track chi2 after re-tracking: " << trackCandidate.GetGlobalChi2() << endl;
413 // set global chi2 to max value in case of problem during track extrapolation
414 if (!extrapStatus) trackCandidate.SetGlobalChi2(2.*AliMUONTrack::MaxChi2());
419 //__________________________________________________________________________
420 Bool_t AliMUONTrackReconstructorK::FollowTracks(AliMUONVClusterStore& clusterStore)
422 /// Follow tracks in stations(1..) 3, 2 and 1
423 AliDebug(1,"Enter FollowTracks");
426 Int_t currentNRecTracks;
428 for (Int_t station = 2; station >= 0; station--) {
430 // Save the actual number of reconstructed track in case of
431 // tracks are added or suppressed during the tracking procedure
432 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
433 currentNRecTracks = fNRecTracks;
435 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
436 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
438 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
440 // Look for compatible cluster(s) in station(0..) "station"
441 if (!FollowTrackInStation(*track, clusterStore, station)) {
443 // Try to recover track if required
444 if (GetRecoParam()->RecoverTracks()) {
446 // work on a copy of the track if this station is not required
447 // to keep the case where no cluster is reconstructed as a possible candidate
448 if (!GetRecoParam()->RequestStation(station)) {
449 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
454 if (!RecoverTrack(*track, clusterStore, station)) {
455 // remove track if no cluster found
456 fRecTracksPtr->Remove(track);
460 } else if (GetRecoParam()->RequestStation(station)) {
461 // remove track if no cluster found
462 fRecTracksPtr->Remove(track);
468 // abort tracking if there are too many candidates
469 if (GetRecoParam()->RequestStation(station)) {
470 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
471 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
475 if ((fNRecTracks + currentNRecTracks - iRecTrack - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
476 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + currentNRecTracks - iRecTrack - 1));
483 fRecTracksPtr->Compress(); // this is essential before checking tracks
485 // Keep only the best tracks if required
486 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
494 //__________________________________________________________________________
495 Bool_t AliMUONTrackReconstructorK::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
497 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
498 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
499 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
500 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
501 /// Remove the obsolete "trackCandidate" at the end.
502 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
503 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
504 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
506 Double_t chi2OfCluster;
507 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
508 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
509 Double_t addChi2TrackAtCluster;
510 Double_t bestAddChi2TrackAtCluster = AliMUONTrack::MaxChi2();
511 Bool_t foundOneCluster = kFALSE;
512 AliMUONTrack *newTrack = 0x0;
513 AliMUONVCluster *cluster;
514 AliMUONTrackParam extrapTrackParamAtCh;
515 AliMUONTrackParam extrapTrackParamAtCluster;
516 AliMUONTrackParam bestTrackParamAtCluster;
518 // Get track parameters according to the propagation direction
519 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
520 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
522 // Printout for debuging
523 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
524 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
525 extrapTrackParamAtCh.GetParameters().Print();
526 extrapTrackParamAtCh.GetCovariances().Print();
530 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
531 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
533 // reset propagator for smoother
534 if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator();
536 // Add MCS in the missing chamber(s) if any
537 while (currentChamber > nextChamber + 1) {
538 // extrapolation to the missing chamber
540 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber),
541 GetRecoParam()->UseSmoother())) return kFALSE;
543 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
546 //Extrapolate trackCandidate to chamber
547 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber),
548 GetRecoParam()->UseSmoother())) return kFALSE;
550 // Printout for debuging
551 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
552 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
553 extrapTrackParamAtCh.GetParameters().Print();
554 extrapTrackParamAtCh.GetCovariances().Print();
557 // Printout for debuging
558 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
559 cout << "FollowTrackInChamber: look for clusters in chamber(1..): " << nextChamber+1 << endl;
562 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
563 // except for station 4 and 5 that are already entirely clusterized
564 if (GetRecoParam()->CombineClusterTrackReco()) {
565 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
568 // Create iterators to loop over clusters in both chambers
569 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
571 // look for candidates in chamber
572 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
574 // try to add the current cluster fast
575 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
577 // try to add the current cluster accuratly
578 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster,
579 GetRecoParam()->UseSmoother());
581 // if good chi2 then consider to add cluster
582 if (chi2OfCluster < maxChi2OfCluster) {
584 if (GetRecoParam()->UseSmoother()) {
585 // save extrapolated parameters for smoother
586 extrapTrackParamAtCluster.SetExtrapParameters(extrapTrackParamAtCluster.GetParameters());
588 // save extrapolated covariance matrix for smoother
589 extrapTrackParamAtCluster.SetExtrapCovariances(extrapTrackParamAtCluster.GetCovariances());
592 // Compute new track parameters including new cluster using kalman filter
593 addChi2TrackAtCluster = RunKalmanFilter(extrapTrackParamAtCluster);
595 // skip track out of limits
596 if (!IsAcceptable(extrapTrackParamAtCluster)) continue;
598 // remember a cluster was found
599 foundOneCluster = kTRUE;
601 // Printout for debuging
602 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
603 cout << "FollowTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
604 << " (Chi2 = " << chi2OfCluster << ")" << endl;
608 if (GetRecoParam()->TrackAllTracks()) {
609 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
610 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
611 UpdateTrack(*newTrack,extrapTrackParamAtCluster,addChi2TrackAtCluster);
614 // Printout for debuging
615 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
616 cout << "FollowTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
617 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
620 } else if (addChi2TrackAtCluster < bestAddChi2TrackAtCluster) {
621 // keep track of the best cluster
622 bestAddChi2TrackAtCluster = addChi2TrackAtCluster;
623 bestTrackParamAtCluster = extrapTrackParamAtCluster;
630 // fill out the best track if required else clean up the fRecTracksPtr array
631 if (!GetRecoParam()->TrackAllTracks()) {
632 if (foundOneCluster) {
633 UpdateTrack(trackCandidate,bestTrackParamAtCluster,bestAddChi2TrackAtCluster);
635 // Printout for debuging
636 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
637 cout << "FollowTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
638 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
641 } else return kFALSE;
643 } else if (foundOneCluster) {
645 // remove obsolete track
646 fRecTracksPtr->Remove(&trackCandidate);
649 } else return kFALSE;
655 //__________________________________________________________________________
656 Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
658 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
659 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
660 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
661 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
662 /// Remove the obsolete "trackCandidate" at the end.
663 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
664 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
665 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
667 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
668 // - nextStation == station(1...) 5 => forward propagation
669 // - nextStation < station(1...) 5 => backward propagation
671 if (nextStation==4) {
672 ch1 = 2*nextStation+1;
676 ch2 = 2*nextStation+1;
679 Double_t chi2OfCluster;
680 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
681 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
682 Double_t addChi2TrackAtCluster1;
683 Double_t addChi2TrackAtCluster2;
684 Double_t bestAddChi2TrackAtCluster1 = AliMUONTrack::MaxChi2();
685 Double_t bestAddChi2TrackAtCluster2 = AliMUONTrack::MaxChi2();
686 Bool_t foundOneCluster = kFALSE;
687 Bool_t foundTwoClusters = kFALSE;
688 AliMUONTrack *newTrack = 0x0;
689 AliMUONVCluster *clusterCh1, *clusterCh2;
690 AliMUONTrackParam extrapTrackParam;
691 AliMUONTrackParam extrapTrackParamAtCh;
692 AliMUONTrackParam extrapTrackParamAtCluster1;
693 AliMUONTrackParam extrapTrackParamAtCluster2;
694 AliMUONTrackParam bestTrackParamAtCluster1;
695 AliMUONTrackParam bestTrackParamAtCluster2;
697 // Get track parameters according to the propagation direction
698 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
699 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
701 // Printout for debuging
702 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
703 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
704 extrapTrackParamAtCh.GetParameters().Print();
705 extrapTrackParamAtCh.GetCovariances().Print();
709 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
710 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
712 // reset propagator for smoother
713 if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator();
715 // Add MCS in the missing chamber(s) if any
716 while (ch1 < ch2 && currentChamber > ch2 + 1) {
717 // extrapolation to the missing chamber
719 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber),
720 GetRecoParam()->UseSmoother())) return kFALSE;
722 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
725 //Extrapolate trackCandidate to chamber "ch2"
726 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2),
727 GetRecoParam()->UseSmoother())) return kFALSE;
729 // Printout for debuging
730 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
731 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
732 extrapTrackParamAtCh.GetParameters().Print();
733 extrapTrackParamAtCh.GetCovariances().Print();
736 // Printout for debuging
737 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
738 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
741 // Ask the clustering to reconstruct new clusters around the track position in the current station
742 // except for station 4 and 5 that are already entirely clusterized
743 if (GetRecoParam()->CombineClusterTrackReco()) {
744 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
747 Int_t nClusters = clusterStore.GetSize();
748 Bool_t *clusterCh1Used = new Bool_t[nClusters];
749 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
752 // Create iterators to loop over clusters in both chambers
753 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
754 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
756 // look for candidates in chamber 2
757 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
759 // try to add the current cluster fast
760 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
762 // try to add the current cluster accuratly
763 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2,
764 GetRecoParam()->UseSmoother());
766 // if good chi2 then try to attach a cluster in the other chamber too
767 if (chi2OfCluster < maxChi2OfCluster) {
769 if (GetRecoParam()->UseSmoother()) {
770 // save extrapolated parameters for smoother
771 extrapTrackParamAtCluster2.SetExtrapParameters(extrapTrackParamAtCluster2.GetParameters());
773 // save extrapolated covariance matrix for smoother
774 extrapTrackParamAtCluster2.SetExtrapCovariances(extrapTrackParamAtCluster2.GetCovariances());
777 // Compute new track parameters including "clusterCh2" using kalman filter
778 addChi2TrackAtCluster2 = RunKalmanFilter(extrapTrackParamAtCluster2);
780 // skip track out of limits
781 if (!IsAcceptable(extrapTrackParamAtCluster2)) continue;
783 // Printout for debuging
784 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
785 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
786 << " (Chi2 = " << chi2OfCluster << ")" << endl;
788 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
791 // copy new track parameters for next step
792 extrapTrackParam = extrapTrackParamAtCluster2;
795 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParam,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
797 // reset propagator for smoother
798 if (GetRecoParam()->UseSmoother()) extrapTrackParam.ResetPropagator();
800 //Extrapolate track parameters to chamber "ch1"
801 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1),
802 GetRecoParam()->UseSmoother());
804 // reset cluster iterator of chamber 1
808 // look for second candidates in chamber 1
809 Bool_t foundSecondCluster = kFALSE;
810 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
813 // try to add the current cluster fast
814 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
816 // try to add the current cluster accuratly
817 chi2OfCluster = TryOneCluster(extrapTrackParam, clusterCh1, extrapTrackParamAtCluster1,
818 GetRecoParam()->UseSmoother());
820 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
821 if (chi2OfCluster < maxChi2OfCluster) {
823 if (GetRecoParam()->UseSmoother()) {
824 // save extrapolated parameters for smoother
825 extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters());
827 // save extrapolated covariance matrix for smoother
828 extrapTrackParamAtCluster1.SetExtrapCovariances(extrapTrackParamAtCluster1.GetCovariances());
831 // Compute new track parameters including "clusterCh1" using kalman filter
832 addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1);
834 // skip track out of limits
835 if (!IsAcceptable(extrapTrackParamAtCluster1)) continue;
837 // remember a second cluster was found
838 foundSecondCluster = kTRUE;
839 foundTwoClusters = kTRUE;
841 // Printout for debuging
842 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
843 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
844 << " (Chi2 = " << chi2OfCluster << ")" << endl;
848 if (GetRecoParam()->TrackAllTracks()) {
849 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
850 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
851 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2,addChi2TrackAtCluster1,addChi2TrackAtCluster2);
854 // Tag clusterCh1 as used
855 clusterCh1Used[iCluster1] = kTRUE;
857 // Printout for debuging
858 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
859 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
860 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
863 } else if (addChi2TrackAtCluster1+addChi2TrackAtCluster2 < bestAddChi2TrackAtCluster1+bestAddChi2TrackAtCluster2) {
864 // keep track of the best couple of clusters
865 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster1;
866 bestAddChi2TrackAtCluster2 = addChi2TrackAtCluster2;
867 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
868 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
875 // if no clusterCh1 found then consider to add clusterCh2 only
876 if (!foundSecondCluster) {
878 // remember a cluster was found
879 foundOneCluster = kTRUE;
881 if (GetRecoParam()->TrackAllTracks()) {
882 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
883 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
884 UpdateTrack(*newTrack,extrapTrackParamAtCluster2,addChi2TrackAtCluster2);
887 // Printout for debuging
888 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
889 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
890 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
893 } else if (!foundTwoClusters && addChi2TrackAtCluster2 < bestAddChi2TrackAtCluster1) {
894 // keep track of the best single cluster except if a couple of clusters has already been found
895 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster2;
896 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
905 // look for candidates in chamber 1 not already attached to a track
906 // if we want to keep all possible tracks or if no good couple of clusters has been found
907 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
909 // add MCS effect for next step
910 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
912 //Extrapolate trackCandidate to chamber "ch1"
913 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1),
914 GetRecoParam()->UseSmoother());
916 // Printout for debuging
917 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
918 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
919 extrapTrackParamAtCh.GetParameters().Print();
920 extrapTrackParamAtCh.GetCovariances().Print();
923 // Printout for debuging
924 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
925 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
928 // reset cluster iterator of chamber 1
932 // look for second candidates in chamber 1
933 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
936 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
938 // try to add the current cluster fast
939 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
941 // try to add the current cluster accuratly
942 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1,
943 GetRecoParam()->UseSmoother());
945 // if good chi2 then consider to add clusterCh1
946 // We do not try to attach a cluster in the other chamber too since it has already been done above
947 if (chi2OfCluster < maxChi2OfCluster) {
949 if (GetRecoParam()->UseSmoother()) {
950 // save extrapolated parameters for smoother
951 extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters());
953 // save extrapolated covariance matrix for smoother
954 extrapTrackParamAtCluster1.SetExtrapCovariances(extrapTrackParamAtCluster1.GetCovariances());
957 // Compute new track parameters including "clusterCh1" using kalman filter
958 addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1);
960 // skip track out of limits
961 if (!IsAcceptable(extrapTrackParamAtCluster1)) continue;
963 // remember a cluster was found
964 foundOneCluster = kTRUE;
966 // Printout for debuging
967 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
968 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
969 << " (Chi2 = " << chi2OfCluster << ")" << endl;
973 if (GetRecoParam()->TrackAllTracks()) {
974 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
975 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
976 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,addChi2TrackAtCluster1);
979 // Printout for debuging
980 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
981 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
982 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
985 } else if (addChi2TrackAtCluster1 < bestAddChi2TrackAtCluster1) {
986 // keep track of the best single cluster except if a couple of clusters has already been found
987 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster1;
988 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
997 // fill out the best track if required else clean up the fRecTracksPtr array
998 if (!GetRecoParam()->TrackAllTracks()) {
999 if (foundTwoClusters) {
1000 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2,bestAddChi2TrackAtCluster1,bestAddChi2TrackAtCluster2);
1002 // Printout for debuging
1003 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1004 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
1005 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1008 } else if (foundOneCluster) {
1009 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestAddChi2TrackAtCluster1);
1011 // Printout for debuging
1012 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1013 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
1014 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1018 delete [] clusterCh1Used;
1022 } else if (foundOneCluster || foundTwoClusters) {
1024 // remove obsolete track
1025 fRecTracksPtr->Remove(&trackCandidate);
1029 delete [] clusterCh1Used;
1033 delete [] clusterCh1Used;
1038 //__________________________________________________________________________
1039 Double_t AliMUONTrackReconstructorK::RunKalmanFilter(AliMUONTrackParam &trackParamAtCluster)
1041 /// Compute new track parameters and their covariances including new cluster using kalman filter
1042 /// return the additional track chi2
1043 AliDebug(1,"Enter RunKalmanFilter");
1045 // Get actual track parameters (p)
1046 TMatrixD param(trackParamAtCluster.GetParameters());
1048 // Get new cluster parameters (m)
1049 AliMUONVCluster *cluster = trackParamAtCluster.GetClusterPtr();
1050 TMatrixD clusterParam(5,1);
1051 clusterParam.Zero();
1052 clusterParam(0,0) = cluster->GetX();
1053 clusterParam(2,0) = cluster->GetY();
1055 // Compute the actual parameter weight (W)
1056 TMatrixD paramWeight(trackParamAtCluster.GetCovariances());
1057 if (paramWeight.Determinant() != 0) {
1058 paramWeight.Invert();
1060 AliWarning(" Determinant = 0");
1061 return 2.*AliMUONTrack::MaxChi2();
1064 // Compute the new cluster weight (U)
1065 TMatrixD clusterWeight(5,5);
1066 clusterWeight.Zero();
1067 clusterWeight(0,0) = 1. / cluster->GetErrX2();
1068 clusterWeight(2,2) = 1. / cluster->GetErrY2();
1070 // Compute the new parameters covariance matrix ( (W+U)^-1 )
1071 TMatrixD newParamCov(paramWeight,TMatrixD::kPlus,clusterWeight);
1072 if (newParamCov.Determinant() != 0) {
1073 newParamCov.Invert();
1075 AliWarning(" Determinant = 0");
1076 return 2.*AliMUONTrack::MaxChi2();
1079 // Save the new parameters covariance matrix
1080 trackParamAtCluster.SetCovariances(newParamCov);
1082 // Compute the new parameters (p' = ((W+U)^-1)U(m-p) + p)
1083 TMatrixD tmp(clusterParam,TMatrixD::kMinus,param);
1084 TMatrixD tmp2(clusterWeight,TMatrixD::kMult,tmp); // U(m-p)
1085 TMatrixD newParam(newParamCov,TMatrixD::kMult,tmp2); // ((W+U)^-1)U(m-p)
1086 newParam += param; // ((W+U)^-1)U(m-p) + p
1088 // Save the new parameters
1089 trackParamAtCluster.SetParameters(newParam);
1091 // Compute the additional chi2 (= ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m))
1092 tmp = newParam; // p'
1093 tmp -= param; // (p'-p)
1094 TMatrixD tmp3(paramWeight,TMatrixD::kMult,tmp); // W(p'-p)
1095 TMatrixD addChi2Track(tmp,TMatrixD::kTransposeMult,tmp3); // ((p'-p)^-1)W(p'-p)
1096 tmp = newParam; // p'
1097 tmp -= clusterParam; // (p'-m)
1098 TMatrixD tmp4(clusterWeight,TMatrixD::kMult,tmp); // U(p'-m)
1099 addChi2Track += TMatrixD(tmp,TMatrixD::kTransposeMult,tmp4); // ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m)
1101 return addChi2Track(0,0);
1105 //__________________________________________________________________________
1106 void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster, Double_t addChi2)
1108 /// Add 1 cluster to the track candidate
1109 /// Update chi2 of the track
1111 // Flag cluster as being (not) removable
1112 if (GetRecoParam()->RequestStation(trackParamAtCluster.GetClusterPtr()->GetChamberId()/2))
1113 trackParamAtCluster.SetRemovable(kFALSE);
1114 else trackParamAtCluster.SetRemovable(kTRUE);
1115 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
1117 // Update the track chi2 into trackParamAtCluster
1118 trackParamAtCluster.SetTrackChi2(track.GetGlobalChi2() + addChi2);
1120 // Update the chi2 of the new track
1121 track.SetGlobalChi2(trackParamAtCluster.GetTrackChi2());
1123 // Update array of TrackParamAtCluster
1124 track.AddTrackParamAtCluster(trackParamAtCluster,*(trackParamAtCluster.GetClusterPtr()));
1128 //__________________________________________________________________________
1129 void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2,
1130 Double_t addChi2AtCluster1, Double_t addChi2AtCluster2)
1132 /// Add 2 clusters to the track candidate (order is important)
1133 /// Update track and local chi2
1135 // Update local chi2 at first cluster
1136 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1137 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1138 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1139 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1140 deltaY*deltaY / cluster1->GetErrY2();
1141 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1143 // Flag first cluster as being removable
1144 trackParamAtCluster1.SetRemovable(kTRUE);
1146 // Update local chi2 at second cluster
1147 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1148 AliMUONTrackParam extrapTrackParamAtCluster2(trackParamAtCluster1);
1149 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParamAtCluster2, trackParamAtCluster2.GetZ());
1150 deltaX = extrapTrackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1151 deltaY = extrapTrackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1152 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1153 deltaY*deltaY / cluster2->GetErrY2();
1154 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1156 // Flag second cluster as being removable
1157 trackParamAtCluster2.SetRemovable(kTRUE);
1159 // Update the track chi2 into trackParamAtCluster2
1160 trackParamAtCluster2.SetTrackChi2(track.GetGlobalChi2() + addChi2AtCluster2);
1162 // Update the track chi2 into trackParamAtCluster1
1163 trackParamAtCluster1.SetTrackChi2(trackParamAtCluster2.GetTrackChi2() + addChi2AtCluster1);
1165 // Update the chi2 of the new track
1166 track.SetGlobalChi2(trackParamAtCluster1.GetTrackChi2());
1168 // Update array of trackParamAtCluster
1169 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1170 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1174 //__________________________________________________________________________
1175 Bool_t AliMUONTrackReconstructorK::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1177 /// Try to recover the track candidate in the next station
1178 /// by removing the worst of the two clusters attached in the current station
1179 /// Return kTRUE if recovering succeeds
1180 AliDebug(1,"Enter RecoverTrack");
1182 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1183 if (nextStation > 1) return kFALSE;
1185 Int_t worstClusterNumber = -1;
1186 Double_t localChi2, worstLocalChi2 = -1.;
1188 // Look for the cluster to remove
1189 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1190 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1192 // check if current cluster is in the previous station
1193 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1195 // check if current cluster is removable
1196 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1198 // reset the current cluster as being not removable if it is on a required station
1199 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1201 // Pick up cluster with the worst chi2
1202 localChi2 = trackParamAtCluster->GetLocalChi2();
1203 if (localChi2 > worstLocalChi2) {
1204 worstLocalChi2 = localChi2;
1205 worstClusterNumber = clusterNumber;
1209 // check if worst cluster found
1210 if (worstClusterNumber < 0) return kFALSE;
1212 // Remove the worst cluster
1213 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1215 // Re-calculate track parameters at the (new) first cluster
1216 if (!RetracePartialTrack(trackCandidate,(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(1))) return kFALSE;
1218 // skip track out of limits
1219 if (!IsAcceptable(*((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()))) return kFALSE;
1221 // Look for new cluster(s) in next station
1222 return FollowTrackInStation(trackCandidate, clusterStore, nextStation);
1226 //__________________________________________________________________________
1227 Bool_t AliMUONTrackReconstructorK::RunSmoother(AliMUONTrack &track)
1229 /// Compute new track parameters and their covariances using smoother
1230 AliDebug(1,"Enter UseSmoother");
1232 AliMUONTrackParam *previousTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1234 // Smoothed parameters and covariances at first cluster = filtered parameters and covariances
1235 previousTrackParam->SetSmoothParameters(previousTrackParam->GetParameters());
1236 previousTrackParam->SetSmoothCovariances(previousTrackParam->GetCovariances());
1238 AliMUONTrackParam *currentTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(previousTrackParam);
1240 // Save local chi2 at first cluster = last additional chi2 provided by Kalman
1241 previousTrackParam->SetLocalChi2(previousTrackParam->GetTrackChi2() - currentTrackParam->GetTrackChi2());
1243 // if the track contains only 2 clusters simply copy the filtered parameters
1244 if (track.GetNClusters() == 2) {
1245 currentTrackParam->SetSmoothParameters(currentTrackParam->GetParameters());
1246 currentTrackParam->SetSmoothCovariances(currentTrackParam->GetCovariances());
1247 currentTrackParam->SetLocalChi2(currentTrackParam->GetTrackChi2());
1251 while (currentTrackParam) {
1254 const TMatrixD &extrapParameters = previousTrackParam->GetExtrapParameters(); // X(k+1 k)
1255 const TMatrixD &filteredParameters = currentTrackParam->GetParameters(); // X(k k)
1256 const TMatrixD &previousSmoothParameters = previousTrackParam->GetSmoothParameters(); // X(k+1 n)
1257 const TMatrixD &propagator = previousTrackParam->GetPropagator(); // F(k)
1258 const TMatrixD &extrapCovariances = previousTrackParam->GetExtrapCovariances(); // C(k+1 k)
1259 const TMatrixD &filteredCovariances = currentTrackParam->GetCovariances(); // C(k k)
1260 const TMatrixD &previousSmoothCovariances = previousTrackParam->GetSmoothCovariances(); // C(k+1 n)
1262 // Compute smoother gain: A(k) = C(kk) * F(k)^t * (C(k+1 k))^-1
1263 TMatrixD extrapWeight(extrapCovariances);
1264 if (extrapWeight.Determinant() != 0) {
1265 extrapWeight.Invert(); // (C(k+1 k))^-1
1267 AliWarning(" Determinant = 0");
1270 TMatrixD smootherGain(filteredCovariances,TMatrixD::kMultTranspose,propagator); // C(kk) * F(k)^t
1271 smootherGain *= extrapWeight; // C(kk) * F(k)^t * (C(k+1 k))^-1
1273 // Compute smoothed parameters: X(k n) = X(k k) + A(k) * (X(k+1 n) - X(k+1 k))
1274 TMatrixD tmpParam(previousSmoothParameters,TMatrixD::kMinus,extrapParameters); // X(k+1 n) - X(k+1 k)
1275 TMatrixD smoothParameters(smootherGain,TMatrixD::kMult,tmpParam); // A(k) * (X(k+1 n) - X(k+1 k))
1276 smoothParameters += filteredParameters; // X(k k) + A(k) * (X(k+1 n) - X(k+1 k))
1278 // Save smoothed parameters
1279 currentTrackParam->SetSmoothParameters(smoothParameters);
1281 // Compute smoothed covariances: C(k n) = C(k k) + A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1282 TMatrixD tmpCov(previousSmoothCovariances,TMatrixD::kMinus,extrapCovariances); // C(k+1 n) - C(k+1 k)
1283 TMatrixD tmpCov2(tmpCov,TMatrixD::kMultTranspose,smootherGain); // (C(k+1 n) - C(k+1 k)) * (A(k))^t
1284 TMatrixD smoothCovariances(smootherGain,TMatrixD::kMult,tmpCov2); // A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1285 smoothCovariances += filteredCovariances; // C(k k) + A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1287 // Save smoothed covariances
1288 currentTrackParam->SetSmoothCovariances(smoothCovariances);
1290 // Compute smoothed residual: r(k n) = cluster - X(k n)
1291 AliMUONVCluster* cluster = currentTrackParam->GetClusterPtr();
1292 TMatrixD smoothResidual(2,1);
1293 smoothResidual.Zero();
1294 smoothResidual(0,0) = cluster->GetX() - smoothParameters(0,0);
1295 smoothResidual(1,0) = cluster->GetY() - smoothParameters(2,0);
1297 // Compute weight of smoothed residual: W(k n) = (clusterCov - C(k n))^-1
1298 TMatrixD smoothResidualWeight(2,2);
1299 smoothResidualWeight(0,0) = cluster->GetErrX2() - smoothCovariances(0,0);
1300 smoothResidualWeight(0,1) = - smoothCovariances(0,2);
1301 smoothResidualWeight(1,0) = - smoothCovariances(2,0);
1302 smoothResidualWeight(1,1) = cluster->GetErrY2() - smoothCovariances(2,2);
1303 if (smoothResidualWeight.Determinant() != 0) {
1304 smoothResidualWeight.Invert();
1306 AliWarning(" Determinant = 0");
1310 // Compute local chi2 = (r(k n))^t * W(k n) * r(k n)
1311 TMatrixD tmpChi2(smoothResidual,TMatrixD::kTransposeMult,smoothResidualWeight); // (r(k n))^t * W(k n)
1312 TMatrixD localChi2(tmpChi2,TMatrixD::kMult,smoothResidual); // (r(k n))^t * W(k n) * r(k n)
1315 currentTrackParam->SetLocalChi2(localChi2(0,0));
1317 previousTrackParam = currentTrackParam;
1318 currentTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(previousTrackParam);
1325 //__________________________________________________________________________
1326 Bool_t AliMUONTrackReconstructorK::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1328 /// Complete tracks by adding missing clusters (if there is an overlap between
1329 /// two detection elements, the track may have two clusters in the same chamber).
1330 /// Recompute track parameters and covariances at each clusters.
1331 /// Remove tracks getting abnormal (i.e. extrapolation failed...) after being complemented.
1332 /// Return kTRUE if one or more tracks have been complemented or removed.
1333 AliDebug(1,"Enter ComplementTracks");
1335 Int_t chamberId, detElemId;
1336 Double_t chi2OfCluster, addChi2TrackAtCluster, bestAddChi2TrackAtCluster;
1337 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
1338 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
1339 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
1340 AliMUONVCluster *cluster;
1341 AliMUONTrackParam *trackParam, *previousTrackParam, *nextTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1342 AliMUONTrack *nextTrack;
1344 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1346 trackModified = kFALSE;
1348 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1349 previousTrackParam = trackParam;
1350 while (trackParam) {
1351 foundOneCluster = kFALSE;
1352 bestAddChi2TrackAtCluster = AliMUONTrack::MaxChi2();
1353 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1354 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1356 // prepare nextTrackParam before adding new cluster because of the sorting
1357 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1359 // Create iterators to loop over clusters in current chamber
1360 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1362 // look for one second candidate in the same chamber
1363 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1365 // look for a cluster in another detection element
1366 if (cluster->GetDetElemId() == detElemId) continue;
1368 // try to add the current cluster fast
1369 if (!TryOneClusterFast(*trackParam, cluster)) continue;
1371 // try to add the current cluster accurately
1372 // never use track parameters at last cluster because the covariance matrix is meaningless
1373 if (nextTrackParam) chi2OfCluster = TryOneCluster(*trackParam, cluster, trackParamAtCluster);
1374 else chi2OfCluster = TryOneCluster(*previousTrackParam, cluster, trackParamAtCluster);
1376 // if good chi2 then consider to add this cluster to the track
1377 if (chi2OfCluster < maxChi2OfCluster) {
1379 // Compute local track parameters including current cluster using kalman filter
1380 addChi2TrackAtCluster = RunKalmanFilter(trackParamAtCluster);
1382 // keep track of the best cluster
1383 if (addChi2TrackAtCluster < bestAddChi2TrackAtCluster) {
1384 bestAddChi2TrackAtCluster = addChi2TrackAtCluster;
1385 bestTrackParamAtCluster = trackParamAtCluster;
1386 foundOneCluster = kTRUE;
1393 // add new cluster if any
1394 if (foundOneCluster) {
1396 // Printout for debuging
1397 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1398 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1399 bestTrackParamAtCluster.GetClusterPtr()->Print();
1400 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1401 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1402 bestTrackParamAtCluster.GetParameters().Print();
1403 bestTrackParamAtCluster.GetCovariances().Print();
1407 trackParam->SetRemovable(kTRUE);
1408 bestTrackParamAtCluster.SetRemovable(kTRUE);
1409 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1410 trackModified = kTRUE;
1414 previousTrackParam = trackParam;
1415 trackParam = nextTrackParam;
1418 // prepare next track
1419 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
1421 // re-compute track parameters using kalman filter if needed
1422 if (trackModified && !RetraceTrack(*track,kTRUE)) {
1423 AliWarning("track modified but problem occur during refitting --> remove track");
1424 fRecTracksPtr->Remove(track);
1435 //__________________________________________________________________________
1436 void AliMUONTrackReconstructorK::ImproveTrack(AliMUONTrack &track)
1438 /// Improve the given track by removing removable clusters with local chi2 highter than the defined cut
1439 /// Removable clusters are identified by the method AliMUONTrack::TagRemovableClusters()
1440 /// Recompute track parameters and covariances at the remaining clusters
1441 /// and if something goes wrong (i.e. extrapolation failed...) set track chi2 to max value
1442 AliDebug(1,"Enter ImproveTrack");
1444 Double_t localChi2, worstLocalChi2;
1445 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster, *nextTrackParam, *next2nextTrackParam;
1446 Int_t nextChamber, next2nextChamber;
1448 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1449 GetRecoParam()->GetSigmaCutForImprovement();
1451 while (!track.IsImproved()) {
1453 // identify removable clusters
1454 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
1456 // Run smoother if required
1458 if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track);
1460 // Use standard procedure to compute local chi2 if smoother not required or not working
1463 // Update track parameters and covariances
1464 if (!track.UpdateCovTrackParamAtCluster()) {
1465 AliWarning("unable to update track parameters and covariances --> stop improvement");
1466 // restore the kalman parameters
1467 RetraceTrack(track,kTRUE);
1471 // Compute local chi2 of each clusters
1472 track.ComputeLocalChi2(kTRUE);
1475 // Look for the cluster to remove
1476 worstTrackParamAtCluster = 0x0;
1477 worstLocalChi2 = -1.;
1478 trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->First();
1479 while (trackParamAtCluster) {
1481 // save parameters into smooth parameters in case of smoother did not work properly
1482 if (GetRecoParam()->UseSmoother() && !smoothed) {
1483 trackParamAtCluster->SetSmoothParameters(trackParamAtCluster->GetParameters());
1484 trackParamAtCluster->SetSmoothCovariances(trackParamAtCluster->GetCovariances());
1487 // Pick up cluster with the worst chi2
1488 localChi2 = trackParamAtCluster->GetLocalChi2();
1489 if (localChi2 > worstLocalChi2) {
1490 worstLocalChi2 = localChi2;
1491 worstTrackParamAtCluster = trackParamAtCluster;
1494 trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1497 // Check whether the worst chi2 is under requirement or not
1498 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1499 track.SetImproved(kTRUE);
1503 // if the worst cluster is not removable then stop improvement
1504 if (!worstTrackParamAtCluster->IsRemovable()) {
1505 // restore the kalman parameters in case they have been lost
1506 if (!smoothed) RetraceTrack(track,kTRUE);
1510 // get track parameters at cluster next to the one to be removed
1511 nextTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(worstTrackParamAtCluster);
1513 // Remove the worst cluster
1514 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1516 // Re-calculate track parameters
1517 // - from the cluster immediately downstream the one suppressed
1518 // - or from the begining - if parameters have been re-computed using the standard method (kalman parameters have been lost)
1519 // - or if the removed cluster was used to compute the tracking seed
1520 Bool_t normalExtrap;
1521 if (smoothed && nextTrackParam) {
1523 nextChamber = nextTrackParam->GetClusterPtr()->GetChamberId();
1524 next2nextTrackParam = nextTrackParam;
1527 next2nextChamber = next2nextTrackParam->GetClusterPtr()->GetChamberId();
1528 next2nextTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(next2nextTrackParam);
1530 } while (next2nextTrackParam && (next2nextChamber == nextChamber));
1532 if (next2nextChamber == nextChamber) normalExtrap = RetraceTrack(track,kTRUE);
1533 else normalExtrap = RetracePartialTrack(track,nextTrackParam);
1535 } else normalExtrap = RetraceTrack(track,kTRUE);
1537 // stop in case of extrapolation problem
1538 if (!normalExtrap) {
1539 AliWarning("track partially improved but problem occur during refitting --> stop improvement");
1543 // Printout for debuging
1544 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1545 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1552 //__________________________________________________________________________
1553 Bool_t AliMUONTrackReconstructorK::FinalizeTrack(AliMUONTrack &track)
1555 /// Update track parameters and covariances at each attached cluster
1556 /// using smoother if required, if not already done
1557 /// return kFALSE if the track cannot be extrapolated uo to the last chamber
1559 AliMUONTrackParam *trackParamAtCluster;
1560 Bool_t smoothed = kFALSE;
1562 // update track parameters (using smoother if required) if not already done
1563 if (track.IsImproved()) smoothed = GetRecoParam()->UseSmoother();
1565 if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track);
1567 if (track.UpdateCovTrackParamAtCluster()) track.ComputeLocalChi2(kTRUE);
1569 AliWarning("finalization failed due to extrapolation problem");
1575 // copy smoothed parameters and covariances if any
1578 trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1579 while (trackParamAtCluster) {
1581 trackParamAtCluster->SetParameters(trackParamAtCluster->GetSmoothParameters());
1582 trackParamAtCluster->SetCovariances(trackParamAtCluster->GetSmoothCovariances());
1584 trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->After(trackParamAtCluster));
1593 //__________________________________________________________________________
1594 Bool_t AliMUONTrackReconstructorK::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1596 /// re-fit the given track
1597 AliDebug(1,"Enter RefitTrack");
1599 // check validity of the track (i.e. at least 2 chambers hit on stations 4 and 5)
1600 if (!track.IsValid(0)) {
1601 AliWarning("the track is not valid --> unable to refit");
1605 // re-compute track parameters and covariances using Kalman filter
1606 if (!RetraceTrack(track,kTRUE)) {
1607 AliWarning("bad track refitting due to extrapolation failure");
1611 // Improve the reconstructed tracks if required
1612 track.SetImproved(kFALSE);
1613 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1615 // Fill AliMUONTrack data members
1616 if (track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) return FinalizeTrack(track);
1618 AliWarning("track not finalized due to extrapolation failure");