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