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 AliMUONVTrackReconstructor
20 /// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
22 /// This class contains as data a pointer to the array of reconstructed tracks
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
29 /// Several options and adjustable parameters are available for both KALMAN and ORIGINAL
30 /// tracking algorithms. They can be changed through the AliMUONRecoParam object
31 /// set in the reconstruction macro or read from the CDB
32 /// (see methods in AliMUONRecoParam.h file for details)
34 /// Main parameters and options are:
35 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
36 /// attached to the track candidate and to select good tracks.
37 /// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
38 /// are made assuming linear propagation between stations 4 and 5.
39 /// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
40 /// new clusters pass the quality cut, either we consider all the possibilities
41 /// (duplicating tracks) or we attach only the best cluster.
42 /// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
43 /// lost during the tracking by removing the worst of the 2 clusters attached in the
45 /// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
46 /// of the tracks at the end of the tracking by removing clusters that do not pass
47 /// new quality cut (the track is removed is it does not contain enough cluster anymore).
48 /// - *fgkComplementTracks* : if this flag is set to 'true', we try to improve the quality
49 /// of the tracks at the end of the tracking by adding potentially missing clusters
50 /// (we may have 2 clusters in the same chamber because of the overlapping of detection
51 /// elements, which is not handle by the tracking algorithm).
52 /// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
53 /// quality of the tracks.
55 /// \author Philippe Pillot
56 //-----------------------------------------------------------------------------
58 #include "AliMUONVTrackReconstructor.h"
60 #include "AliMUONConstants.h"
61 #include "AliMUONObjectPair.h"
62 #include "AliMUONTriggerTrack.h"
63 #include "AliMUONTriggerCircuit.h"
64 #include "AliMUONLocalTrigger.h"
65 #include "AliMUONGlobalTrigger.h"
66 #include "AliMUONTrack.h"
67 #include "AliMUONTrackParam.h"
68 #include "AliMUONTrackExtrap.h"
69 #include "AliMUONTrackHitPattern.h"
70 #include "AliMUONVTrackStore.h"
71 #include "AliMUONVClusterStore.h"
72 #include "AliMUONVCluster.h"
73 #include "AliMUONVClusterServer.h"
74 #include "AliMUONVTriggerStore.h"
75 #include "AliMUONVTriggerTrackStore.h"
76 #include "AliMpDEManager.h"
77 #include "AliMpArea.h"
80 #include "AliCodeTimer.h"
81 #include "AliTracker.h"
83 #include <TClonesArray.h>
88 #include <Riostream.h>
91 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
94 //__________________________________________________________________________
95 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(const AliMUONRecoParam* recoParam,
96 AliMUONVClusterServer* clusterServer)
100 fClusterServer(clusterServer),
101 fRecoParam(recoParam)
103 /// Constructor for class AliMUONVTrackReconstructor
104 /// WARNING: if clusterServer=0x0, no clusterization will be possible at this level
106 // Memory allocation for the TClonesArray of reconstructed tracks
107 fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
109 // set the magnetic field for track extrapolations
110 const AliMagF* kField = AliTracker::GetFieldMap();
111 if (!kField) AliFatal("No field available");
112 AliMUONTrackExtrap::SetField(kField);
115 //__________________________________________________________________________
116 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
118 /// Destructor for class AliMUONVTrackReconstructor
119 delete fRecTracksPtr;
122 //__________________________________________________________________________
123 void AliMUONVTrackReconstructor::ResetTracks()
125 /// To reset the TClonesArray of reconstructed tracks
126 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
131 //__________________________________________________________________________
132 void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
134 /// To reconstruct one event
136 AliCodeTimerAuto("");
138 // Reset array of tracks
141 // Look for candidates from clusters in stations(1..) 4 and 5
142 MakeTrackCandidates(clusterStore);
144 // Look for extra candidates from clusters in stations(1..) 4 and 5
145 if (GetRecoParam()->MakeMoreTrackCandidates()) MakeMoreTrackCandidates(clusterStore);
147 // Stop tracking if no candidate found
148 if (fRecTracksPtr->GetEntriesFast() == 0) return;
150 // Follow tracks in stations(1..) 3, 2 and 1
151 FollowTracks(clusterStore);
153 // Complement the reconstructed tracks
154 if (GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
156 // Improve the reconstructed tracks
157 if (GetRecoParam()->ImproveTracks()) ImproveTracks();
159 // Remove double tracks
160 RemoveDoubleTracks();
162 // Fill AliMUONTrack data members
165 // Add tracks to MUON data container
166 for (Int_t i=0; i<fNRecTracks; ++i)
168 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
169 track->SetUniqueID(i+1);
170 trackStore.Add(*track);
174 //__________________________________________________________________________
175 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliMUONVClusterStore& clusterStore, Int_t ch1, Int_t ch2)
177 /// To make the list of segments from the list of clusters in the 2 given chambers.
178 /// Return a new TClonesArray of segments.
179 /// It is the responsibility of the user to delete it afterward.
180 AliDebug(1,Form("Enter MakeSegmentsBetweenChambers (1..) %d-%d", ch1+1, ch2+1));
182 AliMUONVCluster *cluster1, *cluster2;
183 AliMUONObjectPair *segment;
184 Double_t nonBendingSlope = 0, bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
186 // Create iterators to loop over clusters in both chambers
187 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
188 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
191 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
193 // Loop over clusters in the first chamber of the station
194 while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
196 // reset cluster iterator of chamber 2
199 // Loop over clusters in the second chamber of the station
200 while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
203 nonBendingSlope = (cluster1->GetX() - cluster2->GetX()) / (cluster1->GetZ() - cluster2->GetZ());
205 // check if non bending slope is within tolerances
206 if (TMath::Abs(nonBendingSlope) > GetRecoParam()->GetMaxNonBendingSlope()) continue;
209 bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
211 // check the bending momentum of the bending slope depending if the field is ON or OFF
212 if (AliMUONTrackExtrap::IsFieldON()) {
215 impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
217 // absolute value of bending momentum
218 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
220 // check if bending momentum is within tolerances
221 if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
222 bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue;
226 // check if non bending slope is within tolerances
227 if (TMath::Abs(bendingSlope) > GetRecoParam()->GetMaxBendingSlope()) continue;
231 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
233 // Printout for debug
234 if (AliLog::GetGlobalDebugLevel() > 1) {
235 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
237 cout << "Cluster in first chamber" << endl;
239 cout << "Cluster in second chamber" << endl;
247 // Printout for debug
248 AliDebug(1,Form("chambers%d-%d: NSegments = %d ", ch1+1, ch2+1, segments->GetEntriesFast()));
253 //__________________________________________________________________________
254 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
256 /// To remove identical tracks:
257 /// Tracks are considered identical if they have all their clusters in common.
258 /// One keeps the track with the larger number of clusters if need be
259 AliMUONTrack *track1, *track2, *trackToRemove;
260 Int_t clustersInCommon, nClusters1, nClusters2;
261 Bool_t removedTrack1;
262 // Loop over first track of the pair
263 track1 = (AliMUONTrack*) fRecTracksPtr->First();
265 removedTrack1 = kFALSE;
266 nClusters1 = track1->GetNClusters();
267 // Loop over second track of the pair
268 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
270 nClusters2 = track2->GetNClusters();
271 // number of clusters in common between two tracks
272 clustersInCommon = track1->ClustersInCommon(track2);
273 // check for identical tracks
274 if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
275 // decide which track to remove
276 if (nClusters2 > nClusters1) {
277 // remove track1 and continue the first loop with the track next to track1
278 trackToRemove = track1;
279 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
280 fRecTracksPtr->Remove(trackToRemove);
281 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
283 removedTrack1 = kTRUE;
286 // remove track2 and continue the second loop with the track next to track2
287 trackToRemove = track2;
288 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
289 fRecTracksPtr->Remove(trackToRemove);
290 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
293 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
295 if (removedTrack1) continue;
296 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
301 //__________________________________________________________________________
302 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
304 /// To remove double tracks:
305 /// Tracks are considered identical if more than half of the clusters of the track
306 /// which has the smaller number of clusters are in common with the other track.
307 /// Among two identical tracks, one keeps the track with the larger number of clusters
308 /// or, if these numbers are equal, the track with the minimum chi2.
309 AliMUONTrack *track1, *track2, *trackToRemove;
310 Int_t clustersInCommon, nClusters1, nClusters2;
311 Bool_t removedTrack1;
312 // Loop over first track of the pair
313 track1 = (AliMUONTrack*) fRecTracksPtr->First();
315 removedTrack1 = kFALSE;
316 nClusters1 = track1->GetNClusters();
317 // Loop over second track of the pair
318 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
320 nClusters2 = track2->GetNClusters();
321 // number of clusters in common between two tracks
322 clustersInCommon = track1->ClustersInCommon(track2);
323 // check for identical tracks
324 if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
325 // decide which track to remove
326 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
327 // remove track2 and continue the second loop with the track next to track2
328 trackToRemove = track2;
329 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
330 fRecTracksPtr->Remove(trackToRemove);
331 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
334 // else remove track1 and continue the first loop with the track next to track1
335 trackToRemove = track1;
336 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
337 fRecTracksPtr->Remove(trackToRemove);
338 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
340 removedTrack1 = kTRUE;
343 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
345 if (removedTrack1) continue;
346 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
351 //__________________________________________________________________________
352 void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackParam &trackParam,
353 AliMUONVClusterStore& clusterStore, Int_t chamber)
355 /// Ask the clustering to reconstruct new clusters around the track candidate position
357 // check if the current chamber is useable
358 if (!fClusterServer || !GetRecoParam()->UseChamber(chamber)) return;
360 // maximum distance between the center of the chamber and a detection element
361 // (accounting for the inclination of the chamber)
362 static const Double_t kMaxDZ = 15.; // 15 cm
364 // extrapolate track parameters to the chamber
365 AliMUONTrackParam extrapTrackParam(trackParam);
366 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(chamber));
368 // build the searching area using the track resolution and the maximum-distance-to-track value
369 const TMatrixD& kParamCov = extrapTrackParam.GetCovariances();
370 Double_t errX2 = kParamCov(0,0) + kMaxDZ * kMaxDZ * kParamCov(1,1) + 2. * kMaxDZ * TMath::Abs(kParamCov(0,1));
371 Double_t errY2 = kParamCov(2,2) + kMaxDZ * kMaxDZ * kParamCov(3,3) + 2. * kMaxDZ * TMath::Abs(kParamCov(2,3));
372 Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * kMaxDZ +
373 GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
374 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2);
375 Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * kMaxDZ +
376 GetRecoParam()->GetMaxBendingDistanceToTrack() +
377 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2);
378 TVector2 dimensions(dX, dY);
379 TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
380 AliMpArea area(position, dimensions);
382 // ask to cluterize in the given area of the given chamber
383 fClusterServer->Clusterize(chamber, clusterStore, area, GetRecoParam());
387 //__________________________________________________________________________
388 void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
389 AliMUONVClusterStore& clusterStore, Int_t station)
391 /// Ask the clustering to reconstruct new clusters around the track candidate position
392 /// in the 2 chambers of the given station
393 AskForNewClustersInChamber(trackParam, clusterStore, 2*station+1);
394 AskForNewClustersInChamber(trackParam, clusterStore, 2*station);
397 //__________________________________________________________________________
398 Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
399 AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
401 /// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
402 /// return the corresponding Chi2
403 /// return trackParamAtCluster
405 // extrapolate track parameters and covariances at the z position of the tested cluster
406 trackParamAtCluster = trackParam;
407 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator);
409 // set pointer to cluster into trackParamAtCluster
410 trackParamAtCluster.SetClusterPtr(cluster);
412 // Set differences between trackParam and cluster in the bending and non bending directions
413 Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
414 Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
416 // Calculate errors and covariances
417 const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
418 Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
419 Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
422 return dX * dX / sigmaX2 + dY * dY / sigmaY2;
426 //__________________________________________________________________________
427 Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster)
429 /// Test the compatibility between the track and the cluster
430 /// given the track resolution + the maximum-distance-to-track value
431 /// and assuming linear propagation of the track:
432 /// return kTRUE if they are compatibles
434 Double_t dZ = cluster->GetZ() - trackParam.GetZ();
435 Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
436 Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
437 const TMatrixD& kParamCov = trackParam.GetCovariances();
438 Double_t errX2 = kParamCov(0,0) + dZ * dZ * kParamCov(1,1) + 2. * dZ * kParamCov(0,1);
439 Double_t errY2 = kParamCov(2,2) + dZ * dZ * kParamCov(3,3) + 2. * dZ * kParamCov(2,3);
441 Double_t dXmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2) +
442 GetRecoParam()->GetMaxNonBendingDistanceToTrack();
443 Double_t dYmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2) +
444 GetRecoParam()->GetMaxBendingDistanceToTrack();
446 if (TMath::Abs(dX) > dXmax || TMath::Abs(dY) > dYmax) return kFALSE;
452 //__________________________________________________________________________
453 Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
454 AliMUONTrackParam &trackParamAtCluster2)
456 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
457 /// assuming linear propagation between the two clusters:
458 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
459 /// return trackParamAtCluster2
461 // extrapolate linearly track parameters and covariances at the z position of the second cluster
462 trackParamAtCluster2 = trackParamAtCluster1;
463 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
465 // set pointer to cluster2 into trackParamAtCluster2
466 trackParamAtCluster2.SetClusterPtr(cluster2);
468 // Set differences between track and clusters in the bending and non bending directions
469 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
470 Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
471 Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
472 Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
473 Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
475 // Calculate errors and covariances
476 const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
477 const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
478 Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
479 Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
480 Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
481 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
482 Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
483 Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
484 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
487 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
488 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
489 if (detX == 0. || detY == 0.) return 1.e10;
490 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
491 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
495 //__________________________________________________________________________
496 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
499 /// Follow trackCandidate in chamber(0..) nextChamber assuming linear propagation, and search for compatible cluster(s)
500 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
501 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
502 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
503 /// Remove the obsolete "trackCandidate" at the end.
504 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
505 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
506 AliDebug(1,Form("Enter FollowLinearTrackInChamber(1..) %d", nextChamber+1));
508 Double_t chi2WithOneCluster = 1.e10;
509 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
510 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
511 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
512 Bool_t foundOneCluster = kFALSE;
513 AliMUONTrack *newTrack = 0x0;
514 AliMUONVCluster *cluster;
515 AliMUONTrackParam trackParam;
516 AliMUONTrackParam extrapTrackParamAtCluster;
517 AliMUONTrackParam bestTrackParamAtCluster;
519 // Get track parameters according to the propagation direction
520 if (nextChamber > 7) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
521 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
523 // Printout for debuging
524 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
525 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
526 trackParam.GetParameters().Print();
527 trackParam.GetCovariances().Print();
531 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
533 // Printout for debuging
534 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
535 cout << "FollowLinearTrackInChamber: look for cluster in chamber(1..): " << nextChamber+1 << endl;
538 // Create iterators to loop over clusters in chamber
539 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
541 // look for candidates in chamber
542 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
544 // try to add the current cluster fast
545 if (!TryOneClusterFast(trackParam, cluster)) continue;
547 // try to add the current cluster accuratly
548 extrapTrackParamAtCluster = trackParam;
549 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster, cluster->GetZ());
550 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster, cluster, extrapTrackParamAtCluster);
552 // if good chi2 then consider to add cluster
553 if (chi2WithOneCluster < maxChi2WithOneCluster) {
554 foundOneCluster = kTRUE;
556 // Printout for debuging
557 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
558 cout << "FollowLinearTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
559 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
563 if (GetRecoParam()->TrackAllTracks()) {
564 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
565 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
566 if (GetRecoParam()->RequestStation(nextChamber/2))
567 extrapTrackParamAtCluster.SetRemovable(kFALSE);
568 else extrapTrackParamAtCluster.SetRemovable(kTRUE);
569 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster,*cluster);
572 // Printout for debuging
573 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
574 cout << "FollowLinearTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
575 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
578 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
579 // keep track of the best cluster
580 bestChi2WithOneCluster = chi2WithOneCluster;
581 bestTrackParamAtCluster = extrapTrackParamAtCluster;
588 // fill out the best track if required else clean up the fRecTracksPtr array
589 if (!GetRecoParam()->TrackAllTracks()) {
590 if (foundOneCluster) {
591 if (GetRecoParam()->RequestStation(nextChamber/2))
592 bestTrackParamAtCluster.SetRemovable(kFALSE);
593 else bestTrackParamAtCluster.SetRemovable(kTRUE);
594 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
596 // Printout for debuging
597 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
598 cout << "FollowLinearTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
599 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
602 } else return kFALSE;
604 } else if (foundOneCluster) {
606 // remove obsolete track
607 fRecTracksPtr->Remove(&trackCandidate);
610 } else return kFALSE;
616 //__________________________________________________________________________
617 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
620 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
621 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
622 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
623 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
624 /// Remove the obsolete "trackCandidate" at the end.
625 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
626 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
627 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
629 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
630 // - nextStation == station(1...) 5 => forward propagation
631 // - nextStation < station(1...) 5 => backward propagation
633 if (nextStation==4) {
634 ch1 = 2*nextStation+1;
638 ch2 = 2*nextStation+1;
641 Double_t chi2WithOneCluster = 1.e10;
642 Double_t chi2WithTwoClusters = 1.e10;
643 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
644 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
645 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
646 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
647 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
648 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
649 Bool_t foundOneCluster = kFALSE;
650 Bool_t foundTwoClusters = kFALSE;
651 AliMUONTrack *newTrack = 0x0;
652 AliMUONVCluster *clusterCh1, *clusterCh2;
653 AliMUONTrackParam trackParam;
654 AliMUONTrackParam extrapTrackParamAtCluster1;
655 AliMUONTrackParam extrapTrackParamAtCluster2;
656 AliMUONTrackParam bestTrackParamAtCluster1;
657 AliMUONTrackParam bestTrackParamAtCluster2;
659 Int_t nClusters = clusterStore.GetSize();
660 Bool_t *clusterCh1Used = new Bool_t[nClusters];
661 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
664 // Get track parameters according to the propagation direction
665 if (nextStation==4) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
666 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
668 // Printout for debuging
669 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
670 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
671 trackParam.GetParameters().Print();
672 trackParam.GetCovariances().Print();
676 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
678 // Printout for debuging
679 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
680 cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
683 // Create iterators to loop over clusters in both chambers
684 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
685 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
687 // look for candidates in chamber 2
688 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
690 // try to add the current cluster fast
691 if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
693 // try to add the current cluster accuratly
694 extrapTrackParamAtCluster2 = trackParam;
695 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
696 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
698 // if good chi2 then try to attach a cluster in the other chamber too
699 if (chi2WithOneCluster < maxChi2WithOneCluster) {
700 Bool_t foundSecondCluster = kFALSE;
702 // Printout for debuging
703 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
704 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
705 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
707 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
711 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
713 // reset cluster iterator of chamber 1
717 // look for second candidates in chamber 1
718 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
721 // try to add the current cluster fast
722 if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
724 // try to add the current cluster in addition to the one found in the previous chamber
725 chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
727 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
728 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
729 foundSecondCluster = kTRUE;
730 foundTwoClusters = kTRUE;
732 // Printout for debuging
733 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
734 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
735 << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
739 if (GetRecoParam()->TrackAllTracks()) {
740 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
741 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
742 extrapTrackParamAtCluster1.SetRemovable(kTRUE);
743 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
744 extrapTrackParamAtCluster2.SetRemovable(kTRUE);
745 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
748 // Tag clusterCh1 as used
749 clusterCh1Used[iCluster1] = kTRUE;
751 // Printout for debuging
752 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
753 cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
754 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
757 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
758 // keep track of the best couple of clusters
759 bestChi2WithTwoClusters = chi2WithTwoClusters;
760 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
761 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
768 // if no cluster found in chamber1 then consider to add clusterCh2 only
769 if (!foundSecondCluster) {
770 foundOneCluster = kTRUE;
772 if (GetRecoParam()->TrackAllTracks()) {
773 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
774 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
775 if (GetRecoParam()->RequestStation(nextStation))
776 extrapTrackParamAtCluster2.SetRemovable(kFALSE);
777 else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
778 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
781 // Printout for debuging
782 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
783 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
784 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
787 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
788 // keep track of the best cluster except if a couple of clusters has already been found
789 bestChi2WithOneCluster = chi2WithOneCluster;
790 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
799 // look for candidates in chamber 1 not already attached to a track
800 // if we want to keep all possible tracks or if no good couple of clusters has been found
801 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
803 // Printout for debuging
804 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
805 cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
808 //Extrapolate trackCandidate to chamber "ch2"
809 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
811 // add MCS effect for next step
812 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
814 // reset cluster iterator of chamber 1
818 // look for second candidates in chamber 1
819 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
822 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
824 // try to add the current cluster fast
825 if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
827 // try to add the current cluster accuratly
828 extrapTrackParamAtCluster1 = trackParam;
829 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
830 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
832 // if good chi2 then consider to add clusterCh1
833 // We do not try to attach a cluster in the other chamber too since it has already been done above
834 if (chi2WithOneCluster < maxChi2WithOneCluster) {
835 foundOneCluster = kTRUE;
837 // Printout for debuging
838 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
839 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
840 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
844 if (GetRecoParam()->TrackAllTracks()) {
845 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
846 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
847 if (GetRecoParam()->RequestStation(nextStation))
848 extrapTrackParamAtCluster1.SetRemovable(kFALSE);
849 else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
850 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
853 // Printout for debuging
854 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
855 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
856 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
859 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
860 // keep track of the best cluster except if a couple of clusters has already been found
861 bestChi2WithOneCluster = chi2WithOneCluster;
862 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
871 // fill out the best track if required else clean up the fRecTracksPtr array
872 if (!GetRecoParam()->TrackAllTracks()) {
873 if (foundTwoClusters) {
874 bestTrackParamAtCluster1.SetRemovable(kTRUE);
875 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
876 bestTrackParamAtCluster2.SetRemovable(kTRUE);
877 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
879 // Printout for debuging
880 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
881 cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
882 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
885 } else if (foundOneCluster) {
886 if (GetRecoParam()->RequestStation(nextStation))
887 bestTrackParamAtCluster1.SetRemovable(kFALSE);
888 else bestTrackParamAtCluster1.SetRemovable(kTRUE);
889 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
891 // Printout for debuging
892 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
893 cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
894 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
898 delete [] clusterCh1Used;
902 } else if (foundOneCluster || foundTwoClusters) {
904 // remove obsolete track
905 fRecTracksPtr->Remove(&trackCandidate);
909 delete [] clusterCh1Used;
913 delete [] clusterCh1Used;
918 //__________________________________________________________________________
919 void AliMUONVTrackReconstructor::ImproveTracks()
921 /// Improve tracks by removing clusters with local chi2 highter than the defined cut
922 /// Recompute track parameters and covariances at the remaining clusters
923 AliDebug(1,"Enter ImproveTracks");
925 AliMUONTrack *track, *nextTrack;
927 track = (AliMUONTrack*) fRecTracksPtr->First();
930 // prepare next track in case the actual track is suppressed
931 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
933 ImproveTrack(*track);
935 // remove track if improvement failed
936 if (!track->IsImproved()) {
937 fRecTracksPtr->Remove(track);
944 // compress the array in case of some tracks have been removed
945 fRecTracksPtr->Compress();
949 //__________________________________________________________________________
950 void AliMUONVTrackReconstructor::Finalize()
952 /// Recompute track parameters and covariances at each attached cluster from those at the first one
956 track = (AliMUONTrack*) fRecTracksPtr->First();
959 FinalizeTrack(*track);
961 track = (AliMUONTrack*) fRecTracksPtr->After(track);
967 //__________________________________________________________________________
968 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
969 const AliMUONVTriggerTrackStore& triggerTrackStore,
970 const AliMUONVTriggerStore& triggerStore,
971 const AliMUONTrackHitPattern& trackHitPattern)
973 /// Try to match track from tracking system with trigger track
974 AliCodeTimerAuto("");
976 trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
979 //__________________________________________________________________________
980 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
981 const AliMUONVTriggerStore& triggerStore,
982 AliMUONVTriggerTrackStore& triggerTrackStore)
984 /// To make the trigger tracks from Local Trigger
986 AliCodeTimerAuto("");
988 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
990 UChar_t gloTrigPat = 0;
994 gloTrigPat = globalTrigger->GetGlobalResponse();
997 TIter next(triggerStore.CreateIterator());
998 AliMUONLocalTrigger* locTrg(0x0);
1000 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
1001 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
1003 AliMUONTriggerTrack triggerTrack;
1005 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
1007 Bool_t xTrig=locTrg->IsTrigX();
1008 Bool_t yTrig=locTrg->IsTrigY();
1010 Int_t localBoardId = locTrg->LoCircuit();
1013 { // make Trigger Track if trigger in X and Y
1015 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
1016 // need first to convert deviation to [0-30]
1017 // (see AliMUONLocalTriggerBoard::LocalTrigger)
1018 Int_t deviation = locTrg->GetDeviation();
1019 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
1020 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
1021 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
1023 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
1024 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
1026 Float_t thetax = TMath::ATan2( x11 , z11 );
1027 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
1029 triggerTrack.SetX11(x11);
1030 triggerTrack.SetY11(y11);
1031 triggerTrack.SetThetax(thetax);
1032 triggerTrack.SetThetay(thetay);
1033 triggerTrack.SetGTPattern(gloTrigPat);
1034 triggerTrack.SetLoTrgNum(localBoardId);
1036 triggerTrackStore.Add(triggerTrack);
1038 } // end of loop on Local Trigger