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 (!clusterFound && GetRecoParam()->RequestStation(7-istat)) {
122 fRecTracksPtr->Remove(track);
124 } else if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
125 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks));
132 // delete the array of segments
136 // Keep all different tracks or only the best ones as required
137 if (GetRecoParam()->TrackAllTracks()) RemoveIdenticalTracks();
138 else RemoveDoubleTracks();
140 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
146 //__________________________________________________________________________
147 Bool_t AliMUONTrackReconstructor::MakeMoreTrackCandidates(AliMUONVClusterStore& clusterStore)
149 /// To make extra track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE):
150 /// clustering is supposed to be already done
151 /// Start with segments made of 1 cluster in each of the stations 4 and 5 then follow track in remaining chambers.
152 /// Good candidates are made of at least three clusters if both station are requested (two otherwise).
153 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
155 TClonesArray *segments;
156 AliMUONObjectPair *segment;
158 Int_t iCandidate = 0, iCurrentTrack, nCurrentTracks;
161 AliDebug(1,"Enter MakeMoreTrackCandidates");
163 // Double loop over chambers in stations(1..) 4 and 5 to make track candidates
164 for (Int_t ich1 = 6; ich1 <= 7; ich1++) {
165 for (Int_t ich2 = 8; ich2 <= 9; ich2++) {
167 // Make segments in the station
168 segments = MakeSegmentsBetweenChambers(clusterStore, ich1, ich2);
170 /// Remove segments already attached to a track
171 RemoveUsedSegments(*segments);
173 // Loop over segments
174 for (Int_t iSegment=0; iSegment<segments->GetEntriesFast(); iSegment++)
176 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
177 segment = (AliMUONObjectPair*) segments->UncheckedAt(iSegment);
179 // Transform segments to tracks and put them at the end of fRecTracksPtr
180 iCurrentTrack = fRecTracksPtr->GetLast()+1;
181 track = new ((*fRecTracksPtr)[iCurrentTrack]) AliMUONTrack(segment,GetRecoParam()->GetBendingVertexDispersion());
184 // Look for compatible cluster(s) in the second chamber of station 5
185 clusterFound = FollowLinearTrackInChamber(*track, clusterStore, 17-ich2);
187 // skip the original track in case it has been removed
188 if (GetRecoParam()->TrackAllTracks() && clusterFound) iCurrentTrack++;
190 // loop over every new tracks
191 nCurrentTracks = fRecTracksPtr->GetLast()+1;
192 while (iCurrentTrack < nCurrentTracks) {
193 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iCurrentTrack);
195 // Look for compatible cluster(s) in the second chamber of station 4
196 FollowLinearTrackInChamber(*track, clusterStore, 13-ich1);
201 // abort tracking if there are too many candidates
202 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
203 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks));
210 // delete the array of segments
215 // Keep only the best tracks if required
216 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
217 else fRecTracksPtr->Compress();
219 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
225 //__________________________________________________________________________
226 Bool_t AliMUONTrackReconstructor::FollowTracks(AliMUONVClusterStore& clusterStore)
228 /// Follow tracks in stations(1..) 3, 2 and 1
229 AliDebug(1,"Enter FollowTracks");
231 AliMUONTrack *track, *nextTrack;
232 AliMUONTrackParam *trackParam, *nextTrackParam;
233 Int_t currentNRecTracks;
235 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
236 GetRecoParam()->GetSigmaCutForTracking();
238 for (Int_t station = 2; station >= 0; station--) {
240 // Save the actual number of reconstructed track in case of
241 // tracks are added or suppressed during the tracking procedure
242 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
243 currentNRecTracks = fNRecTracks;
245 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
246 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
248 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
251 // Do not take into account the multiple scattering to speed up the fit
252 // Calculate the track parameter covariance matrix
253 // If there is no cluster out of station 4 or 5 then use the vertex to better constrain the fit
254 if (((AliMUONTrackParam*) track->GetTrackParamAtCluster()->First())->GetClusterPtr()->GetChamberId() > 5)
255 Fit(*track, kFALSE, kTRUE, kTRUE);
256 else Fit(*track, kFALSE, kFALSE, kTRUE);
258 // remove track with absolute bending momentum out of limits
259 if (AliMUONTrackExtrap::IsFieldON()) {
260 Double_t bendingMomentum = TMath::Abs(1. / ((AliMUONTrackParam*)track->GetTrackParamAtCluster()->First())->GetInverseBendingMomentum());
261 if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
262 bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) {
263 fRecTracksPtr->Remove(track);
269 // remove track if the normalized chi2 is too high
270 if (track->GetNormalizedChi2() > sigmaCut2) {
271 fRecTracksPtr->Remove(track);
276 // save parameters from fit into smoothed parameters to complete track afterward
277 if (GetRecoParam()->ComplementTracks()) {
279 if (station==2) { // save track parameters on stations 4 and 5
281 // extrapolate track parameters and covariances at each cluster
282 track->UpdateCovTrackParamAtCluster();
285 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
287 trackParam->SetSmoothParameters(trackParam->GetParameters());
288 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
289 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
292 } else { // or save track parameters on last station only
294 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
295 if (trackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
297 // save parameters from fit
298 trackParam->SetSmoothParameters(trackParam->GetParameters());
299 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
301 // save parameters extrapolated to the second chamber of the same station if it has been hit
302 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
303 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2*(station+2)) {
305 // reset parameters and covariances
306 nextTrackParam->SetParameters(trackParam->GetParameters());
307 nextTrackParam->SetZ(trackParam->GetZ());
308 nextTrackParam->SetCovariances(trackParam->GetCovariances());
310 // extrapolate them to the z of the corresponding cluster
311 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
314 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
315 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
325 // Look for compatible cluster(s) in station(0..) "station"
326 if (!FollowTrackInStation(*track, clusterStore, station)) {
328 // Try to recover track if required
329 if (GetRecoParam()->RecoverTracks()) {
331 // work on a copy of the track if this station is not required
332 // to keep the case where no cluster is reconstructed as a possible candidate
333 if (!GetRecoParam()->RequestStation(station)) {
334 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*track);
339 if (!RecoverTrack(*track, clusterStore, station)) {
340 // remove track if no cluster found
341 fRecTracksPtr->Remove(track);
345 } else if (GetRecoParam()->RequestStation(station)) {
346 // remove track if no cluster found
347 fRecTracksPtr->Remove(track);
353 // abort tracking if there are too many candidates
354 if (fNRecTracks > GetRecoParam()->GetMaxTrackCandidates()) {
355 AliError(Form("Too many track candidates (%d tracks). Abort tracking.", fNRecTracks));
361 // Compress fRecTracksPtr for the next step
362 fRecTracksPtr->Compress();
364 // Keep only the best tracks if required
365 if (!GetRecoParam()->TrackAllTracks()) RemoveDoubleTracks();
369 // Last fit of track candidates with all stations
370 // Take into account the multiple scattering and remove bad tracks
371 Int_t trackIndex = -1;
372 track = (AliMUONTrack*) fRecTracksPtr->First();
376 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
378 Fit(*track, kTRUE, kFALSE, kTRUE);
380 // Printout for debuging
381 if (AliLog::GetGlobalDebugLevel() >= 3) {
382 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
383 track->RecursiveDump();
386 // Remove the track if the normalized chi2 is too high
387 if (track->GetNormalizedChi2() > sigmaCut2) {
388 fRecTracksPtr->Remove(track);
394 // save parameters from fit into smoothed parameters to complete track afterward
395 if (GetRecoParam()->ComplementTracks()) {
397 trackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
398 if (trackParam->GetClusterPtr()->GetChamberId() < 2) {
400 // save parameters from fit
401 trackParam->SetSmoothParameters(trackParam->GetParameters());
402 trackParam->SetSmoothCovariances(trackParam->GetCovariances());
404 // save parameters extrapolated to the second chamber of the same station if it has been hit
405 nextTrackParam = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->After(trackParam);
406 if (nextTrackParam->GetClusterPtr()->GetChamberId() < 2) {
408 // reset parameters and covariances
409 nextTrackParam->SetParameters(trackParam->GetParameters());
410 nextTrackParam->SetZ(trackParam->GetZ());
411 nextTrackParam->SetCovariances(trackParam->GetCovariances());
413 // extrapolate them to the z of the corresponding cluster
414 AliMUONTrackExtrap::ExtrapToZCov(nextTrackParam, nextTrackParam->GetClusterPtr()->GetZ());
417 nextTrackParam->SetSmoothParameters(nextTrackParam->GetParameters());
418 nextTrackParam->SetSmoothCovariances(nextTrackParam->GetCovariances());
430 fRecTracksPtr->Compress();
436 //__________________________________________________________________________
437 Bool_t AliMUONTrackReconstructor::FollowTrackInChamber(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextChamber)
439 /// Follow trackCandidate in chamber(0..) nextChamber and search for compatible cluster(s)
440 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
441 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
442 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
443 /// Remove the obsolete "trackCandidate" at the end.
444 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
445 AliDebug(1,Form("Enter FollowTrackInChamber(1..) %d", nextChamber+1));
447 Double_t chi2WithOneCluster = 1.e10;
448 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
449 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
450 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
451 Bool_t foundOneCluster = kFALSE;
452 AliMUONTrack *newTrack = 0x0;
453 AliMUONVCluster *cluster;
454 AliMUONTrackParam extrapTrackParam;
455 AliMUONTrackParam extrapTrackParamAtCh;
456 AliMUONTrackParam extrapTrackParamAtCluster;
457 AliMUONTrackParam bestTrackParamAtCluster;
459 // Get track parameters according to the propagation direction
460 if (nextChamber > 7) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
461 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
463 // Printout for debuging
464 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
465 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
466 extrapTrackParamAtCh.GetParameters().Print();
467 extrapTrackParamAtCh.GetCovariances().Print();
471 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
473 // Add MCS in the missing chamber(s) if any
474 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
475 while (currentChamber > nextChamber + 1) {
476 // extrapolation to the missing chamber
478 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber));
480 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
483 //Extrapolate trackCandidate to chamber
484 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(nextChamber));
486 // Printout for debuging
487 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
488 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(nextChamber)<<":"<<endl;
489 extrapTrackParamAtCh.GetParameters().Print();
490 extrapTrackParamAtCh.GetCovariances().Print();
493 // Printout for debuging
494 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
495 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << nextChamber+1 << endl;
498 // Ask the clustering to reconstruct new clusters around the track position in the current chamber
499 // except for station 4 and 5 that are already entirely clusterized
500 if (GetRecoParam()->CombineClusterTrackReco()) {
501 if (nextChamber < 6) AskForNewClustersInChamber(extrapTrackParamAtCh, clusterStore, nextChamber);
504 // Create iterators to loop over clusters in both chambers
505 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
507 // look for cluster in chamber
508 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
510 // try to add the current cluster fast
511 if (!TryOneClusterFast(extrapTrackParamAtCh, cluster)) continue;
513 // try to add the current cluster accuratly
514 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, cluster, extrapTrackParamAtCluster);
516 // if good chi2 then consider to add cluster
517 if (chi2WithOneCluster < maxChi2WithOneCluster) {
518 foundOneCluster = kTRUE;
520 // Printout for debuging
521 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
522 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << nextChamber+1
523 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
527 if (GetRecoParam()->TrackAllTracks()) {
528 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
529 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
530 UpdateTrack(*newTrack,extrapTrackParamAtCluster);
533 // Printout for debuging
534 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
535 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << nextChamber+1 << endl;
536 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
539 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
540 // keep track of the best single cluster except if a couple of clusters has already been found
541 bestChi2WithOneCluster = chi2WithOneCluster;
542 bestTrackParamAtCluster = extrapTrackParamAtCluster;
549 // fill out the best track if required else clean up the fRecTracksPtr array
550 if (!GetRecoParam()->TrackAllTracks()) {
551 if (foundOneCluster) {
552 UpdateTrack(trackCandidate,bestTrackParamAtCluster);
554 // Printout for debuging
555 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
556 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
557 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
560 } else return kFALSE;
562 } else if (foundOneCluster) {
564 // remove obsolete track
565 fRecTracksPtr->Remove(&trackCandidate);
568 } else return kFALSE;
574 //__________________________________________________________________________
575 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
577 /// Follow trackCandidate in station(0..) nextStation and search for compatible cluster(s)
578 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
579 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
580 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
581 /// Remove the obsolete "trackCandidate" at the end.
582 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
583 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
585 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
586 // - nextStation == station(1...) 5 => forward propagation
587 // - nextStation < station(1...) 5 => backward propagation
589 if (nextStation==4) {
590 ch1 = 2*nextStation+1;
594 ch2 = 2*nextStation+1;
597 Double_t chi2WithOneCluster = 1.e10;
598 Double_t chi2WithTwoClusters = 1.e10;
599 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
600 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
601 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
602 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
603 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
604 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
605 Bool_t foundOneCluster = kFALSE;
606 Bool_t foundTwoClusters = kFALSE;
607 AliMUONTrack *newTrack = 0x0;
608 AliMUONVCluster *clusterCh1, *clusterCh2;
609 AliMUONTrackParam extrapTrackParam;
610 AliMUONTrackParam extrapTrackParamAtCh;
611 AliMUONTrackParam extrapTrackParamAtCluster1;
612 AliMUONTrackParam extrapTrackParamAtCluster2;
613 AliMUONTrackParam bestTrackParamAtCluster1;
614 AliMUONTrackParam bestTrackParamAtCluster2;
616 Int_t nClusters = clusterStore.GetSize();
617 Bool_t *clusterCh1Used = new Bool_t[nClusters];
618 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
621 // Get track parameters according to the propagation direction
622 if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
623 else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
625 // Printout for debuging
626 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
627 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
628 extrapTrackParamAtCh.GetParameters().Print();
629 extrapTrackParamAtCh.GetCovariances().Print();
633 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
635 // Add MCS in the missing chamber(s) if any
636 Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
637 while (ch1 < ch2 && currentChamber > ch2 + 1) {
638 // extrapolation to the missing chamber
640 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber));
642 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
645 //Extrapolate trackCandidate to chamber "ch2"
646 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2));
648 // Printout for debuging
649 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
650 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
651 extrapTrackParamAtCh.GetParameters().Print();
652 extrapTrackParamAtCh.GetCovariances().Print();
655 // Printout for debuging
656 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
657 cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
660 // Ask the clustering to reconstruct new clusters around the track position in the current station
661 // except for station 4 and 5 that are already entirely clusterized
662 if (GetRecoParam()->CombineClusterTrackReco()) {
663 if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
666 // Create iterators to loop over clusters in both chambers
667 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
668 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
670 // look for candidates in chamber 2
671 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
673 // try to add the current cluster fast
674 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
676 // try to add the current cluster accuratly
677 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
679 // if good chi2 then try to attach a cluster in the other chamber too
680 if (chi2WithOneCluster < maxChi2WithOneCluster) {
681 Bool_t foundSecondCluster = kFALSE;
683 // Printout for debuging
684 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
685 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
686 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
688 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
691 // add MCS effect for next step
692 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
694 // copy new track parameters for next step
695 extrapTrackParam = extrapTrackParamAtCluster2;
697 //Extrapolate track parameters to chamber "ch1"
698 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
700 // reset cluster iterator of chamber 1
704 // look for second candidates in chamber 1
705 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
708 // try to add the current cluster fast
709 if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
711 // try to add the current cluster accuratly
712 chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
714 // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
715 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
716 foundSecondCluster = kTRUE;
717 foundTwoClusters = kTRUE;
719 // Printout for debuging
720 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
721 cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
722 << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
726 if (GetRecoParam()->TrackAllTracks()) {
727 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
728 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
729 UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
732 // Tag clusterCh1 as used
733 clusterCh1Used[iCluster1] = kTRUE;
735 // Printout for debuging
736 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
737 cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
738 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
741 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
742 // keep track of the best couple of clusters
743 bestChi2WithTwoClusters = chi2WithTwoClusters;
744 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
745 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
752 // if no clusterCh1 found then consider to add clusterCh2 only
753 if (!foundSecondCluster) {
754 foundOneCluster = kTRUE;
756 if (GetRecoParam()->TrackAllTracks()) {
757 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
758 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
759 UpdateTrack(*newTrack,extrapTrackParamAtCluster2);
762 // Printout for debuging
763 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
764 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
765 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
768 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
769 // keep track of the best single cluster except if a couple of clusters has already been found
770 bestChi2WithOneCluster = chi2WithOneCluster;
771 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
780 // look for candidates in chamber 1 not already attached to a track
781 // if we want to keep all possible tracks or if no good couple of clusters has been found
782 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
784 // add MCS effect for next step
785 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
787 //Extrapolate trackCandidate to chamber "ch1"
788 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
790 // Printout for debuging
791 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
792 cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch1)<<":"<<endl;
793 extrapTrackParamAtCh.GetParameters().Print();
794 extrapTrackParamAtCh.GetCovariances().Print();
797 // Printout for debuging
798 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
799 cout << "FollowTrackInStation: look for single clusters in chamber(1..): " << ch1+1 << endl;
802 // reset cluster iterator of chamber 1
806 // look for second candidates in chamber 1
807 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
810 if (clusterCh1Used[iCluster1]) continue; // Skip cluster already used
812 // try to add the current cluster fast
813 if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh1)) continue;
815 // try to add the current cluster accuratly
816 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh1, extrapTrackParamAtCluster1);
818 // if good chi2 then consider to add clusterCh1
819 // We do not try to attach a cluster in the other chamber too since it has already been done above
820 if (chi2WithOneCluster < maxChi2WithOneCluster) {
821 foundOneCluster = kTRUE;
823 // Printout for debuging
824 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
825 cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch1+1
826 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
830 if (GetRecoParam()->TrackAllTracks()) {
831 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
832 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
833 UpdateTrack(*newTrack,extrapTrackParamAtCluster1);
836 // Printout for debuging
837 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
838 cout << "FollowTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
839 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
842 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
843 // keep track of the best single cluster except if a couple of clusters has already been found
844 bestChi2WithOneCluster = chi2WithOneCluster;
845 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
854 // fill out the best track if required else clean up the fRecTracksPtr array
855 if (!GetRecoParam()->TrackAllTracks()) {
856 if (foundTwoClusters) {
857 UpdateTrack(trackCandidate,bestTrackParamAtCluster1,bestTrackParamAtCluster2);
859 // Printout for debuging
860 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
861 cout << "FollowTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
862 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
865 } else if (foundOneCluster) {
866 UpdateTrack(trackCandidate,bestTrackParamAtCluster1);
868 // Printout for debuging
869 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
870 cout << "FollowTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
871 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
875 delete [] clusterCh1Used;
879 } else if (foundOneCluster || foundTwoClusters) {
881 // remove obsolete track
882 fRecTracksPtr->Remove(&trackCandidate);
886 delete [] clusterCh1Used;
890 delete [] clusterCh1Used;
895 //__________________________________________________________________________
896 Double_t AliMUONTrackReconstructor::TryTwoClusters(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
897 AliMUONTrackParam &trackParamAtCluster2)
899 /// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix):
900 /// return the corresponding Chi2 accounting for covariances between the 2 clusters
901 /// return trackParamAtCluster1 & 2
903 // extrapolate track parameters at the z position of the second cluster (no need to extrapolate the covariances)
904 trackParamAtCluster2.SetParameters(trackParamAtCluster1.GetParameters());
905 trackParamAtCluster2.SetZ(trackParamAtCluster1.GetZ());
906 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
908 // set pointer to cluster2 into trackParamAtCluster2
909 trackParamAtCluster2.SetClusterPtr(cluster2);
911 // Set differences between track and the 2 clusters in the bending and non bending directions
912 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
914 dPos(0,0) = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
915 dPos(1,0) = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
916 dPos(2,0) = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
917 dPos(3,0) = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
919 // Calculate the error matrix from the track parameter covariances at first cluster
922 if (trackParamAtCluster1.CovariancesExist()) {
923 // Save track parameters at first cluster
924 TMatrixD paramAtCluster1Save(trackParamAtCluster1.GetParameters());
926 // Save track coordinates at second cluster
927 Double_t nonBendingCoor2 = trackParamAtCluster2.GetNonBendingCoor();
928 Double_t bendingCoor2 = trackParamAtCluster2.GetBendingCoor();
930 // copy track parameters at first cluster for jacobian calculation
931 AliMUONTrackParam trackParam(trackParamAtCluster1);
933 // add MCS effect to the covariance matrix at first cluster
934 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
936 // Get the pointer to the parameter covariance matrix at first cluster
937 const TMatrixD& kParamCov = trackParam.GetCovariances();
939 // Calculate the jacobian related to the transformation between track parameters
940 // at first cluster and track coordinates at the 2 cluster z-positions
943 // first derivative at the first cluster:
944 jacob(0,0) = 1.; // dx1/dx
945 jacob(1,2) = 1.; // dy1/dy
946 // first derivative at the second cluster:
947 TMatrixD dParam(5,1);
948 for (Int_t i=0; i<5; i++) {
949 // Skip jacobian calculation for parameters with no associated error
950 if (kParamCov(i,i) == 0.) continue;
951 // Small variation of parameter i only
952 for (Int_t j=0; j<5; j++) {
954 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
955 if (j == 4) dParam(j,0) *= TMath::Sign(1.,-paramAtCluster1Save(4,0)); // variation always in the same direction
956 } else dParam(j,0) = 0.;
959 // Set new track parameters at first cluster
960 trackParam.SetParameters(paramAtCluster1Save);
961 trackParam.AddParameters(dParam);
962 trackParam.SetZ(cluster1->GetZ());
964 // Extrapolate new track parameters to the z position of the second cluster
965 AliMUONTrackExtrap::ExtrapToZ(&trackParam,cluster2->GetZ());
967 // Calculate the jacobian
968 jacob(2,i) = (trackParam.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
969 jacob(3,i) = (trackParam.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
972 // Calculate the error matrix
973 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
974 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
977 // Add cluster resolution to the error matrix
978 error(0,0) += cluster1->GetErrX2();
979 error(1,1) += cluster1->GetErrY2();
980 error(2,2) += cluster2->GetErrX2();
981 error(3,3) += cluster2->GetErrY2();
983 // invert the error matrix for Chi2 calculation
984 if (error.Determinant() != 0) {
987 AliWarning(" Determinant error=0");
991 // Compute the Chi2 value
992 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
993 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
999 //__________________________________________________________________________
1000 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster)
1002 /// Add 1 cluster to the track candidate
1003 /// Update chi2 of the track
1005 // Compute local chi2
1006 AliMUONVCluster* cluster = trackParamAtCluster.GetClusterPtr();
1007 Double_t deltaX = trackParamAtCluster.GetNonBendingCoor() - cluster->GetX();
1008 Double_t deltaY = trackParamAtCluster.GetBendingCoor() - cluster->GetY();
1009 Double_t localChi2 = deltaX*deltaX / cluster->GetErrX2() +
1010 deltaY*deltaY / cluster->GetErrY2();
1012 // Flag cluster as being not removable
1013 if (GetRecoParam()->RequestStation(cluster->GetChamberId()/2))
1014 trackParamAtCluster.SetRemovable(kFALSE);
1015 else trackParamAtCluster.SetRemovable(kTRUE);
1016 trackParamAtCluster.SetLocalChi2(0.); // --> Local chi2 not used
1018 // Update the chi2 of the new track
1019 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2);
1021 // Update TrackParamAtCluster
1022 track.AddTrackParamAtCluster(trackParamAtCluster,*cluster);
1026 //__________________________________________________________________________
1027 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtCluster1, AliMUONTrackParam &trackParamAtCluster2)
1029 /// Add 2 clusters to the track candidate
1030 /// Update track and local chi2
1032 // Update local chi2 at first cluster
1033 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
1034 Double_t deltaX = trackParamAtCluster1.GetNonBendingCoor() - cluster1->GetX();
1035 Double_t deltaY = trackParamAtCluster1.GetBendingCoor() - cluster1->GetY();
1036 Double_t localChi2AtCluster1 = deltaX*deltaX / cluster1->GetErrX2() +
1037 deltaY*deltaY / cluster1->GetErrY2();
1038 trackParamAtCluster1.SetLocalChi2(localChi2AtCluster1);
1040 // Flag first cluster as being removable
1041 trackParamAtCluster1.SetRemovable(kTRUE);
1043 // Update local chi2 at second cluster
1044 AliMUONVCluster* cluster2 = trackParamAtCluster2.GetClusterPtr();
1045 deltaX = trackParamAtCluster2.GetNonBendingCoor() - cluster2->GetX();
1046 deltaY = trackParamAtCluster2.GetBendingCoor() - cluster2->GetY();
1047 Double_t localChi2AtCluster2 = deltaX*deltaX / cluster2->GetErrX2() +
1048 deltaY*deltaY / cluster2->GetErrY2();
1049 trackParamAtCluster2.SetLocalChi2(localChi2AtCluster2);
1051 // Flag first cluster as being removable
1052 trackParamAtCluster2.SetRemovable(kTRUE);
1054 // Update the chi2 of the new track
1055 track.SetGlobalChi2(track.GetGlobalChi2() + localChi2AtCluster1 + localChi2AtCluster2);
1057 // Update TrackParamAtCluster
1058 track.AddTrackParamAtCluster(trackParamAtCluster1,*cluster1);
1059 track.AddTrackParamAtCluster(trackParamAtCluster2,*cluster2);
1063 //__________________________________________________________________________
1064 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, AliMUONVClusterStore& clusterStore, Int_t nextStation)
1066 /// Try to recover the track candidate in the next station
1067 /// by removing the worst of the two clusters attached in the current station
1068 /// Return kTRUE if recovering succeeds
1069 AliDebug(1,"Enter RecoverTrack");
1071 // Do not try to recover track until we have attached cluster(s) on station(1..) 3
1072 if (nextStation > 1) return kFALSE;
1074 Int_t worstClusterNumber = -1;
1075 Double_t localChi2, worstLocalChi2 = -1.;
1077 // Look for the cluster to remove
1078 for (Int_t clusterNumber = 0; clusterNumber < 2; clusterNumber++) {
1079 AliMUONTrackParam *trackParamAtCluster = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(clusterNumber);
1081 // check if current cluster is in the previous station
1082 if (trackParamAtCluster->GetClusterPtr()->GetChamberId()/2 != nextStation+1) break;
1084 // check if current cluster is removable
1085 if (!trackParamAtCluster->IsRemovable()) return kFALSE;
1087 // reset the current cluster as beig not removable if it is on a required station
1088 if (GetRecoParam()->RequestStation(nextStation+1)) trackParamAtCluster->SetRemovable(kFALSE);
1090 // Pick up cluster with the worst chi2
1091 localChi2 = trackParamAtCluster->GetLocalChi2();
1092 if (localChi2 > worstLocalChi2) {
1093 worstLocalChi2 = localChi2;
1094 worstClusterNumber = clusterNumber;
1099 // check if worst cluster found
1100 if (worstClusterNumber < 0) return kFALSE;
1102 // Remove the worst cluster
1103 trackCandidate.RemoveTrackParamAtCluster((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->UncheckedAt(worstClusterNumber));
1105 // Re-fit the track:
1106 // Do not take into account the multiple scattering to speed up the fit
1107 // Calculate the track parameter covariance matrix
1108 Fit(trackCandidate, kFALSE, kFALSE, kTRUE);
1110 // skip track with absolute bending momentum out of limits
1111 if (AliMUONTrackExtrap::IsFieldON()) {
1112 Double_t bendingMomentum = TMath::Abs(1. / ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First())->GetInverseBendingMomentum());
1113 if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
1114 bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) return kFALSE;
1117 // Look for new cluster(s) in next station
1118 return FollowTrackInStation(trackCandidate,clusterStore,nextStation);
1122 //__________________________________________________________________________
1123 void AliMUONTrackReconstructor::SetVertexErrXY2ForFit(AliMUONTrack &trackCandidate)
1125 /// Compute the vertex resolution square from natural vertex dispersion and
1126 /// multiple scattering effets according to trackCandidate path in absorber
1127 /// It is necessary to account for multiple scattering effects here instead of during the fit of
1128 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
1129 AliDebug(1,"Enter SetVertexForFit");
1131 Double_t nonBendingReso2 = GetRecoParam()->GetNonBendingVertexDispersion() *
1132 GetRecoParam()->GetNonBendingVertexDispersion();
1133 Double_t bendingReso2 = GetRecoParam()->GetBendingVertexDispersion() *
1134 GetRecoParam()->GetBendingVertexDispersion();
1136 // add multiple scattering effets
1137 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtCluster()->First())));
1138 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
1139 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
1140 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
1141 nonBendingReso2 += kParamCov(0,0);
1142 bendingReso2 += kParamCov(2,2);
1144 // Set the vertex resolution square
1145 trackCandidate.SetVertexErrXY2(nonBendingReso2,bendingReso2);
1148 //__________________________________________________________________________
1149 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t fitWithVertex, Bool_t calcCov)
1152 /// w/wo multiple Coulomb scattering according to "includeMCS".
1153 /// w/wo constraining the vertex according to "fitWithVertex".
1154 /// calculating or not the covariance matrix according to "calcCov".
1155 AliDebug(1,"Enter Fit");
1157 Double_t benC, errorParam, invBenP, nonBenC, x, y;
1158 AliMUONTrackParam *trackParam;
1159 Double_t arg[1], fedm, errdef, globalChi2;
1161 Int_t status, covStatus;
1163 // Instantiate gMinuit if not already done
1164 if (!gMinuit) gMinuit = new TMinuit(6);
1165 // Clear MINUIT parameters
1167 // Give the fitted track to MINUIT
1168 gMinuit->SetObjectFit(&track);
1169 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
1170 // Define print level
1172 gMinuit->mnexcm("SET PRI", arg, 1, status);
1173 // Print covariance matrix
1174 gMinuit->mnexcm("SHO COV", arg, 0, status);
1177 gMinuit->mnexcm("SET PRI", arg, 1, status);
1180 gMinuit->mnexcm("SET NOW", arg, 0, status);
1183 //gMinuit->mnexcm("SET STR", arg, 1, status);
1185 // set flag w/wo multiple scattering according to "includeMCS"
1186 track.FitWithMCS(includeMCS);
1188 // compute cluster weights only once
1189 if (!track.ComputeClusterWeights()) {
1190 AliWarning("cannot take into account the multiple scattering effects");
1191 track.FitWithMCS(kFALSE);
1195 track.FitWithVertex(fitWithVertex);
1196 if (fitWithVertex) SetVertexErrXY2ForFit(track);
1198 // Set fitting function
1199 gMinuit->SetFCN(TrackChi2);
1201 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
1202 // Mandatory limits to avoid NaN values of parameters
1203 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtCluster()->First());
1204 Double_t maxIBM = 1. / GetRecoParam()->GetMinBendingMomentum();
1205 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
1206 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -1., 1., status);
1207 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
1208 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -1.5, 1.5, status);
1209 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -maxIBM, maxIBM, status);
1212 gMinuit->mnexcm("MIGRAD", arg, 0, status);
1214 // Calculate the covariance matrix more accurately if required
1215 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
1217 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
1218 gMinuit->GetParameter(0, x, errorParam);
1219 trackParam->SetNonBendingCoor(x);
1220 gMinuit->GetParameter(1, nonBenC, errorParam);
1221 trackParam->SetNonBendingSlope(nonBenC);
1222 gMinuit->GetParameter(2, y, errorParam);
1223 trackParam->SetBendingCoor(y);
1224 gMinuit->GetParameter(3, benC, errorParam);
1225 trackParam->SetBendingSlope(benC);
1226 gMinuit->GetParameter(4, invBenP, errorParam);
1227 trackParam->SetInverseBendingMomentum(invBenP);
1229 // global result of the fit
1230 gMinuit->mnstat(globalChi2, fedm, errdef, npari, nparx, covStatus);
1231 track.SetGlobalChi2(globalChi2);
1233 // Get the covariance matrix if required
1235 // Covariance matrix according to HESSE status
1236 // If problem then keep only the diagonal terms (variances)
1237 Double_t matrix[5][5];
1238 gMinuit->mnemat(&matrix[0][0],5);
1239 if (covStatus == 3) trackParam->SetCovariances(matrix);
1240 else trackParam->SetVariances(matrix);
1241 } else trackParam->DeleteCovariances();
1245 //__________________________________________________________________________
1246 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
1248 /// Return the "Chi2" to be minimized with Minuit for track fitting.
1249 /// Assumes that the trackParamAtCluster are sorted according to increasing Z.
1250 /// Track parameters at each cluster are updated accordingly.
1251 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
1252 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
1254 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
1255 AliMUONTrackParam* trackParamAtCluster = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtCluster()->First();
1257 chi2 = 0.; // initialize chi2
1259 // update track parameters
1260 trackParamAtCluster->SetNonBendingCoor(param[0]);
1261 trackParamAtCluster->SetNonBendingSlope(param[1]);
1262 trackParamAtCluster->SetBendingCoor(param[2]);
1263 trackParamAtCluster->SetBendingSlope(param[3]);
1264 trackParamAtCluster->SetInverseBendingMomentum(param[4]);
1265 trackBeingFitted->UpdateTrackParamAtCluster();
1267 // Take the vertex into account in the fit if required
1268 if (trackBeingFitted->FitWithVertex()) {
1269 Double_t nonBendingReso2,bendingReso2;
1270 trackBeingFitted->GetVertexErrXY2(nonBendingReso2,bendingReso2);
1271 if (nonBendingReso2 == 0. || bendingReso2 == 0.) chi2 += 1.e10;
1273 AliMUONTrackParam paramAtVertex(*trackParamAtCluster);
1274 AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.); // vextex position = (0,0,0)
1275 dX = paramAtVertex.GetNonBendingCoor();
1276 dY = paramAtVertex.GetBendingCoor();
1277 chi2 += dX * dX / nonBendingReso2 + dY * dY / bendingReso2;
1281 // compute chi2 w/wo multiple scattering
1282 chi2 += trackBeingFitted->ComputeGlobalChi2(trackBeingFitted->FitWithMCS());
1286 //__________________________________________________________________________
1287 Bool_t AliMUONTrackReconstructor::ComplementTracks(const AliMUONVClusterStore& clusterStore)
1289 /// Complete tracks by adding missing clusters (if there is an overlap between
1290 /// two detection elements, the track may have two clusters in the same chamber).
1291 /// Re-fit track parameters and covariances.
1292 /// Return kTRUE if one or more tracks have been complemented.
1293 AliDebug(1,"Enter ComplementTracks");
1295 Int_t chamberId, detElemId;
1296 Double_t chi2OfCluster, bestChi2OfCluster;
1297 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForTracking() *
1298 GetRecoParam()->GetSigmaCutForTracking();
1299 Bool_t foundOneCluster, trackModified, hasChanged = kFALSE;
1300 AliMUONVCluster* cluster;
1301 AliMUONTrackParam *trackParam, *nextTrackParam, copyOfTrackParam, trackParamAtCluster, bestTrackParamAtCluster;
1303 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
1305 trackModified = kFALSE;
1307 trackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->First();
1308 while (trackParam) {
1309 foundOneCluster = kFALSE;
1310 bestChi2OfCluster = 2. * sigmaCut2; // 2 because 2 quantities in chi2
1311 chamberId = trackParam->GetClusterPtr()->GetChamberId();
1312 detElemId = trackParam->GetClusterPtr()->GetDetElemId();
1314 // prepare nextTrackParam before adding new cluster because of the sorting
1315 nextTrackParam = (AliMUONTrackParam*)track->GetTrackParamAtCluster()->After(trackParam);
1317 // recover track parameters from local fit and put them into a copy of trackParam
1318 copyOfTrackParam.SetZ(trackParam->GetZ());
1319 copyOfTrackParam.SetParameters(trackParam->GetSmoothParameters());
1320 copyOfTrackParam.SetCovariances(trackParam->GetSmoothCovariances());
1322 // Create iterators to loop over clusters in current chamber
1323 TIter nextInCh(clusterStore.CreateChamberIterator(chamberId,chamberId));
1325 // look for one second candidate in the same chamber
1326 while ( ( cluster = static_cast<AliMUONVCluster*>(nextInCh()) ) ) {
1328 // look for a cluster in another detection element
1329 if (cluster->GetDetElemId() == detElemId) continue;
1331 // try to add the current cluster fast
1332 if (!TryOneClusterFast(copyOfTrackParam, cluster)) continue;
1334 // try to add the current cluster accurately
1335 chi2OfCluster = TryOneCluster(copyOfTrackParam, cluster, trackParamAtCluster);
1337 // if better chi2 then prepare to add this cluster to the track
1338 if (chi2OfCluster < bestChi2OfCluster) {
1339 bestChi2OfCluster = chi2OfCluster;
1340 bestTrackParamAtCluster = trackParamAtCluster;
1341 foundOneCluster = kTRUE;
1346 // add new cluster if any
1347 if (foundOneCluster) {
1349 // Printout for debuging
1350 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1351 cout << "ComplementTracks: found one cluster in chamber(1..): " << chamberId+1 << endl;
1352 bestTrackParamAtCluster.GetClusterPtr()->Print();
1353 cout<<endl<<"Track parameters and covariances at cluster:"<<endl;
1354 bestTrackParamAtCluster.GetParameters().Print();
1355 bestTrackParamAtCluster.GetCovariances().Print();
1358 trackParam->SetRemovable(kTRUE);
1359 bestTrackParamAtCluster.SetRemovable(kTRUE);
1360 track->AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
1361 trackModified = kTRUE;
1365 trackParam = nextTrackParam;
1368 // re-fit track parameters if needed
1369 if (trackModified) Fit(*track, kTRUE, kFALSE, kTRUE);
1371 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1378 //__________________________________________________________________________
1379 void AliMUONTrackReconstructor::ImproveTrack(AliMUONTrack &track)
1381 /// Improve the given track by removing clusters with local chi2 highter than the defined cut
1382 /// Recompute track parameters and covariances at the remaining clusters
1383 AliDebug(1,"Enter ImproveTrack");
1385 Double_t localChi2, worstLocalChi2;
1386 AliMUONTrackParam *trackParamAtCluster, *worstTrackParamAtCluster;
1387 Double_t sigmaCut2 = GetRecoParam()->GetSigmaCutForImprovement() *
1388 GetRecoParam()->GetSigmaCutForImprovement();
1390 while (!track.IsImproved()) {
1392 // identify removable clusters
1393 track.TagRemovableClusters(GetRecoParam()->RequestedStationMask());
1395 // Update track parameters and covariances
1396 track.UpdateCovTrackParamAtCluster();
1398 // Compute local chi2 of each clusters
1399 track.ComputeLocalChi2(kTRUE);
1401 // Look for the cluster to remove
1402 worstTrackParamAtCluster = NULL;
1403 worstLocalChi2 = 0.;
1404 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1405 while (trackParamAtCluster) {
1407 // Pick up cluster with the worst chi2
1408 localChi2 = trackParamAtCluster->GetLocalChi2();
1409 if (localChi2 > worstLocalChi2) {
1410 worstLocalChi2 = localChi2;
1411 worstTrackParamAtCluster = trackParamAtCluster;
1414 trackParamAtCluster = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->After(trackParamAtCluster);
1417 // Check if worst cluster found
1418 if (!worstTrackParamAtCluster) {
1419 AliWarning("Bad local chi2 values?");
1423 // Check whether the worst chi2 is under requirement or not
1424 if (worstLocalChi2 < 2. * sigmaCut2) { // 2 because 2 quantities in chi2
1425 track.SetImproved(kTRUE);
1429 // if the worst cluster is not removable then stop improvement
1430 if (!worstTrackParamAtCluster->IsRemovable()) break;
1432 // Remove the worst cluster
1433 track.RemoveTrackParamAtCluster(worstTrackParamAtCluster);
1435 // Re-fit the track:
1436 // Take into account the multiple scattering
1437 // Calculate the track parameter covariance matrix
1438 Fit(track, kTRUE, kFALSE, kTRUE);
1440 // Printout for debuging
1441 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
1442 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(&track)+1 << " improved " << endl;
1449 //__________________________________________________________________________
1450 void AliMUONTrackReconstructor::FinalizeTrack(AliMUONTrack &track)
1452 /// Recompute track parameters and covariances at each attached cluster
1453 /// from those at the first one, if not already done
1454 AliDebug(1,"Enter FinalizeTrack");
1455 if (!track.IsImproved()) track.UpdateCovTrackParamAtCluster();
1458 //__________________________________________________________________________
1459 Bool_t AliMUONTrackReconstructor::RefitTrack(AliMUONTrack &track, Bool_t enableImprovement)
1461 /// re-fit the given track
1463 // check validity of the track
1464 if (track.GetNClusters() < 3) {
1465 AliWarning("the track does not contain enough clusters --> unable to refit");
1469 // reset the seed (i.e. parameters at first cluster) before fitting
1470 AliMUONTrackParam* firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
1471 if (firstTrackParam->GetInverseBendingMomentum() == 0.) {
1472 AliWarning("track parameters at first chamber are not initialized --> unable to refit");
1476 // compute track parameters at each cluster from parameters at the first one
1477 // necessary to compute multiple scattering effect during refitting
1478 track.UpdateTrackParamAtCluster();
1480 // Re-fit the track:
1481 // Take into account the multiple scattering
1482 // Calculate the track parameter covariance matrix
1483 Fit(track, kTRUE, kFALSE, kTRUE);
1485 // Improve the reconstructed tracks if required
1486 track.SetImproved(kFALSE);
1487 if (enableImprovement && GetRecoParam()->ImproveTracks()) ImproveTrack(track);
1489 // Fill AliMUONTrack data members
1490 FinalizeTrack(track);