Making AZ cluster finder and Kalman tracking the default methods (see README how...
[u/mrichter/AliRoot.git] / TOF / AliTOFtrack.cxx
CommitLineData
74ea065c 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 **************************************************************************/
2c770f53 15////////////////////////////////////////////////////////////////////////
16//
17// AliTOFtrack class
18//
19// Authors: Bologna-CERN-ITEP-Salerno Group
20//
21// Description: class for handling ESD extracted tracks for TOF matching.
74ea065c 22/* $Id$ */
23
24#include <Riostream.h>
25#include <TObject.h>
d076c8d5 26#include "AliLog.h"
74ea065c 27#include "AliTOFtrack.h"
28#include "AliESDtrack.h"
29
30ClassImp(AliTOFtrack)
31
32//_____________________________________________________________________________
33AliTOFtrack::AliTOFtrack(const AliTOFtrack& t) : AliKalmanTrack(t) {
34 //
35 // Copy constructor.
36 //
37
38 SetSeedIndex(t.GetSeedIndex());
39 SetLabel(t.GetLabel());
40 fSeedLab=t.GetSeedLabel();
41 SetChi2(t.GetChi2());
42
43 fAlpha=t.fAlpha;
44 fX=t.fX;
45
46 fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
47
48 fCyy=t.fCyy;
49 fCzy=t.fCzy; fCzz=t.fCzz;
50 fCey=t.fCey; fCez=t.fCez; fCee=t.fCee;
51 fCty=t.fCty; fCtz=t.fCtz; fCte=t.fCte; fCtt=t.fCtt;
52 fCcy=t.fCcy; fCcz=t.fCcz; fCce=t.fCce; fCct=t.fCct; fCcc=t.fCcc;
53
54
55}
56
57//_____________________________________________________________________________
58AliTOFtrack::AliTOFtrack(const AliESDtrack& t)
59 :AliKalmanTrack() {
60 //
61 // Constructor from AliESDtrack
62 //
63
64 SetSeedIndex(-1);
65 SetLabel(t.GetLabel());
66 SetChi2(0.);
67 SetMass(t.GetMass());
68
69 fAlpha = t.GetAlpha();
70 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
71 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
72 Double_t x, p[5]; t.GetExternalParameters(x,p);
73
74 fX=x;
75
74ea065c 76 fY=p[0];
c84a5e9e 77 fZ=p[1]; SaveLocalConvConst();
78 fT=p[3]; x=GetLocalConvConst();
74ea065c 79 fC=p[4]/x;
80 fE=fC*fX - p[2];
81
82 //Conversion of the covariance matrix
83 Double_t c[15]; t.GetExternalCovariance(c);
84
85 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
86
87 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
88 Double_t c32=fX*c[13] - c[8];
89 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
90
91 fCyy=c[0 ];
92 fCzy=c[1 ]; fCzz=c[2 ];
93 fCey=c20; fCez=c21; fCee=c22;
94 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
95 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
96
97 if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
98 StartTimeIntegral();
99 Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
100 SetIntegratedLength(t.GetIntegratedLength());
101
102
103}
104//____________________________________________________________________________
105void AliTOFtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
106 //
107 // This function returns external TOF track representation
108 //
109 xr=fX;
110 x[0]=GetY();
111 x[1]=GetZ();
112 x[2]=GetSnp();
113 x[3]=GetTgl();
114 x[4]=Get1Pt();
115}
116
117//_____________________________________________________________________________
118void AliTOFtrack::GetExternalCovariance(Double_t cc[15]) const {
119 //
120 // This function returns external representation of the covriance matrix.
121 //
c84a5e9e 122 Double_t a=GetLocalConvConst();
74ea065c 123 Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
124 Double_t c32=fX*fCct-fCte;
125 Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
126
127 cc[0 ]=fCyy;
128 cc[1 ]=fCzy; cc[2 ]=fCzz;
129 cc[3 ]=c20; cc[4 ]=c21; cc[5 ]=c22;
130 cc[6 ]=fCty; cc[7 ]=fCtz; cc[8 ]=c32; cc[9 ]=fCtt;
131 cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a;
132
133}
134
135
136//_____________________________________________________________________________
137void AliTOFtrack::GetCovariance(Double_t cc[15]) const {
2c770f53 138 //
139 // Returns the covariance matrix.
140 //
74ea065c 141
142 cc[0]=fCyy;
143 cc[1]=fCzy; cc[2]=fCzz;
144 cc[3]=fCey; cc[4]=fCez; cc[5]=fCee;
145 cc[6]=fCcy; cc[7]=fCcz; cc[8]=fCce; cc[9]=fCcc;
146 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
147
148}
149
150
151//_____________________________________________________________________________
152Int_t AliTOFtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
153{
154 // Propagates a track of particle with mass=pm to a reference plane
155 // defined by x=xk through media of density=rho and radiationLength=x0
156
157 if (xk == fX) return 1;
158
159 if (TMath::Abs(fC*xk - fE) >= 0.90000) {
160 return 0;
161 }
c84a5e9e 162 Double_t lcc=GetLocalConvConst();
74ea065c 163
164 // track Length measurement [SR, GSI, 17.02.2003]
165
166 Double_t oldX = fX, oldY = fY, oldZ = fZ;
167
168 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
169 Double_t c1=fC*x1 - fE;
170 if((c1*c1) > 1){
171 return 0;}
172 Double_t r1=sqrt(1.- c1*c1);
173 Double_t c2=fC*x2 - fE;
174 if((c2*c2) > 1) {
175 return 0;
176 }
177 Double_t r2=sqrt(1.- c2*c2);
178
179 fY += dx*(c1+c2)/(r1+r2);
180 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
181
182 //f = F - 1
183 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
184 Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
185 Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
186 Double_t cr=c1*r2+c2*r1;
187 Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
188 Double_t f13= dx*cc/cr;
189 Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
190
191 //b = C*ft
192 Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
193 Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
194 Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
195 Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
196 Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
197
198 //a = f*b = f*C*ft
199 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
200
201 //F*C*Ft = C + (a + b + bt)
202 fCyy += a00 + 2*b00;
203 fCzy += a01 + b01 + b10;
204 fCey += b20;
205 fCty += b30;
206 fCcy += b40;
207 fCzz += a11 + 2*b11;
208 fCez += b21;
209 fCtz += b31;
210 fCcz += b41;
211
212 fX=x2;
213
c84a5e9e 214 //Change of the magnetic field *************
215 SaveLocalConvConst();
216 cc=fC;
217 fC*=lcc/GetLocalConvConst();
218 fE+=fX*(fC-cc);
219
74ea065c 220 //Multiple scattering ******************
221 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
222 Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
223 Double_t beta2=p2/(p2 + GetMass()*GetMass());
224 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
225
226 Double_t ey=fC*fX - fE, ez=fT;
227 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
228
229 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
230 fCte += ez*zz1*xy*theta2;
231 fCtt += zz1*zz1*theta2;
232 fCce += xz*ez*xy*theta2;
233 fCct += xz*zz1*theta2;
234 fCcc += xz*xz*theta2;
235 /*
236 Double_t dc22 = (1-ey*ey+xz*xz*fX*fX)*theta2;
237 Double_t dc32 = (xz*fX*zz1)*theta2;
238 Double_t dc33 = (zz1*zz1)*theta2;
239 Double_t dc42 = (xz*fX*xz)*theta2;
240 Double_t dc43 = (zz1*xz)*theta2;
241 Double_t dc44 = (xz*xz)*theta2;
242 fCee += dc22;
243 fCte += dc32;
244 fCtt += dc33;
245 fCce += dc42;
246 fCct += dc43;
247 fCcc += dc44;
248 */
249 //Energy losses************************
250 if((5940*beta2/(1-beta2+1e-10) - beta2) < 0){return 0;}
251
252 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
253 if (x1 < x2) dE=-dE;
254 cc=fC;
255 fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
256 fE+=fX*(fC-cc);
257
258 // track time measurement [SR, GSI 17.02.2002]
259 if (x1 < x2)
260 if (IsStartedTimeIntegral()) {
261 Double_t l2 = (fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ);
262 AddTimeStep(TMath::Sqrt(l2));
263 }
264
265 return 1;
266}
267
268//_____________________________________________________________________________
269Int_t AliTOFtrack::PropagateToInnerTOF( Bool_t holes)
270{
271 // Propagates a track of particle with mass=pm to a reference plane
272 // defined by x=xk through media of density=rho and radiationLength=x0
273
274
275 Double_t ymax=AliTOFGeometry::RinTOF()*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
276 Bool_t skip = kFALSE;
2c770f53 277 Double_t y=GetYat(AliTOFGeometry::RinTOF(),skip);
74ea065c 278 if(skip){
279 return 0;
280 }
281 if (y > ymax) {
2c770f53 282 if (!Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 283 return 0;
284 }
285 } else if (y <-ymax) {
2c770f53 286 if (!Rotate(-AliTOFGeometry::GetAlpha())) {
74ea065c 287 return 0;
288 }
289 }
290
291
2c770f53 292 Double_t x = GetX();
74ea065c 293 Int_t nsteps=Int_t((370.-x)/0.5); // 0.5 cm Steps
294 for (Int_t istep=0;istep<nsteps;istep++){
295 Float_t xp = x+istep*0.5;
296 Double_t param[2];
2c770f53 297 GetPropagationParameters(holes,param);
298 PropagateTo(xp,param[0],param[1]);
74ea065c 299
300 }
301
2c770f53 302 if(!PropagateTo(AliTOFGeometry::RinTOF()))return 0;
74ea065c 303
304 return 1;
305
306}
307
308//_____________________________________________________________________________
309Int_t AliTOFtrack::Rotate(Double_t alpha)
310{
311 // Rotates track parameters in R*phi plane
312
313
314 fAlpha += alpha;
315 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
316 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
317
318 Double_t x1=fX, y1=fY;
319 Double_t ca=cos(alpha), sa=sin(alpha);
320 Double_t r1=fC*fX - fE;
321
322 fX = x1*ca + y1*sa;
323 fY =-x1*sa + y1*ca;
324 if((r1*r1) > 1) return 0;
325 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
326
327 Double_t r2=fC*fX - fE;
328 if (TMath::Abs(r2) >= 0.90000) {
d076c8d5 329 AliWarning("Rotation failed !");
74ea065c 330 return 0;
331 }
332
333 if((r2*r2) > 1) return 0;
334 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
335 if ((fY-y0)*fC >= 0.) {
d076c8d5 336 AliWarning("Rotation failed !!!");
74ea065c 337 return 0;
338 }
339
340 //f = F - 1
341 Double_t f00=ca-1, f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
342 f20=fC*sa, f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
343
344 //b = C*ft
345 Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
346 Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
347 Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
348 Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
349 Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
350
351 //a = f*b = f*C*ft
352 Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
353
354 //F*C*Ft = C + (a + b + bt)
355 fCyy += a00 + 2*b00;
356 fCzy += b10;
357 fCey += a02+b20+b02;
358 fCty += b30;
359 fCcy += b40;
360 fCez += b12;
361 fCte += b32;
362 fCee += a22 + 2*b22;
363 fCce += b42;
364
365 return 1;
366}
367
2c770f53 368//_________________________________________________________________________
4668c628 369Double_t AliTOFtrack::GetYat(Double_t xk, Bool_t & skip) const {
2c770f53 370//-----------------------------------------------------------------
371// This function calculates the Y-coordinate of a track at the plane x=xk.
372// Needed for matching with the TOF (I.Belikov)
373//-----------------------------------------------------------------
374 skip=kFALSE;
375 Double_t c1=fC*fX - fE, r1=TMath::Sqrt(TMath::Abs(1.- c1*c1));
376 Double_t c2=fC*xk - fE, r2=TMath::Sqrt(TMath::Abs(1.- c2*c2));
377 if( ((1.- c2*c2)<0) || ((1.- c1*c1)<0) ) skip=kTRUE;
378 return fY + (xk-fX)*(c1+c2)/(r1+r2);
379}
74ea065c 380//_________________________________________________________________________
381void AliTOFtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
382{
383 // Returns reconstructed track momentum in the global system.
384
385 Double_t pt=TMath::Abs(GetPt()); // GeV/c
386 Double_t r=fC*fX-fE;
387
388 Double_t y0;
389 if(r > 1) { py = pt; px = 0; }
390 else if(r < -1) { py = -pt; px = 0; }
391 else {
392 y0=fY + sqrt(1.- r*r)/fC;
393 px=-pt*(fY-y0)*fC; //cos(phi);
394 py=-pt*(fE-fX*fC); //sin(phi);
395 }
396 pz=pt*fT;
397 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
398 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
399 px=tmp;
400
401}
402
403//_________________________________________________________________________
404void AliTOFtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
405{
406 // Returns reconstructed track coordinates in the global system.
407
408 x = fX; y = fY; z = fZ;
409 Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
410 y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
411 x=tmp;
412
413}
414
415//_________________________________________________________________________
416void AliTOFtrack::ResetCovariance() {
417 //
418 // Resets covariance matrix
419 //
420
421 fCyy*=10.;
422 fCzy=0.; fCzz*=10.;
423 fCey=0.; fCez=0.; fCee*=10.;
424 fCty=0.; fCtz=0.; fCte=0.; fCtt*=10.;
425 fCcy=0.; fCcz=0.; fCce=0.; fCct=0.; fCcc*=10.;
426}
427
428
429//_________________________________________________________________________
430void AliTOFtrack::ResetCovariance(Float_t mult) {
431 //
432 // Resets covariance matrix
433 //
434
435 fCyy*=mult;
436 fCzy*=0.; fCzz*=mult;
437 fCey*=0.; fCez*=0.; fCee*=mult;
438 fCty*=0.; fCtz*=0.; fCte*=0.; fCtt*=mult;
439 fCcy*=0.; fCcz*=0.; fCce*=0.; fCct*=0.; fCcc*=mult;
440}
441
442//_____________________________________________________________________________
443Int_t AliTOFtrack::Compare(const TObject *o) const {
444 //-----------------------------------------------------------------
445 // This function compares tracks according to the their curvature
446 //-----------------------------------------------------------------
447 AliTOFtrack *t=(AliTOFtrack*)o;
448 Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
449 Double_t c =GetSigmaY2()*GetSigmaZ2();
450 if (c>co) return 1;
451 else if (c<co) return -1;
452 return 0;
453}
454
455//_____________________________________________________________________________
456void AliTOFtrack::GetPropagationParameters(Bool_t holes, Double_t *param) {
457
2c770f53 458 //Get average medium density, x0 while propagating the track
459
460 //For TRD holes description
74ea065c 461
462 Double_t thetamin = (90.-31.1) * TMath::Pi()/180.;
463 Double_t thetamax = (90.+31.1) * TMath::Pi()/180.;
464
465 Double_t zmin = -55.;
466 Double_t zmax = 55.;
467
2c770f53 468 // Detector inner/outer radii
74ea065c 469 Double_t rTPC = 261.53;
470 Double_t rTPCTRD = 294.5;
471 Double_t rTRD = 369.1;
472
2c770f53 473 // Medium parameters
74ea065c 474 Double_t x0TPC = 40.;
475 Double_t rhoTPC =0.06124;
476
477 Double_t x0Air = 36.66;
478 Double_t rhoAir =1.2931e-3;
479
480 Double_t x0TRD = 171.7;
481 Double_t rhoTRD =0.33;
482
2c770f53 483 Int_t isec = GetSector();
74ea065c 484 Double_t xtr,ytr,ztr;
2c770f53 485 GetGlobalXYZ(xtr,ytr,ztr);
74ea065c 486 Float_t thetatr = TMath::ATan2(TMath::Sqrt(xtr*xtr+ytr*ytr),ztr);
487
488 if(holes){
489 if (isec == 0 || isec == 1 || isec == 2 ) {
490 if( thetatr>=thetamin && thetatr<=thetamax){
491 x0TRD= x0Air;
492 rhoTRD = rhoAir;
493 }
494 }
495 if (isec == 11 || isec == 12 || isec == 13 || isec == 14 || isec == 15 ) {
496 if( ztr>=zmin && ztr<=zmax){
497 x0TRD= x0Air;
498 rhoTRD = rhoAir;
499 }
500 }
501 }
502
2c770f53 503 if(GetX() <= rTPC)
74ea065c 504 {param[0]=x0TPC;param[1]=rhoTPC;}
2c770f53 505 else if(GetX() > rTPC && GetX() < rTPCTRD)
74ea065c 506 {param[0]=x0Air;param[1]=rhoAir;}
2c770f53 507 else if(GetX() >= rTPCTRD && GetX() < rTRD)
74ea065c 508 {param[0]=x0TRD;param[1]=rhoTRD;}
2c770f53 509 else if(GetX() >= rTRD )
74ea065c 510 {param[0]=x0Air;param[1]=rhoAir;}
74ea065c 511}