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 // Reconstructed track
26 ///////////////////////////////////////////////////
28 #include <stdlib.h> // for exit()
29 #include <Riostream.h>
32 #include "AliMUONTrack.h"
34 #include "AliMUONTrackParam.h"
35 #include "AliMUONHitForRec.h"
36 #include "AliMUONConstants.h"
37 #include "AliMUONTrackExtrap.h"
44 ClassImp(AliMUONTrack) // Class implementation in ROOT context
47 const Double_t AliMUONTrack::fgkMaxTrackingDistanceBending = 2.;
48 const Double_t AliMUONTrack::fgkMaxTrackingDistanceNonBending = 2.;
50 //__________________________________________________________________________
51 AliMUONTrack::AliMUONTrack()
53 fTrackParamAtVertex(),
54 fTrackParamAtHit(0x0),
58 fFitWithVertex(kFALSE),
61 fMatchTrigger(kFALSE),
62 fChi2MatchTrigger(0.),
65 /// Default constructor
68 //__________________________________________________________________________
69 AliMUONTrack::AliMUONTrack(AliMUONHitForRec* hitForRec1, AliMUONHitForRec* hitForRec2)
71 fTrackParamAtVertex(),
72 fTrackParamAtHit(0x0),
76 fFitWithVertex(kFALSE),
79 fMatchTrigger(kFALSE),
80 fChi2MatchTrigger(0.),
83 /// Constructor from thw hitForRec's
85 fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);
86 fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10);
88 if (!hitForRec1) return; //AZ
90 // Add hits to the track
91 AddTrackParamAtHit(0,hitForRec1);
92 AddTrackParamAtHit(0,hitForRec2);
94 // sort TrackParamAtHit according to increasing -Z
95 fTrackParamAtHit->Sort();
97 // Set track parameters at first track hit
98 AliMUONTrackParam* trackParamAtFirstHit = (AliMUONTrackParam*) fTrackParamAtHit->First();
99 AliMUONHitForRec* firstHit = trackParamAtFirstHit->GetHitForRecPtr();
100 AliMUONHitForRec* lastHit = ((AliMUONTrackParam*) fTrackParamAtHit->Last())->GetHitForRecPtr();
102 Double_t z1 = firstHit->GetZ();
103 trackParamAtFirstHit->SetZ(z1);
104 Double_t dZ = z1 - lastHit->GetZ();
106 Double_t nonBendingCoor = firstHit->GetNonBendingCoor();
107 trackParamAtFirstHit->SetNonBendingCoor(nonBendingCoor);
108 trackParamAtFirstHit->SetNonBendingSlope((nonBendingCoor - lastHit->GetNonBendingCoor()) / dZ);
110 Double_t bendingCoor = firstHit->GetBendingCoor();
111 trackParamAtFirstHit->SetBendingCoor(bendingCoor);
112 Double_t bendingSlope = (bendingCoor - lastHit->GetBendingCoor()) / dZ;
113 trackParamAtFirstHit->SetBendingSlope(bendingSlope);
114 // Inverse bending momentum
115 Double_t bendingImpact = bendingCoor - z1 * bendingSlope;
116 Double_t inverseBendingMomentum = 1. / AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpact);
117 trackParamAtFirstHit->SetInverseBendingMomentum(inverseBendingMomentum);
119 // Evaluate covariances
120 TMatrixD *paramCov = trackParamAtFirstHit->GetCovariances();
123 (*paramCov)(0,0) = firstHit->GetNonBendingReso2();
124 (*paramCov)(0,1) = firstHit->GetNonBendingReso2() / dZ;
125 (*paramCov)(1,0) = (*paramCov)(0,1);
126 (*paramCov)(1,1) = ( firstHit->GetNonBendingReso2() + lastHit->GetNonBendingReso2() ) / dZ / dZ;
128 (*paramCov)(2,2) = firstHit->GetBendingReso2();
129 (*paramCov)(2,3) = firstHit->GetBendingReso2() / dZ;
130 (*paramCov)(3,2) = (*paramCov)(2,3);
131 (*paramCov)(3,3) = ( firstHit->GetBendingReso2() + lastHit->GetBendingReso2() ) / dZ / dZ;
132 // Inverse bending momentum (50% error)
133 (*paramCov)(4,4) = 0.5*inverseBendingMomentum * 0.5*inverseBendingMomentum;
137 //__________________________________________________________________________
138 AliMUONTrack::~AliMUONTrack()
141 if (fTrackParamAtHit) {
142 // delete the TClonesArray of pointers to TrackParam
143 delete fTrackParamAtHit;
144 fTrackParamAtHit = 0x0;
147 if (fHitForRecAtHit) {
148 // delete the TClonesArray of pointers to HitForRec
149 delete fHitForRecAtHit;
150 fHitForRecAtHit = 0x0;
154 // delete the vertex used during the tracking procedure
160 //__________________________________________________________________________
161 AliMUONTrack::AliMUONTrack (const AliMUONTrack& theMUONTrack)
162 : TObject(theMUONTrack),
163 fTrackParamAtVertex(theMUONTrack.fTrackParamAtVertex),
164 fTrackParamAtHit(0x0),
165 fHitForRecAtHit(0x0),
166 fNTrackHits(theMUONTrack.fNTrackHits),
167 fExtrapTrackParam(theMUONTrack.fExtrapTrackParam),
168 fFitWithVertex(theMUONTrack.fFitWithVertex),
170 fFitFMin(theMUONTrack.fFitFMin),
171 fMatchTrigger(theMUONTrack.fMatchTrigger),
172 fChi2MatchTrigger(theMUONTrack.fChi2MatchTrigger),
173 fTrackID(theMUONTrack.fTrackID)
178 // necessary to make a copy of the objects and not only the pointers in TClonesArray.
179 if (theMUONTrack.fTrackParamAtHit) {
180 maxIndex = (theMUONTrack.fTrackParamAtHit)->GetEntriesFast();
181 fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",maxIndex);
182 for (Int_t index = 0; index < maxIndex; index++) {
183 new ((*fTrackParamAtHit)[index]) AliMUONTrackParam(*(AliMUONTrackParam*)theMUONTrack.fTrackParamAtHit->At(index));
187 // necessary to make a copy of the objects and not only the pointers in TClonesArray.
188 if (theMUONTrack.fHitForRecAtHit) {
189 maxIndex = (theMUONTrack.fHitForRecAtHit)->GetEntriesFast();
190 fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",maxIndex);
191 for (Int_t index = 0; index < maxIndex; index++) {
192 new ((*fHitForRecAtHit)[index]) AliMUONHitForRec(*(AliMUONHitForRec*)theMUONTrack.fHitForRecAtHit->At(index));
196 // copy vertex used during the tracking procedure if any
197 if (theMUONTrack.fVertex) fVertex = new AliMUONHitForRec(*(theMUONTrack.fVertex));
201 //__________________________________________________________________________
202 AliMUONTrack & AliMUONTrack::operator=(const AliMUONTrack& theMUONTrack)
204 /// Asignment operator
205 // check assignement to self
206 if (this == &theMUONTrack)
209 // base class assignement
210 TObject::operator=(theMUONTrack);
212 fTrackParamAtVertex = theMUONTrack.fTrackParamAtVertex;
216 // necessary to make a copy of the objects and not only the pointers in TClonesArray.
217 if (theMUONTrack.fTrackParamAtHit) {
218 if (fTrackParamAtHit) fTrackParamAtHit->Clear();
219 else fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);
220 maxIndex = (theMUONTrack.fTrackParamAtHit)->GetEntriesFast();
221 for (Int_t index = 0; index < maxIndex; index++) {
222 new ((*fTrackParamAtHit)[fTrackParamAtHit->GetEntriesFast()])
223 AliMUONTrackParam(*(AliMUONTrackParam*)(theMUONTrack.fTrackParamAtHit)->At(index));
225 } else if (fTrackParamAtHit) {
226 delete fTrackParamAtHit;
227 fTrackParamAtHit = 0x0;
230 // necessary to make a copy of the objects and not only the pointers in TClonesArray.
231 if (theMUONTrack.fHitForRecAtHit) {
232 if (fHitForRecAtHit) fHitForRecAtHit->Clear();
233 else fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10);
234 maxIndex = (theMUONTrack.fHitForRecAtHit)->GetEntriesFast();
235 for (Int_t index = 0; index < maxIndex; index++) {
236 new ((*fHitForRecAtHit)[fHitForRecAtHit->GetEntriesFast()])
237 AliMUONHitForRec(*(AliMUONHitForRec*)(theMUONTrack.fHitForRecAtHit)->At(index));
239 } else if (fHitForRecAtHit) {
240 delete fHitForRecAtHit;
241 fHitForRecAtHit = 0x0;
244 // copy vertex used during the tracking procedure if any.
245 if (theMUONTrack.fVertex) {
246 if (fVertex) *fVertex = *(theMUONTrack.fVertex);
247 else fVertex = new AliMUONHitForRec(*(theMUONTrack.fVertex));
248 } else if (fVertex) {
253 fExtrapTrackParam = theMUONTrack.fExtrapTrackParam;
255 fNTrackHits = theMUONTrack.fNTrackHits;
256 fFitWithVertex = theMUONTrack.fFitWithVertex;
257 fFitFMin = theMUONTrack.fFitFMin;
258 fMatchTrigger = theMUONTrack.fMatchTrigger;
259 fChi2MatchTrigger = theMUONTrack.fChi2MatchTrigger;
260 fTrackID = theMUONTrack.fTrackID;
265 //__________________________________________________________________________
266 void AliMUONTrack::AddTrackParamAtHit(AliMUONTrackParam *trackParam, AliMUONHitForRec *hitForRec)
268 /// Add TrackParamAtHit if "trackParam" != NULL else create empty TrackParamAtHit
269 /// Update link to HitForRec if "hitForRec" != NULL
270 if (!fTrackParamAtHit) {
271 fTrackParamAtHit = new TClonesArray("AliMUONTrackParam",10);
274 AliMUONTrackParam* trackParamAtHit;
275 if (trackParam) trackParamAtHit = new ((*fTrackParamAtHit)[fNTrackHits]) AliMUONTrackParam(*trackParam);
276 else trackParamAtHit = new ((*fTrackParamAtHit)[fNTrackHits]) AliMUONTrackParam();
277 if (hitForRec) trackParamAtHit->SetHitForRecPtr(hitForRec);
281 //__________________________________________________________________________
282 void AliMUONTrack::AddHitForRecAtHit(const AliMUONHitForRec *hitForRec)
284 /// Add hitForRec to the array of hitForRec at hit
285 if (!fHitForRecAtHit)
286 fHitForRecAtHit = new TClonesArray("AliMUONHitForRec",10);
289 AliFatal("AliMUONTrack::AddHitForRecAtHit: hitForRec == NULL");
291 new ((*fHitForRecAtHit)[fHitForRecAtHit->GetEntriesFast()]) AliMUONHitForRec(*hitForRec);
294 //__________________________________________________________________________
295 void AliMUONTrack::SetVertex(AliMUONHitForRec* vertex)
297 /// Set the vertex used during the tracking procedure
298 if (!fVertex) fVertex = new AliMUONHitForRec(*vertex);
299 else *fVertex = *vertex;
302 //__________________________________________________________________________
303 Int_t AliMUONTrack::HitsInCommon(AliMUONTrack* track) const
305 /// Returns the number of hits in common between the current track ("this")
306 /// and the track pointed to by "track".
307 Int_t hitsInCommon = 0;
308 AliMUONTrackParam *trackParamAtHit1, *trackParamAtHit2;
309 // Loop over hits of first track
310 trackParamAtHit1 = (AliMUONTrackParam*) this->fTrackParamAtHit->First();
311 while (trackParamAtHit1) {
312 // Loop over hits of second track
313 trackParamAtHit2 = (AliMUONTrackParam*) track->fTrackParamAtHit->First();
314 while (trackParamAtHit2) {
315 // Increment "hitsInCommon" if both TrackParamAtHits point to the same HitForRec
316 if ((trackParamAtHit1->GetHitForRecPtr()) == (trackParamAtHit2->GetHitForRecPtr())) {
320 trackParamAtHit2 = (AliMUONTrackParam*) track->fTrackParamAtHit->After(trackParamAtHit2);
321 } // trackParamAtHit2
322 trackParamAtHit1 = (AliMUONTrackParam*) this->fTrackParamAtHit->After(trackParamAtHit1);
323 } // trackParamAtHit1
327 //__________________________________________________________________________
328 Bool_t* AliMUONTrack::CompatibleTrack(AliMUONTrack * track, Double_t sigma2Cut) const
330 /// Return kTRUE/kFALSE for each chamber if hit is compatible or not
331 TClonesArray *hitArray, *thisHitArray;
332 AliMUONHitForRec *hit, *thisHit;
335 Float_t deltaZMax = 1.; // 1 cm
337 Bool_t *nCompHit = new Bool_t[AliMUONConstants::NTrackingCh()];
339 for ( Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
340 nCompHit[ch] = kFALSE;
343 thisHitArray = this->GetHitForRecAtHit();
345 hitArray = track->GetHitForRecAtHit();
347 for (Int_t iHthis = 0; iHthis < thisHitArray->GetEntriesFast(); iHthis++) {
348 thisHit = (AliMUONHitForRec*) thisHitArray->At(iHthis);
349 chamberNumber = thisHit->GetChamberNumber();
350 if (chamberNumber < 0 || chamberNumber > AliMUONConstants::NTrackingCh()) continue;
351 nCompHit[chamberNumber] = kFALSE;
352 for (Int_t iH = 0; iH < hitArray->GetEntriesFast(); iH++) {
353 hit = (AliMUONHitForRec*) hitArray->At(iH);
354 deltaZ = TMath::Abs(thisHit->GetZ() - hit->GetZ());
355 chi2 = thisHit->NormalizedChi2WithHitForRec(hit,sigma2Cut); // set cut to 4 sigmas
356 if (chi2 < 3. && deltaZ < deltaZMax) {
357 nCompHit[chamberNumber] = kTRUE;
366 //__________________________________________________________________________
367 Double_t AliMUONTrack::TryOneHitForRec(AliMUONHitForRec* hitForRec)
369 /// Test the compatibility between the track and the hitForRec:
370 /// return the corresponding Chi2
372 // Get track parameters and their covariances at the z position of hitForRec
373 AliMUONTrackParam extrapTrackParam(fExtrapTrackParam);
374 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, hitForRec->GetZ());
376 // Set differences between trackParam and hitForRec in the bending and non bending directions
378 dPos(0,0) = hitForRec->GetNonBendingCoor() - extrapTrackParam.GetNonBendingCoor();
379 dPos(1,0) = hitForRec->GetBendingCoor() - extrapTrackParam.GetBendingCoor();
381 // quick test of hitForRec compatibility within a wide road of x*y = 10*1 cm2 to save computing time
382 if (TMath::Abs(dPos(0,0)) > fgkMaxTrackingDistanceNonBending ||
383 TMath::Abs(dPos(1,0)) > fgkMaxTrackingDistanceBending) return 1.e10;
385 // Set the error matrix from trackParam covariances and hitForRec resolution
386 TMatrixD* paramCov = extrapTrackParam.GetCovariances();
388 error(0,0) = (*paramCov)(0,0) + hitForRec->GetNonBendingReso2();
389 error(0,1) = (*paramCov)(0,2);
390 error(1,0) = (*paramCov)(2,0);
391 error(1,1) = (*paramCov)(2,2) + hitForRec->GetBendingReso2();
393 // Invert the error matrix for Chi2 calculation
394 if (error.Determinant() != 0) {
397 AliWarning(" Determinant error=0");
401 // Compute the Chi2 value
402 TMatrixD tmp(error,TMatrixD::kMult,dPos);
403 TMatrixD result(dPos,TMatrixD::kTransposeMult,tmp);
409 //__________________________________________________________________________
410 Double_t AliMUONTrack::TryTwoHitForRec(AliMUONHitForRec* hitForRec1, AliMUONHitForRec* hitForRec2)
412 /// Test the compatibility between the track and the 2 hitForRec together:
413 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
415 // Get track parameters and their covariances at the z position of the first hitForRec
416 AliMUONTrackParam extrapTrackParam1(fExtrapTrackParam);
417 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam1, hitForRec1->GetZ());
419 // Get track parameters at second hitForRec
420 AliMUONTrackParam extrapTrackParam2(extrapTrackParam1);
421 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam2, hitForRec2->GetZ());
423 // Set differences between track and the 2 hitForRec in the bending and non bending directions
425 dPos(0,0) = hitForRec1->GetNonBendingCoor() - extrapTrackParam1.GetNonBendingCoor();
426 dPos(1,0) = hitForRec1->GetBendingCoor() - extrapTrackParam1.GetBendingCoor();
427 dPos(2,0) = hitForRec2->GetNonBendingCoor() - extrapTrackParam2.GetNonBendingCoor();
428 dPos(3,0) = hitForRec2->GetBendingCoor() - extrapTrackParam2.GetBendingCoor();
430 // quick tests of hitForRec compatibility within a wide road of x*y = 1*1 cm2 to save computing time
431 if (TMath::Abs(dPos(0,0)) > fgkMaxTrackingDistanceNonBending ||
432 TMath::Abs(dPos(1,0)) > fgkMaxTrackingDistanceBending ||
433 TMath::Abs(dPos(2,0)) > fgkMaxTrackingDistanceNonBending ||
434 TMath::Abs(dPos(3,0)) > fgkMaxTrackingDistanceBending) return 1.e10;
436 // Calculate the error matrix from the track parameter covariances at first hitForRec
439 if (extrapTrackParam1.CovariancesExist()) {
440 // Get the pointer to the parameter covariance matrix at first hitForRec
441 TMatrixD* paramCov = extrapTrackParam1.GetCovariances();
443 // Save track parameters at first hitForRec
444 AliMUONTrackParam extrapTrackParam1Save(extrapTrackParam1);
445 Double_t nonBendingCoor1 = extrapTrackParam1Save.GetNonBendingCoor();
446 Double_t nonBendingSlope1 = extrapTrackParam1Save.GetNonBendingSlope();
447 Double_t bendingCoor1 = extrapTrackParam1Save.GetBendingCoor();
448 Double_t bendingSlope1 = extrapTrackParam1Save.GetBendingSlope();
449 Double_t inverseBendingMomentum1 = extrapTrackParam1Save.GetInverseBendingMomentum();
450 Double_t z1 = extrapTrackParam1Save.GetZ();
452 // Save track coordinates at second hitForRec
453 Double_t nonBendingCoor2 = extrapTrackParam2.GetNonBendingCoor();
454 Double_t bendingCoor2 = extrapTrackParam2.GetBendingCoor();
456 // Calculate the jacobian related to the transformation between track parameters
457 // at first hitForRec and track coordinates at the 2 hitForRec z-position
460 // first derivative at the first hitForRec:
461 jacob(0,0) = 1.; // dx1/dx
462 jacob(1,2) = 1.; // dy1/dy
463 // first derivative at the second hitForRec:
465 for (Int_t i=0; i<5; i++) {
466 // Skip jacobian calculation for parameters with no associated error
467 if ((*paramCov)(i,i) == 0.) continue;
468 // Small variation of parameter i only
469 for (Int_t j=0; j<5; j++) {
471 dParam[j] = TMath::Sqrt((*paramCov)(i,i));
472 if (j == 4) dParam[j] *= TMath::Sign(1.,-inverseBendingMomentum1); // variation always in the same direction
473 } else dParam[j] = 0.;
475 // Set new track parameters at first hitForRec
476 extrapTrackParam1Save.SetNonBendingCoor (nonBendingCoor1 + dParam[0]);
477 extrapTrackParam1Save.SetNonBendingSlope (nonBendingSlope1 + dParam[1]);
478 extrapTrackParam1Save.SetBendingCoor (bendingCoor1 + dParam[2]);
479 extrapTrackParam1Save.SetBendingSlope (bendingSlope1 + dParam[3]);
480 extrapTrackParam1Save.SetInverseBendingMomentum(inverseBendingMomentum1 + dParam[4]);
481 extrapTrackParam1Save.SetZ (z1);
482 // Extrapolate new track parameters to the z position of the second hitForRec
483 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam1Save,hitForRec2->GetZ());
484 // Calculate the jacobian
485 jacob(2,i) = (extrapTrackParam1Save.GetNonBendingCoor() - nonBendingCoor2) / dParam[i]; // dx2/dParami
486 jacob(3,i) = (extrapTrackParam1Save.GetBendingCoor() - bendingCoor2 ) / dParam[i]; // dy2/dParami
489 // Calculate the error matrix
490 TMatrixD tmp((*paramCov),TMatrixD::kMultTranspose,jacob);
491 error = TMatrixD(jacob,TMatrixD::kMult,tmp);
494 // Add hitForRec resolution to the error matrix
495 error(0,0) += hitForRec1->GetNonBendingReso2();
496 error(1,1) += hitForRec1->GetBendingReso2();
497 error(2,2) += hitForRec2->GetNonBendingReso2();
498 error(3,3) += hitForRec2->GetBendingReso2();
500 // invert the error matrix for Chi2 calculation
501 if (error.Determinant() != 0) {
504 AliWarning(" Determinant error=0");
508 // Compute the Chi2 value
509 TMatrixD tmp2(error,TMatrixD::kMult,dPos);
510 TMatrixD result(dPos,TMatrixD::kTransposeMult,tmp2);
516 //__________________________________________________________________________
517 void AliMUONTrack::RecursiveDump(void) const
519 /// Recursive dump of AliMUONTrack, i.e. with dump of TrackParamAtHit's and attached HitForRec's
520 AliMUONTrackParam *trackParamAtHit;
521 AliMUONHitForRec *hitForRec;
522 cout << "Recursive dump of Track: " << this << endl;
525 for (Int_t trackHitIndex = 0; trackHitIndex < fNTrackHits; trackHitIndex++) {
526 trackParamAtHit = (AliMUONTrackParam*) ((*fTrackParamAtHit)[trackHitIndex]);
528 cout << "TrackParamAtHit: " << trackParamAtHit << " (index: " << trackHitIndex << ")" << endl;
529 trackParamAtHit->Dump();
530 hitForRec = trackParamAtHit->GetHitForRecPtr();
532 cout << "HitForRec: " << hitForRec << endl;
538 //_____________________________________________-
539 void AliMUONTrack::Print(Option_t* opt) const
541 /// Printing Track information
542 /// "full" option for printing all the information about the track
546 if ( sopt.Contains("FULL") ) {
547 cout << "<AliMUONTrack> No.Clusters=" << setw(2) << GetNTrackHits() <<
548 // ", Bending P="<< setw(8) << setprecision(5) << 1./GetInverseBendingMomentum() <<
549 //", NonBendSlope=" << setw(8) << setprecision(5) << GetNonBendingSlope()*180./TMath::Pi() <<
550 //", BendSlope=" << setw(8) << setprecision(5) << GetBendingSlope()*180./TMath::Pi() <<
551 ", Match2Trig=" << setw(1) << GetMatchTrigger() <<
552 ", Chi2-tracking-trigger=" << setw(8) << setprecision(5) << GetChi2MatchTrigger() << endl ;
553 GetTrackParamAtHit()->First()->Print("full");
556 cout << "<AliMUONTrack>";
557 GetTrackParamAtHit()->First()->Print("");