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 ////////////////////////////////////
20 /// \class AliMUONVTrackReconstructor
21 /// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
23 /// This class contains as data:
24 /// * a pointer to the array of hits to be reconstructed (the event)
25 /// * a pointer to the array of reconstructed tracks
27 /// It contains as methods, among others:
28 /// * EventReconstruct to build the muon tracks
29 /// * EventReconstructTrigger to build the trigger tracks
31 /// Several options and adjustable parameters are available for both Kalman and Original
32 /// tracking algorithms (hard coded for the moment in AliMUONVTrackReconstructor.cxx):
33 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
34 /// attached to the track candidate and to select good tracks.
35 /// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
36 /// are made assuming linear propagation between stations 4 and 5.
37 /// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
38 /// new clusters pass the quality cut, either we consider all the possibilities
39 /// (duplicating tracks) or we attach only the best cluster.
40 /// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
41 /// lost during the tracking by removing the worst of the 2 clusters attached in the
43 /// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
44 /// of the tracks at the end of the tracking by removing clusters that do not pass
45 /// new quality cut (within the limit that we must keep at least one cluster per
47 /// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
48 /// quality of the tracks.
50 /// \author Philippe Pillot
52 ////////////////////////////////////
54 #include "AliMUONVTrackReconstructor.h"
56 #include "AliMUONConstants.h"
57 #include "AliMUONRawCluster.h"
58 #include "AliMUONHitForRec.h"
59 #include "AliMUONObjectPair.h"
60 #include "AliMUONTriggerTrack.h"
61 #include "AliMUONTriggerCircuit.h"
62 #include "AliMUONLocalTrigger.h"
63 #include "AliMUONGlobalTrigger.h"
64 #include "AliMUONTrack.h"
65 #include "AliMUONTrackParam.h"
66 #include "AliMUONTrackExtrap.h"
67 #include "AliMUONTrackHitPattern.h"
68 #include "AliMUONVTrackStore.h"
69 #include "AliMUONVClusterStore.h"
70 #include "AliMUONRawCluster.h"
71 #include "AliMUONVTriggerStore.h"
72 #include "AliMUONVTriggerTrackStore.h"
73 #include "AliMpDEManager.h"
76 #include "AliTracker.h"
78 #include <TClonesArray.h>
82 #include <Riostream.h>
85 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
89 //************* Defaults parameters for reconstruction
90 const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
91 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
92 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
93 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceBending = 2.;
94 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceNonBending = 2.;
96 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForTracking = 6.0;
97 const Bool_t AliMUONVTrackReconstructor::fgkMakeTrackCandidatesFast = kFALSE;
98 const Bool_t AliMUONVTrackReconstructor::fgkTrackAllTracks = kTRUE;
99 const Bool_t AliMUONVTrackReconstructor::fgkRecoverTracks = kTRUE;
100 const Bool_t AliMUONVTrackReconstructor::fgkImproveTracks = kTRUE;
101 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForImprovement = 4.0;
104 //__________________________________________________________________________
105 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor()
107 fMinBendingMomentum(fgkDefaultMinBendingMomentum),
108 fMaxBendingMomentum(fgkDefaultMaxBendingMomentum),
109 fMaxNormChi2MatchTrigger(fgkDefaultMaxNormChi2MatchTrigger),
112 fNHitsForRecPerChamber(0x0),
113 fIndexOfFirstHitForRecPerChamber(0x0),
117 /// Constructor for class AliMUONVTrackReconstructor
118 fNHitsForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
119 fIndexOfFirstHitForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
121 // Memory allocation for the TClonesArray of hits for reconstruction
122 // Is 10000 the right size ????
123 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
125 // Memory allocation for the TClonesArray of reconstructed tracks
126 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
128 // set the magnetic field for track extrapolations
129 const AliMagF* kField = AliTracker::GetFieldMap();
130 if (!kField) AliFatal("No field available");
131 AliMUONTrackExtrap::SetField(kField);
134 //__________________________________________________________________________
135 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
137 /// Destructor for class AliMUONVTrackReconstructor
138 delete [] fNHitsForRecPerChamber;
139 delete [] fIndexOfFirstHitForRecPerChamber;
140 delete fHitsForRecPtr;
141 delete fRecTracksPtr;
144 //__________________________________________________________________________
145 void AliMUONVTrackReconstructor::ResetHitsForRec()
147 /// To reset the TClonesArray of HitsForRec,
148 /// and the number of HitForRec and the index of the first HitForRec per chamber
149 if (fHitsForRecPtr) fHitsForRecPtr->Clear("C");
151 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
152 fNHitsForRecPerChamber[ch] = 0;
153 fIndexOfFirstHitForRecPerChamber[ch] = 0;
157 //__________________________________________________________________________
158 void AliMUONVTrackReconstructor::ResetTracks()
160 /// To reset the TClonesArray of reconstructed tracks
161 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
166 //__________________________________________________________________________
167 void AliMUONVTrackReconstructor::EventReconstruct(const AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
169 /// To reconstruct one event
174 AddHitsForRecFromRawClusters(clusterStore);
177 // Add tracks to MUON data container
178 for (Int_t i=0; i<fNRecTracks; ++i)
180 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
181 trackStore.Add(*track);
185 //__________________________________________________________________________
186 void AliMUONVTrackReconstructor::AddHitsForRecFromRawClusters(const AliMUONVClusterStore& clusterStore)
188 /// Build internal array of hit for rec from clusterStore
190 TIter next(clusterStore.CreateIterator());
191 AliMUONRawCluster* clus(0x0);
194 while ( ( clus = static_cast<AliMUONRawCluster*>(next()) ) )
196 // new AliMUONHitForRec from raw cluster
197 // and increment number of AliMUONHitForRec's (total and in chamber)
198 AliMUONHitForRec* hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
200 // more information into HitForRec
201 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
202 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
203 // original raw cluster
204 Int_t ch = AliMpDEManager::GetChamberId(clus->GetDetElemId());
205 hitForRec->SetChamberNumber(ch);
206 hitForRec->SetHitNumber(iclus);
207 // Z coordinate of the raw cluster (cm)
208 hitForRec->SetZ(clus->GetZ(0));
209 if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
210 cout << "Chamber " << ch <<" raw cluster " << iclus << " : " << endl;
212 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
213 hitForRec->Print("full");
216 } // end of chamber loop
218 SortHitsForRecWithIncreasingChamber();
220 AliDebug(1,"End of AddHitsForRecFromRawClusters");
222 if (AliLog::GetGlobalDebugLevel() > 0)
224 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
225 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++)
227 AliDebug(1, Form("Chamber(0...): %d",ch));
228 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
229 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
230 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
231 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
233 AliDebug(1, Form("HitForRec index(0...): %d",hit));
234 ((*fHitsForRecPtr)[hit])->Dump();
240 //__________________________________________________________________________
241 void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
243 /// Sort HitsForRec's in increasing order with respect to chamber number.
244 /// Uses the function "Compare".
245 /// Update the information for HitsForRec per chamber too.
246 Int_t ch, nhits, prevch;
247 fHitsForRecPtr->Sort();
248 for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
249 fNHitsForRecPerChamber[ch] = 0;
250 fIndexOfFirstHitForRecPerChamber[ch] = 0;
252 prevch = 0; // previous chamber
253 nhits = 0; // number of hits in current chamber
254 // Loop over HitsForRec
255 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
256 // chamber number (0...)
257 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
258 // increment number of hits in current chamber
259 (fNHitsForRecPerChamber[ch])++;
260 // update index of first HitForRec in current chamber
261 // if chamber number different from previous one
263 fIndexOfFirstHitForRecPerChamber[ch] = hit;
270 //__________________________________________________________________________
271 void AliMUONVTrackReconstructor::MakeTracks()
273 /// To make the tracks from the list of segments and points in all stations
274 AliDebug(1,"Enter MakeTracks");
275 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
276 MakeTrackCandidates();
277 if (fRecTracksPtr->GetEntriesFast() == 0) return;
278 // Follow tracks in stations(1..) 3, 2 and 1
280 // Improve the reconstructed tracks
281 if (fgkImproveTracks) ImproveTracks();
282 // Remove double tracks
283 RemoveDoubleTracks();
284 // Fill AliMUONTrack data members
288 //__________________________________________________________________________
289 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
291 /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
292 /// Return a new TClonesArray of segments.
293 /// It is the responsibility of the user to delete it afterward.
294 AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
296 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
297 AliMUONObjectPair *segment;
298 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
299 // first and second chambers (0...) in the station
300 Int_t ch1 = 2 * station;
304 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
305 segments->SetOwner(kTRUE);
307 // Loop over HitForRec's in the first chamber of the station
308 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
309 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
312 // pointer to the HitForRec
313 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
314 // Loop over HitsForRec's in the second chamber of the station
315 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
316 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
319 // pointer to the HitForRec
320 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
321 if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. )
324 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
326 impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
327 // absolute value of bending momentum
328 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
331 AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
334 // check for bending momentum within tolerances
335 if ((bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum))
338 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
339 if (AliLog::GetGlobalDebugLevel() > 1) {
340 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
342 cout << "HitForRec in first chamber" << endl;
344 cout << "HitForRec in second chamber" << endl;
349 } // for (Int_t hit1...
350 AliDebug(1,Form("Station: %d NSegments: %d ", station, segments->GetEntriesFast()));
354 //__________________________________________________________________________
355 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
357 /// To remove identical tracks:
358 /// Tracks are considered identical if they have all their hits in common.
359 /// One keeps the track with the larger number of hits if need be
360 AliMUONTrack *track1, *track2, *trackToRemove;
361 Int_t hitsInCommon, nHits1, nHits2;
362 Bool_t removedTrack1;
363 // Loop over first track of the pair
364 track1 = (AliMUONTrack*) fRecTracksPtr->First();
366 removedTrack1 = kFALSE;
367 nHits1 = track1->GetNTrackHits();
368 // Loop over second track of the pair
369 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
371 nHits2 = track2->GetNTrackHits();
372 // number of hits in common between two tracks
373 hitsInCommon = track1->HitsInCommon(track2);
374 // check for identical tracks
375 if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
376 // decide which track to remove
377 if (nHits2 > nHits1) {
378 // remove track1 and continue the first loop with the track next to track1
379 trackToRemove = track1;
380 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
381 fRecTracksPtr->Remove(trackToRemove);
382 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
384 removedTrack1 = kTRUE;
387 // remove track2 and continue the second loop with the track next to track2
388 trackToRemove = track2;
389 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
390 fRecTracksPtr->Remove(trackToRemove);
391 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
394 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
396 if (removedTrack1) continue;
397 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
402 //__________________________________________________________________________
403 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
405 /// To remove double tracks:
406 /// Tracks are considered identical if more than half of the hits of the track
407 /// which has the smaller number of hits are in common with the other track.
408 /// Among two identical tracks, one keeps the track with the larger number of hits
409 /// or, if these numbers are equal, the track with the minimum chi2.
410 AliMUONTrack *track1, *track2, *trackToRemove;
411 Int_t hitsInCommon, nHits1, nHits2;
412 Bool_t removedTrack1;
413 // Loop over first track of the pair
414 track1 = (AliMUONTrack*) fRecTracksPtr->First();
416 removedTrack1 = kFALSE;
417 nHits1 = track1->GetNTrackHits();
418 // Loop over second track of the pair
419 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
421 nHits2 = track2->GetNTrackHits();
422 // number of hits in common between two tracks
423 hitsInCommon = track1->HitsInCommon(track2);
424 // check for identical tracks
425 if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
426 // decide which track to remove
427 if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
428 // remove track2 and continue the second loop with the track next to track2
429 trackToRemove = track2;
430 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
431 fRecTracksPtr->Remove(trackToRemove);
432 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
435 // else remove track1 and continue the first loop with the track next to track1
436 trackToRemove = track1;
437 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
438 fRecTracksPtr->Remove(trackToRemove);
439 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
441 removedTrack1 = kTRUE;
444 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
446 if (removedTrack1) continue;
447 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
452 //__________________________________________________________________________
453 Double_t AliMUONVTrackReconstructor::TryOneHitForRec(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec,
454 AliMUONTrackParam &trackParamAtHit, Bool_t updatePropagator)
456 /// Test the compatibility between the track and the hitForRec (using trackParam's covariance matrix):
457 /// return the corresponding Chi2
458 /// return trackParamAtHit
460 // extrapolate track parameters and covariances at the z position of the tested hit
461 trackParamAtHit = trackParam;
462 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtHit, hitForRec->GetZ(), updatePropagator);
464 // set pointer to hit into trackParamAtHit
465 trackParamAtHit.SetHitForRecPtr(hitForRec);
467 // Set differences between trackParam and hitForRec in the bending and non bending directions
468 Double_t dX = hitForRec->GetNonBendingCoor() - trackParamAtHit.GetNonBendingCoor();
469 Double_t dY = hitForRec->GetBendingCoor() - trackParamAtHit.GetBendingCoor();
471 // Calculate errors and covariances
472 const TMatrixD& kParamCov = trackParamAtHit.GetCovariances();
473 Double_t sigma2X = kParamCov(0,0) + hitForRec->GetNonBendingReso2();
474 Double_t sigma2Y = kParamCov(2,2) + hitForRec->GetBendingReso2();
477 return dX * dX / sigma2X + dY * dY / sigma2Y;
481 //__________________________________________________________________________
482 Bool_t AliMUONVTrackReconstructor::TryOneHitForRecFast(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec)
484 /// Test the compatibility between the track and the hitForRec within a wide fix window
485 /// assuming linear propagation of the track:
486 /// return kTRUE if they are compatibles
488 Double_t dZ = hitForRec->GetZ() - trackParam.GetZ();
489 Double_t dX = hitForRec->GetNonBendingCoor() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
490 Double_t dY = hitForRec->GetBendingCoor() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
492 if (TMath::Abs(dX) > fgkMaxTrackingDistanceNonBending || TMath::Abs(dY) > fgkMaxTrackingDistanceBending) return kFALSE;
498 //__________________________________________________________________________
499 Double_t AliMUONVTrackReconstructor::TryTwoHitForRecFast(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2,
500 AliMUONTrackParam &trackParamAtHit2)
502 /// Test the compatibility between the track and the 2 hitForRec together (using trackParam's covariance matrix)
503 /// assuming linear propagation between the two hits:
504 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
505 /// return trackParamAtHit1 & 2
507 // extrapolate linearly track parameters at the z position of the second hit
508 trackParamAtHit2 = trackParamAtHit1;
509 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtHit2, hitForRec2->GetZ());
511 // set pointer to hit2 into trackParamAtHit2
512 trackParamAtHit2.SetHitForRecPtr(hitForRec2);
514 // Set differences between track and hitForRec in the bending and non bending directions
515 AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr();
516 Double_t dX1 = hitForRec1->GetNonBendingCoor() - trackParamAtHit1.GetNonBendingCoor();
517 Double_t dX2 = hitForRec2->GetNonBendingCoor() - trackParamAtHit2.GetNonBendingCoor();
518 Double_t dY1 = hitForRec1->GetBendingCoor() - trackParamAtHit1.GetBendingCoor();
519 Double_t dY2 = hitForRec2->GetBendingCoor() - trackParamAtHit2.GetBendingCoor();
521 // Calculate errors and covariances
522 const TMatrixD& kParamCov1 = trackParamAtHit1.GetCovariances();
523 const TMatrixD& kParamCov2 = trackParamAtHit2.GetCovariances();
524 Double_t dZ = trackParamAtHit2.GetZ() - trackParamAtHit1.GetZ();
525 Double_t sigma2X1 = kParamCov1(0,0) + hitForRec1->GetNonBendingReso2();
526 Double_t sigma2X2 = kParamCov2(0,0) + hitForRec2->GetNonBendingReso2();
527 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
528 Double_t sigma2Y1 = kParamCov1(2,2) + hitForRec1->GetBendingReso2();
529 Double_t sigma2Y2 = kParamCov2(2,2) + hitForRec2->GetBendingReso2();
530 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
533 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
534 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
535 if (detX == 0. || detY == 0.) return 1.e10;
536 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
537 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
541 //__________________________________________________________________________
542 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation)
544 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible HitForRec(s)
545 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
546 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
547 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
548 /// Remove the obsolete "trackCandidate" at the end.
549 /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
550 /// return kTRUE if new hits have been found (otherwise return kFALSE)
551 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
553 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
554 // - nextStation == station(1...) 5 => forward propagation
555 // - nextStation < station(1...) 5 => backward propagation
557 if (nextStation==4) {
558 ch1 = 2*nextStation+1;
562 ch2 = 2*nextStation+1;
565 Double_t chi2WithOneHitForRec = 1.e10;
566 Double_t chi2WithTwoHitForRec = 1.e10;
567 Double_t maxChi2WithOneHitForRec = 2. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 2 because 2 quantities in chi2
568 Double_t maxChi2WithTwoHitForRec = 4. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 4 because 4 quantities in chi2
569 Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
570 Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
571 Bool_t foundOneHit = kFALSE;
572 Bool_t foundTwoHits = kFALSE;
573 AliMUONTrack *newTrack = 0x0;
574 AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
575 AliMUONTrackParam extrapTrackParamAtHit1;
576 AliMUONTrackParam extrapTrackParamAtHit2;
577 AliMUONTrackParam bestTrackParamAtHit1;
578 AliMUONTrackParam bestTrackParamAtHit2;
579 Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
580 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
582 // Get track parameters
583 AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First());
586 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
588 // Printout for debuging
589 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
590 cout << "FollowLinearTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
593 // look for candidates in chamber 2
594 for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
596 hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
598 // try to add the current hit fast
599 if (!TryOneHitForRecFast(trackParam, hitForRecCh2)) continue;
601 // try to add the current hit accuratly
602 extrapTrackParamAtHit2 = trackParam;
603 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit2, hitForRecCh2->GetZ());
604 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit2, hitForRecCh2, extrapTrackParamAtHit2);
606 // if good chi2 then try to attach a hitForRec in the other chamber too
607 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
608 Bool_t foundSecondHit = kFALSE;
610 // Printout for debuging
611 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
612 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch2+1
613 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
614 cout << " look for second hits in chamber(1..): " << ch1+1 << " ..." << endl;
618 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.);
620 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
622 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
624 // try to add the current hit fast
625 if (!TryOneHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1)) continue;
627 // try to add the current hit in addition to the one found on the previous chamber
628 chi2WithTwoHitForRec = TryTwoHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1);
630 // if good chi2 then consider to add the 2 hitForRec to the "trackCandidate"
631 if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
632 foundSecondHit = kTRUE;
633 foundTwoHits = kTRUE;
635 // Printout for debuging
636 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
637 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
638 << " (Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
641 if (fgkTrackAllTracks) {
642 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
643 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
644 extrapTrackParamAtHit1.SetRemovable(kTRUE);
645 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
646 extrapTrackParamAtHit2.SetRemovable(kTRUE);
647 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
648 newTrack->GetTrackParamAtHit()->Sort();
651 // Tag hitForRecCh1 as used
652 hitForRecCh1Used[hit1] = kTRUE;
654 // Printout for debuging
655 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
656 cout << "FollowLinearTrackInStation: added two hits in station(1..): " << nextStation+1 << endl;
657 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
660 } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
661 // keep track of the best couple of hits
662 bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
663 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
664 bestTrackParamAtHit2 = extrapTrackParamAtHit2;
671 // if no hitForRecCh1 found then consider to add hitForRecCh2 only
672 if (!foundSecondHit) {
675 if (fgkTrackAllTracks) {
676 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
677 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
678 extrapTrackParamAtHit2.SetRemovable(kFALSE);
679 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
680 newTrack->GetTrackParamAtHit()->Sort();
683 // Printout for debuging
684 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
685 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl;
686 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
689 } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
690 // keep track of the best single hitForRec except if a couple of hits has already been found
691 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
692 bestTrackParamAtHit1 = extrapTrackParamAtHit2;
701 // look for candidates in chamber 1 not already attached to a track
702 // if we want to keep all possible tracks or if no good couple of hitForRec has been found
703 if (fgkTrackAllTracks || !foundTwoHits) {
705 // Printout for debuging
706 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
707 cout << "FollowLinearTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
710 //Extrapolate trackCandidate to chamber "ch2"
711 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
713 // add MCS effect for next step
714 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
716 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
718 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
720 if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
722 // try to add the current hit fast
723 if (!TryOneHitForRecFast(trackParam, hitForRecCh1)) continue;
725 // try to add the current hit accuratly
726 extrapTrackParamAtHit1 = trackParam;
727 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit1, hitForRecCh1->GetZ());
728 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit1, hitForRecCh1, extrapTrackParamAtHit1);
730 // if good chi2 then consider to add hitForRecCh1
731 // We do not try to attach a hitForRec in the other chamber too since it has already been done above
732 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
735 // Printout for debuging
736 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
737 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
738 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
741 if (fgkTrackAllTracks) {
742 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
743 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
744 extrapTrackParamAtHit1.SetRemovable(kFALSE);
745 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
746 newTrack->GetTrackParamAtHit()->Sort();
749 // Printout for debuging
750 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
751 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl;
752 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
755 } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
756 // keep track of the best single hitForRec except if a couple of hits has already been found
757 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
758 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
767 // fill out the best track if required else clean up the fRecTracksPtr array
768 if (!fgkTrackAllTracks) {
770 bestTrackParamAtHit1.SetRemovable(kTRUE);
771 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
772 bestTrackParamAtHit2.SetRemovable(kTRUE);
773 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit2,bestTrackParamAtHit2.GetHitForRecPtr());
774 trackCandidate.GetTrackParamAtHit()->Sort();
776 // Printout for debuging
777 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
778 cout << "FollowLinearTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl;
779 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
782 } else if (foundOneHit) {
783 bestTrackParamAtHit1.SetRemovable(kFALSE);
784 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
785 trackCandidate.GetTrackParamAtHit()->Sort();
787 // Printout for debuging
788 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
789 cout << "FollowLinearTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl;
790 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
793 } else return kFALSE;
795 } else if (foundOneHit || foundTwoHits) {
797 // remove obsolete track
798 fRecTracksPtr->Remove(&trackCandidate);
801 } else return kFALSE;
807 //__________________________________________________________________________
808 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
809 const AliMUONVTriggerTrackStore& triggerTrackStore,
810 const AliMUONVTriggerStore& triggerStore,
811 const AliMUONTrackHitPattern& trackHitPattern)
813 /// Try to match track from tracking system with trigger track
814 static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
818 Double_t distTriggerTrack[3];
819 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
821 TIter itTrack(trackStore.CreateIterator());
824 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
827 chi2MatchTrigger = 0.;
829 Int_t doubleMatch=-1; // Check if track matches 2 trigger tracks
830 Double_t doubleChi2 = -1.;
832 AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last())));
833 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
835 xTrack = trackParam.GetNonBendingCoor();
836 yTrack = trackParam.GetBendingCoor();
837 ySlopeTrack = trackParam.GetBendingSlope();
838 minChi2MatchTrigger = 999.;
840 AliMUONTriggerTrack *triggerTrack;
841 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
842 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
844 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
845 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
846 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
848 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
849 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
850 if (chi2 < fMaxNormChi2MatchTrigger)
852 Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
853 if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger)
857 doubleMatch = loTrgNum;
858 doubleChi2 = chi2MatchTrigger;
860 minChi2MatchTrigger = chi2;
861 chi2MatchTrigger = chi2;
862 loTrgNum = triggerTrack->GetLoTrgNum();
863 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
865 if(locTrg->LoLpt()>0)matchTrigger=2;
866 if(locTrg->LoHpt()>0)matchTrigger=3;
868 else if(isDoubleTrack)
870 doubleMatch = triggerTrack->GetLoTrgNum();
876 { // If two trigger tracks match, select the one passing more trigger cuts
877 AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
878 AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
879 if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
881 if(locTrg1->LoHpt()>0)matchTrigger=3;
883 loTrgNum = doubleMatch;
884 chi2MatchTrigger=doubleChi2;
888 track->SetMatchTrigger(matchTrigger);
889 track->SetLoTrgNum(loTrgNum);
890 track->SetChi2MatchTrigger(chi2MatchTrigger);
892 AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
896 track->SetLocalTrigger(locTrg->LoCircuit(),
905 trackHitPattern.GetHitPattern(trackStore,triggerStore);
908 //__________________________________________________________________________
909 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
910 const AliMUONVTriggerStore& triggerStore,
911 AliMUONVTriggerTrackStore& triggerTrackStore)
913 /// To make the trigger tracks from Local Trigger
916 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
918 UChar_t gloTrigPat = 0;
922 gloTrigPat = globalTrigger->GetGlobalResponse();
925 TIter next(triggerStore.CreateIterator());
926 AliMUONLocalTrigger* locTrg(0x0);
928 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
929 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
931 AliMUONTriggerTrack triggerTrack;
933 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
938 Int_t localBoardId = locTrg->LoCircuit();
939 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
940 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
941 else xTrig=kTRUE; // trigger in X
942 if (locTrg->LoTrigY()==1 &&
943 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
944 else yTrig = kTRUE; // trigger in Y
947 { // make Trigger Track if trigger in X and Y
949 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
950 // need first to convert deviation to [0-30]
951 // (see AliMUONLocalTriggerBoard::LocalTrigger)
952 Int_t deviation = locTrg->LoDev();
954 if ( !locTrg->LoSdev() && deviation ) sign=-1;
955 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
956 if ( locTrg->LoSdev() == 1 ) sign=+1;
959 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
960 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
961 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
963 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
964 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
966 Float_t thetax = TMath::ATan2( x11 , z11 );
967 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
969 triggerTrack.SetX11(x11);
970 triggerTrack.SetY11(y11);
971 triggerTrack.SetThetax(thetax);
972 triggerTrack.SetThetay(thetay);
973 triggerTrack.SetGTPattern(gloTrigPat);
974 triggerTrack.SetLoTrgNum(localBoardId);
976 triggerTrackStore.Add(triggerTrack);
978 } // end of loop on Local Trigger