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() :
46 //______________________________________________________________________________
47 AliTrackPointArray::AliTrackPointArray(Int_t npoints):
50 fX(new Float_t[npoints]),
51 fY(new Float_t[npoints]),
52 fZ(new Float_t[npoints]),
54 fCov(new Float_t[fSize]),
55 fVolumeID(new UShort_t[npoints])
61 //______________________________________________________________________________
62 AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
64 fNPoints(array.fNPoints),
65 fX(new Float_t[fNPoints]),
66 fY(new Float_t[fNPoints]),
67 fZ(new Float_t[fNPoints]),
69 fCov(new Float_t[fSize]),
70 fVolumeID(new UShort_t[fNPoints])
74 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
75 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
76 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
77 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
78 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
81 //_____________________________________________________________________________
82 AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
84 // assignment operator
86 if(this==&array) return *this;
87 ((TObject *)this)->operator=(array);
89 fNPoints = array.fNPoints;
91 fX = new Float_t[fNPoints];
92 fY = new Float_t[fNPoints];
93 fZ = new Float_t[fNPoints];
94 fVolumeID = new UShort_t[fNPoints];
95 fCov = new Float_t[fSize];
96 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
97 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
98 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
99 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
100 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
105 //______________________________________________________________________________
106 AliTrackPointArray::~AliTrackPointArray()
118 //______________________________________________________________________________
119 Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
121 // Add a point to the array at position i
123 if (i >= fNPoints) return kFALSE;
127 fVolumeID[i] = p->GetVolumeID();
128 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
133 //______________________________________________________________________________
134 Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
136 // Get the point at position i
138 if (i >= fNPoints) return kFALSE;
139 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
140 p.SetVolumeID(fVolumeID[i]);
144 //______________________________________________________________________________
145 Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
147 // This method checks if the array
148 // has at least one hit in the detector
149 // volume defined by volid
150 Bool_t check = kFALSE;
151 for (Int_t ipoint = 0; ipoint < fNPoints; ipoint++)
152 if (fVolumeID[ipoint] == volid) check = kTRUE;
157 ClassImp(AliTrackPoint)
159 //______________________________________________________________________________
160 AliTrackPoint::AliTrackPoint() :
167 // Default constructor
169 memset(fCov,0,6*sizeof(Float_t));
173 //______________________________________________________________________________
174 AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid) :
187 //______________________________________________________________________________
188 AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid) :
197 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
201 //______________________________________________________________________________
202 AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
211 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
212 SetVolumeID(p.fVolumeID);
215 //_____________________________________________________________________________
216 AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
218 // assignment operator
220 if(this==&p) return *this;
221 ((TObject *)this)->operator=(p);
223 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
224 SetVolumeID(p.fVolumeID);
229 //______________________________________________________________________________
230 void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
232 // Set XYZ coordinates and their cov matrix
238 memcpy(fCov,cov,6*sizeof(Float_t));
241 //______________________________________________________________________________
242 void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
244 // Set XYZ coordinates and their cov matrix
246 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
249 //______________________________________________________________________________
250 void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
256 memcpy(cov,fCov,6*sizeof(Float_t));
259 //______________________________________________________________________________
260 Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
262 // This method calculates the track to space-point residuals. The track
263 // interpolation is also stored as AliTrackPoint. Using the option
264 // 'weighted' one can calculate the residual either with or without
265 // taking into account the covariance matrix of the space-point and
266 // track interpolation. The second case the residual becomes a pull.
271 Float_t xyz[3],xyzp[3];
274 res = (xyz[0]-xyzp[0])*(xyz[0]-xyzp[0])+
275 (xyz[1]-xyzp[1])*(xyz[1]-xyzp[1])+
276 (xyz[2]-xyzp[2])*(xyz[2]-xyzp[2]);
279 Float_t xyz[3],xyzp[3];
280 Float_t cov[6],covp[6];
283 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
284 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
285 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
287 TMatrixDSym mcovp(3);
288 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
289 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
290 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
291 TMatrixDSym msum = mcov + mcovp;
293 // mcov.Print(); mcovp.Print(); msum.Print();
294 if (msum.IsValid()) {
295 for (Int_t i = 0; i < 3; i++)
296 for (Int_t j = 0; j < 3; j++)
297 res += (xyz[i]-xyzp[i])*(xyz[j]-xyzp[j])*msum(i,j);
304 //_____________________________________________________________________________
305 Bool_t AliTrackPoint::GetPCA(const AliTrackPoint &p, AliTrackPoint &out) const
308 // Get the intersection point between this point and
309 // the point "p" belongs to.
310 // The result is stored as a point 'out'
311 // return kFALSE in case of failure.
321 const Float_t *cv=GetCov();
322 tC(0,0)=cv[0]; tC(0,1)=cv[1]; tC(0,2)=cv[2];
323 tC(1,0)=cv[1]; tC(1,1)=cv[3]; tC(1,2)=cv[4];
324 tC(2,0)=cv[2]; tC(2,1)=cv[4]; tC(2,2)=cv[5];
334 const Float_t *cv=p.GetCov();
335 mC(0,0)=cv[0]; mC(0,1)=cv[1]; mC(0,2)=cv[2];
336 mC(1,0)=cv[1]; mC(1,1)=cv[3]; mC(1,2)=cv[4];
337 mC(2,0)=cv[2]; mC(2,1)=cv[4]; mC(2,2)=cv[5];
343 if (!tmW.IsValid()) return kFALSE;
345 TMatrixD mW(tC,TMatrixD::kMult,tmW);
346 TMatrixD tW(mC,TMatrixD::kMult,tmW);
348 TMatrixD mi(mW,TMatrixD::kMult,m);
349 TMatrixD ti(tW,TMatrixD::kMult,t);
352 TMatrixD iC(tC,TMatrixD::kMult,tmW);
355 out.SetXYZ(ti(0,0),ti(1,0),ti(2,0));
356 UShort_t id=p.GetVolumeID();
362 //______________________________________________________________________________
363 Float_t AliTrackPoint::GetAngle() const
365 // The method uses the covariance matrix of
366 // the space-point in order to extract the
367 // orientation of the detector plane.
368 // The rotation in XY plane only is calculated.
370 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
372 phi = TMath::Pi() - phi;
373 if ((fY-fX) < 0) phi += TMath::Pi();
376 if ((fX+fY) < 0) phi += TMath::Pi();
383 //_____________________________________________________________________________
384 AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
386 // Transform the space-point coordinates
387 // and covariance matrix from global to
388 // local (detector plane) coordinate system
389 // XY plane rotation only
391 static AliTrackPoint p;
394 Float_t xyz[3],cov[6];
397 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
399 Float_t newxyz[3],newcov[6];
400 newxyz[0] = cos*xyz[0] + sin*xyz[1];
401 newxyz[1] = cos*xyz[1] - sin*xyz[0];
404 newcov[0] = cov[0]*cos*cos+
407 newcov[1] = cov[1]*(cos*cos-sin*sin)+
408 (cov[3]-cov[0])*sin*cos;
409 newcov[2] = cov[2]*cos+
411 newcov[3] = cov[0]*sin*sin-
414 newcov[4] = cov[4]*cos-
418 p.SetXYZ(newxyz,newcov);
419 p.SetVolumeID(GetVolumeID());
424 //_____________________________________________________________________________
425 AliTrackPoint& AliTrackPoint::MasterToLocal() const
427 // Transform the space-point coordinates
428 // and the covariance matrix from the
429 // (master) to the local (tracking)
432 Float_t alpha = GetAngle();
433 return Rotate(alpha);
436 //_____________________________________________________________________________
437 void AliTrackPoint::Print(Option_t *) const
439 // Print the space-point coordinates and
442 printf("VolumeID=%d\n", GetVolumeID());
443 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
444 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
445 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);
450 //________________________________
451 void AliTrackPoint::SetAlignCovMatrix(const TMatrixDSym alignparmtrx){
452 // Add the uncertainty on the cluster position due to alignment
453 // (using the 6x6 AliAlignObj Cov. Matrix alignparmtrx) to the already
454 // present Cov. Matrix
462 cov(1,0)=cov(0,1)=fCov[1];
463 cov(2,0)=cov(0,2)=fCov[2];
465 cov(2,1)=cov(1,2)=fCov[4];
468 jacob(0,0) = 1; jacob(1,0) = 0; jacob(2,0) = 0;
469 jacob(0,1) = 0; jacob(1,1) = 1; jacob(2,1) = 0;
470 jacob(0,2) = 0; jacob(1,2) = 0; jacob(2,2) = 1;
471 jacob(0,3) = 0; jacob(1,3) =-fZ; jacob(2,3) = fY;
472 jacob(0,4) = fZ; jacob(1,4) = 0; jacob(2,4) =-fX;
473 jacob(0,5) = fY; jacob(1,5) = fX; jacob(2,5) = 0;
475 TMatrixD jacobT=jacob.T();jacob.T();
477 coval=jacob*alignparmtrx*jacobT+cov;
480 newcov[0]=coval(0,0);
481 newcov[1]=coval(1,0);
482 newcov[2]=coval(2,0);
483 newcov[3]=coval(1,1);
484 newcov[4]=coval(2,1);
485 newcov[5]=coval(2,2);
487 SetXYZ(fX,fY,fZ,newcov);