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 "AliMUONHitForRec.h"
33 #include "AliMUONTrack.h"
34 #include "AliMUONTrackParam.h"
35 #include "AliMUONTrackExtrap.h"
39 #include <Riostream.h>
43 // Functions to be minimized with Minuit
44 void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag);
47 ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
50 //************* Parameters for reconstruction
51 const Double_t AliMUONTrackReconstructor::fgkBendingVertexDispersion = 10.;
52 const Double_t AliMUONTrackReconstructor::fgkNonBendingVertexDispersion = 10.;
55 //__________________________________________________________________________
56 AliMUONTrackReconstructor::AliMUONTrackReconstructor()
57 : AliMUONVTrackReconstructor()
59 /// Constructor for class AliMUONTrackReconstructor
60 AliInfo("*** Original tracking ***");
63 //__________________________________________________________________________
64 AliMUONTrackReconstructor::~AliMUONTrackReconstructor()
69 //__________________________________________________________________________
70 void AliMUONTrackReconstructor::MakeTrackCandidates()
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 hitForRec's.
75 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
76 TClonesArray *segments;
81 AliDebug(1,"Enter MakeTrackCandidates");
83 // Loop over stations(1..) 5 and 4 and make track candidates
84 for (Int_t istat=4; istat>=3; istat--) {
86 // Make segments in the station
87 segments = MakeSegmentsInStation(istat);
90 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++)
92 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
94 // Transform segments to tracks and put them at the end of fRecTracksPtr
95 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg]));
98 // Printout for debuging
99 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2))
101 cout<<endl<<"Track parameter covariances at first hit with multiple Coulomb scattering effects:"<<endl;
102 ((AliMUONTrackParam*) track->GetTrackParamAtHit()->First())->GetCovariances().Print();
105 // Look for compatible hitForRec(s) in the other station
106 if (fgkMakeTrackCandidatesFast) hitFound = FollowLinearTrackInStation(*track,7-istat);
107 else hitFound = FollowTrackInStation(*track,7-istat);
109 // Remove track if no hit found
111 fRecTracksPtr->Remove(track);
117 // delete the array of segments
121 fRecTracksPtr->Compress(); // this is essential before checking tracks
123 // Keep all different tracks or only the best ones as required
124 if (fgkTrackAllTracks) RemoveIdenticalTracks();
125 else RemoveDoubleTracks();
127 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
131 //__________________________________________________________________________
132 void AliMUONTrackReconstructor::FollowTracks()
134 /// Follow tracks in stations(1..) 3, 2 and 1
135 AliDebug(1,"Enter FollowTracks");
137 AliMUONTrack *track, *nextTrack;
138 Int_t currentNRecTracks;
141 for (Int_t station = 2; station >= 0; station--) {
143 // Save the actual number of reconstructed track in case of
144 // tracks are added or suppressed during the tracking procedure
145 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
146 currentNRecTracks = fNRecTracks;
148 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
149 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
151 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
154 // Do not take into account the multiple scattering to speed up the fit
155 // Calculate the track parameter covariance matrix
156 // If "station" is station(1..) 3 then use the vertex to better constrain the fit
158 SetVertexForFit(*track);
159 track->SetFitWithVertex(kTRUE);
160 } else track->SetFitWithVertex(kFALSE);
161 Fit(*track, kFALSE, kTRUE);
163 // Remove the track if the normalized chi2 is too high
164 if (track->GetNormalizedChi2() > fgkSigmaToCutForTracking * fgkSigmaToCutForTracking) {
165 fRecTracksPtr->Remove(track);
170 // Printout for debuging
171 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
172 cout<<endl<<"Track parameter covariances at first hit with multiple Coulomb scattering effects:"<<endl;
173 ((AliMUONTrackParam*) track->GetTrackParamAtHit()->First())->GetCovariances().Print();
176 // Look for compatible hitForRec in station(0..) "station"
177 hitFound = FollowTrackInStation(*track,station);
179 // Try to recover track if required
180 if (!hitFound && fgkRecoverTracks) hitFound = RecoverTrack(*track,station);
182 // remove track if no hit found
184 fRecTracksPtr->Remove(track);
190 // Compress fRecTracksPtr for the next step
191 fRecTracksPtr->Compress();
193 // Keep only the best tracks if required
194 if (!fgkTrackAllTracks) RemoveDoubleTracks();
198 // Last fit of track candidates with all station
199 // Take into account the multiple scattering and remove bad tracks
200 Int_t trackIndex = -1;
201 track = (AliMUONTrack*) fRecTracksPtr->First();
205 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
207 track->SetFitWithVertex(kFALSE); // just to be sure
208 Fit(*track, kTRUE, kTRUE);
210 // Printout for debuging
211 if (AliLog::GetGlobalDebugLevel() >= 3) {
212 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
213 track->RecursiveDump();
216 // Remove the track if the normalized chi2 is too high
217 if (track->GetNormalizedChi2() > fgkSigmaToCutForTracking * fgkSigmaToCutForTracking) {
218 fRecTracksPtr->Remove(track);
226 fRecTracksPtr->Compress();
230 //__________________________________________________________________________
231 Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation)
233 /// Follow trackCandidate in station(0..) nextStation and search for compatible HitForRec(s)
234 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
235 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
236 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
237 /// Remove the obsolete "trackCandidate" at the end.
238 /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
239 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
241 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
242 // - nextStation == station(1...) 5 => forward propagation
243 // - nextStation < station(1...) 5 => backward propagation
245 if (nextStation==4) {
246 ch1 = 2*nextStation+1;
250 ch2 = 2*nextStation+1;
253 Double_t chi2WithOneHitForRec = 1.e10;
254 Double_t chi2WithTwoHitForRec = 1.e10;
255 Double_t maxChi2WithOneHitForRec = 2. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 2 because 2 quantities in chi2
256 Double_t maxChi2WithTwoHitForRec = 4. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 4 because 4 quantities in chi2
257 Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
258 Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
259 Bool_t foundOneHit = kFALSE;
260 Bool_t foundTwoHits = kFALSE;
261 AliMUONTrack *newTrack = 0x0;
262 AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
263 AliMUONTrackParam extrapTrackParam;
264 AliMUONTrackParam extrapTrackParamAtHit1;
265 AliMUONTrackParam extrapTrackParamAtHit2;
266 AliMUONTrackParam bestTrackParamAtHit1;
267 AliMUONTrackParam bestTrackParamAtHit2;
268 Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
269 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
271 // Get track parameters
272 AliMUONTrackParam extrapTrackParamAtCh(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First());
275 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
277 // Add MCS in the missing chamber if any (only 1 chamber can be missing according to tracking criteria)
278 if (ch1 < ch2 && extrapTrackParamAtCh.GetHitForRecPtr()->GetChamberNumber() > ch2 + 1) {
279 // extrapolation to the missing chamber
280 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2 + 1));
282 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
285 //Extrapolate trackCandidate to chamber "ch2"
286 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2));
288 // Printout for debuging
289 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
290 cout<<endl<<"Track parameter covariances at first hit extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
291 extrapTrackParamAtCh.GetCovariances().Print();
294 // Printout for debuging
295 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
296 cout << "FollowTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
299 // look for candidates in chamber 2
300 for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
302 hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
304 // try to add the current hit fast
305 if (!TryOneHitForRecFast(extrapTrackParamAtCh, hitForRecCh2)) continue;
307 // try to add the current hit accuratly
308 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtCh, hitForRecCh2, extrapTrackParamAtHit2);
310 // if good chi2 then try to attach a hitForRec in the other chamber too
311 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
312 Bool_t foundSecondHit = kFALSE;
314 // Printout for debuging
315 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
316 cout << "FollowTrackInStation: found one hit in chamber(1..): " << ch2+1
317 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
318 cout << " look for second hits in chamber(1..): " << ch1+1 << " ..." << endl;
321 // add MCS effect for next step
322 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.);
324 // copy new track parameters for next step
325 extrapTrackParam = extrapTrackParamAtHit2;
327 //Extrapolate track parameters to chamber "ch1"
328 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
330 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
332 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
334 // try to add the current hit fast
335 if (!TryOneHitForRecFast(extrapTrackParam, hitForRecCh1)) continue;
337 // try to add the current hit accuratly
338 chi2WithTwoHitForRec = TryTwoHitForRec(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1);
340 // if good chi2 then create a new track by adding the 2 hitForRec to the "trackCandidate"
341 if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
342 foundSecondHit = kTRUE;
343 foundTwoHits = kTRUE;
345 // Printout for debuging
346 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
347 cout << "FollowTrackInStation: found second hit in chamber(1..): " << ch1+1
348 << " (Global Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
351 if (fgkTrackAllTracks) {
352 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
353 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
354 UpdateTrack(*newTrack,extrapTrackParamAtHit1,extrapTrackParamAtHit2);
357 // Tag hitForRecCh1 as used
358 hitForRecCh1Used[hit1] = kTRUE;
360 // Printout for debuging
361 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
362 cout << "FollowTrackInStation: added two hits in station(1..): " << nextStation+1 << endl;
363 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
366 } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
367 // keep track of the best couple of hits
368 bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
369 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
370 bestTrackParamAtHit2 = extrapTrackParamAtHit2;
377 // if no hitForRecCh1 found then consider to add hitForRecCh2 only
378 if (!foundSecondHit) {
381 if (fgkTrackAllTracks) {
382 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
383 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
384 UpdateTrack(*newTrack,extrapTrackParamAtHit2);
387 // Printout for debuging
388 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
389 cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl;
390 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
393 } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
394 // keep track of the best single hitForRec except if a couple of hits has already been found
395 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
396 bestTrackParamAtHit1 = extrapTrackParamAtHit2;
405 // look for candidates in chamber 1 not already attached to a track
406 // if we want to keep all possible tracks or if no good couple of hitForRec has been found
407 if (fgkTrackAllTracks || !foundTwoHits) {
409 // Printout for debuging
410 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
411 cout << "FollowTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
414 // add MCS effect for next step
415 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.);
417 //Extrapolate trackCandidate to chamber "ch1"
418 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1));
420 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
422 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
424 if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
426 // try to add the current hit fast
427 if (!TryOneHitForRecFast(extrapTrackParamAtCh, hitForRecCh1)) continue;
429 // try to add the current hit accuratly
430 chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtCh, hitForRecCh1, extrapTrackParamAtHit1);
432 // if good chi2 then consider to add hitForRecCh1
433 // We do not try to attach a hitForRec in the other chamber too since it has already been done above
434 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
437 // Printout for debuging
438 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
439 cout << "FollowTrackInStation: found one hit in chamber(1..): " << ch1+1
440 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
443 if (fgkTrackAllTracks) {
444 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
445 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
446 UpdateTrack(*newTrack,extrapTrackParamAtHit1);
449 // Printout for debuging
450 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
451 cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl;
452 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
455 } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
456 // keep track of the best single hitForRec except if a couple of hits has already been found
457 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
458 bestTrackParamAtHit1 = extrapTrackParamAtHit1;
467 // fill out the best track if required else clean up the fRecTracksPtr array
468 if (!fgkTrackAllTracks) {
470 UpdateTrack(trackCandidate,bestTrackParamAtHit1,bestTrackParamAtHit2);
472 // Printout for debuging
473 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
474 cout << "FollowTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl;
475 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
478 } else if (foundOneHit) {
479 UpdateTrack(trackCandidate,bestTrackParamAtHit1);
481 // Printout for debuging
482 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
483 cout << "FollowTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl;
484 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
488 delete [] hitForRecCh1Used;
492 } else if (foundOneHit || foundTwoHits) {
494 // remove obsolete track
495 fRecTracksPtr->Remove(&trackCandidate);
499 delete [] hitForRecCh1Used;
503 delete [] hitForRecCh1Used;
508 //__________________________________________________________________________
509 Double_t AliMUONTrackReconstructor::TryTwoHitForRec(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2,
510 AliMUONTrackParam &trackParamAtHit2)
512 /// Test the compatibility between the track and the 2 hitForRec together (using trackParam's covariance matrix):
513 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
514 /// return trackParamAtHit1 & 2
516 // extrapolate track parameters at the z position of the second hit
517 trackParamAtHit2.SetParameters(trackParamAtHit1.GetParameters());
518 trackParamAtHit2.SetZ(trackParamAtHit1.GetZ());
519 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtHit2, hitForRec2->GetZ());
521 // set pointer to hit2 into trackParamAtHit2
522 trackParamAtHit2.SetHitForRecPtr(hitForRec2);
524 // Set differences between track and the 2 hitForRec in the bending and non bending directions
525 AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr();
527 dPos(0,0) = hitForRec1->GetNonBendingCoor() - trackParamAtHit1.GetNonBendingCoor();
528 dPos(1,0) = hitForRec1->GetBendingCoor() - trackParamAtHit1.GetBendingCoor();
529 dPos(2,0) = hitForRec2->GetNonBendingCoor() - trackParamAtHit2.GetNonBendingCoor();
530 dPos(3,0) = hitForRec2->GetBendingCoor() - trackParamAtHit2.GetBendingCoor();
532 // Calculate the error matrix from the track parameter covariances at first hitForRec
535 if (trackParamAtHit1.CovariancesExist()) {
536 // Save track parameters at first hitForRec
537 AliMUONTrackParam trackParamAtHit1Save(trackParamAtHit1);
538 TMatrixD paramAtHit1Save(trackParamAtHit1Save.GetParameters());
539 Double_t z1 = trackParamAtHit1Save.GetZ();
541 // Save track coordinates at second hitForRec
542 Double_t nonBendingCoor2 = trackParamAtHit2.GetNonBendingCoor();
543 Double_t bendingCoor2 = trackParamAtHit2.GetBendingCoor();
545 // add MCS effect at first hitForRec
546 AliMUONTrackExtrap::AddMCSEffect(&trackParamAtHit1Save,AliMUONConstants::ChamberThicknessInX0(),1.);
548 // Get the pointer to the parameter covariance matrix at first hitForRec
549 const TMatrixD& kParamCov = trackParamAtHit1Save.GetCovariances();
551 // Calculate the jacobian related to the transformation between track parameters
552 // at first hitForRec and track coordinates at the 2 hitForRec z-position
555 // first derivative at the first hitForRec:
556 jacob(0,0) = 1.; // dx1/dx
557 jacob(1,2) = 1.; // dy1/dy
558 // first derivative at the second hitForRec:
559 TMatrixD dParam(5,1);
560 for (Int_t i=0; i<5; i++) {
561 // Skip jacobian calculation for parameters with no associated error
562 if (kParamCov(i,i) == 0.) continue;
563 // Small variation of parameter i only
564 for (Int_t j=0; j<5; j++) {
566 dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
567 if (j == 4) dParam(j,0) *= TMath::Sign(1.,-paramAtHit1Save(4,0)); // variation always in the same direction
568 } else dParam(j,0) = 0.;
571 // Set new track parameters at first hitForRec
572 trackParamAtHit1Save.SetParameters(paramAtHit1Save);
573 trackParamAtHit1Save.AddParameters(dParam);
574 trackParamAtHit1Save.SetZ(z1);
576 // Extrapolate new track parameters to the z position of the second hitForRec
577 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtHit1Save,hitForRec2->GetZ());
579 // Calculate the jacobian
580 jacob(2,i) = (trackParamAtHit1Save.GetNonBendingCoor() - nonBendingCoor2) / dParam(i,0); // dx2/dParami
581 jacob(3,i) = (trackParamAtHit1Save.GetBendingCoor() - bendingCoor2 ) / dParam(i,0); // dy2/dParami
584 // Calculate the error matrix
585 TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov);
586 error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob);
589 // Add hitForRec resolution to the error matrix
590 error(0,0) += hitForRec1->GetNonBendingReso2();
591 error(1,1) += hitForRec1->GetBendingReso2();
592 error(2,2) += hitForRec2->GetNonBendingReso2();
593 error(3,3) += hitForRec2->GetBendingReso2();
595 // invert the error matrix for Chi2 calculation
596 if (error.Determinant() != 0) {
599 AliWarning(" Determinant error=0");
603 // Compute the Chi2 value
604 TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error);
605 TMatrixD result(tmp2,TMatrixD::kMult,dPos);
611 //__________________________________________________________________________
612 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtHit)
614 /// Add 1 hit to the track candidate
615 /// Update chi2 of the track
617 // Compute local chi2
618 AliMUONHitForRec* hit = trackParamAtHit.GetHitForRecPtr();
619 Double_t deltaX = trackParamAtHit.GetNonBendingCoor() - hit->GetNonBendingCoor();
620 Double_t deltaY = trackParamAtHit.GetBendingCoor() - hit->GetBendingCoor();
621 Double_t localChi2 = deltaX*deltaX / hit->GetNonBendingReso2() +
622 deltaY*deltaY / hit->GetBendingReso2();
624 // Flag hit as being not removable
625 trackParamAtHit.SetRemovable(kFALSE);
626 trackParamAtHit.SetLocalChi2(0.); // --> Local chi2 not used
628 // Update the chi2 of the new track
629 track.SetFitFMin(track.GetFitFMin() + localChi2);
631 // Update TrackParamAtHit
632 track.AddTrackParamAtHit(&trackParamAtHit,trackParamAtHit.GetHitForRecPtr());
633 track.GetTrackParamAtHit()->Sort();
637 //__________________________________________________________________________
638 void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtHit1, AliMUONTrackParam &trackParamAtHit2)
640 /// Add 2 hits to the track candidate
641 /// Update track and local chi2
643 // Update local chi2 at first hit
644 AliMUONHitForRec* hit1 = trackParamAtHit1.GetHitForRecPtr();
645 Double_t deltaX = trackParamAtHit1.GetNonBendingCoor() - hit1->GetNonBendingCoor();
646 Double_t deltaY = trackParamAtHit1.GetBendingCoor() - hit1->GetBendingCoor();
647 Double_t localChi2AtHit1 = deltaX*deltaX / hit1->GetNonBendingReso2() +
648 deltaY*deltaY / hit1->GetBendingReso2();
649 trackParamAtHit1.SetLocalChi2(localChi2AtHit1);
651 // Flag first hit as being removable
652 trackParamAtHit1.SetRemovable(kTRUE);
654 // Update local chi2 at second hit
655 AliMUONHitForRec* hit2 = trackParamAtHit2.GetHitForRecPtr();
656 deltaX = trackParamAtHit2.GetNonBendingCoor() - hit2->GetNonBendingCoor();
657 deltaY = trackParamAtHit2.GetBendingCoor() - hit2->GetBendingCoor();
658 Double_t localChi2AtHit2 = deltaX*deltaX / hit2->GetNonBendingReso2() +
659 deltaY*deltaY / hit2->GetBendingReso2();
660 trackParamAtHit2.SetLocalChi2(localChi2AtHit2);
662 // Flag first hit as being removable
663 trackParamAtHit2.SetRemovable(kTRUE);
665 // Update the chi2 of the new track
666 track.SetFitFMin(track.GetFitFMin() + localChi2AtHit1 + localChi2AtHit2);
668 // Update TrackParamAtHit
669 track.AddTrackParamAtHit(&trackParamAtHit1,trackParamAtHit1.GetHitForRecPtr());
670 track.AddTrackParamAtHit(&trackParamAtHit2,trackParamAtHit2.GetHitForRecPtr());
671 track.GetTrackParamAtHit()->Sort();
675 //__________________________________________________________________________
676 Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, Int_t nextStation)
678 /// Try to recover the track candidate in the next station
679 /// by removing the worst of the two hits attached in the current station
680 /// Return kTRUE if recovering succeeds
681 AliDebug(1,"Enter RecoverTrack");
683 // Do not try to recover track until we have attached hit(s) on station(1..) 3
684 if (nextStation > 1) return kFALSE;
686 Int_t worstHitNumber = -1;
687 Double_t localChi2, worstLocalChi2 = 0.;
689 // Look for the hit to remove
690 for (Int_t hitNumber = 0; hitNumber < 2; hitNumber++) {
691 AliMUONTrackParam *trackParamAtHit = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt(hitNumber);
693 // check if current hit is removable
694 if (!trackParamAtHit->IsRemovable()) return kFALSE;
696 // Pick up hit with the worst chi2
697 localChi2 = trackParamAtHit->GetLocalChi2();
698 if (localChi2 > worstLocalChi2) {
699 worstLocalChi2 = localChi2;
700 worstHitNumber = hitNumber;
704 // Reset best hit as being NOT removable
705 ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt((worstHitNumber+1)%2))->SetRemovable(kFALSE);
707 // Remove the worst hit
708 trackCandidate.RemoveTrackParamAtHit((AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt(worstHitNumber));
711 // Do not take into account the multiple scattering to speed up the fit
712 // Calculate the track parameter covariance matrix
713 trackCandidate.SetFitWithVertex(kFALSE); // To be sure
714 Fit(trackCandidate, kFALSE, kTRUE);
716 // Look for new hit(s) in next station
717 return FollowTrackInStation(trackCandidate,nextStation);
721 //__________________________________________________________________________
722 void AliMUONTrackReconstructor::SetVertexForFit(AliMUONTrack &trackCandidate)
724 /// Add the vertex as a measured hit to constrain the fit of the "trackCandidate"
725 /// Compute the vertex resolution from natural vertex dispersion and
726 /// multiple scattering effets according to trackCandidate path in absorber
727 /// It is necessary to account for multiple scattering effects here instead of during the fit of
728 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
729 AliDebug(1,"Enter SetVertexForFit");
731 Double_t nonBendingReso2 = fgkNonBendingVertexDispersion * fgkNonBendingVertexDispersion;
732 Double_t bendingReso2 = fgkBendingVertexDispersion * fgkBendingVertexDispersion;
733 // add multiple scattering effets
734 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtHit()->First())));
735 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
736 AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.);
737 const TMatrixD& kParamCov = paramAtVertex.GetCovariances();
738 nonBendingReso2 += kParamCov(0,0);
739 bendingReso2 += kParamCov(2,2);
741 AliMUONHitForRec vertex; // Coordinates set to (0.,0.,0.) by default
742 vertex.SetNonBendingReso2(nonBendingReso2);
743 vertex.SetBendingReso2(bendingReso2);
744 trackCandidate.SetVertex(&vertex);
747 //__________________________________________________________________________
748 void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t calcCov)
750 /// Fit the track "track" w/wo multiple Coulomb scattering according to "includeMCS".
752 Double_t benC, errorParam, invBenP, nonBenC, x, y;
753 AliMUONTrackParam *trackParam;
754 Double_t arg[1], fedm, errdef, fitFMin;
756 Int_t status, covStatus;
758 // Instantiate gMinuit if not already done
759 if (!gMinuit) gMinuit = new TMinuit(6);
760 // Clear MINUIT parameters
762 // Give the fitted track to MINUIT
763 gMinuit->SetObjectFit(&track);
764 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
765 // Define print level
767 gMinuit->mnexcm("SET PRI", arg, 1, status);
768 // Print covariance matrix
769 gMinuit->mnexcm("SHO COV", arg, 0, status);
772 gMinuit->mnexcm("SET PRI", arg, 1, status);
775 gMinuit->mnexcm("SET NOW", arg, 0, status);
778 //gMinuit->mnexcm("SET STR", arg, 1, status);
780 // set flag w/wo multiple scattering according to "includeMCS"
781 track.SetFitWithMCS(includeMCS);
783 // compute hit weights only once
784 if (!track.ComputeHitWeights()) {
785 AliWarning("cannot take into account the multiple scattering effects");
786 track.SetFitWithMCS(kFALSE);
790 // Set fitting function
791 gMinuit->SetFCN(TrackChi2);
793 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
794 trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtHit()->First());
795 // could be tried with no limits for the search (min=max=0) ????
796 // mandatory limits in non Bending to avoid NaN values of parameters
797 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
798 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -0.5, 0.5, status);
799 // mandatory limits in Bending to avoid NaN values of parameters
800 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
801 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -0.5, 0.5, status);
802 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -0.4, 0.4, status);
805 gMinuit->mnexcm("MIGRAD", arg, 0, status);
807 // Calculate the covariance matrix more accurately if required
808 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
810 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
811 gMinuit->GetParameter(0, x, errorParam);
812 trackParam->SetNonBendingCoor(x);
813 gMinuit->GetParameter(1, nonBenC, errorParam);
814 trackParam->SetNonBendingSlope(nonBenC);
815 gMinuit->GetParameter(2, y, errorParam);
816 trackParam->SetBendingCoor(y);
817 gMinuit->GetParameter(3, benC, errorParam);
818 trackParam->SetBendingSlope(benC);
819 gMinuit->GetParameter(4, invBenP, errorParam);
820 trackParam->SetInverseBendingMomentum(invBenP);
822 // global result of the fit
823 gMinuit->mnstat(fitFMin, fedm, errdef, npari, nparx, covStatus);
824 track.SetFitFMin(fitFMin);
826 // Get the covariance matrix if required
828 // Covariance matrix according to HESSE status
829 // If problem then keep only the diagonal terms (variances)
830 Double_t matrix[5][5];
831 gMinuit->mnemat(&matrix[0][0],5);
832 if (covStatus == 3) trackParam->SetCovariances(matrix);
833 else trackParam->SetVariances(matrix);
834 } else trackParam->DeleteCovariances();
838 //__________________________________________________________________________
839 void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/)
841 /// Return the "Chi2" to be minimized with Minuit for track fitting.
842 /// Assumes that the track hits are sorted according to increasing Z.
843 /// Track parameters at each TrackHit are updated accordingly.
844 /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()".
845 /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()".
847 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
848 AliMUONTrackParam* trackParamAtHit = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtHit()->First();
850 chi2 = 0.; // initialize chi2
852 // update track parameters
853 trackParamAtHit->SetNonBendingCoor(param[0]);
854 trackParamAtHit->SetNonBendingSlope(param[1]);
855 trackParamAtHit->SetBendingCoor(param[2]);
856 trackParamAtHit->SetBendingSlope(param[3]);
857 trackParamAtHit->SetInverseBendingMomentum(param[4]);
858 trackBeingFitted->UpdateTrackParamAtHit();
860 // Take the vertex into account in the fit if required
861 if (trackBeingFitted->GetFitWithVertex()) {
862 AliMUONTrackParam paramAtVertex(*trackParamAtHit);
863 AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.);
864 AliMUONHitForRec *vertex = trackBeingFitted->GetVertex();
866 cout<<"Error in TrackChi2: Want to use the vertex in tracking but it has not been created!!"<<endl;
869 dX = vertex->GetNonBendingCoor() - paramAtVertex.GetNonBendingCoor();
870 dY = vertex->GetBendingCoor() - paramAtVertex.GetBendingCoor();
871 chi2 += dX * dX / vertex->GetNonBendingReso2() + dY * dY / vertex->GetBendingReso2();
874 // compute chi2 w/wo multiple scattering
875 if (trackBeingFitted->GetFitWithMCS()) chi2 += trackBeingFitted->ComputeGlobalChi2(kTRUE);
876 else chi2 += trackBeingFitted->ComputeGlobalChi2(kFALSE);
880 //__________________________________________________________________________
881 void AliMUONTrackReconstructor::ImproveTracks()
883 /// Improve tracks by removing clusters with local chi2 highter than the defined cut
884 /// Recompute track parameters and covariances at the remaining clusters
885 AliDebug(1,"Enter ImproveTracks");
887 Double_t localChi2, worstLocalChi2;
889 AliMUONTrackParam *trackParamAtHit, *worstTrackParamAtHit;
891 // Remove double track to improve only "good" tracks
892 RemoveDoubleTracks();
894 AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First();
897 while (!track->IsImproved()) {
899 // Update track parameters and covariances
900 track->UpdateCovTrackParamAtHit();
902 // Compute local chi2 of each hits
903 track->ComputeLocalChi2(kTRUE);
905 // Look for the hit to remove
906 worstTrackParamAtHit = 0;
908 trackParamAtHit = (AliMUONTrackParam*) track->GetTrackParamAtHit()->First();
909 while (trackParamAtHit) {
911 // Pick up hit with the worst chi2
912 localChi2 = trackParamAtHit->GetLocalChi2();
913 if (localChi2 > worstLocalChi2) {
914 worstLocalChi2 = localChi2;
915 worstTrackParamAtHit = trackParamAtHit;
918 trackParamAtHit = (AliMUONTrackParam*) track->GetTrackParamAtHit()->After(trackParamAtHit);
921 // Check if bad hit found
922 if (!worstTrackParamAtHit) {
923 track->SetImproved(kTRUE);
927 // check whether the worst hit is removable or not
928 if (!worstTrackParamAtHit->IsRemovable()) {
929 track->SetImproved(kTRUE);
933 // Check whether the worst chi2 is under requirement or not
934 if (worstLocalChi2 < 2. * fgkSigmaToCutForImprovement * fgkSigmaToCutForImprovement) { // 2 because 2 quantities in chi2
935 track->SetImproved(kTRUE);
939 // Reset the second hit in the same station as the bad one as being NOT removable
940 worstChamber = worstTrackParamAtHit->GetHitForRecPtr()->GetChamberNumber();
941 if (worstChamber%2 == 0) ((AliMUONTrackParam*)track->GetTrackParamAtHit()->After(worstTrackParamAtHit))->SetRemovable(kFALSE);
942 else ((AliMUONTrackParam*)track->GetTrackParamAtHit()->Before(worstTrackParamAtHit))->SetRemovable(kFALSE);
944 // Remove the worst hit
945 track->RemoveTrackParamAtHit(worstTrackParamAtHit);
948 // Take into account the multiple scattering
949 // Calculate the track parameter covariance matrix
950 track->SetFitWithVertex(kFALSE); // To be sure
951 Fit(*track, kTRUE, kTRUE);
953 // Printout for debuging
954 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
955 cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(track)+1 << " improved " << endl;
960 track = (AliMUONTrack*) fRecTracksPtr->After(track);
965 //__________________________________________________________________________
966 void AliMUONTrackReconstructor::Finalize()
968 /// Fill AliMUONTrack's fHitForRecAtHit array
969 /// Recompute track parameters and covariances at each attached cluster from those at the first one
971 AliMUONTrackParam *trackParamAtHit;
973 track = (AliMUONTrack*) fRecTracksPtr->First();
976 // update track parameters if not already done
977 if (!track->IsImproved()) track->UpdateCovTrackParamAtHit();
979 trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First());
980 while (trackParamAtHit) {
982 // update array of track hit
983 track->AddHitForRecAtHit(trackParamAtHit->GetHitForRecPtr());
985 trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->After(trackParamAtHit));
988 track = (AliMUONTrack*) fRecTracksPtr->After(track);