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>
49 // Functions to be minimized with Minuit
50 void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag);
53 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
56 //__________________________________________________________________________
57 AliMUONTrackReconstructor::AliMUONTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
58 : AliMUONVTrackReconstructor(recoParam,clusterServer)
63 //__________________________________________________________________________
64 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
69 //__________________________________________________________________________
70 Bool_t AliMUONTrackReconstructor::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
72 /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
73 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
74 /// Good candidates are made of at least three clusters.
75 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
77 TClonesArray *segments;
82 AliDebug(1,"Enter MakeTrackCandidates");
84 // Unless we're doing combined tracking, we'll clusterize all stations at once
85 Int_t firstChamber(0);
88 if (GetRecoParam()->CombineClusterTrackReco()) {
89 // ... Here's the exception : ask the clustering to reconstruct
90 // clusters *only* in station 4 and 5 for combined tracking
94 for (Int_t i = firstChamber; i <= lastChamber; ++i )
96 if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam());
99 // Loop over stations(1..) 5 and 4 and make track candidates
100 for (Int_t istat=4; istat>=3; istat--) {
102 // Make segments in the station
103 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
105 // Loop over segments
106 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
108 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
110 // Transform segments to tracks and put them at the end of fRecTracksPtr
111 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]),GetRecoParam()->GetBendingVertexDispersion());
114 // Look for compatible cluster(s) in the other station
115 if (GetRecoParam()->MakeTrackCandidatesFast())
116 clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
117 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
119 // Remove track if no cluster found on a requested station
120 // or abort tracking if there are too many candidates
121 if (GetRecoParam()->RequestStation(7-istat)) {
123 fRecTracksPtr->Remove(track);
125 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
126 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
131 if ((fNRecTracks + segments->GetEntriesFast() - iseg - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
132 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iseg - 1));
140 // delete the array of segments
144 // Keep all different tracks or only the best ones as required
145 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
146 else RemoveDoubleTracks();
148 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
154 //__________________________________________________________________________
155 Bool_t AliMUONTrackReconstructor::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
157 /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
158 /// clustering is supposed to be already done
159 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
160 /// Good candidates are made of at least three clusters if both station are requested (two otherwise).
161 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
163 TClonesArray *segments;
164 AliMUONObjectPair *segment;
166 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
169 AliDebug(1,"Enter MakeMoreTrackCandidates");
171 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
172 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
173 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
175 // Make segments in the station
176 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
178 /// Remove segments already attached to a track
179 RemoveUsedSegments(*segments);
181 // Loop over segments
182 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++)
184 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
185 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
187 // Transform segments to tracks and put them at the end of fRecTracksPtr
188 iCurrentTrack = fRecTracksPtr->GetLast()+1;
189 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
192 // Look for compatible cluster(s) in the second chamber of station 5
193 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
195 // skip the original track in case it has been removed
196 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
198 // loop over every new tracks
199 nCurrentTracks = fRecTracksPtr->GetLast()+1;
200 while (iCurrentTrack < nCurrentTracks) {
201 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
203 // Look for compatible cluster(s) in the second chamber of station 4
204 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
209 // abort tracking if there are too many candidates
210 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
211 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
218 // delete the array of segments
223 // Keep only the best tracks if required
224 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
225 else fRecTracksPtr->Compress();
227 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
233 //__________________________________________________________________________
234 Bool_t AliMUONTrackReconstructor::FollowTracks(AliMUONVClusterStore& clusterStore)
236 /// Follow tracks in stations(1..) 3, 2 and 1
237 AliDebug(1,"Enter FollowTracks");
239 AliMUONTrack *track, *nextTrack;
240 AliMUONTrackParam *trackParam, *nextTrackParam;
241 Int_t currentNRecTracks;
243 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
244 GetRecoParam()->GetSigmaCutForTracking();
246 for (Int_t station = 2; station >= 0; station--) {
248 // Save the actual number of reconstructed track in case of
249 // tracks are added or suppressed during the tracking procedure
250 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
251 currentNRecTracks = fNRecTracks;
253 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
254 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
256 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
259 // Do not take into account the multiple scattering to speed up the fit
260 // Calculate the track parameter covariance matrix
261 // If there is no cluster out of station 4 or 5 then use the vertex to better constrain the fit
262 if (((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetClusterPtr()->GetChamberId() > 5)
263 Fit(*track, kFALSE, kTRUE, kTRUE);
264 else Fit(*track, kFALSE, kFALSE, kTRUE);
266 // remove tracks out of limits
267 if (!IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
268 fRecTracksPtr->Remove(track);
273 // remove track if the normalized chi2 is too high
274 if (track->GetNormalizedChi2() > sigmaCut2) {
275 fRecTracksPtr->Remove(track);
280 // save parameters from fit into smoothed parameters to complete track afterward
281 if (GetRecoParam()->ComplementTracks()) {
283 if (station==2) { // save track parameters on stations 4 and 5
285 // extrapolate track parameters and covariances at each cluster
286 // remove the track in case of failure
287 if (!track->UpdateCovTrackParamAtCluster()) {
288 fRecTracksPtr->Remove(track);
294 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
296 trackParam->SetSmoothParameters(trackParam->GetParameters());
297 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
298 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
301 } else { // or save track parameters on last station only
303 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
304 if (trackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
306 // save parameters from fit
307 trackParam->SetSmoothParameters(trackParam->GetParameters());
308 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
310 // save parameters extrapolated to the second chamber of the same station if it has been hit
311 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
312 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
314 // reset parameters and covariances
315 nextTrackParam->SetParameters(trackParam->GetParameters());
316 nextTrackParam->SetZ(trackParam->GetZ());
317 nextTrackParam->SetCovariances(trackParam->GetCovariances());
319 // extrapolate them to the z of the corresponding cluster
320 // remove the track in case of failure
321 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
322 fRecTracksPtr->Remove(track);
328 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
329 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
339 // Look for compatible cluster(s) in station(0..) "station"
340 if (!FollowTrackInStation(*track, clusterStore, station)) {
342 // Try to recover track if required
343 if (GetRecoParam()->RecoverTracks()) {
345 // work on a copy of the track if this station is not required
346 // to keep the case where no cluster is reconstructed as a possible candidate
347 if (!GetRecoParam()->RequestStation(station)) {
348 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
353 if (!RecoverTrack(*track, clusterStore, station)) {
354 // remove track if no cluster found
355 fRecTracksPtr->Remove(track);
359 } else if (GetRecoParam()->RequestStation(station)) {
360 // remove track if no cluster found
361 fRecTracksPtr->Remove(track);
367 // abort tracking if there are too many candidates
368 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
369 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
375 // Compress fRecTracksPtr for the next step
376 fRecTracksPtr->Compress();
378 // Keep only the best tracks if required
379 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
383 // Last fit of track candidates with all stations
384 // Take into account the multiple scattering and remove bad tracks
385 Int_t trackIndex = -1;
386 track = (AliMUONTrack*) fRecTracksPtr->First();
390 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
392 Fit(*track, kTRUE, kFALSE, kTRUE);
394 // Printout for debuging
395 if (AliLog::GetGlobalDebugLevel() >= 3) {
396 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
397 track->RecursiveDump();
400 // Remove the track if the normalized chi2 is too high
401 if (track->GetNormalizedChi2() > sigmaCut2) {
402 fRecTracksPtr->Remove(track);
408 // save parameters from fit into smoothed parameters to complete track afterward
409 if (GetRecoParam()->ComplementTracks()) {
411 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
412 if (trackParam->GetClusterPtr()->GetChamberId() < 2) {
414 // save parameters from fit
415 trackParam->SetSmoothParameters(trackParam->GetParameters());
416 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
418 // save parameters extrapolated to the second chamber of the same station if it has been hit
419 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
420 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
422 // reset parameters and covariances
423 nextTrackParam->SetParameters(trackParam->GetParameters());
424 nextTrackParam->SetZ(trackParam->GetZ());
425 nextTrackParam->SetCovariances(trackParam->GetCovariances());
427 // extrapolate them to the z of the corresponding cluster
428 // remove the track in case of failure
429 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
430 fRecTracksPtr->Remove(track);
437 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
438 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
450 fRecTracksPtr->Compress();
456 //__________________________________________________________________________
457 Bool_t AliMUONTrackReconstructor::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
459 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
460 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
461 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
462 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
463 /// Remove the obsolete "trackCandidate" at the end.
464 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
465 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
467 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
468 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
469 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
470 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
471 Bool_t foundOneCluster = kFALSE;
472 AliMUONTrack *newTrack = 0x0;
473 AliMUONVCluster *cluster;
474 AliMUONTrackParam extrapTrackParam;
475 AliMUONTrackParam extrapTrackParamAtCh;
476 AliMUONTrackParam extrapTrackParamAtCluster;
477 AliMUONTrackParam bestTrackParamAtCluster;
479 // Get track parameters according to the propagation direction
480 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
481 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
483 // Printout for debuging
484 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
485 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
486 extrapTrackParamAtCh.GetParameters().Print();
487 extrapTrackParamAtCh.GetCovariances().Print();
491 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
492 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
494 // Add MCS in the missing chamber(s) if any
495 while (currentChamber > nextChamber + 1) {
496 // extrapolation to the missing chamber
498 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
500 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
503 //Extrapolate trackCandidate to chamber
504 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber))) return kFALSE;
506 // Printout for debuging
507 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
508 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
509 extrapTrackParamAtCh.GetParameters().Print();
510 extrapTrackParamAtCh.GetCovariances().Print();
513 // Printout for debuging
514 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
515 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << nextChamber+1 << endl;
518 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
519 // except for station 4 and 5 that are already entirely clusterized
520 if (GetRecoParam()->CombineClusterTrackReco()) {
521 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
524 // Create iterators to loop over clusters in both chambers
525 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
527 // look for cluster in chamber
528 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
530 // try to add the current cluster fast
531 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
533 // try to add the current cluster accuratly
534 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
536 // if good chi2 then consider to add cluster
537 if (chi2WithOneCluster < maxChi2WithOneCluster) {
538 foundOneCluster = kTRUE;
540 // Printout for debuging
541 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
542 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
543 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
547 if (GetRecoParam()->TrackAllTracks()) {
548 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
549 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
550 UpdateTrack(*newTrack,extrapTrackParamAtCluster);
553 // Printout for debuging
554 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
555 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
556 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
559 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
560 // keep track of the best single cluster except if a couple of clusters has already been found
561 bestChi2WithOneCluster = chi2WithOneCluster;
562 bestTrackParamAtCluster = extrapTrackParamAtCluster;
569 // fill out the best track if required else clean up the fRecTracksPtr array
570 if (!GetRecoParam()->TrackAllTracks()) {
571 if (foundOneCluster) {
572 UpdateTrack(trackCandidate,bestTrackParamAtCluster);
574 // Printout for debuging
575 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
576 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
577 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
580 } else return kFALSE;
582 } else if (foundOneCluster) {
584 // remove obsolete track
585 fRecTracksPtr->Remove(&trackCandidate);
588 } else return kFALSE;
594 //__________________________________________________________________________
595 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
597 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
598 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
599 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
600 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
601 /// Remove the obsolete "trackCandidate" at the end.
602 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
603 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
605 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
606 // - nextStation == station(1...) 5 => forward propagation
607 // - nextStation < station(1...) 5 => backward propagation
609 if (nextStation==4) {
610 ch1 = 2*nextStation+1;
614 ch2 = 2*nextStation+1;
617 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
618 Double_t chi2WithTwoClusters = AliMUONTrack::MaxChi2();
619 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
620 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
621 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
622 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
623 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
624 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
625 Bool_t foundOneCluster = kFALSE;
626 Bool_t foundTwoClusters = kFALSE;
627 AliMUONTrack *newTrack = 0x0;
628 AliMUONVCluster *clusterCh1, *clusterCh2;
629 AliMUONTrackParam extrapTrackParam;
630 AliMUONTrackParam extrapTrackParamAtCh;
631 AliMUONTrackParam extrapTrackParamAtCluster1;
632 AliMUONTrackParam extrapTrackParamAtCluster2;
633 AliMUONTrackParam bestTrackParamAtCluster1;
634 AliMUONTrackParam bestTrackParamAtCluster2;
636 // Get track parameters according to the propagation direction
637 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
638 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
640 // Printout for debuging
641 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
642 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
643 extrapTrackParamAtCh.GetParameters().Print();
644 extrapTrackParamAtCh.GetCovariances().Print();
648 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
649 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
651 // Add MCS in the missing chamber(s) if any
652 while (ch1 < ch2 && currentChamber > ch2 + 1) {
653 // extrapolation to the missing chamber
655 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
657 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
660 //Extrapolate trackCandidate to chamber "ch2"
661 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2))) return kFALSE;
663 // Printout for debuging
664 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
665 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
666 extrapTrackParamAtCh.GetParameters().Print();
667 extrapTrackParamAtCh.GetCovariances().Print();
670 // Printout for debuging
671 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
672 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
675 // Ask the clustering to reconstruct new clusters around the track position in the current station
676 // except for station 4 and 5 that are already entirely clusterized
677 if (GetRecoParam()->CombineClusterTrackReco()) {
678 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
681 Int_t nClusters = clusterStore.GetSize();
682 Bool_t *clusterCh1Used = new Bool_t[nClusters];
683 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
686 // Create iterators to loop over clusters in both chambers
687 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
688 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
690 // look for candidates in chamber 2
691 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
693 // try to add the current cluster fast
694 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
696 // try to add the current cluster accuratly
697 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
699 // if good chi2 then try to attach a cluster in the other chamber too
700 if (chi2WithOneCluster < maxChi2WithOneCluster) {
701 Bool_t foundSecondCluster = kFALSE;
703 // Printout for debuging
704 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
705 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
706 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
708 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
711 // add MCS effect for next step
712 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
714 // copy new track parameters for next step
715 extrapTrackParam = extrapTrackParamAtCluster2;
717 //Extrapolate track parameters to chamber "ch1"
718 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
720 // reset cluster iterator of chamber 1
724 // look for second candidates in chamber 1
725 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
728 // try to add the current cluster fast
729 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
731 // try to add the current cluster accurately
732 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
734 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
735 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
736 foundSecondCluster = kTRUE;
737 foundTwoClusters = kTRUE;
739 // Printout for debuging
740 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
741 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
742 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
746 if (GetRecoParam()->TrackAllTracks()) {
747 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
748 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
749 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
752 // Tag clusterCh1 as used
753 clusterCh1Used[iCluster1] = kTRUE;
755 // Printout for debuging
756 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
757 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
758 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
761 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
762 // keep track of the best couple of clusters
763 bestChi2WithTwoClusters = chi2WithTwoClusters;
764 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
765 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
772 // if no clusterCh1 found then consider to add clusterCh2 only
773 if (!foundSecondCluster) {
774 foundOneCluster = kTRUE;
776 if (GetRecoParam()->TrackAllTracks()) {
777 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
778 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
779 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
782 // Printout for debuging
783 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
784 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
785 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
788 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
789 // keep track of the best single cluster except if a couple of clusters has already been found
790 bestChi2WithOneCluster = chi2WithOneCluster;
791 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
800 // look for candidates in chamber 1 not already attached to a track
801 // if we want to keep all possible tracks or if no good couple of clusters has been found
802 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
804 // add MCS effect for next step
805 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
807 //Extrapolate trackCandidate to chamber "ch1"
808 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
810 // Printout for debuging
811 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
812 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
813 extrapTrackParamAtCh.GetParameters().Print();
814 extrapTrackParamAtCh.GetCovariances().Print();
817 // Printout for debuging
818 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
819 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
822 // reset cluster iterator of chamber 1
826 // look for second candidates in chamber 1
827 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
830 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
832 // try to add the current cluster fast
833 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
835 // try to add the current cluster accuratly
836 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
838 // if good chi2 then consider to add clusterCh1
839 // We do not try to attach a cluster in the other chamber too since it has already been done above
840 if (chi2WithOneCluster < maxChi2WithOneCluster) {
841 foundOneCluster = kTRUE;
843 // Printout for debuging
844 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
845 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
846 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
850 if (GetRecoParam()->TrackAllTracks()) {
851 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
852 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
853 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
856 // Printout for debuging
857 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
858 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
859 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
862 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
863 // keep track of the best single cluster except if a couple of clusters has already been found
864 bestChi2WithOneCluster = chi2WithOneCluster;
865 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
874 // fill out the best track if required else clean up the fRecTracksPtr array
875 if (!GetRecoParam()->TrackAllTracks()) {
876 if (foundTwoClusters) {
877 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
879 // Printout for debuging
880 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
881 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
882 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
885 } else if (foundOneCluster) {
886 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
888 // Printout for debuging
889 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
890 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
891 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
895 delete [] clusterCh1Used;
899 } else if (foundOneCluster || foundTwoClusters) {
901 // remove obsolete track
902 fRecTracksPtr->Remove(&trackCandidate);
906 delete [] clusterCh1Used;
910 delete [] clusterCh1Used;
915 //__________________________________________________________________________
916 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
917 AliMUONTrackParam &trackParamAtCluster2)
919 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
920 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
921 /// return trackParamAtCluster1 & 2
923 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
924 // and set pointer to cluster into trackParamAtCluster
925 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
926 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
927 trackParamAtCluster2.SetClusterPtr(cluster2);
928 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
930 // Set differences between track and the 2 clusters in the bending and non bending directions
931 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
933 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
934 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
935 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
936 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
938 // Calculate the error matrix from the track parameter covariances at first cluster
941 if (trackParamAtCluster1.CovariancesExist()) {
942 // Save track parameters at first cluster
943 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
945 // Save track coordinates at second cluster
946 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
947 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
949 // copy track parameters at first cluster for jacobian calculation
950 AliMUONTrackParam trackParam(trackParamAtCluster1);
952 // Get the pointer to the parameter covariance matrix at first cluster
953 const TMatrixD& kParamCov = trackParam.GetCovariances();
955 // Calculate the jacobian related to the transformation between track parameters
956 // at first cluster and track coordinates at the 2 cluster z-positions
959 // first derivative at the first cluster:
960 jacob(0,0) = 1.; // dx1/dx
961 jacob(1,2) = 1.; // dy1/dy
962 // first derivative at the second cluster:
963 TMatrixD dParam(5,1);
964 Double_t direction[5] = {-1.,-1.,1.,1.,-1.};
965 for (Int_t i=0; i<5; i++) {
966 // Skip jacobian calculation for parameters with no associated error
967 if (kParamCov(i,i) == 0.) continue;
968 // Small variation of parameter i only
969 for (Int_t j=0; j<5; j++) {
971 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
972 dParam(j,0) *= TMath::Sign(1.,direction[j]*paramAtCluster1Save(j,0)); // variation always in the same direction
973 } else dParam(j,0) = 0.;
976 // Set new track parameters at first cluster
977 trackParam.SetParameters(paramAtCluster1Save);
978 trackParam.AddParameters(dParam);
979 trackParam.SetZ(cluster1->GetZ());
981 // Extrapolate new track parameters to the z position of the second cluster
982 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
984 // Calculate the jacobian
985 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
986 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
989 // Calculate the error matrix
990 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
991 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
994 // Add cluster resolution to the error matrix
995 error(0,0) += cluster1->GetErrX2();
996 error(1,1) += cluster1->GetErrY2();
997 error(2,2) += cluster2->GetErrX2();
998 error(3,3) += cluster2->GetErrY2();
1000 // invert the error matrix for Chi2 calculation
1001 if (error.Determinant() != 0) {
1004 AliWarning(" Determinant error=0");
1005 return 2.*AliMUONTrack::MaxChi2();
1008 // Compute the Chi2 value
1009 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
1010 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
1016 //__________________________________________________________________________
1017 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
1019 /// Add 1 cluster to the track candidate
1020 /// Update chi2 of the track
1022 // Compute local chi2
1023 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
1024 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
1025 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
1026 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
1027 deltaY*deltaY / cluster->GetErrY2();
1029 // Flag cluster as being not removable
1030 if (GetRecoParam()->RequestStation(cluster->GetChamberId()/2))
1031 trackParamAtCluster.SetRemovable(kFALSE);
1032 else trackParamAtCluster.SetRemovable(kTRUE);
1033 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
1035 // Update the chi2 of the new track
1036 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
1038 // Update TrackParamAtCluster
1039 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
1043 //__________________________________________________________________________
1044 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
1046 /// Add 2 clusters to the track candidate
1047 /// Update track and local chi2
1049 // Update local chi2 at first cluster
1050 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1051 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1052 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1053 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1054 deltaY*deltaY / cluster1->GetErrY2();
1055 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1057 // Flag first cluster as being removable
1058 trackParamAtCluster1.SetRemovable(kTRUE);
1060 // Update local chi2 at second cluster
1061 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1062 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1063 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1064 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1065 deltaY*deltaY / cluster2->GetErrY2();
1066 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1068 // Flag first cluster as being removable
1069 trackParamAtCluster2.SetRemovable(kTRUE);
1071 // Update the chi2 of the new track
1072 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
1074 // Update TrackParamAtCluster
1075 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1076 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1080 //__________________________________________________________________________
1081 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1083 /// Try to recover the track candidate in the next station
1084 /// by removing the worst of the two clusters attached in the current station
1085 /// Return kTRUE if recovering succeeds
1086 AliDebug(1,"Enter RecoverTrack");
1088 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1089 if (nextStation > 1) return kFALSE;
1091 Int_t worstClusterNumber = -1;
1092 Double_t localChi2, worstLocalChi2 = -1.;
1094 // Look for the cluster to remove
1095 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1096 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1098 // check if current cluster is in the previous station
1099 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1101 // check if current cluster is removable
1102 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1104 // reset the current cluster as beig not removable if it is on a required station
1105 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1107 // Pick up cluster with the worst chi2
1108 localChi2 = trackParamAtCluster->GetLocalChi2();
1109 if (localChi2 > worstLocalChi2) {
1110 worstLocalChi2 = localChi2;
1111 worstClusterNumber = clusterNumber;
1116 // check if worst cluster found
1117 if (worstClusterNumber < 0) return kFALSE;
1119 // Remove the worst cluster
1120 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1122 // Re-fit the track:
1123 // Do not take into account the multiple scattering to speed up the fit
1124 // Calculate the track parameter covariance matrix
1125 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
1127 // skip track if the normalized chi2 is too high
1128 if (trackCandidate.GetNormalizedChi2() > GetRecoParam()->GetSigmaCutForTracking() * GetRecoParam()->GetSigmaCutForTracking()) return kFALSE;
1130 // skip track out of limits
1131 if (!IsAcceptable(*((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()))) return kFALSE;
1133 // Look for new cluster(s) in next station
1134 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
1138 //__________________________________________________________________________
1139 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
1141 /// Compute the vertex resolution square from natural vertex dispersion and
1142 /// multiple scattering effets according to trackCandidate path in absorber
1143 /// It is necessary to account for multiple scattering effects here instead of during the fit of
1144 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
1145 AliDebug(1,"Enter SetVertexForFit");
1147 Double_t nonBendingReso2 = GetRecoParam()->GetNonBendingVertexDispersion() *
1148 GetRecoParam()->GetNonBendingVertexDispersion();
1149 Double_t bendingReso2 = GetRecoParam()->GetBendingVertexDispersion() *
1150 GetRecoParam()->GetBendingVertexDispersion();
1152 // add multiple scattering effets
1153 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
1154 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
1155 if (!AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex,AliMUONConstants::AbsZEnd())) {
1156 nonBendingReso2 = 0.;
1159 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
1160 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
1161 nonBendingReso2 += kParamCov(0,0);
1162 bendingReso2 += kParamCov(2,2);
1165 // Set the vertex resolution square
1166 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
1169 //__________________________________________________________________________
1170 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
1173 /// w/wo multiple Coulomb scattering according to "includeMCS".
1174 /// w/wo constraining the vertex according to "fitWithVertex".
1175 /// calculating or not the covariance matrix according to "calcCov".
1176 AliDebug(1,"Enter Fit");
1178 Double_t benC, errorParam, invBenP, nonBenC, x, y;
1179 AliMUONTrackParam *trackParam;
1180 Double_t arg[1], fedm, errdef, globalChi2;
1182 Int_t status, covStatus;
1184 // Instantiate gMinuit if not already done
1185 if (!gMinuit) gMinuit = new TMinuit(6);
1186 // Clear MINUIT parameters
1188 // Give the fitted track to MINUIT
1189 gMinuit->SetObjectFit(&track);
1190 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1191 // Define print level
1193 gMinuit->mnexcm("SET PRI", arg, 1, status);
1194 // Print covariance matrix
1195 gMinuit->mnexcm("SHO COV", arg, 0, status);
1198 gMinuit->mnexcm("SET PRI", arg, 1, status);
1201 gMinuit->mnexcm("SET NOW", arg, 0, status);
1204 //gMinuit->mnexcm("SET STR", arg, 1, status);
1206 // set flag w/wo multiple scattering according to "includeMCS"
1207 track.FitWithMCS(includeMCS);
1209 // compute cluster weights only once
1210 if (!track.UpdateTrackParamAtCluster() || !track.ComputeClusterWeights()) {
1211 AliWarning("cannot take into account the multiple scattering effects");
1212 track.FitWithMCS(kFALSE);
1216 track.FitWithVertex(fitWithVertex);
1217 if (fitWithVertex) SetVertexErrXY2ForFit(track);
1219 // Set fitting function
1220 gMinuit->SetFCN(TrackChi2);
1222 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
1223 // Mandatory limits to avoid NaN values of parameters
1224 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1225 Double_t maxIBM = 1. / GetRecoParam()->GetMinBendingMomentum();
1226 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
1227 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -1., 1., status);
1228 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
1229 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -1.5, 1.5, status);
1230 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -maxIBM, maxIBM, status);
1233 gMinuit->mnexcm("MIGRAD", arg, 0, status);
1235 // Calculate the covariance matrix more accurately if required
1236 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
1238 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
1239 gMinuit->GetParameter(0, x, errorParam);
1240 trackParam->SetNonBendingCoor(x);
1241 gMinuit->GetParameter(1, nonBenC, errorParam);
1242 trackParam->SetNonBendingSlope(nonBenC);
1243 gMinuit->GetParameter(2, y, errorParam);
1244 trackParam->SetBendingCoor(y);
1245 gMinuit->GetParameter(3, benC, errorParam);
1246 trackParam->SetBendingSlope(benC);
1247 gMinuit->GetParameter(4, invBenP, errorParam);
1248 trackParam->SetInverseBendingMomentum(invBenP);
1250 // global result of the fit
1251 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
1252 track.SetGlobalChi2(globalChi2);
1254 // Get the covariance matrix if required
1256 // Covariance matrix according to HESSE status
1257 // If problem then keep only the diagonal terms (variances)
1258 Double_t matrix[5][5];
1259 gMinuit->mnemat(&matrix[0][0],5);
1260 if (covStatus == 3) trackParam->SetCovariances(matrix);
1261 else trackParam->SetVariances(matrix);
1262 } else trackParam->DeleteCovariances();
1266 //__________________________________________________________________________
1267 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
1269 /// Return the "Chi2" to be minimized with Minuit for track fitting.
1270 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
1271 /// Track parameters at each cluster are updated accordingly.
1272 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
1273 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
1275 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
1276 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
1278 chi2 = 0.; // initialize chi2
1280 // update track parameters
1281 trackParamAtCluster->SetNonBendingCoor(param[0]);
1282 trackParamAtCluster->SetNonBendingSlope(param[1]);
1283 trackParamAtCluster->SetBendingCoor(param[2]);
1284 trackParamAtCluster->SetBendingSlope(param[3]);
1285 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
1286 if (!trackBeingFitted->UpdateTrackParamAtCluster()) {
1287 chi2 = 2.*AliMUONTrack::MaxChi2();
1291 // Take the vertex into account in the fit if required
1292 if (trackBeingFitted->FitWithVertex()) {
1293 Double_t nonBendingReso2,bendingReso2;
1294 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
1295 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
1296 if (nonBendingReso2 != 0. && bendingReso2 != 0. && AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.)) { // vextex position = (0,0,0)
1297 dX = paramAtVertex.GetNonBendingCoor();
1298 dY = paramAtVertex.GetBendingCoor();
1299 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
1301 chi2 = 2.*AliMUONTrack::MaxChi2();
1306 // compute chi2 w/wo multiple scattering
1307 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
1311 //__________________________________________________________________________
1312 Bool_t AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1314 /// Complete tracks by adding missing clusters (if there is an overlap between
1315 /// two detection elements, the track may have two clusters in the same chamber).
1316 /// Re-fit track parameters and covariances.
1317 /// Return kTRUE if one or more tracks have been complemented.
1318 AliDebug(1,"Enter ComplementTracks");
1320 Int_t chamberId, detElemId;
1321 Double_t chi2OfCluster, bestChi2OfCluster;
1322 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
1323 GetRecoParam()->GetSigmaCutForTracking();
1324 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
1325 AliMUONVCluster* cluster;
1326 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1328 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1330 trackModified = kFALSE;
1332 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1333 while (trackParam) {
1334 foundOneCluster = kFALSE;
1335 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
1336 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1337 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1339 // prepare nextTrackParam before adding new cluster because of the sorting
1340 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1342 // recover track parameters from local fit and put them into a copy of trackParam
1343 copyOfTrackParam.SetZ(trackParam->GetZ());
1344 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1345 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1347 // Create iterators to loop over clusters in current chamber
1348 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1350 // look for one second candidate in the same chamber
1351 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1353 // look for a cluster in another detection element
1354 if (cluster->GetDetElemId() == detElemId) continue;
1356 // try to add the current cluster fast
1357 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1359 // try to add the current cluster accurately
1360 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1362 // if better chi2 then prepare to add this cluster to the track
1363 if (chi2OfCluster < bestChi2OfCluster) {
1364 bestChi2OfCluster = chi2OfCluster;
1365 bestTrackParamAtCluster = trackParamAtCluster;
1366 foundOneCluster = kTRUE;
1371 // add new cluster if any
1372 if (foundOneCluster) {
1374 // Printout for debuging
1375 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1376 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1377 bestTrackParamAtCluster.GetClusterPtr()->Print();
1378 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1379 bestTrackParamAtCluster.GetParameters().Print();
1380 bestTrackParamAtCluster.GetCovariances().Print();
1383 trackParam->SetRemovable(kTRUE);
1384 bestTrackParamAtCluster.SetRemovable(kTRUE);
1385 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1386 trackModified = kTRUE;
1390 trackParam = nextTrackParam;
1393 // re-fit track parameters if needed
1394 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1396 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1403 //__________________________________________________________________________
1404 void AliMUONTrackReconstructor::ImproveTrack(AliMUONTrack &track)
1406 /// Improve the given track by removing clusters with local chi2 highter than the defined cut
1407 /// Recompute track parameters and covariances at the remaining clusters
1408 AliDebug(1,"Enter ImproveTrack");
1410 Double_t localChi2, worstLocalChi2;
1411 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster;
1412 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1413 GetRecoParam()->GetSigmaCutForImprovement();
1415 while (!track.IsImproved()) {
1417 // identify removable clusters
1418 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
1420 // Update track parameters and covariances
1421 if (!track.UpdateCovTrackParamAtCluster()) {
1422 AliWarning("unable to update track parameters and covariances --> stop improvement");
1426 // Compute local chi2 of each clusters
1427 track.ComputeLocalChi2(kTRUE);
1429 // Look for the cluster to remove
1430 worstTrackParamAtCluster = NULL;
1431 worstLocalChi2 = 0.;
1432 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1433 while (trackParamAtCluster) {
1435 // Pick up cluster with the worst chi2
1436 localChi2 = trackParamAtCluster->GetLocalChi2();
1437 if (localChi2 > worstLocalChi2) {
1438 worstLocalChi2 = localChi2;
1439 worstTrackParamAtCluster = trackParamAtCluster;
1442 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1445 // Check if worst cluster found
1446 if (!worstTrackParamAtCluster) {
1447 AliWarning("Bad local chi2 values?");
1451 // Check whether the worst chi2 is under requirement or not
1452 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1453 track.SetImproved(kTRUE);
1457 // if the worst cluster is not removable then stop improvement
1458 if (!worstTrackParamAtCluster->IsRemovable()) break;
1460 // Remove the worst cluster
1461 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1463 // Re-fit the track:
1464 // Take into account the multiple scattering
1465 // Calculate the track parameter covariance matrix
1466 Fit(track, kTRUE, kFALSE, kTRUE);
1468 // Printout for debuging
1469 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1470 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1477 //__________________________________________________________________________
1478 Bool_t AliMUONTrackReconstructor::FinalizeTrack(AliMUONTrack &track)
1480 /// Recompute track parameters and covariances at each attached cluster
1481 /// from those at the first one, if not already done
1482 AliDebug(1,"Enter FinalizeTrack");
1483 if (!track.IsImproved() && !track.UpdateCovTrackParamAtCluster()) {
1484 AliWarning("finalization failed due to extrapolation problem");
1490 //__________________________________________________________________________
1491 Bool_t AliMUONTrackReconstructor::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1493 /// re-fit the given track
1495 // check validity of the track
1496 if (track.GetNClusters() < 3) {
1497 AliWarning("the track does not contain enough clusters --> unable to refit");
1501 // reset the seed (i.e. parameters at first cluster) before fitting
1502 AliMUONTrackParam* firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1503 if (firstTrackParam->GetInverseBendingMomentum() == 0.) {
1504 AliWarning("track parameters at first chamber are not initialized --> unable to refit");
1508 // compute track parameters at each cluster from parameters at the first one
1509 // necessary to compute multiple scattering effect during refitting
1510 if (!track.UpdateTrackParamAtCluster()) {
1511 AliWarning("bad track refitting due to extrapolation failure");
1515 // Re-fit the track:
1516 // Take into account the multiple scattering
1517 // Calculate the track parameter covariance matrix
1518 Fit(track, kTRUE, kFALSE, kTRUE);
1520 // Improve the reconstructed tracks if required
1521 track.SetImproved(kFALSE);
1522 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1524 // Fill AliMUONTrack data members
1525 if (track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) return FinalizeTrack(track);
1527 AliWarning("track not finalized due to extrapolation failure");