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);
54 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
57 //__________________________________________________________________________
58 AliMUONTrackReconstructor::AliMUONTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
59 : AliMUONVTrackReconstructor(recoParam,clusterServer)
64 //__________________________________________________________________________
65 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
70 //__________________________________________________________________________
71 Bool_t AliMUONTrackReconstructor::MakeTrackCandidates(AliMUONVClusterStore& clusterStore)
73 /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
74 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
75 /// Good candidates are made of at least three clusters.
76 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
78 TClonesArray *segments;
83 AliDebug(1,"Enter MakeTrackCandidates");
85 // Unless we're doing combined tracking, we'll clusterize all stations at once
86 Int_t firstChamber(0);
89 if (GetRecoParam()->CombineClusterTrackReco()) {
90 // ... Here's the exception : ask the clustering to reconstruct
91 // clusters *only* in station 4 and 5 for combined tracking
95 for (Int_t i = firstChamber; i <= lastChamber; ++i )
97 if (fClusterServer && GetRecoParam()->UseChamber(i)) fClusterServer->Clusterize(i, clusterStore, AliMpArea(), GetRecoParam());
100 // Loop over stations(1..) 5 and 4 and make track candidates
101 for (Int_t istat=4; istat>=3; istat--) {
103 // Make segments in the station
104 segments = MakeSegmentsBetweenChambers(clusterStore, 2*istat, 2*istat+1);
106 // Loop over segments
107 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
109 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
111 // Transform segments to tracks and put them at the end of fRecTracksPtr
112 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]),GetRecoParam()->GetBendingVertexDispersion());
115 // Look for compatible cluster(s) in the other station
116 if (GetRecoParam()->MakeTrackCandidatesFast())
117 clusterFound = FollowLinearTrackInStation(*track, clusterStore, 7-istat);
118 else clusterFound = FollowTrackInStation(*track, clusterStore, 7-istat);
120 // Remove track if no cluster found on a requested station
121 // or abort tracking if there are too many candidates
122 if (GetRecoParam()->RequestStation(7-istat)) {
124 fRecTracksPtr->Remove(track);
126 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
127 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
132 if ((fNRecTracks + segments->GetEntriesFast() - iseg - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
133 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iseg - 1));
141 // delete the array of segments
145 // Keep all different tracks or only the best ones as required
146 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
147 else RemoveDoubleTracks();
149 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
155 //__________________________________________________________________________
156 Bool_t AliMUONTrackReconstructor::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
158 /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
159 /// clustering is supposed to be already done
160 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
161 /// Good candidates are made of at least three clusters if both station are requested (two otherwise).
162 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
164 TClonesArray *segments;
165 AliMUONObjectPair *segment;
167 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
170 AliDebug(1,"Enter MakeMoreTrackCandidates");
172 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
173 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
174 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
176 // Make segments in the station
177 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
179 /// Remove segments already attached to a track
180 RemoveUsedSegments(*segments);
182 // Loop over segments
183 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++)
185 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
186 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
188 // Transform segments to tracks and put them at the end of fRecTracksPtr
189 iCurrentTrack = fRecTracksPtr->GetLast()+1;
190 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
193 // Look for compatible cluster(s) in the second chamber of station 5
194 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
196 // skip the original track in case it has been removed
197 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
199 // loop over every new tracks
200 nCurrentTracks = fRecTracksPtr->GetLast()+1;
201 while (iCurrentTrack < nCurrentTracks) {
202 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
204 // Look for compatible cluster(s) in the second chamber of station 4
205 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
210 // abort tracking if there are too many candidates
211 if ((fNRecTracks + segments->GetEntriesFast() - iSegment - 1) > GetRecoParam()->GetMaxTrackCandidates()) {
212 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks + segments->GetEntriesFast() - iSegment - 1));
219 // delete the array of segments
224 // Keep only the best tracks if required
225 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
226 else fRecTracksPtr->Compress();
228 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
234 //__________________________________________________________________________
235 Bool_t AliMUONTrackReconstructor::FollowTracks(AliMUONVClusterStore& clusterStore)
237 /// Follow tracks in stations(1..) 3, 2 and 1
238 AliDebug(1,"Enter FollowTracks");
240 AliMUONTrack *track, *nextTrack;
241 AliMUONTrackParam *trackParam, *nextTrackParam;
242 Int_t currentNRecTracks;
244 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
245 GetRecoParam()->GetSigmaCutForTracking();
247 for (Int_t station = 2; station >= 0; station--) {
249 // Save the actual number of reconstructed track in case of
250 // tracks are added or suppressed during the tracking procedure
251 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
252 currentNRecTracks = fNRecTracks;
254 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
255 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
257 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
260 // Do not take into account the multiple scattering to speed up the fit
261 // Calculate the track parameter covariance matrix
262 // If there is no cluster out of station 4 or 5 then use the vertex to better constrain the fit
263 if (((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetClusterPtr()->GetChamberId() > 5)
264 Fit(*track, kFALSE, kTRUE, kTRUE);
265 else Fit(*track, kFALSE, kFALSE, kTRUE);
267 // remove tracks out of limits
268 if (!IsAcceptable(*((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First()))) {
269 fRecTracksPtr->Remove(track);
274 // remove track if the normalized chi2 is too high
275 if (track->GetNormalizedChi2() > sigmaCut2) {
276 fRecTracksPtr->Remove(track);
281 // save parameters from fit into smoothed parameters to complete track afterward
282 if (GetRecoParam()->ComplementTracks()) {
284 if (station==2) { // save track parameters on stations 4 and 5
286 // extrapolate track parameters and covariances at each cluster
287 // remove the track in case of failure
288 if (!track->UpdateCovTrackParamAtCluster()) {
289 fRecTracksPtr->Remove(track);
295 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
297 trackParam->SetSmoothParameters(trackParam->GetParameters());
298 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
299 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
302 } else { // or save track parameters on last station only
304 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
305 if (trackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
307 // save parameters from fit
308 trackParam->SetSmoothParameters(trackParam->GetParameters());
309 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
311 // save parameters extrapolated to the second chamber of the same station if it has been hit
312 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
313 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
315 // reset parameters and covariances
316 nextTrackParam->SetParameters(trackParam->GetParameters());
317 nextTrackParam->SetZ(trackParam->GetZ());
318 nextTrackParam->SetCovariances(trackParam->GetCovariances());
320 // extrapolate them to the z of the corresponding cluster
321 // remove the track in case of failure
322 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
323 fRecTracksPtr->Remove(track);
329 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
330 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
340 // Look for compatible cluster(s) in station(0..) "station"
341 if (!FollowTrackInStation(*track, clusterStore, station)) {
343 // Try to recover track if required
344 if (GetRecoParam()->RecoverTracks()) {
346 // work on a copy of the track if this station is not required
347 // to keep the case where no cluster is reconstructed as a possible candidate
348 if (!GetRecoParam()->RequestStation(station)) {
349 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
354 if (!RecoverTrack(*track, clusterStore, station)) {
355 // remove track if no cluster found
356 fRecTracksPtr->Remove(track);
360 } else if (GetRecoParam()->RequestStation(station)) {
361 // remove track if no cluster found
362 fRecTracksPtr->Remove(track);
368 // abort tracking if there are too many candidates
369 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
370 AliError(Form("Too many track candidates (%d tracks). Stop tracking.", fNRecTracks));
376 // Compress fRecTracksPtr for the next step
377 fRecTracksPtr->Compress();
379 // Keep only the best tracks if required
380 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
384 // Last fit of track candidates with all stations
385 // Take into account the multiple scattering and remove bad tracks
386 Int_t trackIndex = -1;
387 track = (AliMUONTrack*) fRecTracksPtr->First();
391 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
393 Fit(*track, kTRUE, kFALSE, kTRUE);
395 // Printout for debuging
396 if (AliLog::GetGlobalDebugLevel() >= 3) {
397 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
398 track->RecursiveDump();
401 // Remove the track if the normalized chi2 is too high
402 if (track->GetNormalizedChi2() > sigmaCut2) {
403 fRecTracksPtr->Remove(track);
409 // save parameters from fit into smoothed parameters to complete track afterward
410 if (GetRecoParam()->ComplementTracks()) {
412 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
413 if (trackParam->GetClusterPtr()->GetChamberId() < 2) {
415 // save parameters from fit
416 trackParam->SetSmoothParameters(trackParam->GetParameters());
417 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
419 // save parameters extrapolated to the second chamber of the same station if it has been hit
420 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
421 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
423 // reset parameters and covariances
424 nextTrackParam->SetParameters(trackParam->GetParameters());
425 nextTrackParam->SetZ(trackParam->GetZ());
426 nextTrackParam->SetCovariances(trackParam->GetCovariances());
428 // extrapolate them to the z of the corresponding cluster
429 // remove the track in case of failure
430 if (!AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ())) {
431 fRecTracksPtr->Remove(track);
438 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
439 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
451 fRecTracksPtr->Compress();
457 //__________________________________________________________________________
458 Bool_t AliMUONTrackReconstructor::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
460 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
461 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
462 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
463 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
464 /// Remove the obsolete "trackCandidate" at the end.
465 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
466 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
468 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
469 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
470 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
471 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
472 Bool_t foundOneCluster = kFALSE;
473 AliMUONTrack *newTrack = 0x0;
474 AliMUONVCluster *cluster;
475 AliMUONTrackParam extrapTrackParam;
476 AliMUONTrackParam extrapTrackParamAtCh;
477 AliMUONTrackParam extrapTrackParamAtCluster;
478 AliMUONTrackParam bestTrackParamAtCluster;
480 // Get track parameters according to the propagation direction
481 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
482 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
484 // Printout for debuging
485 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
486 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
487 extrapTrackParamAtCh.GetParameters().Print();
488 extrapTrackParamAtCh.GetCovariances().Print();
492 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
493 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
495 // Add MCS in the missing chamber(s) if any
496 while (currentChamber > nextChamber + 1) {
497 // extrapolation to the missing chamber
499 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
501 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
504 //Extrapolate trackCandidate to chamber
505 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber))) return kFALSE;
507 // Printout for debuging
508 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
509 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
510 extrapTrackParamAtCh.GetParameters().Print();
511 extrapTrackParamAtCh.GetCovariances().Print();
514 // Printout for debuging
515 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
516 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << nextChamber+1 << endl;
519 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
520 // except for station 4 and 5 that are already entirely clusterized
521 if (GetRecoParam()->CombineClusterTrackReco()) {
522 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
525 // Create iterators to loop over clusters in both chambers
526 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
528 // look for cluster in chamber
529 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
531 // try to add the current cluster fast
532 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
534 // try to add the current cluster accuratly
535 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
537 // if good chi2 then consider to add cluster
538 if (chi2WithOneCluster < maxChi2WithOneCluster) {
539 foundOneCluster = kTRUE;
541 // Printout for debuging
542 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
543 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
544 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
548 if (GetRecoParam()->TrackAllTracks()) {
549 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
550 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
551 UpdateTrack(*newTrack,extrapTrackParamAtCluster);
554 // Printout for debuging
555 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
556 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
557 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
560 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
561 // keep track of the best single cluster except if a couple of clusters has already been found
562 bestChi2WithOneCluster = chi2WithOneCluster;
563 bestTrackParamAtCluster = extrapTrackParamAtCluster;
570 // fill out the best track if required else clean up the fRecTracksPtr array
571 if (!GetRecoParam()->TrackAllTracks()) {
572 if (foundOneCluster) {
573 UpdateTrack(trackCandidate,bestTrackParamAtCluster);
575 // Printout for debuging
576 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
577 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
578 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
581 } else return kFALSE;
583 } else if (foundOneCluster) {
585 // remove obsolete track
586 fRecTracksPtr->Remove(&trackCandidate);
589 } else return kFALSE;
595 //__________________________________________________________________________
596 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
598 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
599 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
600 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
601 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
602 /// Remove the obsolete "trackCandidate" at the end.
603 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
604 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
606 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
607 // - nextStation == station(1...) 5 => forward propagation
608 // - nextStation < station(1...) 5 => backward propagation
610 if (nextStation==4) {
611 ch1 = 2*nextStation+1;
615 ch2 = 2*nextStation+1;
618 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
619 Double_t chi2WithTwoClusters = AliMUONTrack::MaxChi2();
620 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
621 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
622 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
623 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
624 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
625 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
626 Bool_t foundOneCluster = kFALSE;
627 Bool_t foundTwoClusters = kFALSE;
628 AliMUONTrack *newTrack = 0x0;
629 AliMUONVCluster *clusterCh1, *clusterCh2;
630 AliMUONTrackParam extrapTrackParam;
631 AliMUONTrackParam extrapTrackParamAtCh;
632 AliMUONTrackParam extrapTrackParamAtCluster1;
633 AliMUONTrackParam extrapTrackParamAtCluster2;
634 AliMUONTrackParam bestTrackParamAtCluster1;
635 AliMUONTrackParam bestTrackParamAtCluster2;
637 // Get track parameters according to the propagation direction
638 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
639 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
641 // Printout for debuging
642 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
643 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
644 extrapTrackParamAtCh.GetParameters().Print();
645 extrapTrackParamAtCh.GetCovariances().Print();
649 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
650 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
652 // Add MCS in the missing chamber(s) if any
653 while (ch1 < ch2 && currentChamber > ch2 + 1) {
654 // extrapolation to the missing chamber
656 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
658 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
661 //Extrapolate trackCandidate to chamber "ch2"
662 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2))) return kFALSE;
664 // Printout for debuging
665 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
666 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
667 extrapTrackParamAtCh.GetParameters().Print();
668 extrapTrackParamAtCh.GetCovariances().Print();
671 // Printout for debuging
672 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
673 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
676 // Ask the clustering to reconstruct new clusters around the track position in the current station
677 // except for station 4 and 5 that are already entirely clusterized
678 if (GetRecoParam()->CombineClusterTrackReco()) {
679 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
682 Int_t nClusters = clusterStore.GetSize();
683 Bool_t *clusterCh1Used = new Bool_t[nClusters];
684 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
687 // Create iterators to loop over clusters in both chambers
688 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
689 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
691 // look for candidates in chamber 2
692 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
694 // try to add the current cluster fast
695 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
697 // try to add the current cluster accuratly
698 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
700 // if good chi2 then try to attach a cluster in the other chamber too
701 if (chi2WithOneCluster < maxChi2WithOneCluster) {
702 Bool_t foundSecondCluster = kFALSE;
704 // Printout for debuging
705 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
706 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
707 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
709 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
712 // add MCS effect for next step
713 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
715 // copy new track parameters for next step
716 extrapTrackParam = extrapTrackParamAtCluster2;
718 //Extrapolate track parameters to chamber "ch1"
719 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
721 // reset cluster iterator of chamber 1
725 // look for second candidates in chamber 1
726 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
729 // try to add the current cluster fast
730 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
732 // try to add the current cluster accurately
733 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
735 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
736 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
737 foundSecondCluster = kTRUE;
738 foundTwoClusters = kTRUE;
740 // Printout for debuging
741 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
742 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
743 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
747 if (GetRecoParam()->TrackAllTracks()) {
748 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
749 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
750 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
753 // Tag clusterCh1 as used
754 clusterCh1Used[iCluster1] = kTRUE;
756 // Printout for debuging
757 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
758 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
759 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
762 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
763 // keep track of the best couple of clusters
764 bestChi2WithTwoClusters = chi2WithTwoClusters;
765 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
766 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
773 // if no clusterCh1 found then consider to add clusterCh2 only
774 if (!foundSecondCluster) {
775 foundOneCluster = kTRUE;
777 if (GetRecoParam()->TrackAllTracks()) {
778 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
779 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
780 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
783 // Printout for debuging
784 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
785 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
786 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
789 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
790 // keep track of the best single cluster except if a couple of clusters has already been found
791 bestChi2WithOneCluster = chi2WithOneCluster;
792 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
801 // look for candidates in chamber 1 not already attached to a track
802 // if we want to keep all possible tracks or if no good couple of clusters has been found
803 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
805 // add MCS effect for next step
806 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
808 //Extrapolate trackCandidate to chamber "ch1"
809 Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
811 // Printout for debuging
812 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
813 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
814 extrapTrackParamAtCh.GetParameters().Print();
815 extrapTrackParamAtCh.GetCovariances().Print();
818 // Printout for debuging
819 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
820 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
823 // reset cluster iterator of chamber 1
827 // look for second candidates in chamber 1
828 if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
831 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
833 // try to add the current cluster fast
834 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
836 // try to add the current cluster accuratly
837 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
839 // if good chi2 then consider to add clusterCh1
840 // We do not try to attach a cluster in the other chamber too since it has already been done above
841 if (chi2WithOneCluster < maxChi2WithOneCluster) {
842 foundOneCluster = kTRUE;
844 // Printout for debuging
845 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
846 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
847 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
851 if (GetRecoParam()->TrackAllTracks()) {
852 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
853 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
854 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
857 // Printout for debuging
858 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
859 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
860 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
863 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
864 // keep track of the best single cluster except if a couple of clusters has already been found
865 bestChi2WithOneCluster = chi2WithOneCluster;
866 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
875 // fill out the best track if required else clean up the fRecTracksPtr array
876 if (!GetRecoParam()->TrackAllTracks()) {
877 if (foundTwoClusters) {
878 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
880 // Printout for debuging
881 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
882 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
883 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
886 } else if (foundOneCluster) {
887 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
889 // Printout for debuging
890 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
891 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
892 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
896 delete [] clusterCh1Used;
900 } else if (foundOneCluster || foundTwoClusters) {
902 // remove obsolete track
903 fRecTracksPtr->Remove(&trackCandidate);
907 delete [] clusterCh1Used;
911 delete [] clusterCh1Used;
916 //__________________________________________________________________________
917 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
918 AliMUONTrackParam &trackParamAtCluster2)
920 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
921 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
922 /// return trackParamAtCluster1 & 2
924 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
925 // and set pointer to cluster into trackParamAtCluster
926 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
927 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
928 trackParamAtCluster2.SetClusterPtr(cluster2);
929 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
931 // Set differences between track and the 2 clusters in the bending and non bending directions
932 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
934 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
935 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
936 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
937 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
939 // Calculate the error matrix from the track parameter covariances at first cluster
942 if (trackParamAtCluster1.CovariancesExist()) {
943 // Save track parameters at first cluster
944 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
946 // Save track coordinates at second cluster
947 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
948 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
950 // copy track parameters at first cluster for jacobian calculation
951 AliMUONTrackParam trackParam(trackParamAtCluster1);
953 // Get the pointer to the parameter covariance matrix at first cluster
954 const TMatrixD& kParamCov = trackParam.GetCovariances();
956 // Calculate the jacobian related to the transformation between track parameters
957 // at first cluster and track coordinates at the 2 cluster z-positions
960 // first derivative at the first cluster:
961 jacob(0,0) = 1.; // dx1/dx
962 jacob(1,2) = 1.; // dy1/dy
963 // first derivative at the second cluster:
964 TMatrixD dParam(5,1);
965 Double_t direction[5] = {-1.,-1.,1.,1.,-1.};
966 for (Int_t i=0; i<5; i++) {
967 // Skip jacobian calculation for parameters with no associated error
968 if (kParamCov(i,i) == 0.) continue;
969 // Small variation of parameter i only
970 for (Int_t j=0; j<5; j++) {
972 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
973 dParam(j,0) *= TMath::Sign(1.,direction[j]*paramAtCluster1Save(j,0)); // variation always in the same direction
974 } else dParam(j,0) = 0.;
977 // Set new track parameters at first cluster
978 trackParam.SetParameters(paramAtCluster1Save);
979 trackParam.AddParameters(dParam);
980 trackParam.SetZ(cluster1->GetZ());
982 // Extrapolate new track parameters to the z position of the second cluster
983 if (!AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ())) return 2.*AliMUONTrack::MaxChi2();
985 // Calculate the jacobian
986 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
987 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
990 // Calculate the error matrix
991 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
992 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
995 // Add cluster resolution to the error matrix
996 error(0,0) += cluster1->GetErrX2();
997 error(1,1) += cluster1->GetErrY2();
998 error(2,2) += cluster2->GetErrX2();
999 error(3,3) += cluster2->GetErrY2();
1001 // invert the error matrix for Chi2 calculation
1002 if (error.Determinant() != 0) {
1005 AliWarning(" Determinant error=0");
1006 return 2.*AliMUONTrack::MaxChi2();
1009 // Compute the Chi2 value
1010 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
1011 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
1017 //__________________________________________________________________________
1018 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
1020 /// Add 1 cluster to the track candidate
1021 /// Update chi2 of the track
1023 // Compute local chi2
1024 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
1025 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
1026 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
1027 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
1028 deltaY*deltaY / cluster->GetErrY2();
1030 // Flag cluster as being not removable
1031 if (GetRecoParam()->RequestStation(cluster->GetChamberId()/2))
1032 trackParamAtCluster.SetRemovable(kFALSE);
1033 else trackParamAtCluster.SetRemovable(kTRUE);
1034 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
1036 // Update the chi2 of the new track
1037 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
1039 // Update TrackParamAtCluster
1040 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
1044 //__________________________________________________________________________
1045 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
1047 /// Add 2 clusters to the track candidate
1048 /// Update track and local chi2
1050 // Update local chi2 at first cluster
1051 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1052 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1053 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1054 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1055 deltaY*deltaY / cluster1->GetErrY2();
1056 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1058 // Flag first cluster as being removable
1059 trackParamAtCluster1.SetRemovable(kTRUE);
1061 // Update local chi2 at second cluster
1062 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1063 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1064 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1065 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1066 deltaY*deltaY / cluster2->GetErrY2();
1067 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1069 // Flag first cluster as being removable
1070 trackParamAtCluster2.SetRemovable(kTRUE);
1072 // Update the chi2 of the new track
1073 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
1075 // Update TrackParamAtCluster
1076 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1077 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1081 //__________________________________________________________________________
1082 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1084 /// Try to recover the track candidate in the next station
1085 /// by removing the worst of the two clusters attached in the current station
1086 /// Return kTRUE if recovering succeeds
1087 AliDebug(1,"Enter RecoverTrack");
1089 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1090 if (nextStation > 1) return kFALSE;
1092 Int_t worstClusterNumber = -1;
1093 Double_t localChi2, worstLocalChi2 = -1.;
1095 // Look for the cluster to remove
1096 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1097 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1099 // check if current cluster is in the previous station
1100 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1102 // check if current cluster is removable
1103 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1105 // reset the current cluster as beig not removable if it is on a required station
1106 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1108 // Pick up cluster with the worst chi2
1109 localChi2 = trackParamAtCluster->GetLocalChi2();
1110 if (localChi2 > worstLocalChi2) {
1111 worstLocalChi2 = localChi2;
1112 worstClusterNumber = clusterNumber;
1117 // check if worst cluster found
1118 if (worstClusterNumber < 0) return kFALSE;
1120 // Remove the worst cluster
1121 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1123 // Re-fit the track:
1124 // Do not take into account the multiple scattering to speed up the fit
1125 // Calculate the track parameter covariance matrix
1126 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
1128 // skip track if the normalized chi2 is too high
1129 if (trackCandidate.GetNormalizedChi2() > GetRecoParam()->GetSigmaCutForTracking() * GetRecoParam()->GetSigmaCutForTracking()) return kFALSE;
1131 // skip track out of limits
1132 if (!IsAcceptable(*((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First()))) return kFALSE;
1134 // Look for new cluster(s) in next station
1135 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
1139 //__________________________________________________________________________
1140 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
1142 /// Compute the vertex resolution square from natural vertex dispersion and
1143 /// multiple scattering effets according to trackCandidate path in absorber
1144 /// It is necessary to account for multiple scattering effects here instead of during the fit of
1145 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
1146 AliDebug(1,"Enter SetVertexForFit");
1148 Double_t nonBendingReso2 = GetRecoParam()->GetNonBendingVertexDispersion() *
1149 GetRecoParam()->GetNonBendingVertexDispersion();
1150 Double_t bendingReso2 = GetRecoParam()->GetBendingVertexDispersion() *
1151 GetRecoParam()->GetBendingVertexDispersion();
1153 // add multiple scattering effets
1154 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
1155 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
1156 if (!AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex,AliMUONConstants::AbsZEnd())) {
1157 nonBendingReso2 = 0.;
1160 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
1161 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
1162 nonBendingReso2 += kParamCov(0,0);
1163 bendingReso2 += kParamCov(2,2);
1166 // Set the vertex resolution square
1167 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
1170 //__________________________________________________________________________
1171 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
1174 /// w/wo multiple Coulomb scattering according to "includeMCS".
1175 /// w/wo constraining the vertex according to "fitWithVertex".
1176 /// calculating or not the covariance matrix according to "calcCov".
1177 AliDebug(1,"Enter Fit");
1179 Double_t benC, errorParam, invBenP, nonBenC, x, y;
1180 AliMUONTrackParam *trackParam;
1181 Double_t arg[1], fedm, errdef, globalChi2;
1183 Int_t status, covStatus;
1185 // Instantiate gMinuit if not already done
1186 if (!gMinuit) gMinuit = new TMinuit(6);
1187 // Clear MINUIT parameters
1189 // Give the fitted track to MINUIT
1190 gMinuit->SetObjectFit(&track);
1191 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1192 // Define print level
1194 gMinuit->mnexcm("SET PRI", arg, 1, status);
1195 // Print covariance matrix
1196 gMinuit->mnexcm("SHO COV", arg, 0, status);
1199 gMinuit->mnexcm("SET PRI", arg, 1, status);
1202 gMinuit->mnexcm("SET NOW", arg, 0, status);
1205 //gMinuit->mnexcm("SET STR", arg, 1, status);
1207 // set flag w/wo multiple scattering according to "includeMCS"
1208 track.FitWithMCS(includeMCS);
1210 // compute cluster weights only once
1211 if (!track.UpdateTrackParamAtCluster() || !track.ComputeClusterWeights()) {
1212 AliWarning("cannot take into account the multiple scattering effects");
1213 track.FitWithMCS(kFALSE);
1217 track.FitWithVertex(fitWithVertex);
1218 if (fitWithVertex) SetVertexErrXY2ForFit(track);
1220 // Set fitting function
1221 gMinuit->SetFCN(TrackChi2);
1223 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
1224 // Mandatory limits to avoid NaN values of parameters
1225 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1226 Double_t maxIBM = 1. / GetRecoParam()->GetMinBendingMomentum();
1227 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
1228 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -1., 1., status);
1229 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
1230 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -1.5, 1.5, status);
1231 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -maxIBM, maxIBM, status);
1234 gMinuit->mnexcm("MIGRAD", arg, 0, status);
1236 // Calculate the covariance matrix more accurately if required
1237 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
1239 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
1240 gMinuit->GetParameter(0, x, errorParam);
1241 trackParam->SetNonBendingCoor(x);
1242 gMinuit->GetParameter(1, nonBenC, errorParam);
1243 trackParam->SetNonBendingSlope(nonBenC);
1244 gMinuit->GetParameter(2, y, errorParam);
1245 trackParam->SetBendingCoor(y);
1246 gMinuit->GetParameter(3, benC, errorParam);
1247 trackParam->SetBendingSlope(benC);
1248 gMinuit->GetParameter(4, invBenP, errorParam);
1249 trackParam->SetInverseBendingMomentum(invBenP);
1251 // global result of the fit
1252 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
1253 track.SetGlobalChi2(globalChi2);
1255 // Get the covariance matrix if required
1257 // Covariance matrix according to HESSE status
1258 // If problem then keep only the diagonal terms (variances)
1259 Double_t matrix[5][5];
1260 for (Int_t i=0; i<5; i++) for (Int_t j=0; j<5; j++) matrix[i][j] = 0.;
1261 gMinuit->mnemat(&matrix[0][0],5);
1262 if (covStatus == 3) trackParam->SetCovariances(matrix);
1263 else trackParam->SetVariances(matrix);
1264 } else trackParam->DeleteCovariances();
1268 //__________________________________________________________________________
1269 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
1271 /// Return the "Chi2" to be minimized with Minuit for track fitting.
1272 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
1273 /// Track parameters at each cluster are updated accordingly.
1274 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
1275 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
1277 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
1278 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
1280 chi2 = 0.; // initialize chi2
1282 // update track parameters
1283 trackParamAtCluster->SetNonBendingCoor(param[0]);
1284 trackParamAtCluster->SetNonBendingSlope(param[1]);
1285 trackParamAtCluster->SetBendingCoor(param[2]);
1286 trackParamAtCluster->SetBendingSlope(param[3]);
1287 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
1288 if (!trackBeingFitted->UpdateTrackParamAtCluster()) {
1289 chi2 = 2.*AliMUONTrack::MaxChi2();
1293 // Take the vertex into account in the fit if required
1294 if (trackBeingFitted->FitWithVertex()) {
1295 Double_t nonBendingReso2,bendingReso2;
1296 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
1297 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
1298 if (nonBendingReso2 != 0. && bendingReso2 != 0. && AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.)) { // vextex position = (0,0,0)
1299 dX = paramAtVertex.GetNonBendingCoor();
1300 dY = paramAtVertex.GetBendingCoor();
1301 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
1303 chi2 = 2.*AliMUONTrack::MaxChi2();
1308 // compute chi2 w/wo multiple scattering
1309 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
1313 //__________________________________________________________________________
1314 Bool_t AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1316 /// Complete tracks by adding missing clusters (if there is an overlap between
1317 /// two detection elements, the track may have two clusters in the same chamber).
1318 /// Re-fit track parameters and covariances.
1319 /// Return kTRUE if one or more tracks have been complemented.
1320 AliDebug(1,"Enter ComplementTracks");
1322 Int_t chamberId, detElemId;
1323 Double_t chi2OfCluster, bestChi2OfCluster;
1324 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
1325 GetRecoParam()->GetSigmaCutForTracking();
1326 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
1327 AliMUONVCluster* cluster;
1328 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1330 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1332 trackModified = kFALSE;
1334 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1335 while (trackParam) {
1336 foundOneCluster = kFALSE;
1337 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
1338 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1339 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1341 // prepare nextTrackParam before adding new cluster because of the sorting
1342 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1344 // recover track parameters from local fit and put them into a copy of trackParam
1345 copyOfTrackParam.SetZ(trackParam->GetZ());
1346 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1347 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1349 // Create iterators to loop over clusters in current chamber
1350 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1352 // look for one second candidate in the same chamber
1353 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1355 // look for a cluster in another detection element
1356 if (cluster->GetDetElemId() == detElemId) continue;
1358 // try to add the current cluster fast
1359 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1361 // try to add the current cluster accurately
1362 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1364 // if better chi2 then prepare to add this cluster to the track
1365 if (chi2OfCluster < bestChi2OfCluster) {
1366 bestChi2OfCluster = chi2OfCluster;
1367 bestTrackParamAtCluster = trackParamAtCluster;
1368 foundOneCluster = kTRUE;
1373 // add new cluster if any
1374 if (foundOneCluster) {
1376 // Printout for debuging
1377 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1378 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1379 bestTrackParamAtCluster.GetClusterPtr()->Print();
1380 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1381 bestTrackParamAtCluster.GetParameters().Print();
1382 bestTrackParamAtCluster.GetCovariances().Print();
1385 trackParam->SetRemovable(kTRUE);
1386 bestTrackParamAtCluster.SetRemovable(kTRUE);
1387 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1388 trackModified = kTRUE;
1392 trackParam = nextTrackParam;
1395 // re-fit track parameters if needed
1396 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1398 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1405 //__________________________________________________________________________
1406 void AliMUONTrackReconstructor::ImproveTrack(AliMUONTrack &track)
1408 /// Improve the given track by removing clusters with local chi2 highter than the defined cut
1409 /// Recompute track parameters and covariances at the remaining clusters
1410 AliDebug(1,"Enter ImproveTrack");
1412 Double_t localChi2, worstLocalChi2;
1413 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster;
1414 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1415 GetRecoParam()->GetSigmaCutForImprovement();
1417 while (!track.IsImproved()) {
1419 // identify removable clusters
1420 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
1422 // Update track parameters and covariances
1423 if (!track.UpdateCovTrackParamAtCluster()) {
1424 AliWarning("unable to update track parameters and covariances --> stop improvement");
1428 // Compute local chi2 of each clusters
1429 track.ComputeLocalChi2(kTRUE);
1431 // Look for the cluster to remove
1432 worstTrackParamAtCluster = NULL;
1433 worstLocalChi2 = 0.;
1434 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1435 while (trackParamAtCluster) {
1437 // Pick up cluster with the worst chi2
1438 localChi2 = trackParamAtCluster->GetLocalChi2();
1439 if (localChi2 > worstLocalChi2) {
1440 worstLocalChi2 = localChi2;
1441 worstTrackParamAtCluster = trackParamAtCluster;
1444 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1447 // Check if worst cluster found
1448 if (!worstTrackParamAtCluster) {
1449 AliWarning("Bad local chi2 values?");
1453 // Check whether the worst chi2 is under requirement or not
1454 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1455 track.SetImproved(kTRUE);
1459 // if the worst cluster is not removable then stop improvement
1460 if (!worstTrackParamAtCluster->IsRemovable()) break;
1462 // Remove the worst cluster
1463 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1465 // Re-fit the track:
1466 // Take into account the multiple scattering
1467 // Calculate the track parameter covariance matrix
1468 Fit(track, kTRUE, kFALSE, kTRUE);
1470 // Printout for debuging
1471 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1472 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1479 //__________________________________________________________________________
1480 Bool_t AliMUONTrackReconstructor::FinalizeTrack(AliMUONTrack &track)
1482 /// Recompute track parameters and covariances at each attached cluster
1483 /// from those at the first one, if not already done
1484 AliDebug(1,"Enter FinalizeTrack");
1485 if (!track.IsImproved() && !track.UpdateCovTrackParamAtCluster()) {
1486 AliWarning("finalization failed due to extrapolation problem");
1492 //__________________________________________________________________________
1493 Bool_t AliMUONTrackReconstructor::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1495 /// re-fit the given track
1497 // check validity of the track
1498 if (track.GetNClusters() < 3) {
1499 AliWarning("the track does not contain enough clusters --> unable to refit");
1503 // reset the seed (i.e. parameters at first cluster) before fitting
1504 AliMUONTrackParam* firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1505 if (firstTrackParam->GetInverseBendingMomentum() == 0.) {
1506 AliWarning("track parameters at first chamber are not initialized --> unable to refit");
1510 // compute track parameters at each cluster from parameters at the first one
1511 // necessary to compute multiple scattering effect during refitting
1512 if (!track.UpdateTrackParamAtCluster()) {
1513 AliWarning("bad track refitting due to extrapolation failure");
1517 // Re-fit the track:
1518 // Take into account the multiple scattering
1519 // Calculate the track parameter covariance matrix
1520 Fit(track, kTRUE, kFALSE, kTRUE);
1522 // Improve the reconstructed tracks if required
1523 track.SetImproved(kFALSE);
1524 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1526 // Fill AliMUONTrack data members
1527 if (track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) return FinalizeTrack(track);
1529 AliWarning("track not finalized due to extrapolation failure");