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 **************************************************************************/
16 //////////////////////////////////////////////////////////////////////////////
17 // Class AliTrackPointArray //
18 // This class contains the ESD track space-points which are used during //
19 // the alignment procedures. Each space-point consist of 3 coordinates //
20 // (and their errors) and the index of the sub-detector which contains //
21 // the space-point. //
22 // cvetan.cheshkov@cern.ch 3/11/2005 //
23 //////////////////////////////////////////////////////////////////////////////
27 #include <TMatrixDSym.h>
28 #include <TGeoMatrix.h>
29 #include <TMatrixDSymEigen.h>
31 #include "AliTrackPointArray.h"
33 ClassImp(AliTrackPointArray)
35 //______________________________________________________________________________
36 AliTrackPointArray::AliTrackPointArray() :
54 //______________________________________________________________________________
55 AliTrackPointArray::AliTrackPointArray(Int_t npoints):
59 fX(new Float_t[npoints]),
60 fY(new Float_t[npoints]),
61 fZ(new Float_t[npoints]),
62 fCharge(new Float_t[npoints]),
63 fDriftTime(new Float_t[npoints]),
64 fChargeRatio(new Float_t[npoints]),
65 fClusterType(new Int_t[npoints]),
66 fIsExtra(new Bool_t[npoints]),
68 fCov(new Float_t[fSize]),
69 fVolumeID(new UShort_t[npoints])
73 for (Int_t ip=0; ip<npoints;ip++){
83 for (Int_t icov=0;icov<6; icov++)
88 //______________________________________________________________________________
89 AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
91 fSorted(array.fSorted),
92 fNPoints(array.fNPoints),
93 fX(new Float_t[fNPoints]),
94 fY(new Float_t[fNPoints]),
95 fZ(new Float_t[fNPoints]),
96 fCharge(new Float_t[fNPoints]),
97 fDriftTime(new Float_t[fNPoints]),
98 fChargeRatio(new Float_t[fNPoints]),
99 fClusterType(new Int_t[fNPoints]),
100 fIsExtra(new Bool_t[fNPoints]),
102 fCov(new Float_t[fSize]),
103 fVolumeID(new UShort_t[fNPoints])
107 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
108 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
109 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
111 memcpy(fCharge,array.fCharge,fNPoints*sizeof(Float_t));
113 memset(fCharge, 0, fNPoints*sizeof(Float_t));
115 if (array.fDriftTime) {
116 memcpy(fDriftTime,array.fDriftTime,fNPoints*sizeof(Float_t));
118 memset(fDriftTime, 0, fNPoints*sizeof(Float_t));
120 if (array.fChargeRatio) {
121 memcpy(fChargeRatio,array.fChargeRatio,fNPoints*sizeof(Float_t));
123 memset(fChargeRatio, 0, fNPoints*sizeof(Float_t));
125 if (array.fClusterType) {
126 memcpy(fClusterType,array.fClusterType,fNPoints*sizeof(Int_t));
128 memset(fClusterType, 0, fNPoints*sizeof(Int_t));
130 if (array.fIsExtra) {
131 memcpy(fIsExtra,array.fIsExtra,fNPoints*sizeof(Bool_t));
133 memset(fIsExtra, 0, fNPoints*sizeof(Bool_t));
135 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
136 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
139 //_____________________________________________________________________________
140 AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
142 // assignment operator
144 if(this==&array) return *this;
145 ((TObject *)this)->operator=(array);
147 fSorted = array.fSorted;
148 fNPoints = array.fNPoints;
151 fX = new Float_t[fNPoints];
153 fY = new Float_t[fNPoints];
155 fZ = new Float_t[fNPoints];
157 fCharge = new Float_t[fNPoints];
158 delete [] fDriftTime;
159 fDriftTime = new Float_t[fNPoints];
160 delete [] fChargeRatio;
161 fChargeRatio = new Float_t[fNPoints];
162 delete [] fClusterType;
163 fClusterType = new Int_t[fNPoints];
165 fIsExtra = new Bool_t[fNPoints];
167 fVolumeID = new UShort_t[fNPoints];
169 fCov = new Float_t[fSize];
170 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
171 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
172 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
173 memcpy(fCharge,array.fCharge,fNPoints*sizeof(Float_t));
174 memcpy(fDriftTime,array.fDriftTime,fNPoints*sizeof(Float_t));
175 memcpy(fChargeRatio,array.fChargeRatio,fNPoints*sizeof(Float_t));
176 memcpy(fClusterType,array.fClusterType,fNPoints*sizeof(Int_t));
177 memcpy(fIsExtra,array.fIsExtra,fNPoints*sizeof(Bool_t));
178 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
179 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
184 //______________________________________________________________________________
185 AliTrackPointArray::~AliTrackPointArray()
193 delete [] fDriftTime;
194 delete [] fChargeRatio;
195 delete [] fClusterType;
202 //______________________________________________________________________________
203 Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
205 // Add a point to the array at position i
207 if (i >= fNPoints) return kFALSE;
211 fCharge[i] = p->GetCharge();
212 fDriftTime[i] = p->GetDriftTime();
213 fChargeRatio[i]=p->GetChargeRatio();
214 fClusterType[i]=p->GetClusterType();
215 fIsExtra[i] = p->IsExtra();
216 fVolumeID[i] = p->GetVolumeID();
217 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
222 //______________________________________________________________________________
223 Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
225 // Get the point at position i
227 if (i >= fNPoints) return kFALSE;
228 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
229 p.SetVolumeID(fVolumeID[i]);
230 p.SetCharge(fCharge ? fCharge[i] : 0);
231 p.SetDriftTime(fDriftTime ? fDriftTime[i] : 0);
232 p.SetChargeRatio(fChargeRatio ? fChargeRatio[i] : 0);
233 p.SetClusterType(fClusterType ? fClusterType[i] : 0);
234 p.SetExtra(fIsExtra ? fIsExtra[i] : kFALSE);
238 //______________________________________________________________________________
239 Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
241 // This method checks if the array
242 // has at least one hit in the detector
243 // volume defined by volid
244 Bool_t check = kFALSE;
245 for (Int_t ipoint = 0; ipoint < fNPoints; ipoint++)
246 if (fVolumeID[ipoint] == volid) check = kTRUE;
251 //______________________________________________________________________________
252 void AliTrackPointArray::Sort(Bool_t down)
254 // Sort the array by the values of Y-coordinate of the track points.
255 // The order is given by "down".
256 // Optimized more for maintenance rather than for speed.
260 Int_t *index=new Int_t[fNPoints];
261 AliTrackPointArray a(*this);
262 TMath::Sort(fNPoints,a.GetY(),index,down);
265 for (Int_t i = 0; i < fNPoints; i++) {
266 a.GetPoint(p,index[i]);
274 ClassImp(AliTrackPoint)
276 //______________________________________________________________________________
277 AliTrackPoint::AliTrackPoint() :
289 // Default constructor
291 memset(fCov,0,6*sizeof(Float_t));
295 //______________________________________________________________________________
296 AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid, Float_t charge, Float_t drifttime,Float_t chargeratio, Int_t clutyp) :
312 SetDriftTime(drifttime);
313 SetChargeRatio(chargeratio);
314 SetClusterType(clutyp);
318 //______________________________________________________________________________
319 AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid, Float_t charge, Float_t drifttime,Float_t chargeratio, Int_t clutyp) :
333 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
335 SetDriftTime(drifttime);
336 SetChargeRatio(chargeratio);
338 SetClusterType(clutyp);
341 //______________________________________________________________________________
342 AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
356 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
357 SetCharge(p.fCharge);
358 SetDriftTime(p.fDriftTime);
359 SetChargeRatio(p.fChargeRatio);
360 SetClusterType(p.fClusterType);
361 SetExtra(p.fIsExtra);
362 SetVolumeID(p.fVolumeID);
365 //_____________________________________________________________________________
366 AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
368 // assignment operator
370 if(this==&p) return *this;
371 ((TObject *)this)->operator=(p);
373 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
374 SetCharge(p.fCharge);
375 SetDriftTime(p.fDriftTime);
376 SetChargeRatio(p.fChargeRatio);
377 SetClusterType(p.fClusterType);
378 SetExtra(p.fIsExtra);
379 SetVolumeID(p.fVolumeID);
384 //______________________________________________________________________________
385 void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
387 // Set XYZ coordinates and their cov matrix
393 memcpy(fCov,cov,6*sizeof(Float_t));
396 //______________________________________________________________________________
397 void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
399 // Set XYZ coordinates and their cov matrix
401 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
404 //______________________________________________________________________________
405 void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
411 memcpy(cov,fCov,6*sizeof(Float_t));
414 //______________________________________________________________________________
415 Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
417 // This method calculates the track to space-point residuals. The track
418 // interpolation is also stored as AliTrackPoint. Using the option
419 // 'weighted' one can calculate the residual either with or without
420 // taking into account the covariance matrix of the space-point and
421 // track interpolation. The second case the residual becomes a pull.
426 Float_t xyz[3],xyzp[3];
429 res = (xyz[0]-xyzp[0])*(xyz[0]-xyzp[0])+
430 (xyz[1]-xyzp[1])*(xyz[1]-xyzp[1])+
431 (xyz[2]-xyzp[2])*(xyz[2]-xyzp[2]);
434 Float_t xyz[3],xyzp[3];
435 Float_t cov[6],covp[6];
438 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
439 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
440 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
442 TMatrixDSym mcovp(3);
443 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
444 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
445 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
446 TMatrixDSym msum = mcov + mcovp;
448 // mcov.Print(); mcovp.Print(); msum.Print();
449 if (msum.IsValid()) {
450 for (Int_t i = 0; i < 3; i++)
451 for (Int_t j = 0; j < 3; j++)
452 res += (xyz[i]-xyzp[i])*(xyz[j]-xyzp[j])*msum(i,j);
459 //_____________________________________________________________________________
460 Bool_t AliTrackPoint::GetPCA(const AliTrackPoint &p, AliTrackPoint &out) const
463 // Get the intersection point between this point and
464 // the point "p" belongs to.
465 // The result is stored as a point 'out'
466 // return kFALSE in case of failure.
476 const Float_t *cv=GetCov();
477 tC(0,0)=cv[0]; tC(0,1)=cv[1]; tC(0,2)=cv[2];
478 tC(1,0)=cv[1]; tC(1,1)=cv[3]; tC(1,2)=cv[4];
479 tC(2,0)=cv[2]; tC(2,1)=cv[4]; tC(2,2)=cv[5];
489 const Float_t *cv=p.GetCov();
490 mC(0,0)=cv[0]; mC(0,1)=cv[1]; mC(0,2)=cv[2];
491 mC(1,0)=cv[1]; mC(1,1)=cv[3]; mC(1,2)=cv[4];
492 mC(2,0)=cv[2]; mC(2,1)=cv[4]; mC(2,2)=cv[5];
498 if (!tmW.IsValid()) return kFALSE;
500 TMatrixD mW(tC,TMatrixD::kMult,tmW);
501 TMatrixD tW(mC,TMatrixD::kMult,tmW);
503 TMatrixD mi(mW,TMatrixD::kMult,m);
504 TMatrixD ti(tW,TMatrixD::kMult,t);
507 TMatrixD iC(tC,TMatrixD::kMult,tmW);
510 out.SetXYZ(ti(0,0),ti(1,0),ti(2,0));
511 UShort_t id=p.GetVolumeID();
517 //______________________________________________________________________________
518 Float_t AliTrackPoint::GetAngle() const
520 // The method uses the covariance matrix of
521 // the space-point in order to extract the
522 // orientation of the detector plane.
523 // The rotation in XY plane only is calculated.
525 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
527 phi = TMath::Pi() - phi;
528 if ((fY-fX) < 0) phi += TMath::Pi();
531 if ((fX+fY) < 0) phi += TMath::Pi();
538 //______________________________________________________________________________
539 Bool_t AliTrackPoint::GetRotMatrix(TGeoRotation& rot) const
541 // Returns the orientation of the
542 // sensitive layer (using cluster
543 // covariance matrix).
544 // Assumes that cluster has errors only in the layer's plane.
545 // Return value is kTRUE in case of success.
549 const Float_t *cov=GetCov();
550 mcov(0,0)=cov[0]; mcov(0,1)=cov[1]; mcov(0,2)=cov[2];
551 mcov(1,0)=cov[1]; mcov(1,1)=cov[3]; mcov(1,2)=cov[4];
552 mcov(2,0)=cov[2]; mcov(2,1)=cov[4]; mcov(2,2)=cov[5];
555 TMatrixDSymEigen eigen(mcov);
556 TMatrixD eigenMatrix = eigen.GetEigenVectors();
558 rot.SetMatrix(eigenMatrix.GetMatrixArray());
564 //_____________________________________________________________________________
565 AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
567 // Transform the space-point coordinates
568 // and covariance matrix from global to
569 // local (detector plane) coordinate system
570 // XY plane rotation only
572 static AliTrackPoint p;
575 Float_t xyz[3],cov[6];
578 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
580 Float_t newxyz[3],newcov[6];
581 newxyz[0] = cos*xyz[0] + sin*xyz[1];
582 newxyz[1] = cos*xyz[1] - sin*xyz[0];
585 newcov[0] = cov[0]*cos*cos+
588 newcov[1] = cov[1]*(cos*cos-sin*sin)+
589 (cov[3]-cov[0])*sin*cos;
590 newcov[2] = cov[2]*cos+
592 newcov[3] = cov[0]*sin*sin-
595 newcov[4] = cov[4]*cos-
599 p.SetXYZ(newxyz,newcov);
600 p.SetVolumeID(GetVolumeID());
605 //_____________________________________________________________________________
606 AliTrackPoint& AliTrackPoint::MasterToLocal() const
608 // Transform the space-point coordinates
609 // and the covariance matrix from the
610 // (master) to the local (tracking)
613 Float_t alpha = GetAngle();
614 return Rotate(alpha);
617 //_____________________________________________________________________________
618 void AliTrackPoint::Print(Option_t *) const
620 // Print the space-point coordinates and
623 printf("VolumeID=%d\n", GetVolumeID());
624 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
625 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
626 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);
627 printf("Charge = %f\n", fCharge);
628 printf("Drift Time = %f\n", fDriftTime);
629 printf("Charge Ratio = %f\n", fChargeRatio);
630 printf("Cluster Type = %d\n", fClusterType);
631 if(fIsExtra) printf("This is an extra point\n");
636 //________________________________
637 void AliTrackPoint::SetAlignCovMatrix(const TMatrixDSym alignparmtrx){
638 // Add the uncertainty on the cluster position due to alignment
639 // (using the 6x6 AliAlignObj Cov. Matrix alignparmtrx) to the already
640 // present Cov. Matrix
648 cov(1,0)=cov(0,1)=fCov[1];
649 cov(2,0)=cov(0,2)=fCov[2];
651 cov(2,1)=cov(1,2)=fCov[4];
654 jacob(0,0) = 1; jacob(1,0) = 0; jacob(2,0) = 0;
655 jacob(0,1) = 0; jacob(1,1) = 1; jacob(2,1) = 0;
656 jacob(0,2) = 0; jacob(1,2) = 0; jacob(2,2) = 1;
657 jacob(0,3) = 0; jacob(1,3) =-fZ; jacob(2,3) = fY;
658 jacob(0,4) = fZ; jacob(1,4) = 0; jacob(2,4) =-fX;
659 jacob(0,5) = -fY; jacob(1,5) = fX; jacob(2,5) = 0;
661 TMatrixD jacobT=jacob.T();jacob.T();
663 coval=jacob*alignparmtrx*jacobT+cov;
666 newcov[0]=coval(0,0);
667 newcov[1]=coval(1,0);
668 newcov[2]=coval(2,0);
669 newcov[3]=coval(1,1);
670 newcov[4]=coval(2,1);
671 newcov[5]=coval(2,2);
673 SetXYZ(fX,fY,fZ,newcov);