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 //////////////////////////////////////////////////////////////////////////////
26 #include <TMatrixDSym.h>
28 #include "AliTrackPointArray.h"
30 ClassImp(AliTrackPointArray)
32 //______________________________________________________________________________
33 AliTrackPointArray::AliTrackPointArray() :
45 //______________________________________________________________________________
46 AliTrackPointArray::AliTrackPointArray(Int_t npoints):
49 fX(new Float_t[npoints]),
50 fY(new Float_t[npoints]),
51 fZ(new Float_t[npoints]),
53 fCov(new Float_t[fSize]),
54 fVolumeID(new UShort_t[npoints])
60 //______________________________________________________________________________
61 AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
63 fNPoints(array.fNPoints),
64 fX(new Float_t[fNPoints]),
65 fY(new Float_t[fNPoints]),
66 fZ(new Float_t[fNPoints]),
68 fCov(new Float_t[fSize]),
69 fVolumeID(new UShort_t[fNPoints])
73 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
74 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
75 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
76 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
77 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
80 //_____________________________________________________________________________
81 AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
83 // assignment operator
85 if(this==&array) return *this;
86 ((TObject *)this)->operator=(array);
88 fNPoints = array.fNPoints;
90 fX = new Float_t[fNPoints];
91 fY = new Float_t[fNPoints];
92 fZ = new Float_t[fNPoints];
93 fVolumeID = new UShort_t[fNPoints];
94 fCov = new Float_t[fSize];
95 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
96 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
97 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
98 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
99 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
104 //______________________________________________________________________________
105 AliTrackPointArray::~AliTrackPointArray()
117 //______________________________________________________________________________
118 Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
120 // Add a point to the array at position i
122 if (i >= fNPoints) return kFALSE;
126 fVolumeID[i] = p->GetVolumeID();
127 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
131 //______________________________________________________________________________
132 Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
134 // Get the point at position i
136 if (i >= fNPoints) return kFALSE;
137 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
138 p.SetVolumeID(fVolumeID[i]);
142 //______________________________________________________________________________
143 Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
145 // This method checks if the array
146 // has at least one hit in the detector
147 // volume defined by volid
148 Bool_t check = kFALSE;
149 for (Int_t ipoint = 0; ipoint < fNPoints; ipoint++)
150 if (fVolumeID[ipoint] == volid) check = kTRUE;
155 ClassImp(AliTrackPoint)
157 //______________________________________________________________________________
158 AliTrackPoint::AliTrackPoint() :
165 // Default constructor
167 memset(fCov,0,6*sizeof(Float_t));
171 //______________________________________________________________________________
172 AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid) :
185 //______________________________________________________________________________
186 AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid) :
195 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
199 //______________________________________________________________________________
200 AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
209 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
210 SetVolumeID(p.fVolumeID);
213 //_____________________________________________________________________________
214 AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
216 // assignment operator
218 if(this==&p) return *this;
219 ((TObject *)this)->operator=(p);
221 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
222 SetVolumeID(p.fVolumeID);
227 //______________________________________________________________________________
228 void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
230 // Set XYZ coordinates and their cov matrix
236 memcpy(fCov,cov,6*sizeof(Float_t));
239 //______________________________________________________________________________
240 void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
242 // Set XYZ coordinates and their cov matrix
244 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
247 //______________________________________________________________________________
248 void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
254 memcpy(cov,fCov,6*sizeof(Float_t));
257 //______________________________________________________________________________
258 Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
260 // This method calculates the track to space-point residuals. The track
261 // interpolation is also stored as AliTrackPoint. Using the option
262 // 'weighted' one can calculate the residual either with or without
263 // taking into account the covariance matrix of the space-point and
264 // track interpolation. The second case the residual becomes a pull.
269 Float_t xyz[3],xyzp[3];
272 res = (xyz[0]-xyzp[0])*(xyz[0]-xyzp[0])+
273 (xyz[1]-xyzp[1])*(xyz[1]-xyzp[1])+
274 (xyz[2]-xyzp[2])*(xyz[2]-xyzp[2]);
277 Float_t xyz[3],xyzp[3];
278 Float_t cov[6],covp[6];
281 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
282 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
283 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
285 TMatrixDSym mcovp(3);
286 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
287 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
288 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
289 TMatrixDSym msum = mcov + mcovp;
291 // mcov.Print(); mcovp.Print(); msum.Print();
292 if (msum.IsValid()) {
293 for (Int_t i = 0; i < 3; i++)
294 for (Int_t j = 0; j < 3; j++)
295 res += (xyz[i]-xyzp[i])*(xyz[j]-xyzp[j])*msum(i,j);
302 //______________________________________________________________________________
303 Float_t AliTrackPoint::GetAngle() const
305 // The method uses the covariance matrix of
306 // the space-point in order to extract the
307 // orientation of the detector plane.
308 // The rotation in XY plane only is calculated.
310 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
312 phi = TMath::Pi() - phi;
313 if ((fY-fX) < 0) phi += TMath::Pi();
316 if ((fX+fY) < 0) phi += TMath::Pi();
323 //_____________________________________________________________________________
324 AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
326 // Transform the space-point coordinates
327 // and covariance matrix from global to
328 // local (detector plane) coordinate system
329 // XY plane rotation only
331 static AliTrackPoint p;
334 Float_t xyz[3],cov[6];
337 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
339 Float_t newxyz[3],newcov[6];
340 newxyz[0] = cos*xyz[0] + sin*xyz[1];
341 newxyz[1] = cos*xyz[1] - sin*xyz[0];
344 newcov[0] = cov[0]*cos*cos+
347 newcov[1] = cov[1]*(cos*cos-sin*sin)+
348 (cov[3]-cov[0])*sin*cos;
349 newcov[2] = cov[2]*cos+
351 newcov[3] = cov[0]*sin*sin-
354 newcov[4] = cov[4]*cos-
358 p.SetXYZ(newxyz,newcov);
359 p.SetVolumeID(GetVolumeID());
364 //_____________________________________________________________________________
365 AliTrackPoint& AliTrackPoint::MasterToLocal() const
367 // Transform the space-point coordinates
368 // and the covariance matrix from the
369 // (master) to the local (tracking)
372 Float_t alpha = GetAngle();
373 return Rotate(alpha);
376 //_____________________________________________________________________________
377 void AliTrackPoint::Print(Option_t *) const
379 // Print the space-point coordinates and
382 printf("VolumeID=%d\n", GetVolumeID());
383 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
384 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
385 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);