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"
38 #include "AliMUONRecoParam.h"
40 #include "AliMpArea.h"
45 #include <Riostream.h>
48 #include <TClonesArray.h>
50 // Functions to be minimized with Minuit
51 void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag);
56 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
59 //__________________________________________________________________________
60 AliMUONTrackReconstructor::AliMUONTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
61 : AliMUONVTrackReconstructor(recoParam,clusterServer)
66 //__________________________________________________________________________
67 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
72 //__________________________________________________________________________
73 Bool_t AliMUONTrackReconstructor::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
75 /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
76 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
77 /// Good candidates are made of at least three clusters.
78 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
80 TClonesArray *segments;
85 AliDebug(1,"Enter MakeTrackCandidates");
87 // Unless we're doing combined tracking, we'll clusterize all stations at once
88 Int_t firstChamber(0);
91 if (GetRecoParam()->CombineClusterTrackReco()) {
92 // ... Here's the exception : ask the clustering to reconstruct
93 // clusters *only* in station 4 and 5 for combined tracking
97 for (Int_t i = firstChamber; i <= lastChamber; ++i )
99 if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam());
102 // Loop over stations(1..) 5 and 4 and make track candidates
103 for (Int_t istat=4; istat>=3; istat--) {
105 // Make segments in the station
106 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
108 // Loop over segments
109 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
111 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
113 // Transform segments to tracks and put them at the end of fRecTracksPtr
114 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]),GetRecoParam()->GetBendingVertexDispersion());
117 // Look for compatible cluster(s) in the other station
118 if (GetRecoParam()->MakeTrackCandidatesFast())
119 clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
120 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
122 // Remove track if no cluster found on a requested station
123 // or abort tracking if there are too many candidates
124 if (GetRecoParam()->RequestStation(7-istat)) {
126 fRecTracksPtr->Remove(track);
128 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
129 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
133 if ((fNRecTracks + segments->GetEntriesFast() - iseg - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
134 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iseg - 1));
143 // Keep all different tracks or only the best ones as required
144 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
145 else RemoveDoubleTracks();
147 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
153 //__________________________________________________________________________
154 Bool_t AliMUONTrackReconstructor::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
156 /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
157 /// clustering is supposed to be already done
158 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
159 /// Good candidates are made of at least three clusters if both station are requested (two otherwise).
160 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
162 TClonesArray *segments;
163 AliMUONObjectPair *segment;
165 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
168 AliDebug(1,"Enter MakeMoreTrackCandidates");
170 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
171 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
172 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
174 // Make segments in the station
175 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
177 /// Remove segments already attached to a track
178 RemoveUsedSegments(*segments);
180 // Loop over segments
181 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++)
183 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
184 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
186 // Transform segments to tracks and put them at the end of fRecTracksPtr
187 iCurrentTrack = fRecTracksPtr->GetLast()+1;
188 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
191 // Look for compatible cluster(s) in the second chamber of station 5
192 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
194 // skip the original track in case it has been removed
195 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
197 // loop over every new tracks
198 nCurrentTracks = fRecTracksPtr->GetLast()+1;
199 while (iCurrentTrack < nCurrentTracks) {
200 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
202 // Look for compatible cluster(s) in the second chamber of station 4
203 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
208 // abort tracking if there are too many candidates
209 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
210 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
219 // Keep only the best tracks if required
220 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
221 else fRecTracksPtr->Compress();
223 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
229 //__________________________________________________________________________
230 Bool_t AliMUONTrackReconstructor::FollowTracks(AliMUONVClusterStore& clusterStore)
232 /// Follow tracks in stations(1..) 3, 2 and 1
233 AliDebug(1,"Enter FollowTracks");
235 AliMUONTrack *track, *nextTrack;
236 AliMUONTrackParam *trackParam, *nextTrackParam;
237 Int_t currentNRecTracks;
239 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
240 GetRecoParam()->GetSigmaCutForTracking();
242 for (Int_t station = 2; station >= 0; station--) {
244 // Save the actual number of reconstructed track in case of
245 // tracks are added or suppressed during the tracking procedure
246 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
247 currentNRecTracks = fNRecTracks;
249 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
250 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
252 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
255 // Do not take into account the multiple scattering to speed up the fit
256 // Calculate the track parameter covariance matrix
257 // If there is no cluster out of station 4 or 5 then use the vertex to better constrain the fit
258 if (((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetClusterPtr()->GetChamberId() > 5)
259 Fit(*track, kFALSE, kTRUE, kTRUE);
260 else Fit(*track, kFALSE, kFALSE, kTRUE);
262 // remove tracks out of limits
263 if (!IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
264 fRecTracksPtr->Remove(track);
269 // remove track if the normalized chi2 is too high
270 if (track->GetNormalizedChi2() > sigmaCut2) {
271 fRecTracksPtr->Remove(track);
276 // save parameters from fit into smoothed parameters to complete track afterward
277 if (GetRecoParam()->ComplementTracks()) {
279 if (station==2) { // save track parameters on stations 4 and 5
281 // extrapolate track parameters and covariances at each cluster
282 // remove the track in case of failure
283 if (!track->UpdateCovTrackParamAtCluster()) {
284 fRecTracksPtr->Remove(track);
290 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
292 trackParam->SetSmoothParameters(trackParam->GetParameters());
293 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
294 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
297 } else { // or save track parameters on last station only
299 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
300 if (trackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
302 // save parameters from fit
303 trackParam->SetSmoothParameters(trackParam->GetParameters());
304 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
306 // save parameters extrapolated to the second chamber of the same station if it has been hit
307 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
308 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
310 // reset parameters and covariances
311 nextTrackParam->SetParameters(trackParam->GetParameters());
312 nextTrackParam->SetZ(trackParam->GetZ());
313 nextTrackParam->SetCovariances(trackParam->GetCovariances());
315 // extrapolate them to the z of the corresponding cluster
316 // remove the track in case of failure
317 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
318 fRecTracksPtr->Remove(track);
324 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
325 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
335 // Look for compatible cluster(s) in station(0..) "station"
336 if (!FollowTrackInStation(*track, clusterStore, station)) {
338 // Try to recover track if required
339 if (GetRecoParam()->RecoverTracks()) {
341 // work on a copy of the track if this station is not required
342 // to keep the case where no cluster is reconstructed as a possible candidate
343 if (!GetRecoParam()->RequestStation(station)) {
344 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
349 if (!RecoverTrack(*track, clusterStore, station)) {
350 // remove track if no cluster found
351 fRecTracksPtr->Remove(track);
355 } else if (GetRecoParam()->RequestStation(station)) {
356 // remove track if no cluster found
357 fRecTracksPtr->Remove(track);
363 // abort tracking if there are too many candidates
364 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
365 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
371 // Compress fRecTracksPtr for the next step
372 fRecTracksPtr->Compress();
374 // Keep only the best tracks if required
375 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
379 // Last fit of track candidates with all stations
380 // Take into account the multiple scattering and remove bad tracks
381 Int_t trackIndex = -1;
382 track = (AliMUONTrack*) fRecTracksPtr->First();
386 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
388 Fit(*track, kTRUE, kFALSE, kTRUE);
390 // Printout for debuging
391 if (AliLog::GetGlobalDebugLevel() >= 3) {
392 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
393 track->RecursiveDump();
396 // Remove the track if the normalized chi2 is too high
397 if (track->GetNormalizedChi2() > sigmaCut2) {
398 fRecTracksPtr->Remove(track);
404 // save parameters from fit into smoothed parameters to complete track afterward
405 if (GetRecoParam()->ComplementTracks()) {
407 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
408 if (trackParam->GetClusterPtr()->GetChamberId() < 2) {
410 // save parameters from fit
411 trackParam->SetSmoothParameters(trackParam->GetParameters());
412 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
414 // save parameters extrapolated to the second chamber of the same station if it has been hit
415 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
416 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
418 // reset parameters and covariances
419 nextTrackParam->SetParameters(trackParam->GetParameters());
420 nextTrackParam->SetZ(trackParam->GetZ());
421 nextTrackParam->SetCovariances(trackParam->GetCovariances());
423 // extrapolate them to the z of the corresponding cluster
424 // remove the track in case of failure
425 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
426 fRecTracksPtr->Remove(track);
433 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
434 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
446 fRecTracksPtr->Compress();
452 //__________________________________________________________________________
453 Bool_t AliMUONTrackReconstructor::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
455 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
456 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
457 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
458 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
459 /// Remove the obsolete "trackCandidate" at the end.
460 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
461 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
463 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
464 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
465 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
466 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
467 Bool_t foundOneCluster = kFALSE;
468 AliMUONTrack *newTrack = 0x0;
469 AliMUONVCluster *cluster;
470 AliMUONTrackParam extrapTrackParam;
471 AliMUONTrackParam extrapTrackParamAtCh;
472 AliMUONTrackParam extrapTrackParamAtCluster;
473 AliMUONTrackParam bestTrackParamAtCluster;
475 // Get track parameters according to the propagation direction
476 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
477 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
479 // Printout for debuging
480 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
481 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
482 extrapTrackParamAtCh.GetParameters().Print();
483 extrapTrackParamAtCh.GetCovariances().Print();
487 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
488 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
490 // Add MCS in the missing chamber(s) if any
491 while (currentChamber > nextChamber + 1) {
492 // extrapolation to the missing chamber
494 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
496 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
499 //Extrapolate trackCandidate to chamber
500 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber))) return kFALSE;
502 // Printout for debuging
503 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
504 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
505 extrapTrackParamAtCh.GetParameters().Print();
506 extrapTrackParamAtCh.GetCovariances().Print();
509 // Printout for debuging
510 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
511 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << nextChamber+1 << endl;
514 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
515 // except for station 4 and 5 that are already entirely clusterized
516 if (GetRecoParam()->CombineClusterTrackReco()) {
517 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
520 // Create iterators to loop over clusters in both chambers
521 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
523 // look for cluster in chamber
524 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
526 // try to add the current cluster fast
527 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
529 // try to add the current cluster accuratly
530 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
532 // if good chi2 then consider to add cluster
533 if (chi2WithOneCluster < maxChi2WithOneCluster) {
534 foundOneCluster = kTRUE;
536 // Printout for debuging
537 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
538 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
539 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
543 if (GetRecoParam()->TrackAllTracks()) {
544 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
545 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
546 UpdateTrack(*newTrack,extrapTrackParamAtCluster);
549 // Printout for debuging
550 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
551 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
552 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
555 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
556 // keep track of the best single cluster except if a couple of clusters has already been found
557 bestChi2WithOneCluster = chi2WithOneCluster;
558 bestTrackParamAtCluster = extrapTrackParamAtCluster;
565 // fill out the best track if required else clean up the fRecTracksPtr array
566 if (!GetRecoParam()->TrackAllTracks()) {
567 if (foundOneCluster) {
568 UpdateTrack(trackCandidate,bestTrackParamAtCluster);
570 // Printout for debuging
571 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
572 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
573 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
576 } else return kFALSE;
578 } else if (foundOneCluster) {
580 // remove obsolete track
581 fRecTracksPtr->Remove(&trackCandidate);
584 } else return kFALSE;
590 //__________________________________________________________________________
591 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
593 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
594 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
595 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
596 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
597 /// Remove the obsolete "trackCandidate" at the end.
598 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
599 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
601 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
602 // - nextStation == station(1...) 5 => forward propagation
603 // - nextStation < station(1...) 5 => backward propagation
605 if (nextStation==4) {
606 ch1 = 2*nextStation+1;
610 ch2 = 2*nextStation+1;
613 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
614 Double_t chi2WithTwoClusters = AliMUONTrack::MaxChi2();
615 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
616 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
617 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
618 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
619 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
620 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
621 Bool_t foundOneCluster = kFALSE;
622 Bool_t foundTwoClusters = kFALSE;
623 AliMUONTrack *newTrack = 0x0;
624 AliMUONVCluster *clusterCh1, *clusterCh2;
625 AliMUONTrackParam extrapTrackParam;
626 AliMUONTrackParam extrapTrackParamAtCh;
627 AliMUONTrackParam extrapTrackParamAtCluster1;
628 AliMUONTrackParam extrapTrackParamAtCluster2;
629 AliMUONTrackParam bestTrackParamAtCluster1;
630 AliMUONTrackParam bestTrackParamAtCluster2;
632 // Get track parameters according to the propagation direction
633 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
634 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
636 // Printout for debuging
637 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
638 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
639 extrapTrackParamAtCh.GetParameters().Print();
640 extrapTrackParamAtCh.GetCovariances().Print();
644 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
645 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
647 // Add MCS in the missing chamber(s) if any
648 while (ch1 < ch2 && currentChamber > ch2 + 1) {
649 // extrapolation to the missing chamber
651 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
653 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
656 //Extrapolate trackCandidate to chamber "ch2"
657 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2))) return kFALSE;
659 // Printout for debuging
660 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
661 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
662 extrapTrackParamAtCh.GetParameters().Print();
663 extrapTrackParamAtCh.GetCovariances().Print();
666 // Printout for debuging
667 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
668 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
671 // Ask the clustering to reconstruct new clusters around the track position in the current station
672 // except for station 4 and 5 that are already entirely clusterized
673 if (GetRecoParam()->CombineClusterTrackReco()) {
674 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
677 Int_t nClusters = clusterStore.GetSize();
678 Bool_t *clusterCh1Used = new Bool_t[nClusters];
679 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
682 // Create iterators to loop over clusters in both chambers
683 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
684 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
686 // look for candidates in chamber 2
687 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
689 // try to add the current cluster fast
690 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
692 // try to add the current cluster accuratly
693 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
695 // if good chi2 then try to attach a cluster in the other chamber too
696 if (chi2WithOneCluster < maxChi2WithOneCluster) {
697 Bool_t foundSecondCluster = kFALSE;
699 // Printout for debuging
700 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
701 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
702 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
704 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
707 // add MCS effect for next step
708 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
710 // copy new track parameters for next step
711 extrapTrackParam = extrapTrackParamAtCluster2;
713 //Extrapolate track parameters to chamber "ch1"
714 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
716 // reset cluster iterator of chamber 1
720 // look for second candidates in chamber 1
721 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
724 // try to add the current cluster fast
725 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
727 // try to add the current cluster accurately
728 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
730 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
731 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
732 foundSecondCluster = kTRUE;
733 foundTwoClusters = kTRUE;
735 // Printout for debuging
736 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
737 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
738 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
742 if (GetRecoParam()->TrackAllTracks()) {
743 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
744 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
745 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
748 // Tag clusterCh1 as used
749 clusterCh1Used[iCluster1] = kTRUE;
751 // Printout for debuging
752 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
753 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
754 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
757 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
758 // keep track of the best couple of clusters
759 bestChi2WithTwoClusters = chi2WithTwoClusters;
760 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
761 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
768 // if no clusterCh1 found then consider to add clusterCh2 only
769 if (!foundSecondCluster) {
770 foundOneCluster = kTRUE;
772 if (GetRecoParam()->TrackAllTracks()) {
773 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
774 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
775 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
778 // Printout for debuging
779 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
780 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
781 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
784 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
785 // keep track of the best single cluster except if a couple of clusters has already been found
786 bestChi2WithOneCluster = chi2WithOneCluster;
787 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
796 // look for candidates in chamber 1 not already attached to a track
797 // if we want to keep all possible tracks or if no good couple of clusters has been found
798 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
800 // add MCS effect for next step
801 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
803 //Extrapolate trackCandidate to chamber "ch1"
804 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
806 // Printout for debuging
807 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
808 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
809 extrapTrackParamAtCh.GetParameters().Print();
810 extrapTrackParamAtCh.GetCovariances().Print();
813 // Printout for debuging
814 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
815 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
818 // reset cluster iterator of chamber 1
822 // look for second candidates in chamber 1
823 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
826 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
828 // try to add the current cluster fast
829 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
831 // try to add the current cluster accuratly
832 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
834 // if good chi2 then consider to add clusterCh1
835 // We do not try to attach a cluster in the other chamber too since it has already been done above
836 if (chi2WithOneCluster < maxChi2WithOneCluster) {
837 foundOneCluster = kTRUE;
839 // Printout for debuging
840 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
841 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
842 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
846 if (GetRecoParam()->TrackAllTracks()) {
847 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
848 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
849 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
852 // Printout for debuging
853 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
854 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
855 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
858 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
859 // keep track of the best single cluster except if a couple of clusters has already been found
860 bestChi2WithOneCluster = chi2WithOneCluster;
861 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
870 // fill out the best track if required else clean up the fRecTracksPtr array
871 if (!GetRecoParam()->TrackAllTracks()) {
872 if (foundTwoClusters) {
873 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
875 // Printout for debuging
876 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
877 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
878 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
881 } else if (foundOneCluster) {
882 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
884 // Printout for debuging
885 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
886 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
887 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
891 delete [] clusterCh1Used;
895 } else if (foundOneCluster || foundTwoClusters) {
897 // remove obsolete track
898 fRecTracksPtr->Remove(&trackCandidate);
902 delete [] clusterCh1Used;
906 delete [] clusterCh1Used;
911 //__________________________________________________________________________
912 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
913 AliMUONTrackParam &trackParamAtCluster2)
915 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
916 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
917 /// return trackParamAtCluster1 & 2
919 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
920 // and set pointer to cluster into trackParamAtCluster
921 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
922 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
923 trackParamAtCluster2.SetClusterPtr(cluster2);
924 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
926 // Set differences between track and the 2 clusters in the bending and non bending directions
927 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
929 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
930 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
931 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
932 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
934 // Calculate the error matrix from the track parameter covariances at first cluster
937 if (trackParamAtCluster1.CovariancesExist()) {
938 // Save track parameters at first cluster
939 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
941 // Save track coordinates at second cluster
942 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
943 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
945 // copy track parameters at first cluster for jacobian calculation
946 AliMUONTrackParam trackParam(trackParamAtCluster1);
948 // Get the pointer to the parameter covariance matrix at first cluster
949 const TMatrixD& kParamCov = trackParam.GetCovariances();
951 // Calculate the jacobian related to the transformation between track parameters
952 // at first cluster and track coordinates at the 2 cluster z-positions
955 // first derivative at the first cluster:
956 jacob(0,0) = 1.; // dx1/dx
957 jacob(1,2) = 1.; // dy1/dy
958 // first derivative at the second cluster:
959 TMatrixD dParam(5,1);
960 Double_t direction[5] = {-1.,-1.,1.,1.,-1.};
961 for (Int_t i=0; i<5; i++) {
962 // Skip jacobian calculation for parameters with no associated error
963 if (kParamCov(i,i) == 0.) continue;
964 // Small variation of parameter i only
965 for (Int_t j=0; j<5; j++) {
967 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
968 dParam(j,0) *= TMath::Sign(1.,direction[j]*paramAtCluster1Save(j,0)); // variation always in the same direction
969 } else dParam(j,0) = 0.;
972 // Set new track parameters at first cluster
973 trackParam.SetParameters(paramAtCluster1Save);
974 trackParam.AddParameters(dParam);
975 trackParam.SetZ(cluster1->GetZ());
977 // Extrapolate new track parameters to the z position of the second cluster
978 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
980 // Calculate the jacobian
981 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
982 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
985 // Calculate the error matrix
986 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
987 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
990 // Add cluster resolution to the error matrix
991 error(0,0) += cluster1->GetErrX2();
992 error(1,1) += cluster1->GetErrY2();
993 error(2,2) += cluster2->GetErrX2();
994 error(3,3) += cluster2->GetErrY2();
996 // invert the error matrix for Chi2 calculation
997 if (error.Determinant() != 0) {
1000 AliWarning(" Determinant error=0");
1001 return 2.*AliMUONTrack::MaxChi2();
1004 // Compute the Chi2 value
1005 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
1006 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
1012 //__________________________________________________________________________
1013 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
1015 /// Add 1 cluster to the track candidate
1016 /// Update chi2 of the track
1018 // Compute local chi2
1019 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
1020 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
1021 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
1022 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
1023 deltaY*deltaY / cluster->GetErrY2();
1025 // Flag cluster as being not removable
1026 if (GetRecoParam()->RequestStation(cluster->GetChamberId()/2))
1027 trackParamAtCluster.SetRemovable(kFALSE);
1028 else trackParamAtCluster.SetRemovable(kTRUE);
1029 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
1031 // Update the chi2 of the new track
1032 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
1034 // Update TrackParamAtCluster
1035 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
1039 //__________________________________________________________________________
1040 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
1042 /// Add 2 clusters to the track candidate
1043 /// Update track and local chi2
1045 // Update local chi2 at first cluster
1046 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1047 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1048 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1049 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1050 deltaY*deltaY / cluster1->GetErrY2();
1051 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1053 // Flag first cluster as being removable
1054 trackParamAtCluster1.SetRemovable(kTRUE);
1056 // Update local chi2 at second cluster
1057 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1058 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1059 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1060 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1061 deltaY*deltaY / cluster2->GetErrY2();
1062 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1064 // Flag first cluster as being removable
1065 trackParamAtCluster2.SetRemovable(kTRUE);
1067 // Update the chi2 of the new track
1068 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
1070 // Update TrackParamAtCluster
1071 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1072 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1076 //__________________________________________________________________________
1077 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1079 /// Try to recover the track candidate in the next station
1080 /// by removing the worst of the two clusters attached in the current station
1081 /// Return kTRUE if recovering succeeds
1082 AliDebug(1,"Enter RecoverTrack");
1084 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1085 if (nextStation > 1) return kFALSE;
1087 Int_t worstClusterNumber = -1;
1088 Double_t localChi2, worstLocalChi2 = -1.;
1090 // Look for the cluster to remove
1091 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1092 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1094 // check if current cluster is in the previous station
1095 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1097 // check if current cluster is removable
1098 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1100 // reset the current cluster as beig not removable if it is on a required station
1101 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1103 // Pick up cluster with the worst chi2
1104 localChi2 = trackParamAtCluster->GetLocalChi2();
1105 if (localChi2 > worstLocalChi2) {
1106 worstLocalChi2 = localChi2;
1107 worstClusterNumber = clusterNumber;
1112 // check if worst cluster found
1113 if (worstClusterNumber < 0) return kFALSE;
1115 // Remove the worst cluster
1116 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1118 // Re-fit the track:
1119 // Do not take into account the multiple scattering to speed up the fit
1120 // Calculate the track parameter covariance matrix
1121 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
1123 // skip track if the normalized chi2 is too high
1124 if (trackCandidate.GetNormalizedChi2() > GetRecoParam()->GetSigmaCutForTracking() * GetRecoParam()->GetSigmaCutForTracking()) return kFALSE;
1126 // skip track out of limits
1127 if (!IsAcceptable(*((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()))) return kFALSE;
1129 // Look for new cluster(s) in next station
1130 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
1134 //__________________________________________________________________________
1135 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
1137 /// Compute the vertex resolution square from natural vertex dispersion and
1138 /// multiple scattering effets according to trackCandidate path in absorber
1139 /// It is necessary to account for multiple scattering effects here instead of during the fit of
1140 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
1141 AliDebug(1,"Enter SetVertexForFit");
1143 Double_t nonBendingReso2 = GetRecoParam()->GetNonBendingVertexDispersion() *
1144 GetRecoParam()->GetNonBendingVertexDispersion();
1145 Double_t bendingReso2 = GetRecoParam()->GetBendingVertexDispersion() *
1146 GetRecoParam()->GetBendingVertexDispersion();
1148 // add multiple scattering effets
1149 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
1150 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
1151 if (!AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex,AliMUONConstants::AbsZEnd())) {
1152 nonBendingReso2 = 0.;
1155 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
1156 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
1157 nonBendingReso2 += kParamCov(0,0);
1158 bendingReso2 += kParamCov(2,2);
1161 // Set the vertex resolution square
1162 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
1165 //__________________________________________________________________________
1166 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
1169 /// w/wo multiple Coulomb scattering according to "includeMCS".
1170 /// w/wo constraining the vertex according to "fitWithVertex".
1171 /// calculating or not the covariance matrix according to "calcCov".
1172 AliDebug(1,"Enter Fit");
1174 Double_t benC, errorParam, invBenP, nonBenC, x, y;
1175 AliMUONTrackParam *trackParam;
1176 Double_t arg[1], fedm, errdef, globalChi2;
1178 Int_t status, covStatus;
1180 // Instantiate gMinuit if not already done
1181 if (!gMinuit) gMinuit = new TMinuit(6);
1182 // Clear MINUIT parameters
1184 // Give the fitted track to MINUIT
1185 gMinuit->SetObjectFit(&track);
1186 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1187 // Define print level
1189 gMinuit->mnexcm("SET PRI", arg, 1, status);
1190 // Print covariance matrix
1191 gMinuit->mnexcm("SHO COV", arg, 0, status);
1194 gMinuit->mnexcm("SET PRI", arg, 1, status);
1197 gMinuit->mnexcm("SET NOW", arg, 0, status);
1200 //gMinuit->mnexcm("SET STR", arg, 1, status);
1202 // set flag w/wo multiple scattering according to "includeMCS"
1203 track.FitWithMCS(includeMCS);
1205 // compute cluster weights only once
1206 if (!track.UpdateTrackParamAtCluster() || !track.ComputeClusterWeights()) {
1207 AliWarning("cannot take into account the multiple scattering effects");
1208 track.FitWithMCS(kFALSE);
1212 track.FitWithVertex(fitWithVertex);
1213 if (fitWithVertex) SetVertexErrXY2ForFit(track);
1215 // Set fitting function
1216 gMinuit->SetFCN(TrackChi2);
1218 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
1219 // Mandatory limits to avoid NaN values of parameters
1220 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1221 Double_t maxIBM = 1. / GetRecoParam()->GetMinBendingMomentum();
1222 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
1223 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -1., 1., status);
1224 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
1225 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -1.5, 1.5, status);
1226 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -maxIBM, maxIBM, status);
1229 gMinuit->mnexcm("MIGRAD", arg, 0, status);
1231 // Calculate the covariance matrix more accurately if required
1232 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
1234 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
1235 gMinuit->GetParameter(0, x, errorParam);
1236 trackParam->SetNonBendingCoor(x);
1237 gMinuit->GetParameter(1, nonBenC, errorParam);
1238 trackParam->SetNonBendingSlope(nonBenC);
1239 gMinuit->GetParameter(2, y, errorParam);
1240 trackParam->SetBendingCoor(y);
1241 gMinuit->GetParameter(3, benC, errorParam);
1242 trackParam->SetBendingSlope(benC);
1243 gMinuit->GetParameter(4, invBenP, errorParam);
1244 trackParam->SetInverseBendingMomentum(invBenP);
1246 // global result of the fit
1247 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
1248 track.SetGlobalChi2(globalChi2);
1250 // Get the covariance matrix if required
1252 // Covariance matrix according to HESSE status
1253 // If problem then keep only the diagonal terms (variances)
1254 Double_t matrix[5][5];
1255 for (Int_t i=0; i<5; i++) for (Int_t j=0; j<5; j++) matrix[i][j] = 0.;
1256 gMinuit->mnemat(&matrix[0][0],5);
1257 if (covStatus == 3) trackParam->SetCovariances(matrix);
1258 else trackParam->SetVariances(matrix);
1259 } else trackParam->DeleteCovariances();
1263 //__________________________________________________________________________
1264 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
1266 /// Return the "Chi2" to be minimized with Minuit for track fitting.
1267 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
1268 /// Track parameters at each cluster are updated accordingly.
1269 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
1270 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
1272 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
1273 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
1275 chi2 = 0.; // initialize chi2
1277 // update track parameters
1278 trackParamAtCluster->SetNonBendingCoor(param[0]);
1279 trackParamAtCluster->SetNonBendingSlope(param[1]);
1280 trackParamAtCluster->SetBendingCoor(param[2]);
1281 trackParamAtCluster->SetBendingSlope(param[3]);
1282 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
1283 if (!trackBeingFitted->UpdateTrackParamAtCluster()) {
1284 chi2 = 2.*AliMUONTrack::MaxChi2();
1288 // Take the vertex into account in the fit if required
1289 if (trackBeingFitted->FitWithVertex()) {
1290 Double_t nonBendingReso2,bendingReso2;
1291 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
1292 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
1293 if (nonBendingReso2 != 0. && bendingReso2 != 0. && AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.)) { // vextex position = (0,0,0)
1294 dX = paramAtVertex.GetNonBendingCoor();
1295 dY = paramAtVertex.GetBendingCoor();
1296 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
1298 chi2 = 2.*AliMUONTrack::MaxChi2();
1303 // compute chi2 w/wo multiple scattering
1304 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
1308 //__________________________________________________________________________
1309 Bool_t AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1311 /// Complete tracks by adding missing clusters (if there is an overlap between
1312 /// two detection elements, the track may have two clusters in the same chamber).
1313 /// Re-fit track parameters and covariances.
1314 /// Return kTRUE if one or more tracks have been complemented.
1315 AliDebug(1,"Enter ComplementTracks");
1317 Int_t chamberId, detElemId;
1318 Double_t chi2OfCluster, bestChi2OfCluster;
1319 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
1320 GetRecoParam()->GetSigmaCutForTracking();
1321 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
1322 AliMUONVCluster* cluster;
1323 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1325 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1327 trackModified = kFALSE;
1329 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1330 while (trackParam) {
1331 foundOneCluster = kFALSE;
1332 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
1333 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1334 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1336 // prepare nextTrackParam before adding new cluster because of the sorting
1337 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1339 // recover track parameters from local fit and put them into a copy of trackParam
1340 copyOfTrackParam.SetZ(trackParam->GetZ());
1341 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1342 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1344 // Create iterators to loop over clusters in current chamber
1345 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1347 // look for one second candidate in the same chamber
1348 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1350 // look for a cluster in another detection element
1351 if (cluster->GetDetElemId() == detElemId) continue;
1353 // try to add the current cluster fast
1354 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1356 // try to add the current cluster accurately
1357 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1359 // if better chi2 then prepare to add this cluster to the track
1360 if (chi2OfCluster < bestChi2OfCluster) {
1361 bestChi2OfCluster = chi2OfCluster;
1362 bestTrackParamAtCluster = trackParamAtCluster;
1363 foundOneCluster = kTRUE;
1368 // add new cluster if any
1369 if (foundOneCluster) {
1371 // Printout for debuging
1372 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1373 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1374 bestTrackParamAtCluster.GetClusterPtr()->Print();
1375 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1376 bestTrackParamAtCluster.GetParameters().Print();
1377 bestTrackParamAtCluster.GetCovariances().Print();
1380 trackParam->SetRemovable(kTRUE);
1381 bestTrackParamAtCluster.SetRemovable(kTRUE);
1382 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1383 trackModified = kTRUE;
1387 trackParam = nextTrackParam;
1390 // re-fit track parameters if needed
1391 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1393 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1400 //__________________________________________________________________________
1401 void AliMUONTrackReconstructor::ImproveTrack(AliMUONTrack &track)
1403 /// Improve the given track by removing clusters with local chi2 highter than the defined cut
1404 /// Recompute track parameters and covariances at the remaining clusters
1405 AliDebug(1,"Enter ImproveTrack");
1407 Double_t localChi2, worstLocalChi2;
1408 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster;
1409 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1410 GetRecoParam()->GetSigmaCutForImprovement();
1412 while (!track.IsImproved()) {
1414 // identify removable clusters
1415 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
1417 // Update track parameters and covariances
1418 if (!track.UpdateCovTrackParamAtCluster()) {
1419 AliWarning("unable to update track parameters and covariances --> stop improvement");
1423 // Compute local chi2 of each clusters
1424 track.ComputeLocalChi2(kTRUE);
1426 // Look for the cluster to remove
1427 worstTrackParamAtCluster = NULL;
1428 worstLocalChi2 = 0.;
1429 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1430 while (trackParamAtCluster) {
1432 // Pick up cluster with the worst chi2
1433 localChi2 = trackParamAtCluster->GetLocalChi2();
1434 if (localChi2 > worstLocalChi2) {
1435 worstLocalChi2 = localChi2;
1436 worstTrackParamAtCluster = trackParamAtCluster;
1439 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1442 // Check if worst cluster found
1443 if (!worstTrackParamAtCluster) {
1444 AliWarning("Bad local chi2 values?");
1448 // Check whether the worst chi2 is under requirement or not
1449 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1450 track.SetImproved(kTRUE);
1454 // if the worst cluster is not removable then stop improvement
1455 if (!worstTrackParamAtCluster->IsRemovable()) break;
1457 // Remove the worst cluster
1458 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1460 // Re-fit the track:
1461 // Take into account the multiple scattering
1462 // Calculate the track parameter covariance matrix
1463 Fit(track, kTRUE, kFALSE, kTRUE);
1465 // Printout for debuging
1466 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1467 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1474 //__________________________________________________________________________
1475 Bool_t AliMUONTrackReconstructor::FinalizeTrack(AliMUONTrack &track)
1477 /// Recompute track parameters and covariances at each attached cluster
1478 /// from those at the first one, if not already done
1479 AliDebug(1,"Enter FinalizeTrack");
1480 if (!track.IsImproved() && !track.UpdateCovTrackParamAtCluster()) {
1481 AliWarning("finalization failed due to extrapolation problem");
1487 //__________________________________________________________________________
1488 Bool_t AliMUONTrackReconstructor::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1490 /// re-fit the given track
1492 // check validity of the track
1493 if (track.GetNClusters() < 3) {
1494 AliWarning("the track does not contain enough clusters --> unable to refit");
1498 // reset the seed (i.e. parameters at first cluster) before fitting
1499 AliMUONTrackParam* firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1500 if (firstTrackParam->GetInverseBendingMomentum() == 0.) {
1501 AliWarning("track parameters at first chamber are not initialized --> unable to refit");
1505 // compute track parameters at each cluster from parameters at the first one
1506 // necessary to compute multiple scattering effect during refitting
1507 if (!track.UpdateTrackParamAtCluster()) {
1508 AliWarning("bad track refitting due to extrapolation failure");
1512 // Re-fit the track:
1513 // Take into account the multiple scattering
1514 // Calculate the track parameter covariance matrix
1515 Fit(track, kTRUE, kFALSE, kTRUE);
1517 // Improve the reconstructed tracks if required
1518 track.SetImproved(kFALSE);
1519 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1521 // Fill AliMUONTrack data members
1522 if (track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) return FinalizeTrack(track);
1524 AliWarning("track not finalized due to extrapolation failure");