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>
29 #include "AliTrackPointArray.h"
31 ClassImp(AliTrackPointArray)
33 //______________________________________________________________________________
34 AliTrackPointArray::AliTrackPointArray() :
49 //______________________________________________________________________________
50 AliTrackPointArray::AliTrackPointArray(Int_t npoints):
54 fX(new Float_t[npoints]),
55 fY(new Float_t[npoints]),
56 fZ(new Float_t[npoints]),
57 fCharge(new Float_t[npoints]),
58 fDriftTime(new Float_t[npoints]),
60 fCov(new Float_t[fSize]),
61 fVolumeID(new UShort_t[npoints])
65 for (Int_t ip=0; ip<npoints;ip++){
72 for (Int_t icov=0;icov<6; icov++)
77 //______________________________________________________________________________
78 AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
80 fSorted(array.fSorted),
81 fNPoints(array.fNPoints),
82 fX(new Float_t[fNPoints]),
83 fY(new Float_t[fNPoints]),
84 fZ(new Float_t[fNPoints]),
85 fCharge(new Float_t[fNPoints]),
86 fDriftTime(new Float_t[fNPoints]),
88 fCov(new Float_t[fSize]),
89 fVolumeID(new UShort_t[fNPoints])
93 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
94 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
95 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
97 memcpy(fCharge,array.fCharge,fNPoints*sizeof(Float_t));
99 memset(fCharge, 0, fNPoints*sizeof(Float_t));
101 if (array.fDriftTime) {
102 memcpy(fDriftTime,array.fDriftTime,fNPoints*sizeof(Float_t));
104 memset(fDriftTime, 0, fNPoints*sizeof(Float_t));
106 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
107 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
110 //_____________________________________________________________________________
111 AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
113 // assignment operator
115 if(this==&array) return *this;
116 ((TObject *)this)->operator=(array);
118 fSorted = array.fSorted;
119 fNPoints = array.fNPoints;
122 fX = new Float_t[fNPoints];
124 fY = new Float_t[fNPoints];
126 fZ = new Float_t[fNPoints];
128 fCharge = new Float_t[fNPoints];
129 delete [] fDriftTime;
130 fDriftTime = new Float_t[fNPoints];
132 fVolumeID = new UShort_t[fNPoints];
134 fCov = new Float_t[fSize];
135 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
136 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
137 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
138 memcpy(fCharge,array.fCharge,fNPoints*sizeof(Float_t));
139 memcpy(fDriftTime,array.fDriftTime,fNPoints*sizeof(Float_t));
140 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
141 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
146 //______________________________________________________________________________
147 AliTrackPointArray::~AliTrackPointArray()
155 delete [] fDriftTime;
161 //______________________________________________________________________________
162 Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
164 // Add a point to the array at position i
166 if (i >= fNPoints) return kFALSE;
170 fCharge[i] = p->GetCharge();
171 fDriftTime[i] = p->GetDriftTime();
172 fVolumeID[i] = p->GetVolumeID();
173 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
178 //______________________________________________________________________________
179 Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
181 // Get the point at position i
183 if (i >= fNPoints) return kFALSE;
184 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
185 p.SetVolumeID(fVolumeID[i]);
186 p.SetCharge(fCharge[i]);
187 p.SetDriftTime(fDriftTime[i]);
191 //______________________________________________________________________________
192 Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
194 // This method checks if the array
195 // has at least one hit in the detector
196 // volume defined by volid
197 Bool_t check = kFALSE;
198 for (Int_t ipoint = 0; ipoint < fNPoints; ipoint++)
199 if (fVolumeID[ipoint] == volid) check = kTRUE;
204 //______________________________________________________________________________
205 void AliTrackPointArray::Sort(Bool_t down)
207 // Sort the array by the values of Y-coordinate of the track points.
208 // The order is given by "down".
209 // Optimized more for maintenance rather than for speed.
213 Int_t *index=new Int_t[fNPoints];
214 AliTrackPointArray a(*this);
215 TMath::Sort(fNPoints,a.GetY(),index,down);
218 for (Int_t i = 0; i < fNPoints; i++) {
219 a.GetPoint(p,index[i]);
227 ClassImp(AliTrackPoint)
229 //______________________________________________________________________________
230 AliTrackPoint::AliTrackPoint() :
239 // Default constructor
241 memset(fCov,0,6*sizeof(Float_t));
245 //______________________________________________________________________________
246 AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid, Float_t charge, Float_t drifttime) :
259 SetDriftTime(drifttime);
263 //______________________________________________________________________________
264 AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid, Float_t charge, Float_t drifttime) :
275 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
277 SetDriftTime(drifttime);
281 //______________________________________________________________________________
282 AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
293 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
294 SetCharge(p.fCharge);
295 SetDriftTime(p.fDriftTime);
296 SetVolumeID(p.fVolumeID);
299 //_____________________________________________________________________________
300 AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
302 // assignment operator
304 if(this==&p) return *this;
305 ((TObject *)this)->operator=(p);
307 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
308 SetCharge(p.fCharge);
309 SetDriftTime(p.fDriftTime);
310 SetVolumeID(p.fVolumeID);
315 //______________________________________________________________________________
316 void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
318 // Set XYZ coordinates and their cov matrix
324 memcpy(fCov,cov,6*sizeof(Float_t));
327 //______________________________________________________________________________
328 void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
330 // Set XYZ coordinates and their cov matrix
332 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
335 //______________________________________________________________________________
336 void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
342 memcpy(cov,fCov,6*sizeof(Float_t));
345 //______________________________________________________________________________
346 Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
348 // This method calculates the track to space-point residuals. The track
349 // interpolation is also stored as AliTrackPoint. Using the option
350 // 'weighted' one can calculate the residual either with or without
351 // taking into account the covariance matrix of the space-point and
352 // track interpolation. The second case the residual becomes a pull.
357 Float_t xyz[3],xyzp[3];
360 res = (xyz[0]-xyzp[0])*(xyz[0]-xyzp[0])+
361 (xyz[1]-xyzp[1])*(xyz[1]-xyzp[1])+
362 (xyz[2]-xyzp[2])*(xyz[2]-xyzp[2]);
365 Float_t xyz[3],xyzp[3];
366 Float_t cov[6],covp[6];
369 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
370 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
371 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
373 TMatrixDSym mcovp(3);
374 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
375 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
376 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
377 TMatrixDSym msum = mcov + mcovp;
379 // mcov.Print(); mcovp.Print(); msum.Print();
380 if (msum.IsValid()) {
381 for (Int_t i = 0; i < 3; i++)
382 for (Int_t j = 0; j < 3; j++)
383 res += (xyz[i]-xyzp[i])*(xyz[j]-xyzp[j])*msum(i,j);
390 //_____________________________________________________________________________
391 Bool_t AliTrackPoint::GetPCA(const AliTrackPoint &p, AliTrackPoint &out) const
394 // Get the intersection point between this point and
395 // the point "p" belongs to.
396 // The result is stored as a point 'out'
397 // return kFALSE in case of failure.
407 const Float_t *cv=GetCov();
408 tC(0,0)=cv[0]; tC(0,1)=cv[1]; tC(0,2)=cv[2];
409 tC(1,0)=cv[1]; tC(1,1)=cv[3]; tC(1,2)=cv[4];
410 tC(2,0)=cv[2]; tC(2,1)=cv[4]; tC(2,2)=cv[5];
420 const Float_t *cv=p.GetCov();
421 mC(0,0)=cv[0]; mC(0,1)=cv[1]; mC(0,2)=cv[2];
422 mC(1,0)=cv[1]; mC(1,1)=cv[3]; mC(1,2)=cv[4];
423 mC(2,0)=cv[2]; mC(2,1)=cv[4]; mC(2,2)=cv[5];
429 if (!tmW.IsValid()) return kFALSE;
431 TMatrixD mW(tC,TMatrixD::kMult,tmW);
432 TMatrixD tW(mC,TMatrixD::kMult,tmW);
434 TMatrixD mi(mW,TMatrixD::kMult,m);
435 TMatrixD ti(tW,TMatrixD::kMult,t);
438 TMatrixD iC(tC,TMatrixD::kMult,tmW);
441 out.SetXYZ(ti(0,0),ti(1,0),ti(2,0));
442 UShort_t id=p.GetVolumeID();
448 //______________________________________________________________________________
449 Float_t AliTrackPoint::GetAngle() const
451 // The method uses the covariance matrix of
452 // the space-point in order to extract the
453 // orientation of the detector plane.
454 // The rotation in XY plane only is calculated.
456 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
458 phi = TMath::Pi() - phi;
459 if ((fY-fX) < 0) phi += TMath::Pi();
462 if ((fX+fY) < 0) phi += TMath::Pi();
469 //_____________________________________________________________________________
470 AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
472 // Transform the space-point coordinates
473 // and covariance matrix from global to
474 // local (detector plane) coordinate system
475 // XY plane rotation only
477 static AliTrackPoint p;
480 Float_t xyz[3],cov[6];
483 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
485 Float_t newxyz[3],newcov[6];
486 newxyz[0] = cos*xyz[0] + sin*xyz[1];
487 newxyz[1] = cos*xyz[1] - sin*xyz[0];
490 newcov[0] = cov[0]*cos*cos+
493 newcov[1] = cov[1]*(cos*cos-sin*sin)+
494 (cov[3]-cov[0])*sin*cos;
495 newcov[2] = cov[2]*cos+
497 newcov[3] = cov[0]*sin*sin-
500 newcov[4] = cov[4]*cos-
504 p.SetXYZ(newxyz,newcov);
505 p.SetVolumeID(GetVolumeID());
510 //_____________________________________________________________________________
511 AliTrackPoint& AliTrackPoint::MasterToLocal() const
513 // Transform the space-point coordinates
514 // and the covariance matrix from the
515 // (master) to the local (tracking)
518 Float_t alpha = GetAngle();
519 return Rotate(alpha);
522 //_____________________________________________________________________________
523 void AliTrackPoint::Print(Option_t *) const
525 // Print the space-point coordinates and
528 printf("VolumeID=%d\n", GetVolumeID());
529 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
530 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
531 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);
532 printf("Charge = %f\n", fCharge);
533 printf("Drift Time = %f\n", fDriftTime);
538 //________________________________
539 void AliTrackPoint::SetAlignCovMatrix(const TMatrixDSym alignparmtrx){
540 // Add the uncertainty on the cluster position due to alignment
541 // (using the 6x6 AliAlignObj Cov. Matrix alignparmtrx) to the already
542 // present Cov. Matrix
550 cov(1,0)=cov(0,1)=fCov[1];
551 cov(2,0)=cov(0,2)=fCov[2];
553 cov(2,1)=cov(1,2)=fCov[4];
556 jacob(0,0) = 1; jacob(1,0) = 0; jacob(2,0) = 0;
557 jacob(0,1) = 0; jacob(1,1) = 1; jacob(2,1) = 0;
558 jacob(0,2) = 0; jacob(1,2) = 0; jacob(2,2) = 1;
559 jacob(0,3) = 0; jacob(1,3) =-fZ; jacob(2,3) = fY;
560 jacob(0,4) = fZ; jacob(1,4) = 0; jacob(2,4) =-fX;
561 jacob(0,5) = -fY; jacob(1,5) = fX; jacob(2,5) = 0;
563 TMatrixD jacobT=jacob.T();jacob.T();
565 coval=jacob*alignparmtrx*jacobT+cov;
568 newcov[0]=coval(0,0);
569 newcov[1]=coval(1,0);
570 newcov[2]=coval(2,0);
571 newcov[3]=coval(1,1);
572 newcov[4]=coval(2,1);
573 newcov[5]=coval(2,2);
575 SetXYZ(fX,fY,fZ,newcov);