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 AliMUONTrackReconstructor
20 /// MUON track reconstructor using the original method
22 /// This class contains as data:
23 /// - the parameters for the track reconstruction
25 /// It contains as methods, among others:
26 /// - MakeTracks to build the tracks
27 //-----------------------------------------------------------------------------
29 #include "AliMUONTrackReconstructor.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONVCluster.h"
33 #include "AliMUONVClusterServer.h"
34 #include "AliMUONVClusterStore.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTrackParam.h"
37 #include "AliMUONTrackExtrap.h"
39 #include "AliMpArea.h"
44 #include <Riostream.h>
48 // Functions to be minimized with Minuit
49 void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag);
52 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
55 //__________________________________________________________________________
56 AliMUONTrackReconstructor::AliMUONTrackReconstructor(AliMUONVClusterServer* clusterServer)
57 : AliMUONVTrackReconstructor(clusterServer)
62 //__________________________________________________________________________
63 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
68 //__________________________________________________________________________
69 void AliMUONTrackReconstructor::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
71 /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
72 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
73 /// Good candidates are made of at least three clusters.
74 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
76 TClonesArray *segments;
81 AliDebug(1,"Enter MakeTrackCandidates");
83 // Unless we're doing combined tracking, we'll clusterize all stations at once
84 Int_t firstChamber(0);
87 if (AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco()) {
88 // ... Here's the exception : ask the clustering to reconstruct
89 // clusters *only* in station 4 and 5 for combined tracking
93 for (Int_t i = firstChamber; i <= lastChamber; ++i )
95 if (fClusterServer && AliMUONReconstructor::GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea());
98 // Loop over stations(1..) 5 and 4 and make track candidates
99 for (Int_t istat=4; istat>=3; istat--) {
101 // Make segments in the station
102 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
104 // Loop over segments
105 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
107 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
109 // Transform segments to tracks and put them at the end of fRecTracksPtr
110 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]));
113 // Look for compatible cluster(s) in the other station
114 if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast())
115 clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
116 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
118 // Remove track if no cluster found
119 if (!clusterFound && AliMUONReconstructor::GetRecoParam()->RequestStation(7-istat)) {
120 fRecTracksPtr->Remove(track);
126 // delete the array of segments
130 fRecTracksPtr->Compress(); // this is essential before checking tracks
132 // Keep all different tracks or only the best ones as required
133 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
134 else RemoveDoubleTracks();
136 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
140 //__________________________________________________________________________
141 void AliMUONTrackReconstructor::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
143 /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
144 /// clustering is supposed to be already done
145 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
146 /// Good candidates are made of at least three clusters if both station are requested (two otherwise).
147 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
149 TClonesArray *segments;
151 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
154 AliDebug(1,"Enter MakeMoreTrackCandidates");
156 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
157 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
158 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
160 // Make segments in the station
161 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
163 // Loop over segments
164 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
166 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
168 // Transform segments to tracks and put them at the end of fRecTracksPtr
169 iCurrentTrack = fRecTracksPtr->GetLast()+1;
170 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]));
173 // Look for compatible cluster(s) in the second chamber of station 5
174 if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast())
175 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
176 else clusterFound = FollowTrackInChamber(*track, clusterStore, 17-ich2);
178 // skip the original track in case it has been removed
179 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
181 // loop over every new tracks
182 nCurrentTracks = fRecTracksPtr->GetLast()+1;
183 while (iCurrentTrack < nCurrentTracks) {
184 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
186 // Look for compatible cluster(s) in the second chamber of station 4
187 if (AliMUONReconstructor::GetRecoParam()->MakeTrackCandidatesFast())
188 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
189 else FollowTrackInChamber(*track, clusterStore, 13-ich1);
196 // delete the array of segments
201 fRecTracksPtr->Compress(); // this is essential before checking tracks
203 // Keep all different tracks or only the best ones as required
204 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
205 else RemoveDoubleTracks();
207 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
211 //__________________________________________________________________________
212 void AliMUONTrackReconstructor::FollowTracks(AliMUONVClusterStore& clusterStore)
214 /// Follow tracks in stations(1..) 3, 2 and 1
215 AliDebug(1,"Enter FollowTracks");
217 AliMUONTrack *track, *nextTrack;
218 AliMUONTrackParam *trackParam, *nextTrackParam;
219 Int_t currentNRecTracks;
221 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
222 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking();
224 for (Int_t station = 2; station >= 0; station--) {
226 // Save the actual number of reconstructed track in case of
227 // tracks are added or suppressed during the tracking procedure
228 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
229 currentNRecTracks = fNRecTracks;
231 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
232 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
234 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
237 // Do not take into account the multiple scattering to speed up the fit
238 // Calculate the track parameter covariance matrix
239 // If there is no cluster out of station 4 or 5 then use the vertex to better constrain the fit
240 if (((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetClusterPtr()->GetChamberId() > 5)
241 Fit(*track, kFALSE, kTRUE, kTRUE);
242 else Fit(*track, kFALSE, kFALSE, kTRUE);
244 // remove track with absolute bending momentum out of limits
245 // or if the normalized chi2 is too high
246 Double_t bendingMomentum = TMath::Abs(1. / ((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First())->GetInverseBendingMomentum());
247 if (bendingMomentum < AliMUONReconstructor::GetRecoParam()->GetMinBendingMomentum() ||
248 bendingMomentum > AliMUONReconstructor::GetRecoParam()->GetMaxBendingMomentum() ||
249 track->GetNormalizedChi2() > sigmaCut2) {
250 fRecTracksPtr->Remove(track);
255 // save parameters from fit into smoothed parameters to complete track afterward
256 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) {
258 if (station==2) { // save track parameters on stations 4 and 5
260 // extrapolate track parameters and covariances at each cluster
261 track->UpdateCovTrackParamAtCluster();
264 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
266 trackParam->SetSmoothParameters(trackParam->GetParameters());
267 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
268 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
271 } else { // or save track parameters on last station only
273 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
274 if (trackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
276 // save parameters from fit
277 trackParam->SetSmoothParameters(trackParam->GetParameters());
278 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
280 // save parameters extrapolated to the second chamber of the same station if it has been hit
281 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
282 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
284 // reset parameters and covariances
285 nextTrackParam->SetParameters(trackParam->GetParameters());
286 nextTrackParam->SetZ(trackParam->GetZ());
287 nextTrackParam->SetCovariances(trackParam->GetCovariances());
289 // extrapolate them to the z of the corresponding cluster
290 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
293 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
294 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
304 // Look for compatible cluster(s) in station(0..) "station"
305 if (!FollowTrackInStation(*track, clusterStore, station)) {
307 // Try to recover track if required
308 if (AliMUONReconstructor::GetRecoParam()->RecoverTracks()) {
310 // work on a copy of the track if this station is not required
311 // to keep the case where no cluster is reconstructed as a possible candidate
312 if (!AliMUONReconstructor::GetRecoParam()->RequestStation(station)) {
313 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
318 if (!RecoverTrack(*track, clusterStore, station)) {
319 // remove track if no cluster found
320 fRecTracksPtr->Remove(track);
324 } else if (AliMUONReconstructor::GetRecoParam()->RequestStation(station)) {
325 // remove track if no cluster found
326 fRecTracksPtr->Remove(track);
334 // Compress fRecTracksPtr for the next step
335 fRecTracksPtr->Compress();
337 // Keep only the best tracks if required
338 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
342 // Last fit of track candidates with all stations
343 // Take into account the multiple scattering and remove bad tracks
344 Int_t trackIndex = -1;
345 track = (AliMUONTrack*) fRecTracksPtr->First();
349 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
351 Fit(*track, kTRUE, kFALSE, kTRUE);
353 // Printout for debuging
354 if (AliLog::GetGlobalDebugLevel() >= 3) {
355 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
356 track->RecursiveDump();
359 // Remove the track if the normalized chi2 is too high
360 if (track->GetNormalizedChi2() > sigmaCut2) {
361 fRecTracksPtr->Remove(track);
367 // save parameters from fit into smoothed parameters to complete track afterward
368 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) {
370 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
371 if (trackParam->GetClusterPtr()->GetChamberId() < 2) {
373 // save parameters from fit
374 trackParam->SetSmoothParameters(trackParam->GetParameters());
375 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
377 // save parameters extrapolated to the second chamber of the same station if it has been hit
378 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
379 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
381 // reset parameters and covariances
382 nextTrackParam->SetParameters(trackParam->GetParameters());
383 nextTrackParam->SetZ(trackParam->GetZ());
384 nextTrackParam->SetCovariances(trackParam->GetCovariances());
386 // extrapolate them to the z of the corresponding cluster
387 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
390 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
391 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
403 fRecTracksPtr->Compress();
407 //__________________________________________________________________________
408 Bool_t AliMUONTrackReconstructor::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
410 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
411 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
412 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
413 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
414 /// Remove the obsolete "trackCandidate" at the end.
415 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
416 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
418 Double_t chi2WithOneCluster = 1.e10;
419 Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
420 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
421 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
422 Bool_t foundOneCluster = kFALSE;
423 AliMUONTrack *newTrack = 0x0;
424 AliMUONVCluster *cluster;
425 AliMUONTrackParam extrapTrackParam;
426 AliMUONTrackParam extrapTrackParamAtCh;
427 AliMUONTrackParam extrapTrackParamAtCluster;
428 AliMUONTrackParam bestTrackParamAtCluster;
430 // Get track parameters according to the propagation direction
431 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
432 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
434 // Printout for debuging
435 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
436 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
437 extrapTrackParamAtCh.GetParameters().Print();
438 extrapTrackParamAtCh.GetCovariances().Print();
442 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
444 // Add MCS in the missing chamber(s) if any
445 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
446 while (currentChamber > nextChamber + 1) {
447 // extrapolation to the missing chamber
449 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber));
451 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
454 //Extrapolate trackCandidate to chamber
455 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber));
457 // Printout for debuging
458 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
459 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
460 extrapTrackParamAtCh.GetParameters().Print();
461 extrapTrackParamAtCh.GetCovariances().Print();
464 // Printout for debuging
465 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
466 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << nextChamber+1 << endl;
469 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
470 // except for station 4 and 5 that are already entirely clusterized
471 if (AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco()) {
472 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
475 // Create iterators to loop over clusters in both chambers
476 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
478 // look for cluster in chamber
479 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
481 // try to add the current cluster fast
482 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
484 // try to add the current cluster accuratly
485 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
487 // if good chi2 then consider to add cluster
488 if (chi2WithOneCluster < maxChi2WithOneCluster) {
489 foundOneCluster = kTRUE;
491 // Printout for debuging
492 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
493 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
494 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
498 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
499 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
500 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
501 UpdateTrack(*newTrack,extrapTrackParamAtCluster);
504 // Printout for debuging
505 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
506 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
507 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
510 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
511 // keep track of the best single cluster except if a couple of clusters has already been found
512 bestChi2WithOneCluster = chi2WithOneCluster;
513 bestTrackParamAtCluster = extrapTrackParamAtCluster;
520 // fill out the best track if required else clean up the fRecTracksPtr array
521 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
522 if (foundOneCluster) {
523 UpdateTrack(trackCandidate,bestTrackParamAtCluster);
525 // Printout for debuging
526 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
527 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
528 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
531 } else return kFALSE;
533 } else if (foundOneCluster) {
535 // remove obsolete track
536 fRecTracksPtr->Remove(&trackCandidate);
539 } else return kFALSE;
545 //__________________________________________________________________________
546 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
548 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
549 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
550 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
551 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
552 /// Remove the obsolete "trackCandidate" at the end.
553 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
554 AliDebug(1,Form("Enter FollowTrackInStation(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 chi2WithOneCluster = 1.e10;
569 Double_t chi2WithTwoClusters = 1.e10;
570 Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
571 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
572 Double_t maxChi2WithTwoClusters = 4. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
573 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
574 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
575 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
576 Bool_t foundOneCluster = kFALSE;
577 Bool_t foundTwoClusters = kFALSE;
578 AliMUONTrack *newTrack = 0x0;
579 AliMUONVCluster *clusterCh1, *clusterCh2;
580 AliMUONTrackParam extrapTrackParam;
581 AliMUONTrackParam extrapTrackParamAtCh;
582 AliMUONTrackParam extrapTrackParamAtCluster1;
583 AliMUONTrackParam extrapTrackParamAtCluster2;
584 AliMUONTrackParam bestTrackParamAtCluster1;
585 AliMUONTrackParam bestTrackParamAtCluster2;
587 Int_t nClusters = clusterStore.GetSize();
588 Bool_t *clusterCh1Used = new Bool_t[nClusters];
589 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
592 // Get track parameters according to the propagation direction
593 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
594 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
596 // Printout for debuging
597 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
598 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
599 extrapTrackParamAtCh.GetParameters().Print();
600 extrapTrackParamAtCh.GetCovariances().Print();
604 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
606 // Add MCS in the missing chamber(s) if any
607 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
608 while (ch1 < ch2 && currentChamber > ch2 + 1) {
609 // extrapolation to the missing chamber
611 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber));
613 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
616 //Extrapolate trackCandidate to chamber "ch2"
617 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2));
619 // Printout for debuging
620 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
621 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
622 extrapTrackParamAtCh.GetParameters().Print();
623 extrapTrackParamAtCh.GetCovariances().Print();
626 // Printout for debuging
627 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
628 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
631 // Ask the clustering to reconstruct new clusters around the track position in the current station
632 // except for station 4 and 5 that are already entirely clusterized
633 if (AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco()) {
634 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
637 // Create iterators to loop over clusters in both chambers
638 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
639 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
641 // look for candidates in chamber 2
642 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
644 // try to add the current cluster fast
645 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
647 // try to add the current cluster accuratly
648 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
650 // if good chi2 then try to attach a cluster in the other chamber too
651 if (chi2WithOneCluster < maxChi2WithOneCluster) {
652 Bool_t foundSecondCluster = kFALSE;
654 // Printout for debuging
655 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
656 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
657 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
659 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
662 // add MCS effect for next step
663 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
665 // copy new track parameters for next step
666 extrapTrackParam = extrapTrackParamAtCluster2;
668 //Extrapolate track parameters to chamber "ch1"
669 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
671 // reset cluster iterator of chamber 1
675 // look for second candidates in chamber 1
676 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
679 // try to add the current cluster fast
680 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
682 // try to add the current cluster accuratly
683 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
685 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
686 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
687 foundSecondCluster = kTRUE;
688 foundTwoClusters = kTRUE;
690 // Printout for debuging
691 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
692 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
693 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
697 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
698 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
699 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
700 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
703 // Tag clusterCh1 as used
704 clusterCh1Used[iCluster1] = kTRUE;
706 // Printout for debuging
707 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
708 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
709 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
712 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
713 // keep track of the best couple of clusters
714 bestChi2WithTwoClusters = chi2WithTwoClusters;
715 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
716 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
723 // if no clusterCh1 found then consider to add clusterCh2 only
724 if (!foundSecondCluster) {
725 foundOneCluster = kTRUE;
727 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
728 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
729 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
730 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
733 // Printout for debuging
734 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
735 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
736 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
739 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
740 // keep track of the best single cluster except if a couple of clusters has already been found
741 bestChi2WithOneCluster = chi2WithOneCluster;
742 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
751 // look for candidates in chamber 1 not already attached to a track
752 // if we want to keep all possible tracks or if no good couple of clusters has been found
753 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
755 // add MCS effect for next step
756 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
758 //Extrapolate trackCandidate to chamber "ch1"
759 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
761 // Printout for debuging
762 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
763 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
764 extrapTrackParamAtCh.GetParameters().Print();
765 extrapTrackParamAtCh.GetCovariances().Print();
768 // Printout for debuging
769 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
770 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
773 // reset cluster iterator of chamber 1
777 // look for second candidates in chamber 1
778 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
781 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
783 // try to add the current cluster fast
784 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
786 // try to add the current cluster accuratly
787 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
789 // if good chi2 then consider to add clusterCh1
790 // We do not try to attach a cluster in the other chamber too since it has already been done above
791 if (chi2WithOneCluster < maxChi2WithOneCluster) {
792 foundOneCluster = kTRUE;
794 // Printout for debuging
795 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
796 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
797 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
801 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
802 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
803 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
804 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
807 // Printout for debuging
808 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
809 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
810 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
813 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
814 // keep track of the best single cluster except if a couple of clusters has already been found
815 bestChi2WithOneCluster = chi2WithOneCluster;
816 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
825 // fill out the best track if required else clean up the fRecTracksPtr array
826 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
827 if (foundTwoClusters) {
828 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
830 // Printout for debuging
831 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
832 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
833 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
836 } else if (foundOneCluster) {
837 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
839 // Printout for debuging
840 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
841 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
842 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
846 delete [] clusterCh1Used;
850 } else if (foundOneCluster || foundTwoClusters) {
852 // remove obsolete track
853 fRecTracksPtr->Remove(&trackCandidate);
857 delete [] clusterCh1Used;
861 delete [] clusterCh1Used;
866 //__________________________________________________________________________
867 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
868 AliMUONTrackParam &trackParamAtCluster2)
870 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
871 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
872 /// return trackParamAtCluster1 & 2
874 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
875 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
876 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
877 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
879 // set pointer to cluster2 into trackParamAtCluster2
880 trackParamAtCluster2.SetClusterPtr(cluster2);
882 // Set differences between track and the 2 clusters in the bending and non bending directions
883 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
885 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
886 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
887 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
888 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
890 // Calculate the error matrix from the track parameter covariances at first cluster
893 if (trackParamAtCluster1.CovariancesExist()) {
894 // Save track parameters at first cluster
895 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
897 // Save track coordinates at second cluster
898 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
899 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
901 // copy track parameters at first cluster for jacobian calculation
902 AliMUONTrackParam trackParam(trackParamAtCluster1);
904 // add MCS effect to the covariance matrix at first cluster
905 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
907 // Get the pointer to the parameter covariance matrix at first cluster
908 const TMatrixD& kParamCov = trackParam.GetCovariances();
910 // Calculate the jacobian related to the transformation between track parameters
911 // at first cluster and track coordinates at the 2 cluster z-positions
914 // first derivative at the first cluster:
915 jacob(0,0) = 1.; // dx1/dx
916 jacob(1,2) = 1.; // dy1/dy
917 // first derivative at the second cluster:
918 TMatrixD dParam(5,1);
919 for (Int_t i=0; i<5; i++) {
920 // Skip jacobian calculation for parameters with no associated error
921 if (kParamCov(i,i) == 0.) continue;
922 // Small variation of parameter i only
923 for (Int_t j=0; j<5; j++) {
925 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
926 if (j == 4) dParam(j,0) *= TMath::Sign(1.,-paramAtCluster1Save(4,0)); // variation always in the same direction
927 } else dParam(j,0) = 0.;
930 // Set new track parameters at first cluster
931 trackParam.SetParameters(paramAtCluster1Save);
932 trackParam.AddParameters(dParam);
933 trackParam.SetZ(cluster1->GetZ());
935 // Extrapolate new track parameters to the z position of the second cluster
936 AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ());
938 // Calculate the jacobian
939 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
940 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
943 // Calculate the error matrix
944 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
945 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
948 // Add cluster resolution to the error matrix
949 error(0,0) += cluster1->GetErrX2();
950 error(1,1) += cluster1->GetErrY2();
951 error(2,2) += cluster2->GetErrX2();
952 error(3,3) += cluster2->GetErrY2();
954 // invert the error matrix for Chi2 calculation
955 if (error.Determinant() != 0) {
958 AliWarning(" Determinant error=0");
962 // Compute the Chi2 value
963 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
964 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
970 //__________________________________________________________________________
971 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
973 /// Add 1 cluster to the track candidate
974 /// Update chi2 of the track
976 // Compute local chi2
977 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
978 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
979 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
980 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
981 deltaY*deltaY / cluster->GetErrY2();
983 // Flag cluster as being not removable
984 if (AliMUONReconstructor::GetRecoParam()->RequestStation(cluster->GetChamberId()/2))
985 trackParamAtCluster.SetRemovable(kFALSE);
986 else trackParamAtCluster.SetRemovable(kTRUE);
987 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
989 // Update the chi2 of the new track
990 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
992 // Update TrackParamAtCluster
993 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
997 //__________________________________________________________________________
998 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
1000 /// Add 2 clusters to the track candidate
1001 /// Update track and local chi2
1003 // Update local chi2 at first cluster
1004 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1005 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1006 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1007 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1008 deltaY*deltaY / cluster1->GetErrY2();
1009 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1011 // Flag first cluster as being removable
1012 trackParamAtCluster1.SetRemovable(kTRUE);
1014 // Update local chi2 at second cluster
1015 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1016 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1017 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1018 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1019 deltaY*deltaY / cluster2->GetErrY2();
1020 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1022 // Flag first cluster as being removable
1023 trackParamAtCluster2.SetRemovable(kTRUE);
1025 // Update the chi2 of the new track
1026 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
1028 // Update TrackParamAtCluster
1029 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1030 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1034 //__________________________________________________________________________
1035 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1037 /// Try to recover the track candidate in the next station
1038 /// by removing the worst of the two clusters attached in the current station
1039 /// Return kTRUE if recovering succeeds
1040 AliDebug(1,"Enter RecoverTrack");
1042 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1043 if (nextStation > 1) return kFALSE;
1045 Int_t worstClusterNumber = -1;
1046 Double_t localChi2, worstLocalChi2 = -1.;
1048 // Look for the cluster to remove
1049 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1050 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1052 // check if current cluster is in the previous station
1053 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1055 // check if current cluster is removable
1056 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1058 // reset the current cluster as beig not removable if it is on a required station
1059 if (AliMUONReconstructor::GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1061 // Pick up cluster with the worst chi2
1062 localChi2 = trackParamAtCluster->GetLocalChi2();
1063 if (localChi2 > worstLocalChi2) {
1064 worstLocalChi2 = localChi2;
1065 worstClusterNumber = clusterNumber;
1070 // check if worst cluster found
1071 if (worstClusterNumber < 0) return kFALSE;
1073 // Remove the worst cluster
1074 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1076 // Re-fit the track:
1077 // Do not take into account the multiple scattering to speed up the fit
1078 // Calculate the track parameter covariance matrix
1079 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
1081 // Look for new cluster(s) in next station
1082 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
1086 //__________________________________________________________________________
1087 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
1089 /// Compute the vertex resolution square from natural vertex dispersion and
1090 /// multiple scattering effets according to trackCandidate path in absorber
1091 /// It is necessary to account for multiple scattering effects here instead of during the fit of
1092 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
1093 AliDebug(1,"Enter SetVertexForFit");
1095 Double_t nonBendingReso2 = AliMUONReconstructor::GetRecoParam()->GetNonBendingVertexDispersion() *
1096 AliMUONReconstructor::GetRecoParam()->GetNonBendingVertexDispersion();
1097 Double_t bendingReso2 = AliMUONReconstructor::GetRecoParam()->GetBendingVertexDispersion() *
1098 AliMUONReconstructor::GetRecoParam()->GetBendingVertexDispersion();
1100 // add multiple scattering effets
1101 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
1102 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
1103 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
1104 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
1105 nonBendingReso2 += kParamCov(0,0);
1106 bendingReso2 += kParamCov(2,2);
1108 // Set the vertex resolution square
1109 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
1112 //__________________________________________________________________________
1113 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
1116 /// w/wo multiple Coulomb scattering according to "includeMCS".
1117 /// w/wo constraining the vertex according to "fitWithVertex".
1118 /// calculating or not the covariance matrix according to "calcCov".
1119 AliDebug(1,"Enter Fit");
1121 Double_t benC, errorParam, invBenP, nonBenC, x, y;
1122 AliMUONTrackParam *trackParam;
1123 Double_t arg[1], fedm, errdef, globalChi2;
1125 Int_t status, covStatus;
1127 // Instantiate gMinuit if not already done
1128 if (!gMinuit) gMinuit = new TMinuit(6);
1129 // Clear MINUIT parameters
1131 // Give the fitted track to MINUIT
1132 gMinuit->SetObjectFit(&track);
1133 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1134 // Define print level
1136 gMinuit->mnexcm("SET PRI", arg, 1, status);
1137 // Print covariance matrix
1138 gMinuit->mnexcm("SHO COV", arg, 0, status);
1141 gMinuit->mnexcm("SET PRI", arg, 1, status);
1144 gMinuit->mnexcm("SET NOW", arg, 0, status);
1147 //gMinuit->mnexcm("SET STR", arg, 1, status);
1149 // set flag w/wo multiple scattering according to "includeMCS"
1150 track.FitWithMCS(includeMCS);
1152 // compute cluster weights only once
1153 if (!track.ComputeClusterWeights()) {
1154 AliWarning("cannot take into account the multiple scattering effects");
1155 track.FitWithMCS(kFALSE);
1159 track.FitWithVertex(fitWithVertex);
1160 if (fitWithVertex) SetVertexErrXY2ForFit(track);
1162 // Set fitting function
1163 gMinuit->SetFCN(TrackChi2);
1165 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
1166 // Mandatory limits to avoid NaN values of parameters
1167 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1168 Double_t maxIBM = 1. / AliMUONReconstructor::GetRecoParam()->GetMinBendingMomentum();
1169 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
1170 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -1., 1., status);
1171 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
1172 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -1.5, 1.5, status);
1173 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -maxIBM, maxIBM, status);
1176 gMinuit->mnexcm("MIGRAD", arg, 0, status);
1178 // Calculate the covariance matrix more accurately if required
1179 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
1181 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
1182 gMinuit->GetParameter(0, x, errorParam);
1183 trackParam->SetNonBendingCoor(x);
1184 gMinuit->GetParameter(1, nonBenC, errorParam);
1185 trackParam->SetNonBendingSlope(nonBenC);
1186 gMinuit->GetParameter(2, y, errorParam);
1187 trackParam->SetBendingCoor(y);
1188 gMinuit->GetParameter(3, benC, errorParam);
1189 trackParam->SetBendingSlope(benC);
1190 gMinuit->GetParameter(4, invBenP, errorParam);
1191 trackParam->SetInverseBendingMomentum(invBenP);
1193 // global result of the fit
1194 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
1195 track.SetGlobalChi2(globalChi2);
1197 // Get the covariance matrix if required
1199 // Covariance matrix according to HESSE status
1200 // If problem then keep only the diagonal terms (variances)
1201 Double_t matrix[5][5];
1202 gMinuit->mnemat(&matrix[0][0],5);
1203 if (covStatus == 3) trackParam->SetCovariances(matrix);
1204 else trackParam->SetVariances(matrix);
1205 } else trackParam->DeleteCovariances();
1209 //__________________________________________________________________________
1210 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
1212 /// Return the "Chi2" to be minimized with Minuit for track fitting.
1213 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
1214 /// Track parameters at each cluster are updated accordingly.
1215 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
1216 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
1218 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
1219 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
1221 chi2 = 0.; // initialize chi2
1223 // update track parameters
1224 trackParamAtCluster->SetNonBendingCoor(param[0]);
1225 trackParamAtCluster->SetNonBendingSlope(param[1]);
1226 trackParamAtCluster->SetBendingCoor(param[2]);
1227 trackParamAtCluster->SetBendingSlope(param[3]);
1228 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
1229 trackBeingFitted->UpdateTrackParamAtCluster();
1231 // Take the vertex into account in the fit if required
1232 if (trackBeingFitted->FitWithVertex()) {
1233 Double_t nonBendingReso2,bendingReso2;
1234 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
1235 if (nonBendingReso2 == 0. || bendingReso2 == 0.) chi2 += 1.e10;
1237 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
1238 AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.); // vextex position = (0,0,0)
1239 dX = paramAtVertex.GetNonBendingCoor();
1240 dY = paramAtVertex.GetBendingCoor();
1241 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
1245 // compute chi2 w/wo multiple scattering
1246 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
1250 //__________________________________________________________________________
1251 void AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1253 /// Complete tracks by adding missing clusters (if there is an overlap between
1254 /// two detection elements, the track may have two clusters in the same chamber)
1255 /// Re-fit track parameters and covariances
1256 AliDebug(1,"Enter ComplementTracks");
1258 Int_t chamberId, detElemId;
1259 Double_t chi2OfCluster, bestChi2OfCluster;
1260 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
1261 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking();
1262 Bool_t foundOneCluster, trackModified;
1263 AliMUONVCluster* cluster;
1264 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1266 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1268 trackModified = kFALSE;
1270 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1271 while (trackParam) {
1272 foundOneCluster = kFALSE;
1273 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
1274 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1275 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1277 // prepare nextTrackParam before adding new cluster because of the sorting
1278 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1280 // recover track parameters from local fit and put them into a copy of trackParam
1281 copyOfTrackParam.SetZ(trackParam->GetZ());
1282 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1283 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1285 // Create iterators to loop over clusters in current chamber
1286 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1288 // look for one second candidate in the same chamber
1289 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1291 // look for a cluster in another detection element
1292 if (cluster->GetDetElemId() == detElemId) continue;
1294 // try to add the current cluster fast
1295 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1297 // try to add the current cluster accurately
1298 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1300 // if better chi2 then prepare to add this cluster to the track
1301 if (chi2OfCluster < bestChi2OfCluster) {
1302 bestChi2OfCluster = chi2OfCluster;
1303 bestTrackParamAtCluster = trackParamAtCluster;
1304 foundOneCluster = kTRUE;
1309 // add new cluster if any
1310 if (foundOneCluster) {
1312 // Printout for debuging
1313 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1314 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1315 bestTrackParamAtCluster.GetClusterPtr()->Print();
1316 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1317 bestTrackParamAtCluster.GetParameters().Print();
1318 bestTrackParamAtCluster.GetCovariances().Print();
1321 trackParam->SetRemovable(kTRUE);
1322 bestTrackParamAtCluster.SetRemovable(kTRUE);
1323 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1324 trackModified = kTRUE;
1327 trackParam = nextTrackParam;
1330 // re-fit track parameters if needed
1331 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1333 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1338 //__________________________________________________________________________
1339 void AliMUONTrackReconstructor::ImproveTrack(AliMUONTrack &track)
1341 /// Improve the given track by removing clusters with local chi2 highter than the defined cut
1342 /// Recompute track parameters and covariances at the remaining clusters
1343 AliDebug(1,"Enter ImproveTrack");
1345 Double_t localChi2, worstLocalChi2;
1346 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster;
1347 Double_t sigmaCut2 = AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement() *
1348 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForImprovement();
1350 while (!track.IsImproved()) {
1352 // identify removable clusters
1353 track.TagRemovableClusters();
1355 // Update track parameters and covariances
1356 track.UpdateCovTrackParamAtCluster();
1358 // Compute local chi2 of each clusters
1359 track.ComputeLocalChi2(kTRUE);
1361 // Look for the cluster to remove
1362 worstTrackParamAtCluster = NULL;
1363 worstLocalChi2 = 0.;
1364 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1365 while (trackParamAtCluster) {
1367 // Pick up cluster with the worst chi2
1368 localChi2 = trackParamAtCluster->GetLocalChi2();
1369 if (localChi2 > worstLocalChi2) {
1370 worstLocalChi2 = localChi2;
1371 worstTrackParamAtCluster = trackParamAtCluster;
1374 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1377 // Check if worst cluster found
1378 if (!worstTrackParamAtCluster) {
1379 AliWarning("Bad local chi2 values?");
1383 // Check whether the worst chi2 is under requirement or not
1384 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1385 track.SetImproved(kTRUE);
1389 // if the worst cluster is not removable then stop improvement
1390 if (!worstTrackParamAtCluster->IsRemovable()) break;
1392 // Remove the worst cluster
1393 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1395 // Re-fit the track:
1396 // Take into account the multiple scattering
1397 // Calculate the track parameter covariance matrix
1398 Fit(track, kTRUE, kFALSE, kTRUE);
1400 // Printout for debuging
1401 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1402 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1409 //__________________________________________________________________________
1410 void AliMUONTrackReconstructor::FinalizeTrack(AliMUONTrack &track)
1412 /// Recompute track parameters and covariances at each attached cluster
1413 /// from those at the first one, if not already done
1414 AliDebug(1,"Enter FinalizeTrack");
1415 if (!track.IsImproved()) track.UpdateCovTrackParamAtCluster();
1418 //__________________________________________________________________________
1419 Bool_t AliMUONTrackReconstructor::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1421 /// re-fit the given track
1423 // check validity of the track
1424 if (!track.IsValid()) {
1425 AliWarning("the track does not contain enough clusters --> unable to refit");
1429 // reset the seed (i.e. parameters at first cluster) before fitting
1430 AliMUONTrackParam* firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1431 if (firstTrackParam->GetInverseBendingMomentum() == 0.) {
1432 AliWarning("track parameters at first chamber are not initialized --> unable to refit");
1436 // compute track parameters at each cluster from parameters at the first one
1437 // necessary to compute multiple scattering effect during refitting
1438 track.UpdateTrackParamAtCluster();
1440 // Re-fit the track:
1441 // Take into account the multiple scattering
1442 // Calculate the track parameter covariance matrix
1443 Fit(track, kTRUE, kFALSE, kTRUE);
1445 // Improve the reconstructed tracks if required
1446 track.SetImproved(kFALSE);
1447 if (enableImprovement && AliMUONReconstructor::GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1449 // Fill AliMUONTrack data members
1450 FinalizeTrack(track);