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