Remving, the info moved to READMEtrigger
[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//______________________________________________________________________________
fe12e09c 33AliTrackPointArray::AliTrackPointArray() :
34 TObject(),
35 fNPoints(0),
36 fX(0),
37 fY(0),
38 fZ(0),
39 fSize(0),
40 fCov(0),
41 fVolumeID(0)
98937d93 42{
98937d93 43}
44
45//______________________________________________________________________________
46AliTrackPointArray::AliTrackPointArray(Int_t npoints):
fe12e09c 47 TObject(),
48 fNPoints(npoints),
49 fX(new Float_t[npoints]),
50 fY(new Float_t[npoints]),
51 fZ(new Float_t[npoints]),
52 fSize(6*npoints),
53 fCov(new Float_t[fSize]),
54 fVolumeID(new UShort_t[npoints])
98937d93 55{
56 // Constructor
57 //
98937d93 58}
59
60//______________________________________________________________________________
61AliTrackPointArray::AliTrackPointArray(const AliTrackPointArray &array):
fe12e09c 62 TObject(array),
63 fNPoints(array.fNPoints),
64 fX(new Float_t[fNPoints]),
65 fY(new Float_t[fNPoints]),
66 fZ(new Float_t[fNPoints]),
67 fSize(array.fSize),
68 fCov(new Float_t[fSize]),
69 fVolumeID(new UShort_t[fNPoints])
98937d93 70{
71 // Copy constructor
72 //
98937d93 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));
78}
79
80//_____________________________________________________________________________
81AliTrackPointArray &AliTrackPointArray::operator =(const AliTrackPointArray& array)
82{
83 // assignment operator
84 //
85 if(this==&array) return *this;
86 ((TObject *)this)->operator=(array);
87
88 fNPoints = array.fNPoints;
89 fSize = array.fSize;
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));
100
101 return *this;
102}
103
104//______________________________________________________________________________
105AliTrackPointArray::~AliTrackPointArray()
106{
107 // Destructor
108 //
109 delete [] fX;
110 delete [] fY;
111 delete [] fZ;
112 delete [] fVolumeID;
113 delete [] fCov;
114}
115
116
117//______________________________________________________________________________
118Bool_t AliTrackPointArray::AddPoint(Int_t i, const AliTrackPoint *p)
119{
120 // Add a point to the array at position i
121 //
122 if (i >= fNPoints) return kFALSE;
123 fX[i] = p->GetX();
124 fY[i] = p->GetY();
125 fZ[i] = p->GetZ();
126 fVolumeID[i] = p->GetVolumeID();
127 memcpy(&fCov[6*i],p->GetCov(),6*sizeof(Float_t));
128 return kTRUE;
129}
130
131//______________________________________________________________________________
132Bool_t AliTrackPointArray::GetPoint(AliTrackPoint &p, Int_t i) const
133{
134 // Get the point at position i
135 //
136 if (i >= fNPoints) return kFALSE;
137 p.SetXYZ(fX[i],fY[i],fZ[i],&fCov[6*i]);
138 p.SetVolumeID(fVolumeID[i]);
139 return kTRUE;
140}
141
142//______________________________________________________________________________
143Bool_t AliTrackPointArray::HasVolumeID(UShort_t volid) const
144{
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;
151
152 return check;
153}
154
155ClassImp(AliTrackPoint)
156
157//______________________________________________________________________________
fe12e09c 158AliTrackPoint::AliTrackPoint() :
159 TObject(),
160 fX(0),
161 fY(0),
162 fZ(0),
163 fVolumeID(0)
98937d93 164{
165 // Default constructor
166 //
98937d93 167 memset(fCov,0,6*sizeof(Float_t));
168}
169
170
171//______________________________________________________________________________
fe12e09c 172AliTrackPoint::AliTrackPoint(Float_t x, Float_t y, Float_t z, const Float_t *cov, UShort_t volid) :
173 TObject(),
174 fX(0),
175 fY(0),
176 fZ(0),
177 fVolumeID(0)
98937d93 178{
179 // Constructor
180 //
181 SetXYZ(x,y,z,cov);
182 SetVolumeID(volid);
183}
184
185//______________________________________________________________________________
fe12e09c 186AliTrackPoint::AliTrackPoint(const Float_t *xyz, const Float_t *cov, UShort_t volid) :
187 TObject(),
188 fX(0),
189 fY(0),
190 fZ(0),
191 fVolumeID(0)
98937d93 192{
193 // Constructor
194 //
195 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
196 SetVolumeID(volid);
197}
198
199//______________________________________________________________________________
200AliTrackPoint::AliTrackPoint(const AliTrackPoint &p):
fe12e09c 201 TObject(p),
202 fX(0),
203 fY(0),
204 fZ(0),
205 fVolumeID(0)
98937d93 206{
207 // Copy constructor
208 //
209 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
210 SetVolumeID(p.fVolumeID);
211}
212
213//_____________________________________________________________________________
214AliTrackPoint &AliTrackPoint::operator =(const AliTrackPoint& p)
215{
216 // assignment operator
217 //
218 if(this==&p) return *this;
219 ((TObject *)this)->operator=(p);
220
221 SetXYZ(p.fX,p.fY,p.fZ,&(p.fCov[0]));
222 SetVolumeID(p.fVolumeID);
223
224 return *this;
225}
226
227//______________________________________________________________________________
228void AliTrackPoint::SetXYZ(Float_t x, Float_t y, Float_t z, const Float_t *cov)
229{
230 // Set XYZ coordinates and their cov matrix
231 //
232 fX = x;
233 fY = y;
234 fZ = z;
235 if (cov)
236 memcpy(fCov,cov,6*sizeof(Float_t));
237}
238
239//______________________________________________________________________________
240void AliTrackPoint::SetXYZ(const Float_t *xyz, const Float_t *cov)
241{
242 // Set XYZ coordinates and their cov matrix
243 //
244 SetXYZ(xyz[0],xyz[1],xyz[2],cov);
245}
246
247//______________________________________________________________________________
248void AliTrackPoint::GetXYZ(Float_t *xyz, Float_t *cov) const
249{
250 xyz[0] = fX;
251 xyz[1] = fY;
252 xyz[2] = fZ;
253 if (cov)
254 memcpy(cov,fCov,6*sizeof(Float_t));
255}
46ae650f 256
257//______________________________________________________________________________
258Float_t AliTrackPoint::GetResidual(const AliTrackPoint &p, Bool_t weighted) const
259{
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.
265
266 Float_t res = 0;
267
268 if (!weighted) {
269 Float_t xyz[3],xyzp[3];
270 GetXYZ(xyz);
271 p.GetXYZ(xyzp);
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]);
275 }
276 else {
277 Float_t xyz[3],xyzp[3];
278 Float_t cov[6],covp[6];
279 GetXYZ(xyz,cov);
280 TMatrixDSym mcov(3);
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];
284 p.GetXYZ(xyzp,covp);
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;
290 msum.Invert();
cc345ce3 291 // mcov.Print(); mcovp.Print(); msum.Print();
46ae650f 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);
296 }
297 }
298
299 return res;
300}
301
302//______________________________________________________________________________
303Float_t AliTrackPoint::GetAngle() const
304{
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.
309
8e52c1a8 310 Float_t phi= TMath::ATan2(TMath::Sqrt(fCov[0]),TMath::Sqrt(fCov[3]));
311 if (fCov[1] > 0) {
312 phi = TMath::Pi() - phi;
313 if ((fY-fX) < 0) phi += TMath::Pi();
314 }
46ae650f 315 else {
8e52c1a8 316 if ((fX+fY) < 0) phi += TMath::Pi();
317 }
318
319 return phi;
320
46ae650f 321}
322
323//_____________________________________________________________________________
324AliTrackPoint& AliTrackPoint::Rotate(Float_t alpha) const
325{
326 // Transform the space-point coordinates
327 // and covariance matrix from global to
328 // local (detector plane) coordinate system
329 // XY plane rotation only
330
331 static AliTrackPoint p;
332 p = *this;
333
334 Float_t xyz[3],cov[6];
335 GetXYZ(xyz,cov);
336
337 Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
338
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];
342 newxyz[2] = xyz[2];
343
344 newcov[0] = cov[0]*cos*cos+
345 2*cov[1]*sin*cos+
346 cov[3]*sin*sin;
347 newcov[1] = cov[1]*(cos*cos-sin*sin)+
348 (cov[3]-cov[0])*sin*cos;
349 newcov[2] = cov[2]*cos+
350 cov[4]*sin;
351 newcov[3] = cov[0]*sin*sin-
352 2*cov[1]*sin*cos+
353 cov[3]*cos*cos;
354 newcov[4] = cov[4]*cos-
355 cov[2]*sin;
356 newcov[5] = cov[5];
357
358 p.SetXYZ(newxyz,newcov);
359 p.SetVolumeID(GetVolumeID());
360
361 return p;
362}
363
364//_____________________________________________________________________________
365AliTrackPoint& AliTrackPoint::MasterToLocal() const
366{
367 // Transform the space-point coordinates
368 // and the covariance matrix from the
369 // (master) to the local (tracking)
370 // coordinate system
371
372 Float_t alpha = GetAngle();
373 return Rotate(alpha);
374}
375
376//_____________________________________________________________________________
377void AliTrackPoint::Print(Option_t *) const
378{
379 // Print the space-point coordinates and
380 // covariance matrix
381
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]);
386
387}