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 "AliCodeTimer.h"
75 #include "AliTracker.h"
77 #include <TClonesArray.h>
81 #include <Riostream.h>
84 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
88 //************* Defaults parameters for reconstruction
89 const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
90 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
91 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
92 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceBending = 2.;
93 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceNonBending = 2.;
95 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForTracking = 6.0;
96 const Bool_t AliMUONVTrackReconstructor::fgkMakeTrackCandidatesFast = kFALSE;
97 const Bool_t AliMUONVTrackReconstructor::fgkTrackAllTracks = kTRUE;
98 const Bool_t AliMUONVTrackReconstructor::fgkRecoverTracks = kTRUE;
99 const Bool_t AliMUONVTrackReconstructor::fgkComplementTracks = kTRUE;
100 const Bool_t AliMUONVTrackReconstructor::fgkImproveTracks = kTRUE;
101 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForImprovement = 5.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
171 AliCodeTimerAuto("");
175 AddHitsForRecFromRawClusters(clusterStore);
178 // Add tracks to MUON data container
179 for (Int_t i=0; i<fNRecTracks; ++i)
181 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
182 trackStore.Add(*track);
186 //__________________________________________________________________________
187 void AliMUONVTrackReconstructor::AddHitsForRecFromRawClusters(const AliMUONVClusterStore& clusterStore)
189 /// Build internal array of hit for rec from clusterStore
191 TIter next(clusterStore.CreateIterator());
192 AliMUONRawCluster* clus(0x0);
195 while ( ( clus = static_cast<AliMUONRawCluster*>(next()) ) )
197 // new AliMUONHitForRec from raw cluster
198 // and increment number of AliMUONHitForRec's (total and in chamber)
199 AliMUONHitForRec* hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
201 // more information into HitForRec
202 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
203 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
204 // original raw cluster
205 Int_t ch = AliMpDEManager::GetChamberId(clus->GetDetElemId());
206 hitForRec->SetChamberNumber(ch);
207 hitForRec->SetHitNumber(iclus);
208 // Z coordinate of the raw cluster (cm)
209 hitForRec->SetZ(clus->GetZ());
210 if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
211 cout << "Chamber " << ch <<" raw cluster " << iclus << " : " << endl;
213 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
214 hitForRec->Print("full");
217 } // end of chamber loop
219 SortHitsForRecWithIncreasingChamber();
221 AliDebug(1,"End of AddHitsForRecFromRawClusters");
223 if (AliLog::GetGlobalDebugLevel() > 0)
225 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
226 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++)
228 AliDebug(1, Form("Chamber(0...): %d",ch));
229 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
230 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
231 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
232 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
234 AliDebug(1, Form("HitForRec index(0...): %d",hit));
235 ((*fHitsForRecPtr)[hit])->Dump();
241 //__________________________________________________________________________
242 void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
244 /// Sort HitsForRec's in increasing order with respect to chamber number.
245 /// Uses the function "Compare".
246 /// Update the information for HitsForRec per chamber too.
247 Int_t ch, nhits, prevch;
248 fHitsForRecPtr->Sort();
249 for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
250 fNHitsForRecPerChamber[ch] = 0;
251 fIndexOfFirstHitForRecPerChamber[ch] = 0;
253 prevch = 0; // previous chamber
254 nhits = 0; // number of hits in current chamber
255 // Loop over HitsForRec
256 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
257 // chamber number (0...)
258 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
259 // increment number of hits in current chamber
260 (fNHitsForRecPerChamber[ch])++;
261 // update index of first HitForRec in current chamber
262 // if chamber number different from previous one
264 fIndexOfFirstHitForRecPerChamber[ch] = hit;
271 //__________________________________________________________________________
272 void AliMUONVTrackReconstructor::MakeTracks()
274 /// To make the tracks from the list of segments and points in all stations
275 AliDebug(1,"Enter MakeTracks");
276 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
277 MakeTrackCandidates();
278 if (fRecTracksPtr->GetEntriesFast() == 0) return;
279 // Follow tracks in stations(1..) 3, 2 and 1
281 // Complement the reconstructed tracks
282 if (fgkComplementTracks) ComplementTracks();
283 // Improve the reconstructed tracks
284 if (fgkImproveTracks) ImproveTracks();
285 // Remove double tracks
286 RemoveDoubleTracks();
287 // Fill AliMUONTrack data members
291 //__________________________________________________________________________
292 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
294 /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
295 /// Return a new TClonesArray of segments.
296 /// It is the responsibility of the user to delete it afterward.
297 AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
299 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
300 AliMUONObjectPair *segment;
301 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
302 // first and second chambers (0...) in the station
303 Int_t ch1 = 2 * station;
307 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
308 segments->SetOwner(kTRUE);
310 // Loop over HitForRec's in the first chamber of the station
311 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
312 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
315 // pointer to the HitForRec
316 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
317 // Loop over HitsForRec's in the second chamber of the station
318 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
319 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
322 // pointer to the HitForRec
323 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
324 if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. )
327 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
329 impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
330 // absolute value of bending momentum
331 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
334 AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
337 // check for bending momentum within tolerances
338 if ((bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum))
341 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
342 if (AliLog::GetGlobalDebugLevel() > 1) {
343 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
345 cout << "HitForRec in first chamber" << endl;
347 cout << "HitForRec in second chamber" << endl;
352 } // for (Int_t hit1...
353 AliDebug(1,Form("Station: %d NSegments: %d ", station, segments->GetEntriesFast()));
357 //__________________________________________________________________________
358 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
360 /// To remove identical tracks:
361 /// Tracks are considered identical if they have all their hits in common.
362 /// One keeps the track with the larger number of hits if need be
363 AliMUONTrack *track1, *track2, *trackToRemove;
364 Int_t hitsInCommon, nHits1, nHits2;
365 Bool_t removedTrack1;
366 // Loop over first track of the pair
367 track1 = (AliMUONTrack*) fRecTracksPtr->First();
369 removedTrack1 = kFALSE;
370 nHits1 = track1->GetNTrackHits();
371 // Loop over second track of the pair
372 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
374 nHits2 = track2->GetNTrackHits();
375 // number of hits in common between two tracks
376 hitsInCommon = track1->HitsInCommon(track2);
377 // check for identical tracks
378 if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
379 // decide which track to remove
380 if (nHits2 > nHits1) {
381 // remove track1 and continue the first loop with the track next to track1
382 trackToRemove = track1;
383 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
384 fRecTracksPtr->Remove(trackToRemove);
385 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
387 removedTrack1 = kTRUE;
390 // remove track2 and continue the second loop with the track next to track2
391 trackToRemove = track2;
392 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
393 fRecTracksPtr->Remove(trackToRemove);
394 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
397 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
399 if (removedTrack1) continue;
400 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
405 //__________________________________________________________________________
406 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
408 /// To remove double tracks:
409 /// Tracks are considered identical if more than half of the hits of the track
410 /// which has the smaller number of hits are in common with the other track.
411 /// Among two identical tracks, one keeps the track with the larger number of hits
412 /// or, if these numbers are equal, the track with the minimum chi2.
413 AliMUONTrack *track1, *track2, *trackToRemove;
414 Int_t hitsInCommon, nHits1, nHits2;
415 Bool_t removedTrack1;
416 // Loop over first track of the pair
417 track1 = (AliMUONTrack*) fRecTracksPtr->First();
419 removedTrack1 = kFALSE;
420 nHits1 = track1->GetNTrackHits();
421 // Loop over second track of the pair
422 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
424 nHits2 = track2->GetNTrackHits();
425 // number of hits in common between two tracks
426 hitsInCommon = track1->HitsInCommon(track2);
427 // check for identical tracks
428 if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
429 // decide which track to remove
430 if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
431 // remove track2 and continue the second loop with the track next to track2
432 trackToRemove = track2;
433 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
434 fRecTracksPtr->Remove(trackToRemove);
435 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
438 // else remove track1 and continue the first loop with the track next to track1
439 trackToRemove = track1;
440 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
441 fRecTracksPtr->Remove(trackToRemove);
442 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
444 removedTrack1 = kTRUE;
447 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
449 if (removedTrack1) continue;
450 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
455 //__________________________________________________________________________
456 Double_t AliMUONVTrackReconstructor::TryOneHitForRec(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec,
457 AliMUONTrackParam &trackParamAtHit, Bool_t updatePropagator)
459 /// Test the compatibility between the track and the hitForRec (using trackParam's covariance matrix):
460 /// return the corresponding Chi2
461 /// return trackParamAtHit
463 // extrapolate track parameters and covariances at the z position of the tested hit
464 trackParamAtHit = trackParam;
465 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtHit, hitForRec->GetZ(), updatePropagator);
467 // set pointer to hit into trackParamAtHit
468 trackParamAtHit.SetHitForRecPtr(hitForRec);
470 // Set differences between trackParam and hitForRec in the bending and non bending directions
471 Double_t dX = hitForRec->GetNonBendingCoor() - trackParamAtHit.GetNonBendingCoor();
472 Double_t dY = hitForRec->GetBendingCoor() - trackParamAtHit.GetBendingCoor();
474 // Calculate errors and covariances
475 const TMatrixD& kParamCov = trackParamAtHit.GetCovariances();
476 Double_t sigma2X = kParamCov(0,0) + hitForRec->GetNonBendingReso2();
477 Double_t sigma2Y = kParamCov(2,2) + hitForRec->GetBendingReso2();
480 return dX * dX / sigma2X + dY * dY / sigma2Y;
484 //__________________________________________________________________________
485 Bool_t AliMUONVTrackReconstructor::TryOneHitForRecFast(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec)
487 /// Test the compatibility between the track and the hitForRec within a wide fix window
488 /// assuming linear propagation of the track:
489 /// return kTRUE if they are compatibles
491 Double_t dZ = hitForRec->GetZ() - trackParam.GetZ();
492 Double_t dX = hitForRec->GetNonBendingCoor() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
493 Double_t dY = hitForRec->GetBendingCoor() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
495 if (TMath::Abs(dX) > fgkMaxTrackingDistanceNonBending || TMath::Abs(dY) > fgkMaxTrackingDistanceBending) return kFALSE;
501 //__________________________________________________________________________
502 Double_t AliMUONVTrackReconstructor::TryTwoHitForRecFast(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2,
503 AliMUONTrackParam &trackParamAtHit2)
505 /// Test the compatibility between the track and the 2 hitForRec together (using trackParam's covariance matrix)
506 /// assuming linear propagation between the two hits:
507 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
508 /// return trackParamAtHit1 & 2
510 // extrapolate linearly track parameters at the z position of the second hit
511 trackParamAtHit2 = trackParamAtHit1;
512 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtHit2, hitForRec2->GetZ());
514 // set pointer to hit2 into trackParamAtHit2
515 trackParamAtHit2.SetHitForRecPtr(hitForRec2);
517 // Set differences between track and hitForRec in the bending and non bending directions
518 AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr();
519 Double_t dX1 = hitForRec1->GetNonBendingCoor() - trackParamAtHit1.GetNonBendingCoor();
520 Double_t dX2 = hitForRec2->GetNonBendingCoor() - trackParamAtHit2.GetNonBendingCoor();
521 Double_t dY1 = hitForRec1->GetBendingCoor() - trackParamAtHit1.GetBendingCoor();
522 Double_t dY2 = hitForRec2->GetBendingCoor() - trackParamAtHit2.GetBendingCoor();
524 // Calculate errors and covariances
525 const TMatrixD& kParamCov1 = trackParamAtHit1.GetCovariances();
526 const TMatrixD& kParamCov2 = trackParamAtHit2.GetCovariances();
527 Double_t dZ = trackParamAtHit2.GetZ() - trackParamAtHit1.GetZ();
528 Double_t sigma2X1 = kParamCov1(0,0) + hitForRec1->GetNonBendingReso2();
529 Double_t sigma2X2 = kParamCov2(0,0) + hitForRec2->GetNonBendingReso2();
530 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
531 Double_t sigma2Y1 = kParamCov1(2,2) + hitForRec1->GetBendingReso2();
532 Double_t sigma2Y2 = kParamCov2(2,2) + hitForRec2->GetBendingReso2();
533 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
536 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
537 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
538 if (detX == 0. || detY == 0.) return 1.e10;
539 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
540 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
544 //__________________________________________________________________________
545 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation)
547 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible HitForRec(s)
548 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
549 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
550 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
551 /// Remove the obsolete "trackCandidate" at the end.
552 /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
553 /// return kTRUE if new hits have been found (otherwise return kFALSE)
554 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
556 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
557 // - nextStation == station(1...) 5 => forward propagation
558 // - nextStation < station(1...) 5 => backward propagation
560 if (nextStation==4) {
561 ch1 = 2*nextStation+1;
565 ch2 = 2*nextStation+1;
568 Double_t chi2WithOneHitForRec = 1.e10;
569 Double_t chi2WithTwoHitForRec = 1.e10;
570 Double_t maxChi2WithOneHitForRec = 2. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 2 because 2 quantities in chi2
571 Double_t maxChi2WithTwoHitForRec = 4. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 4 because 4 quantities in chi2
572 Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
573 Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
574 Bool_t foundOneHit = kFALSE;
575 Bool_t foundTwoHits = kFALSE;
576 AliMUONTrack *newTrack = 0x0;
577 AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
578 AliMUONTrackParam extrapTrackParamAtHit1;
579 AliMUONTrackParam extrapTrackParamAtHit2;
580 AliMUONTrackParam bestTrackParamAtHit1;
581 AliMUONTrackParam bestTrackParamAtHit2;
582 Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
583 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
585 // Get track parameters
586 AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First());
589 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
591 // Printout for debuging
592 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
593 cout << "FollowLinearTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
596 // look for candidates in chamber 2
597 for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
599 hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
601 // try to add the current hit fast
602 if (!TryOneHitForRecFast(trackParam, hitForRecCh2)) continue;
604 // try to add the current hit accuratly
605 extrapTrackParamAtHit2 = trackParam;
606 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit2, hitForRecCh2->GetZ());
607 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit2, hitForRecCh2, extrapTrackParamAtHit2);
609 // if good chi2 then try to attach a hitForRec in the other chamber too
610 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
611 Bool_t foundSecondHit = kFALSE;
613 // Printout for debuging
614 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
615 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch2+1
616 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
617 cout << " look for second hits in chamber(1..): " << ch1+1 << " ..." << endl;
621 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.);
623 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
625 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
627 // try to add the current hit fast
628 if (!TryOneHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1)) continue;
630 // try to add the current hit in addition to the one found on the previous chamber
631 chi2WithTwoHitForRec = TryTwoHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1);
633 // if good chi2 then consider to add the 2 hitForRec to the "trackCandidate"
634 if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
635 foundSecondHit = kTRUE;
636 foundTwoHits = kTRUE;
638 // Printout for debuging
639 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
640 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
641 << " (Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
644 if (fgkTrackAllTracks) {
645 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
646 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
647 extrapTrackParamAtHit1.SetRemovable(kTRUE);
648 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
649 extrapTrackParamAtHit2.SetRemovable(kTRUE);
650 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
651 newTrack->GetTrackParamAtHit()->Sort();
654 // Tag hitForRecCh1 as used
655 hitForRecCh1Used[hit1] = kTRUE;
657 // Printout for debuging
658 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
659 cout << "FollowLinearTrackInStation: added two hits in station(1..): " << nextStation+1 << endl;
660 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
663 } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
664 // keep track of the best couple of hits
665 bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
666 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
667 bestTrackParamAtHit2 = extrapTrackParamAtHit2;
674 // if no hitForRecCh1 found then consider to add hitForRecCh2 only
675 if (!foundSecondHit) {
678 if (fgkTrackAllTracks) {
679 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
680 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
681 extrapTrackParamAtHit2.SetRemovable(kFALSE);
682 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
683 newTrack->GetTrackParamAtHit()->Sort();
686 // Printout for debuging
687 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
688 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl;
689 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
692 } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
693 // keep track of the best single hitForRec except if a couple of hits has already been found
694 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
695 bestTrackParamAtHit1 = extrapTrackParamAtHit2;
704 // look for candidates in chamber 1 not already attached to a track
705 // if we want to keep all possible tracks or if no good couple of hitForRec has been found
706 if (fgkTrackAllTracks || !foundTwoHits) {
708 // Printout for debuging
709 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
710 cout << "FollowLinearTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
713 //Extrapolate trackCandidate to chamber "ch2"
714 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
716 // add MCS effect for next step
717 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
719 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
721 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
723 if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
725 // try to add the current hit fast
726 if (!TryOneHitForRecFast(trackParam, hitForRecCh1)) continue;
728 // try to add the current hit accuratly
729 extrapTrackParamAtHit1 = trackParam;
730 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit1, hitForRecCh1->GetZ());
731 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit1, hitForRecCh1, extrapTrackParamAtHit1);
733 // if good chi2 then consider to add hitForRecCh1
734 // We do not try to attach a hitForRec in the other chamber too since it has already been done above
735 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
738 // Printout for debuging
739 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
740 cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
741 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
744 if (fgkTrackAllTracks) {
745 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
746 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
747 extrapTrackParamAtHit1.SetRemovable(kFALSE);
748 newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
749 newTrack->GetTrackParamAtHit()->Sort();
752 // Printout for debuging
753 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
754 cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl;
755 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
758 } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
759 // keep track of the best single hitForRec except if a couple of hits has already been found
760 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
761 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
770 // fill out the best track if required else clean up the fRecTracksPtr array
771 if (!fgkTrackAllTracks) {
773 bestTrackParamAtHit1.SetRemovable(kTRUE);
774 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
775 bestTrackParamAtHit2.SetRemovable(kTRUE);
776 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit2,bestTrackParamAtHit2.GetHitForRecPtr());
777 trackCandidate.GetTrackParamAtHit()->Sort();
779 // Printout for debuging
780 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
781 cout << "FollowLinearTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl;
782 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
785 } else if (foundOneHit) {
786 bestTrackParamAtHit1.SetRemovable(kFALSE);
787 trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
788 trackCandidate.GetTrackParamAtHit()->Sort();
790 // Printout for debuging
791 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
792 cout << "FollowLinearTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl;
793 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
797 delete [] hitForRecCh1Used;
801 } else if (foundOneHit || foundTwoHits) {
803 // remove obsolete track
804 fRecTracksPtr->Remove(&trackCandidate);
808 delete [] hitForRecCh1Used;
812 delete [] hitForRecCh1Used;
817 //__________________________________________________________________________
818 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
819 const AliMUONVTriggerTrackStore& triggerTrackStore,
820 const AliMUONVTriggerStore& triggerStore,
821 const AliMUONTrackHitPattern& trackHitPattern)
823 /// Try to match track from tracking system with trigger track
824 AliCodeTimerAuto("");
826 static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
830 Double_t distTriggerTrack[3];
831 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
833 TIter itTrack(trackStore.CreateIterator());
836 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
839 chi2MatchTrigger = 0.;
841 Int_t doubleMatch=-1; // Check if track matches 2 trigger tracks
842 Double_t doubleChi2 = -1.;
844 AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last())));
845 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
847 xTrack = trackParam.GetNonBendingCoor();
848 yTrack = trackParam.GetBendingCoor();
849 ySlopeTrack = trackParam.GetBendingSlope();
850 minChi2MatchTrigger = 999.;
852 AliMUONTriggerTrack *triggerTrack;
853 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
854 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
856 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
857 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
858 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
860 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
861 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
862 if (chi2 < fMaxNormChi2MatchTrigger)
864 Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
865 if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger)
869 doubleMatch = loTrgNum;
870 doubleChi2 = chi2MatchTrigger;
872 minChi2MatchTrigger = chi2;
873 chi2MatchTrigger = chi2;
874 loTrgNum = triggerTrack->GetLoTrgNum();
875 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
877 if(locTrg->LoLpt()>0)matchTrigger=2;
878 if(locTrg->LoHpt()>0)matchTrigger=3;
880 else if(isDoubleTrack)
882 doubleMatch = triggerTrack->GetLoTrgNum();
888 { // If two trigger tracks match, select the one passing more trigger cuts
889 AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
890 AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
891 if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
893 if(locTrg1->LoHpt()>0)matchTrigger=3;
895 loTrgNum = doubleMatch;
896 chi2MatchTrigger=doubleChi2;
900 track->SetMatchTrigger(matchTrigger);
901 track->SetLoTrgNum(loTrgNum);
902 track->SetChi2MatchTrigger(chi2MatchTrigger);
904 AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
908 track->SetLocalTrigger(locTrg->LoCircuit(),
917 trackHitPattern.GetHitPattern(trackStore,triggerStore);
920 //__________________________________________________________________________
921 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
922 const AliMUONVTriggerStore& triggerStore,
923 AliMUONVTriggerTrackStore& triggerTrackStore)
925 /// To make the trigger tracks from Local Trigger
927 AliCodeTimerAuto("");
929 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
931 UChar_t gloTrigPat = 0;
935 gloTrigPat = globalTrigger->GetGlobalResponse();
938 TIter next(triggerStore.CreateIterator());
939 AliMUONLocalTrigger* locTrg(0x0);
941 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
942 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
944 AliMUONTriggerTrack triggerTrack;
946 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
951 Int_t localBoardId = locTrg->LoCircuit();
952 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
953 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
954 else xTrig=kTRUE; // trigger in X
955 if (locTrg->LoTrigY()==1 &&
956 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
957 else yTrig = kTRUE; // trigger in Y
960 { // make Trigger Track if trigger in X and Y
962 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
963 // need first to convert deviation to [0-30]
964 // (see AliMUONLocalTriggerBoard::LocalTrigger)
965 Int_t deviation = locTrg->LoDev();
967 if ( !locTrg->LoSdev() && deviation ) sign=-1;
968 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
969 if ( locTrg->LoSdev() == 1 ) sign=+1;
972 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
973 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
974 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
976 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
977 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
979 Float_t thetax = TMath::ATan2( x11 , z11 );
980 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
982 triggerTrack.SetX11(x11);
983 triggerTrack.SetY11(y11);
984 triggerTrack.SetThetax(thetax);
985 triggerTrack.SetThetay(thetay);
986 triggerTrack.SetGTPattern(gloTrigPat);
987 triggerTrack.SetLoTrgNum(localBoardId);
989 triggerTrackStore.Add(triggerTrack);
991 } // end of loop on Local Trigger