Missing constant included.
[u/mrichter/AliRoot.git] / TRD / AliTRDtrack.cxx
CommitLineData
46d29e70 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
0fa7dfa7 16/* $Id$ */
46d29e70 17
a2cb5b3d 18#include <Riostream.h>
5443e65e 19#include <TObject.h>
46d29e70 20
46d29e70 21#include "AliTRDgeometry.h"
22#include "AliTRDcluster.h"
23#include "AliTRDtrack.h"
5443e65e 24#include "../TPC/AliTPCtrack.h"
79e94bf8 25#include "AliESDtrack.h"
46d29e70 26
b3a5a838 27
46d29e70 28ClassImp(AliTRDtrack)
29
30
31//_____________________________________________________________________________
32
a819a5f7 33AliTRDtrack::AliTRDtrack(const AliTRDcluster *c, UInt_t index,
5443e65e 34 const Double_t xx[5], const Double_t cc[15],
35 Double_t xref, Double_t alpha) : AliKalmanTrack() {
46d29e70 36 //-----------------------------------------------------------------
37 // This is the main track constructor.
38 //-----------------------------------------------------------------
5443e65e 39
40 fSeedLab = -1;
46d29e70 41
42 fAlpha=alpha;
5443e65e 43 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
44 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
45
46d29e70 46 fX=xref;
47
b3a5a838 48 fY=xx[0]; fZ=xx[1]; fE=xx[2]; fT=xx[3]; fC=xx[4];
46d29e70 49
50 fCyy=cc[0];
51 fCzy=cc[1]; fCzz=cc[2];
b3a5a838 52 fCey=cc[3]; fCez=cc[4]; fCee=cc[5];
53 fCty=cc[6]; fCtz=cc[7]; fCte=cc[8]; fCtt=cc[9];
b8dc2353 54 fCcy=cc[10]; fCcz=cc[11]; fCce=cc[12]; fCct=cc[13]; fCcc=cc[14];
55
5443e65e 56 fIndex[0]=index;
57 SetNumberOfClusters(1);
58
59 fdEdx=0.;
a2b90f83 60
b3a5a838 61 fLhElectron = 0.0;
9c9d2487 62 fNWrong = 0;
63 fNRotate = 0;
b3a5a838 64
5443e65e 65 Double_t q = TMath::Abs(c->GetQ());
a819a5f7 66 Double_t s = fX*fC - fE, t=fT;
5443e65e 67 if(s*s < 1) q *= TMath::Sqrt((1-s*s)/(1+t*t));
68
69 fdQdl[0] = q;
0d5b5c27 70
71 // initialisation [SR, GSI 18.02.2003] (i startd for 1)
73ae7b59 72 for(UInt_t i=1; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 73 fdQdl[i] = 0;
74 fIndex[i] = 0;
75 }
46d29e70 76}
77
78//_____________________________________________________________________________
5443e65e 79AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) : AliKalmanTrack(t) {
46d29e70 80 //
81 // Copy constructor.
82 //
b8dc2353 83
5443e65e 84 SetLabel(t.GetLabel());
85 fSeedLab=t.GetSeedLabel();
46d29e70 86
5443e65e 87 SetChi2(t.GetChi2());
46d29e70 88 fdEdx=t.fdEdx;
89
b3a5a838 90 fLhElectron = 0.0;
9c9d2487 91 fNWrong = t.fNWrong;
92 fNRotate = t.fNRotate;
b3a5a838 93
46d29e70 94 fAlpha=t.fAlpha;
95 fX=t.fX;
96
b8dc2353 97 fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
46d29e70 98
99 fCyy=t.fCyy;
100 fCzy=t.fCzy; fCzz=t.fCzz;
b3a5a838 101 fCey=t.fCey; fCez=t.fCez; fCee=t.fCee;
102 fCty=t.fCty; fCtz=t.fCtz; fCte=t.fCte; fCtt=t.fCtt;
b8dc2353 103 fCcy=t.fCcy; fCcz=t.fCcz; fCce=t.fCce; fCct=t.fCct; fCcc=t.fCcc;
46d29e70 104
5443e65e 105 Int_t n=t.GetNumberOfClusters();
106 SetNumberOfClusters(n);
107 for (Int_t i=0; i<n; i++) {
a819a5f7 108 fIndex[i]=t.fIndex[i];
109 fdQdl[i]=t.fdQdl[i];
110 }
b8dc2353 111
0d5b5c27 112 // initialisation (i starts from n) [SR, GSI, 18.02.2003]
73ae7b59 113 for(UInt_t i=n; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 114 fdQdl[i] = 0;
115 fIndex[i] = 0;
116 }
5443e65e 117}
118
119//_____________________________________________________________________________
b3a5a838 120AliTRDtrack::AliTRDtrack(const AliKalmanTrack& t, Double_t alpha)
121 :AliKalmanTrack(t) {
5443e65e 122 //
123 // Constructor from AliTPCtrack or AliITStrack .
124 //
125
126 SetLabel(t.GetLabel());
127 SetChi2(0.);
b8dc2353 128 SetMass(t.GetMass());
5443e65e 129 SetNumberOfClusters(0);
130
131 fdEdx=0;
132
b3a5a838 133 fLhElectron = 0.0;
9c9d2487 134 fNWrong = 0;
135 fNRotate = 0;
b3a5a838 136
5443e65e 137 fAlpha = alpha;
138 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
139 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
140
141 Double_t x, p[5]; t.GetExternalParameters(x,p);
142
143 fX=x;
144
145 x = GetConvConst();
146
b8dc2353 147 fY=p[0];
148 fZ=p[1];
b3a5a838 149 fT=p[3];
150 fC=p[4]/x;
b8dc2353 151 fE=fC*fX - p[2];
5443e65e 152
153 //Conversion of the covariance matrix
154 Double_t c[15]; t.GetExternalCovariance(c);
79e94bf8 155
156 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
157
158 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
159 Double_t c32=fX*c[13] - c[8];
160 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
161
162 fCyy=c[0 ];
163 fCzy=c[1 ]; fCzz=c[2 ];
164 fCey=c20; fCez=c21; fCee=c22;
165 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
166 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
167
168 // Initialization [SR, GSI, 18.02.2003]
73ae7b59 169 for(UInt_t i=0; i<kMAX_CLUSTERS_PER_TRACK; i++) {
79e94bf8 170 fdQdl[i] = 0;
171 fIndex[i] = 0;
172 }
173}
174//_____________________________________________________________________________
175AliTRDtrack::AliTRDtrack(const AliESDtrack& t)
176 :AliKalmanTrack() {
177 //
178 // Constructor from AliESDtrack
179 //
180
181 SetLabel(t.GetLabel());
182 SetChi2(0.);
183 SetMass(t.GetMass());
1e9bb598 184 SetNumberOfClusters(t.GetTRDclusters(fIndex));
79e94bf8 185
186 fdEdx=0;
187
188 fLhElectron = 0.0;
189 fNWrong = 0;
190 fNRotate = 0;
191
192 fAlpha = t.GetAlpha();
193 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
194 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
195
196 Double_t x, p[5]; t.GetExternalParameters(x,p);
197
198 fX=x;
199
200 x = GetConvConst();
201
202 fY=p[0];
203 fZ=p[1];
204 fT=p[3];
205 fC=p[4]/x;
206 fE=fC*fX - p[2];
207
208 //Conversion of the covariance matrix
209 Double_t c[15]; t.GetExternalCovariance(c);
5443e65e 210
211 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
212
213 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
214 Double_t c32=fX*c[13] - c[8];
215 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
216
b8dc2353 217 fCyy=c[0 ];
218 fCzy=c[1 ]; fCzz=c[2 ];
219 fCey=c20; fCez=c21; fCee=c22;
220 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
221 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
5443e65e 222
0d5b5c27 223 // Initialization [SR, GSI, 18.02.2003]
73ae7b59 224 for(UInt_t i=0; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 225 fdQdl[i] = 0;
226 fIndex[i] = 0;
227 }
c630aafd 228
229 if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
230 StartTimeIntegral();
231 Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
232 SetIntegratedLength(t.GetIntegratedLength());
233
5443e65e 234}
9c9d2487 235//_____________________________________________________________________________
236
237void AliTRDtrack::GetBarrelTrack(AliBarrelTrack *track) {
238 //
239 //
240 //
241
242 if (!track) return;
243 Double_t xr, vec[5], cov[15];
244
245 track->SetLabel(GetLabel());
246 track->SetX(fX, fAlpha);
247 track->SetNClusters(GetNumberOfClusters(), GetChi2());
248 track->SetNWrongClusters(fNWrong);
249 track->SetNRotate(fNRotate);
2b5dc063 250 Double_t times[10];
251 GetIntegratedTimes(times);
252 track->SetTime(times, GetIntegratedLength());
9c9d2487 253
2b5dc063 254 track->SetMass(GetMass());
255 track->SetdEdX(GetdEdx());
5443e65e 256
9c9d2487 257 GetExternalParameters(xr, vec);
258 track->SetStateVector(vec);
259
260 GetExternalCovariance(cov);
261 track->SetCovarianceMatrix(cov);
262}
5443e65e 263//____________________________________________________________________________
264void AliTRDtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
265 //
266 // This function returns external TRD track representation
267 //
268 xr=fX;
269 x[0]=GetY();
270 x[1]=GetZ();
271 x[2]=GetSnp();
272 x[3]=GetTgl();
b8dc2353 273 x[4]=Get1Pt();
5443e65e 274}
275
276//_____________________________________________________________________________
277void AliTRDtrack::GetExternalCovariance(Double_t cc[15]) const {
278 //
279 // This function returns external representation of the covriance matrix.
280 //
281 Double_t a=GetConvConst();
282
b3a5a838 283 Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
284 Double_t c32=fX*fCct-fCte;
285 Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
5443e65e 286
287 cc[0 ]=fCyy;
288 cc[1 ]=fCzy; cc[2 ]=fCzz;
289 cc[3 ]=c20; cc[4 ]=c21; cc[5 ]=c22;
290 cc[6 ]=fCty; cc[7 ]=fCtz; cc[8 ]=c32; cc[9 ]=fCtt;
b8dc2353 291 cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a;
292
5443e65e 293}
294
46d29e70 295
296//_____________________________________________________________________________
297void AliTRDtrack::GetCovariance(Double_t cc[15]) const {
b8dc2353 298
46d29e70 299 cc[0]=fCyy;
300 cc[1]=fCzy; cc[2]=fCzz;
b3a5a838 301 cc[3]=fCey; cc[4]=fCez; cc[5]=fCee;
302 cc[6]=fCcy; cc[7]=fCcz; cc[8]=fCce; cc[9]=fCcc;
303 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
b8dc2353 304
46d29e70 305}
306
307//_____________________________________________________________________________
2a941f4e 308Int_t AliTRDtrack::Compare(const TObject *o) const {
46d29e70 309
5443e65e 310// Compares tracks according to their Y2 or curvature
46d29e70 311
312 AliTRDtrack *t=(AliTRDtrack*)o;
313 // Double_t co=t->GetSigmaY2();
314 // Double_t c =GetSigmaY2();
315
316 Double_t co=TMath::Abs(t->GetC());
317 Double_t c =TMath::Abs(GetC());
318
319 if (c>co) return 1;
320 else if (c<co) return -1;
321 return 0;
322}
323
324//_____________________________________________________________________________
a819a5f7 325void AliTRDtrack::CookdEdx(Double_t low, Double_t up) {
326 //-----------------------------------------------------------------
327 // Calculates dE/dX within the "low" and "up" cuts.
328 //-----------------------------------------------------------------
5443e65e 329
a819a5f7 330 Int_t i;
5443e65e 331 Int_t nc=GetNumberOfClusters();
a819a5f7 332
5443e65e 333 Float_t sorted[kMAX_CLUSTERS_PER_TRACK];
334 for (i=0; i < nc; i++) {
335 sorted[i]=fdQdl[i];
336 }
a819a5f7 337
338 Int_t swap;
5443e65e 339
a819a5f7 340 do {
341 swap=0;
342 for (i=0; i<nc-1; i++) {
343 if (sorted[i]<=sorted[i+1]) continue;
344 Float_t tmp=sorted[i];
345 sorted[i]=sorted[i+1]; sorted[i+1]=tmp;
346 swap++;
347 }
348 } while (swap);
349
350 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
351 Float_t dedx=0;
352 for (i=nl; i<=nu; i++) dedx += sorted[i];
353 dedx /= (nu-nl+1);
5443e65e 354
a819a5f7 355 SetdEdx(dedx);
356}
357
358
a819a5f7 359//_____________________________________________________________________________
b3a5a838 360Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
46d29e70 361{
362 // Propagates a track of particle with mass=pm to a reference plane
363 // defined by x=xk through media of density=rho and radiationLength=x0
364
9c9d2487 365 if (xk == fX) return 1;
366
46d29e70 367 if (TMath::Abs(fC*xk - fE) >= 0.99999) {
b8dc2353 368 Int_t n=GetNumberOfClusters();
9c9d2487 369 if (n>4) cerr << n << " AliTRDtrack: Propagation failed, \tPt = "
370 << GetPt() << "\t" << GetLabel() << "\t" << GetMass() << endl;
46d29e70 371 return 0;
372 }
373
0d5b5c27 374 // track Length measurement [SR, GSI, 17.02.2003]
375 Double_t oldX = fX, oldY = fY, oldZ = fZ;
376
46d29e70 377 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
5443e65e 378 Double_t c1=fC*x1 - fE;
379 if((c1*c1) > 1) return 0;
380 Double_t r1=sqrt(1.- c1*c1);
b8dc2353 381 Double_t c2=fC*x2 - fE;
5443e65e 382 if((c2*c2) > 1) return 0;
383 Double_t r2=sqrt(1.- c2*c2);
46d29e70 384
385 fY += dx*(c1+c2)/(r1+r2);
386 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
387
388 //f = F - 1
389 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
b3a5a838 390 Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
391 Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
46d29e70 392 Double_t cr=c1*r2+c2*r1;
b3a5a838 393 Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
394 Double_t f13= dx*cc/cr;
b8dc2353 395 Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
46d29e70 396
397 //b = C*ft
b3a5a838 398 Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
399 Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
400 Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
401 Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
402 Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
46d29e70 403
404 //a = f*b = f*C*ft
b3a5a838 405 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
46d29e70 406
407 //F*C*Ft = C + (a + b + bt)
408 fCyy += a00 + 2*b00;
409 fCzy += a01 + b01 + b10;
b3a5a838 410 fCey += b20;
411 fCty += b30;
412 fCcy += b40;
46d29e70 413 fCzz += a11 + 2*b11;
b3a5a838 414 fCez += b21;
415 fCtz += b31;
b8dc2353 416 fCcz += b41;
46d29e70 417
b8dc2353 418 fX=x2;
46d29e70 419
420 //Multiple scattering ******************
46d29e70 421 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
b8dc2353 422 Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
b3a5a838 423 Double_t beta2=p2/(p2 + GetMass()*GetMass());
b8dc2353 424 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
46d29e70 425
426 Double_t ey=fC*fX - fE, ez=fT;
427 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
428
46d29e70 429 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
430 fCte += ez*zz1*xy*theta2;
431 fCtt += zz1*zz1*theta2;
b3a5a838 432 fCce += xz*ez*xy*theta2;
433 fCct += xz*zz1*theta2;
434 fCcc += xz*xz*theta2;
46d29e70 435
46d29e70 436 //Energy losses************************
b8dc2353 437 if((5940*beta2/(1-beta2+1e-10) - beta2) < 0) return 0;
5443e65e 438
b8dc2353 439 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
440 if (x1 < x2) dE=-dE;
441 cc=fC;
b3a5a838 442 fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
b8dc2353 443 fE+=fX*(fC-cc);
46d29e70 444
0d5b5c27 445 // track time measurement [SR, GSI 17.02.2002]
0fa7dfa7 446 if (x1 < x2)
0d5b5c27 447 if (IsStartedTimeIntegral()) {
448 Double_t l2 = (fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ);
449 AddTimeStep(TMath::Sqrt(l2));
450 }
451
b8dc2353 452 return 1;
46d29e70 453}
454
fd621f36 455
46d29e70 456//_____________________________________________________________________________
fd621f36 457Int_t AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index, Double_t h01)
46d29e70 458{
459 // Assignes found cluster to the track and updates track information
460
b8dc2353 461 Bool_t fNoTilt = kTRUE;
462 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
fd621f36 463
b8dc2353 464 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
465 r00+=fCyy; r01+=fCzy; r11+=fCzz;
46d29e70 466 Double_t det=r00*r11 - r01*r01;
467 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
468
b8dc2353 469 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
470 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
471 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
472 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
473 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
46d29e70 474
475 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
b3a5a838 476 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
fd621f36 477
b3a5a838 478 Double_t c01=fCzy, c02=fCey, c03=fCty, c04=fCcy;
479 Double_t c12=fCez, c13=fCtz, c14=fCcz;
46d29e70 480
b8dc2353 481 if(fNoTilt) {
482 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
483 Int_t n=GetNumberOfClusters();
484 if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
485 return 0;
486 }
487 fY += k00*dy + k01*dz;
488 fZ += k10*dy + k11*dz;
489 fE = eta;
9c9d2487 490 //fT += k30*dy + k31*dz;
b8dc2353 491 fC = cur;
492 }
493 else {
494 Double_t xu_factor = 100.; // empirical factor set by C.Xu
495 // in the first tilt version
496 r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2()*xu_factor;
497 r00+=(fCyy+2.0*h01*fCzy+h01*h01*fCzz);
498 r01+=(fCzy+h01*fCzz);
499 det=r00*r11 - r01*r01;
500 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
501
502 k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
503 k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
504 k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
505 k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
506 k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
507
508 dy=c->GetY() - fY; dz=c->GetZ() - fZ;
509 dy=dy+h01*dz;
510
511 cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
512 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
513 Int_t n=GetNumberOfClusters();
514 if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
515 return 0;
516 }
517 fY += k00*dy + k01*dz;
518 fZ += k10*dy + k11*dz;
519 fE = eta;
9c9d2487 520 //fT += k30*dy + k31*dz;
b8dc2353 521 fC = cur;
522
523 k01+=h01*k00;
524 k11+=h01*k10;
525 k21+=h01*k20;
526 k31+=h01*k30;
527 k41+=h01*k40;
528 }
529
46d29e70 530 fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
b3a5a838 531 fCey-=k00*c02+k01*c12; fCty-=k00*c03+k01*c13;
532 fCcy-=k00*c04+k01*c14;
b8dc2353 533
46d29e70 534 fCzz-=k10*c01+k11*fCzz;
b3a5a838 535 fCez-=k10*c02+k11*c12; fCtz-=k10*c03+k11*c13;
536 fCcz-=k10*c04+k11*c14;
b8dc2353 537
b3a5a838 538 fCee-=k20*c02+k21*c12; fCte-=k20*c03+k21*c13;
539 fCce-=k20*c04+k21*c14;
b8dc2353 540
b3a5a838 541 fCtt-=k30*c03+k31*c13;
b8dc2353 542 fCct-=k40*c03+k41*c13;
543
544 fCcc-=k40*c04+k41*c14;
46d29e70 545
b8dc2353 546 Int_t n=GetNumberOfClusters();
5443e65e 547 fIndex[n]=index;
b8dc2353 548 SetNumberOfClusters(n+1);
fd621f36 549
b8dc2353 550 SetChi2(GetChi2()+chisq);
46d29e70 551 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
5443e65e 552
b8dc2353 553 return 1;
46d29e70 554}
555
fd621f36 556
46d29e70 557//_____________________________________________________________________________
558Int_t AliTRDtrack::Rotate(Double_t alpha)
559{
560 // Rotates track parameters in R*phi plane
9c9d2487 561
562 fNRotate++;
46d29e70 563
564 fAlpha += alpha;
b3a5a838 565 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
b8dc2353 566 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
46d29e70 567
568 Double_t x1=fX, y1=fY;
569 Double_t ca=cos(alpha), sa=sin(alpha);
570 Double_t r1=fC*fX - fE;
571
572 fX = x1*ca + y1*sa;
b8dc2353 573 fY =-x1*sa + y1*ca;
574 if((r1*r1) > 1) return 0;
46d29e70 575 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
576
577 Double_t r2=fC*fX - fE;
578 if (TMath::Abs(r2) >= 0.99999) {
b8dc2353 579 Int_t n=GetNumberOfClusters();
5443e65e 580 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
46d29e70 581 return 0;
582 }
583
b8dc2353 584 if((r2*r2) > 1) return 0;
46d29e70 585 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
586 if ((fY-y0)*fC >= 0.) {
b8dc2353 587 Int_t n=GetNumberOfClusters();
5443e65e 588 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !!!\n";
46d29e70 589 return 0;
590 }
591
592 //f = F - 1
b3a5a838 593 Double_t f00=ca-1, f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
b8dc2353 594 f20=fC*sa, f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
46d29e70 595
596 //b = C*ft
b3a5a838 597 Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
598 Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
599 Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
600 Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
601 Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
46d29e70 602
603 //a = f*b = f*C*ft
b3a5a838 604 Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
46d29e70 605
46d29e70 606 //F*C*Ft = C + (a + b + bt)
607 fCyy += a00 + 2*b00;
608 fCzy += b10;
b3a5a838 609 fCey += a02+b20+b02;
610 fCty += b30;
611 fCcy += b40;
612 fCez += b12;
613 fCte += b32;
614 fCee += a22 + 2*b22;
615 fCce += b42;
46d29e70 616
b8dc2353 617 return 1;
46d29e70 618}
619
620
46d29e70 621//_____________________________________________________________________________
fd621f36 622Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c, Double_t h01) const
46d29e70 623{
fd621f36 624
b8dc2353 625 Bool_t fNoTilt = kTRUE;
626 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
627 Double_t chi2, dy, r00, r01, r11;
628
629 if(fNoTilt) {
630 dy=c->GetY() - fY;
631 r00=c->GetSigmaY2();
632 chi2 = (dy*dy)/r00;
46d29e70 633 }
b8dc2353 634 else {
635 r00=c->GetSigmaY2(); r01=0.; r11=c->GetSigmaZ2();
636 r00+=fCyy; r01+=fCzy; r11+=fCzz;
637
638 Double_t det=r00*r11 - r01*r01;
639 if (TMath::Abs(det) < 1.e-10) {
640 Int_t n=GetNumberOfClusters();
641 if (n>4) cerr<<n<<" AliTRDtrack warning: Singular matrix !\n";
642 return 1e10;
643 }
644 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
645 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
646 dy=dy+h01*dz;
a819a5f7 647
b8dc2353 648 chi2 = (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
649 }
650 return chi2;
fd621f36 651}
46d29e70 652
653
654//_________________________________________________________________________
655void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
656{
657 // Returns reconstructed track momentum in the global system.
658
659 Double_t pt=TMath::Abs(GetPt()); // GeV/c
660 Double_t r=fC*fX-fE;
5443e65e 661
662 Double_t y0;
663 if(r > 1) { py = pt; px = 0; }
664 else if(r < -1) { py = -pt; px = 0; }
665 else {
666 y0=fY + sqrt(1.- r*r)/fC;
667 px=-pt*(fY-y0)*fC; //cos(phi);
668 py=-pt*(fE-fX*fC); //sin(phi);
669 }
46d29e70 670 pz=pt*fT;
671 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
672 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
673 px=tmp;
674
675}
676
5443e65e 677//_________________________________________________________________________
678void AliTRDtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
46d29e70 679{
5443e65e 680 // Returns reconstructed track coordinates in the global system.
681
682 x = fX; y = fY; z = fZ;
683 Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
684 y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
685 x=tmp;
686
687}
3ab6f951 688
5443e65e 689//_________________________________________________________________________
690void AliTRDtrack::ResetCovariance() {
691 //
692 // Resets covariance matrix
693 //
46d29e70 694
5443e65e 695 fCyy*=10.;
b8dc2353 696 fCzy=0.; fCzz*=10.;
697 fCey=0.; fCez=0.; fCee*=10.;
698 fCty=0.; fCtz=0.; fCte=0.; fCtt*=10.;
699 fCcy=0.; fCcz=0.; fCce=0.; fCct=0.; fCcc*=10.;
5443e65e 700}
b8dc2353 701