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:
23 /// * a pointer to the array of hits to be reconstructed (the event)
24 /// * a pointer to the array of reconstructed tracks
26 /// It contains as methods, among others:
27 /// * EventReconstruct to build the muon tracks
28 /// * EventReconstructTrigger to build the trigger tracks
30 /// Several options and adjustable parameters are available for both Kalman and Original
31 /// tracking algorithms (hard coded for the moment in AliMUONVTrackReconstructor.cxx):
32 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
33 /// attached to the track candidate and to select good tracks.
34 /// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
35 /// are made assuming linear propagation between stations 4 and 5.
36 /// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
37 /// new clusters pass the quality cut, either we consider all the possibilities
38 /// (duplicating tracks) or we attach only the best cluster.
39 /// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
40 /// lost during the tracking by removing the worst of the 2 clusters attached in the
42 /// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
43 /// of the tracks at the end of the tracking by removing clusters that do not pass
44 /// new quality cut (within the limit that we must keep at least one cluster per
46 /// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
47 /// quality of the tracks.
49 /// \author Philippe Pillot
50 //-----------------------------------------------------------------------------
52 #include "AliMUONVTrackReconstructor.h"
54 #include "AliMUONConstants.h"
55 #include "AliMUONRawCluster.h"
56 #include "AliMUONHitForRec.h"
57 #include "AliMUONObjectPair.h"
58 #include "AliMUONTriggerTrack.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMUONLocalTrigger.h"
61 #include "AliMUONGlobalTrigger.h"
62 #include "AliMUONTrack.h"
63 #include "AliMUONTrackParam.h"
64 #include "AliMUONTrackExtrap.h"
65 #include "AliMUONTrackHitPattern.h"
66 #include "AliMUONVTrackStore.h"
67 #include "AliMUONVClusterStore.h"
68 #include "AliMUONRawCluster.h"
69 #include "AliMUONVTriggerStore.h"
70 #include "AliMUONVTriggerTrackStore.h"
71 #include "AliMpDEManager.h"
74 #include "AliTracker.h"
76 #include <TClonesArray.h>
80 #include <Riostream.h>
83 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
87 //************* Defaults parameters for reconstruction
88 const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
89 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
90 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
91 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceBending = 2.;
92 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceNonBending = 2.;
94 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForTracking = 6.0;
95 const Bool_t AliMUONVTrackReconstructor::fgkMakeTrackCandidatesFast = kFALSE;
96 const Bool_t AliMUONVTrackReconstructor::fgkTrackAllTracks = kTRUE;
97 const Bool_t AliMUONVTrackReconstructor::fgkRecoverTracks = kTRUE;
98 const Bool_t AliMUONVTrackReconstructor::fgkImproveTracks = kTRUE;
99 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForImprovement = 4.0;
102 //__________________________________________________________________________
103 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor()
105 fMinBendingMomentum(fgkDefaultMinBendingMomentum),
106 fMaxBendingMomentum(fgkDefaultMaxBendingMomentum),
107 fMaxNormChi2MatchTrigger(fgkDefaultMaxNormChi2MatchTrigger),
110 fNHitsForRecPerChamber(0x0),
111 fIndexOfFirstHitForRecPerChamber(0x0),
115 /// Constructor for class AliMUONVTrackReconstructor
116 fNHitsForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
117 fIndexOfFirstHitForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
119 // Memory allocation for the TClonesArray of hits for reconstruction
120 // Is 10000 the right size ????
121 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
123 // Memory allocation for the TClonesArray of reconstructed tracks
124 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
126 // set the magnetic field for track extrapolations
127 const AliMagF* kField = AliTracker::GetFieldMap();
128 if (!kField) AliFatal("No field available");
129 AliMUONTrackExtrap::SetField(kField);
132 //__________________________________________________________________________
133 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
135 /// Destructor for class AliMUONVTrackReconstructor
136 delete [] fNHitsForRecPerChamber;
137 delete [] fIndexOfFirstHitForRecPerChamber;
138 delete fHitsForRecPtr;
139 delete fRecTracksPtr;
142 //__________________________________________________________________________
143 void AliMUONVTrackReconstructor::ResetHitsForRec()
145 /// To reset the TClonesArray of HitsForRec,
146 /// and the number of HitForRec and the index of the first HitForRec per chamber
147 if (fHitsForRecPtr) fHitsForRecPtr->Clear("C");
149 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
150 fNHitsForRecPerChamber[ch] = 0;
151 fIndexOfFirstHitForRecPerChamber[ch] = 0;
155 //__________________________________________________________________________
156 void AliMUONVTrackReconstructor::ResetTracks()
158 /// To reset the TClonesArray of reconstructed tracks
159 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
164 //__________________________________________________________________________
165 void AliMUONVTrackReconstructor::EventReconstruct(const AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
167 /// To reconstruct one event
172 AddHitsForRecFromRawClusters(clusterStore);
175 // Add tracks to MUON data container
176 for (Int_t i=0; i<fNRecTracks; ++i)
178 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
179 trackStore.Add(*track);
183 //__________________________________________________________________________
184 void AliMUONVTrackReconstructor::AddHitsForRecFromRawClusters(const AliMUONVClusterStore& clusterStore)
186 /// Build internal array of hit for rec from clusterStore
188 TIter next(clusterStore.CreateIterator());
189 AliMUONRawCluster* clus(0x0);
192 while ( ( clus = static_cast<AliMUONRawCluster*>(next()) ) )
194 // new AliMUONHitForRec from raw cluster
195 // and increment number of AliMUONHitForRec's (total and in chamber)
196 AliMUONHitForRec* hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
198 // more information into HitForRec
199 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
200 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
201 // original raw cluster
202 Int_t ch = AliMpDEManager::GetChamberId(clus->GetDetElemId());
203 hitForRec->SetChamberNumber(ch);
204 hitForRec->SetHitNumber(iclus);
205 // Z coordinate of the raw cluster (cm)
206 hitForRec->SetZ(clus->GetZ(0));
207 if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
208 cout << "Chamber " << ch <<" raw cluster " << iclus << " : " << endl;
210 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
211 hitForRec->Print("full");
214 } // end of chamber loop
216 SortHitsForRecWithIncreasingChamber();
218 AliDebug(1,"End of AddHitsForRecFromRawClusters");
220 if (AliLog::GetGlobalDebugLevel() > 0)
222 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
223 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++)
225 AliDebug(1, Form("Chamber(0...): %d",ch));
226 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
227 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
228 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
229 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
231 AliDebug(1, Form("HitForRec index(0...): %d",hit));
232 ((*fHitsForRecPtr)[hit])->Dump();
238 //__________________________________________________________________________
239 void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
241 /// Sort HitsForRec's in increasing order with respect to chamber number.
242 /// Uses the function "Compare".
243 /// Update the information for HitsForRec per chamber too.
244 Int_t ch, nhits, prevch;
245 fHitsForRecPtr->Sort();
246 for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
247 fNHitsForRecPerChamber[ch] = 0;
248 fIndexOfFirstHitForRecPerChamber[ch] = 0;
250 prevch = 0; // previous chamber
251 nhits = 0; // number of hits in current chamber
252 // Loop over HitsForRec
253 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
254 // chamber number (0...)
255 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
256 // increment number of hits in current chamber
257 (fNHitsForRecPerChamber[ch])++;
258 // update index of first HitForRec in current chamber
259 // if chamber number different from previous one
261 fIndexOfFirstHitForRecPerChamber[ch] = hit;
268 //__________________________________________________________________________
269 void AliMUONVTrackReconstructor::MakeTracks()
271 /// To make the tracks from the list of segments and points in all stations
272 AliDebug(1,"Enter MakeTracks");
273 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
274 MakeTrackCandidates();
275 if (fRecTracksPtr->GetEntriesFast() == 0) return;
276 // Follow tracks in stations(1..) 3, 2 and 1
278 // Improve the reconstructed tracks
279 if (fgkImproveTracks) ImproveTracks();
280 // Remove double tracks
281 RemoveDoubleTracks();
282 // Fill AliMUONTrack data members
286 //__________________________________________________________________________
287 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
289 /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
290 /// Return a new TClonesArray of segments.
291 /// It is the responsibility of the user to delete it afterward.
292 AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
294 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
295 AliMUONObjectPair *segment;
296 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
297 // first and second chambers (0...) in the station
298 Int_t ch1 = 2 * station;
302 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
303 segments->SetOwner(kTRUE);
305 // Loop over HitForRec's in the first chamber of the station
306 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
307 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
310 // pointer to the HitForRec
311 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
312 // Loop over HitsForRec's in the second chamber of the station
313 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
314 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
317 // pointer to the HitForRec
318 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
319 if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. )
322 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
324 impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
325 // absolute value of bending momentum
326 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
329 AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
332 // check for bending momentum within tolerances
333 if ((bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum))
336 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
337 if (AliLog::GetGlobalDebugLevel() > 1) {
338 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
340 cout << "HitForRec in first chamber" << endl;
342 cout << "HitForRec in second chamber" << endl;
347 } // for (Int_t hit1...
348 AliDebug(1,Form("Station: %d NSegments: %d ", station, segments->GetEntriesFast()));
352 //__________________________________________________________________________
353 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
355 /// To remove identical tracks:
356 /// Tracks are considered identical if they have all their hits in common.
357 /// One keeps the track with the larger number of hits if need be
358 AliMUONTrack *track1, *track2, *trackToRemove;
359 Int_t hitsInCommon, nHits1, nHits2;
360 Bool_t removedTrack1;
361 // Loop over first track of the pair
362 track1 = (AliMUONTrack*) fRecTracksPtr->First();
364 removedTrack1 = kFALSE;
365 nHits1 = track1->GetNTrackHits();
366 // Loop over second track of the pair
367 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
369 nHits2 = track2->GetNTrackHits();
370 // number of hits in common between two tracks
371 hitsInCommon = track1->HitsInCommon(track2);
372 // check for identical tracks
373 if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
374 // decide which track to remove
375 if (nHits2 > nHits1) {
376 // remove track1 and continue the first loop with the track next to track1
377 trackToRemove = track1;
378 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
379 fRecTracksPtr->Remove(trackToRemove);
380 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
382 removedTrack1 = kTRUE;
385 // remove track2 and continue the second loop with the track next to track2
386 trackToRemove = track2;
387 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
388 fRecTracksPtr->Remove(trackToRemove);
389 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
392 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
394 if (removedTrack1) continue;
395 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
400 //__________________________________________________________________________
401 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
403 /// To remove double tracks:
404 /// Tracks are considered identical if more than half of the hits of the track
405 /// which has the smaller number of hits are in common with the other track.
406 /// Among two identical tracks, one keeps the track with the larger number of hits
407 /// or, if these numbers are equal, the track with the minimum chi2.
408 AliMUONTrack *track1, *track2, *trackToRemove;
409 Int_t hitsInCommon, nHits1, nHits2;
410 Bool_t removedTrack1;
411 // Loop over first track of the pair
412 track1 = (AliMUONTrack*) fRecTracksPtr->First();
414 removedTrack1 = kFALSE;
415 nHits1 = track1->GetNTrackHits();
416 // Loop over second track of the pair
417 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
419 nHits2 = track2->GetNTrackHits();
420 // number of hits in common between two tracks
421 hitsInCommon = track1->HitsInCommon(track2);
422 // check for identical tracks
423 if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
424 // decide which track to remove
425 if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
426 // remove track2 and continue the second loop with the track next to track2
427 trackToRemove = track2;
428 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
429 fRecTracksPtr->Remove(trackToRemove);
430 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
433 // else remove track1 and continue the first loop with the track next to track1
434 trackToRemove = track1;
435 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
436 fRecTracksPtr->Remove(trackToRemove);
437 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
439 removedTrack1 = kTRUE;
442 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
444 if (removedTrack1) continue;
445 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
450 //__________________________________________________________________________
451 Double_t AliMUONVTrackReconstructor::TryOneHitForRec(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec,
452 AliMUONTrackParam &trackParamAtHit, Bool_t updatePropagator)
454 /// Test the compatibility between the track and the hitForRec (using trackParam's covariance matrix):
455 /// return the corresponding Chi2
456 /// return trackParamAtHit
458 // extrapolate track parameters and covariances at the z position of the tested hit
459 trackParamAtHit = trackParam;
460 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtHit, hitForRec->GetZ(), updatePropagator);
462 // set pointer to hit into trackParamAtHit
463 trackParamAtHit.SetHitForRecPtr(hitForRec);
465 // Set differences between trackParam and hitForRec in the bending and non bending directions
466 Double_t dX = hitForRec->GetNonBendingCoor() - trackParamAtHit.GetNonBendingCoor();
467 Double_t dY = hitForRec->GetBendingCoor() - trackParamAtHit.GetBendingCoor();
469 // Calculate errors and covariances
470 const TMatrixD& kParamCov = trackParamAtHit.GetCovariances();
471 Double_t sigma2X = kParamCov(0,0) + hitForRec->GetNonBendingReso2();
472 Double_t sigma2Y = kParamCov(2,2) + hitForRec->GetBendingReso2();
475 return dX * dX / sigma2X + dY * dY / sigma2Y;
479 //__________________________________________________________________________
480 Bool_t AliMUONVTrackReconstructor::TryOneHitForRecFast(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec)
482 /// Test the compatibility between the track and the hitForRec within a wide fix window
483 /// assuming linear propagation of the track:
484 /// return kTRUE if they are compatibles
486 Double_t dZ = hitForRec->GetZ() - trackParam.GetZ();
487 Double_t dX = hitForRec->GetNonBendingCoor() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
488 Double_t dY = hitForRec->GetBendingCoor() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
490 if (TMath::Abs(dX) > fgkMaxTrackingDistanceNonBending || TMath::Abs(dY) > fgkMaxTrackingDistanceBending) return kFALSE;
496 //__________________________________________________________________________
497 Double_t AliMUONVTrackReconstructor::TryTwoHitForRecFast(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2,
498 AliMUONTrackParam &trackParamAtHit2)
500 /// Test the compatibility between the track and the 2 hitForRec together (using trackParam's covariance matrix)
501 /// assuming linear propagation between the two hits:
502 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
503 /// return trackParamAtHit1 & 2
505 // extrapolate linearly track parameters at the z position of the second hit
506 trackParamAtHit2 = trackParamAtHit1;
507 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtHit2, hitForRec2->GetZ());
509 // set pointer to hit2 into trackParamAtHit2
510 trackParamAtHit2.SetHitForRecPtr(hitForRec2);
512 // Set differences between track and hitForRec in the bending and non bending directions
513 AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr();
514 Double_t dX1 = hitForRec1->GetNonBendingCoor() - trackParamAtHit1.GetNonBendingCoor();
515 Double_t dX2 = hitForRec2->GetNonBendingCoor() - trackParamAtHit2.GetNonBendingCoor();
516 Double_t dY1 = hitForRec1->GetBendingCoor() - trackParamAtHit1.GetBendingCoor();
517 Double_t dY2 = hitForRec2->GetBendingCoor() - trackParamAtHit2.GetBendingCoor();
519 // Calculate errors and covariances
520 const TMatrixD& kParamCov1 = trackParamAtHit1.GetCovariances();
521 const TMatrixD& kParamCov2 = trackParamAtHit2.GetCovariances();
522 Double_t dZ = trackParamAtHit2.GetZ() - trackParamAtHit1.GetZ();
523 Double_t sigma2X1 = kParamCov1(0,0) + hitForRec1->GetNonBendingReso2();
524 Double_t sigma2X2 = kParamCov2(0,0) + hitForRec2->GetNonBendingReso2();
525 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
526 Double_t sigma2Y1 = kParamCov1(2,2) + hitForRec1->GetBendingReso2();
527 Double_t sigma2Y2 = kParamCov2(2,2) + hitForRec2->GetBendingReso2();
528 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
531 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
532 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
533 if (detX == 0. || detY == 0.) return 1.e10;
534 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
535 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
539 //__________________________________________________________________________
540 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation)
542 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible HitForRec(s)
543 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
544 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
545 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
546 /// Remove the obsolete "trackCandidate" at the end.
547 /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
548 /// return kTRUE if new hits have been found (otherwise return kFALSE)
549 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
551 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
552 // - nextStation == station(1...) 5 => forward propagation
553 // - nextStation < station(1...) 5 => backward propagation
555 if (nextStation==4) {
556 ch1 = 2*nextStation+1;
560 ch2 = 2*nextStation+1;
563 Double_t chi2WithOneHitForRec = 1.e10;
564 Double_t chi2WithTwoHitForRec = 1.e10;
565 Double_t maxChi2WithOneHitForRec = 2. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 2 because 2 quantities in chi2
566 Double_t maxChi2WithTwoHitForRec = 4. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 4 because 4 quantities in chi2
567 Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
568 Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
569 Bool_t foundOneHit = kFALSE;
570 Bool_t foundTwoHits = kFALSE;
571 AliMUONTrack *newTrack = 0x0;
572 AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
573 AliMUONTrackParam extrapTrackParamAtHit1;
574 AliMUONTrackParam extrapTrackParamAtHit2;
575 AliMUONTrackParam bestTrackParamAtHit1;
576 AliMUONTrackParam bestTrackParamAtHit2;
577 Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
578 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
580 // Get track parameters
581 AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First());
584 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
586 // Printout for debuging
587 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
588 cout << "FollowLinearTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
591 // look for candidates in chamber 2
592 for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
594 hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
596 // try to add the current hit fast
597 if (!TryOneHitForRecFast(trackParam, hitForRecCh2)) continue;
599 // try to add the current hit accuratly
600 extrapTrackParamAtHit2 = trackParam;
601 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit2, hitForRecCh2->GetZ());
602 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit2, hitForRecCh2, extrapTrackParamAtHit2);
604 // if good chi2 then try to attach a hitForRec in the other chamber too
605 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
606 Bool_t foundSecondHit = kFALSE;
608 // Printout for debuging
609 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
610 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch2+1
611 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
612 cout << " look for second hits in chamber(1..): " << ch1+1 << " ..." << endl;
616 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.);
618 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
620 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
622 // try to add the current hit fast
623 if (!TryOneHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1)) continue;
625 // try to add the current hit in addition to the one found on the previous chamber
626 chi2WithTwoHitForRec = TryTwoHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1);
628 // if good chi2 then consider to add the 2 hitForRec to the "trackCandidate"
629 if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
630 foundSecondHit = kTRUE;
631 foundTwoHits = kTRUE;
633 // Printout for debuging
634 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
635 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
636 << " (Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
639 if (fgkTrackAllTracks) {
640 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
641 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
642 extrapTrackParamAtHit1.SetRemovable(kTRUE);
643 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
644 extrapTrackParamAtHit2.SetRemovable(kTRUE);
645 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
646 newTrack->GetTrackParamAtHit()->Sort();
649 // Tag hitForRecCh1 as used
650 hitForRecCh1Used[hit1] = kTRUE;
652 // Printout for debuging
653 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
654 cout << "FollowLinearTrackInStation: added two hits in station(1..): " << nextStation+1 << endl;
655 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
658 } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
659 // keep track of the best couple of hits
660 bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
661 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
662 bestTrackParamAtHit2 = extrapTrackParamAtHit2;
669 // if no hitForRecCh1 found then consider to add hitForRecCh2 only
670 if (!foundSecondHit) {
673 if (fgkTrackAllTracks) {
674 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
675 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
676 extrapTrackParamAtHit2.SetRemovable(kFALSE);
677 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
678 newTrack->GetTrackParamAtHit()->Sort();
681 // Printout for debuging
682 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
683 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl;
684 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
687 } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
688 // keep track of the best single hitForRec except if a couple of hits has already been found
689 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
690 bestTrackParamAtHit1 = extrapTrackParamAtHit2;
699 // look for candidates in chamber 1 not already attached to a track
700 // if we want to keep all possible tracks or if no good couple of hitForRec has been found
701 if (fgkTrackAllTracks || !foundTwoHits) {
703 // Printout for debuging
704 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
705 cout << "FollowLinearTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
708 //Extrapolate trackCandidate to chamber "ch2"
709 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
711 // add MCS effect for next step
712 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
714 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
716 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
718 if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
720 // try to add the current hit fast
721 if (!TryOneHitForRecFast(trackParam, hitForRecCh1)) continue;
723 // try to add the current hit accuratly
724 extrapTrackParamAtHit1 = trackParam;
725 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit1, hitForRecCh1->GetZ());
726 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit1, hitForRecCh1, extrapTrackParamAtHit1);
728 // if good chi2 then consider to add hitForRecCh1
729 // We do not try to attach a hitForRec in the other chamber too since it has already been done above
730 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
733 // Printout for debuging
734 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
735 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
736 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
739 if (fgkTrackAllTracks) {
740 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
741 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
742 extrapTrackParamAtHit1.SetRemovable(kFALSE);
743 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
744 newTrack->GetTrackParamAtHit()->Sort();
747 // Printout for debuging
748 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
749 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl;
750 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
753 } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
754 // keep track of the best single hitForRec except if a couple of hits has already been found
755 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
756 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
765 // fill out the best track if required else clean up the fRecTracksPtr array
766 if (!fgkTrackAllTracks) {
768 bestTrackParamAtHit1.SetRemovable(kTRUE);
769 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
770 bestTrackParamAtHit2.SetRemovable(kTRUE);
771 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit2,bestTrackParamAtHit2.GetHitForRecPtr());
772 trackCandidate.GetTrackParamAtHit()->Sort();
774 // Printout for debuging
775 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
776 cout << "FollowLinearTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl;
777 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
780 } else if (foundOneHit) {
781 bestTrackParamAtHit1.SetRemovable(kFALSE);
782 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
783 trackCandidate.GetTrackParamAtHit()->Sort();
785 // Printout for debuging
786 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
787 cout << "FollowLinearTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl;
788 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
792 delete [] hitForRecCh1Used;
796 } else if (foundOneHit || foundTwoHits) {
798 // remove obsolete track
799 fRecTracksPtr->Remove(&trackCandidate);
803 delete [] hitForRecCh1Used;
807 delete [] hitForRecCh1Used;
812 //__________________________________________________________________________
813 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
814 const AliMUONVTriggerTrackStore& triggerTrackStore,
815 const AliMUONVTriggerStore& triggerStore,
816 const AliMUONTrackHitPattern& trackHitPattern)
818 /// Try to match track from tracking system with trigger track
819 static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
823 Double_t distTriggerTrack[3];
824 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
826 TIter itTrack(trackStore.CreateIterator());
829 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
832 chi2MatchTrigger = 0.;
834 Int_t doubleMatch=-1; // Check if track matches 2 trigger tracks
835 Double_t doubleChi2 = -1.;
837 AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last())));
838 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
840 xTrack = trackParam.GetNonBendingCoor();
841 yTrack = trackParam.GetBendingCoor();
842 ySlopeTrack = trackParam.GetBendingSlope();
843 minChi2MatchTrigger = 999.;
845 AliMUONTriggerTrack *triggerTrack;
846 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
847 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
849 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
850 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
851 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
853 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
854 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
855 if (chi2 < fMaxNormChi2MatchTrigger)
857 Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
858 if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger)
862 doubleMatch = loTrgNum;
863 doubleChi2 = chi2MatchTrigger;
865 minChi2MatchTrigger = chi2;
866 chi2MatchTrigger = chi2;
867 loTrgNum = triggerTrack->GetLoTrgNum();
868 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
870 if(locTrg->LoLpt()>0)matchTrigger=2;
871 if(locTrg->LoHpt()>0)matchTrigger=3;
873 else if(isDoubleTrack)
875 doubleMatch = triggerTrack->GetLoTrgNum();
881 { // If two trigger tracks match, select the one passing more trigger cuts
882 AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
883 AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
884 if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
886 if(locTrg1->LoHpt()>0)matchTrigger=3;
888 loTrgNum = doubleMatch;
889 chi2MatchTrigger=doubleChi2;
893 track->SetMatchTrigger(matchTrigger);
894 track->SetLoTrgNum(loTrgNum);
895 track->SetChi2MatchTrigger(chi2MatchTrigger);
897 AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
901 track->SetLocalTrigger(locTrg->LoCircuit(),
910 trackHitPattern.GetHitPattern(trackStore,triggerStore);
913 //__________________________________________________________________________
914 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
915 const AliMUONVTriggerStore& triggerStore,
916 AliMUONVTriggerTrackStore& triggerTrackStore)
918 /// To make the trigger tracks from Local Trigger
921 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
923 UChar_t gloTrigPat = 0;
927 gloTrigPat = globalTrigger->GetGlobalResponse();
930 TIter next(triggerStore.CreateIterator());
931 AliMUONLocalTrigger* locTrg(0x0);
933 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
934 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
936 AliMUONTriggerTrack triggerTrack;
938 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
943 Int_t localBoardId = locTrg->LoCircuit();
944 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
945 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
946 else xTrig=kTRUE; // trigger in X
947 if (locTrg->LoTrigY()==1 &&
948 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
949 else yTrig = kTRUE; // trigger in Y
952 { // make Trigger Track if trigger in X and Y
954 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
955 // need first to convert deviation to [0-30]
956 // (see AliMUONLocalTriggerBoard::LocalTrigger)
957 Int_t deviation = locTrg->LoDev();
959 if ( !locTrg->LoSdev() && deviation ) sign=-1;
960 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
961 if ( locTrg->LoSdev() == 1 ) sign=+1;
964 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
965 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
966 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
968 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
969 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
971 Float_t thetax = TMath::ATan2( x11 , z11 );
972 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
974 triggerTrack.SetX11(x11);
975 triggerTrack.SetY11(y11);
976 triggerTrack.SetThetax(thetax);
977 triggerTrack.SetThetay(thetay);
978 triggerTrack.SetGTPattern(gloTrigPat);
979 triggerTrack.SetLoTrgNum(localBoardId);
981 triggerTrackStore.Add(triggerTrack);
983 } // end of loop on Local Trigger