Added check for ppad[1] range
[u/mrichter/AliRoot.git] / TPC / AliTPCtrack.cxx
CommitLineData
73042f01 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
73042f01 16//-----------------------------------------------------------------
17// Implementation of the TPC track class
18//
19// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
20//-----------------------------------------------------------------
21
b19a0509 22#include <iostream.h>
23
73042f01 24#include "AliTPCtrack.h"
25#include "AliTPCcluster.h"
26#include "AliTPCClustersRow.h"
27#include "AliTPCClustersArray.h"
28
29ClassImp(AliTPCtrack)
b9de75e1 30
73042f01 31//_________________________________________________________________________
32AliTPCtrack::AliTPCtrack(UInt_t index, const Double_t xx[5],
b19a0509 33const Double_t cc[15], Double_t xref, Double_t alpha) : AliKalmanTrack() {
73042f01 34 //-----------------------------------------------------------------
35 // This is the main track constructor.
36 //-----------------------------------------------------------------
73042f01 37 fX=xref;
be9c5115 38 fAlpha=alpha;
39 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
40 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
41 fdEdx=0.;
73042f01 42
b19a0509 43 fP0=xx[0]; fP1=xx[1]; fP2=xx[2]; fP3=xx[3]; fP4=xx[4];
73042f01 44
b19a0509 45 fC00=cc[0];
46 fC10=cc[1]; fC11=cc[2];
47 fC20=cc[3]; fC21=cc[4]; fC22=cc[5];
48 fC30=cc[6]; fC31=cc[7]; fC32=cc[8]; fC33=cc[9];
49 fC40=cc[10]; fC41=cc[11]; fC42=cc[12]; fC43=cc[13]; fC44=cc[14];
73042f01 50
be9c5115 51 fIndex[0]=index;
52 SetNumberOfClusters(1);
b9de75e1 53
54}
55
56//_____________________________________________________________________________
57AliTPCtrack::AliTPCtrack(const AliKalmanTrack& t,Double_t alpha) {
58 //-----------------------------------------------------------------
59 // Conversion AliKalmanTrack -> AliTPCtrack.
60 //-----------------------------------------------------------------
61 SetLabel(t.GetLabel());
62 SetChi2(0.);
63 SetNumberOfClusters(0);
64 //SetConvConst(t.GetConvConst());
65
66 fdEdx = 0.;
67 fAlpha = alpha;
68 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
69 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
70
71 //Conversion of the track parameters
72 Double_t x,p[5]; t.GetExternalParameters(x,p);
73 fX=x; x=GetConvConst();
74 fP0=p[0];
75 fP1=p[1];
76 fP3=p[3];
77 fP4=p[4]/x;
78 fP2=fP4*fX - p[2];
79
80 //Conversion of the covariance matrix
81 Double_t c[15]; t.GetExternalCovariance(c);
82 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
83
84 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
85 Double_t c32=fX*c[13] - c[8];
86 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
87
88 fC00=c[0 ];
89 fC10=c[1 ]; fC11=c[2 ];
90 fC20=c20; fC21=c21; fC22=c22;
91 fC30=c[6 ]; fC31=c[7 ]; fC32=c32; fC33=c[9 ];
92 fC40=c[10]; fC41=c[11]; fC42=c42; fC43=c[13]; fC44=c[14];
93
73042f01 94}
95
96//_____________________________________________________________________________
b19a0509 97AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) : AliKalmanTrack(t) {
73042f01 98 //-----------------------------------------------------------------
99 // This is a track copy constructor.
100 //-----------------------------------------------------------------
be9c5115 101 fX=t.fX;
102 fAlpha=t.fAlpha;
73042f01 103 fdEdx=t.fdEdx;
104
be9c5115 105 fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;
106
107 fC00=t.fC00;
108 fC10=t.fC10; fC11=t.fC11;
109 fC20=t.fC20; fC21=t.fC21; fC22=t.fC22;
110 fC30=t.fC30; fC31=t.fC31; fC32=t.fC32; fC33=t.fC33;
111 fC40=t.fC40; fC41=t.fC41; fC42=t.fC42; fC43=t.fC43; fC44=t.fC44;
112
113 Int_t n=GetNumberOfClusters();
114 for (Int_t i=0; i<n; i++) fIndex[i]=t.fIndex[i];
115}
116
117//_____________________________________________________________________________
118Int_t AliTPCtrack::Compare(const TObject *o) const {
119 //-----------------------------------------------------------------
120 // This function compares tracks according to the their curvature
121 //-----------------------------------------------------------------
122 AliTPCtrack *t=(AliTPCtrack*)o;
123 Double_t co=TMath::Abs(t->Get1Pt());
124 Double_t c =TMath::Abs(Get1Pt());
125 if (c>co) return 1;
126 else if (c<co) return -1;
127 return 0;
128}
129
130//_____________________________________________________________________________
131void AliTPCtrack::GetExternalCovariance(Double_t cc[15]) const {
132 //-------------------------------------------------------------------------
133 // This function returns an external representation of the covriance matrix.
134 // (See comments in AliTPCtrack.h about external track representation)
135 //-------------------------------------------------------------------------
9b280d80 136 Double_t a=GetConvConst();
be9c5115 137
b9de75e1 138 Double_t c22=fX*fX*fC44-2*fX*fC42+fC22;
139 Double_t c32=fX*fC43-fC32;
140 Double_t c20=fX*fC40-fC20, c21=fX*fC41-fC21, c42=fX*fC44-fC42;
be9c5115 141
142 cc[0 ]=fC00;
143 cc[1 ]=fC10; cc[2 ]=fC11;
144 cc[3 ]=c20; cc[4 ]=c21; cc[5 ]=c22;
b9de75e1 145 cc[6 ]=fC30; cc[7 ]=fC31; cc[8 ]=c32; cc[9 ]=fC33;
146 cc[10]=fC40*a; cc[11]=fC41*a; cc[12]=c42*a; cc[13]=fC43*a; cc[14]=fC44*a*a;
be9c5115 147
148}
149
150//_____________________________________________________________________________
151Double_t AliTPCtrack::GetPredictedChi2(const AliCluster *c) const
152{
153 //-----------------------------------------------------------------
154 // This function calculates a predicted chi2 increment.
155 //-----------------------------------------------------------------
156 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
157 r00+=fC00; r01+=fC10; r11+=fC11;
158
159 Double_t det=r00*r11 - r01*r01;
160 if (TMath::Abs(det) < 1.e-10) {
161 Int_t n=GetNumberOfClusters();
162 if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
163 return 1e10;
164 }
165 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
166
167 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
168
169 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
73042f01 170}
171
172//_____________________________________________________________________________
173Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
174{
175 //-----------------------------------------------------------------
176 // This function propagates a track to a reference plane x=xk.
177 //-----------------------------------------------------------------
b9de75e1 178 if (TMath::Abs(fP4*xk - fP2) >= 0.99999) {
be9c5115 179 Int_t n=GetNumberOfClusters();
180 if (n>4) cerr<<n<<" AliTPCtrack warning: Propagation failed !\n";
73042f01 181 return 0;
182 }
183
b19a0509 184 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
b9de75e1 185 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
186 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
73042f01 187
b19a0509 188 fP0 += dx*(c1+c2)/(r1+r2);
b9de75e1 189 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
73042f01 190
191 //f = F - 1
192 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
b19a0509 193 Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
b9de75e1 194 Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
73042f01 195 Double_t cr=c1*r2+c2*r1;
b9de75e1 196 Double_t f12=-dx*fP3*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
197 Double_t f13= dx*cc/cr;
198 Double_t f14=dx*fP3*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
73042f01 199
200 //b = C*ft
b9de75e1 201 Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
202 Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
203 Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
204 Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
205 Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
73042f01 206
207 //a = f*b = f*C*ft
b9de75e1 208 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
73042f01 209
210 //F*C*Ft = C + (a + b + bt)
b19a0509 211 fC00 += a00 + 2*b00;
212 fC10 += a01 + b01 + b10;
213 fC20 += b20;
214 fC30 += b30;
215 fC40 += b40;
216 fC11 += a11 + 2*b11;
217 fC21 += b21;
218 fC31 += b31;
219 fC41 += b41;
73042f01 220
221 fX=x2;
222
223 //Multiple scattering******************
b19a0509 224 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fP0)*(y1-fP0)+(z1-fP1)*(z1-fP1));
be9c5115 225 Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
73042f01 226 Double_t beta2=p2/(p2 + pm*pm);
be9c5115 227 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
b19a0509 228 //Double_t theta2=1.0259e-6*10*10/20/(beta2*p2)*d*rho;
73042f01 229
b9de75e1 230 Double_t ey=fP4*fX - fP2, ez=fP3;
231 Double_t xz=fP4*ez, zz1=ez*ez+1, xy=fP2+ey;
73042f01 232
b19a0509 233 fC22 += (2*ey*ez*ez*fP2+1-ey*ey+ez*ez+fP2*fP2*ez*ez)*theta2;
b9de75e1 234 fC32 += ez*zz1*xy*theta2;
235 fC33 += zz1*zz1*theta2;
236 fC42 += xz*ez*xy*theta2;
237 fC43 += xz*zz1*theta2;
238 fC44 += xz*xz*theta2;
73042f01 239
240 //Energy losses************************
241 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
242 if (x1 < x2) dE=-dE;
b9de75e1 243 cc=fP4;
244 fP4*=(1.- sqrt(p2+pm*pm)/p2*dE);
245 fP2+=fX*(fP4-cc);
73042f01 246
247 return 1;
248}
249
250//_____________________________________________________________________________
b19a0509 251Int_t AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm)
73042f01 252{
253 //-----------------------------------------------------------------
254 // This function propagates tracks to the "vertex".
255 //-----------------------------------------------------------------
b9de75e1 256 Double_t c=fP4*fX - fP2;
257 Double_t tgf=-fP2/(fP4*fP0 + sqrt(1-c*c));
73042f01 258 Double_t snf=tgf/sqrt(1.+ tgf*tgf);
b9de75e1 259 Double_t xv=(fP2+snf)/fP4;
b19a0509 260 return PropagateTo(xv,x0,rho,pm);
73042f01 261}
262
263//_____________________________________________________________________________
be9c5115 264Int_t AliTPCtrack::Update(const AliCluster *c, Double_t chisq, UInt_t index) {
73042f01 265 //-----------------------------------------------------------------
266 // This function associates a cluster with this track.
267 //-----------------------------------------------------------------
268 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
b19a0509 269 r00+=fC00; r01+=fC10; r11+=fC11;
73042f01 270 Double_t det=r00*r11 - r01*r01;
271 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
272
b19a0509 273 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
274 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
275 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
276 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
277 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
73042f01 278
b19a0509 279 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
b9de75e1 280 Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
73042f01 281 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
be9c5115 282 Int_t n=GetNumberOfClusters();
283 if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
284 return 0;
73042f01 285 }
286
b19a0509 287 fP0 += k00*dy + k01*dz;
288 fP1 += k10*dy + k11*dz;
289 fP2 = eta;
b9de75e1 290 fP3 += k30*dy + k31*dz;
291 fP4 = cur;
73042f01 292
b19a0509 293 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
294 Double_t c12=fC21, c13=fC31, c14=fC41;
73042f01 295
b19a0509 296 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
297 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
298 fC40-=k00*c04+k01*c14;
73042f01 299
b19a0509 300 fC11-=k10*c01+k11*fC11;
301 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
302 fC41-=k10*c04+k11*c14;
73042f01 303
b19a0509 304 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
305 fC42-=k20*c04+k21*c14;
73042f01 306
b19a0509 307 fC33-=k30*c03+k31*c13;
b9de75e1 308 fC43-=k40*c03+k41*c13;
73042f01 309
b19a0509 310 fC44-=k40*c04+k41*c14;
73042f01 311
be9c5115 312 Int_t n=GetNumberOfClusters();
313 fIndex[n]=index;
314 SetNumberOfClusters(n+1);
315 SetChi2(GetChi2()+chisq);
316
317 return 1;
73042f01 318}
319
320//_____________________________________________________________________________
321Int_t AliTPCtrack::Rotate(Double_t alpha)
322{
323 //-----------------------------------------------------------------
324 // This function rotates this track.
325 //-----------------------------------------------------------------
326 fAlpha += alpha;
be9c5115 327 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
328 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
73042f01 329
b19a0509 330 Double_t x1=fX, y1=fP0;
73042f01 331 Double_t ca=cos(alpha), sa=sin(alpha);
b9de75e1 332 Double_t r1=fP4*fX - fP2;
73042f01 333
334 fX = x1*ca + y1*sa;
b19a0509 335 fP0=-x1*sa + y1*ca;
b9de75e1 336 fP2=fP2*ca + (fP4*y1 + sqrt(1.- r1*r1))*sa;
73042f01 337
b9de75e1 338 Double_t r2=fP4*fX - fP2;
73042f01 339 if (TMath::Abs(r2) >= 0.99999) {
be9c5115 340 Int_t n=GetNumberOfClusters();
341 if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !\n";
73042f01 342 return 0;
343 }
344
b9de75e1 345 Double_t y0=fP0 + sqrt(1.- r2*r2)/fP4;
346 if ((fP0-y0)*fP4 >= 0.) {
be9c5115 347 Int_t n=GetNumberOfClusters();
348 if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !!!\n";
73042f01 349 return 0;
350 }
351
352 //f = F - 1
b9de75e1 353 Double_t f00=ca-1, f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
354 f20=fP4*sa, f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
73042f01 355
356 //b = C*ft
b9de75e1 357 Double_t b00=fC00*f00, b02=fC00*f20+fC40*f24+fC20*f22;
358 Double_t b10=fC10*f00, b12=fC10*f20+fC41*f24+fC21*f22;
359 Double_t b20=fC20*f00, b22=fC20*f20+fC42*f24+fC22*f22;
360 Double_t b30=fC30*f00, b32=fC30*f20+fC43*f24+fC32*f22;
361 Double_t b40=fC40*f00, b42=fC40*f20+fC44*f24+fC42*f22;
73042f01 362
363 //a = f*b = f*C*ft
b9de75e1 364 Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
73042f01 365
366 // *** Double_t dy2=fCyy;
367
368 //F*C*Ft = C + (a + b + bt)
b19a0509 369 fC00 += a00 + 2*b00;
370 fC10 += b10;
371 fC20 += a02+b20+b02;
372 fC30 += b30;
373 fC40 += b40;
374 fC21 += b12;
375 fC32 += b32;
376 fC22 += a22 + 2*b22;
377 fC42 += b42;
73042f01 378
379 // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
380 // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
381
382 return 1;
383}
384
b9de75e1 385void AliTPCtrack::ResetCovariance() {
386 //------------------------------------------------------------------
387 //This function makes a track forget its history :)
388 //------------------------------------------------------------------
389
390 fC00*=10.;
391 fC10=0.; fC11*=10.;
392 fC20=0.; fC21=0.; fC22*=10.;
393 fC30=0.; fC31=0.; fC32=0.; fC33*=10.;
394 fC40=0.; fC41=0.; fC42=0.; fC43=0.; fC44*=10.;
395
73042f01 396}