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