]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackReconstructorK.cxx
Updated READMEmapping
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackReconstructorK.cxx
CommitLineData
8cc77df0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
3d1463c8 18//-----------------------------------------------------------------------------
06ca6d7b 19/// \class AliMUONTrackReconstructorK
06ca6d7b 20///
21/// MUON track reconstructor using the kalman method
22///
23/// This class contains as data:
24/// - the parameters for the track reconstruction
25///
26/// It contains as methods, among others:
27/// - MakeTracks to build the tracks
28///
3d1463c8 29//-----------------------------------------------------------------------------
8cc77df0 30
8cc77df0 31#include "AliMUONTrackReconstructorK.h"
96ebe67e 32
8cc77df0 33#include "AliMUONConstants.h"
96ebe67e 34#include "AliMUONVCluster.h"
1fef78c8 35#include "AliMUONVClusterServer.h"
96ebe67e 36#include "AliMUONVClusterStore.h"
ea94c18b 37#include "AliMUONTrack.h"
38#include "AliMUONTrackParam.h"
39#include "AliMUONTrackExtrap.h"
5a240757 40#include "AliMUONRecoParam.h"
8cde4af5 41
1fef78c8 42#include "AliMpArea.h"
43
8cc77df0 44#include "AliLog.h"
45
8cde4af5 46#include <Riostream.h>
ea94c18b 47#include <TMath.h>
48#include <TMatrixD.h>
8cde4af5 49
50/// \cond CLASSIMP
8cc77df0 51ClassImp(AliMUONTrackReconstructorK) // Class implementation in ROOT context
8cde4af5 52/// \endcond
8cc77df0 53
019df241 54 //__________________________________________________________________________
a0dc65b4 55AliMUONTrackReconstructorK::AliMUONTrackReconstructorK(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
56 : AliMUONVTrackReconstructor(recoParam, clusterServer)
8cc77df0 57{
96ebe67e 58 /// Constructor
8cc77df0 59}
60
019df241 61 //__________________________________________________________________________
ea94c18b 62AliMUONTrackReconstructorK::~AliMUONTrackReconstructorK()
8cc77df0 63{
ea94c18b 64/// Destructor
65}
8cc77df0 66
67 //__________________________________________________________________________
89c8d66d 68Bool_t AliMUONTrackReconstructorK::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
8cc77df0 69{
89c8d66d 70 /// To make track candidates (assuming linear propagation if AliMUONRecoParam::MakeTrackCandidatesFast() return kTRUE):
ea94c18b 71 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
89c8d66d 72 /// Good candidates are made of at least three clusters if both stations are requested (two otherwise).
73 /// Keep only best candidates or all of them according to the flag AliMUONRecoParam::TrackAllTracks().
b709ac13 74
208f139e 75 TClonesArray *segments;
89c8d66d 76 AliMUONObjectPair *segment;
ea94c18b 77 AliMUONTrack *track;
78 Int_t iCandidate = 0;
96ebe67e 79 Bool_t clusterFound;
8cc77df0 80
ea94c18b 81 AliDebug(1,"Enter MakeTrackCandidates");
8cc77df0 82
1fef78c8 83 // Unless we're doing combined tracking, we'll clusterize all stations at once
84 Int_t firstChamber(0);
85 Int_t lastChamber(9);
86
a0dc65b4 87 if (GetRecoParam()->CombineClusterTrackReco()) {
1fef78c8 88 // ... Here's the exception : ask the clustering to reconstruct
89 // clusters *only* in station 4 and 5 for combined tracking
90 firstChamber = 6;
91 }
92
93 for (Int_t i = firstChamber; i <= lastChamber; ++i )
94 {
35be7ed7 95 if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam());
1fef78c8 96 }
97
ea94c18b 98 // Loop over stations(1..) 5 and 4 and make track candidates
99 for (Int_t istat=4; istat>=3; istat--) {
100
208f139e 101 // Make segments in the station
9bf6860b 102 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
ea94c18b 103
104 // Loop over segments
89c8d66d 105 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++) {
ea94c18b 106 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
89c8d66d 107 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
ea94c18b 108
109 // Transform segments to tracks and put them at the end of fRecTracksPtr
89c8d66d 110 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
ea94c18b 111 fNRecTracks++;
112
96ebe67e 113 // Look for compatible cluster(s) in the other station
89c8d66d 114 if (GetRecoParam()->MakeTrackCandidatesFast()) clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
115 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
019df241 116
9bf6860b 117 // Remove track if no cluster found on a requested station
89c8d66d 118 // or abort tracking if there are too many candidates
6b191dea 119 if (GetRecoParam()->RequestStation(7-istat)) {
120 if (!clusterFound) {
121 fRecTracksPtr->Remove(track);
122 fNRecTracks--;
123 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
124 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks));
125 delete segments;
126 return kFALSE;
127 }
128 } else {
129 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
130 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
131 delete segments;
132 return kFALSE;
133 }
ea94c18b 134 }
135
136 }
89c8d66d 137
ea94c18b 138 // delete the array of segments
7ec3b9cf 139 delete segments;
ea94c18b 140 }
141
89c8d66d 142 // Keep all different tracks if required
143 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
ea94c18b 144
89c8d66d 145 // Retrace tracks using Kalman filter and select them if needed
146 Int_t nCurrentTracks = fRecTracksPtr->GetLast()+1;
147 for (Int_t iRecTrack = 0; iRecTrack < nCurrentTracks; iRecTrack++) {
148 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
ea94c18b 149
89c8d66d 150 // skip empty slots
151 if(!track) continue;
152
153 // retrace tracks using Kalman filter
154 RetraceTrack(*track,kTRUE);
155
6b191dea 156 // remove tracks out of limits
157 if (!IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
158 fRecTracksPtr->Remove(track);
159 fNRecTracks--;
ea94c18b 160 }
161
162 }
163
89c8d66d 164 // Keep only the best tracks if required
165 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
3e9a7a05 166 else fRecTracksPtr->Compress();
ea94c18b 167
168 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
169
89c8d66d 170 return kTRUE;
171
9bf6860b 172}
173
174 //__________________________________________________________________________
89c8d66d 175Bool_t AliMUONTrackReconstructorK::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
9bf6860b 176{
89c8d66d 177 /// To make extra track candidates assuming linear propagation:
9bf6860b 178 /// clustering is supposed to be already done
179 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
89c8d66d 180 /// Good candidates are made of at least three clusters if both stations are requested (two otherwise).
9bf6860b 181 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
182
183 TClonesArray *segments;
89c8d66d 184 AliMUONObjectPair *segment;
9bf6860b 185 AliMUONTrack *track;
186 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
187 Int_t initialNRecTracks = fNRecTracks;
188 Bool_t clusterFound;
189
190 AliDebug(1,"Enter MakeMoreTrackCandidates");
191
192 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
193 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
194 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
195
196 // Make segments between ch1 and ch2
197 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
198
89c8d66d 199 /// Remove segments already attached to a track
200 RemoveUsedSegments(*segments);
201
9bf6860b 202 // Loop over segments
89c8d66d 203 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++) {
9bf6860b 204 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
89c8d66d 205 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
9bf6860b 206
207 // Transform segments to tracks and put them at the end of fRecTracksPtr
208 iCurrentTrack = fRecTracksPtr->GetLast()+1;
89c8d66d 209 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
9bf6860b 210 fNRecTracks++;
211
212 // Look for compatible cluster(s) in the second chamber of station 5
89c8d66d 213 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
9bf6860b 214
215 // skip the original track in case it has been removed
a0dc65b4 216 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
9bf6860b 217
218 // loop over every new tracks
219 nCurrentTracks = fRecTracksPtr->GetLast()+1;
220 while (iCurrentTrack < nCurrentTracks) {
221 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
222
223 // Look for compatible cluster(s) in the second chamber of station 4
89c8d66d 224 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
9bf6860b 225
226 iCurrentTrack++;
227 }
228
89c8d66d 229 // abort tracking if there are too many candidates
6b191dea 230 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
231 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
89c8d66d 232 delete segments;
233 return kFALSE;
234 }
235
9bf6860b 236 }
237
238 // delete the array of segments
239 delete segments;
240 }
241 }
242
89c8d66d 243 // Retrace tracks using Kalman filter (also compute track chi2) and select them
244 nCurrentTracks = fRecTracksPtr->GetLast()+1;
245 for (Int_t iRecTrack = initialNRecTracks; iRecTrack < nCurrentTracks; iRecTrack++) {
9bf6860b 246 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
247
89c8d66d 248 // skip empty slots
249 if(!track) continue;
250
251 // retrace tracks using Kalman filter
9bf6860b 252 RetraceTrack(*track,kTRUE);
253
89c8d66d 254 // remove tracks with absolute bending momentum out of limits
6b191dea 255 if (!IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
256 fRecTracksPtr->Remove(track);
257 fNRecTracks--;
9bf6860b 258 }
259
260 }
261
89c8d66d 262 // Keep only the best tracks if required
263 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
264 else fRecTracksPtr->Compress();
9bf6860b 265
266 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
267
89c8d66d 268 return kTRUE;
269
8cc77df0 270}
271
ea94c18b 272 //__________________________________________________________________________
273void AliMUONTrackReconstructorK::RetraceTrack(AliMUONTrack &trackCandidate, Bool_t resetSeed)
8cc77df0 274{
96ebe67e 275 /// Re-run the kalman filter from the most downstream cluster to the most uptream one
ea94c18b 276 AliDebug(1,"Enter RetraceTrack");
277
7332f213 278 AliMUONTrackParam* lastTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Last();
ea94c18b 279
96ebe67e 280 // Reset the "seed" (= track parameters and their covariances at last cluster) if required
ea94c18b 281 if (resetSeed) {
7332f213 282
283 // parameters at last cluster
284 AliMUONVCluster* cluster2 = lastTrackParam->GetClusterPtr();
285 Double_t x2 = cluster2->GetX();
286 Double_t y2 = cluster2->GetY();
287 Double_t z2 = cluster2->GetZ();
288
289 // parameters at last but one cluster
290 AliMUONTrackParam* previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(lastTrackParam);
291 AliMUONVCluster* cluster1 = previousTrackParam->GetClusterPtr();
0e894e58 292 // make sure it is on the previous chamber (can have 2 clusters in the same chamber after "ComplementTrack")
293 if (cluster2->GetChamberId() == cluster1->GetChamberId()) {
294 previousTrackParam = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(previousTrackParam);
295 cluster1 = previousTrackParam->GetClusterPtr();
296 }
7332f213 297 Double_t x1 = cluster1->GetX();
298 Double_t y1 = cluster1->GetY();
299 Double_t z1 = cluster1->GetZ();
300
301 // reset track parameters
302 Double_t dZ = z1 - z2;
303 lastTrackParam->SetNonBendingCoor(x2);
304 lastTrackParam->SetBendingCoor(y2);
305 lastTrackParam->SetZ(z2);
306 lastTrackParam->SetNonBendingSlope((x1 - x2) / dZ);
307 lastTrackParam->SetBendingSlope((y1 - y2) / dZ);
308 Double_t bendingImpact = y2 - z2 * lastTrackParam->GetBendingSlope();
9bf6860b 309 Double_t inverseBendingMomentum = 1. / AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpact);
310 lastTrackParam->SetInverseBendingMomentum(inverseBendingMomentum);
7332f213 311
312 // => Reset track parameter covariances at last cluster (as if the other clusters did not exist)
313 TMatrixD lastParamCov(5,5);
314 lastParamCov.Zero();
ea94c18b 315 // Non bending plane
7332f213 316 lastParamCov(0,0) = cluster2->GetErrX2();
89c8d66d 317 lastParamCov(0,1) = - cluster2->GetErrX2() / dZ;
318 lastParamCov(1,0) = lastParamCov(0,1);
319 lastParamCov(1,1) = ( 1000. * cluster1->GetErrX2() + cluster2->GetErrX2() ) / dZ / dZ;
ea94c18b 320 // Bending plane
7332f213 321 lastParamCov(2,2) = cluster2->GetErrY2();
89c8d66d 322 lastParamCov(2,3) = - cluster2->GetErrY2() / dZ;
323 lastParamCov(3,2) = lastParamCov(2,3);
324 lastParamCov(3,3) = ( 1000. * cluster1->GetErrY2() + cluster2->GetErrY2() ) / dZ / dZ;
9bf6860b 325 // Inverse bending momentum (vertex resolution + bending slope resolution + 10% error on dipole parameters+field)
89c8d66d 326 if (AliMUONTrackExtrap::IsFieldON()) {
327 lastParamCov(4,4) = ((GetRecoParam()->GetBendingVertexDispersion() *
328 GetRecoParam()->GetBendingVertexDispersion() +
329 (z1 * z1 * cluster2->GetErrY2() + z2 * z2 * 1000. * cluster1->GetErrY2()) / dZ / dZ) /
330 bendingImpact / bendingImpact + 0.1 * 0.1) * inverseBendingMomentum * inverseBendingMomentum;
331 lastParamCov(2,4) = z1 * cluster2->GetErrY2() * inverseBendingMomentum / bendingImpact / dZ;
332 lastParamCov(4,2) = lastParamCov(2,4);
333 lastParamCov(3,4) = - (z1 * cluster2->GetErrY2() + z2 * 1000. * cluster1->GetErrY2()) *
334 inverseBendingMomentum / bendingImpact / dZ / dZ;
335 lastParamCov(4,3) = lastParamCov(3,4);
336 } else lastParamCov(4,4) = inverseBendingMomentum*inverseBendingMomentum;
7332f213 337 lastTrackParam->SetCovariances(lastParamCov);
ea94c18b 338
339 // Reset the track chi2
7332f213 340 lastTrackParam->SetTrackChi2(0.);
ea94c18b 341
342 }
343
344 // Redo the tracking
7332f213 345 RetracePartialTrack(trackCandidate, lastTrackParam);
ea94c18b 346
347}
8cc77df0 348
ea94c18b 349 //__________________________________________________________________________
350void AliMUONTrackReconstructorK::RetracePartialTrack(AliMUONTrack &trackCandidate, const AliMUONTrackParam* startingTrackParam)
351{
96ebe67e 352 /// Re-run the kalman filter from the cluster attached to startingTrackParam to the most uptream cluster
ea94c18b 353 AliDebug(1,"Enter RetracePartialTrack");
354
355 // Printout for debuging
356 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 357 cout << "RetracePartialTrack: track chi2 before re-tracking: " << trackCandidate.GetGlobalChi2() << endl;
ea94c18b 358 }
359
360 // Reset the track chi2
96ebe67e 361 trackCandidate.SetGlobalChi2(startingTrackParam->GetTrackChi2());
ea94c18b 362
96ebe67e 363 // loop over attached clusters until the first one and recompute track parameters and covariances using kalman filter
364 Int_t expectedChamber = startingTrackParam->GetClusterPtr()->GetChamberId() - 1;
ea94c18b 365 Int_t currentChamber;
96ebe67e 366 Double_t addChi2TrackAtCluster;
367 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackCandidate.GetTrackParamAtCluster()->Before(startingTrackParam);
368 while (trackParamAtCluster) {
ea94c18b 369
370 // reset track parameters and their covariances
96ebe67e 371 trackParamAtCluster->SetParameters(startingTrackParam->GetParameters());
372 trackParamAtCluster->SetZ(startingTrackParam->GetZ());
373 trackParamAtCluster->SetCovariances(startingTrackParam->GetCovariances());
ea94c18b 374
375 // add MCS effect
96ebe67e 376 AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.);
ea94c18b 377
378 // reset propagator for smoother
a0dc65b4 379 if (GetRecoParam()->UseSmoother()) trackParamAtCluster->ResetPropagator();
ea94c18b 380
9bf6860b 381 // add MCS in missing chambers if any
96ebe67e 382 currentChamber = trackParamAtCluster->GetClusterPtr()->GetChamberId();
ea94c18b 383 while (currentChamber < expectedChamber) {
384 // extrapolation to the missing chamber (update the propagator)
96ebe67e 385 AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, AliMUONConstants::DefaultChamberZ(expectedChamber),
a0dc65b4 386 GetRecoParam()->UseSmoother());
ea94c18b 387 // add MCS effect
96ebe67e 388 AliMUONTrackExtrap::AddMCSEffect(trackParamAtCluster,AliMUONConstants::ChamberThicknessInX0(),1.);
ea94c18b 389 expectedChamber--;
390 }
391
96ebe67e 392 // extrapolation to the plane of the cluster attached to the current trackParamAtCluster (update the propagator)
393 AliMUONTrackExtrap::ExtrapToZCov(trackParamAtCluster, trackParamAtCluster->GetClusterPtr()->GetZ(),
a0dc65b4 394 GetRecoParam()->UseSmoother());
ea94c18b 395
a0dc65b4 396 if (GetRecoParam()->UseSmoother()) {
ea94c18b 397 // save extrapolated parameters for smoother
96ebe67e 398 trackParamAtCluster->SetExtrapParameters(trackParamAtCluster->GetParameters());
ea94c18b 399
400 // save extrapolated covariance matrix for smoother
96ebe67e 401 trackParamAtCluster->SetExtrapCovariances(trackParamAtCluster->GetCovariances());
ea94c18b 402 }
403
9bf6860b 404 // Compute new track parameters using kalman filter
96ebe67e 405 addChi2TrackAtCluster = RunKalmanFilter(*trackParamAtCluster);
ea94c18b 406
407 // Update the track chi2
96ebe67e 408 trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2() + addChi2TrackAtCluster);
409 trackParamAtCluster->SetTrackChi2(trackCandidate.GetGlobalChi2());
ea94c18b 410
96ebe67e 411 // prepare next step
412 expectedChamber = currentChamber - 1;
413 startingTrackParam = trackParamAtCluster;
414 trackParamAtCluster = (AliMUONTrackParam*) (trackCandidate.GetTrackParamAtCluster()->Before(startingTrackParam));
ea94c18b 415 }
416
417 // Printout for debuging
418 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 419 cout << "RetracePartialTrack: track chi2 after re-tracking: " << trackCandidate.GetGlobalChi2() << endl;
ea94c18b 420 }
421
422}
8cc77df0 423
ea94c18b 424 //__________________________________________________________________________
89c8d66d 425Bool_t AliMUONTrackReconstructorK::FollowTracks(AliMUONVClusterStore& clusterStore)
ea94c18b 426{
427 /// Follow tracks in stations(1..) 3, 2 and 1
428 AliDebug(1,"Enter FollowTracks");
429
430 AliMUONTrack *track;
431 Int_t currentNRecTracks;
ea94c18b 432
433 for (Int_t station = 2; station >= 0; station--) {
434
435 // Save the actual number of reconstructed track in case of
436 // tracks are added or suppressed during the tracking procedure
437 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
438 currentNRecTracks = fNRecTracks;
439
440 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
441 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
442
443 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
444
96ebe67e 445 // Look for compatible cluster(s) in station(0..) "station"
9bf6860b 446 if (!FollowTrackInStation(*track, clusterStore, station)) {
447
448 // Try to recover track if required
a0dc65b4 449 if (GetRecoParam()->RecoverTracks()) {
9bf6860b 450
451 // work on a copy of the track if this station is not required
452 // to keep the case where no cluster is reconstructed as a possible candidate
a0dc65b4 453 if (!GetRecoParam()->RequestStation(station)) {
9bf6860b 454 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
455 fNRecTracks++;
456 }
457
458 // try to recover
459 if (!RecoverTrack(*track, clusterStore, station)) {
460 // remove track if no cluster found
461 fRecTracksPtr->Remove(track);
462 fNRecTracks--;
463 }
464
a0dc65b4 465 } else if (GetRecoParam()->RequestStation(station)) {
9bf6860b 466 // remove track if no cluster found
467 fRecTracksPtr->Remove(track);
468 fNRecTracks--;
469 }
470
8cc77df0 471 }
ea94c18b 472
89c8d66d 473 // abort tracking if there are too many candidates
6b191dea 474 if (GetRecoParam()->RequestStation(station)) {
475 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
476 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks));
477 return kFALSE;
478 }
479 } else {
480 if ((fNRecTracks + currentNRecTracks - iRecTrack - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
481 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks + currentNRecTracks - iRecTrack - 1));
482 return kFALSE;
483 }
89c8d66d 484 }
485
8cc77df0 486 }
ea94c18b 487
488 fRecTracksPtr->Compress(); // this is essential before checking tracks
489
ea94c18b 490 // Keep only the best tracks if required
a0dc65b4 491 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
ea94c18b 492
493 }
494
89c8d66d 495 return kTRUE;
496
9bf6860b 497}
498
499 //__________________________________________________________________________
500Bool_t AliMUONTrackReconstructorK::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
501{
502 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
503 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
504 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
505 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
506 /// Remove the obsolete "trackCandidate" at the end.
507 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
508 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
509 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
510
9bf6860b 511 Double_t chi2OfCluster;
a0dc65b4 512 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
513 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
9bf6860b 514 Double_t addChi2TrackAtCluster;
515 Double_t bestAddChi2TrackAtCluster = 1.e10;
516 Bool_t foundOneCluster = kFALSE;
517 AliMUONTrack *newTrack = 0x0;
518 AliMUONVCluster *cluster;
519 AliMUONTrackParam extrapTrackParamAtCh;
520 AliMUONTrackParam extrapTrackParamAtCluster;
521 AliMUONTrackParam bestTrackParamAtCluster;
522
523 // Get track parameters according to the propagation direction
524 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
525 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
526
527 // Printout for debuging
528 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
529 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
530 extrapTrackParamAtCh.GetParameters().Print();
531 extrapTrackParamAtCh.GetCovariances().Print();
532 }
533
534 // Add MCS effect
535 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
536
537 // reset propagator for smoother
a0dc65b4 538 if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator();
9bf6860b 539
540 // Add MCS in the missing chamber(s) if any
541 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
542 while (currentChamber > nextChamber + 1) {
543 // extrapolation to the missing chamber
544 currentChamber--;
545 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber),
a0dc65b4 546 GetRecoParam()->UseSmoother());
9bf6860b 547 // add MCS effect
548 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
549 }
550
551 //Extrapolate trackCandidate to chamber
552 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber),
a0dc65b4 553 GetRecoParam()->UseSmoother());
9bf6860b 554
555 // Printout for debuging
556 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
557 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
558 extrapTrackParamAtCh.GetParameters().Print();
559 extrapTrackParamAtCh.GetCovariances().Print();
560 }
561
562 // Printout for debuging
563 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
564 cout << "FollowTrackInChamber: look for clusters in chamber(1..): " << nextChamber+1 << endl;
565 }
566
567 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
568 // except for station 4 and 5 that are already entirely clusterized
a0dc65b4 569 if (GetRecoParam()->CombineClusterTrackReco()) {
9bf6860b 570 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
571 }
572
573 // Create iterators to loop over clusters in both chambers
574 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
575
576 // look for candidates in chamber
577 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
578
579 // try to add the current cluster fast
580 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
581
582 // try to add the current cluster accuratly
583 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster,
a0dc65b4 584 GetRecoParam()->UseSmoother());
9bf6860b 585
586 // if good chi2 then consider to add cluster
587 if (chi2OfCluster < maxChi2OfCluster) {
9bf6860b 588
a0dc65b4 589 if (GetRecoParam()->UseSmoother()) {
9bf6860b 590 // save extrapolated parameters for smoother
591 extrapTrackParamAtCluster.SetExtrapParameters(extrapTrackParamAtCluster.GetParameters());
592
593 // save extrapolated covariance matrix for smoother
594 extrapTrackParamAtCluster.SetExtrapCovariances(extrapTrackParamAtCluster.GetCovariances());
595 }
596
597 // Compute new track parameters including new cluster using kalman filter
598 addChi2TrackAtCluster = RunKalmanFilter(extrapTrackParamAtCluster);
599
6b191dea 600 // skip track out of limits
601 if (!IsAcceptable(extrapTrackParamAtCluster)) continue;
89c8d66d 602
603 // remember a cluster was found
604 foundOneCluster = kTRUE;
605
606 // Printout for debuging
607 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
608 cout << "FollowTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
609 << " (Chi2 = " << chi2OfCluster << ")" << endl;
610 cluster->Print();
611 }
9bf6860b 612
a0dc65b4 613 if (GetRecoParam()->TrackAllTracks()) {
9bf6860b 614 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
615 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
616 UpdateTrack(*newTrack,extrapTrackParamAtCluster,addChi2TrackAtCluster);
617 fNRecTracks++;
618
619 // Printout for debuging
620 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
621 cout << "FollowTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
622 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
623 }
624
625 } else if (addChi2TrackAtCluster < bestAddChi2TrackAtCluster) {
626 // keep track of the best cluster
627 bestAddChi2TrackAtCluster = addChi2TrackAtCluster;
628 bestTrackParamAtCluster = extrapTrackParamAtCluster;
629 }
630
631 }
632
633 }
634
635 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 636 if (!GetRecoParam()->TrackAllTracks()) {
9bf6860b 637 if (foundOneCluster) {
638 UpdateTrack(trackCandidate,bestTrackParamAtCluster,bestAddChi2TrackAtCluster);
639
640 // Printout for debuging
641 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
642 cout << "FollowTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
643 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
644 }
645
646 } else return kFALSE;
647
648 } else if (foundOneCluster) {
649
650 // remove obsolete track
651 fRecTracksPtr->Remove(&trackCandidate);
652 fNRecTracks--;
653
654 } else return kFALSE;
655
656 return kTRUE;
657
ea94c18b 658}
b0e4c598 659
ea94c18b 660 //__________________________________________________________________________
1fef78c8 661Bool_t AliMUONTrackReconstructorK::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
ea94c18b 662{
96ebe67e 663 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
ea94c18b 664 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
665 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
666 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
667 /// Remove the obsolete "trackCandidate" at the end.
96ebe67e 668 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
669 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
ea94c18b 670 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
671
672 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
673 // - nextStation == station(1...) 5 => forward propagation
674 // - nextStation < station(1...) 5 => backward propagation
675 Int_t ch1, ch2;
676 if (nextStation==4) {
677 ch1 = 2*nextStation+1;
678 ch2 = 2*nextStation;
679 } else {
680 ch1 = 2*nextStation;
681 ch2 = 2*nextStation+1;
682 }
683
96ebe67e 684 Double_t chi2OfCluster;
a0dc65b4 685 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
686 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
96ebe67e 687 Double_t addChi2TrackAtCluster1;
688 Double_t addChi2TrackAtCluster2;
689 Double_t bestAddChi2TrackAtCluster1 = 1.e10;
690 Double_t bestAddChi2TrackAtCluster2 = 1.e10;
691 Bool_t foundOneCluster = kFALSE;
692 Bool_t foundTwoClusters = kFALSE;
ea94c18b 693 AliMUONTrack *newTrack = 0x0;
96ebe67e 694 AliMUONVCluster *clusterCh1, *clusterCh2;
ea94c18b 695 AliMUONTrackParam extrapTrackParam;
7332f213 696 AliMUONTrackParam extrapTrackParamAtCh;
96ebe67e 697 AliMUONTrackParam extrapTrackParamAtCluster1;
698 AliMUONTrackParam extrapTrackParamAtCluster2;
699 AliMUONTrackParam bestTrackParamAtCluster1;
700 AliMUONTrackParam bestTrackParamAtCluster2;
701
702 Int_t nClusters = clusterStore.GetSize();
703 Bool_t *clusterCh1Used = new Bool_t[nClusters];
704 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
705 Int_t iCluster1;
706
7332f213 707 // Get track parameters according to the propagation direction
708
709 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
710 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
ea94c18b 711
9bf6860b 712 // Printout for debuging
713 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
714 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
715 extrapTrackParamAtCh.GetParameters().Print();
716 extrapTrackParamAtCh.GetCovariances().Print();
717 }
718
ea94c18b 719 // Add MCS effect
019df241 720 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
ea94c18b 721
722 // reset propagator for smoother
a0dc65b4 723 if (GetRecoParam()->UseSmoother()) extrapTrackParamAtCh.ResetPropagator();
ea94c18b 724
9bf6860b 725 // Add MCS in the missing chamber(s) if any
726 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
727 while (ch1 < ch2 && currentChamber > ch2 + 1) {
ea94c18b 728 // extrapolation to the missing chamber
9bf6860b 729 currentChamber--;
730 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber),
a0dc65b4 731 GetRecoParam()->UseSmoother());
ea94c18b 732 // add MCS effect
019df241 733 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
ea94c18b 734 }
735
736 //Extrapolate trackCandidate to chamber "ch2"
3304fa09 737 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2),
a0dc65b4 738 GetRecoParam()->UseSmoother());
ea94c18b 739
740 // Printout for debuging
741 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
9bf6860b 742 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
743 extrapTrackParamAtCh.GetParameters().Print();
019df241 744 extrapTrackParamAtCh.GetCovariances().Print();
ea94c18b 745 }
746
747 // Printout for debuging
748 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 749 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
ea94c18b 750 }
751
1fef78c8 752 // Ask the clustering to reconstruct new clusters around the track position in the current station
753 // except for station 4 and 5 that are already entirely clusterized
a0dc65b4 754 if (GetRecoParam()->CombineClusterTrackReco()) {
1fef78c8 755 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
756 }
757
96ebe67e 758 // Create iterators to loop over clusters in both chambers
759 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
760 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
761
762 // look for candidates in chamber 2
763 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
ea94c18b 764
96ebe67e 765 // try to add the current cluster fast
766 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
019df241 767
96ebe67e 768 // try to add the current cluster accuratly
769 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2,
a0dc65b4 770 GetRecoParam()->UseSmoother());
ea94c18b 771
96ebe67e 772 // if good chi2 then try to attach a cluster in the other chamber too
773 if (chi2OfCluster < maxChi2OfCluster) {
ea94c18b 774
a0dc65b4 775 if (GetRecoParam()->UseSmoother()) {
ea94c18b 776 // save extrapolated parameters for smoother
96ebe67e 777 extrapTrackParamAtCluster2.SetExtrapParameters(extrapTrackParamAtCluster2.GetParameters());
ea94c18b 778
779 // save extrapolated covariance matrix for smoother
96ebe67e 780 extrapTrackParamAtCluster2.SetExtrapCovariances(extrapTrackParamAtCluster2.GetCovariances());
ea94c18b 781 }
782
96ebe67e 783 // Compute new track parameters including "clusterCh2" using kalman filter
784 addChi2TrackAtCluster2 = RunKalmanFilter(extrapTrackParamAtCluster2);
ea94c18b 785
6b191dea 786 // skip track out of limits
787 if (!IsAcceptable(extrapTrackParamAtCluster2)) continue;
89c8d66d 788
789 // Printout for debuging
790 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
791 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
792 << " (Chi2 = " << chi2OfCluster << ")" << endl;
793 clusterCh2->Print();
794 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
795 }
796
ea94c18b 797 // copy new track parameters for next step
96ebe67e 798 extrapTrackParam = extrapTrackParamAtCluster2;
ea94c18b 799
800 // add MCS effect
801 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
802
803 // reset propagator for smoother
a0dc65b4 804 if (GetRecoParam()->UseSmoother()) extrapTrackParam.ResetPropagator();
ea94c18b 805
019df241 806 //Extrapolate track parameters to chamber "ch1"
3304fa09 807 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1),
a0dc65b4 808 GetRecoParam()->UseSmoother());
019df241 809
96ebe67e 810 // reset cluster iterator of chamber 1
811 nextInCh1.Reset();
812 iCluster1 = -1;
813
814 // look for second candidates in chamber 1
89c8d66d 815 Bool_t foundSecondCluster = kFALSE;
96ebe67e 816 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
817 iCluster1++;
ea94c18b 818
96ebe67e 819 // try to add the current cluster fast
820 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
019df241 821
96ebe67e 822 // try to add the current cluster accuratly
823 chi2OfCluster = TryOneCluster(extrapTrackParam, clusterCh1, extrapTrackParamAtCluster1,
a0dc65b4 824 GetRecoParam()->UseSmoother());
019df241 825
96ebe67e 826 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
827 if (chi2OfCluster < maxChi2OfCluster) {
019df241 828
a0dc65b4 829 if (GetRecoParam()->UseSmoother()) {
ea94c18b 830 // save extrapolated parameters for smoother
96ebe67e 831 extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters());
ea94c18b 832
833 // save extrapolated covariance matrix for smoother
96ebe67e 834 extrapTrackParamAtCluster1.SetExtrapCovariances(extrapTrackParamAtCluster1.GetCovariances());
ea94c18b 835 }
836
96ebe67e 837 // Compute new track parameters including "clusterCh1" using kalman filter
838 addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1);
ea94c18b 839
6b191dea 840 // skip track out of limits
841 if (!IsAcceptable(extrapTrackParamAtCluster1)) continue;
89c8d66d 842
843 // remember a second cluster was found
844 foundSecondCluster = kTRUE;
845 foundTwoClusters = kTRUE;
846
847 // Printout for debuging
848 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
849 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
850 << " (Chi2 = " << chi2OfCluster << ")" << endl;
851 clusterCh1->Print();
852 }
9bf6860b 853
a0dc65b4 854 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 855 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
ea94c18b 856 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 857 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2,addChi2TrackAtCluster1,addChi2TrackAtCluster2);
ea94c18b 858 fNRecTracks++;
859
96ebe67e 860 // Tag clusterCh1 as used
861 clusterCh1Used[iCluster1] = kTRUE;
ea94c18b 862
863 // Printout for debuging
864 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 865 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
ea94c18b 866 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
867 }
868
96ebe67e 869 } else if (addChi2TrackAtCluster1+addChi2TrackAtCluster2 < bestAddChi2TrackAtCluster1+bestAddChi2TrackAtCluster2) {
870 // keep track of the best couple of clusters
871 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster1;
872 bestAddChi2TrackAtCluster2 = addChi2TrackAtCluster2;
873 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
874 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
ea94c18b 875 }
876
b0e4c598 877 }
ea94c18b 878
8cc77df0 879 }
ea94c18b 880
96ebe67e 881 // if no clusterCh1 found then consider to add clusterCh2 only
882 if (!foundSecondCluster) {
89c8d66d 883
884 // remember a cluster was found
96ebe67e 885 foundOneCluster = kTRUE;
ea94c18b 886
a0dc65b4 887 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 888 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
ea94c18b 889 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 890 UpdateTrack(*newTrack,extrapTrackParamAtCluster2,addChi2TrackAtCluster2);
ea94c18b 891 fNRecTracks++;
892
ea94c18b 893 // Printout for debuging
894 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 895 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
ea94c18b 896 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
897 }
898
96ebe67e 899 } else if (!foundTwoClusters && addChi2TrackAtCluster2 < bestAddChi2TrackAtCluster1) {
900 // keep track of the best single cluster except if a couple of clusters has already been found
901 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster2;
902 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
ea94c18b 903 }
904
905 }
906
8cc77df0 907 }
ea94c18b 908
909 }
910
911 // look for candidates in chamber 1 not already attached to a track
96ebe67e 912 // if we want to keep all possible tracks or if no good couple of clusters has been found
a0dc65b4 913 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
ea94c18b 914
ea94c18b 915 // add MCS effect for next step
019df241 916 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
917
918 //Extrapolate trackCandidate to chamber "ch1"
3304fa09 919 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1),
a0dc65b4 920 GetRecoParam()->UseSmoother());
019df241 921
9bf6860b 922 // Printout for debuging
923 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
924 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
925 extrapTrackParamAtCh.GetParameters().Print();
926 extrapTrackParamAtCh.GetCovariances().Print();
927 }
928
929 // Printout for debuging
930 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
931 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
932 }
933
96ebe67e 934 // reset cluster iterator of chamber 1
935 nextInCh1.Reset();
936 iCluster1 = -1;
937
938 // look for second candidates in chamber 1
939 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
940 iCluster1++;
ea94c18b 941
96ebe67e 942 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
ea94c18b 943
96ebe67e 944 // try to add the current cluster fast
945 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
019df241 946
96ebe67e 947 // try to add the current cluster accuratly
948 chi2OfCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1,
a0dc65b4 949 GetRecoParam()->UseSmoother());
019df241 950
96ebe67e 951 // if good chi2 then consider to add clusterCh1
952 // We do not try to attach a cluster in the other chamber too since it has already been done above
953 if (chi2OfCluster < maxChi2OfCluster) {
019df241 954
a0dc65b4 955 if (GetRecoParam()->UseSmoother()) {
ea94c18b 956 // save extrapolated parameters for smoother
96ebe67e 957 extrapTrackParamAtCluster1.SetExtrapParameters(extrapTrackParamAtCluster1.GetParameters());
ea94c18b 958
959 // save extrapolated covariance matrix for smoother
96ebe67e 960 extrapTrackParamAtCluster1.SetExtrapCovariances(extrapTrackParamAtCluster1.GetCovariances());
ea94c18b 961 }
962
96ebe67e 963 // Compute new track parameters including "clusterCh1" using kalman filter
964 addChi2TrackAtCluster1 = RunKalmanFilter(extrapTrackParamAtCluster1);
ea94c18b 965
6b191dea 966 // skip track out of limits
967 if (!IsAcceptable(extrapTrackParamAtCluster1)) continue;
89c8d66d 968
969 // remember a cluster was found
970 foundOneCluster = kTRUE;
971
972 // Printout for debuging
973 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
974 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
975 << " (Chi2 = " << chi2OfCluster << ")" << endl;
976 clusterCh1->Print();
977 }
9bf6860b 978
a0dc65b4 979 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 980 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
ea94c18b 981 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 982 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,addChi2TrackAtCluster1);
ea94c18b 983 fNRecTracks++;
984
ea94c18b 985 // Printout for debuging
986 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 987 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
ea94c18b 988 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
989 }
990
96ebe67e 991 } else if (addChi2TrackAtCluster1 < bestAddChi2TrackAtCluster1) {
992 // keep track of the best single cluster except if a couple of clusters has already been found
993 bestAddChi2TrackAtCluster1 = addChi2TrackAtCluster1;
994 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
ea94c18b 995 }
996
997 }
998
8cc77df0 999 }
ea94c18b 1000
1001 }
1002
1003 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 1004 if (!GetRecoParam()->TrackAllTracks()) {
96ebe67e 1005 if (foundTwoClusters) {
1006 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2,bestAddChi2TrackAtCluster1,bestAddChi2TrackAtCluster2);
ea94c18b 1007
ea94c18b 1008 // Printout for debuging
1009 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1010 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
ea94c18b 1011 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1012 }
1013
96ebe67e 1014 } else if (foundOneCluster) {
1015 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestAddChi2TrackAtCluster1);
ea94c18b 1016
ea94c18b 1017 // Printout for debuging
1018 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1019 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
ea94c18b 1020 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1021 }
1022
17773e2e 1023 } else {
96ebe67e 1024 delete [] clusterCh1Used;
17773e2e 1025 return kFALSE;
1026 }
9bf6860b 1027
96ebe67e 1028 } else if (foundOneCluster || foundTwoClusters) {
ea94c18b 1029
1030 // remove obsolete track
1031 fRecTracksPtr->Remove(&trackCandidate);
1032 fNRecTracks--;
1033
17773e2e 1034 } else {
96ebe67e 1035 delete [] clusterCh1Used;
17773e2e 1036 return kFALSE;
9bf6860b 1037 }
1038
96ebe67e 1039 delete [] clusterCh1Used;
ea94c18b 1040 return kTRUE;
1041
1042}
8cc77df0 1043
ea94c18b 1044 //__________________________________________________________________________
96ebe67e 1045Double_t AliMUONTrackReconstructorK::RunKalmanFilter(AliMUONTrackParam &trackParamAtCluster)
ea94c18b 1046{
96ebe67e 1047 /// Compute new track parameters and their covariances including new cluster using kalman filter
ea94c18b 1048 /// return the additional track chi2
1049 AliDebug(1,"Enter RunKalmanFilter");
1050
1051 // Get actual track parameters (p)
96ebe67e 1052 TMatrixD param(trackParamAtCluster.GetParameters());
ea94c18b 1053
96ebe67e 1054 // Get new cluster parameters (m)
1055 AliMUONVCluster *cluster = trackParamAtCluster.GetClusterPtr();
1056 TMatrixD clusterParam(5,1);
1057 clusterParam.Zero();
1058 clusterParam(0,0) = cluster->GetX();
1059 clusterParam(2,0) = cluster->GetY();
ea94c18b 1060
1061 // Compute the actual parameter weight (W)
96ebe67e 1062 TMatrixD paramWeight(trackParamAtCluster.GetCovariances());
ea94c18b 1063 if (paramWeight.Determinant() != 0) {
1064 paramWeight.Invert();
1065 } else {
1066 AliWarning(" Determinant = 0");
1067 return 1.e10;
8cc77df0 1068 }
ea94c18b 1069
96ebe67e 1070 // Compute the new cluster weight (U)
1071 TMatrixD clusterWeight(5,5);
1072 clusterWeight.Zero();
1073 clusterWeight(0,0) = 1. / cluster->GetErrX2();
1074 clusterWeight(2,2) = 1. / cluster->GetErrY2();
8cc77df0 1075
ea94c18b 1076 // Compute the new parameters covariance matrix ( (W+U)^-1 )
96ebe67e 1077 TMatrixD newParamCov(paramWeight,TMatrixD::kPlus,clusterWeight);
ea94c18b 1078 if (newParamCov.Determinant() != 0) {
1079 newParamCov.Invert();
1080 } else {
1081 AliWarning(" Determinant = 0");
1082 return 1.e10;
1083 }
1084
1085 // Save the new parameters covariance matrix
96ebe67e 1086 trackParamAtCluster.SetCovariances(newParamCov);
ea94c18b 1087
1088 // Compute the new parameters (p' = ((W+U)^-1)U(m-p) + p)
96ebe67e 1089 TMatrixD tmp(clusterParam,TMatrixD::kMinus,param);
1090 TMatrixD tmp2(clusterWeight,TMatrixD::kMult,tmp); // U(m-p)
ea94c18b 1091 TMatrixD newParam(newParamCov,TMatrixD::kMult,tmp2); // ((W+U)^-1)U(m-p)
1092 newParam += param; // ((W+U)^-1)U(m-p) + p
1093
1094 // Save the new parameters
96ebe67e 1095 trackParamAtCluster.SetParameters(newParam);
ea94c18b 1096
1097 // Compute the additional chi2 (= ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m))
1098 tmp = newParam; // p'
1099 tmp -= param; // (p'-p)
1100 TMatrixD tmp3(paramWeight,TMatrixD::kMult,tmp); // W(p'-p)
1101 TMatrixD addChi2Track(tmp,TMatrixD::kTransposeMult,tmp3); // ((p'-p)^-1)W(p'-p)
1102 tmp = newParam; // p'
96ebe67e 1103 tmp -= clusterParam; // (p'-m)
1104 TMatrixD tmp4(clusterWeight,TMatrixD::kMult,tmp); // U(p'-m)
ea94c18b 1105 addChi2Track += TMatrixD(tmp,TMatrixD::kTransposeMult,tmp4); // ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m)
1106
1107 return addChi2Track(0,0);
1108
8cc77df0 1109}
1110
ea94c18b 1111 //__________________________________________________________________________
96ebe67e 1112void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster, Double_t addChi2)
8cc77df0 1113{
96ebe67e 1114 /// Add 1 cluster to the track candidate
ea94c18b 1115 /// Update chi2 of the track
1116
9bf6860b 1117 // Flag cluster as being (not) removable
a0dc65b4 1118 if (GetRecoParam()->RequestStation(trackParamAtCluster.GetClusterPtr()->GetChamberId()/2))
9bf6860b 1119 trackParamAtCluster.SetRemovable(kFALSE);
1120 else trackParamAtCluster.SetRemovable(kTRUE);
96ebe67e 1121 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
5f4ceff2 1122
96ebe67e 1123 // Update the track chi2 into trackParamAtCluster
1124 trackParamAtCluster.SetTrackChi2(track.GetGlobalChi2() + addChi2);
ea94c18b 1125
1126 // Update the chi2 of the new track
96ebe67e 1127 track.SetGlobalChi2(trackParamAtCluster.GetTrackChi2());
ea94c18b 1128
96ebe67e 1129 // Update array of TrackParamAtCluster
1130 track.AddTrackParamAtCluster(trackParamAtCluster,*(trackParamAtCluster.GetClusterPtr()));
ea94c18b 1131
1132}
8cc77df0 1133
ea94c18b 1134 //__________________________________________________________________________
96ebe67e 1135void AliMUONTrackReconstructorK::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2,
1136 Double_t addChi2AtCluster1, Double_t addChi2AtCluster2)
ea94c18b 1137{
96ebe67e 1138 /// Add 2 clusters to the track candidate (order is important)
ea94c18b 1139 /// Update track and local chi2
1140
96ebe67e 1141 // Update local chi2 at first cluster
1142 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1143 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1144 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1145 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1146 deltaY*deltaY / cluster1->GetErrY2();
1147 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
ea94c18b 1148
96ebe67e 1149 // Flag first cluster as being removable
1150 trackParamAtCluster1.SetRemovable(kTRUE);
ea94c18b 1151
96ebe67e 1152 // Update local chi2 at second cluster
1153 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1154 AliMUONTrackParam extrapTrackParamAtCluster2(trackParamAtCluster1);
1155 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParamAtCluster2, trackParamAtCluster2.GetZ());
1156 deltaX = extrapTrackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1157 deltaY = extrapTrackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1158 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1159 deltaY*deltaY / cluster2->GetErrY2();
1160 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
ea94c18b 1161
96ebe67e 1162 // Flag second cluster as being removable
1163 trackParamAtCluster2.SetRemovable(kTRUE);
ea94c18b 1164
96ebe67e 1165 // Update the track chi2 into trackParamAtCluster2
1166 trackParamAtCluster2.SetTrackChi2(track.GetGlobalChi2() + addChi2AtCluster2);
ea94c18b 1167
96ebe67e 1168 // Update the track chi2 into trackParamAtCluster1
1169 trackParamAtCluster1.SetTrackChi2(trackParamAtCluster2.GetTrackChi2() + addChi2AtCluster1);
ea94c18b 1170
1171 // Update the chi2 of the new track
96ebe67e 1172 track.SetGlobalChi2(trackParamAtCluster1.GetTrackChi2());
ea94c18b 1173
96ebe67e 1174 // Update array of trackParamAtCluster
1175 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1176 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
ea94c18b 1177
1178}
8cc77df0 1179
ea94c18b 1180 //__________________________________________________________________________
1fef78c8 1181Bool_t AliMUONTrackReconstructorK::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
ea94c18b 1182{
1183 /// Try to recover the track candidate in the next station
96ebe67e 1184 /// by removing the worst of the two clusters attached in the current station
ea94c18b 1185 /// Return kTRUE if recovering succeeds
1186 AliDebug(1,"Enter RecoverTrack");
1187
96ebe67e 1188 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
ea94c18b 1189 if (nextStation > 1) return kFALSE;
1190
96ebe67e 1191 Int_t worstClusterNumber = -1;
9bf6860b 1192 Double_t localChi2, worstLocalChi2 = -1.;
ea94c18b 1193
96ebe67e 1194 // Look for the cluster to remove
1195 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1196 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
ea94c18b 1197
9bf6860b 1198 // check if current cluster is in the previous station
1199 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1200
96ebe67e 1201 // check if current cluster is removable
1202 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
ea94c18b 1203
9bf6860b 1204 // reset the current cluster as being not removable if it is on a required station
a0dc65b4 1205 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
9bf6860b 1206
96ebe67e 1207 // Pick up cluster with the worst chi2
1208 localChi2 = trackParamAtCluster->GetLocalChi2();
1209 if (localChi2 > worstLocalChi2) {
1210 worstLocalChi2 = localChi2;
1211 worstClusterNumber = clusterNumber;
8cc77df0 1212 }
ea94c18b 1213 }
1214
9bf6860b 1215 // check if worst cluster found
1216 if (worstClusterNumber < 0) return kFALSE;
ea94c18b 1217
96ebe67e 1218 // Remove the worst cluster
1219 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
ea94c18b 1220
96ebe67e 1221 // Re-calculate track parameters at the (new) first cluster
1222 RetracePartialTrack(trackCandidate,(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(1));
ea94c18b 1223
6b191dea 1224 // skip track out of limits
1225 if (!IsAcceptable(*((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()))) return kFALSE;
9bf6860b 1226
96ebe67e 1227 // Look for new cluster(s) in next station
1228 return FollowTrackInStation(trackCandidate, clusterStore, nextStation);
ea94c18b 1229
8cc77df0 1230}
1231
1232 //__________________________________________________________________________
ea94c18b 1233Bool_t AliMUONTrackReconstructorK::RunSmoother(AliMUONTrack &track)
8cc77df0 1234{
ea94c18b 1235 /// Compute new track parameters and their covariances using smoother
3304fa09 1236 AliDebug(1,"Enter UseSmoother");
ea94c18b 1237
96ebe67e 1238 AliMUONTrackParam *previousTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
ea94c18b 1239
96ebe67e 1240 // Smoothed parameters and covariances at first cluster = filtered parameters and covariances
ea94c18b 1241 previousTrackParam->SetSmoothParameters(previousTrackParam->GetParameters());
1242 previousTrackParam->SetSmoothCovariances(previousTrackParam->GetCovariances());
1243
96ebe67e 1244 // Compute local chi2 at first cluster
1245 AliMUONVCluster *cluster = previousTrackParam->GetClusterPtr();
1246 Double_t dX = cluster->GetX() - previousTrackParam->GetNonBendingCoor();
1247 Double_t dY = cluster->GetY() - previousTrackParam->GetBendingCoor();
7cdc832b 1248 Double_t chi2 = dX * dX / cluster->GetErrX2() + dY * dY / cluster->GetErrY2();
ea94c18b 1249
96ebe67e 1250 // Save local chi2 at first cluster
7cdc832b 1251 previousTrackParam->SetLocalChi2(chi2);
ea94c18b 1252
96ebe67e 1253 AliMUONTrackParam *currentTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(previousTrackParam);
ea94c18b 1254 while (currentTrackParam) {
1255
1256 // Get variables
1257 const TMatrixD &extrapParameters = previousTrackParam->GetExtrapParameters(); // X(k+1 k)
1258 const TMatrixD &filteredParameters = currentTrackParam->GetParameters(); // X(k k)
1259 const TMatrixD &previousSmoothParameters = previousTrackParam->GetSmoothParameters(); // X(k+1 n)
1260 const TMatrixD &propagator = previousTrackParam->GetPropagator(); // F(k)
1261 const TMatrixD &extrapCovariances = previousTrackParam->GetExtrapCovariances(); // C(k+1 k)
1262 const TMatrixD &filteredCovariances = currentTrackParam->GetCovariances(); // C(k k)
1263 const TMatrixD &previousSmoothCovariances = previousTrackParam->GetSmoothCovariances(); // C(k+1 n)
1264
1265 // Compute smoother gain: A(k) = C(kk) * F(f)^t * (C(k+1 k))^-1
1266 TMatrixD extrapWeight(extrapCovariances);
1267 if (extrapWeight.Determinant() != 0) {
1268 extrapWeight.Invert(); // (C(k+1 k))^-1
1269 } else {
1270 AliWarning(" Determinant = 0");
1271 return kFALSE;
1272 }
1273 TMatrixD smootherGain(filteredCovariances,TMatrixD::kMultTranspose,propagator); // C(kk) * F(f)^t
1274 smootherGain *= extrapWeight; // C(kk) * F(f)^t * (C(k+1 k))^-1
1275
1276 // Compute smoothed parameters: X(k n) = X(k k) + A(k) * (X(k+1 n) - X(k+1 k))
1277 TMatrixD tmpParam(previousSmoothParameters,TMatrixD::kMinus,extrapParameters); // X(k+1 n) - X(k+1 k)
1278 TMatrixD smoothParameters(smootherGain,TMatrixD::kMult,tmpParam); // A(k) * (X(k+1 n) - X(k+1 k))
1279 smoothParameters += filteredParameters; // X(k k) + A(k) * (X(k+1 n) - X(k+1 k))
1280
1281 // Save smoothed parameters
1282 currentTrackParam->SetSmoothParameters(smoothParameters);
1283
1284 // Compute smoothed covariances: C(k n) = C(k k) + A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1285 TMatrixD tmpCov(previousSmoothCovariances,TMatrixD::kMinus,extrapCovariances); // C(k+1 n) - C(k+1 k)
1286 TMatrixD tmpCov2(tmpCov,TMatrixD::kMultTranspose,smootherGain); // (C(k+1 n) - C(k+1 k)) * (A(k))^t
1287 TMatrixD smoothCovariances(smootherGain,TMatrixD::kMult,tmpCov2); // A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1288 smoothCovariances += filteredCovariances; // C(k k) + A(k) * (C(k+1 n) - C(k+1 k)) * (A(k))^t
1289
1290 // Save smoothed covariances
1291 currentTrackParam->SetSmoothCovariances(smoothCovariances);
1292
96ebe67e 1293 // Compute smoothed residual: r(k n) = cluster - X(k n)
1294 cluster = currentTrackParam->GetClusterPtr();
ea94c18b 1295 TMatrixD smoothResidual(2,1);
1296 smoothResidual.Zero();
96ebe67e 1297 smoothResidual(0,0) = cluster->GetX() - smoothParameters(0,0);
1298 smoothResidual(1,0) = cluster->GetY() - smoothParameters(2,0);
ea94c18b 1299
96ebe67e 1300 // Compute weight of smoothed residual: W(k n) = (clusterCov - C(k n))^-1
ea94c18b 1301 TMatrixD smoothResidualWeight(2,2);
96ebe67e 1302 smoothResidualWeight(0,0) = cluster->GetErrX2() - smoothCovariances(0,0);
ea94c18b 1303 smoothResidualWeight(0,1) = - smoothCovariances(0,2);
1304 smoothResidualWeight(1,0) = - smoothCovariances(2,0);
96ebe67e 1305 smoothResidualWeight(1,1) = cluster->GetErrY2() - smoothCovariances(2,2);
ea94c18b 1306 if (smoothResidualWeight.Determinant() != 0) {
1307 smoothResidualWeight.Invert();
1308 } else {
1309 AliWarning(" Determinant = 0");
1310 return kFALSE;
1311 }
1312
1313 // Compute local chi2 = (r(k n))^t * W(k n) * r(k n)
1314 TMatrixD tmpChi2(smoothResidual,TMatrixD::kTransposeMult,smoothResidualWeight); // (r(k n))^t * W(k n)
1315 TMatrixD localChi2(tmpChi2,TMatrixD::kMult,smoothResidual); // (r(k n))^t * W(k n) * r(k n)
1316
1317 // Save local chi2
1318 currentTrackParam->SetLocalChi2(localChi2(0,0));
1319
1320 previousTrackParam = currentTrackParam;
96ebe67e 1321 currentTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(previousTrackParam);
ea94c18b 1322 }
1323
1324 return kTRUE;
1325
8cc77df0 1326}
1327
8cc77df0 1328 //__________________________________________________________________________
89c8d66d 1329Bool_t AliMUONTrackReconstructorK::ComplementTracks(const AliMUONVClusterStore& clusterStore)
b709ac13 1330{
1331 /// Complete tracks by adding missing clusters (if there is an overlap between
89c8d66d 1332 /// two detection elements, the track may have two clusters in the same chamber).
1333 /// Recompute track parameters and covariances at each clusters.
1334 /// Return kTRUE if one or more tracks have been complemented.
b709ac13 1335 AliDebug(1,"Enter ComplementTracks");
1336
1337 Int_t chamberId, detElemId;
96ebe67e 1338 Double_t chi2OfCluster, addChi2TrackAtCluster, bestAddChi2TrackAtCluster;
a0dc65b4 1339 Double_t maxChi2OfCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
1340 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
89c8d66d 1341 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
96ebe67e 1342 AliMUONVCluster *cluster;
1343 AliMUONTrackParam *trackParam, *previousTrackParam, *nextTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
b709ac13 1344
b709ac13 1345 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1346 while (track) {
1347 trackModified = kFALSE;
1348
96ebe67e 1349 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
b709ac13 1350 previousTrackParam = trackParam;
1351 while (trackParam) {
96ebe67e 1352 foundOneCluster = kFALSE;
1353 bestAddChi2TrackAtCluster = 1.e10;
1354 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1355 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
b709ac13 1356
1357 // prepare nextTrackParam before adding new cluster because of the sorting
96ebe67e 1358 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
b709ac13 1359
96ebe67e 1360 // Create iterators to loop over clusters in current chamber
1361 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
b709ac13 1362
1363 // look for one second candidate in the same chamber
96ebe67e 1364 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
b709ac13 1365
1366 // look for a cluster in another detection element
96ebe67e 1367 if (cluster->GetDetElemId() == detElemId) continue;
b709ac13 1368
96ebe67e 1369 // try to add the current cluster fast
1370 if (!TryOneClusterFast(*trackParam, cluster)) continue;
b709ac13 1371
96ebe67e 1372 // try to add the current cluster accurately
b709ac13 1373 // never use track parameters at last cluster because the covariance matrix is meaningless
96ebe67e 1374 if (nextTrackParam) chi2OfCluster = TryOneCluster(*trackParam, cluster, trackParamAtCluster);
1375 else chi2OfCluster = TryOneCluster(*previousTrackParam, cluster, trackParamAtCluster);
b709ac13 1376
1377 // if good chi2 then consider to add this cluster to the track
96ebe67e 1378 if (chi2OfCluster < maxChi2OfCluster) {
b709ac13 1379
96ebe67e 1380 // Compute local track parameters including current cluster using kalman filter
1381 addChi2TrackAtCluster = RunKalmanFilter(trackParamAtCluster);
b709ac13 1382
1383 // keep track of the best cluster
96ebe67e 1384 if (addChi2TrackAtCluster < bestAddChi2TrackAtCluster) {
1385 bestAddChi2TrackAtCluster = addChi2TrackAtCluster;
1386 bestTrackParamAtCluster = trackParamAtCluster;
1387 foundOneCluster = kTRUE;
b709ac13 1388 }
1389
1390 }
1391
1392 }
1393
1394 // add new cluster if any
96ebe67e 1395 if (foundOneCluster) {
0e894e58 1396
1397 // Printout for debuging
1398 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1399 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1400 bestTrackParamAtCluster.GetClusterPtr()->Print();
ad3c6eda 1401 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1402 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1403 bestTrackParamAtCluster.GetParameters().Print();
1404 bestTrackParamAtCluster.GetCovariances().Print();
1405 }
0e894e58 1406 }
1407
7332f213 1408 trackParam->SetRemovable(kTRUE);
1409 bestTrackParamAtCluster.SetRemovable(kTRUE);
1410 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
b709ac13 1411 trackModified = kTRUE;
89c8d66d 1412 hasChanged = kTRUE;
b709ac13 1413 }
1414
1415 previousTrackParam = trackParam;
1416 trackParam = nextTrackParam;
1417 }
1418
1419 // re-compute track parameters using kalman filter if needed
1420 if (trackModified) RetraceTrack(*track,kTRUE);
1421
1422 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1423 }
1424
89c8d66d 1425 return hasChanged;
1426
b709ac13 1427}
1428
1429//__________________________________________________________________________
7332f213 1430void AliMUONTrackReconstructorK::ImproveTrack(AliMUONTrack &track)
8cc77df0 1431{
7332f213 1432 /// Improve the given track by removing removable clusters with local chi2 highter than the defined cut
1433 /// Removable clusters are identified by the method AliMUONTrack::TagRemovableClusters()
ea94c18b 1434 /// Recompute track parameters and covariances at the remaining clusters
7332f213 1435 AliDebug(1,"Enter ImproveTrack");
ea94c18b 1436
1437 Double_t localChi2, worstLocalChi2;
7332f213 1438 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster, *nextTrackParam;
ea94c18b 1439 Bool_t smoothed;
a0dc65b4 1440 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1441 GetRecoParam()->GetSigmaCutForImprovement();
ea94c18b 1442
7332f213 1443 while (!track.IsImproved()) {
ea94c18b 1444
7332f213 1445 // identify removable clusters
a0dc65b4 1446 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
b709ac13 1447
7332f213 1448 // Run smoother if required
1449 smoothed = kFALSE;
a0dc65b4 1450 if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track);
7332f213 1451
1452 // Use standard procedure to compute local chi2 if smoother not required or not working
1453 if (!smoothed) {
ea94c18b 1454
7332f213 1455 // Update track parameters and covariances
1456 track.UpdateCovTrackParamAtCluster();
ea94c18b 1457
7332f213 1458 // Compute local chi2 of each clusters
1459 track.ComputeLocalChi2(kTRUE);
1460 }
1461
1462 // Look for the cluster to remove
1463 worstTrackParamAtCluster = 0x0;
1464 worstLocalChi2 = 0.;
1465 trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->First();
1466 while (trackParamAtCluster) {
ea94c18b 1467
7332f213 1468 // save parameters into smooth parameters in case of smoother did not work properly
a0dc65b4 1469 if (GetRecoParam()->UseSmoother() && !smoothed) {
7332f213 1470 trackParamAtCluster->SetSmoothParameters(trackParamAtCluster->GetParameters());
1471 trackParamAtCluster->SetSmoothCovariances(trackParamAtCluster->GetCovariances());
ea94c18b 1472 }
1473
7332f213 1474 // Pick up cluster with the worst chi2
1475 localChi2 = trackParamAtCluster->GetLocalChi2();
1476 if (localChi2 > worstLocalChi2) {
1477 worstLocalChi2 = localChi2;
1478 worstTrackParamAtCluster = trackParamAtCluster;
ea94c18b 1479 }
1480
7332f213 1481 trackParamAtCluster = (AliMUONTrackParam*)track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1482 }
1483
1484 // Check if worst cluster found
1485 if (!worstTrackParamAtCluster) {
1486 AliWarning("Bad local chi2 values?");
1487 break;
1488 }
1489
1490 // Check whether the worst chi2 is under requirement or not
1491 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1492 track.SetImproved(kTRUE);
1493 break;
1494 }
1495
1496 // if the worst cluster is not removable then stop improvement
1497 if (!worstTrackParamAtCluster->IsRemovable()) break;
1498
1499 // get track parameters at cluster next to the one to be removed
1500 nextTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(worstTrackParamAtCluster);
1501
1502 // Remove the worst cluster
1503 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1504
1505 // Re-calculate track parameters
1506 // - from the cluster immediately downstream the one suppressed
1507 // - or from the begining - if parameters have been re-computed using the standard method (kalman parameters have been lost)
1508 // - or if the removed cluster was the last one
1509 if (smoothed && nextTrackParam) RetracePartialTrack(track,nextTrackParam);
1510 else RetraceTrack(track,kTRUE);
1511
1512 // Printout for debuging
1513 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructorK") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1514 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
ea94c18b 1515 }
1516
ea94c18b 1517 }
1518
8cc77df0 1519}
1520
7332f213 1521//__________________________________________________________________________
1522void AliMUONTrackReconstructorK::FinalizeTrack(AliMUONTrack &track)
b0e4c598 1523{
96ebe67e 1524 /// Update track parameters and covariances at each attached cluster
7332f213 1525 /// using smoother if required, if not already done
b709ac13 1526
96ebe67e 1527 AliMUONTrackParam *trackParamAtCluster;
ea94c18b 1528 Bool_t smoothed = kFALSE;
1529
7332f213 1530 // update track parameters (using smoother if required) if not already done
1531 if (!track.IsImproved()) {
1532 smoothed = kFALSE;
a0dc65b4 1533 if (GetRecoParam()->UseSmoother()) smoothed = RunSmoother(track);
7332f213 1534 if (!smoothed) track.UpdateCovTrackParamAtCluster();
a0dc65b4 1535 } else smoothed = GetRecoParam()->UseSmoother();
7332f213 1536
1537 // copy smoothed parameters and covariances if any
1538 if (smoothed) {
ea94c18b 1539
7332f213 1540 trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1541 while (trackParamAtCluster) {
ea94c18b 1542
7332f213 1543 trackParamAtCluster->SetParameters(trackParamAtCluster->GetSmoothParameters());
1544 trackParamAtCluster->SetCovariances(trackParamAtCluster->GetSmoothCovariances());
ea94c18b 1545
7332f213 1546 trackParamAtCluster = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->After(trackParamAtCluster));
ea94c18b 1547 }
1548
b0e4c598 1549 }
7332f213 1550
7deb8eb0 1551}
1552
1553 //__________________________________________________________________________
b1fea02e 1554Bool_t AliMUONTrackReconstructorK::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
7deb8eb0 1555{
1556 /// re-fit the given track
89c8d66d 1557 AliDebug(1,"Enter RefitTrack");
7deb8eb0 1558
1559 // check validity of the track
ad3c6eda 1560 if (track.GetNClusters() < 3) {
7deb8eb0 1561 AliWarning("the track does not contain enough clusters --> unable to refit");
1562 return kFALSE;
1563 }
1564
1565 // re-compute track parameters and covariances using Kalman filter
1566 RetraceTrack(track,kTRUE);
1567
1568 // Improve the reconstructed tracks if required
b1fea02e 1569 track.SetImproved(kFALSE);
a0dc65b4 1570 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
7deb8eb0 1571
1572 // Fill AliMUONTrack data members
1573 FinalizeTrack(track);
1574
1575 return kTRUE;
1576
b0e4c598 1577}
ea94c18b 1578