]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVTrackReconstructor.cxx
Removal of calls to static AliMUONReconstructor::GetRecoParam(). Thanks to Laurent...
[u/mrichter/AliRoot.git] / MUON / AliMUONVTrackReconstructor.cxx
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
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONVTrackReconstructor
20 /// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
21 ///
22 /// This class contains as data a pointer to the array of reconstructed tracks
23 ///
24 /// It contains as methods, among others:
25 /// * EventReconstruct to build the muon tracks
26 /// * EventReconstructTrigger to build the trigger tracks
27 /// * ValidateTracksWithTrigger to match tracker/trigger tracks
28 ///
29 /// Several options and adjustable parameters are available for both KALMAN and ORIGINAL
30 /// tracking algorithms. They can be changed by using:
31 /// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
32 /// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
33 /// AliMUONReconstructor::SetRecoParam(muonRecoParam);
34 ///
35 /// Main parameters and options are:
36 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
37 ///   attached to the track candidate and to select good tracks.
38 /// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
39 ///   are made assuming linear propagation between stations 4 and 5.
40 /// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
41 ///   new clusters pass the quality cut, either we consider all the possibilities
42 ///   (duplicating tracks) or we attach only the best cluster.
43 /// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
44 ///   lost during the tracking by removing the worst of the 2 clusters attached in the
45 ///   previous station.
46 /// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
47 ///   of the tracks at the end of the tracking by removing clusters that do not pass
48 ///   new quality cut (the track is removed is it does not contain enough cluster anymore).
49 /// - *fgkComplementTracks* : if this flag is set to 'true', we try to improve the quality
50 ///   of the tracks at the end of the tracking by adding potentially missing clusters
51 ///   (we may have 2 clusters in the same chamber because of the overlapping of detection
52 ///   elements, which is not handle by the tracking algorithm).
53 /// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
54 ///   quality of the tracks.
55 ///
56 ///  \author Philippe Pillot
57 //-----------------------------------------------------------------------------
58
59 #include "AliMUONVTrackReconstructor.h"
60
61 #include "AliMUONConstants.h"
62 #include "AliMUONObjectPair.h"
63 #include "AliMUONTriggerTrack.h"
64 #include "AliMUONTriggerCircuit.h"
65 #include "AliMUONLocalTrigger.h"
66 #include "AliMUONGlobalTrigger.h"
67 #include "AliMUONTrack.h"
68 #include "AliMUONTrackParam.h"
69 #include "AliMUONTrackExtrap.h"
70 #include "AliMUONTrackHitPattern.h"
71 #include "AliMUONVTrackStore.h"
72 #include "AliMUONVClusterStore.h"
73 #include "AliMUONVCluster.h"
74 #include "AliMUONVClusterServer.h"
75 #include "AliMUONVTriggerStore.h"
76 #include "AliMUONVTriggerTrackStore.h"
77 #include "AliMpDEManager.h"
78 #include "AliMpArea.h"
79
80 #include "AliLog.h"
81 #include "AliCodeTimer.h"
82 #include "AliTracker.h"
83
84 #include <TClonesArray.h>
85 #include <TMath.h>
86 #include <TMatrixD.h>
87 #include <TVector2.h>
88
89 #include <Riostream.h>
90
91 /// \cond CLASSIMP
92 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
93 /// \endcond
94
95   //__________________________________________________________________________
96 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(const AliMUONRecoParam* recoParam,
97                                                        AliMUONVClusterServer* clusterServer)
98 : TObject(),
99 fRecTracksPtr(0x0),
100 fNRecTracks(0),
101 fClusterServer(clusterServer),
102 fRecoParam(recoParam)
103 {
104   /// Constructor for class AliMUONVTrackReconstructor
105   /// WARNING: if clusterServer=0x0, no clusterization will be possible at this level
106   
107   // Memory allocation for the TClonesArray of reconstructed tracks
108   fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
109   
110   // set the magnetic field for track extrapolations
111   const AliMagF* kField = AliTracker::GetFieldMap();
112   if (!kField) AliFatal("No field available");
113   AliMUONTrackExtrap::SetField(kField);
114 }
115
116   //__________________________________________________________________________
117 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
118 {
119   /// Destructor for class AliMUONVTrackReconstructor
120   delete fRecTracksPtr;
121 }
122
123   //__________________________________________________________________________
124 void AliMUONVTrackReconstructor::ResetTracks()
125 {
126   /// To reset the TClonesArray of reconstructed tracks
127   if (fRecTracksPtr) fRecTracksPtr->Clear("C");
128   fNRecTracks = 0;
129   return;
130 }
131
132   //__________________________________________________________________________
133 void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
134 {
135   /// To reconstruct one event
136   AliDebug(1,"");
137   AliCodeTimerAuto("");
138   
139   // Reset array of tracks
140   ResetTracks();
141   
142   // Look for candidates from clusters in stations(1..) 4 and 5
143   MakeTrackCandidates(clusterStore);
144   
145   // Look for extra candidates from clusters in stations(1..) 4 and 5
146   if (GetRecoParam()->MakeMoreTrackCandidates()) MakeMoreTrackCandidates(clusterStore);
147   
148   // Stop tracking if no candidate found
149   if (fRecTracksPtr->GetEntriesFast() == 0) return;
150   
151   // Follow tracks in stations(1..) 3, 2 and 1
152   FollowTracks(clusterStore);
153   
154   // Complement the reconstructed tracks
155   if (GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
156   
157   // Improve the reconstructed tracks
158   if (GetRecoParam()->ImproveTracks()) ImproveTracks();
159   
160   // Remove double tracks
161   RemoveDoubleTracks();
162   
163   // Fill AliMUONTrack data members
164   Finalize();
165   
166   // Add tracks to MUON data container 
167   for (Int_t i=0; i<fNRecTracks; ++i) 
168   {
169     AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
170     track->SetUniqueID(i+1);
171     trackStore.Add(*track);
172   }
173 }
174
175   //__________________________________________________________________________
176 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliMUONVClusterStore& clusterStore, Int_t ch1, Int_t ch2)
177 {
178   /// To make the list of segments from the list of clusters in the 2 given chambers.
179   /// Return a new TClonesArray of segments.
180   /// It is the responsibility of the user to delete it afterward.
181   AliDebug(1,Form("Enter MakeSegmentsBetweenChambers (1..) %d-%d", ch1+1, ch2+1));
182   
183   AliMUONVCluster *cluster1, *cluster2;
184   AliMUONObjectPair *segment;
185   Double_t nonBendingSlope = 0, bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
186   
187   // Create iterators to loop over clusters in both chambers
188   TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
189   TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
190   
191   // list of segments
192   TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
193   
194   // Loop over clusters in the first chamber of the station
195   while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
196     
197     // reset cluster iterator of chamber 2
198     nextInCh2.Reset();
199     
200     // Loop over clusters in the second chamber of the station
201     while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
202       
203       // non bending slope
204       nonBendingSlope = (cluster1->GetX() - cluster2->GetX()) / (cluster1->GetZ() - cluster2->GetZ());
205       
206       // check if non bending slope is within tolerances
207       if (TMath::Abs(nonBendingSlope) > GetRecoParam()->GetMaxNonBendingSlope()) continue;
208       
209       // bending slope
210       bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
211       
212       // check the bending momentum of the bending slope depending if the field is ON or OFF
213       if (AliMUONTrackExtrap::IsFieldON()) {
214         
215         // impact parameter
216         impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
217         
218         // absolute value of bending momentum
219         bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
220         
221         // check if bending momentum is within tolerances
222         if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
223             bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue;
224         
225       } else {
226         
227         // check if non bending slope is within tolerances
228         if (TMath::Abs(bendingSlope) > GetRecoParam()->GetMaxBendingSlope()) continue;
229       
230       }
231       // make new segment
232       segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
233       
234       // Printout for debug
235       if (AliLog::GetGlobalDebugLevel() > 1) {
236         cout << "segmentIndex(0...): " << segments->GetLast() << endl;
237         segment->Dump();
238         cout << "Cluster in first chamber" << endl;
239         cluster1->Print();
240         cout << "Cluster in second chamber" << endl;
241         cluster2->Print();
242       }
243       
244     }
245     
246   }
247   
248   // Printout for debug
249   AliDebug(1,Form("chambers%d-%d: NSegments =  %d ", ch1+1, ch2+1, segments->GetEntriesFast()));
250   
251   return segments;
252 }
253
254   //__________________________________________________________________________
255 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
256 {
257   /// To remove identical tracks:
258   /// Tracks are considered identical if they have all their clusters in common.
259   /// One keeps the track with the larger number of clusters if need be
260   AliMUONTrack *track1, *track2, *trackToRemove;
261   Int_t clustersInCommon, nClusters1, nClusters2;
262   Bool_t removedTrack1;
263   // Loop over first track of the pair
264   track1 = (AliMUONTrack*) fRecTracksPtr->First();
265   while (track1) {
266     removedTrack1 = kFALSE;
267     nClusters1 = track1->GetNClusters();
268     // Loop over second track of the pair
269     track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
270     while (track2) {
271       nClusters2 = track2->GetNClusters();
272       // number of clusters in common between two tracks
273       clustersInCommon = track1->ClustersInCommon(track2);
274       // check for identical tracks
275       if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
276         // decide which track to remove
277         if (nClusters2 > nClusters1) {
278           // remove track1 and continue the first loop with the track next to track1
279           trackToRemove = track1;
280           track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
281           fRecTracksPtr->Remove(trackToRemove);
282           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
283           fNRecTracks--;
284           removedTrack1 = kTRUE;
285           break;
286         } else {
287           // remove track2 and continue the second loop with the track next to track2
288           trackToRemove = track2;
289           track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
290           fRecTracksPtr->Remove(trackToRemove);
291           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
292           fNRecTracks--;
293         }
294       } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
295     } // track2
296     if (removedTrack1) continue;
297     track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
298   } // track1
299   return;
300 }
301
302   //__________________________________________________________________________
303 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
304 {
305   /// To remove double tracks:
306   /// Tracks are considered identical if more than half of the clusters of the track
307   /// which has the smaller number of clusters are in common with the other track.
308   /// Among two identical tracks, one keeps the track with the larger number of clusters
309   /// or, if these numbers are equal, the track with the minimum chi2.
310   AliMUONTrack *track1, *track2, *trackToRemove;
311   Int_t clustersInCommon, nClusters1, nClusters2;
312   Bool_t removedTrack1;
313   // Loop over first track of the pair
314   track1 = (AliMUONTrack*) fRecTracksPtr->First();
315   while (track1) {
316     removedTrack1 = kFALSE;
317     nClusters1 = track1->GetNClusters();
318     // Loop over second track of the pair
319     track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
320     while (track2) {
321       nClusters2 = track2->GetNClusters();
322       // number of clusters in common between two tracks
323       clustersInCommon = track1->ClustersInCommon(track2);
324       // check for identical tracks
325       if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
326         // decide which track to remove
327         if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
328           // remove track2 and continue the second loop with the track next to track2
329           trackToRemove = track2;
330           track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
331           fRecTracksPtr->Remove(trackToRemove);
332           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
333           fNRecTracks--;
334         } else {
335           // else remove track1 and continue the first loop with the track next to track1
336           trackToRemove = track1;
337           track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
338           fRecTracksPtr->Remove(trackToRemove);
339           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
340           fNRecTracks--;
341           removedTrack1 = kTRUE;
342           break;
343         }
344       } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
345     } // track2
346     if (removedTrack1) continue;
347     track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
348   } // track1
349   return;
350 }
351
352   //__________________________________________________________________________
353 void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackParam &trackParam,
354                                                             AliMUONVClusterStore& clusterStore, Int_t chamber)
355 {
356   /// Ask the clustering to reconstruct new clusters around the track candidate position
357   
358   // check if the current chamber is useable
359   if (!fClusterServer || !GetRecoParam()->UseChamber(chamber)) return;
360   
361   // maximum distance between the center of the chamber and a detection element
362   // (accounting for the inclination of the chamber)
363   static const Double_t kMaxDZ = 15.; // 15 cm
364   
365   // extrapolate track parameters to the chamber
366   AliMUONTrackParam extrapTrackParam(trackParam);
367   AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(chamber));
368   
369   // build the searching area using the track resolution and the maximum-distance-to-track value
370   const TMatrixD& kParamCov = extrapTrackParam.GetCovariances();
371   Double_t errX2 = kParamCov(0,0) + kMaxDZ * kMaxDZ * kParamCov(1,1) + 2. * kMaxDZ * TMath::Abs(kParamCov(0,1));
372   Double_t errY2 = kParamCov(2,2) + kMaxDZ * kMaxDZ * kParamCov(3,3) + 2. * kMaxDZ * TMath::Abs(kParamCov(2,3));
373   Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * kMaxDZ +
374                 GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
375                 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2);
376   Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * kMaxDZ +
377                 GetRecoParam()->GetMaxBendingDistanceToTrack() +
378                 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2);
379   TVector2 dimensions(dX, dY);
380   TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
381   AliMpArea area(position, dimensions);
382   
383   // ask to cluterize in the given area of the given chamber
384   fClusterServer->Clusterize(chamber, clusterStore, area);
385   
386 }
387
388   //__________________________________________________________________________
389 void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
390                                                             AliMUONVClusterStore& clusterStore, Int_t station)
391 {
392   /// Ask the clustering to reconstruct new clusters around the track candidate position
393   /// in the 2 chambers of the given station
394   AskForNewClustersInChamber(trackParam, clusterStore, 2*station+1);
395   AskForNewClustersInChamber(trackParam, clusterStore, 2*station);
396 }
397
398   //__________________________________________________________________________
399 Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
400                                                    AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
401 {
402 /// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
403 /// return the corresponding Chi2
404 /// return trackParamAtCluster
405   
406   // extrapolate track parameters and covariances at the z position of the tested cluster
407   trackParamAtCluster = trackParam;
408   AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator);
409   
410   // set pointer to cluster into trackParamAtCluster
411   trackParamAtCluster.SetClusterPtr(cluster);
412   
413   // Set differences between trackParam and cluster in the bending and non bending directions
414   Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
415   Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
416   
417   // Calculate errors and covariances
418   const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
419   Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
420   Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
421   
422   // Compute chi2
423   return dX * dX / sigmaX2 + dY * dY / sigmaY2;
424   
425 }
426
427   //__________________________________________________________________________
428 Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster)
429 {
430 /// Test the compatibility between the track and the cluster
431 /// given the track resolution + the maximum-distance-to-track value
432 /// and assuming linear propagation of the track:
433 /// return kTRUE if they are compatibles
434   
435   Double_t dZ = cluster->GetZ() - trackParam.GetZ();
436   Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
437   Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
438   const TMatrixD& kParamCov = trackParam.GetCovariances();
439   Double_t errX2 = kParamCov(0,0) + dZ * dZ * kParamCov(1,1) + 2. * dZ * kParamCov(0,1);
440   Double_t errY2 = kParamCov(2,2) + dZ * dZ * kParamCov(3,3) + 2. * dZ * kParamCov(2,3);
441
442   Double_t dXmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2) +
443                    GetRecoParam()->GetMaxNonBendingDistanceToTrack();
444   Double_t dYmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2) +
445                    GetRecoParam()->GetMaxBendingDistanceToTrack();
446   
447   if (TMath::Abs(dX) > dXmax || TMath::Abs(dY) > dYmax) return kFALSE;
448   
449   return kTRUE;
450   
451 }
452
453   //__________________________________________________________________________
454 Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
455                                                         AliMUONTrackParam &trackParamAtCluster2)
456 {
457 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
458 /// assuming linear propagation between the two clusters:
459 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
460 /// return trackParamAtCluster2
461   
462   // extrapolate linearly track parameters and covariances at the z position of the second cluster
463   trackParamAtCluster2 = trackParamAtCluster1;
464   AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
465   
466   // set pointer to cluster2 into trackParamAtCluster2
467   trackParamAtCluster2.SetClusterPtr(cluster2);
468   
469   // Set differences between track and clusters in the bending and non bending directions
470   AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
471   Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
472   Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
473   Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
474   Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
475   
476   // Calculate errors and covariances
477   const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
478   const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
479   Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
480   Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
481   Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
482   Double_t covX1X2  = kParamCov1(0,0) + dZ * kParamCov1(0,1);
483   Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
484   Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
485   Double_t covY1Y2  = kParamCov1(2,2) + dZ * kParamCov1(2,3);
486   
487   // Compute chi2
488   Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
489   Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
490   if (detX == 0. || detY == 0.) return 1.e10;
491   return   (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
492          + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
493   
494 }
495
496   //__________________________________________________________________________
497 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
498                                                               Int_t nextChamber)
499 {
500   /// Follow trackCandidate in chamber(0..) nextChamber assuming linear propagation, and search for compatible cluster(s)
501   /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
502   /// kTRUE:  duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
503   ///         fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
504   ///         Remove the obsolete "trackCandidate" at the end.
505   /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
506   /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
507   AliDebug(1,Form("Enter FollowLinearTrackInChamber(1..) %d", nextChamber+1));
508   
509   Double_t chi2WithOneCluster = 1.e10;
510   Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
511                                         GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
512   Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
513   Bool_t foundOneCluster = kFALSE;
514   AliMUONTrack *newTrack = 0x0;
515   AliMUONVCluster *cluster;
516   AliMUONTrackParam trackParam;
517   AliMUONTrackParam extrapTrackParamAtCluster;
518   AliMUONTrackParam bestTrackParamAtCluster;
519   
520   // Get track parameters according to the propagation direction
521   if (nextChamber > 7) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
522   else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
523   
524   // Printout for debuging
525   if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
526     cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
527     trackParam.GetParameters().Print();
528     trackParam.GetCovariances().Print();
529   }
530   
531   // Add MCS effect
532   AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
533   
534   // Printout for debuging
535   if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
536     cout << "FollowLinearTrackInChamber: look for cluster in chamber(1..): " << nextChamber+1 << endl;
537   }
538   
539   // Create iterators to loop over clusters in chamber
540   TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
541   
542   // look for candidates in chamber
543   while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
544     
545     // try to add the current cluster fast
546     if (!TryOneClusterFast(trackParam, cluster)) continue;
547     
548     // try to add the current cluster accuratly
549     extrapTrackParamAtCluster = trackParam;
550     AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster, cluster->GetZ());
551     chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster, cluster, extrapTrackParamAtCluster);
552     
553     // if good chi2 then consider to add cluster
554     if (chi2WithOneCluster < maxChi2WithOneCluster) {
555       foundOneCluster = kTRUE;
556       
557       // Printout for debuging
558       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
559         cout << "FollowLinearTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
560         << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
561         cluster->Print();
562       }
563       
564       if (GetRecoParam()->TrackAllTracks()) {
565         // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
566         newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
567         if (GetRecoParam()->RequestStation(nextChamber/2))
568           extrapTrackParamAtCluster.SetRemovable(kFALSE);
569         else extrapTrackParamAtCluster.SetRemovable(kTRUE);
570         newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster,*cluster);
571         fNRecTracks++;
572         
573         // Printout for debuging
574         if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
575           cout << "FollowLinearTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
576           if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
577         }
578         
579       } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
580         // keep track of the best cluster
581         bestChi2WithOneCluster = chi2WithOneCluster;
582         bestTrackParamAtCluster = extrapTrackParamAtCluster;
583       }
584       
585     }
586     
587   }
588   
589   // fill out the best track if required else clean up the fRecTracksPtr array
590   if (!GetRecoParam()->TrackAllTracks()) {
591     if (foundOneCluster) {
592       if (GetRecoParam()->RequestStation(nextChamber/2))
593         bestTrackParamAtCluster.SetRemovable(kFALSE);
594       else bestTrackParamAtCluster.SetRemovable(kTRUE);
595       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
596       
597       // Printout for debuging
598       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
599         cout << "FollowLinearTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
600         if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
601       }
602       
603     } else return kFALSE;
604     
605   } else if (foundOneCluster) {
606     
607     // remove obsolete track
608     fRecTracksPtr->Remove(&trackCandidate);
609     fNRecTracks--;
610     
611   } else return kFALSE;
612   
613   return kTRUE;
614   
615 }
616
617 //__________________________________________________________________________
618 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
619                                                               Int_t nextStation)
620 {
621   /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
622   /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
623   /// kTRUE:  duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
624   ///         fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
625   ///         Remove the obsolete "trackCandidate" at the end.
626   /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
627   /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
628   AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
629   
630   // Order the chamber according to the propagation direction (tracking starts with chamber 2):
631   // - nextStation == station(1...) 5 => forward propagation
632   // - nextStation < station(1...) 5 => backward propagation
633   Int_t ch1, ch2;
634   if (nextStation==4) {
635     ch1 = 2*nextStation+1;
636     ch2 = 2*nextStation;
637   } else {
638     ch1 = 2*nextStation;
639     ch2 = 2*nextStation+1;
640   }
641   
642   Double_t chi2WithOneCluster = 1.e10;
643   Double_t chi2WithTwoClusters = 1.e10;
644   Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
645                                         GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
646   Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
647                                          GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
648   Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
649   Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
650   Bool_t foundOneCluster = kFALSE;
651   Bool_t foundTwoClusters = kFALSE;
652   AliMUONTrack *newTrack = 0x0;
653   AliMUONVCluster *clusterCh1, *clusterCh2;
654   AliMUONTrackParam trackParam;
655   AliMUONTrackParam extrapTrackParamAtCluster1;
656   AliMUONTrackParam extrapTrackParamAtCluster2;
657   AliMUONTrackParam bestTrackParamAtCluster1;
658   AliMUONTrackParam bestTrackParamAtCluster2;
659   
660   Int_t nClusters = clusterStore.GetSize();
661   Bool_t *clusterCh1Used = new Bool_t[nClusters];
662   for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
663   Int_t iCluster1;
664   
665   // Get track parameters according to the propagation direction
666   if (nextStation==4) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
667   else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
668   
669   // Printout for debuging
670   if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
671     cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
672     trackParam.GetParameters().Print();
673     trackParam.GetCovariances().Print();
674   }
675   
676   // Add MCS effect
677   AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
678   
679   // Printout for debuging
680   if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
681     cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
682   }
683   
684   // Create iterators to loop over clusters in both chambers
685   TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
686   TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
687   
688   // look for candidates in chamber 2
689   while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
690     
691     // try to add the current cluster fast
692     if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
693     
694     // try to add the current cluster accuratly
695     extrapTrackParamAtCluster2 = trackParam;
696     AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
697     chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
698     
699     // if good chi2 then try to attach a cluster in the other chamber too
700     if (chi2WithOneCluster < maxChi2WithOneCluster) {
701       Bool_t foundSecondCluster = kFALSE;
702       
703       // Printout for debuging
704       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
705         cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
706              << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
707         clusterCh2->Print();
708         cout << "                      look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
709       }
710       
711       // add MCS effect
712       AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
713       
714       // reset cluster iterator of chamber 1
715       nextInCh1.Reset();
716       iCluster1 = -1;
717       
718       // look for second candidates in chamber 1
719       while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
720         iCluster1++;
721         
722         // try to add the current cluster fast
723         if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
724         
725         // try to add the current cluster in addition to the one found in the previous chamber
726         chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
727         
728         // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
729         if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
730           foundSecondCluster = kTRUE;
731           foundTwoClusters = kTRUE;
732           
733           // Printout for debuging
734           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
735             cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
736                  << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
737             clusterCh1->Print();
738           }
739           
740           if (GetRecoParam()->TrackAllTracks()) {
741             // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
742             newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
743             extrapTrackParamAtCluster1.SetRemovable(kTRUE);
744             newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
745             extrapTrackParamAtCluster2.SetRemovable(kTRUE);
746             newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
747             fNRecTracks++;
748             
749             // Tag clusterCh1 as used
750             clusterCh1Used[iCluster1] = kTRUE;
751             
752             // Printout for debuging
753             if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
754               cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
755               if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
756             }
757             
758           } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
759             // keep track of the best couple of clusters
760             bestChi2WithTwoClusters = chi2WithTwoClusters;
761             bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
762             bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
763           }
764           
765         }
766         
767       }
768       
769       // if no cluster found in chamber1 then consider to add clusterCh2 only
770       if (!foundSecondCluster) {
771         foundOneCluster = kTRUE;
772         
773         if (GetRecoParam()->TrackAllTracks()) {
774           // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
775           newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
776           if (GetRecoParam()->RequestStation(nextStation))
777             extrapTrackParamAtCluster2.SetRemovable(kFALSE);
778           else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
779           newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
780           fNRecTracks++;
781           
782           // Printout for debuging
783           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
784             cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
785             if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
786           }
787           
788         } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
789           // keep track of the best cluster except if a couple of clusters has already been found
790           bestChi2WithOneCluster = chi2WithOneCluster;
791           bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
792         }
793         
794       }
795       
796     }
797     
798   }
799   
800   // look for candidates in chamber 1 not already attached to a track
801   // if we want to keep all possible tracks or if no good couple of clusters has been found
802   if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
803     
804     // Printout for debuging
805     if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
806       cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
807     }
808     
809     //Extrapolate trackCandidate to chamber "ch2"
810     AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
811     
812     // add MCS effect for next step
813     AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
814     
815     // reset cluster iterator of chamber 1
816     nextInCh1.Reset();
817     iCluster1 = -1;
818     
819     // look for second candidates in chamber 1
820     while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
821       iCluster1++;
822       
823       if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
824       
825       // try to add the current cluster fast
826       if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
827       
828       // try to add the current cluster accuratly
829       extrapTrackParamAtCluster1 = trackParam;
830       AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
831       chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
832       
833       // if good chi2 then consider to add clusterCh1
834       // We do not try to attach a cluster in the other chamber too since it has already been done above
835       if (chi2WithOneCluster < maxChi2WithOneCluster) {
836         foundOneCluster = kTRUE;
837         
838         // Printout for debuging
839         if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
840           cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
841                << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
842           clusterCh1->Print();
843         }
844         
845         if (GetRecoParam()->TrackAllTracks()) {
846           // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
847           newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
848           if (GetRecoParam()->RequestStation(nextStation))
849             extrapTrackParamAtCluster1.SetRemovable(kFALSE);
850           else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
851           newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
852           fNRecTracks++;
853           
854           // Printout for debuging
855           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
856             cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
857             if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
858           }
859           
860         } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
861           // keep track of the best cluster except if a couple of clusters has already been found
862           bestChi2WithOneCluster = chi2WithOneCluster;
863           bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
864         }
865         
866       }
867       
868     }
869     
870   }
871   
872   // fill out the best track if required else clean up the fRecTracksPtr array
873   if (!GetRecoParam()->TrackAllTracks()) {
874     if (foundTwoClusters) {
875       bestTrackParamAtCluster1.SetRemovable(kTRUE);
876       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
877       bestTrackParamAtCluster2.SetRemovable(kTRUE);
878       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
879       
880       // Printout for debuging
881       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
882         cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
883         if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
884       }
885       
886     } else if (foundOneCluster) {
887       if (GetRecoParam()->RequestStation(nextStation))
888         bestTrackParamAtCluster1.SetRemovable(kFALSE);
889       else bestTrackParamAtCluster1.SetRemovable(kTRUE);
890       trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
891       
892       // Printout for debuging
893       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
894         cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
895         if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
896       }
897       
898     } else {
899       delete [] clusterCh1Used;
900       return kFALSE;
901     }
902     
903   } else if (foundOneCluster || foundTwoClusters) {
904     
905     // remove obsolete track
906     fRecTracksPtr->Remove(&trackCandidate);
907     fNRecTracks--;
908     
909   } else {
910     delete [] clusterCh1Used;  
911     return kFALSE;
912   }
913   
914   delete [] clusterCh1Used;
915   return kTRUE;
916   
917 }
918
919 //__________________________________________________________________________
920 void AliMUONVTrackReconstructor::ImproveTracks()
921 {
922   /// Improve tracks by removing clusters with local chi2 highter than the defined cut
923   /// Recompute track parameters and covariances at the remaining clusters
924   AliDebug(1,"Enter ImproveTracks");
925   
926   AliMUONTrack *track, *nextTrack;
927   
928   track = (AliMUONTrack*) fRecTracksPtr->First();
929   while (track) {
930     
931     // prepare next track in case the actual track is suppressed
932     nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
933     
934     ImproveTrack(*track);
935     
936     // remove track if improvement failed
937     if (!track->IsImproved()) {
938       fRecTracksPtr->Remove(track);
939       fNRecTracks--;
940     }
941     
942     track = nextTrack;
943   }
944   
945   // compress the array in case of some tracks have been removed
946   fRecTracksPtr->Compress();
947   
948 }
949
950 //__________________________________________________________________________
951 void AliMUONVTrackReconstructor::Finalize()
952 {
953   /// Recompute track parameters and covariances at each attached cluster from those at the first one
954   
955   AliMUONTrack *track;
956   
957   track = (AliMUONTrack*) fRecTracksPtr->First();
958   while (track) {
959     
960     FinalizeTrack(*track);
961     
962     track = (AliMUONTrack*) fRecTracksPtr->After(track);
963     
964   }
965   
966 }
967
968 //__________________________________________________________________________
969 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
970                                                            const AliMUONVTriggerTrackStore& triggerTrackStore,
971                                                            const AliMUONVTriggerStore& triggerStore,
972                                                            const AliMUONTrackHitPattern& trackHitPattern)
973 {
974   /// Try to match track from tracking system with trigger track
975   AliCodeTimerAuto("");
976
977   trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
978 }
979
980   //__________________________________________________________________________
981 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
982                                                          const AliMUONVTriggerStore& triggerStore,
983                                                          AliMUONVTriggerTrackStore& triggerTrackStore)
984 {
985   /// To make the trigger tracks from Local Trigger
986   AliDebug(1, "");
987   AliCodeTimerAuto("");
988   
989   AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
990   
991   UChar_t gloTrigPat = 0;
992
993   if (globalTrigger)
994   {
995     gloTrigPat = globalTrigger->GetGlobalResponse();
996   }
997   
998   TIter next(triggerStore.CreateIterator());
999   AliMUONLocalTrigger* locTrg(0x0);
1000
1001   Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
1002   Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
1003       
1004   AliMUONTriggerTrack triggerTrack;
1005   
1006   while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
1007   {
1008     Bool_t xTrig=locTrg->IsTrigX();
1009     Bool_t yTrig=locTrg->IsTrigY();
1010     
1011     Int_t localBoardId = locTrg->LoCircuit();
1012     
1013     if (xTrig && yTrig) 
1014     { // make Trigger Track if trigger in X and Y
1015       
1016       Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX()); 
1017       // need first to convert deviation to [0-30] 
1018       // (see AliMUONLocalTriggerBoard::LocalTrigger)
1019       Int_t deviation = locTrg->GetDeviation(); 
1020       Int_t stripX21 = locTrg->LoStripX()+deviation+1;
1021       Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);       
1022       Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
1023       
1024       AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
1025                        locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
1026       
1027       Float_t thetax = TMath::ATan2( x11 , z11 );
1028       Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
1029       
1030       triggerTrack.SetX11(x11);
1031       triggerTrack.SetY11(y11);
1032       triggerTrack.SetThetax(thetax);
1033       triggerTrack.SetThetay(thetay);
1034       triggerTrack.SetGTPattern(gloTrigPat);
1035       triggerTrack.SetLoTrgNum(localBoardId);
1036       
1037       triggerTrackStore.Add(triggerTrack);
1038     } // board is fired 
1039   } // end of loop on Local Trigger
1040 }
1041