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 by using:
31 /// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
32 /// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
33 /// AliMUONReconstructor::SetRecoParam(muonRecoParam);
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
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.
56 /// \author Philippe Pillot
57 //-----------------------------------------------------------------------------
59 #include "AliMUONVTrackReconstructor.h"
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"
81 #include "AliCodeTimer.h"
82 #include "AliTracker.h"
84 #include <TClonesArray.h>
89 #include <Riostream.h>
92 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
95 //__________________________________________________________________________
96 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(AliMUONVClusterServer& clusterServer)
100 fClusterServer(clusterServer)
102 /// Constructor for class AliMUONVTrackReconstructor
104 // Memory allocation for the TClonesArray of reconstructed tracks
105 fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
107 // set the magnetic field for track extrapolations
108 const AliMagF* kField = AliTracker::GetFieldMap();
109 if (!kField) AliFatal("No field available");
110 AliMUONTrackExtrap::SetField(kField);
113 //__________________________________________________________________________
114 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
116 /// Destructor for class AliMUONVTrackReconstructor
117 delete fRecTracksPtr;
120 //__________________________________________________________________________
121 void AliMUONVTrackReconstructor::ResetTracks()
123 /// To reset the TClonesArray of reconstructed tracks
124 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
129 //__________________________________________________________________________
130 void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
132 /// To reconstruct one event
134 AliCodeTimerAuto("");
136 // Reset array of tracks
139 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
140 MakeTrackCandidates(clusterStore);
142 // Stop tracking if no candidate found
143 if (fRecTracksPtr->GetEntriesFast() == 0) return;
145 // Follow tracks in stations(1..) 3, 2 and 1
146 FollowTracks(clusterStore);
148 // Complement the reconstructed tracks
149 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
151 // Improve the reconstructed tracks
152 if (AliMUONReconstructor::GetRecoParam()->ImproveTracks()) ImproveTracks();
154 // Remove double tracks
155 RemoveDoubleTracks();
157 // Fill AliMUONTrack data members
160 // Add tracks to MUON data container
161 for (Int_t i=0; i<fNRecTracks; ++i)
163 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
164 trackStore.Add(*track);
168 //__________________________________________________________________________
169 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(const AliMUONVClusterStore& clusterStore, Int_t station)
171 /// To make the list of segments in station(0..) "Station" from the list of clusters to be reconstructed.
172 /// Return a new TClonesArray of segments.
173 /// It is the responsibility of the user to delete it afterward.
174 AliDebug(1,Form("Enter MakeSegmentsPerStation (1..) %d",station+1));
176 AliMUONVCluster *cluster1, *cluster2;
177 AliMUONObjectPair *segment;
178 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
179 Int_t ch1 = 2 * station;
182 // Create iterators to loop over clusters in both chambers
183 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
184 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
187 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
188 segments->SetOwner(kTRUE);
190 // Loop over clusters in the first chamber of the station
191 while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
193 // reset cluster iterator of chamber 2
196 // Loop over clusters in the second chamber of the station
197 while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
200 bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
203 impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
205 // absolute value of bending momentum
206 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
208 // check for bending momentum within tolerances
209 if ((bendingMomentum < AliMUONReconstructor::GetRecoParam()->GetMaxBendingMomentum()) &&
210 (bendingMomentum > AliMUONReconstructor::GetRecoParam()->GetMinBendingMomentum())) {
213 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
215 // Printout for debug
216 if (AliLog::GetGlobalDebugLevel() > 1) {
217 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
219 cout << "Cluster in first chamber" << endl;
221 cout << "Cluster in second chamber" << endl;
231 // Printout for debug
232 AliDebug(1,Form("Station: %d NSegments: %d ", station+1, segments->GetEntriesFast()));
237 //__________________________________________________________________________
238 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
240 /// To remove identical tracks:
241 /// Tracks are considered identical if they have all their clusters in common.
242 /// One keeps the track with the larger number of clusters if need be
243 AliMUONTrack *track1, *track2, *trackToRemove;
244 Int_t clustersInCommon, nClusters1, nClusters2;
245 Bool_t removedTrack1;
246 // Loop over first track of the pair
247 track1 = (AliMUONTrack*) fRecTracksPtr->First();
249 removedTrack1 = kFALSE;
250 nClusters1 = track1->GetNClusters();
251 // Loop over second track of the pair
252 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
254 nClusters2 = track2->GetNClusters();
255 // number of clusters in common between two tracks
256 clustersInCommon = track1->ClustersInCommon(track2);
257 // check for identical tracks
258 if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
259 // decide which track to remove
260 if (nClusters2 > nClusters1) {
261 // remove track1 and continue the first loop with the track next to track1
262 trackToRemove = track1;
263 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
264 fRecTracksPtr->Remove(trackToRemove);
265 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
267 removedTrack1 = kTRUE;
270 // remove track2 and continue the second loop with the track next to track2
271 trackToRemove = track2;
272 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
273 fRecTracksPtr->Remove(trackToRemove);
274 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
277 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
279 if (removedTrack1) continue;
280 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
285 //__________________________________________________________________________
286 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
288 /// To remove double tracks:
289 /// Tracks are considered identical if more than half of the clusters of the track
290 /// which has the smaller number of clusters are in common with the other track.
291 /// Among two identical tracks, one keeps the track with the larger number of clusters
292 /// or, if these numbers are equal, the track with the minimum chi2.
293 AliMUONTrack *track1, *track2, *trackToRemove;
294 Int_t clustersInCommon, nClusters1, nClusters2;
295 Bool_t removedTrack1;
296 // Loop over first track of the pair
297 track1 = (AliMUONTrack*) fRecTracksPtr->First();
299 removedTrack1 = kFALSE;
300 nClusters1 = track1->GetNClusters();
301 // Loop over second track of the pair
302 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
304 nClusters2 = track2->GetNClusters();
305 // number of clusters in common between two tracks
306 clustersInCommon = track1->ClustersInCommon(track2);
307 // check for identical tracks
308 if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
309 // decide which track to remove
310 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
311 // remove track2 and continue the second loop with the track next to track2
312 trackToRemove = track2;
313 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
314 fRecTracksPtr->Remove(trackToRemove);
315 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
318 // else remove track1 and continue the first loop with the track next to track1
319 trackToRemove = track1;
320 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
321 fRecTracksPtr->Remove(trackToRemove);
322 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
324 removedTrack1 = kTRUE;
327 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
329 if (removedTrack1) continue;
330 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
335 //__________________________________________________________________________
336 void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
337 AliMUONVClusterStore& clusterStore, Int_t station)
339 /// Ask the clustering to reconstruct new clusters around the track candidate position
340 /// in the 2 chambers of the given station
342 // maximum shift of the searching area due to distance between detection elements and the track slope
343 static const Double_t kgMaxShift = 2.; // 2 cm
345 // extrapolate track parameters to the second chamber of the station
346 AliMUONTrackParam extrapTrackParam(trackParam);
347 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(2*station+1));
349 // build the searching area
350 TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
351 TVector2 dimensions(AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() + kgMaxShift,
352 AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack() + kgMaxShift);
353 AliMpArea area2(position, dimensions);
355 // ask to cluterize in the given area of the given chamber
356 fClusterServer.Clusterize(2*station+1, clusterStore, area2);
358 // extrapolate track parameters to the first chamber of the station
359 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(2*station));
361 // build the searching area
362 position.Set(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
363 // dimensions.Set(AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() + kgMaxShift,
364 // AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack() + kgMaxShift);
365 AliMpArea area1(position, dimensions);
367 // ask to cluterize in the given area of the given chamber
368 fClusterServer.Clusterize(2*station, clusterStore, area1);
371 //__________________________________________________________________________
372 Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
373 AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
375 /// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
376 /// return the corresponding Chi2
377 /// return trackParamAtCluster
379 // extrapolate track parameters and covariances at the z position of the tested cluster
380 trackParamAtCluster = trackParam;
381 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator);
383 // set pointer to cluster into trackParamAtCluster
384 trackParamAtCluster.SetClusterPtr(cluster);
386 // Set differences between trackParam and cluster in the bending and non bending directions
387 Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
388 Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
390 // Calculate errors and covariances
391 const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
392 Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
393 Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
396 return dX * dX / sigmaX2 + dY * dY / sigmaY2;
400 //__________________________________________________________________________
401 Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster)
403 /// Test the compatibility between the track and the cluster within a wide fix window
404 /// assuming linear propagation of the track:
405 /// return kTRUE if they are compatibles
407 Double_t dZ = cluster->GetZ() - trackParam.GetZ();
408 Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
409 Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
411 if (TMath::Abs(dX) > AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() ||
412 TMath::Abs(dY) > AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack()) return kFALSE;
418 //__________________________________________________________________________
419 Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
420 AliMUONTrackParam &trackParamAtCluster2)
422 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
423 /// assuming linear propagation between the two clusters:
424 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
425 /// return trackParamAtCluster2
427 // extrapolate linearly track parameters and covariances at the z position of the second cluster
428 trackParamAtCluster2 = trackParamAtCluster1;
429 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
431 // set pointer to cluster2 into trackParamAtCluster2
432 trackParamAtCluster2.SetClusterPtr(cluster2);
434 // Set differences between track and clusters in the bending and non bending directions
435 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
436 Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
437 Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
438 Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
439 Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
441 // Calculate errors and covariances
442 const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
443 const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
444 Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
445 Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
446 Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
447 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
448 Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
449 Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
450 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
453 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
454 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
455 if (detX == 0. || detY == 0.) return 1.e10;
456 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
457 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
461 //__________________________________________________________________________
462 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
465 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
466 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
467 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
468 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
469 /// Remove the obsolete "trackCandidate" at the end.
470 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
471 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
472 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
474 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
475 // - nextStation == station(1...) 5 => forward propagation
476 // - nextStation < station(1...) 5 => backward propagation
478 if (nextStation==4) {
479 ch1 = 2*nextStation+1;
483 ch2 = 2*nextStation+1;
486 Double_t chi2WithOneCluster = 1.e10;
487 Double_t chi2WithTwoClusters = 1.e10;
488 Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
489 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
490 Double_t maxChi2WithTwoClusters = 4. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
491 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
492 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
493 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
494 Bool_t foundOneCluster = kFALSE;
495 Bool_t foundTwoClusters = kFALSE;
496 AliMUONTrack *newTrack = 0x0;
497 AliMUONVCluster *clusterCh1, *clusterCh2;
498 AliMUONTrackParam extrapTrackParamAtCluster1;
499 AliMUONTrackParam extrapTrackParamAtCluster2;
500 AliMUONTrackParam bestTrackParamAtCluster1;
501 AliMUONTrackParam bestTrackParamAtCluster2;
503 Int_t nClusters = clusterStore.GetSize();
504 Bool_t *clusterCh1Used = new Bool_t[nClusters];
505 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
508 // Get track parameters
509 AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First());
512 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
514 // Printout for debuging
515 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
516 cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
519 // Create iterators to loop over clusters in both chambers
520 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
521 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
523 // look for candidates in chamber 2
524 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
526 // try to add the current cluster fast
527 if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
529 // try to add the current cluster accuratly
530 extrapTrackParamAtCluster2 = trackParam;
531 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
532 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
534 // if good chi2 then try to attach a cluster in the other chamber too
535 if (chi2WithOneCluster < maxChi2WithOneCluster) {
536 Bool_t foundSecondCluster = kFALSE;
538 // Printout for debuging
539 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
540 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
541 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
542 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
546 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
548 // reset cluster iterator of chamber 1
552 // look for second candidates in chamber 1
553 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
556 // try to add the current cluster fast
557 if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
559 // try to add the current cluster in addition to the one found in the previous chamber
560 chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
562 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
563 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
564 foundSecondCluster = kTRUE;
565 foundTwoClusters = kTRUE;
567 // Printout for debuging
568 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
569 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
570 << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
573 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
574 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
575 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
576 extrapTrackParamAtCluster1.SetRemovable(kTRUE);
577 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
578 extrapTrackParamAtCluster2.SetRemovable(kTRUE);
579 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
580 newTrack->GetTrackParamAtCluster()->Sort();
583 // Tag clusterCh1 as used
584 clusterCh1Used[iCluster1] = kTRUE;
586 // Printout for debuging
587 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
588 cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
589 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
592 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
593 // keep track of the best couple of clusters
594 bestChi2WithTwoClusters = chi2WithTwoClusters;
595 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
596 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
603 // if no cluster found in chamber1 then consider to add clusterCh2 only
604 if (!foundSecondCluster) {
605 foundOneCluster = kTRUE;
607 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
608 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
609 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
610 extrapTrackParamAtCluster2.SetRemovable(kFALSE);
611 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
612 newTrack->GetTrackParamAtCluster()->Sort();
615 // Printout for debuging
616 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
617 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
618 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
621 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
622 // keep track of the best cluster except if a couple of clusters has already been found
623 bestChi2WithOneCluster = chi2WithOneCluster;
624 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
633 // look for candidates in chamber 1 not already attached to a track
634 // if we want to keep all possible tracks or if no good couple of clusters has been found
635 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
637 // Printout for debuging
638 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
639 cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
642 //Extrapolate trackCandidate to chamber "ch2"
643 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
645 // add MCS effect for next step
646 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
648 // reset cluster iterator of chamber 1
652 // look for second candidates in chamber 1
653 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
656 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
658 // try to add the current cluster fast
659 if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
661 // try to add the current cluster accuratly
662 extrapTrackParamAtCluster1 = trackParam;
663 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
664 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
666 // if good chi2 then consider to add clusterCh1
667 // We do not try to attach a cluster in the other chamber too since it has already been done above
668 if (chi2WithOneCluster < maxChi2WithOneCluster) {
669 foundOneCluster = kTRUE;
671 // Printout for debuging
672 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
673 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
674 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
677 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
678 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
679 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
680 extrapTrackParamAtCluster1.SetRemovable(kFALSE);
681 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
682 newTrack->GetTrackParamAtCluster()->Sort();
685 // Printout for debuging
686 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
687 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
688 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
691 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
692 // keep track of the best cluster except if a couple of clusters has already been found
693 bestChi2WithOneCluster = chi2WithOneCluster;
694 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
703 // fill out the best track if required else clean up the fRecTracksPtr array
704 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
705 if (foundTwoClusters) {
706 bestTrackParamAtCluster1.SetRemovable(kTRUE);
707 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
708 bestTrackParamAtCluster2.SetRemovable(kTRUE);
709 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
710 trackCandidate.GetTrackParamAtCluster()->Sort();
712 // Printout for debuging
713 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
714 cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
715 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
718 } else if (foundOneCluster) {
719 bestTrackParamAtCluster1.SetRemovable(kFALSE);
720 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
721 trackCandidate.GetTrackParamAtCluster()->Sort();
723 // Printout for debuging
724 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
725 cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
726 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
730 delete [] clusterCh1Used;
734 } else if (foundOneCluster || foundTwoClusters) {
736 // remove obsolete track
737 fRecTracksPtr->Remove(&trackCandidate);
741 delete [] clusterCh1Used;
745 delete [] clusterCh1Used;
750 //__________________________________________________________________________
751 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
752 const AliMUONVTriggerTrackStore& triggerTrackStore,
753 const AliMUONVTriggerStore& triggerStore,
754 const AliMUONTrackHitPattern& trackHitPattern)
756 /// Try to match track from tracking system with trigger track
757 AliCodeTimerAuto("");
759 trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
760 trackHitPattern.UpdateQA();
763 //__________________________________________________________________________
764 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
765 const AliMUONVTriggerStore& triggerStore,
766 AliMUONVTriggerTrackStore& triggerTrackStore)
768 /// To make the trigger tracks from Local Trigger
770 AliCodeTimerAuto("");
772 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
774 UChar_t gloTrigPat = 0;
778 gloTrigPat = globalTrigger->GetGlobalResponse();
781 TIter next(triggerStore.CreateIterator());
782 AliMUONLocalTrigger* locTrg(0x0);
784 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
785 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
787 AliMUONTriggerTrack triggerTrack;
789 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
794 Int_t localBoardId = locTrg->LoCircuit();
795 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
796 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
797 else xTrig=kTRUE; // trigger in X
798 if (locTrg->LoTrigY()==1 &&
799 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
800 else yTrig = kTRUE; // trigger in Y
803 { // make Trigger Track if trigger in X and Y
805 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
806 // need first to convert deviation to [0-30]
807 // (see AliMUONLocalTriggerBoard::LocalTrigger)
808 Int_t deviation = locTrg->LoDev();
810 if ( !locTrg->LoSdev() && deviation ) sign=-1;
811 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
812 if ( locTrg->LoSdev() == 1 ) sign=+1;
815 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
816 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
817 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
819 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
820 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
822 Float_t thetax = TMath::ATan2( x11 , z11 );
823 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
825 triggerTrack.SetX11(x11);
826 triggerTrack.SetY11(y11);
827 triggerTrack.SetThetax(thetax);
828 triggerTrack.SetThetay(thetay);
829 triggerTrack.SetGTPattern(gloTrigPat);
830 triggerTrack.SetLoTrgNum(localBoardId);
832 triggerTrackStore.Add(triggerTrack);
834 } // end of loop on Local Trigger