]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackReconstructor.cxx
Moving from base to calib, and adding packing interface (a packed value is simply...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackReconstructor.cxx
CommitLineData
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
7945aae7 18/// \class AliMUONTrackReconstructor
19/// MUON track reconstructor using the original method
20///
21/// This class contains as data:
22/// - the parameters for the track reconstruction
23///
24/// It contains as methods, among others:
25/// - MakeTracks to build the tracks
26///
a9e2aefa 27
29f1b13a 28#include "AliMUONTrackReconstructor.h"
5e671e06 29#include "AliMUONData.h"
29fc2c86 30#include "AliMUONConstants.h"
a9e2aefa 31#include "AliMUONRawCluster.h"
2457f726 32#include "AliMUONHitForRec.h"
208f139e 33#include "AliMUONObjectPair.h"
a9e2aefa 34#include "AliMUONTrack.h"
37827b29 35#include "AliMUONTrackParam.h"
36#include "AliMUONTrackExtrap.h"
af743f54 37
8c343c7c 38#include "AliLog.h"
af743f54 39
208f139e 40#include <TMinuit.h>
af743f54 41#include <Riostream.h>
42#include <TMatrixD.h>
a9e2aefa 43
de2cd600 44// Functions to be minimized with Minuit
45void TrackChi2(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
46void TrackChi2MCS(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
47
de2cd600 48Double_t MultipleScatteringAngle2(AliMUONTrackParam *param);
49
7945aae7 50/// \cond CLASSIMP
29f1b13a 51ClassImp(AliMUONTrackReconstructor) // Class implementation in ROOT context
7945aae7 52/// \endcond
a9e2aefa 53
2457f726 54//************* Defaults parameters for reconstruction
208f139e 55const Double_t AliMUONTrackReconstructor::fgkMaxNormChi2 = 100.0;
56const Bool_t AliMUONTrackReconstructor::fgkTrackAllTracks = kFALSE;
2457f726 57
3bc8b580 58//__________________________________________________________________________
cc9e7528 59AliMUONTrackReconstructor::AliMUONTrackReconstructor(AliMUONData* data)
208f139e 60 : AliMUONVTrackReconstructor(data)
a9e2aefa 61{
2457f726 62 /// Constructor for class AliMUONTrackReconstructor
de2cd600 63
a9e2aefa 64 // Memory allocation for the TClonesArray of reconstructed tracks
a9e2aefa 65 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
a9e2aefa 66}
9cbdf048 67
a9e2aefa 68 //__________________________________________________________________________
29f1b13a 69AliMUONTrackReconstructor::~AliMUONTrackReconstructor(void)
a9e2aefa 70{
2457f726 71 /// Destructor for class AliMUONTrackReconstructor
de2cd600 72 delete fRecTracksPtr;
a9e2aefa 73}
a9e2aefa 74
75 //__________________________________________________________________________
2457f726 76void AliMUONTrackReconstructor::AddHitsForRecFromRawClusters()
a9e2aefa 77{
2457f726 78 /// To add to the list of hits for reconstruction all the raw clusters
e6b25a6e 79 TTree *treeR;
a9e2aefa 80 AliMUONHitForRec *hitForRec;
81 AliMUONRawCluster *clus;
208f139e 82 Int_t iclus, nclus;
a9e2aefa 83 TClonesArray *rawclusters;
b840996b 84 AliDebug(1,"Enter AddHitsForRecFromRawClusters");
2457f726 85
e6b25a6e 86 treeR = fMUONData->TreeR();
87 if (!treeR) {
88 AliError("TreeR must be loaded");
2457f726 89 exit(0);
f69d51b5 90 }
e6b25a6e 91
e6b25a6e 92 fMUONData->SetTreeAddress("RC");
2457f726 93 fMUONData->GetRawClusters(); // only one entry
94
a9e2aefa 95 // Loop over tracking chambers
190f97ea 96 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
52c9bc11 97 rawclusters =fMUONData->RawClusters(ch);
a9e2aefa 98 nclus = (Int_t) (rawclusters->GetEntries());
99 // Loop over (cathode correlated) raw clusters
100 for (iclus = 0; iclus < nclus; iclus++) {
101 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
102 // new AliMUONHitForRec from raw cluster
103 // and increment number of AliMUONHitForRec's (total and in chamber)
104 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
105 fNHitsForRec++;
a9e2aefa 106 // more information into HitForRec
fff097e0 107 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
108 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
a9e2aefa 109 // original raw cluster
110 hitForRec->SetChamberNumber(ch);
111 hitForRec->SetHitNumber(iclus);
ba5b68db 112 // Z coordinate of the raw cluster (cm)
ba12c242 113 hitForRec->SetZ(clus->GetZ(0));
8cde4af5 114 if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
115 cout << "Chamber " << ch <<" raw cluster " << iclus << " : " << endl;
116 clus->Print("full");
117 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
118 hitForRec->Print("full");
119 }
a9e2aefa 120 } // end of cluster loop
121 } // end of chamber loop
cc87ebcd 122 SortHitsForRecWithIncreasingChamber();
2457f726 123
124 AliDebug(1,"End of AddHitsForRecFromRawClusters");
125 if (AliLog::GetGlobalDebugLevel() > 0) {
126 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
127 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
128 AliDebug(1, Form("Chamber(0...): %d",ch));
129 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
130 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
131 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
132 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
133 hit++) {
134 AliDebug(1, Form("HitForRec index(0...): %d",hit));
135 ((*fHitsForRecPtr)[hit])->Dump();
136 }
137 }
138 }
139
a9e2aefa 140 return;
141}
142
a9e2aefa 143 //__________________________________________________________________________
29f1b13a 144void AliMUONTrackReconstructor::MakeTracks(void)
a9e2aefa 145{
2457f726 146 /// To make the tracks from the list of segments and points in all stations
b840996b 147 AliDebug(1,"Enter MakeTracks");
2457f726 148 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
149 MakeTrackCandidates();
150 // Follow tracks in stations(1..) 3, 2 and 1
151 FollowTracks();
152 // Remove double tracks
153 RemoveDoubleTracks();
208f139e 154 // Fill out the AliMUONTrack's
155 FillMUONTrack();
276c44b7 156}
157
de2cd600 158 //__________________________________________________________________________
159void AliMUONTrackReconstructor::MakeTrackCandidates(void)
160{
208f139e 161 /// To make track candidates:
162 /// Start with segments station(1..) 4 or 5 then follow track in station 5 or 4.
163 /// Good candidates are made of at least three hitForRec's.
164 /// Keep only best candidates or all of them according to the flag fgkTrackAllTracks.
165 TClonesArray *segments;
166 AliMUONObjectPair *segment;
167 AliMUONHitForRec *hitForRec1, *hitForRec2;
168 AliMUONTrack *track;
169 AliMUONTrackParam *trackParamAtFirstHit;
170 Int_t iCandidate = 0;
171
de2cd600 172 AliDebug(1,"Enter MakeTrackCandidates");
de2cd600 173
208f139e 174 // Loop over stations(1..) 5 and 4 and make track candidates
175 for (Int_t istat=4; istat>=3; istat--) {
176 // Make segments in the station
177 segments = MakeSegmentsInStation(istat);
178 // Loop over segments
179 for (Int_t iseg=0; iseg<segments->GetEntriesFast(); iseg++) {
180 AliDebug(1,Form("Making primary candidate(1..) %d",++iCandidate));
181 // Transform segments to tracks and put them at the end of fRecTracksPtr
182 segment = (AliMUONObjectPair*) ((*segments)[iseg]);
183 hitForRec1 = (AliMUONHitForRec*) segment->First();
184 hitForRec2 = (AliMUONHitForRec*) segment->Second();
185 track = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(hitForRec1, hitForRec2);
a9e2aefa 186 fNRecTracks++;
208f139e 187 // Add MCS effects in parameter covariances
188 trackParamAtFirstHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First());
8cde4af5 189 AliMUONTrackExtrap::AddMCSEffect(trackParamAtFirstHit,AliMUONConstants::ChamberThicknessInX0(),1.);
208f139e 190 // Printout for debuging
191 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
192 cout<<endl<<"Track parameter covariances at first hit with multiple Coulomb scattering effects:"<<endl;
193 trackParamAtFirstHit->GetCovariances()->Print();
194 }
195 // Look for compatible hitForRec(s) in the other station
196 FollowTrackInStation(track,7-istat);
a9e2aefa 197 }
208f139e 198 // delete the array of segments
199 delete segments;
200 }
201 fRecTracksPtr->Compress(); // this is essential before checking tracks
202
203 // Keep all different tracks or only the best ones as required
204 if (fgkTrackAllTracks) RemoveIdenticalTracks();
205 else RemoveDoubleTracks();
206
207 AliDebug(1,Form("Number of good candidates = %d",fNRecTracks));
208
a9e2aefa 209}
210
211 //__________________________________________________________________________
208f139e 212void AliMUONTrackReconstructor::RemoveIdenticalTracks(void)
a9e2aefa 213{
208f139e 214 /// To remove identical tracks:
215 /// Tracks are considered identical if they have all their hits in common.
216 /// One keeps the track with the larger number of hits if need be
217 AliMUONTrack *track1, *track2, *trackToRemove;
218 Int_t hitsInCommon, nHits1, nHits2;
219 Bool_t removedTrack1;
220 // Loop over first track of the pair
221 track1 = (AliMUONTrack*) fRecTracksPtr->First();
222 while (track1) {
223 removedTrack1 = kFALSE;
224 nHits1 = track1->GetNTrackHits();
225 // Loop over second track of the pair
226 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
227 while (track2) {
228 nHits2 = track2->GetNTrackHits();
229 // number of hits in common between two tracks
230 hitsInCommon = track1->HitsInCommon(track2);
231 // check for identical tracks
232 if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
233 // decide which track to remove
234 if (nHits2 > nHits1) {
235 // remove track1 and continue the first loop with the track next to track1
236 trackToRemove = track1;
237 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
238 fRecTracksPtr->Remove(trackToRemove);
239 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
240 fNRecTracks--;
241 removedTrack1 = kTRUE;
242 break;
243 } else {
244 // remove track2 and continue the second loop with the track next to track2
245 trackToRemove = track2;
246 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
247 fRecTracksPtr->Remove(trackToRemove);
248 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
249 fNRecTracks--;
250 }
251 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
252 } // track2
253 if (removedTrack1) continue;
254 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
255 } // track1
256 return;
a9e2aefa 257}
258
259 //__________________________________________________________________________
208f139e 260void AliMUONTrackReconstructor::RemoveDoubleTracks(void)
a9e2aefa 261{
208f139e 262 /// To remove double tracks:
263 /// Tracks are considered identical if more than half of the hits of the track
264 /// which has the smaller number of hits are in common with the other track.
265 /// Among two identical tracks, one keeps the track with the larger number of hits
266 /// or, if these numbers are equal, the track with the minimum chi2.
267 AliMUONTrack *track1, *track2, *trackToRemove;
268 Int_t hitsInCommon, nHits1, nHits2;
269 Bool_t removedTrack1;
270 // Loop over first track of the pair
271 track1 = (AliMUONTrack*) fRecTracksPtr->First();
272 while (track1) {
273 removedTrack1 = kFALSE;
274 nHits1 = track1->GetNTrackHits();
275 // Loop over second track of the pair
276 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
277 while (track2) {
278 nHits2 = track2->GetNTrackHits();
279 // number of hits in common between two tracks
280 hitsInCommon = track1->HitsInCommon(track2);
281 // check for identical tracks
282 if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
283 // decide which track to remove
284 if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
285 // remove track2 and continue the second loop with the track next to track2
286 trackToRemove = track2;
287 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
288 fRecTracksPtr->Remove(trackToRemove);
289 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
290 fNRecTracks--;
291 } else {
292 // else remove track1 and continue the first loop with the track next to track1
293 trackToRemove = track1;
294 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
295 fRecTracksPtr->Remove(trackToRemove);
296 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
297 fNRecTracks--;
298 removedTrack1 = kTRUE;
299 break;
300 }
301 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
302 } // track2
303 if (removedTrack1) continue;
304 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
305 } // track1
306 return;
a9e2aefa 307}
308
309 //__________________________________________________________________________
29f1b13a 310void AliMUONTrackReconstructor::FollowTracks(void)
a9e2aefa 311{
2457f726 312 /// Follow tracks in stations(1..) 3, 2 and 1
208f139e 313 AliDebug(1,"Enter FollowTracks");
314
04b5ea16 315 AliMUONTrack *track, *nextTrack;
208f139e 316 AliMUONTrackParam *trackParamAtFirstHit;
317 Double_t numberOfDegFree, chi2Norm;
af743f54 318 Int_t currentNRecTracks;
208f139e 319
320 for (Int_t station = 2; station >= 0; station--) {
321 // Save the actual number of reconstructed track in case of
322 // tracks are added or suppressed during the tracking procedure
323 // !! Do not compress fRecTracksPtr until the end of the loop over tracks !!
af743f54 324 currentNRecTracks = fNRecTracks;
325 for (Int_t iRecTrack = 0; iRecTrack <currentNRecTracks; iRecTrack++) {
208f139e 326 AliDebug(1,Form("FollowTracks: track candidate(1..) %d", iRecTrack+1));
327 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iRecTrack);
328 // Fit the track:
329 // Do not take into account the multiple scattering to speed up the fit
330 // Calculate the track parameter covariance matrix
331 // If "station" is station(1..) 3 then use the vertex to better constrain the fit
332 if (station==2) {
333 SetVertexForFit(track);
334 track->SetFitWithVertex(kTRUE);
335 } else track->SetFitWithVertex(kFALSE);
336 Fit(track,kFALSE, kTRUE);
337 // Remove the track if the normalized chi2 is too high
338 numberOfDegFree = (2. * track->GetNTrackHits() - 5.);
339 if (numberOfDegFree > 0) chi2Norm = track->GetFitFMin() / numberOfDegFree;
340 else chi2Norm = 1.e10;
341 if (chi2Norm > fgkMaxNormChi2) {
342 fRecTracksPtr->Remove(track);
343 fNRecTracks--;
344 continue;
345 }
346 // Add MCS effects in parameter covariances
347 trackParamAtFirstHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First());
8cde4af5 348 AliMUONTrackExtrap::AddMCSEffect(trackParamAtFirstHit,AliMUONConstants::ChamberThicknessInX0(),1.);
208f139e 349 // Printout for debuging
350 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
351 cout<<endl<<"Track parameter covariances at first hit with multiple Coulomb scattering effects:"<<endl;
352 trackParamAtFirstHit->GetCovariances()->Print();
353 }
354 // Look for compatible hitForRec in station(0..) "station"
355 FollowTrackInStation(track,station);
356 }
357 // Compress fRecTracksPtr for the next step
358 fRecTracksPtr->Compress();
359 // Keep only the best tracks if required
360 if (!fgkTrackAllTracks) RemoveDoubleTracks();
361 }
362
363 // Last fit of track candidates with all station
364 // Take into account the multiple scattering and remove bad tracks
365 Int_t trackIndex = -1;
04b5ea16 366 track = (AliMUONTrack*) fRecTracksPtr->First();
04b5ea16 367 while (track) {
04b5ea16 368 trackIndex++;
369 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
208f139e 370 track->SetFitWithVertex(kFALSE); // just to be sure
371 Fit(track,kTRUE, kFALSE);
372 // Printout for debuging
373 if (AliLog::GetGlobalDebugLevel() >= 3) {
374 cout << "FollowTracks: track candidate(0..) " << trackIndex << " after final fit" << endl;
a9e2aefa 375 track->RecursiveDump();
208f139e 376 }
377 // Remove the track if the normalized chi2 is too high
378 numberOfDegFree = (2.0 * track->GetNTrackHits() - 5);
379 if (numberOfDegFree > 0) chi2Norm = track->GetFitFMin() / numberOfDegFree;
380 else chi2Norm = 1.e10;
381 if (chi2Norm > fgkMaxNormChi2) {
382 fRecTracksPtr->Remove(track);
383 fNRecTracks--;
a9e2aefa 384 }
208f139e 385 track = nextTrack;
386 }
387 fRecTracksPtr->Compress();
388
389}
1a38e749 390
208f139e 391 //__________________________________________________________________________
392void AliMUONTrackReconstructor::FollowTrackInStation(AliMUONTrack* trackCandidate, Int_t nextStation)
393{
394 /// Follow trackCandidate in station(0..) nextStation and search for compatible HitForRec(s)
395 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
396 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
397 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
398 /// Remove the obsolete "trackCandidate" at the end.
399 /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
400 AliDebug(1,Form("Enter FollowTrackInStation(1..) %d", nextStation+1));
401
402 Int_t ch1 = 2*nextStation;
403 Int_t ch2 = 2*nextStation+1;
404 Double_t zCh2 = AliMUONConstants::DefaultChamberZ(ch2);
405 Double_t chi2WithOneHitForRec = 1.e10;
406 Double_t chi2WithTwoHitForRec = 1.e10;
407 Double_t maxChi2WithOneHitForRec = 2.*fgkMaxNormChi2; // 2 because 2 quantities in chi2
408 Double_t maxChi2WithTwoHitForRec = 4.*fgkMaxNormChi2; // 4 because 4 quantities in chi2
409 Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
410 Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
411 AliMUONTrack *newTrack = 0x0;
412 AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
413 AliMUONHitForRec *bestHitForRec1 = 0x0, *bestHitForRec2 = 0x0;
847cbaef 414 Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
415 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
208f139e 416 //
417 //Extrapolate trackCandidate to chamber "ch2" to save computing time in the next steps
418 AliMUONTrackParam *extrapTrackParamPtr = trackCandidate->GetExtrapTrackParam();
419 *extrapTrackParamPtr = *((AliMUONTrackParam*)(trackCandidate->GetTrackParamAtHit()->First()));
420 AliMUONTrackExtrap::ExtrapToZCov(extrapTrackParamPtr, zCh2);
421 AliMUONTrackParam extrapTrackParamSave(*extrapTrackParamPtr);
422 //
423 // Printout for debuging
424 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
425 TMatrixD* paramCovForDebug = extrapTrackParamPtr->GetCovariances();
426 cout<<endl<<"Track parameter covariances at first hit extrapolated to z = "<<zCh2<<":"<<endl;
427 paramCovForDebug->Print();
428 }
429 //
430 // look for candidates in chamber 2
431 // Printout for debuging
432 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
433 cout << "FollowTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
434 }
435 for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
436 hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
437 // extrapolate track parameters and covariances only once for this hit
438 AliMUONTrackExtrap::ExtrapToZCov(extrapTrackParamPtr, hitForRecCh2->GetZ());
439 chi2WithOneHitForRec = trackCandidate->TryOneHitForRec(hitForRecCh2);
440 // if good chi2 then try to attach a hitForRec in the other chamber too
441 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
442 // Printout for debuging
443 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
444 cout << "FollowTrackInStation: look for second hits in chamber(1..): " << ch1+1 << endl;
a9e2aefa 445 }
208f139e 446 Bool_t foundSecondHit = kFALSE;
447 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
448 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
449 chi2WithTwoHitForRec = trackCandidate->TryTwoHitForRec(hitForRecCh2, hitForRecCh1); // order hits like that to save computing time
450 // if good chi2 then create a new track by adding the 2 hitForRec to the "trackCandidate"
451 if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
452 foundSecondHit = kTRUE;
453 if (fgkTrackAllTracks) {
454 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
455 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*trackCandidate);
456 fNRecTracks++;
af743f54 457 AliMUONTrackParam trackParam1(extrapTrackParamSave);
458 AliMUONTrackExtrap::ExtrapToZ(&trackParam1, hitForRecCh1->GetZ());
459 newTrack->AddTrackParamAtHit(&trackParam1,hitForRecCh1);
460 AliMUONTrackParam trackParam2(extrapTrackParamSave);
461 AliMUONTrackExtrap::ExtrapToZ(&trackParam2, hitForRecCh2->GetZ());
462 newTrack->AddTrackParamAtHit(&trackParam2,hitForRecCh2);
208f139e 463 // Sort TrackParamAtHit according to increasing Z
464 newTrack->GetTrackParamAtHit()->Sort();
465 // Update the chi2 of the new track
466 if (newTrack->GetFitFMin()<0) newTrack->SetFitFMin(chi2WithTwoHitForRec);
467 else newTrack->SetFitFMin(newTrack->GetFitFMin() + chi2WithTwoHitForRec);
847cbaef 468 // Tag hitForRecCh1 as used
469 hitForRecCh1Used[hit1] = kTRUE;
208f139e 470 // Printout for debuging
471 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
472 cout << "FollowTrackInStation: added two hits in station(1..): " << nextStation+1
473 << " (Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
474 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
a9e2aefa 475 }
208f139e 476 } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
477 // keep track of the best couple of hits
478 bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
479 bestHitForRec1 = hitForRecCh1;
480 bestHitForRec2 = hitForRecCh2;
481 }
a9e2aefa 482 }
d0bfce8d 483 }
208f139e 484 // if no hitForRecCh1 found then consider to add hitForRecCh2 only
485 if (!foundSecondHit) {
486 if (fgkTrackAllTracks) {
487 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
488 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*trackCandidate);
489 fNRecTracks++;
af743f54 490 AliMUONTrackParam trackParam1(extrapTrackParamSave);
491 AliMUONTrackExtrap::ExtrapToZ(&trackParam1, hitForRecCh2->GetZ());
492 newTrack->AddTrackParamAtHit(&trackParam1,hitForRecCh2);
208f139e 493 // Sort TrackParamAtHit according to increasing Z
494 newTrack->GetTrackParamAtHit()->Sort();
495 // Update the chi2 of the new track
496 if (newTrack->GetFitFMin()<0) newTrack->SetFitFMin(chi2WithOneHitForRec);
497 else newTrack->SetFitFMin(newTrack->GetFitFMin() + chi2WithOneHitForRec);
498 // Printout for debuging
499 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
500 cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch2+1
501 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
502 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
503 }
504 } if (!bestHitForRec2 && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
505 // keep track of the best single hitForRec except if a couple
506 // of hits has already been found (i.e. bestHitForRec2!=0x0)
507 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
508 bestHitForRec1 = hitForRecCh2;
509 }
d0bfce8d 510 }
208f139e 511 }
512 // reset the extrapolated track parameter for next step
513 trackCandidate->SetExtrapTrackParam(&extrapTrackParamSave);
514 }
515 //
516 // look for candidates in chamber 1 not already attached to a track
517 // if we want to keep all possible tracks or if no good couple of hitForRec has been found
518 if (fgkTrackAllTracks || !bestHitForRec2) {
519 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
520 cout << "FollowTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
521 }
522 for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
523 hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
847cbaef 524 if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
208f139e 525 chi2WithOneHitForRec = trackCandidate->TryOneHitForRec(hitForRecCh1);
526 // if good chi2 then create a new track by adding the good hitForRec in "ch1" to the "trackCandidate"
527 // We do not try to attach a hitForRec in the other chamber too since it has already been done above
528 if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
529 if (fgkTrackAllTracks) {
530 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
531 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(*trackCandidate);
532 fNRecTracks++;
af743f54 533 AliMUONTrackParam trackParam1(extrapTrackParamSave);
534 AliMUONTrackExtrap::ExtrapToZ(&trackParam1, hitForRecCh1->GetZ());
535 newTrack->AddTrackParamAtHit(&trackParam1,hitForRecCh1);
208f139e 536 // Sort TrackParamAtHit according to increasing Z
537 newTrack->GetTrackParamAtHit()->Sort();
538 // Update the chi2 of the new track
539 if (newTrack->GetFitFMin()<0) newTrack->SetFitFMin(chi2WithOneHitForRec);
540 else newTrack->SetFitFMin(newTrack->GetFitFMin() + chi2WithOneHitForRec);
541 // Printout for debuging
542 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
543 cout << "FollowTrackInStation: added one hit in chamber(1..): " << ch1+1
544 << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
545 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
546 }
547 } if (!bestHitForRec2 && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
548 // keep track of the best single hitForRec except if a couple
549 // of hits has already been found (i.e. bestHitForRec1!=0x0)
550 bestChi2WithOneHitForRec = chi2WithOneHitForRec;
551 bestHitForRec1 = hitForRecCh1;
552 }
d0bfce8d 553 }
208f139e 554 }
555 }
556 //
557 // fill out the best track if required else clean up the fRecTracksPtr array
558 if (!fgkTrackAllTracks && bestHitForRec1) {
af743f54 559 AliMUONTrackParam trackParam1(extrapTrackParamSave);
560 AliMUONTrackExtrap::ExtrapToZ(&trackParam1, bestHitForRec1->GetZ());
561 trackCandidate->AddTrackParamAtHit(&trackParam1,bestHitForRec1);
208f139e 562 if (bestHitForRec2) {
af743f54 563 AliMUONTrackParam trackParam2(extrapTrackParamSave);
564 AliMUONTrackExtrap::ExtrapToZ(&trackParam2, bestHitForRec2->GetZ());
565 trackCandidate->AddTrackParamAtHit(&trackParam2,bestHitForRec2);
208f139e 566 // Sort TrackParamAtHit according to increasing Z
567 trackCandidate->GetTrackParamAtHit()->Sort();
568 // Update the chi2 of the new track
569 if (trackCandidate->GetFitFMin()<0) trackCandidate->SetFitFMin(bestChi2WithTwoHitForRec);
570 else trackCandidate->SetFitFMin(trackCandidate->GetFitFMin() + bestChi2WithTwoHitForRec);
571 // Printout for debuging
572 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
573 cout << "FollowTrackInStation: added the two best hits in station(1..): " << nextStation+1
574 << " (Chi2 = " << bestChi2WithTwoHitForRec << ")" << endl;
575 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
a9e2aefa 576 }
208f139e 577 } else {
578 // Sort TrackParamAtHit according to increasing Z
579 trackCandidate->GetTrackParamAtHit()->Sort();
580 // Update the chi2 of the new track
581 if (trackCandidate->GetFitFMin()<0) trackCandidate->SetFitFMin(bestChi2WithOneHitForRec);
582 else trackCandidate->SetFitFMin(trackCandidate->GetFitFMin() + bestChi2WithOneHitForRec);
583 // Printout for debuging
584 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
585 cout << "FollowTrackInStation: added the best hit in station(1..): " << nextStation+1
586 << " (Chi2 = " << bestChi2WithOneHitForRec << ")" << endl;
587 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
04b5ea16 588 }
208f139e 589 }
590 } else {
591 fRecTracksPtr->Remove(trackCandidate); // obsolete track
592 fNRecTracks--;
593 }
594
04b5ea16 595}
596
de2cd600 597 //__________________________________________________________________________
208f139e 598void AliMUONTrackReconstructor::SetVertexForFit(AliMUONTrack* trackCandidate)
de2cd600 599{
208f139e 600 /// Add the vertex as a measured hit to constrain the fit of the "trackCandidate"
601 /// Compute the vertex resolution from natural vertex dispersion and
602 /// multiple scattering effets according to trackCandidate path in absorber
603 /// It is necessary to account for multiple scattering effects here instead of during the fit of
604 /// the "trackCandidate" to do not influence the result by changing track resolution at vertex
605 AliDebug(1,"Enter SetVertexForFit");
de2cd600 606
208f139e 607 Double_t nonBendingReso2 = fNonBendingVertexDispersion * fNonBendingVertexDispersion;
608 Double_t bendingReso2 = fBendingVertexDispersion * fBendingVertexDispersion;
609 // add multiple scattering effets
610 AliMUONTrackParam paramAtVertex(*((AliMUONTrackParam*)(trackCandidate->GetTrackParamAtHit()->First())));
611 paramAtVertex.DeleteCovariances(); // to be sure to account only for multiple scattering
612 AliMUONTrackExtrap::ExtrapToVertexUncorrected(&paramAtVertex,0.);
613 TMatrixD* paramCov = paramAtVertex.GetCovariances();
614 nonBendingReso2 += (*paramCov)(0,0);
615 bendingReso2 += (*paramCov)(2,2);
616 // Set the vertex
617 AliMUONHitForRec vertex; // Coordinates set to (0.,0.,0.) by default
618 vertex.SetNonBendingReso2(nonBendingReso2);
619 vertex.SetBendingReso2(bendingReso2);
620 trackCandidate->SetVertex(&vertex);
621}
622
623 //__________________________________________________________________________
624void AliMUONTrackReconstructor::Fit(AliMUONTrack *track, Bool_t includeMCS, Bool_t calcCov)
625{
626 /// Fit the track "track" with or without multiple Coulomb scattering according to "includeMCS".
de2cd600 627
208f139e 628 Double_t benC, errorParam, invBenP, nonBenC, x, y;
de2cd600 629 AliMUONTrackParam *trackParam;
208f139e 630 Double_t arg[1], fedm, errdef, fitFMin;
631 Int_t npari, nparx;
632 Int_t status, covStatus;
633
8cde4af5 634 // Instantiate gMinuit if not already done
635 if (!gMinuit) gMinuit = new TMinuit(6);
208f139e 636 // Clear MINUIT parameters
637 gMinuit->mncler();
638 // Give the fitted track to MINUIT
639 gMinuit->SetObjectFit(track);
640 if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
641 // Define print level
642 arg[0] = 1;
643 gMinuit->mnexcm("SET PRI", arg, 1, status);
644 // Print covariance matrix
645 gMinuit->mnexcm("SHO COV", arg, 0, status);
646 } else {
647 arg[0] = -1;
648 gMinuit->mnexcm("SET PRI", arg, 1, status);
649 }
de2cd600 650 // No warnings
208f139e 651 gMinuit->mnexcm("SET NOW", arg, 0, status);
652 // Define strategy
653 //arg[0] = 2;
654 //gMinuit->mnexcm("SET STR", arg, 1, status);
655
656 // Switch between available FCN according to "includeMCS"
657 if (includeMCS) gMinuit->SetFCN(TrackChi2MCS);
658 else gMinuit->SetFCN(TrackChi2);
659
660 // Set fitted parameters (!! The order is very important for the covariance matrix !!)
661 trackParam = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First());
de2cd600 662 // could be tried with no limits for the search (min=max=0) ????
208f139e 663 // mandatory limits in non Bending to avoid NaN values of parameters
664 gMinuit->mnparm(0, "X", trackParam->GetNonBendingCoor(), 0.03, -500.0, 500.0, status);
665 gMinuit->mnparm(1, "NonBenS", trackParam->GetNonBendingSlope(), 0.001, -0.5, 0.5, status);
666 // mandatory limits in Bending to avoid NaN values of parameters
667 gMinuit->mnparm(2, "Y", trackParam->GetBendingCoor(), 0.10, -500.0, 500.0, status);
668 gMinuit->mnparm(3, "BenS", trackParam->GetBendingSlope(), 0.001, -0.5, 0.5, status);
669 gMinuit->mnparm(4, "InvBenP", trackParam->GetInverseBendingMomentum(), 0.003, -0.4, 0.4, status);
670
de2cd600 671 // minimization
208f139e 672 gMinuit->mnexcm("MIGRAD", arg, 0, status);
673
674 // Calculate the covariance matrix more accurately if required
675 if (calcCov) gMinuit->mnexcm("HESSE", arg, 0, status);
8cde4af5 676
de2cd600 677 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
208f139e 678 gMinuit->GetParameter(0, x, errorParam);
679 trackParam->SetNonBendingCoor(x);
680 gMinuit->GetParameter(1, nonBenC, errorParam);
de2cd600 681 trackParam->SetNonBendingSlope(nonBenC);
208f139e 682 gMinuit->GetParameter(2, y, errorParam);
683 trackParam->SetBendingCoor(y);
684 gMinuit->GetParameter(3, benC, errorParam);
685 trackParam->SetBendingSlope(benC);
686 gMinuit->GetParameter(4, invBenP, errorParam);
687 trackParam->SetInverseBendingMomentum(invBenP);
688
de2cd600 689 // global result of the fit
208f139e 690 gMinuit->mnstat(fitFMin, fedm, errdef, npari, nparx, covStatus);
691 track->SetFitFMin(fitFMin);
692
693 // Get the covariance matrix if required
694 if (calcCov) {
695 // Covariance matrix according to HESSE status
696 // If problem then keep only the diagonal terms (variances)
697 Double_t matrix[5][5];
698 gMinuit->mnemat(&matrix[0][0],5);
699 if (covStatus == 3) trackParam->SetCovariances(matrix);
700 else trackParam->SetVariances(matrix);
701 } else *(trackParam->GetCovariances()) = 0;
702
de2cd600 703}
704
705 //__________________________________________________________________________
208f139e 706void TrackChi2(Int_t & /*NParam*/, Double_t * /*Gradient*/, Double_t &Chi2, Double_t *Param, Int_t /*Flag*/)
de2cd600 707{
2457f726 708 /// Return the "Chi2" to be minimized with Minuit for track fitting,
709 /// with "NParam" parameters
710 /// and their current values in array pointed to by "Param".
711 /// Assumes that the track hits are sorted according to increasing Z.
712 /// Track parameters at each TrackHit are updated accordingly.
713 /// Multiple Coulomb scattering is not taken into account
208f139e 714
715 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
716// AliMUONTrack *trackBeingFitted = (AliMUONTrack*) AliMUONTrackReconstructor::Fitter()->GetObjectFit();
de2cd600 717 AliMUONTrackParam param1;
2457f726 718 AliMUONTrackParam* trackParamAtHit;
719 AliMUONHitForRec* hitForRec;
de2cd600 720 Chi2 = 0.0; // initialize Chi2
208f139e 721 Double_t dX, dY;
722
de2cd600 723 // copy of track parameters to be fitted
208f139e 724 param1 = *((AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->First()));
725 param1.SetNonBendingCoor(Param[0]);
726 param1.SetNonBendingSlope(Param[1]);
727 param1.SetBendingCoor(Param[2]);
728 param1.SetBendingSlope(Param[3]);
729 param1.SetInverseBendingMomentum(Param[4]);
730
731 // Take the vertex into account in the fit if required
732 if (trackBeingFitted->GetFitWithVertex()) {
733 AliMUONTrackParam paramAtVertex(param1);
734 AliMUONTrackExtrap::ExtrapToZ(&paramAtVertex, 0.);
735 AliMUONHitForRec *vertex = trackBeingFitted->GetVertex();
736 if (!vertex) {
737 cout<<"Error in TrackChi2: Want to use the vertex in tracking but it has not been created!!"<<endl;
738 exit(-1);
739 }
740 dX = vertex->GetNonBendingCoor() - paramAtVertex.GetNonBendingCoor();
741 dY = vertex->GetBendingCoor() - paramAtVertex.GetBendingCoor();
742 Chi2 += dX * dX / vertex->GetNonBendingReso2() + dY * dY / vertex->GetBendingReso2();
de2cd600 743 }
208f139e 744
de2cd600 745 // Follow track through all planes of track hits
2457f726 746 trackParamAtHit = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->First());
747 while (trackParamAtHit) {
748 hitForRec = trackParamAtHit->GetHitForRecPtr();
749 // extrapolation to the plane of the hitForRec attached to the current trackParamAtHit
37827b29 750 AliMUONTrackExtrap::ExtrapToZ(&param1, hitForRec->GetZ());
de2cd600 751 // update track parameters of the current hit
2457f726 752 trackParamAtHit->SetTrackParam(param1);
de2cd600 753 // Increment Chi2
754 // done hit per hit, with hit resolution,
755 // and not with point and angle like in "reco_muon.F" !!!!
208f139e 756 dX = hitForRec->GetNonBendingCoor() - param1.GetNonBendingCoor();
757 dY = hitForRec->GetBendingCoor() - param1.GetBendingCoor();
2457f726 758 Chi2 = Chi2 + dX * dX / hitForRec->GetNonBendingReso2() + dY * dY / hitForRec->GetBendingReso2();
759 trackParamAtHit = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->After(trackParamAtHit));
de2cd600 760 }
761}
762
763 //__________________________________________________________________________
208f139e 764void TrackChi2MCS(Int_t & /*NParam*/, Double_t * /*Gradient*/, Double_t &Chi2, Double_t *Param, Int_t /*Flag*/)
de2cd600 765{
2457f726 766 /// Return the "Chi2" to be minimized with Minuit for track fitting,
767 /// with "NParam" parameters
768 /// and their current values in array pointed to by "Param".
769 /// Assumes that the track hits are sorted according to increasing Z.
770 /// Track parameters at each TrackHit are updated accordingly.
771 /// Multiple Coulomb scattering is taken into account with covariance matrix.
208f139e 772
773 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) gMinuit->GetObjectFit();
774// AliMUONTrack *trackBeingFitted = (AliMUONTrack*) AliMUONTrackReconstructor::Fitter()->GetObjectFit();
de2cd600 775 AliMUONTrackParam param1;
2457f726 776 AliMUONTrackParam* trackParamAtHit;
777 AliMUONHitForRec* hitForRec;
de2cd600 778 Chi2 = 0.0; // initialize Chi2
de2cd600 779 Int_t chCurrent, chPrev = 0, hitNumber, hitNumber1, hitNumber2, hitNumber3;
780 Double_t z1, z2, z3;
2457f726 781 AliMUONTrackParam *trackParamAtHit1, *trackParamAtHit2, *trackParamAtHit3;
782 AliMUONHitForRec *hitForRec1, *hitForRec2;
de2cd600 783 Double_t hbc1, hbc2, pbc1, pbc2;
784 Double_t hnbc1, hnbc2, pnbc1, pnbc2;
785 Int_t numberOfHit = trackBeingFitted->GetNTrackHits();
786 TMatrixD *covBending = new TMatrixD(numberOfHit, numberOfHit);
787 TMatrixD *covNonBending = new TMatrixD(numberOfHit, numberOfHit);
788 Double_t *msa2 = new Double_t[numberOfHit];
208f139e 789
790 // copy of track parameters to be fitted
791 param1 = *((AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->First()));
792 param1.SetNonBendingCoor(Param[0]);
793 param1.SetNonBendingSlope(Param[1]);
794 param1.SetBendingCoor(Param[2]);
795 param1.SetBendingSlope(Param[3]);
796 param1.SetInverseBendingMomentum(Param[4]);
797
798 // Take the vertex into account in the fit if required
799 if (trackBeingFitted->GetFitWithVertex()) {
800 AliMUONTrackParam paramAtVertex(param1);
801 AliMUONTrackExtrap::ExtrapToZ(&paramAtVertex, 0.);
802 AliMUONHitForRec *vertex = trackBeingFitted->GetVertex();
803 if (!vertex) {
804 cout<<"Error in TrackChi2MCS: Want to use the vertex in tracking but it has not been created!!"<<endl;
805 exit(-1);
806 }
807 Double_t dX = vertex->GetNonBendingCoor() - paramAtVertex.GetNonBendingCoor();
808 Double_t dY = vertex->GetBendingCoor() - paramAtVertex.GetBendingCoor();
809 Chi2 += dX * dX / vertex->GetNonBendingReso2() + dY * dY / vertex->GetBendingReso2();
810 }
811
812 // Predicted coordinates and multiple scattering angles are first calculated
de2cd600 813 for (hitNumber = 0; hitNumber < numberOfHit; hitNumber++) {
2457f726 814 trackParamAtHit = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber));
815 hitForRec = trackParamAtHit->GetHitForRecPtr();
816 // extrapolation to the plane of the hitForRec attached to the current trackParamAtHit
37827b29 817 AliMUONTrackExtrap::ExtrapToZ(&param1, hitForRec->GetZ());
de2cd600 818 // update track parameters of the current hit
2457f726 819 trackParamAtHit->SetTrackParam(param1);
de2cd600 820 // square of multiple scattering angle at current hit, with one chamber
821 msa2[hitNumber] = MultipleScatteringAngle2(&param1);
822 // correction for eventual missing hits or multiple hits in a chamber,
823 // according to the number of chambers
824 // between the current hit and the previous one
2457f726 825 chCurrent = hitForRec->GetChamberNumber();
de2cd600 826 if (hitNumber > 0) msa2[hitNumber] = msa2[hitNumber] * (chCurrent - chPrev);
827 chPrev = chCurrent;
828 }
829
830 // Calculates the covariance matrix
831 for (hitNumber1 = 0; hitNumber1 < numberOfHit; hitNumber1++) {
2457f726 832 trackParamAtHit1 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber1));
833 hitForRec1 = trackParamAtHit1->GetHitForRecPtr();
834 z1 = hitForRec1->GetZ();
de2cd600 835 for (hitNumber2 = hitNumber1; hitNumber2 < numberOfHit; hitNumber2++) {
2457f726 836 trackParamAtHit2 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber2));
837 z2 = trackParamAtHit2->GetHitForRecPtr()->GetZ();
de2cd600 838 // initialization to 0 (diagonal plus upper triangular part)
839 (*covBending)(hitNumber2, hitNumber1) = 0.0;
840 // contribution from multiple scattering in bending plane:
841 // loop over upstream hits
842 for (hitNumber3 = 0; hitNumber3 < hitNumber1; hitNumber3++) {
2457f726 843 trackParamAtHit3 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber3));
844 z3 = trackParamAtHit3->GetHitForRecPtr()->GetZ();
de2cd600 845 (*covBending)(hitNumber2, hitNumber1) = (*covBending)(hitNumber2, hitNumber1) + ((z1 - z3) * (z2 - z3) * msa2[hitNumber3]);
846 }
847 // equal contribution from multiple scattering in non bending plane
848 (*covNonBending)(hitNumber2, hitNumber1) = (*covBending)(hitNumber2, hitNumber1);
849 if (hitNumber1 == hitNumber2) {
850 // Diagonal elements: add contribution from position measurements
851 // in bending plane
2457f726 852 (*covBending)(hitNumber2, hitNumber1) = (*covBending)(hitNumber2, hitNumber1) + hitForRec1->GetBendingReso2();
de2cd600 853 // and in non bending plane
2457f726 854 (*covNonBending)(hitNumber2, hitNumber1) = (*covNonBending)(hitNumber2, hitNumber1) + hitForRec1->GetNonBendingReso2();
de2cd600 855 } else {
856 // Non diagonal elements: symmetrization
857 // for bending plane
858 (*covBending)(hitNumber1, hitNumber2) = (*covBending)(hitNumber2, hitNumber1);
859 // and non bending plane
860 (*covNonBending)(hitNumber1, hitNumber2) = (*covNonBending)(hitNumber2, hitNumber1);
861 }
862 } // for (hitNumber2 = hitNumber1;...
863 } // for (hitNumber1 = 0;...
864
865 // Inversion of covariance matrices
de2cd600 866 Int_t ifailBending;
208f139e 867 gMinuit->mnvert(&((*covBending)(0,0)), numberOfHit, numberOfHit, numberOfHit, ifailBending);
de2cd600 868 Int_t ifailNonBending;
208f139e 869 gMinuit->mnvert(&((*covNonBending)(0,0)), numberOfHit, numberOfHit, numberOfHit, ifailNonBending);
de2cd600 870
871 // It would be worth trying to calculate the inverse of the covariance matrix
872 // only once per fit, since it cannot change much in principle,
873 // and it would save a lot of computing time !!!!
874
875 // Calculates Chi2
876 if ((ifailBending == 0) && (ifailNonBending == 0)) {
877 // with Multiple Scattering if inversion correct
878 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
2457f726 879 trackParamAtHit1 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber1));
880 hitForRec1 = trackParamAtHit1->GetHitForRecPtr();
881 hbc1 = hitForRec1->GetBendingCoor();
882 pbc1 = trackParamAtHit1->GetBendingCoor();
883 hnbc1 = hitForRec1->GetNonBendingCoor();
884 pnbc1 = trackParamAtHit1->GetNonBendingCoor();
de2cd600 885 for (hitNumber2 = 0; hitNumber2 < numberOfHit; hitNumber2++) {
2457f726 886 trackParamAtHit2 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber2));
887 hitForRec2 = trackParamAtHit2->GetHitForRecPtr();
888 hbc2 = hitForRec2->GetBendingCoor();
889 pbc2 = trackParamAtHit2->GetBendingCoor();
890 hnbc2 = hitForRec2->GetNonBendingCoor();
891 pnbc2 = trackParamAtHit2->GetNonBendingCoor();
de2cd600 892 Chi2 += ((*covBending)(hitNumber2, hitNumber1) * (hbc1 - pbc1) * (hbc2 - pbc2)) +
893 ((*covNonBending)(hitNumber2, hitNumber1) * (hnbc1 - pnbc1) * (hnbc2 - pnbc2));
894 }
895 }
896 } else {
897 // without Multiple Scattering if inversion impossible
898 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
2457f726 899 trackParamAtHit1 = (AliMUONTrackParam*) (trackBeingFitted->GetTrackParamAtHit()->UncheckedAt(hitNumber1));
900 hitForRec1 = trackParamAtHit1->GetHitForRecPtr();
901 hbc1 = hitForRec1->GetBendingCoor();
902 pbc1 = trackParamAtHit1->GetBendingCoor();
903 hnbc1 = hitForRec1->GetNonBendingCoor();
904 pnbc1 = trackParamAtHit1->GetNonBendingCoor();
905 Chi2 += ((hbc1 - pbc1) * (hbc1 - pbc1) / hitForRec1->GetBendingReso2()) +
906 ((hnbc1 - pnbc1) * (hnbc1 - pnbc1) / hitForRec1->GetNonBendingReso2());
de2cd600 907 }
908 }
909
910 delete covBending;
911 delete covNonBending;
912 delete [] msa2;
913}
914
208f139e 915 //__________________________________________________________________________
de2cd600 916Double_t MultipleScatteringAngle2(AliMUONTrackParam *param)
917{
2457f726 918 /// Returns square of multiple Coulomb scattering angle
919 /// from TrackParamAtHit pointed to by "param"
de2cd600 920 Double_t slopeBending, slopeNonBending, radiationLength, inverseBendingMomentum2, inverseTotalMomentum2;
921 Double_t varMultipleScatteringAngle;
de2cd600 922 slopeBending = param->GetBendingSlope();
923 slopeNonBending = param->GetNonBendingSlope();
924 // thickness in radiation length for the current track,
925 // taking local angle into account
208f139e 926 radiationLength = AliMUONConstants::ChamberThicknessInX0() *
de2cd600 927 TMath::Sqrt(1.0 + slopeBending*slopeBending + slopeNonBending*slopeNonBending);
928 inverseBendingMomentum2 = param->GetInverseBendingMomentum() * param->GetInverseBendingMomentum();
929 inverseTotalMomentum2 = inverseBendingMomentum2 * (1.0 + slopeBending * slopeBending) /
930 (1.0 + slopeBending *slopeBending + slopeNonBending * slopeNonBending);
931 varMultipleScatteringAngle = 0.0136 * (1.0 + 0.038 * TMath::Log(radiationLength));
932 // The velocity is assumed to be 1 !!!!
933 varMultipleScatteringAngle = inverseTotalMomentum2 * radiationLength * varMultipleScatteringAngle * varMultipleScatteringAngle;
934 return varMultipleScatteringAngle;
d837040f 935}
936
b8dc484b 937 //__________________________________________________________________________
71a2d3aa 938void AliMUONTrackReconstructor::FillMUONTrack(void)
b8dc484b 939{
208f139e 940 /// Fill fHitForRecAtHit of AliMUONTrack's
b8dc484b 941 AliMUONTrack *track;
de2cd600 942 AliMUONTrackParam *trackParamAtHit;
b8dc484b 943 track = (AliMUONTrack*) fRecTracksPtr->First();
944 while (track) {
de2cd600 945 trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->First());
946 while (trackParamAtHit) {
947 track->AddHitForRecAtHit(trackParamAtHit->GetHitForRecPtr());
948 trackParamAtHit = (AliMUONTrackParam*) (track->GetTrackParamAtHit()->After(trackParamAtHit));
949 }
b8dc484b 950 track = (AliMUONTrack*) fRecTracksPtr->After(track);
de2cd600 951 }
b8dc484b 952 return;
953}
954
8429a5e4 955 //__________________________________________________________________________
29f1b13a 956void AliMUONTrackReconstructor::EventDump(void)
04b5ea16 957{
2457f726 958 /// Dump reconstructed event (track parameters at vertex and at first hit),
959 /// and the particle parameters
04b5ea16 960 AliMUONTrack *track;
8cde4af5 961 AliMUONTrackParam trackParam, *trackParam1;
04b5ea16 962 Double_t bendingSlope, nonBendingSlope, pYZ;
963 Double_t pX, pY, pZ, x, y, z, c;
5e671e06 964 Int_t trackIndex, nTrackHits;
04b5ea16 965
b840996b 966 AliDebug(1,"****** enter EventDump ******");
967 AliDebug(1, Form("Number of Reconstructed tracks : %d", fNRecTracks));
968
04b5ea16 969 fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
970 // Loop over reconstructed tracks
971 for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
b840996b 972 AliDebug(1, Form("track number: %d", trackIndex));
04b5ea16 973 // function for each track for modularity ????
974 track = (AliMUONTrack*) ((*fRecTracksPtr)[trackIndex]);
975 nTrackHits = track->GetNTrackHits();
b840996b 976 AliDebug(1, Form("Number of track hits: %d ", nTrackHits));
04b5ea16 977 // track parameters at Vertex
8cde4af5 978 trackParam = (*((AliMUONTrackParam*) track->GetTrackParamAtHit()->First()));
979 AliMUONTrackExtrap::ExtrapToVertex(&trackParam,0.,0.,0.);
980 x = trackParam.GetNonBendingCoor();
981 y = trackParam.GetBendingCoor();
982 z = trackParam.GetZ();
983 bendingSlope = trackParam.GetBendingSlope();
984 nonBendingSlope = trackParam.GetNonBendingSlope();
985 pYZ = 1/TMath::Abs(trackParam.GetInverseBendingMomentum());
04b5ea16 986 pZ = pYZ/TMath::Sqrt(1+bendingSlope*bendingSlope);
987 pX = pZ * nonBendingSlope;
988 pY = pZ * bendingSlope;
8cde4af5 989 c = TMath::Sign(1.0, trackParam.GetInverseBendingMomentum());
b840996b 990 AliDebug(1, Form("Track parameters at Vertex z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
991 z, x, y, pX, pY, pZ, c));
04b5ea16 992
993 // track parameters at first hit
de2cd600 994 trackParam1 = (AliMUONTrackParam*) track->GetTrackParamAtHit()->First();
04b5ea16 995 x = trackParam1->GetNonBendingCoor();
996 y = trackParam1->GetBendingCoor();
997 z = trackParam1->GetZ();
998 bendingSlope = trackParam1->GetBendingSlope();
999 nonBendingSlope = trackParam1->GetNonBendingSlope();
1000 pYZ = 1/TMath::Abs(trackParam1->GetInverseBendingMomentum());
1001 pZ = pYZ/TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
1002 pX = pZ * nonBendingSlope;
1003 pY = pZ * bendingSlope;
1004 c = TMath::Sign(1.0, trackParam1->GetInverseBendingMomentum());
b840996b 1005 AliDebug(1, Form("track parameters at z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1006 z, x, y, pX, pY, pZ, c));
04b5ea16 1007 }
8f373020 1008 // informations about generated particles NO !!!!!!!!
04b5ea16 1009
88cb7938 1010// for (Int_t iPart = 0; iPart < np; iPart++) {
1011// p = gAlice->Particle(iPart);
1012// printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
1013// iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());
1014// }
a9e2aefa 1015 return;
1016}
1017
276c44b7 1018