1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONTrackReconstructor
20 /// MUON track reconstructor using the original method
22 /// This class contains as data:
23 /// - the parameters for the track reconstruction
25 /// It contains as methods, among others:
26 /// - MakeTracks to build the tracks
27 //-----------------------------------------------------------------------------
29 #include "AliMUONTrackReconstructor.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONVCluster.h"
33 #include "AliMUONVClusterStore.h"
34 #include "AliMUONTrack.h"
35 #include "AliMUONTrackParam.h"
36 #include "AliMUONTrackExtrap.h"
41 #include <Riostream.h>
45 // Functions to be minimized with Minuit
46 void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag);
49 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
52 //__________________________________________________________________________
53 AliMUONTrackReconstructor::AliMUONTrackReconstructor()
54 : AliMUONVTrackReconstructor()
59 //__________________________________________________________________________
60 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
65 //__________________________________________________________________________
66 void AliMUONTrackReconstructor::MakeTrackCandidates(const AliMUONVClusterStore& clusterStore)
68 /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
69 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
70 /// Good candidates are made of at least three clusters.
71 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
73 TClonesArray *segments;
78 AliDebug(1,"Enter MakeTrackCandidates");
80 // Loop over stations(1..) 5 and 4 and make track candidates
81 for (Int_t istat=4; istat>=3; istat--) {
83 // Make segments in the station
84 segments = MakeSegmentsInStation(clusterStore,istat);
87 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
89 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
91 // Transform segments to tracks and put them at the end of fRecTracksPtr
92 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]));
95 // Printout for debuging
96 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
97 cout<<endl<<"Track parameter covariances at first cluster:"<<endl;
98 ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetCovariances().Print();
101 // Look for compatible cluster(s) in the other station
102 if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast())
103 clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
104 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
106 // Remove track if no cluster found
108 fRecTracksPtr->Remove(track);
114 // delete the array of segments
118 fRecTracksPtr->Compress(); // this is essential before checking tracks
120 // Keep all different tracks or only the best ones as required
121 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
122 else RemoveDoubleTracks();
124 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
128 //__________________________________________________________________________
129 void AliMUONTrackReconstructor::FollowTracks(const AliMUONVClusterStore& clusterStore)
131 /// Follow tracks in stations(1..) 3, 2 and 1
132 AliDebug(1,"Enter FollowTracks");
134 AliMUONTrack *track, *nextTrack;
135 AliMUONTrackParam *trackParam, *nextTrackParam;
136 Int_t currentNRecTracks;
139 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
140 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking();
142 for (Int_t station = 2; station >= 0; station--) {
144 // Save the actual number of reconstructed track in case of
145 // tracks are added or suppressed during the tracking procedure
146 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
147 currentNRecTracks = fNRecTracks;
149 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
150 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
152 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
155 // Do not take into account the multiple scattering to speed up the fit
156 // Calculate the track parameter covariance matrix
157 // If "station" is station(1..) 3 then use the vertex to better constrain the fit
158 if (station==2) Fit(*track, kFALSE, kTRUE, kTRUE);
159 else Fit(*track, kFALSE, kFALSE, kTRUE);
161 // Remove the track if the normalized chi2 is too high
162 if (track->GetNormalizedChi2() > sigmaCut2) {
163 fRecTracksPtr->Remove(track);
168 // save parameters from fit into smoothed parameters to complete track afterward
169 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) {
171 if (station==2) { // save track parameters on stations 4 and 5
173 // extrapolate track parameters and covariances at each cluster
174 track->UpdateCovTrackParamAtCluster();
177 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
179 trackParam->SetSmoothParameters(trackParam->GetParameters());
180 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
181 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
184 } else { // or save track parameters on last station only
186 // save parameters from fit
187 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
188 trackParam->SetSmoothParameters(trackParam->GetParameters());
189 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
191 // save parameters extrapolated to the second chamber of the same station if it has been hit
192 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
193 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
195 // reset parameters and covariances
196 nextTrackParam->SetParameters(trackParam->GetParameters());
197 nextTrackParam->SetZ(trackParam->GetZ());
198 nextTrackParam->SetCovariances(trackParam->GetCovariances());
200 // extrapolate them to the z of the corresponding cluster
201 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
204 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
205 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
213 // Printout for debuging
214 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
215 cout<<endl<<"Track parameter covariances at first cluster:"<<endl;
216 ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetCovariances().Print();
219 // Look for compatible cluster(s) in station(0..) "station"
220 clusterFound = FollowTrackInStation(*track, clusterStore, station);
222 // Try to recover track if required
223 if (!clusterFound && AliMUONReconstructor::GetRecoParam()->RecoverTracks())
224 clusterFound = RecoverTrack(*track, clusterStore, station);
226 // remove track if no cluster found
228 fRecTracksPtr->Remove(track);
234 // Compress fRecTracksPtr for the next step
235 fRecTracksPtr->Compress();
237 // Keep only the best tracks if required
238 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
242 // Last fit of track candidates with all stations
243 // Take into account the multiple scattering and remove bad tracks
244 Int_t trackIndex = -1;
245 track = (AliMUONTrack*) fRecTracksPtr->First();
249 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
251 Fit(*track, kTRUE, kFALSE, kTRUE);
253 // Printout for debuging
254 if (AliLog::GetGlobalDebugLevel() >= 3) {
255 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
256 track->RecursiveDump();
259 // Remove the track if the normalized chi2 is too high
260 if (track->GetNormalizedChi2() > sigmaCut2) {
261 fRecTracksPtr->Remove(track);
265 // save parameters from fit into smoothed parameters to complete track afterward
266 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) {
268 // save parameters from fit
269 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
270 trackParam->SetSmoothParameters(trackParam->GetParameters());
271 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
273 // save parameters extrapolated to the second chamber of the same station if it has been hit
274 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
275 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
277 // reset parameters and covariances
278 nextTrackParam->SetParameters(trackParam->GetParameters());
279 nextTrackParam->SetZ(trackParam->GetZ());
280 nextTrackParam->SetCovariances(trackParam->GetCovariances());
282 // extrapolate them to the z of the corresponding cluster
283 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
286 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
287 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
297 fRecTracksPtr->Compress();
301 //__________________________________________________________________________
302 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore, Int_t nextStation)
304 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
305 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
306 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
307 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
308 /// Remove the obsolete "trackCandidate" at the end.
309 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
310 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
312 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
313 // - nextStation == station(1...) 5 => forward propagation
314 // - nextStation < station(1...) 5 => backward propagation
316 if (nextStation==4) {
317 ch1 = 2*nextStation+1;
321 ch2 = 2*nextStation+1;
324 Double_t chi2WithOneCluster = 1.e10;
325 Double_t chi2WithTwoClusters = 1.e10;
326 Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
327 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
328 Double_t maxChi2WithTwoClusters = 4. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
329 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
330 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
331 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
332 Bool_t foundOneCluster = kFALSE;
333 Bool_t foundTwoClusters = kFALSE;
334 AliMUONTrack *newTrack = 0x0;
335 AliMUONVCluster *clusterCh1, *clusterCh2;
336 AliMUONTrackParam extrapTrackParam;
337 AliMUONTrackParam extrapTrackParamAtCluster1;
338 AliMUONTrackParam extrapTrackParamAtCluster2;
339 AliMUONTrackParam bestTrackParamAtCluster1;
340 AliMUONTrackParam bestTrackParamAtCluster2;
342 Int_t nClusters = clusterStore.GetSize();
343 Bool_t *clusterCh1Used = new Bool_t[nClusters];
344 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
347 // Get track parameters
348 AliMUONTrackParam extrapTrackParamAtCh(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First());
351 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
353 // Add MCS in the missing chamber if any (only 1 chamber can be missing according to tracking criteria)
354 if (ch1 < ch2 && extrapTrackParamAtCh.GetClusterPtr()->GetChamberId() > ch2 + 1) {
355 // extrapolation to the missing chamber
356 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2 + 1));
358 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
361 //Extrapolate trackCandidate to chamber "ch2"
362 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2));
364 // Printout for debuging
365 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
366 cout<<endl<<"Track parameter covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
367 extrapTrackParamAtCh.GetCovariances().Print();
370 // Printout for debuging
371 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
372 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
375 // Create iterators to loop over clusters in both chambers
376 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
377 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
379 // look for candidates in chamber 2
380 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
382 // try to add the current cluster fast
383 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
385 // try to add the current cluster accuratly
386 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
388 // if good chi2 then try to attach a cluster in the other chamber too
389 if (chi2WithOneCluster < maxChi2WithOneCluster) {
390 Bool_t foundSecondCluster = kFALSE;
392 // Printout for debuging
393 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
394 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
395 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
396 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
399 // add MCS effect for next step
400 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
402 // copy new track parameters for next step
403 extrapTrackParam = extrapTrackParamAtCluster2;
405 //Extrapolate track parameters to chamber "ch1"
406 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
408 // reset cluster iterator of chamber 1
412 // look for second candidates in chamber 1
413 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
416 // try to add the current cluster fast
417 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
419 // try to add the current cluster accuratly
420 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
422 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
423 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
424 foundSecondCluster = kTRUE;
425 foundTwoClusters = kTRUE;
427 // Printout for debuging
428 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
429 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
430 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
433 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
434 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
435 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
436 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
439 // Tag clusterCh1 as used
440 clusterCh1Used[iCluster1] = kTRUE;
442 // Printout for debuging
443 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
444 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
445 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
448 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
449 // keep track of the best couple of clusters
450 bestChi2WithTwoClusters = chi2WithTwoClusters;
451 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
452 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
459 // if no clusterCh1 found then consider to add clusterCh2 only
460 if (!foundSecondCluster) {
461 foundOneCluster = kTRUE;
463 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
464 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
465 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
466 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
469 // Printout for debuging
470 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
471 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
472 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
475 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
476 // keep track of the best single cluster except if a couple of clusters has already been found
477 bestChi2WithOneCluster = chi2WithOneCluster;
478 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
487 // look for candidates in chamber 1 not already attached to a track
488 // if we want to keep all possible tracks or if no good couple of clusters has been found
489 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
491 // Printout for debuging
492 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
493 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
496 // add MCS effect for next step
497 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
499 //Extrapolate trackCandidate to chamber "ch1"
500 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
502 // reset cluster iterator of chamber 1
506 // look for second candidates in chamber 1
507 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
510 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
512 // try to add the current cluster fast
513 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
515 // try to add the current cluster accuratly
516 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
518 // if good chi2 then consider to add clusterCh1
519 // We do not try to attach a cluster in the other chamber too since it has already been done above
520 if (chi2WithOneCluster < maxChi2WithOneCluster) {
521 foundOneCluster = kTRUE;
523 // Printout for debuging
524 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
525 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
526 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
529 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
530 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
531 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
532 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
535 // Printout for debuging
536 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
537 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
538 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
541 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
542 // keep track of the best single cluster except if a couple of clusters has already been found
543 bestChi2WithOneCluster = chi2WithOneCluster;
544 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
553 // fill out the best track if required else clean up the fRecTracksPtr array
554 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
555 if (foundTwoClusters) {
556 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
558 // Printout for debuging
559 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
560 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
561 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
564 } else if (foundOneCluster) {
565 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
567 // Printout for debuging
568 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
569 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
570 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
574 delete [] clusterCh1Used;
578 } else if (foundOneCluster || foundTwoClusters) {
580 // remove obsolete track
581 fRecTracksPtr->Remove(&trackCandidate);
585 delete [] clusterCh1Used;
589 delete [] clusterCh1Used;
594 //__________________________________________________________________________
595 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
596 AliMUONTrackParam &trackParamAtCluster2)
598 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
599 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
600 /// return trackParamAtCluster1 & 2
602 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
603 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
604 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
605 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
607 // set pointer to cluster2 into trackParamAtCluster2
608 trackParamAtCluster2.SetClusterPtr(cluster2);
610 // Set differences between track and the 2 clusters in the bending and non bending directions
611 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
613 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
614 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
615 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
616 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
618 // Calculate the error matrix from the track parameter covariances at first cluster
621 if (trackParamAtCluster1.CovariancesExist()) {
622 // Save track parameters at first cluster
623 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
625 // Save track coordinates at second cluster
626 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
627 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
629 // copy track parameters at first cluster for jacobian calculation
630 AliMUONTrackParam trackParam(trackParamAtCluster1);
632 // add MCS effect to the covariance matrix at first cluster
633 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
635 // Get the pointer to the parameter covariance matrix at first cluster
636 const TMatrixD& kParamCov = trackParam.GetCovariances();
638 // Calculate the jacobian related to the transformation between track parameters
639 // at first cluster and track coordinates at the 2 cluster z-positions
642 // first derivative at the first cluster:
643 jacob(0,0) = 1.; // dx1/dx
644 jacob(1,2) = 1.; // dy1/dy
645 // first derivative at the second cluster:
646 TMatrixD dParam(5,1);
647 for (Int_t i=0; i<5; i++) {
648 // Skip jacobian calculation for parameters with no associated error
649 if (kParamCov(i,i) == 0.) continue;
650 // Small variation of parameter i only
651 for (Int_t j=0; j<5; j++) {
653 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
654 if (j == 4) dParam(j,0) *= TMath::Sign(1.,-paramAtCluster1Save(4,0)); // variation always in the same direction
655 } else dParam(j,0) = 0.;
658 // Set new track parameters at first cluster
659 trackParam.SetParameters(paramAtCluster1Save);
660 trackParam.AddParameters(dParam);
661 trackParam.SetZ(cluster1->GetZ());
663 // Extrapolate new track parameters to the z position of the second cluster
664 AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ());
666 // Calculate the jacobian
667 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
668 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
671 // Calculate the error matrix
672 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
673 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
676 // Add cluster resolution to the error matrix
677 error(0,0) += cluster1->GetErrX2();
678 error(1,1) += cluster1->GetErrY2();
679 error(2,2) += cluster2->GetErrX2();
680 error(3,3) += cluster2->GetErrY2();
682 // invert the error matrix for Chi2 calculation
683 if (error.Determinant() != 0) {
686 AliWarning(" Determinant error=0");
690 // Compute the Chi2 value
691 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
692 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
698 //__________________________________________________________________________
699 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
701 /// Add 1 cluster to the track candidate
702 /// Update chi2 of the track
704 // Compute local chi2
705 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
706 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
707 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
708 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
709 deltaY*deltaY / cluster->GetErrY2();
711 // Flag cluster as being not removable
712 trackParamAtCluster.SetRemovable(kFALSE);
713 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
715 // Update the chi2 of the new track
716 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
718 // Update TrackParamAtCluster
719 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
720 track.GetTrackParamAtCluster()->Sort();
724 //__________________________________________________________________________
725 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
727 /// Add 2 clusters to the track candidate
728 /// Update track and local chi2
730 // Update local chi2 at first cluster
731 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
732 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
733 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
734 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
735 deltaY*deltaY / cluster1->GetErrY2();
736 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
738 // Flag first cluster as being removable
739 trackParamAtCluster1.SetRemovable(kTRUE);
741 // Update local chi2 at second cluster
742 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
743 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
744 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
745 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
746 deltaY*deltaY / cluster2->GetErrY2();
747 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
749 // Flag first cluster as being removable
750 trackParamAtCluster2.SetRemovable(kTRUE);
752 // Update the chi2 of the new track
753 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
755 // Update TrackParamAtCluster
756 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
757 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
758 track.GetTrackParamAtCluster()->Sort();
762 //__________________________________________________________________________
763 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore, Int_t nextStation)
765 /// Try to recover the track candidate in the next station
766 /// by removing the worst of the two clusters attached in the current station
767 /// Return kTRUE if recovering succeeds
768 AliDebug(1,"Enter RecoverTrack");
770 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
771 if (nextStation > 1) return kFALSE;
773 Int_t worstClusterNumber = -1;
774 Double_t localChi2, worstLocalChi2 = 0.;
776 // Look for the cluster to remove
777 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
778 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
780 // check if current cluster is removable
781 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
783 // Pick up cluster with the worst chi2
784 localChi2 = trackParamAtCluster->GetLocalChi2();
785 if (localChi2 > worstLocalChi2) {
786 worstLocalChi2 = localChi2;
787 worstClusterNumber = clusterNumber;
791 // Reset best cluster as being NOT removable
792 ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt((worstClusterNumber+1)%2))->SetRemovable(kFALSE);
794 // Remove the worst cluster
795 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
798 // Do not take into account the multiple scattering to speed up the fit
799 // Calculate the track parameter covariance matrix
800 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
802 // Look for new cluster(s) in next station
803 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
807 //__________________________________________________________________________
808 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
810 /// Compute the vertex resolution square from natural vertex dispersion and
811 /// multiple scattering effets according to trackCandidate path in absorber
812 /// It is necessary to account for multiple scattering effects here instead of during the fit of
813 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
814 AliDebug(1,"Enter SetVertexForFit");
816 Double_t nonBendingReso2 = AliMUONReconstructor::GetRecoParam()->GetNonBendingVertexDispersion() *
817 AliMUONReconstructor::GetRecoParam()->GetNonBendingVertexDispersion();
818 Double_t bendingReso2 = AliMUONReconstructor::GetRecoParam()->GetBendingVertexDispersion() *
819 AliMUONReconstructor::GetRecoParam()->GetBendingVertexDispersion();
821 // add multiple scattering effets
822 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
823 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
824 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
825 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
826 nonBendingReso2 += kParamCov(0,0);
827 bendingReso2 += kParamCov(2,2);
829 // Set the vertex resolution square
830 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
833 //__________________________________________________________________________
834 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
837 /// w/wo multiple Coulomb scattering according to "includeMCS".
838 /// w/wo constraining the vertex according to "fitWithVertex".
839 /// calculating or not the covariance matrix according to "calcCov".
841 Double_t benC, errorParam, invBenP, nonBenC, x, y;
842 AliMUONTrackParam *trackParam;
843 Double_t arg[1], fedm, errdef, globalChi2;
845 Int_t status, covStatus;
847 // Instantiate gMinuit if not already done
848 if (!gMinuit) gMinuit = new TMinuit(6);
849 // Clear MINUIT parameters
851 // Give the fitted track to MINUIT
852 gMinuit->SetObjectFit(&track);
853 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
854 // Define print level
856 gMinuit->mnexcm("SET PRI", arg, 1, status);
857 // Print covariance matrix
858 gMinuit->mnexcm("SHO COV", arg, 0, status);
861 gMinuit->mnexcm("SET PRI", arg, 1, status);
864 gMinuit->mnexcm("SET NOW", arg, 0, status);
867 //gMinuit->mnexcm("SET STR", arg, 1, status);
869 // set flag w/wo multiple scattering according to "includeMCS"
870 track.FitWithMCS(includeMCS);
872 // compute cluster weights only once
873 if (!track.ComputeClusterWeights()) {
874 AliWarning("cannot take into account the multiple scattering effects");
875 track.FitWithMCS(kFALSE);
879 track.FitWithVertex(fitWithVertex);
880 if (fitWithVertex) SetVertexErrXY2ForFit(track);
882 // Set fitting function
883 gMinuit->SetFCN(TrackChi2);
885 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
886 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
887 // could be tried with no limits for the search (min=max=0) ????
888 // mandatory limits in non Bending to avoid NaN values of parameters
889 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
890 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -0.5, 0.5, status);
891 // mandatory limits in Bending to avoid NaN values of parameters
892 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
893 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -0.5, 0.5, status);
894 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -0.4, 0.4, status);
897 gMinuit->mnexcm("MIGRAD", arg, 0, status);
899 // Calculate the covariance matrix more accurately if required
900 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
902 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
903 gMinuit->GetParameter(0, x, errorParam);
904 trackParam->SetNonBendingCoor(x);
905 gMinuit->GetParameter(1, nonBenC, errorParam);
906 trackParam->SetNonBendingSlope(nonBenC);
907 gMinuit->GetParameter(2, y, errorParam);
908 trackParam->SetBendingCoor(y);
909 gMinuit->GetParameter(3, benC, errorParam);
910 trackParam->SetBendingSlope(benC);
911 gMinuit->GetParameter(4, invBenP, errorParam);
912 trackParam->SetInverseBendingMomentum(invBenP);
914 // global result of the fit
915 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
916 track.SetGlobalChi2(globalChi2);
918 // Get the covariance matrix if required
920 // Covariance matrix according to HESSE status
921 // If problem then keep only the diagonal terms (variances)
922 Double_t matrix[5][5];
923 gMinuit->mnemat(&matrix[0][0],5);
924 if (covStatus == 3) trackParam->SetCovariances(matrix);
925 else trackParam->SetVariances(matrix);
926 } else trackParam->DeleteCovariances();
930 //__________________________________________________________________________
931 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
933 /// Return the "Chi2" to be minimized with Minuit for track fitting.
934 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
935 /// Track parameters at each cluster are updated accordingly.
936 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
937 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
939 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
940 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
942 chi2 = 0.; // initialize chi2
944 // update track parameters
945 trackParamAtCluster->SetNonBendingCoor(param[0]);
946 trackParamAtCluster->SetNonBendingSlope(param[1]);
947 trackParamAtCluster->SetBendingCoor(param[2]);
948 trackParamAtCluster->SetBendingSlope(param[3]);
949 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
950 trackBeingFitted->UpdateTrackParamAtCluster();
952 // Take the vertex into account in the fit if required
953 if (trackBeingFitted->FitWithVertex()) {
954 Double_t nonBendingReso2,bendingReso2;
955 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
956 if (nonBendingReso2 == 0. || bendingReso2 == 0.) chi2 += 1.e10;
958 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
959 AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.); // vextex position = (0,0,0)
960 dX = paramAtVertex.GetNonBendingCoor();
961 dY = paramAtVertex.GetBendingCoor();
962 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
966 // compute chi2 w/wo multiple scattering
967 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
971 //__________________________________________________________________________
972 void AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
974 /// Complete tracks by adding missing clusters (if there is an overlap between
975 /// two detection elements, the track may have two clusters in the same chamber)
976 /// Re-fit track parameters and covariances
977 AliDebug(1,"Enter ComplementTracks");
979 Int_t chamberId, detElemId;
980 Double_t chi2OfCluster, bestChi2OfCluster;
981 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
982 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking();
983 Bool_t foundOneCluster, trackModified;
984 AliMUONVCluster* cluster;
985 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
987 // Remove double track to complete only "good" tracks
988 RemoveDoubleTracks();
990 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
992 trackModified = kFALSE;
994 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
996 foundOneCluster = kFALSE;
997 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
998 chamberId = trackParam->GetClusterPtr()->GetChamberId();
999 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1001 // prepare nextTrackParam before adding new cluster because of the sorting
1002 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1004 // recover track parameters from local fit and put them into a copy of trackParam
1005 copyOfTrackParam.SetZ(trackParam->GetZ());
1006 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1007 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1009 // Create iterators to loop over clusters in current chamber
1010 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1012 // look for one second candidate in the same chamber
1013 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1015 // look for a cluster in another detection element
1016 if (cluster->GetDetElemId() == detElemId) continue;
1018 // try to add the current cluster fast
1019 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1021 // try to add the current cluster accurately
1022 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1024 // if better chi2 then prepare to add this cluster to the track
1025 if (chi2OfCluster < bestChi2OfCluster) {
1026 bestChi2OfCluster = chi2OfCluster;
1027 bestTrackParamAtCluster = trackParamAtCluster;
1028 foundOneCluster = kTRUE;
1033 // add new cluster if any
1034 if (foundOneCluster) {
1035 UpdateTrack(*track,bestTrackParamAtCluster);
1036 bestTrackParamAtCluster.SetAloneInChamber(kFALSE);
1037 trackParam->SetAloneInChamber(kFALSE);
1038 trackModified = kTRUE;
1041 trackParam = nextTrackParam;
1044 // re-fit track parameters if needed
1045 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1047 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1052 //__________________________________________________________________________
1053 void AliMUONTrackReconstructor::ImproveTracks()
1055 /// Improve tracks by removing clusters with local chi2 highter than the defined cut
1056 /// Recompute track parameters and covariances at the remaining clusters
1057 AliDebug(1,"Enter ImproveTracks");
1059 Double_t localChi2, worstLocalChi2;
1060 Int_t worstChamber, previousChamber;
1061 AliMUONTrack *track, *nextTrack;
1062 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster, *previousTrackParam, *nextTrackParam;
1063 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement() *
1064 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement();
1066 // Remove double track to improve only "good" tracks
1067 RemoveDoubleTracks();
1069 track = (AliMUONTrack*) fRecTracksPtr->First();
1072 // prepare next track in case the actual track is suppressed
1073 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
1075 while (!track->IsImproved()) {
1077 // Update track parameters and covariances
1078 track->UpdateCovTrackParamAtCluster();
1080 // Compute local chi2 of each clusters
1081 track->ComputeLocalChi2(kTRUE);
1083 // Look for the cluster to remove
1084 worstTrackParamAtCluster = NULL;
1085 worstLocalChi2 = 0.;
1086 trackParamAtCluster = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
1087 while (trackParamAtCluster) {
1089 // Pick up cluster with the worst chi2
1090 localChi2 = trackParamAtCluster->GetLocalChi2();
1091 if (localChi2 > worstLocalChi2) {
1092 worstLocalChi2 = localChi2;
1093 worstTrackParamAtCluster = trackParamAtCluster;
1096 trackParamAtCluster = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParamAtCluster);
1099 // Check if bad cluster found
1100 if (!worstTrackParamAtCluster) {
1101 track->SetImproved(kTRUE);
1105 // Check whether the worst chi2 is under requirement or not
1106 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1107 track->SetImproved(kTRUE);
1111 // if the worst cluster is not removable then remove the entire track
1112 if (!worstTrackParamAtCluster->IsRemovable() && worstTrackParamAtCluster->IsAloneInChamber()) {
1113 fRecTracksPtr->Remove(track);
1118 // Reset the second cluster in the same station as being not removable
1119 // or reset the second cluster in the same chamber as being alone
1120 worstChamber = worstTrackParamAtCluster->GetClusterPtr()->GetChamberId();
1121 previousTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->Before(worstTrackParamAtCluster);
1122 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(worstTrackParamAtCluster);
1123 if (worstTrackParamAtCluster->IsAloneInChamber()) { // Worst cluster removable and alone in chamber
1125 if (worstChamber%2 == 0) { // Modify flags in next chamber
1127 nextTrackParam->SetRemovable(kFALSE);
1128 if (!nextTrackParam->IsAloneInChamber()) // Make sure both clusters in second chamber are not removable anymore
1129 ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(nextTrackParam))->SetRemovable(kFALSE);
1131 } else { // Modify flags in previous chamber
1133 previousTrackParam->SetRemovable(kFALSE);
1134 if (!previousTrackParam->IsAloneInChamber()) // Make sure both clusters in second chamber are not removable anymore
1135 ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->Before(previousTrackParam))->SetRemovable(kFALSE);
1139 } else { // Worst cluster not alone in its chamber
1141 if (previousTrackParam) previousChamber = previousTrackParam->GetClusterPtr()->GetChamberId();
1142 else previousChamber = -1;
1144 if (previousChamber == worstChamber) { // the second cluster on the same chamber is the previous one
1146 previousTrackParam->SetAloneInChamber(kTRUE);
1147 // transfert the removability to the second cluster
1148 if (worstTrackParamAtCluster->IsRemovable()) previousTrackParam->SetRemovable(kTRUE);
1150 } else { // the second cluster on the same chamber is the next one
1152 nextTrackParam->SetAloneInChamber(kTRUE);
1153 // transfert the removability to the second cluster
1154 if (worstTrackParamAtCluster->IsRemovable()) nextTrackParam->SetRemovable(kTRUE);
1160 // Remove the worst cluster
1161 track->RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1163 // Re-fit the track:
1164 // Take into account the multiple scattering
1165 // Calculate the track parameter covariance matrix
1166 Fit(*track, kTRUE, kFALSE, kTRUE);
1168 // Printout for debuging
1169 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1170 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(track)+1 << " improved " << endl;
1178 // compress the array in case of some tracks have been removed
1179 fRecTracksPtr->Compress();
1183 //__________________________________________________________________________
1184 void AliMUONTrackReconstructor::Finalize()
1186 /// Recompute track parameters and covariances at each attached cluster from those at the first one
1188 AliMUONTrack *track;
1190 track = (AliMUONTrack*) fRecTracksPtr->First();
1193 // update track parameters if not already done
1194 if (!track->IsImproved()) track->UpdateCovTrackParamAtCluster();
1196 track = (AliMUONTrack*) fRecTracksPtr->After(track);