Storing angle alpha for the tracks stopped at TRD. The stored value is used for inwar...
[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"
79e94bf8 24#include "AliESDtrack.h"
3c625a9b 25#include "AliTRDclusterCorrection.h"
b3a5a838 26
46d29e70 27ClassImp(AliTRDtrack)
28
46d29e70 29//_____________________________________________________________________________
30
a819a5f7 31AliTRDtrack::AliTRDtrack(const AliTRDcluster *c, UInt_t index,
5443e65e 32 const Double_t xx[5], const Double_t cc[15],
33 Double_t xref, Double_t alpha) : AliKalmanTrack() {
46d29e70 34 //-----------------------------------------------------------------
35 // This is the main track constructor.
36 //-----------------------------------------------------------------
5443e65e 37
38 fSeedLab = -1;
46d29e70 39
40 fAlpha=alpha;
5443e65e 41 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
42 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
43
46d29e70 44 fX=xref;
45
b3a5a838 46 fY=xx[0]; fZ=xx[1]; fE=xx[2]; fT=xx[3]; fC=xx[4];
46d29e70 47
48 fCyy=cc[0];
49 fCzy=cc[1]; fCzz=cc[2];
b3a5a838 50 fCey=cc[3]; fCez=cc[4]; fCee=cc[5];
51 fCty=cc[6]; fCtz=cc[7]; fCte=cc[8]; fCtt=cc[9];
b8dc2353 52 fCcy=cc[10]; fCcz=cc[11]; fCce=cc[12]; fCct=cc[13]; fCcc=cc[14];
53
5443e65e 54 fIndex[0]=index;
55 SetNumberOfClusters(1);
56
57 fdEdx=0.;
a2b90f83 58
b3a5a838 59 fLhElectron = 0.0;
9c9d2487 60 fNWrong = 0;
61 fNRotate = 0;
3c625a9b 62 fStopped = 0;
5443e65e 63 Double_t q = TMath::Abs(c->GetQ());
a819a5f7 64 Double_t s = fX*fC - fE, t=fT;
5443e65e 65 if(s*s < 1) q *= TMath::Sqrt((1-s*s)/(1+t*t));
66
67 fdQdl[0] = q;
0d5b5c27 68
69 // initialisation [SR, GSI 18.02.2003] (i startd for 1)
73ae7b59 70 for(UInt_t i=1; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 71 fdQdl[i] = 0;
72 fIndex[i] = 0;
46e2d86c 73 fIndexBackup[i] = 0; //bacup indexes MI
0d5b5c27 74 }
16d9fbba 75 fNCross =0;
76 fBackupTrack =0;
46d29e70 77}
78
79//_____________________________________________________________________________
5443e65e 80AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) : AliKalmanTrack(t) {
46d29e70 81 //
82 // Copy constructor.
83 //
b8dc2353 84
5443e65e 85 SetLabel(t.GetLabel());
86 fSeedLab=t.GetSeedLabel();
46d29e70 87
5443e65e 88 SetChi2(t.GetChi2());
46d29e70 89 fdEdx=t.fdEdx;
90
b3a5a838 91 fLhElectron = 0.0;
9c9d2487 92 fNWrong = t.fNWrong;
93 fNRotate = t.fNRotate;
3c625a9b 94 fStopped = t.fStopped;
46d29e70 95 fAlpha=t.fAlpha;
96 fX=t.fX;
97
b8dc2353 98 fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
46d29e70 99
100 fCyy=t.fCyy;
101 fCzy=t.fCzy; fCzz=t.fCzz;
b3a5a838 102 fCey=t.fCey; fCez=t.fCez; fCee=t.fCee;
103 fCty=t.fCty; fCtz=t.fCtz; fCte=t.fCte; fCtt=t.fCtt;
b8dc2353 104 fCcy=t.fCcy; fCcz=t.fCcz; fCce=t.fCce; fCct=t.fCct; fCcc=t.fCcc;
46d29e70 105
5443e65e 106 Int_t n=t.GetNumberOfClusters();
107 SetNumberOfClusters(n);
108 for (Int_t i=0; i<n; i++) {
a819a5f7 109 fIndex[i]=t.fIndex[i];
46e2d86c 110 fIndexBackup[i]=t.fIndex[i]; // MI - backup indexes
a819a5f7 111 fdQdl[i]=t.fdQdl[i];
112 }
b8dc2353 113
0d5b5c27 114 // initialisation (i starts from n) [SR, GSI, 18.02.2003]
73ae7b59 115 for(UInt_t i=n; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 116 fdQdl[i] = 0;
117 fIndex[i] = 0;
46e2d86c 118 fIndexBackup[i] = 0; //MI backup indexes
0d5b5c27 119 }
16d9fbba 120 fNCross =0;
121 fBackupTrack =0;
5443e65e 122}
123
124//_____________________________________________________________________________
b3a5a838 125AliTRDtrack::AliTRDtrack(const AliKalmanTrack& t, Double_t alpha)
126 :AliKalmanTrack(t) {
5443e65e 127 //
128 // Constructor from AliTPCtrack or AliITStrack .
129 //
130
131 SetLabel(t.GetLabel());
132 SetChi2(0.);
b8dc2353 133 SetMass(t.GetMass());
5443e65e 134 SetNumberOfClusters(0);
135
c73b3eb3 136 fdEdx=t.GetdEdx();
5443e65e 137
b3a5a838 138 fLhElectron = 0.0;
9c9d2487 139 fNWrong = 0;
140 fNRotate = 0;
3c625a9b 141 fStopped = 0;
b3a5a838 142
5443e65e 143 fAlpha = alpha;
144 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
145 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
146
147 Double_t x, p[5]; t.GetExternalParameters(x,p);
148
149 fX=x;
150
151 x = GetConvConst();
152
b8dc2353 153 fY=p[0];
154 fZ=p[1];
b3a5a838 155 fT=p[3];
156 fC=p[4]/x;
b8dc2353 157 fE=fC*fX - p[2];
5443e65e 158
159 //Conversion of the covariance matrix
160 Double_t c[15]; t.GetExternalCovariance(c);
79e94bf8 161
162 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
163
164 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
165 Double_t c32=fX*c[13] - c[8];
166 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
167
168 fCyy=c[0 ];
169 fCzy=c[1 ]; fCzz=c[2 ];
170 fCey=c20; fCez=c21; fCee=c22;
171 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
172 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
173
174 // Initialization [SR, GSI, 18.02.2003]
73ae7b59 175 for(UInt_t i=0; i<kMAX_CLUSTERS_PER_TRACK; i++) {
79e94bf8 176 fdQdl[i] = 0;
177 fIndex[i] = 0;
46e2d86c 178 fIndexBackup[i] = 0; // MI backup indexes
79e94bf8 179 }
16d9fbba 180 fNCross =0;
181 fBackupTrack =0;
79e94bf8 182}
183//_____________________________________________________________________________
184AliTRDtrack::AliTRDtrack(const AliESDtrack& t)
185 :AliKalmanTrack() {
186 //
187 // Constructor from AliESDtrack
188 //
189
190 SetLabel(t.GetLabel());
191 SetChi2(0.);
192 SetMass(t.GetMass());
1e9bb598 193 SetNumberOfClusters(t.GetTRDclusters(fIndex));
46e2d86c 194 Int_t ncl = t.GetTRDclusters(fIndexBackup);
195 for (UInt_t i=ncl;i<kMAX_CLUSTERS_PER_TRACK;i++) {
196 fIndexBackup[i]=0;
197 fIndex[i] = 0; //MI store indexes
198 }
c73b3eb3 199 fdEdx=t.GetTRDsignal();
79e94bf8 200
201 fLhElectron = 0.0;
202 fNWrong = 0;
3c625a9b 203 fStopped = 0;
79e94bf8 204 fNRotate = 0;
205
206 fAlpha = t.GetAlpha();
207 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
208 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
209
210 Double_t x, p[5]; t.GetExternalParameters(x,p);
c5a8e3df 211 //Conversion of the covariance matrix
212 Double_t c[15]; t.GetExternalCovariance(c);
25cde026 213 if (t.GetStatus()&AliESDtrack::kTRDbackup){
f4e9508c 214 t.GetTRDExternalParameters(x,fAlpha,p,c);
215 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
216 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
c5a8e3df 217 }
79e94bf8 218
219 fX=x;
220
221 x = GetConvConst();
222
223 fY=p[0];
224 fZ=p[1];
225 fT=p[3];
226 fC=p[4]/x;
227 fE=fC*fX - p[2];
228
5443e65e 229
230 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
231
232 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
233 Double_t c32=fX*c[13] - c[8];
234 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
235
b8dc2353 236 fCyy=c[0 ];
237 fCzy=c[1 ]; fCzz=c[2 ];
238 fCey=c20; fCez=c21; fCee=c22;
239 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
240 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
5443e65e 241
0d5b5c27 242 // Initialization [SR, GSI, 18.02.2003]
73ae7b59 243 for(UInt_t i=0; i<kMAX_CLUSTERS_PER_TRACK; i++) {
0d5b5c27 244 fdQdl[i] = 0;
46e2d86c 245 // fIndex[i] = 0; //MI store indexes
0d5b5c27 246 }
16d9fbba 247 fNCross =0;
248 fBackupTrack =0;
c630aafd 249
250 if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
251 StartTimeIntegral();
252 Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
253 SetIntegratedLength(t.GetIntegratedLength());
254
16d9fbba 255}
256
257AliTRDtrack::~AliTRDtrack()
258{
259 //
260 //
261 if (fBackupTrack) delete fBackupTrack;
262 fBackupTrack=0;
263}
264
9c9d2487 265//_____________________________________________________________________________
266
267void AliTRDtrack::GetBarrelTrack(AliBarrelTrack *track) {
268 //
269 //
270 //
271
272 if (!track) return;
273 Double_t xr, vec[5], cov[15];
274
275 track->SetLabel(GetLabel());
276 track->SetX(fX, fAlpha);
277 track->SetNClusters(GetNumberOfClusters(), GetChi2());
278 track->SetNWrongClusters(fNWrong);
279 track->SetNRotate(fNRotate);
2b5dc063 280 Double_t times[10];
281 GetIntegratedTimes(times);
282 track->SetTime(times, GetIntegratedLength());
9c9d2487 283
2b5dc063 284 track->SetMass(GetMass());
285 track->SetdEdX(GetdEdx());
5443e65e 286
9c9d2487 287 GetExternalParameters(xr, vec);
288 track->SetStateVector(vec);
289
290 GetExternalCovariance(cov);
291 track->SetCovarianceMatrix(cov);
292}
5443e65e 293//____________________________________________________________________________
294void AliTRDtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
295 //
296 // This function returns external TRD track representation
297 //
298 xr=fX;
299 x[0]=GetY();
300 x[1]=GetZ();
301 x[2]=GetSnp();
302 x[3]=GetTgl();
b8dc2353 303 x[4]=Get1Pt();
5443e65e 304}
305
306//_____________________________________________________________________________
307void AliTRDtrack::GetExternalCovariance(Double_t cc[15]) const {
308 //
309 // This function returns external representation of the covriance matrix.
310 //
311 Double_t a=GetConvConst();
312
b3a5a838 313 Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
314 Double_t c32=fX*fCct-fCte;
315 Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
5443e65e 316
317 cc[0 ]=fCyy;
318 cc[1 ]=fCzy; cc[2 ]=fCzz;
319 cc[3 ]=c20; cc[4 ]=c21; cc[5 ]=c22;
320 cc[6 ]=fCty; cc[7 ]=fCtz; cc[8 ]=c32; cc[9 ]=fCtt;
b8dc2353 321 cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a;
322
5443e65e 323}
324
46d29e70 325
326//_____________________________________________________________________________
327void AliTRDtrack::GetCovariance(Double_t cc[15]) const {
b8dc2353 328
46d29e70 329 cc[0]=fCyy;
330 cc[1]=fCzy; cc[2]=fCzz;
b3a5a838 331 cc[3]=fCey; cc[4]=fCez; cc[5]=fCee;
332 cc[6]=fCcy; cc[7]=fCcz; cc[8]=fCce; cc[9]=fCcc;
333 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
b8dc2353 334
46d29e70 335}
336
337//_____________________________________________________________________________
2a941f4e 338Int_t AliTRDtrack::Compare(const TObject *o) const {
46d29e70 339
5443e65e 340// Compares tracks according to their Y2 or curvature
46d29e70 341
342 AliTRDtrack *t=(AliTRDtrack*)o;
343 // Double_t co=t->GetSigmaY2();
344 // Double_t c =GetSigmaY2();
345
346 Double_t co=TMath::Abs(t->GetC());
347 Double_t c =TMath::Abs(GetC());
348
349 if (c>co) return 1;
350 else if (c<co) return -1;
351 return 0;
352}
353
a819a5f7 354//_____________________________________________________________________________
355void AliTRDtrack::CookdEdx(Double_t low, Double_t up) {
356 //-----------------------------------------------------------------
357 // Calculates dE/dX within the "low" and "up" cuts.
358 //-----------------------------------------------------------------
5443e65e 359
a819a5f7 360 Int_t i;
5443e65e 361 Int_t nc=GetNumberOfClusters();
a819a5f7 362
5443e65e 363 Float_t sorted[kMAX_CLUSTERS_PER_TRACK];
364 for (i=0; i < nc; i++) {
365 sorted[i]=fdQdl[i];
366 }
a819a5f7 367
368 Int_t swap;
5443e65e 369
a819a5f7 370 do {
371 swap=0;
372 for (i=0; i<nc-1; i++) {
373 if (sorted[i]<=sorted[i+1]) continue;
374 Float_t tmp=sorted[i];
375 sorted[i]=sorted[i+1]; sorted[i+1]=tmp;
376 swap++;
377 }
378 } while (swap);
379
380 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
381 Float_t dedx=0;
382 for (i=nl; i<=nu; i++) dedx += sorted[i];
383 dedx /= (nu-nl+1);
5443e65e 384
a819a5f7 385 SetdEdx(dedx);
386}
387
388
46d29e70 389//_____________________________________________________________________________
b3a5a838 390Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
46d29e70 391{
392 // Propagates a track of particle with mass=pm to a reference plane
393 // defined by x=xk through media of density=rho and radiationLength=x0
394
9c9d2487 395 if (xk == fX) return 1;
396
3c625a9b 397 if (TMath::Abs(fC*xk - fE) >= 0.90000) {
398 // Int_t n=GetNumberOfClusters();
399 //if (n>4) cerr << n << " AliTRDtrack: Propagation failed, \tPt = "
400 // << GetPt() << "\t" << GetLabel() << "\t" << GetMass() << endl;
46d29e70 401 return 0;
402 }
403
0d5b5c27 404 // track Length measurement [SR, GSI, 17.02.2003]
405 Double_t oldX = fX, oldY = fY, oldZ = fZ;
406
46d29e70 407 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
5443e65e 408 Double_t c1=fC*x1 - fE;
409 if((c1*c1) > 1) return 0;
410 Double_t r1=sqrt(1.- c1*c1);
b8dc2353 411 Double_t c2=fC*x2 - fE;
5443e65e 412 if((c2*c2) > 1) return 0;
413 Double_t r2=sqrt(1.- c2*c2);
46d29e70 414
415 fY += dx*(c1+c2)/(r1+r2);
416 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
417
418 //f = F - 1
419 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
b3a5a838 420 Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
421 Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
46d29e70 422 Double_t cr=c1*r2+c2*r1;
b3a5a838 423 Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
424 Double_t f13= dx*cc/cr;
b8dc2353 425 Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
46d29e70 426
427 //b = C*ft
b3a5a838 428 Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
429 Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
430 Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
431 Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
432 Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
46d29e70 433
434 //a = f*b = f*C*ft
b3a5a838 435 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
46d29e70 436
437 //F*C*Ft = C + (a + b + bt)
438 fCyy += a00 + 2*b00;
439 fCzy += a01 + b01 + b10;
b3a5a838 440 fCey += b20;
441 fCty += b30;
442 fCcy += b40;
46d29e70 443 fCzz += a11 + 2*b11;
b3a5a838 444 fCez += b21;
445 fCtz += b31;
b8dc2353 446 fCcz += b41;
46d29e70 447
b8dc2353 448 fX=x2;
46d29e70 449
450 //Multiple scattering ******************
46d29e70 451 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
b8dc2353 452 Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
b3a5a838 453 Double_t beta2=p2/(p2 + GetMass()*GetMass());
b8dc2353 454 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
46d29e70 455
456 Double_t ey=fC*fX - fE, ez=fT;
457 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
3c625a9b 458
46d29e70 459 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
460 fCte += ez*zz1*xy*theta2;
461 fCtt += zz1*zz1*theta2;
b3a5a838 462 fCce += xz*ez*xy*theta2;
463 fCct += xz*zz1*theta2;
464 fCcc += xz*xz*theta2;
3c625a9b 465 /*
466 Double_t dc22 = (1-ey*ey+xz*xz*fX*fX)*theta2;
467 Double_t dc32 = (xz*fX*zz1)*theta2;
468 Double_t dc33 = (zz1*zz1)*theta2;
469 Double_t dc42 = (xz*fX*xz)*theta2;
470 Double_t dc43 = (zz1*xz)*theta2;
471 Double_t dc44 = (xz*xz)*theta2;
472 fCee += dc22;
473 fCte += dc32;
474 fCtt += dc33;
475 fCce += dc42;
476 fCct += dc43;
477 fCcc += dc44;
478 */
46d29e70 479 //Energy losses************************
b8dc2353 480 if((5940*beta2/(1-beta2+1e-10) - beta2) < 0) return 0;
5443e65e 481
b8dc2353 482 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
483 if (x1 < x2) dE=-dE;
484 cc=fC;
b3a5a838 485 fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
b8dc2353 486 fE+=fX*(fC-cc);
46d29e70 487
0d5b5c27 488 // track time measurement [SR, GSI 17.02.2002]
0fa7dfa7 489 if (x1 < x2)
0d5b5c27 490 if (IsStartedTimeIntegral()) {
491 Double_t l2 = (fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ);
492 AddTimeStep(TMath::Sqrt(l2));
493 }
494
b8dc2353 495 return 1;
46d29e70 496}
497
fd621f36 498
46d29e70 499//_____________________________________________________________________________
fd621f36 500Int_t AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index, Double_t h01)
46d29e70 501{
502 // Assignes found cluster to the track and updates track information
503
b8dc2353 504 Bool_t fNoTilt = kTRUE;
505 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
46e2d86c 506 // add angular effect to the error contribution - MI
3c625a9b 507 Float_t tangent2 = (fC*fX-fE)*(fC*fX-fE);
508 if (tangent2 < 0.90000){
46e2d86c 509 tangent2 = tangent2/(1.-tangent2);
510 }
511 Float_t errang = tangent2*0.04; //
512 Float_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12.);
fd621f36 513
46e2d86c 514 Double_t r00=c->GetSigmaY2() +errang, r01=0., r11=c->GetSigmaZ2()*100.;
b8dc2353 515 r00+=fCyy; r01+=fCzy; r11+=fCzz;
46d29e70 516 Double_t det=r00*r11 - r01*r01;
517 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
518
b8dc2353 519 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
520 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
521 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
522 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
523 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
46d29e70 524
525 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
b3a5a838 526 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
fd621f36 527
46d29e70 528
b8dc2353 529 if(fNoTilt) {
3c625a9b 530 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
531 // Int_t n=GetNumberOfClusters();
532 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
b8dc2353 533 return 0;
534 }
535 fY += k00*dy + k01*dz;
536 fZ += k10*dy + k11*dz;
537 fE = eta;
9c9d2487 538 //fT += k30*dy + k31*dz;
b8dc2353 539 fC = cur;
540 }
541 else {
542 Double_t xu_factor = 100.; // empirical factor set by C.Xu
543 // in the first tilt version
46e2d86c 544 dy=c->GetY() - fY; dz=c->GetZ() - fZ;
545 dy=dy+h01*dz;
546 Float_t add=0;
547 if (TMath::Abs(dz)>padlength/2.){
3c625a9b 548 Float_t dy2 = c->GetY() - fY;
549 Float_t sign = (dz>0) ? -1.: 1.;
550 dy2+=h01*sign*padlength/2.;
551 dy = dy2;
552 add = 0;
46e2d86c 553 }
554
555
556
557 r00=c->GetSigmaY2()+errang+add, r01=0., r11=c->GetSigmaZ2()*xu_factor;
b8dc2353 558 r00+=(fCyy+2.0*h01*fCzy+h01*h01*fCzz);
46e2d86c 559
b8dc2353 560 r01+=(fCzy+h01*fCzz);
561 det=r00*r11 - r01*r01;
562 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
563
564 k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
565 k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
566 k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
567 k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
568 k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
569
b8dc2353 570
571 cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
3c625a9b 572 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
573 // Int_t n=GetNumberOfClusters();
574 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
b8dc2353 575 return 0;
576 }
577 fY += k00*dy + k01*dz;
578 fZ += k10*dy + k11*dz;
579 fE = eta;
46e2d86c 580 fT += k30*dy + k31*dz;
b8dc2353 581 fC = cur;
582
583 k01+=h01*k00;
584 k11+=h01*k10;
585 k21+=h01*k20;
586 k31+=h01*k30;
587 k41+=h01*k40;
46e2d86c 588
b8dc2353 589 }
46e2d86c 590 Double_t c01=fCzy, c02=fCey, c03=fCty, c04=fCcy;
591 Double_t c12=fCez, c13=fCtz, c14=fCcz;
592
b8dc2353 593
46d29e70 594 fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
b3a5a838 595 fCey-=k00*c02+k01*c12; fCty-=k00*c03+k01*c13;
596 fCcy-=k00*c04+k01*c14;
b8dc2353 597
46d29e70 598 fCzz-=k10*c01+k11*fCzz;
b3a5a838 599 fCez-=k10*c02+k11*c12; fCtz-=k10*c03+k11*c13;
600 fCcz-=k10*c04+k11*c14;
b8dc2353 601
b3a5a838 602 fCee-=k20*c02+k21*c12; fCte-=k20*c03+k21*c13;
603 fCce-=k20*c04+k21*c14;
b8dc2353 604
b3a5a838 605 fCtt-=k30*c03+k31*c13;
46e2d86c 606 fCct-=k40*c03+k41*c13;
607 //fCct-=k30*c04+k31*c14; // symmetric formula MI
b8dc2353 608
609 fCcc-=k40*c04+k41*c14;
46d29e70 610
b8dc2353 611 Int_t n=GetNumberOfClusters();
5443e65e 612 fIndex[n]=index;
b8dc2353 613 SetNumberOfClusters(n+1);
fd621f36 614
b8dc2353 615 SetChi2(GetChi2()+chisq);
46d29e70 616 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
5443e65e 617
b8dc2353 618 return 1;
46d29e70 619}
46e2d86c 620//_____________________________________________________________________________
3c625a9b 621Int_t AliTRDtrack::UpdateMI(const AliTRDcluster *c, Double_t chisq, UInt_t index, Double_t h01,
622 Int_t plane)
46e2d86c 623{
624 // Assignes found cluster to the track and updates track information
625
626 Bool_t fNoTilt = kTRUE;
627 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
3c625a9b 628 // add angular effect to the error contribution and make correction - MI
c5a8e3df 629 //AliTRDclusterCorrection *corrector = AliTRDclusterCorrection::GetCorrection();
3c625a9b 630 //
631 Double_t tangent2 = (fC*fX-fE)*(fC*fX-fE);
632 if (tangent2 < 0.90000){
46e2d86c 633 tangent2 = tangent2/(1.-tangent2);
634 }
3c625a9b 635 Double_t tangent = TMath::Sqrt(tangent2);
636 if ((fC*fX-fE)<0) tangent*=-1;
c5a8e3df 637 Double_t correction = 0*plane;
46e2d86c 638 Double_t errang = tangent2*0.04; //
c5a8e3df 639 /*
3c625a9b 640 if (corrector!=0){
641 //if (0){
642 correction = corrector->GetCorrection(plane,c->GetLocalTimeBin(),tangent);
643 if (TMath::Abs(correction)>0){
644 //if we have info
645 errang = corrector->GetSigma(plane,c->GetLocalTimeBin(),tangent);
646 errang *= errang;
647 errang += tangent2*0.04;
648 }
649 }
c5a8e3df 650 */
3c625a9b 651 //
46e2d86c 652 Double_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12.);
653
654 Double_t r00=c->GetSigmaY2() +errang, r01=0., r11=c->GetSigmaZ2()*10000.;
655 r00+=fCyy; r01+=fCzy; r11+=fCzz;
656 Double_t det=r00*r11 - r01*r01;
657 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
658
659 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
660 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
661 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
662 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
663 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
664
665 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
666 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
667
668
669 if(fNoTilt) {
3c625a9b 670 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
671 // Int_t n=GetNumberOfClusters();
672 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
46e2d86c 673 return 0;
674 }
675 fY += k00*dy + k01*dz;
676 fZ += k10*dy + k11*dz;
677 fE = eta;
678 //fT += k30*dy + k31*dz;
679 fC = cur;
680 }
681 else {
3c625a9b 682 Double_t xu_factor = 1000.; // empirical factor set by C.Xu
46e2d86c 683 // in the first tilt version
684 dy=c->GetY() - fY; dz=c->GetZ() - fZ;
3c625a9b 685 dy=dy+h01*dz+correction;
46e2d86c 686 Double_t add=0;
687 if (TMath::Abs(dz)>padlength/2.){
688 //Double_t dy2 = c->GetY() - fY;
689 //Double_t sign = (dz>0) ? -1.: 1.;
3c625a9b 690 //dy2-=h01*sign*padlength/2.;
46e2d86c 691 //dy = dy2;
3c625a9b 692 add =1.;
46e2d86c 693 }
694 Double_t s00 = c->GetSigmaY2()+errang+add; // error pad
695 Double_t s11 = c->GetSigmaZ2()*xu_factor; // error pad-row
696 //
697 r00 = fCyy + 2*fCzy*h01 + fCzz*h01*h01+s00;
698 r01 = fCzy + fCzz*h01;
699 r11 = fCzz + s11;
700 det = r00*r11 - r01*r01;
701 // inverse matrix
702 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
703
704 // K matrix
705 k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
706 k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
707 k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
708 k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
709 k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
710 //
711 //Update measurement
712 cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
3c625a9b 713 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
714 //Int_t n=GetNumberOfClusters();
715 // if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
46e2d86c 716 return 0;
717 }
718 fY += k00*dy + k01*dz;
719 fZ += k10*dy + k11*dz;
720 fE = eta;
721 fT += k30*dy + k31*dz;
722 fC = cur;
723
724 k01+=h01*k00;
725 k11+=h01*k10;
726 k21+=h01*k20;
727 k31+=h01*k30;
728 k41+=h01*k40;
729
730 }
731 //Update covariance
732 //
733 //
734 Double_t oldyy = fCyy, oldzz = fCzz; //, oldee=fCee, oldcc =fCcc;
735 Double_t oldzy = fCzy, oldey = fCey, oldty=fCty, oldcy =fCcy;
736 Double_t oldez = fCez, oldtz = fCtz, oldcz=fCcz;
737 //Double_t oldte = fCte, oldce = fCce;
738 //Double_t oldct = fCct;
739
740 fCyy-=k00*oldyy+k01*oldzy;
741 fCzy-=k10*oldyy+k11*oldzy;
742 fCey-=k20*oldyy+k21*oldzy;
743 fCty-=k30*oldyy+k31*oldzy;
744 fCcy-=k40*oldyy+k41*oldzy;
745 //
746 fCzz-=k10*oldzy+k11*oldzz;
747 fCez-=k20*oldzy+k21*oldzz;
748 fCtz-=k30*oldzy+k31*oldzz;
749 fCcz-=k40*oldzy+k41*oldzz;
750 //
751 fCee-=k20*oldey+k21*oldez;
752 fCte-=k30*oldey+k31*oldez;
753 fCce-=k40*oldey+k41*oldez;
754 //
755 fCtt-=k30*oldty+k31*oldtz;
756 fCct-=k40*oldty+k41*oldtz;
757 //
758 fCcc-=k40*oldcy+k41*oldcz;
759 //
760
761 Int_t n=GetNumberOfClusters();
762 fIndex[n]=index;
763 SetNumberOfClusters(n+1);
764
765 SetChi2(GetChi2()+chisq);
766 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
767
768 return 1;
769}
46d29e70 770
fd621f36 771
46d29e70 772//_____________________________________________________________________________
773Int_t AliTRDtrack::Rotate(Double_t alpha)
774{
775 // Rotates track parameters in R*phi plane
9c9d2487 776
777 fNRotate++;
46d29e70 778
779 fAlpha += alpha;
b3a5a838 780 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
b8dc2353 781 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
46d29e70 782
783 Double_t x1=fX, y1=fY;
784 Double_t ca=cos(alpha), sa=sin(alpha);
785 Double_t r1=fC*fX - fE;
786
787 fX = x1*ca + y1*sa;
b8dc2353 788 fY =-x1*sa + y1*ca;
789 if((r1*r1) > 1) return 0;
46d29e70 790 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
791
792 Double_t r2=fC*fX - fE;
3c625a9b 793 if (TMath::Abs(r2) >= 0.90000) {
b8dc2353 794 Int_t n=GetNumberOfClusters();
5443e65e 795 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
46d29e70 796 return 0;
797 }
798
b8dc2353 799 if((r2*r2) > 1) return 0;
46d29e70 800 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
801 if ((fY-y0)*fC >= 0.) {
b8dc2353 802 Int_t n=GetNumberOfClusters();
5443e65e 803 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !!!\n";
46d29e70 804 return 0;
805 }
806
807 //f = F - 1
b3a5a838 808 Double_t f00=ca-1, f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
b8dc2353 809 f20=fC*sa, f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
46d29e70 810
811 //b = C*ft
b3a5a838 812 Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
813 Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
814 Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
815 Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
816 Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
46d29e70 817
818 //a = f*b = f*C*ft
b3a5a838 819 Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
46d29e70 820
46d29e70 821 //F*C*Ft = C + (a + b + bt)
822 fCyy += a00 + 2*b00;
823 fCzy += b10;
b3a5a838 824 fCey += a02+b20+b02;
825 fCty += b30;
826 fCcy += b40;
827 fCez += b12;
828 fCte += b32;
829 fCee += a22 + 2*b22;
830 fCce += b42;
46d29e70 831
b8dc2353 832 return 1;
46d29e70 833}
834
835
46d29e70 836//_____________________________________________________________________________
fd621f36 837Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c, Double_t h01) const
46d29e70 838{
fd621f36 839
b8dc2353 840 Bool_t fNoTilt = kTRUE;
841 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
842 Double_t chi2, dy, r00, r01, r11;
843
844 if(fNoTilt) {
845 dy=c->GetY() - fY;
846 r00=c->GetSigmaY2();
847 chi2 = (dy*dy)/r00;
46d29e70 848 }
b8dc2353 849 else {
850 r00=c->GetSigmaY2(); r01=0.; r11=c->GetSigmaZ2();
851 r00+=fCyy; r01+=fCzy; r11+=fCzz;
852
853 Double_t det=r00*r11 - r01*r01;
854 if (TMath::Abs(det) < 1.e-10) {
855 Int_t n=GetNumberOfClusters();
856 if (n>4) cerr<<n<<" AliTRDtrack warning: Singular matrix !\n";
857 return 1e10;
858 }
859 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
860 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
861 dy=dy+h01*dz;
a819a5f7 862
b8dc2353 863 chi2 = (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
864 }
865 return chi2;
fd621f36 866}
46d29e70 867
868
869//_________________________________________________________________________
870void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
871{
872 // Returns reconstructed track momentum in the global system.
873
874 Double_t pt=TMath::Abs(GetPt()); // GeV/c
875 Double_t r=fC*fX-fE;
5443e65e 876
877 Double_t y0;
878 if(r > 1) { py = pt; px = 0; }
879 else if(r < -1) { py = -pt; px = 0; }
880 else {
881 y0=fY + sqrt(1.- r*r)/fC;
882 px=-pt*(fY-y0)*fC; //cos(phi);
883 py=-pt*(fE-fX*fC); //sin(phi);
884 }
46d29e70 885 pz=pt*fT;
886 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
887 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
888 px=tmp;
889
890}
891
5443e65e 892//_________________________________________________________________________
893void AliTRDtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
46d29e70 894{
5443e65e 895 // Returns reconstructed track coordinates in the global system.
896
897 x = fX; y = fY; z = fZ;
898 Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
899 y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
900 x=tmp;
901
902}
3ab6f951 903
5443e65e 904//_________________________________________________________________________
905void AliTRDtrack::ResetCovariance() {
906 //
907 // Resets covariance matrix
908 //
46d29e70 909
5443e65e 910 fCyy*=10.;
b8dc2353 911 fCzy=0.; fCzz*=10.;
912 fCey=0.; fCez=0.; fCee*=10.;
913 fCty=0.; fCtz=0.; fCte=0.; fCtt*=10.;
914 fCcy=0.; fCcz=0.; fCce=0.; fCct=0.; fCcc*=10.;
5443e65e 915}
b8dc2353 916
46e2d86c 917void AliTRDtrack::ResetCovariance(Float_t mult) {
918 //
919 // Resets covariance matrix
920 //
921
922 fCyy*=mult;
3c625a9b 923 fCzy*=0.; fCzz*=mult;
924 fCey*=0.; fCez*=0.; fCee*=mult;
925 fCty*=0.; fCtz*=0.; fCte*=0.; fCtt*=mult;
926 fCcy*=0.; fCcz*=0.; fCce*=0.; fCct*=0.; fCcc*=mult;
46e2d86c 927}
16d9fbba 928
929
930void AliTRDtrack::MakeBackupTrack()
931{
932 //
933 //
934 if (fBackupTrack) delete fBackupTrack;
935 fBackupTrack = new AliTRDtrack(*this);
936}