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