]>
Commit | Line | Data |
---|---|---|
a9e2aefa | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
cc87ebcd | 16 | /* $Id$ */ |
17 | ||
3d1463c8 | 18 | //----------------------------------------------------------------------------- |
7945aae7 | 19 | /// \class AliMUONTrackReconstructor |
20 | /// MUON track reconstructor using the original method | |
21 | /// | |
22 | /// This class contains as data: | |
23 | /// - the parameters for the track reconstruction | |
24 | /// | |
25 | /// It contains as methods, among others: | |
26 | /// - MakeTracks to build the tracks | |
3d1463c8 | 27 | //----------------------------------------------------------------------------- |
a9e2aefa | 28 | |
29f1b13a | 29 | #include "AliMUONTrackReconstructor.h" |
7ec3b9cf | 30 | |
29fc2c86 | 31 | #include "AliMUONConstants.h" |
2457f726 | 32 | #include "AliMUONHitForRec.h" |
a9e2aefa | 33 | #include "AliMUONTrack.h" |
37827b29 | 34 | #include "AliMUONTrackParam.h" |
35 | #include "AliMUONTrackExtrap.h" | |
8c343c7c | 36 | #include "AliLog.h" |
af743f54 | 37 | |
208f139e | 38 | #include <TMinuit.h> |
af743f54 | 39 | #include <Riostream.h> |
ea94c18b | 40 | #include <TMath.h> |
af743f54 | 41 | #include <TMatrixD.h> |
a9e2aefa | 42 | |
de2cd600 | 43 | // Functions to be minimized with Minuit |
ea94c18b | 44 | void TrackChi2(Int_t &nParam, Double_t *gradient, Double_t &chi2, Double_t *param, Int_t flag); |
de2cd600 | 45 | |
7945aae7 | 46 | /// \cond CLASSIMP |
29f1b13a | 47 | ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context |
7945aae7 | 48 | /// \endcond |
a9e2aefa | 49 | |
ea94c18b | 50 | //************* Parameters for reconstruction |
51 | const Double_t AliMUONTrackReconstructor::fgkBendingVertexDispersion = 10.; | |
52 | const Double_t AliMUONTrackReconstructor::fgkNonBendingVertexDispersion = 10.; | |
53 | ||
2457f726 | 54 | |
019df241 | 55 | //__________________________________________________________________________ |
7ec3b9cf | 56 | AliMUONTrackReconstructor::AliMUONTrackReconstructor() |
57 | : AliMUONVTrackReconstructor() | |
a9e2aefa | 58 | { |
2457f726 | 59 | /// Constructor for class AliMUONTrackReconstructor |
ea94c18b | 60 | AliInfo("*** Original tracking ***"); |
a9e2aefa | 61 | } |
9cbdf048 | 62 | |
019df241 | 63 | //__________________________________________________________________________ |
ea94c18b | 64 | AliMUONTrackReconstructor::~AliMUONTrackReconstructor() |
a9e2aefa | 65 | { |
ea94c18b | 66 | /// Destructor |
67 | } | |
276c44b7 | 68 | |
de2cd600 | 69 | //__________________________________________________________________________ |
ea94c18b | 70 | void AliMUONTrackReconstructor::MakeTrackCandidates() |
de2cd600 | 71 | { |
019df241 | 72 | /// To make track candidates (assuming linear propagation if the flag fgkMakeTrackCandidatesFast is set to kTRUE): |
208f139e | 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; | |
208f139e | 77 | AliMUONTrack *track; |
208f139e | 78 | Int_t iCandidate = 0; |
019df241 | 79 | Bool_t hitFound; |
208f139e | 80 | |
de2cd600 | 81 | AliDebug(1,"Enter MakeTrackCandidates"); |
de2cd600 | 82 | |
208f139e | 83 | // Loop over stations(1..) 5 and 4 and make track candidates |
ea94c18b | 84 | for (Int_t istat=4; istat>=3; istat--) { |
85 | ||
208f139e | 86 | // Make segments in the station |
87 | segments = MakeSegmentsInStation(istat); | |
ea94c18b | 88 | |
208f139e | 89 | // Loop over segments |
7ec3b9cf | 90 | for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++) |
91 | { | |
208f139e | 92 | AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate)); |
ea94c18b | 93 | |
208f139e | 94 | // Transform segments to tracks and put them at the end of fRecTracksPtr |
ea94c18b | 95 | track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack((AliMUONObjectPair*)((*segments)[iseg])); |
a9e2aefa | 96 | fNRecTracks++; |
ea94c18b | 97 | |
208f139e | 98 | // Printout for debuging |
7ec3b9cf | 99 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) |
100 | { | |
208f139e | 101 | cout<<endl<<"Track parameter covariances at first hit with multiple Coulomb scattering effects:"<<endl; |
ea94c18b | 102 | ((AliMUONTrackParam*) track->GetTrackParamAtHit()->First())->GetCovariances().Print(); |
208f139e | 103 | } |
ea94c18b | 104 | |
208f139e | 105 | // Look for compatible hitForRec(s) in the other station |
019df241 | 106 | if (fgkMakeTrackCandidatesFast) hitFound = FollowLinearTrackInStation(*track,7-istat); |
107 | else hitFound = FollowTrackInStation(*track,7-istat); | |
108 | ||
109 | // Remove track if no hit found | |
110 | if (!hitFound) { | |
ea94c18b | 111 | fRecTracksPtr->Remove(track); |
112 | fNRecTracks--; | |
113 | } | |
114 | ||
a9e2aefa | 115 | } |
ea94c18b | 116 | |
208f139e | 117 | // delete the array of segments |
118 | delete segments; | |
119 | } | |
ea94c18b | 120 | |
208f139e | 121 | fRecTracksPtr->Compress(); // this is essential before checking tracks |
122 | ||
123 | // Keep all different tracks or only the best ones as required | |
124 | if (fgkTrackAllTracks) RemoveIdenticalTracks(); | |
125 | else RemoveDoubleTracks(); | |
126 | ||
127 | AliDebug(1,Form("Number of good candidates = %d",fNRecTracks)); | |
128 | ||
a9e2aefa | 129 | } |
130 | ||
131 | //__________________________________________________________________________ | |
ea94c18b | 132 | void AliMUONTrackReconstructor::FollowTracks() |
a9e2aefa | 133 | { |
2457f726 | 134 | /// Follow tracks in stations(1..) 3, 2 and 1 |
208f139e | 135 | AliDebug(1,"Enter FollowTracks"); |
136 | ||
04b5ea16 | 137 | AliMUONTrack *track, *nextTrack; |
af743f54 | 138 | Int_t currentNRecTracks; |
ea94c18b | 139 | Bool_t hitFound; |
208f139e | 140 | |
141 | for (Int_t station = 2; station >= 0; station--) { | |
ea94c18b | 142 | |
208f139e | 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 !! | |
af743f54 | 146 | currentNRecTracks = fNRecTracks; |
ea94c18b | 147 | |
af743f54 | 148 | for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) { |
208f139e | 149 | AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1)); |
ea94c18b | 150 | |
208f139e | 151 | track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack); |
ea94c18b | 152 | |
208f139e | 153 | // Fit the track: |
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 | |
157 | if (station==2) { | |
ea94c18b | 158 | SetVertexForFit(*track); |
208f139e | 159 | track->SetFitWithVertex(kTRUE); |
160 | } else track->SetFitWithVertex(kFALSE); | |
ea94c18b | 161 | Fit(*track, kFALSE, kTRUE); |
162 | ||
208f139e | 163 | // Remove the track if the normalized chi2 is too high |
ea94c18b | 164 | if (track->GetNormalizedChi2() > fgkSigmaToCutForTracking * fgkSigmaToCutForTracking) { |
208f139e | 165 | fRecTracksPtr->Remove(track); |
166 | fNRecTracks--; | |
167 | continue; | |
168 | } | |
ea94c18b | 169 | |
208f139e | 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; | |
ea94c18b | 173 | ((AliMUONTrackParam*) track->GetTrackParamAtHit()->First())->GetCovariances().Print(); |
208f139e | 174 | } |
ea94c18b | 175 | |
208f139e | 176 | // Look for compatible hitForRec in station(0..) "station" |
ea94c18b | 177 | hitFound = FollowTrackInStation(*track,station); |
178 | ||
179 | // Try to recover track if required | |
180 | if (!hitFound && fgkRecoverTracks) hitFound = RecoverTrack(*track,station); | |
181 | ||
182 | // remove track if no hit found | |
183 | if (!hitFound) { | |
184 | fRecTracksPtr->Remove(track); | |
185 | fNRecTracks--; | |
186 | } | |
187 | ||
208f139e | 188 | } |
ea94c18b | 189 | |
208f139e | 190 | // Compress fRecTracksPtr for the next step |
191 | fRecTracksPtr->Compress(); | |
ea94c18b | 192 | |
208f139e | 193 | // Keep only the best tracks if required |
194 | if (!fgkTrackAllTracks) RemoveDoubleTracks(); | |
ea94c18b | 195 | |
208f139e | 196 | } |
197 | ||
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; | |
04b5ea16 | 201 | track = (AliMUONTrack*) fRecTracksPtr->First(); |
04b5ea16 | 202 | while (track) { |
ea94c18b | 203 | |
04b5ea16 | 204 | trackIndex++; |
205 | nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track | |
ea94c18b | 206 | |
208f139e | 207 | track->SetFitWithVertex(kFALSE); // just to be sure |
ea94c18b | 208 | Fit(*track, kTRUE, kTRUE); |
209 | ||
208f139e | 210 | // Printout for debuging |
211 | if (AliLog::GetGlobalDebugLevel() >= 3) { | |
212 | cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl; | |
a9e2aefa | 213 | track->RecursiveDump(); |
208f139e | 214 | } |
ea94c18b | 215 | |
208f139e | 216 | // Remove the track if the normalized chi2 is too high |
ea94c18b | 217 | if (track->GetNormalizedChi2() > fgkSigmaToCutForTracking * fgkSigmaToCutForTracking) { |
208f139e | 218 | fRecTracksPtr->Remove(track); |
219 | fNRecTracks--; | |
a9e2aefa | 220 | } |
ea94c18b | 221 | |
208f139e | 222 | track = nextTrack; |
ea94c18b | 223 | |
208f139e | 224 | } |
ea94c18b | 225 | |
208f139e | 226 | fRecTracksPtr->Compress(); |
227 | ||
228 | } | |
1a38e749 | 229 | |
208f139e | 230 | //__________________________________________________________________________ |
ea94c18b | 231 | Bool_t AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation) |
208f139e | 232 | { |
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)); | |
240 | ||
ea94c18b | 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 | |
244 | Int_t ch1, ch2; | |
245 | if (nextStation==4) { | |
246 | ch1 = 2*nextStation+1; | |
247 | ch2 = 2*nextStation; | |
248 | } else { | |
249 | ch1 = 2*nextStation; | |
250 | ch2 = 2*nextStation+1; | |
251 | } | |
252 | ||
208f139e | 253 | Double_t chi2WithOneHitForRec = 1.e10; |
254 | Double_t chi2WithTwoHitForRec = 1.e10; | |
ea94c18b | 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 | |
208f139e | 257 | Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec; |
258 | Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec; | |
ea94c18b | 259 | Bool_t foundOneHit = kFALSE; |
260 | Bool_t foundTwoHits = kFALSE; | |
208f139e | 261 | AliMUONTrack *newTrack = 0x0; |
262 | AliMUONHitForRec *hitForRecCh1, *hitForRecCh2; | |
019df241 | 263 | AliMUONTrackParam extrapTrackParam; |
ea94c18b | 264 | AliMUONTrackParam extrapTrackParamAtHit1; |
265 | AliMUONTrackParam extrapTrackParamAtHit2; | |
266 | AliMUONTrackParam bestTrackParamAtHit1; | |
267 | AliMUONTrackParam bestTrackParamAtHit2; | |
847cbaef | 268 | Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]]; |
269 | for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE; | |
ea94c18b | 270 | |
019df241 | 271 | // Get track parameters |
272 | AliMUONTrackParam extrapTrackParamAtCh(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First()); | |
ea94c18b | 273 | |
274 | // Add MCS effect | |
019df241 | 275 | AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); |
ea94c18b | 276 | |
277 | // Add MCS in the missing chamber if any (only 1 chamber can be missing according to tracking criteria) | |
019df241 | 278 | if (ch1 < ch2 && extrapTrackParamAtCh.GetHitForRecPtr()->GetChamberNumber() > ch2 + 1) { |
ea94c18b | 279 | // extrapolation to the missing chamber |
019df241 | 280 | AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2 + 1)); |
ea94c18b | 281 | // add MCS effect |
019df241 | 282 | AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); |
ea94c18b | 283 | } |
284 | ||
285 | //Extrapolate trackCandidate to chamber "ch2" | |
019df241 | 286 | AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2)); |
ea94c18b | 287 | |
208f139e | 288 | // Printout for debuging |
289 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { | |
019df241 | 290 | cout<<endl<<"Track parameter covariances at first hit extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl; |
291 | extrapTrackParamAtCh.GetCovariances().Print(); | |
208f139e | 292 | } |
ea94c18b | 293 | |
208f139e | 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; | |
297 | } | |
ea94c18b | 298 | |
299 | // look for candidates in chamber 2 | |
208f139e | 300 | for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) { |
ea94c18b | 301 | |
208f139e | 302 | hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2); |
ea94c18b | 303 | |
019df241 | 304 | // try to add the current hit fast |
305 | if (!TryOneHitForRecFast(extrapTrackParamAtCh, hitForRecCh2)) continue; | |
306 | ||
307 | // try to add the current hit accuratly | |
308 | chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtCh, hitForRecCh2, extrapTrackParamAtHit2); | |
ea94c18b | 309 | |
208f139e | 310 | // if good chi2 then try to attach a hitForRec in the other chamber too |
311 | if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) { | |
ea94c18b | 312 | Bool_t foundSecondHit = kFALSE; |
313 | ||
208f139e | 314 | // Printout for debuging |
315 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
ea94c18b | 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; | |
a9e2aefa | 319 | } |
ea94c18b | 320 | |
321 | // add MCS effect for next step | |
322 | AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.); | |
323 | ||
019df241 | 324 | // copy new track parameters for next step |
325 | extrapTrackParam = extrapTrackParamAtHit2; | |
326 | ||
327 | //Extrapolate track parameters to chamber "ch1" | |
328 | AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1)); | |
329 | ||
208f139e | 330 | for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) { |
ea94c18b | 331 | |
332 | hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1); | |
333 | ||
019df241 | 334 | // try to add the current hit fast |
335 | if (!TryOneHitForRecFast(extrapTrackParam, hitForRecCh1)) continue; | |
336 | ||
337 | // try to add the current hit accuratly | |
ea94c18b | 338 | chi2WithTwoHitForRec = TryTwoHitForRec(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1); |
339 | ||
340 | // if good chi2 then create a new track by adding the 2 hitForRec to the "trackCandidate" | |
208f139e | 341 | if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) { |
342 | foundSecondHit = kTRUE; | |
ea94c18b | 343 | foundTwoHits = kTRUE; |
344 | ||
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; | |
349 | } | |
350 | ||
351 | if (fgkTrackAllTracks) { | |
208f139e | 352 | // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's |
ea94c18b | 353 | newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate); |
354 | UpdateTrack(*newTrack,extrapTrackParamAtHit1,extrapTrackParamAtHit2); | |
208f139e | 355 | fNRecTracks++; |
ea94c18b | 356 | |
847cbaef | 357 | // Tag hitForRecCh1 as used |
358 | hitForRecCh1Used[hit1] = kTRUE; | |
ea94c18b | 359 | |
208f139e | 360 | // Printout for debuging |
361 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
ea94c18b | 362 | cout << "FollowTrackInStation: added two hits in station(1..): " << nextStation+1 << endl; |
208f139e | 363 | if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); |
a9e2aefa | 364 | } |
ea94c18b | 365 | |
208f139e | 366 | } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) { |
367 | // keep track of the best couple of hits | |
368 | bestChi2WithTwoHitForRec = chi2WithTwoHitForRec; | |
ea94c18b | 369 | bestTrackParamAtHit1 = extrapTrackParamAtHit1; |
370 | bestTrackParamAtHit2 = extrapTrackParamAtHit2; | |
208f139e | 371 | } |
ea94c18b | 372 | |
a9e2aefa | 373 | } |
ea94c18b | 374 | |
d0bfce8d | 375 | } |
ea94c18b | 376 | |
208f139e | 377 | // if no hitForRecCh1 found then consider to add hitForRecCh2 only |
378 | if (!foundSecondHit) { | |
ea94c18b | 379 | foundOneHit = kTRUE; |
380 | ||
381 | if (fgkTrackAllTracks) { | |
208f139e | 382 | // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's |
ea94c18b | 383 | newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate); |
384 | UpdateTrack(*newTrack,extrapTrackParamAtHit2); | |
208f139e | 385 | fNRecTracks++; |
ea94c18b | 386 | |
208f139e | 387 | // Printout for debuging |
388 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
ea94c18b | 389 | cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl; |
208f139e | 390 | if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); |
391 | } | |
ea94c18b | 392 | |
393 | } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) { | |
019df241 | 394 | // keep track of the best single hitForRec except if a couple of hits has already been found |
208f139e | 395 | bestChi2WithOneHitForRec = chi2WithOneHitForRec; |
ea94c18b | 396 | bestTrackParamAtHit1 = extrapTrackParamAtHit2; |
208f139e | 397 | } |
ea94c18b | 398 | |
d0bfce8d | 399 | } |
ea94c18b | 400 | |
208f139e | 401 | } |
ea94c18b | 402 | |
208f139e | 403 | } |
ea94c18b | 404 | |
208f139e | 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 | |
ea94c18b | 407 | if (fgkTrackAllTracks || !foundTwoHits) { |
408 | ||
409 | // Printout for debuging | |
208f139e | 410 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { |
411 | cout << "FollowTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl; | |
412 | } | |
ea94c18b | 413 | |
414 | // add MCS effect for next step | |
019df241 | 415 | AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(),1.); |
416 | ||
417 | //Extrapolate trackCandidate to chamber "ch1" | |
418 | AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch1)); | |
419 | ||
208f139e | 420 | for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) { |
ea94c18b | 421 | |
208f139e | 422 | hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1); |
ea94c18b | 423 | |
847cbaef | 424 | if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used |
ea94c18b | 425 | |
019df241 | 426 | // try to add the current hit fast |
427 | if (!TryOneHitForRecFast(extrapTrackParamAtCh, hitForRecCh1)) continue; | |
428 | ||
429 | // try to add the current hit accuratly | |
430 | chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtCh, hitForRecCh1, extrapTrackParamAtHit1); | |
ea94c18b | 431 | |
432 | // if good chi2 then consider to add hitForRecCh1 | |
208f139e | 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) { | |
ea94c18b | 435 | foundOneHit = kTRUE; |
436 | ||
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; | |
441 | } | |
442 | ||
208f139e | 443 | if (fgkTrackAllTracks) { |
444 | // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's | |
ea94c18b | 445 | newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate); |
446 | UpdateTrack(*newTrack,extrapTrackParamAtHit1); | |
208f139e | 447 | fNRecTracks++; |
ea94c18b | 448 | |
449 | // Printout for debuging | |
208f139e | 450 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { |
ea94c18b | 451 | cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl; |
208f139e | 452 | if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); |
453 | } | |
ea94c18b | 454 | |
455 | } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) { | |
019df241 | 456 | // keep track of the best single hitForRec except if a couple of hits has already been found |
208f139e | 457 | bestChi2WithOneHitForRec = chi2WithOneHitForRec; |
ea94c18b | 458 | bestTrackParamAtHit1 = extrapTrackParamAtHit1; |
208f139e | 459 | } |
ea94c18b | 460 | |
d0bfce8d | 461 | } |
ea94c18b | 462 | |
208f139e | 463 | } |
ea94c18b | 464 | |
208f139e | 465 | } |
ea94c18b | 466 | |
208f139e | 467 | // fill out the best track if required else clean up the fRecTracksPtr array |
ea94c18b | 468 | if (!fgkTrackAllTracks) { |
469 | if (foundTwoHits) { | |
470 | UpdateTrack(trackCandidate,bestTrackParamAtHit1,bestTrackParamAtHit2); | |
471 | ||
208f139e | 472 | // Printout for debuging |
473 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
ea94c18b | 474 | cout << "FollowTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl; |
208f139e | 475 | if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); |
a9e2aefa | 476 | } |
ea94c18b | 477 | |
478 | } else if (foundOneHit) { | |
479 | UpdateTrack(trackCandidate,bestTrackParamAtHit1); | |
480 | ||
208f139e | 481 | // Printout for debuging |
482 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
ea94c18b | 483 | cout << "FollowTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl; |
208f139e | 484 | if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump(); |
04b5ea16 | 485 | } |
ea94c18b | 486 | |
dd230855 | 487 | } else { |
488 | delete [] hitForRecCh1Used; | |
489 | return kFALSE; | |
490 | } | |
ea94c18b | 491 | |
492 | } else if (foundOneHit || foundTwoHits) { | |
493 | ||
494 | // remove obsolete track | |
495 | fRecTracksPtr->Remove(&trackCandidate); | |
496 | fNRecTracks--; | |
497 | ||
dd230855 | 498 | } else { |
499 | delete [] hitForRecCh1Used; | |
500 | return kFALSE; | |
501 | } | |
ea94c18b | 502 | |
dd230855 | 503 | delete [] hitForRecCh1Used; |
ea94c18b | 504 | return kTRUE; |
505 | ||
506 | } | |
507 | ||
508 | //__________________________________________________________________________ | |
019df241 | 509 | Double_t AliMUONTrackReconstructor::TryTwoHitForRec(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2, |
510 | AliMUONTrackParam &trackParamAtHit2) | |
ea94c18b | 511 | { |
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 | |
515 | ||
ea94c18b | 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()); | |
520 | ||
521 | // set pointer to hit2 into trackParamAtHit2 | |
522 | trackParamAtHit2.SetHitForRecPtr(hitForRec2); | |
523 | ||
524 | // Set differences between track and the 2 hitForRec in the bending and non bending directions | |
019df241 | 525 | AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr(); |
ea94c18b | 526 | TMatrixD dPos(4,1); |
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(); | |
531 | ||
ea94c18b | 532 | // Calculate the error matrix from the track parameter covariances at first hitForRec |
533 | TMatrixD error(4,4); | |
534 | error.Zero(); | |
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(); | |
540 | ||
541 | // Save track coordinates at second hitForRec | |
542 | Double_t nonBendingCoor2 = trackParamAtHit2.GetNonBendingCoor(); | |
543 | Double_t bendingCoor2 = trackParamAtHit2.GetBendingCoor(); | |
544 | ||
545 | // add MCS effect at first hitForRec | |
546 | AliMUONTrackExtrap::AddMCSEffect(&trackParamAtHit1Save,AliMUONConstants::ChamberThicknessInX0(),1.); | |
547 | ||
548 | // Get the pointer to the parameter covariance matrix at first hitForRec | |
549 | const TMatrixD& kParamCov = trackParamAtHit1Save.GetCovariances(); | |
550 | ||
551 | // Calculate the jacobian related to the transformation between track parameters | |
552 | // at first hitForRec and track coordinates at the 2 hitForRec z-position | |
553 | TMatrixD jacob(4,5); | |
554 | jacob.Zero(); | |
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++) { | |
565 | if (j==i) { | |
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.; | |
569 | } | |
570 | ||
571 | // Set new track parameters at first hitForRec | |
572 | trackParamAtHit1Save.SetParameters(paramAtHit1Save); | |
573 | trackParamAtHit1Save.AddParameters(dParam); | |
574 | trackParamAtHit1Save.SetZ(z1); | |
575 | ||
576 | // Extrapolate new track parameters to the z position of the second hitForRec | |
577 | AliMUONTrackExtrap::ExtrapToZ(&trackParamAtHit1Save,hitForRec2->GetZ()); | |
578 | ||
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 | |
208f139e | 582 | } |
ea94c18b | 583 | |
584 | // Calculate the error matrix | |
585 | TMatrixD tmp(jacob,TMatrixD::kMult,kParamCov); | |
586 | error = TMatrixD(tmp,TMatrixD::kMultTranspose,jacob); | |
587 | } | |
588 | ||
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(); | |
594 | ||
595 | // invert the error matrix for Chi2 calculation | |
596 | if (error.Determinant() != 0) { | |
597 | error.Invert(); | |
208f139e | 598 | } else { |
ea94c18b | 599 | AliWarning(" Determinant error=0"); |
600 | return 1.e10; | |
208f139e | 601 | } |
602 | ||
ea94c18b | 603 | // Compute the Chi2 value |
604 | TMatrixD tmp2(dPos,TMatrixD::kTransposeMult,error); | |
605 | TMatrixD result(tmp2,TMatrixD::kMult,dPos); | |
606 | ||
607 | return result(0,0); | |
608 | ||
609 | } | |
610 | ||
611 | //__________________________________________________________________________ | |
612 | void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtHit) | |
613 | { | |
614 | /// Add 1 hit to the track candidate | |
615 | /// Update chi2 of the track | |
616 | ||
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(); | |
623 | ||
5f4ceff2 | 624 | // Flag hit as being not removable |
625 | trackParamAtHit.SetRemovable(kFALSE); | |
626 | trackParamAtHit.SetLocalChi2(0.); // --> Local chi2 not used | |
627 | ||
ea94c18b | 628 | // Update the chi2 of the new track |
629 | track.SetFitFMin(track.GetFitFMin() + localChi2); | |
630 | ||
631 | // Update TrackParamAtHit | |
632 | track.AddTrackParamAtHit(&trackParamAtHit,trackParamAtHit.GetHitForRecPtr()); | |
633 | track.GetTrackParamAtHit()->Sort(); | |
634 | ||
04b5ea16 | 635 | } |
636 | ||
de2cd600 | 637 | //__________________________________________________________________________ |
ea94c18b | 638 | void AliMUONTrackReconstructor::UpdateTrack(AliMUONTrack &track, AliMUONTrackParam &trackParamAtHit1, AliMUONTrackParam &trackParamAtHit2) |
639 | { | |
640 | /// Add 2 hits to the track candidate | |
641 | /// Update track and local chi2 | |
642 | ||
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); | |
650 | ||
651 | // Flag first hit as being removable | |
652 | trackParamAtHit1.SetRemovable(kTRUE); | |
653 | ||
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); | |
661 | ||
662 | // Flag first hit as being removable | |
663 | trackParamAtHit2.SetRemovable(kTRUE); | |
664 | ||
665 | // Update the chi2 of the new track | |
666 | track.SetFitFMin(track.GetFitFMin() + localChi2AtHit1 + localChi2AtHit2); | |
667 | ||
668 | // Update TrackParamAtHit | |
669 | track.AddTrackParamAtHit(&trackParamAtHit1,trackParamAtHit1.GetHitForRecPtr()); | |
670 | track.AddTrackParamAtHit(&trackParamAtHit2,trackParamAtHit2.GetHitForRecPtr()); | |
671 | track.GetTrackParamAtHit()->Sort(); | |
672 | ||
673 | } | |
674 | ||
675 | //__________________________________________________________________________ | |
676 | Bool_t AliMUONTrackReconstructor::RecoverTrack(AliMUONTrack &trackCandidate, Int_t nextStation) | |
677 | { | |
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"); | |
682 | ||
683 | // Do not try to recover track until we have attached hit(s) on station(1..) 3 | |
684 | if (nextStation > 1) return kFALSE; | |
685 | ||
686 | Int_t worstHitNumber = -1; | |
687 | Double_t localChi2, worstLocalChi2 = 0.; | |
688 | ||
689 | // Look for the hit to remove | |
690 | for (Int_t hitNumber = 0; hitNumber < 2; hitNumber++) { | |
691 | AliMUONTrackParam *trackParamAtHit = (AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt(hitNumber); | |
692 | ||
693 | // check if current hit is removable | |
694 | if (!trackParamAtHit->IsRemovable()) return kFALSE; | |
695 | ||
696 | // Pick up hit with the worst chi2 | |
697 | localChi2 = trackParamAtHit->GetLocalChi2(); | |
698 | if (localChi2 > worstLocalChi2) { | |
699 | worstLocalChi2 = localChi2; | |
700 | worstHitNumber = hitNumber; | |
701 | } | |
702 | } | |
703 | ||
704 | // Reset best hit as being NOT removable | |
705 | ((AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt((worstHitNumber+1)%2))->SetRemovable(kFALSE); | |
706 | ||
707 | // Remove the worst hit | |
708 | trackCandidate.RemoveTrackParamAtHit((AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->UncheckedAt(worstHitNumber)); | |
709 | ||
710 | // Re-fit the track: | |
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); | |
715 | ||
716 | // Look for new hit(s) in next station | |
717 | return FollowTrackInStation(trackCandidate,nextStation); | |
718 | ||
719 | } | |
720 | ||
721 | //__________________________________________________________________________ | |
722 | void AliMUONTrackReconstructor::SetVertexForFit(AliMUONTrack &trackCandidate) | |
de2cd600 | 723 | { |
208f139e | 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"); | |
de2cd600 | 730 | |
ea94c18b | 731 | Double_t nonBendingReso2 = fgkNonBendingVertexDispersion * fgkNonBendingVertexDispersion; |
732 | Double_t bendingReso2 = fgkBendingVertexDispersion * fgkBendingVertexDispersion; | |
208f139e | 733 | // add multiple scattering effets |
ea94c18b | 734 | AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate.GetTrackParamAtHit()->First()))); |
208f139e | 735 | paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering |
736 | AliMUONTrackExtrap::ExtrapToVertexUncorrected(¶mAtVertex,0.); | |
ea94c18b | 737 | const TMatrixD& kParamCov = paramAtVertex.GetCovariances(); |
738 | nonBendingReso2 += kParamCov(0,0); | |
739 | bendingReso2 += kParamCov(2,2); | |
208f139e | 740 | // Set the vertex |
741 | AliMUONHitForRec vertex; // Coordinates set to (0.,0.,0.) by default | |
742 | vertex.SetNonBendingReso2(nonBendingReso2); | |
743 | vertex.SetBendingReso2(bendingReso2); | |
ea94c18b | 744 | trackCandidate.SetVertex(&vertex); |
208f139e | 745 | } |
746 | ||
747 | //__________________________________________________________________________ | |
ea94c18b | 748 | void AliMUONTrackReconstructor::Fit(AliMUONTrack &track, Bool_t includeMCS, Bool_t calcCov) |
208f139e | 749 | { |
ea94c18b | 750 | /// Fit the track "track" w/wo multiple Coulomb scattering according to "includeMCS". |
de2cd600 | 751 | |
208f139e | 752 | Double_t benC, errorParam, invBenP, nonBenC, x, y; |
de2cd600 | 753 | AliMUONTrackParam *trackParam; |
208f139e | 754 | Double_t arg[1], fedm, errdef, fitFMin; |
755 | Int_t npari, nparx; | |
756 | Int_t status, covStatus; | |
757 | ||
8cde4af5 | 758 | // Instantiate gMinuit if not already done |
759 | if (!gMinuit) gMinuit = new TMinuit(6); | |
208f139e | 760 | // Clear MINUIT parameters |
761 | gMinuit->mncler(); | |
762 | // Give the fitted track to MINUIT | |
ea94c18b | 763 | gMinuit->SetObjectFit(&track); |
208f139e | 764 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) { |
765 | // Define print level | |
766 | arg[0] = 1; | |
767 | gMinuit->mnexcm("SET PRI", arg, 1, status); | |
768 | // Print covariance matrix | |
769 | gMinuit->mnexcm("SHO COV", arg, 0, status); | |
770 | } else { | |
771 | arg[0] = -1; | |
772 | gMinuit->mnexcm("SET PRI", arg, 1, status); | |
773 | } | |
de2cd600 | 774 | // No warnings |
208f139e | 775 | gMinuit->mnexcm("SET NOW", arg, 0, status); |
776 | // Define strategy | |
777 | //arg[0] = 2; | |
778 | //gMinuit->mnexcm("SET STR", arg, 1, status); | |
779 | ||
ea94c18b | 780 | // set flag w/wo multiple scattering according to "includeMCS" |
781 | track.SetFitWithMCS(includeMCS); | |
782 | if (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); | |
787 | } | |
788 | } | |
789 | ||
790 | // Set fitting function | |
791 | gMinuit->SetFCN(TrackChi2); | |
208f139e | 792 | |
793 | // Set fitted parameters (!! The order is very important for the covariance matrix !!) | |
ea94c18b | 794 | trackParam = (AliMUONTrackParam*) (track.GetTrackParamAtHit()->First()); |
de2cd600 | 795 | // could be tried with no limits for the search (min=max=0) ???? |
208f139e | 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); | |
803 | ||
de2cd600 | 804 | // minimization |
208f139e | 805 | gMinuit->mnexcm("MIGRAD", arg, 0, status); |
806 | ||
807 | // Calculate the covariance matrix more accurately if required | |
808 | if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status); | |
8cde4af5 | 809 | |
de2cd600 | 810 | // get results into "invBenP", "benC", "nonBenC" ("x", "y") |
208f139e | 811 | gMinuit->GetParameter(0, x, errorParam); |
812 | trackParam->SetNonBendingCoor(x); | |
813 | gMinuit->GetParameter(1, nonBenC, errorParam); | |
de2cd600 | 814 | trackParam->SetNonBendingSlope(nonBenC); |
208f139e | 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); | |
821 | ||
de2cd600 | 822 | // global result of the fit |
208f139e | 823 | gMinuit->mnstat(fitFMin, fedm, errdef, npari, nparx, covStatus); |
ea94c18b | 824 | track.SetFitFMin(fitFMin); |
208f139e | 825 | |
826 | // Get the covariance matrix if required | |
827 | if (calcCov) { | |
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); | |
ea94c18b | 834 | } else trackParam->DeleteCovariances(); |
208f139e | 835 | |
de2cd600 | 836 | } |
837 | ||
838 | //__________________________________________________________________________ | |
ea94c18b | 839 | void TrackChi2(Int_t & /*nParam*/, Double_t * /*gradient*/, Double_t &chi2, Double_t *param, Int_t /*flag*/) |
de2cd600 | 840 | { |
ea94c18b | 841 | /// Return the "Chi2" to be minimized with Minuit for track fitting. |
2457f726 | 842 | /// Assumes that the track hits are sorted according to increasing Z. |
843 | /// Track parameters at each TrackHit are updated accordingly. | |
ea94c18b | 844 | /// Vertex is used according to the flag "trackBeingFitted->GetFitWithVertex()". |
845 | /// Multiple Coulomb scattering is taken into account according to the flag "trackBeingFitted->GetFitWithMCS()". | |
208f139e | 846 | |
847 | AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit(); | |
ea94c18b | 848 | AliMUONTrackParam* trackParamAtHit = (AliMUONTrackParam*) trackBeingFitted->GetTrackParamAtHit()->First(); |
208f139e | 849 | Double_t dX, dY; |
ea94c18b | 850 | chi2 = 0.; // initialize chi2 |
208f139e | 851 | |
ea94c18b | 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(); | |
208f139e | 859 | |
860 | // Take the vertex into account in the fit if required | |
861 | if (trackBeingFitted->GetFitWithVertex()) { | |
ea94c18b | 862 | AliMUONTrackParam paramAtVertex(*trackParamAtHit); |
208f139e | 863 | AliMUONTrackExtrap::ExtrapToZ(¶mAtVertex, 0.); |
864 | AliMUONHitForRec *vertex = trackBeingFitted->GetVertex(); | |
865 | if (!vertex) { | |
866 | cout<<"Error in TrackChi2: Want to use the vertex in tracking but it has not been created!!"<<endl; | |
867 | exit(-1); | |
868 | } | |
869 | dX = vertex->GetNonBendingCoor() - paramAtVertex.GetNonBendingCoor(); | |
870 | dY = vertex->GetBendingCoor() - paramAtVertex.GetBendingCoor(); | |
ea94c18b | 871 | chi2 += dX * dX / vertex->GetNonBendingReso2() + dY * dY / vertex->GetBendingReso2(); |
de2cd600 | 872 | } |
208f139e | 873 | |
ea94c18b | 874 | // compute chi2 w/wo multiple scattering |
875 | if (trackBeingFitted->GetFitWithMCS()) chi2 += trackBeingFitted->ComputeGlobalChi2(kTRUE); | |
876 | else chi2 += trackBeingFitted->ComputeGlobalChi2(kFALSE); | |
877 | ||
de2cd600 | 878 | } |
879 | ||
880 | //__________________________________________________________________________ | |
ea94c18b | 881 | void AliMUONTrackReconstructor::ImproveTracks() |
de2cd600 | 882 | { |
ea94c18b | 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"); | |
208f139e | 886 | |
ea94c18b | 887 | Double_t localChi2, worstLocalChi2; |
888 | Int_t worstChamber; | |
889 | AliMUONTrackParam *trackParamAtHit, *worstTrackParamAtHit; | |
208f139e | 890 | |
ea94c18b | 891 | // Remove double track to improve only "good" tracks |
892 | RemoveDoubleTracks(); | |
893 | ||
894 | AliMUONTrack *track = (AliMUONTrack*) fRecTracksPtr->First(); | |
895 | while (track) { | |
896 | ||
897 | while (!track->IsImproved()) { | |
898 | ||
899 | // Update track parameters and covariances | |
900 | track->UpdateCovTrackParamAtHit(); | |
901 | ||
902 | // Compute local chi2 of each hits | |
903 | track->ComputeLocalChi2(kTRUE); | |
904 | ||
905 | // Look for the hit to remove | |
906 | worstTrackParamAtHit = 0; | |
907 | worstLocalChi2 = 0.; | |
908 | trackParamAtHit = (AliMUONTrackParam*) track->GetTrackParamAtHit()->First(); | |
909 | while (trackParamAtHit) { | |
910 | ||
911 | // Pick up hit with the worst chi2 | |
912 | localChi2 = trackParamAtHit->GetLocalChi2(); | |
913 | if (localChi2 > worstLocalChi2) { | |
914 | worstLocalChi2 = localChi2; | |
915 | worstTrackParamAtHit = trackParamAtHit; | |
916 | } | |
917 | ||
918 | trackParamAtHit = (AliMUONTrackParam*) track->GetTrackParamAtHit()->After(trackParamAtHit); | |
de2cd600 | 919 | } |
ea94c18b | 920 | |
921 | // Check if bad hit found | |
922 | if (!worstTrackParamAtHit) { | |
923 | track->SetImproved(kTRUE); | |
924 | break; | |
de2cd600 | 925 | } |
ea94c18b | 926 | |
927 | // check whether the worst hit is removable or not | |
928 | if (!worstTrackParamAtHit->IsRemovable()) { | |
929 | track->SetImproved(kTRUE); | |
930 | break; | |
de2cd600 | 931 | } |
ea94c18b | 932 | |
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); | |
936 | break; | |
937 | } | |
938 | ||
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); | |
943 | ||
944 | // Remove the worst hit | |
945 | track->RemoveTrackParamAtHit(worstTrackParamAtHit); | |
946 | ||
947 | // Re-fit the track: | |
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); | |
952 | ||
953 | // Printout for debuging | |
954 | if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) { | |
955 | cout << "ImproveTracks: track " << fRecTracksPtr->IndexOf(track)+1 << " improved " << endl; | |
956 | } | |
957 | ||
de2cd600 | 958 | } |
ea94c18b | 959 | |
960 | track = (AliMUONTrack*) fRecTracksPtr->After(track); | |
de2cd600 | 961 | } |
962 | ||
de2cd600 | 963 | } |
964 | ||
208f139e | 965 | //__________________________________________________________________________ |
ea94c18b | 966 | void AliMUONTrackReconstructor::Finalize() |
b8dc484b | 967 | { |
b58638a9 | 968 | /// Fill AliMUONTrack's fHitForRecAtHit array |
969 | /// Recompute track parameters and covariances at each attached cluster from those at the first one | |
b8dc484b | 970 | AliMUONTrack *track; |
de2cd600 | 971 | AliMUONTrackParam *trackParamAtHit; |
b58638a9 | 972 | |
b8dc484b | 973 | track = (AliMUONTrack*) fRecTracksPtr->First(); |
974 | while (track) { | |
ea94c18b | 975 | |
976 | // update track parameters if not already done | |
977 | if (!track->IsImproved()) track->UpdateCovTrackParamAtHit(); | |
978 | ||
de2cd600 | 979 | trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First()); |
980 | while (trackParamAtHit) { | |
ea94c18b | 981 | |
b58638a9 | 982 | // update array of track hit |
ea94c18b | 983 | track->AddHitForRecAtHit(trackParamAtHit->GetHitForRecPtr()); |
984 | ||
985 | trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->After(trackParamAtHit)); | |
de2cd600 | 986 | } |
ea94c18b | 987 | |
b8dc484b | 988 | track = (AliMUONTrack*) fRecTracksPtr->After(track); |
ea94c18b | 989 | |
de2cd600 | 990 | } |
ea94c18b | 991 | |
a9e2aefa | 992 | } |
993 | ||
276c44b7 | 994 |