1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////
20 // MUON track reconstructor using the kalman method
22 // This class contains as data:
23 // * the parameters for the track reconstruction
25 // It contains as methods, among others:
26 // * MakeTracks to build the tracks
28 ////////////////////////////////////
31 #include <Riostream.h>
32 #include <TDirectory.h>
36 #include "AliMUONVTrackReconstructor.h"
37 #include "AliMUONTrackReconstructorK.h"
38 #include "AliMUONData.h"
39 #include "AliMUONConstants.h"
40 #include "AliMUONHitForRec.h"
41 #include "AliMUONRawCluster.h"
42 #include "AliMUONSegment.h"
43 #include "AliMUONTrackK.h"
46 ClassImp(AliMUONTrackReconstructorK) // Class implementation in ROOT context
48 //__________________________________________________________________________
49 AliMUONTrackReconstructorK::AliMUONTrackReconstructorK(AliMUONData* data, const Option_t* TrackMethod)
50 : AliMUONVTrackReconstructor(data),
51 fTrackMethod(2), //tracking method (2-Kalman 3-Combination-Kalman/Clustering)
54 /// Constructor for class AliMUONTrackReconstructorK
56 if (strstr(TrackMethod,"Kalman")) {
57 cout << " *** Tracking with the Kalman filter *** " << endl;
59 } else if (strstr(TrackMethod,"Combi")) {
60 cout << " *** Combined cluster / track finder ***" << endl;
62 } else AliFatal(Form("Tracking method %s not available",TrackMethod));
64 // Memory allocation for the TClonesArray of reconstructed tracks
65 fRecTracksPtr = new TClonesArray("AliMUONTrackK", 10);
68 //__________________________________________________________________________
69 AliMUONTrackReconstructorK::~AliMUONTrackReconstructorK(void)
71 /// Destructor for class AliMUONTrackReconstructorK
75 //__________________________________________________________________________
76 void AliMUONTrackReconstructorK::AddHitsForRecFromRawClusters()
78 /// To add to the list of hits for reconstruction all the raw clusters
80 AliMUONHitForRec *hitForRec;
81 AliMUONRawCluster *clus;
82 Int_t iclus, nclus, nTRentries;
83 TClonesArray *rawclusters;
84 AliDebug(1,"Enter AddHitsForRecFromRawClusters");
86 treeR = fMUONData->TreeR();
88 AliError("TreeR must be loaded");
92 if (fTrackMethod != 3) { //AZ
93 nTRentries = Int_t(treeR->GetEntries());
95 if (!(fMUONData->IsRawClusterBranchesInTree())) {
96 AliError(Form("RawCluster information is not avalaible, nTRentries = %d not equal to 1",nTRentries));
100 fMUONData->SetTreeAddress("RC"); //AZ
101 fMUONData->GetRawClusters(); // only one entry
104 // Loop over tracking chambers
105 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
106 // number of HitsForRec to 0 for the chamber
107 fNHitsForRecPerChamber[ch] = 0;
108 // index of first HitForRec for the chamber
109 if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
110 else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
111 rawclusters =fMUONData->RawClusters(ch);
112 nclus = (Int_t) (rawclusters->GetEntries());
113 // Loop over (cathode correlated) raw clusters
114 for (iclus = 0; iclus < nclus; iclus++) {
115 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
116 // new AliMUONHitForRec from raw cluster
117 // and increment number of AliMUONHitForRec's (total and in chamber)
118 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
120 (fNHitsForRecPerChamber[ch])++;
121 // more information into HitForRec
122 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
123 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
124 // original raw cluster
125 hitForRec->SetChamberNumber(ch);
126 hitForRec->SetHitNumber(iclus);
127 // Z coordinate of the raw cluster (cm)
128 hitForRec->SetZ(clus->GetZ(0));
131 cout << "Chamber " << ch <<
132 " raw cluster " << iclus << " : " << endl;
134 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
135 hitForRec->Print("full");
137 } // end of cluster loop
138 } // end of chamber loop
139 SortHitsForRecWithIncreasingChamber();
141 AliDebug(1,"End of AddHitsForRecFromRawClusters");
142 if (AliLog::GetGlobalDebugLevel() > 0) {
143 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
144 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
145 AliDebug(1, Form("Chamber(0...): %d",ch));
146 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
147 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
148 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
149 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
151 AliDebug(1, Form("HitForRec index(0...): %d",hit));
152 ((*fHitsForRecPtr)[hit])->Dump();
160 //__________________________________________________________________________
161 void AliMUONTrackReconstructorK::MakeSegments(void)
163 /// To make the list of segments in all stations,
164 /// from the list of hits to be reconstructed
165 AliDebug(1,"Enter MakeSegments");
166 //AZ ResetSegments();
167 // Loop over stations
168 for (Int_t st = 3; st < AliMUONConstants::NTrackingCh()/2; st++) MakeSegmentsPerStation(st);
171 cout << "end of MakeSegments" << endl;
172 for (Int_t st = 0; st < AliMUONConstants::NTrackingCh()/2; st++)
174 cout << "station " << st
175 << " has " << fNSegments[st] << " segments:"
177 for (Int_t seg = 0; seg < fNSegments[st]; seg++)
179 ((*fSegmentsPtr[st])[seg])->Print();
186 //__________________________________________________________________________
187 void AliMUONTrackReconstructorK::MakeTracks(void)
189 /// To make the tracks from the list of segments and points in all stations
190 AliDebug(1,"Enter MakeTracks");
191 // The order may be important for the following Reset's
193 MakeTrackCandidates();
194 if (fRecTracksPtr->GetEntriesFast() == 0) return;
195 // Follow tracks in stations(1..) 3, 2 and 1
197 // Remove double tracks
198 RemoveDoubleTracks();
199 // Propagate tracks to the vertex thru absorber
201 // Fill AliMUONTrack data members
205 //__________________________________________________________________________
206 void AliMUONTrackReconstructorK::MakeTrackCandidates(void)
208 /// To make initial tracks for Kalman filter from the list of segments
210 AliMUONSegment *segment;
211 AliMUONTrackK *trackK;
213 AliDebug(1,"Enter MakeTrackCandidatesK");
215 AliMUONTrackK a(this, fHitsForRecPtr);
216 // Loop over stations(1...) 5 and 4
217 for (istat=4; istat>=3; istat--) {
218 // Loop over segments in the station
219 for (iseg=0; iseg<fNSegments[istat]; iseg++) {
220 // Transform segments to tracks and evaluate covariance matrix
221 segment = (AliMUONSegment*) ((*fSegmentsPtr[istat])[iseg]);
222 trackK = new ((*fRecTracksPtr)[fNRecTracks++]) AliMUONTrackK(segment);
223 } // for (iseg=0;...)
224 } // for (istat=4;...)
228 //__________________________________________________________________________
229 void AliMUONTrackReconstructorK::FollowTracks(void)
231 /// Follow tracks using Kalman filter
233 Int_t icand, ichamBeg = 0, ichamEnd, chamBits;
234 Double_t zDipole1, zDipole2;
235 AliMUONTrackK *trackK;
236 AliMUONHitForRec *hit;
237 AliMUONRawCluster *clus;
238 TClonesArray *rawclusters;
239 clus = 0; rawclusters = 0;
241 zDipole1 = fSimpleBPosition + fSimpleBLength/2;
242 zDipole2 = zDipole1 - fSimpleBLength;
245 trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[0]);
247 if (trackK->DebugLevel() > 0) {
248 for (Int_t i1=0; i1<fNHitsForRec; i1++) {
249 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[i1]);
250 printf(" Hit # %d %10.4f %10.4f %10.4f",
251 hit->GetChamberNumber(), hit->GetBendingCoor(),
252 hit->GetNonBendingCoor(), hit->GetZ());
255 rawclusters = fMUONData->RawClusters(hit->GetChamberNumber());
256 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->
258 printf(" %d", clus->GetTrack(1));
259 if (clus->GetTrack(2) != -1) printf(" %d \n", clus->GetTrack(2));
263 } // if (trackK->DebugLevel() > 0)
267 nSeeds = fNRecTracks; // starting number of seeds
268 // Loop over track candidates
269 while (icand < fNRecTracks-1) {
271 if (trackK->DebugLevel()>0) cout << " *** Kalman track candidate No. " << icand << endl;
272 trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
273 if (trackK->GetRecover() < 0) continue; // failed track
275 // Discard candidate which will produce the double track
278 ok = CheckCandidate(icand,nSeeds);
280 trackK->SetRecover(-1); // mark candidate to be removed
287 if (trackK->GetRecover() == 0)
288 hit = (AliMUONHitForRec*) trackK->GetTrackHits()->Last(); // last hit
290 hit = trackK->GetHitLastOk(); // hit where track stopped
292 if (hit) ichamBeg = hit->GetChamberNumber();
294 // Check propagation direction
295 if (!hit) { ichamBeg = ichamEnd; AliFatal(" ??? "); }
296 else if (trackK->GetTrackDir() < 0) {
297 ichamEnd = 9; // forward propagation
298 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
301 ichamEnd = 6; // backward propagation
302 // Change weight matrix and zero fChi2 for backpropagation
304 trackK->SetTrackDir(1);
305 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
310 if (trackK->GetBPFlag()) {
312 ichamEnd = 6; // backward propagation
313 // Change weight matrix and zero fChi2 for backpropagation
315 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
322 trackK->SetTrackDir(1);
323 trackK->SetBPFlag(kFALSE);
324 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
326 if (!ok) { trackK->SetRecover(-1); continue; } // mark candidate to be removed
329 if (trackK->GetRecover() >= 0) {
330 ok = trackK->Smooth();
331 if (!ok) trackK->SetRecover(-1); // mark candidate to be removed
334 // Majority 3 of 4 in first 2 stations
337 Double_t chi2max = 0;
338 for (Int_t i=0; i<trackK->GetNTrackHits(); i++) {
339 hit = (AliMUONHitForRec*) (*trackK->GetTrackHits())[i];
340 chamBits |= BIT(hit->GetChamberNumber());
341 if (trackK->GetChi2PerPoint(i) > chi2max) chi2max = trackK->GetChi2PerPoint(i);
343 if (!((chamBits&3)==3 || (chamBits>>2&3)==3) && chi2max > 25) {
345 trackK->SetRecover(-1); //mark candidate to be removed
348 if (ok) trackK->SetTrackQuality(0); // compute "track quality"
351 for (Int_t i=0; i<fNRecTracks; i++) {
352 trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
353 if (trackK->GetRecover() < 0) fRecTracksPtr->RemoveAt(i);
356 // Compress TClonesArray
357 fRecTracksPtr->Compress();
358 fNRecTracks = fRecTracksPtr->GetEntriesFast();
362 //__________________________________________________________________________
363 Bool_t AliMUONTrackReconstructorK::CheckCandidate(Int_t icand, Int_t nSeeds) const
365 /// Discards track candidate if it will produce the double track (having
366 /// the same seed segment hits as hits of a good track found before)
367 AliMUONTrackK *track1, *track2;
368 AliMUONHitForRec *hit1, *hit2, *hit;
370 track1 = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
371 hit1 = (AliMUONHitForRec*) (*track1->GetTrackHits())[0]; // 1'st hit
372 hit2 = (AliMUONHitForRec*) (*track1->GetTrackHits())[1]; // 2'nd hit
374 for (Int_t i=0; i<icand; i++) {
375 track2 = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
376 //if (track2->GetRecover() < 0) continue;
377 if (track2->GetRecover() < 0 && icand >= nSeeds) continue;
379 if (track1->GetStartSegment() == track2->GetStartSegment()) {
383 for (Int_t j=0; j<track2->GetNTrackHits(); j++) {
384 hit = (AliMUONHitForRec*) (*track2->GetTrackHits())[j];
385 if (hit == hit1 || hit == hit2) {
387 if (nSame == 2) return kFALSE;
395 //__________________________________________________________________________
396 void AliMUONTrackReconstructorK::RemoveDoubleTracks(void)
398 /// Removes double tracks (sharing more than half of their hits).
399 /// Keeps the track with higher quality
400 AliMUONTrackK *track1, *track2, *trackToKill;
402 // Sort tracks according to their quality
403 fRecTracksPtr->Sort();
405 // Loop over first track of the pair
406 track1 = (AliMUONTrackK*) fRecTracksPtr->First();
407 Int_t debug = track1->DebugLevel();
409 // Loop over second track of the pair
410 track2 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
412 // Check whether or not to keep track2
413 if (!track2->KeepTrack(track1)) {
414 if (debug >= 0) cout << " Killed track: " << 1/(*track2->GetTrackParameters())(4,0) <<
415 " " << track2->GetTrackQuality() << endl;
416 trackToKill = track2;
417 track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
419 fRecTracksPtr->Compress();
420 } else track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
422 track1 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
425 fNRecTracks = fRecTracksPtr->GetEntriesFast();
426 if (debug >= 0) cout << " Number of Kalman tracks: " << fNRecTracks << endl;
429 //__________________________________________________________________________
430 void AliMUONTrackReconstructorK::GoToVertex(void)
432 /// Propagates track to the vertex thru absorber
433 /// (using Branson correction for now)
436 for (Int_t i=0; i<fNRecTracks; i++) {
437 //((AliMUONTrackK*)(*fRecTracksPtr)[i])->Branson();
438 ((AliMUONTrackK*)(*fRecTracksPtr)[i])->SetTrackQuality(1); // compute Chi2
439 //((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToZ(zVertex); // w/out absorber
440 ((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToVertex(1); // with absorber
444 //__________________________________________________________________________
445 void AliMUONTrackReconstructorK::FillMUONTrack()
447 // Set track parameters at hits for Kalman track. Fill fTrackParamAtHit of AliMUONTrack's
448 AliMUONTrackK *track;
449 track = (AliMUONTrackK*) fRecTracksPtr->First();
451 track->FillMUONTrack();
452 track = (AliMUONTrackK*) fRecTracksPtr->After(track);
457 //__________________________________________________________________________
458 void AliMUONTrackReconstructorK::EventDump(void)
460 /// Dump reconstructed event (track parameters at vertex and at first hit),
461 /// and the particle parameters
462 AliDebug(1,"****** enter EventDump ******");
463 AliDebug(1, Form("Number of Reconstructed tracks : %d", fNRecTracks));
465 AliWarning("AliMUONTrackReconstructorK::EventDump: not implemented");
467 // informations about generated particles NO !!!!!!!!
469 // for (Int_t iPart = 0; iPart < np; iPart++) {
470 // p = gAlice->Particle(iPart);
471 // printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
472 // iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());