]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTrackPointArray.cxx
Record changes.
[u/mrichter/AliRoot.git] / STEER / AliTrackPointArray.cxx
CommitLineData
98937d93 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
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//////////////////////////////////////////////////////////////////////////////
24
46ae650f 25#include <TMath.h>
26#include <TMatrixDSym.h>
27
98937d93 28#include "AliTrackPointArray.h"
29
30ClassImp(AliTrackPointArray)
31
32//______________________________________________________________________________
33AliTrackPointArray::AliTrackPointArray()
34{
35 fNPoints = fSize = 0;
36 fX = fY = fZ = 0;
37 fVolumeID = 0;
38 fCov = 0;
39}
40
41//______________________________________________________________________________
42AliTrackPointArray::AliTrackPointArray(Int_t npoints):
43 fNPoints(npoints)
44{
45 // Constructor
46 //
47 fSize = 6*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];
53}
54
55//______________________________________________________________________________
56AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
57 TObject(array)
58{
59 // Copy constructor
60 //
61 fNPoints = array.fNPoints;
62 fSize = array.fSize;
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));
73}
74
75//_____________________________________________________________________________
76AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
77{
78 // assignment operator
79 //
80 if(this==&array) return *this;
81 ((TObject *)this)->operator=(array);
82
83 fNPoints = array.fNPoints;
84 fSize = array.fSize;
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));
95
96 return *this;
97}
98
99//______________________________________________________________________________
100AliTrackPointArray::~AliTrackPointArray()
101{
102 // Destructor
103 //
104 delete [] fX;
105 delete [] fY;
106 delete [] fZ;
107 delete [] fVolumeID;
108 delete [] fCov;
109}
110
111
112//______________________________________________________________________________
113Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
114{
115 // Add a point to the array at position i
116 //
117 if (i >= fNPoints) return kFALSE;
118 fX[i] = p->GetX();
119 fY[i] = p->GetY();
120 fZ[i] = p->GetZ();
121 fVolumeID[i] = p->GetVolumeID();
122 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
123 return kTRUE;
124}
125
126//______________________________________________________________________________
127Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
128{
129 // Get the point at position i
130 //
131 if (i >= fNPoints) return kFALSE;
132 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
133 p.SetVolumeID(fVolumeID[i]);
134 return kTRUE;
135}
136
137//______________________________________________________________________________
138Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
139{
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;
146
147 return check;
148}
149
150ClassImp(AliTrackPoint)
151
152//______________________________________________________________________________
153AliTrackPoint::AliTrackPoint()
154{
155 // Default constructor
156 //
157 fX = fY = fZ = 0;
158 fVolumeID = 0;
159 memset(fCov,0,6*sizeof(Float_t));
160}
161
162
163//______________________________________________________________________________
164AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid)
165{
166 // Constructor
167 //
168 SetXYZ(x,y,z,cov);
169 SetVolumeID(volid);
170}
171
172//______________________________________________________________________________
173AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid)
174{
175 // Constructor
176 //
177 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
178 SetVolumeID(volid);
179}
180
181//______________________________________________________________________________
182AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
183 TObject(p)
184{
185 // Copy constructor
186 //
187 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
188 SetVolumeID(p.fVolumeID);
189}
190
191//_____________________________________________________________________________
192AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
193{
194 // assignment operator
195 //
196 if(this==&p) return *this;
197 ((TObject *)this)->operator=(p);
198
199 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
200 SetVolumeID(p.fVolumeID);
201
202 return *this;
203}
204
205//______________________________________________________________________________
206void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
207{
208 // Set XYZ coordinates and their cov matrix
209 //
210 fX = x;
211 fY = y;
212 fZ = z;
213 if (cov)
214 memcpy(fCov,cov,6*sizeof(Float_t));
215}
216
217//______________________________________________________________________________
218void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
219{
220 // Set XYZ coordinates and their cov matrix
221 //
222 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
223}
224
225//______________________________________________________________________________
226void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
227{
228 xyz[0] = fX;
229 xyz[1] = fY;
230 xyz[2] = fZ;
231 if (cov)
232 memcpy(cov,fCov,6*sizeof(Float_t));
233}
46ae650f 234
235//______________________________________________________________________________
236Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
237{
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.
243
244 Float_t res = 0;
245
246 if (!weighted) {
247 Float_t xyz[3],xyzp[3];
248 GetXYZ(xyz);
249 p.GetXYZ(xyzp);
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]);
253 }
254 else {
255 Float_t xyz[3],xyzp[3];
256 Float_t cov[6],covp[6];
257 GetXYZ(xyz,cov);
258 TMatrixDSym mcov(3);
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];
262 p.GetXYZ(xyzp,covp);
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;
268 msum.Invert();
cc345ce3 269 // mcov.Print(); mcovp.Print(); msum.Print();
46ae650f 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);
274 }
275 }
276
277 return res;
278}
279
280//______________________________________________________________________________
281Float_t AliTrackPoint::GetAngle() const
282{
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.
287
8e52c1a8 288 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
289 if (fCov[1] > 0) {
290 phi = TMath::Pi() - phi;
291 if ((fY-fX) < 0) phi += TMath::Pi();
292 }
46ae650f 293 else {
8e52c1a8 294 if ((fX+fY) < 0) phi += TMath::Pi();
295 }
296
297 return phi;
298
46ae650f 299}
300
301//_____________________________________________________________________________
302AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
303{
304 // Transform the space-point coordinates
305 // and covariance matrix from global to
306 // local (detector plane) coordinate system
307 // XY plane rotation only
308
309 static AliTrackPoint p;
310 p = *this;
311
312 Float_t xyz[3],cov[6];
313 GetXYZ(xyz,cov);
314
315 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
316
317 Float_t newxyz[3],newcov[6];
318 newxyz[0] = cos*xyz[0] + sin*xyz[1];
319 newxyz[1] = cos*xyz[1] - sin*xyz[0];
320 newxyz[2] = xyz[2];
321
322 newcov[0] = cov[0]*cos*cos+
323 2*cov[1]*sin*cos+
324 cov[3]*sin*sin;
325 newcov[1] = cov[1]*(cos*cos-sin*sin)+
326 (cov[3]-cov[0])*sin*cos;
327 newcov[2] = cov[2]*cos+
328 cov[4]*sin;
329 newcov[3] = cov[0]*sin*sin-
330 2*cov[1]*sin*cos+
331 cov[3]*cos*cos;
332 newcov[4] = cov[4]*cos-
333 cov[2]*sin;
334 newcov[5] = cov[5];
335
336 p.SetXYZ(newxyz,newcov);
337 p.SetVolumeID(GetVolumeID());
338
339 return p;
340}
341
342//_____________________________________________________________________________
343AliTrackPoint& AliTrackPoint::MasterToLocal() const
344{
345 // Transform the space-point coordinates
346 // and the covariance matrix from the
347 // (master) to the local (tracking)
348 // coordinate system
349
350 Float_t alpha = GetAngle();
351 return Rotate(alpha);
352}
353
354//_____________________________________________________________________________
355void AliTrackPoint::Print(Option_t *) const
356{
357 // Print the space-point coordinates and
358 // covariance matrix
359
360 printf("VolumeID=%d\n", GetVolumeID());
361 printf("X = %12.6f Tx = %12.6f%12.6f%12.6f\n", fX, fCov[0], fCov[1], fCov[2]);
362 printf("Y = %12.6f Ty = %12.6f%12.6f%12.6f\n", fY, fCov[1], fCov[3], fCov[4]);
363 printf("Z = %12.6f Tz = %12.6f%12.6f%12.6f\n", fZ, fCov[2], fCov[4], fCov[5]);
364
365}