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()
41 //______________________________________________________________________________
42 AliTrackPointArray::AliTrackPointArray(Int_t npoints):
48 fX = new Float_t[npoints];
49 fY = new Float_t[npoints];
50 fZ = new Float_t[npoints];
51 fVolumeID = new UShort_t[npoints];
52 fCov = new Float_t[fSize];
55 //______________________________________________________________________________
56 AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
61 fNPoints = array.fNPoints;
63 fX = new Float_t[fNPoints];
64 fY = new Float_t[fNPoints];
65 fZ = new Float_t[fNPoints];
66 fVolumeID = new UShort_t[fNPoints];
67 fCov = new Float_t[fSize];
68 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
69 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
70 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
71 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
72 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
75 //_____________________________________________________________________________
76 AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
78 // assignment operator
80 if(this==&array) return *this;
81 ((TObject *)this)->operator=(array);
83 fNPoints = array.fNPoints;
85 fX = new Float_t[fNPoints];
86 fY = new Float_t[fNPoints];
87 fZ = new Float_t[fNPoints];
88 fVolumeID = new UShort_t[fNPoints];
89 fCov = new Float_t[fSize];
90 memcpy(fX,array.fX,fNPoints*sizeof(Float_t));
91 memcpy(fY,array.fY,fNPoints*sizeof(Float_t));
92 memcpy(fZ,array.fZ,fNPoints*sizeof(Float_t));
93 memcpy(fVolumeID,array.fVolumeID,fNPoints*sizeof(UShort_t));
94 memcpy(fCov,array.fCov,fSize*sizeof(Float_t));
99 //______________________________________________________________________________
100 AliTrackPointArray::~AliTrackPointArray()
112 //______________________________________________________________________________
113 Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
115 // Add a point to the array at position i
117 if (i >= fNPoints) return kFALSE;
121 fVolumeID[i] = p->GetVolumeID();
122 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
126 //______________________________________________________________________________
127 Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
129 // Get the point at position i
131 if (i >= fNPoints) return kFALSE;
132 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
133 p.SetVolumeID(fVolumeID[i]);
137 //______________________________________________________________________________
138 Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
140 // This method checks if the array
141 // has at least one hit in the detector
142 // volume defined by volid
143 Bool_t check = kFALSE;
144 for (Int_t ipoint = 0; ipoint < fNPoints; ipoint++)
145 if (fVolumeID[ipoint] == volid) check = kTRUE;
150 ClassImp(AliTrackPoint)
152 //______________________________________________________________________________
153 AliTrackPoint::AliTrackPoint()
155 // Default constructor
159 memset(fCov,0,6*sizeof(Float_t));
163 //______________________________________________________________________________
164 AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid)
172 //______________________________________________________________________________
173 AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid)
177 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
181 //______________________________________________________________________________
182 AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
187 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
188 SetVolumeID(p.fVolumeID);
191 //_____________________________________________________________________________
192 AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
194 // assignment operator
196 if(this==&p) return *this;
197 ((TObject *)this)->operator=(p);
199 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
200 SetVolumeID(p.fVolumeID);
205 //______________________________________________________________________________
206 void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
208 // Set XYZ coordinates and their cov matrix
214 memcpy(fCov,cov,6*sizeof(Float_t));
217 //______________________________________________________________________________
218 void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
220 // Set XYZ coordinates and their cov matrix
222 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
225 //______________________________________________________________________________
226 void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
232 memcpy(cov,fCov,6*sizeof(Float_t));
235 //______________________________________________________________________________
236 Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
238 // This method calculates the track to space-point residuals. The track
239 // interpolation is also stored as AliTrackPoint. Using the option
240 // 'weighted' one can calculate the residual either with or without
241 // taking into account the covariance matrix of the space-point and
242 // track interpolation. The second case the residual becomes a pull.
247 Float_t xyz[3],xyzp[3];
250 res = (xyz[0]-xyzp[0])*(xyz[0]-xyzp[0])+
251 (xyz[1]-xyzp[1])*(xyz[1]-xyzp[1])+
252 (xyz[2]-xyzp[2])*(xyz[2]-xyzp[2]);
255 Float_t xyz[3],xyzp[3];
256 Float_t cov[6],covp[6];
259 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
260 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
261 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
263 TMatrixDSym mcovp(3);
264 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
265 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
266 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
267 TMatrixDSym msum = mcov + mcovp;
269 // mcov.Print(); mcovp.Print(); msum.Print();
270 if (msum.IsValid()) {
271 for (Int_t i = 0; i < 3; i++)
272 for (Int_t j = 0; j < 3; j++)
273 res += (xyz[i]-xyzp[i])*(xyz[j]-xyzp[j])*msum(i,j);
280 //______________________________________________________________________________
281 Float_t AliTrackPoint::GetAngle() const
283 // The method uses the covariance matrix of
284 // the space-point in order to extract the
285 // orientation of the detector plane.
286 // The rotation in XY plane only is calculated.
288 if ((fCov[2] != 0) || (fCov[4] != 0))
289 return TMath::ATan2(-fCov[4],-fCov[2]);
291 if (fCov[1] == 0) return 0;
292 Float_t phi= TMath::ATan2(TMath::Abs(fCov[1]),fCov[3]);
294 phi += TMath::PiOver2();
295 if ((fY-fX) < 0) phi += TMath::Pi();
298 if ((fX+fY) < 0) phi += TMath::Pi();
302 // return TMath::ATan2(TMath::Sign((Float_t)1.0,fY)*TMath::Abs(fCov[1]),
303 // TMath::Sign((Float_t)1.0,fX)*fCov[3]);
306 //_____________________________________________________________________________
307 AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
309 // Transform the space-point coordinates
310 // and covariance matrix from global to
311 // local (detector plane) coordinate system
312 // XY plane rotation only
314 static AliTrackPoint p;
317 Float_t xyz[3],cov[6];
320 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
322 Float_t newxyz[3],newcov[6];
323 newxyz[0] = cos*xyz[0] + sin*xyz[1];
324 newxyz[1] = cos*xyz[1] - sin*xyz[0];
327 newcov[0] = cov[0]*cos*cos+
330 newcov[1] = cov[1]*(cos*cos-sin*sin)+
331 (cov[3]-cov[0])*sin*cos;
332 newcov[2] = cov[2]*cos+
334 newcov[3] = cov[0]*sin*sin-
337 newcov[4] = cov[4]*cos-
341 p.SetXYZ(newxyz,newcov);
342 p.SetVolumeID(GetVolumeID());
347 //_____________________________________________________________________________
348 AliTrackPoint& AliTrackPoint::MasterToLocal() const
350 // Transform the space-point coordinates
351 // and the covariance matrix from the
352 // (master) to the local (tracking)
355 Float_t alpha = GetAngle();
356 return Rotate(alpha);
359 //_____________________________________________________________________________
360 void AliTrackPoint::Print(Option_t *) const
362 // Print the space-point coordinates and
365 printf("VolumeID=%d\n", GetVolumeID());
366 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
367 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
368 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);