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