Update of TPC code and macros by M.Kowalski
[u/mrichter/AliRoot.git] / TPC / AliTPCtrack.cxx
CommitLineData
73042f01 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
16/*
17$Log$
37831078 18Revision 1.2 2000/06/30 12:07:50 kowal2
19Updated from the TPC-PreRelease branch
20
73042f01 21Revision 1.1.2.2 2000/06/25 08:38:41 kowal2
22Splitted from AliTPCtracking
23
24*/
25
26//-----------------------------------------------------------------
27// Implementation of the TPC track class
28//
29// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
30//-----------------------------------------------------------------
31
32#include "AliTPCtrack.h"
33#include "AliTPCcluster.h"
34#include "AliTPCClustersRow.h"
35#include "AliTPCClustersArray.h"
36
37ClassImp(AliTPCtrack)
38//_________________________________________________________________________
39AliTPCtrack::AliTPCtrack(UInt_t index, const Double_t xx[5],
40const Double_t cc[15], Double_t xref, Double_t alpha) {
41 //-----------------------------------------------------------------
42 // This is the main track constructor.
43 //-----------------------------------------------------------------
44 fLab=-1;
45 fChi2=0.;
46 fdEdx=0.;
47
48 fAlpha=alpha;
49 fX=xref;
50
51 fY=xx[0]; fZ=xx[1]; fC=xx[2]; fE=xx[3]; fT=xx[4];
52
53 fCyy=cc[0];
54 fCzy=cc[1]; fCzz=cc[2];
55 fCcy=cc[3]; fCcz=cc[4]; fCcc=cc[5];
56 fCey=cc[6]; fCez=cc[7]; fCec=cc[8]; fCee=cc[9];
57 fCty=cc[10]; fCtz=cc[11]; fCtc=cc[12]; fCte=cc[13]; fCtt=cc[14];
58
59 fN=0;
60 fIndex[fN++]=index;
61}
62
63//_____________________________________________________________________________
64AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) {
65 //-----------------------------------------------------------------
66 // This is a track copy constructor.
67 //-----------------------------------------------------------------
68 fLab=t.fLab;
69 fChi2=t.fChi2;
70 fdEdx=t.fdEdx;
71
72 fAlpha=t.fAlpha;
73 fX=t.fX;
74
75 fY=t.fY; fZ=t.fZ; fC=t.fC; fE=t.fE; fT=t.fT;
76
77 fCyy=t.fCyy;
78 fCzy=t.fCzy; fCzz=t.fCzz;
79 fCcy=t.fCcy; fCcz=t.fCcz; fCcc=t.fCcc;
80 fCey=t.fCey; fCez=t.fCez; fCec=t.fCec; fCee=t.fCee;
81 fCty=t.fCty; fCtz=t.fCtz; fCtc=t.fCtc; fCte=t.fCte; fCtt=t.fCtt;
82
83 fN=t.fN;
84 for (Int_t i=0; i<fN; i++) fIndex[i]=t.fIndex[i];
85}
86
87//_____________________________________________________________________________
88void AliTPCtrack::GetCovariance(Double_t cc[15]) const {
89 //just to calm down our rule checker
90 cc[0]=fCyy;
91 cc[1]=fCzy; cc[2]=fCzz;
92 cc[3]=fCcy; cc[4]=fCcz; cc[5]=fCcc;
93 cc[6]=fCey; cc[7]=fCez; cc[8]=fCec; cc[9]=fCee;
94 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCtc; cc[13]=fCte; cc[14]=fCtt;
95}
96
97//_____________________________________________________________________________
98Int_t AliTPCtrack::Compare(TObject *o) {
99 //-----------------------------------------------------------------
100 // This function compares tracks according to the their curvature
101 //-----------------------------------------------------------------
102 AliTPCtrack *t=(AliTPCtrack*)o;
103 //Double_t co=t->GetSigmaY2();
104 //Double_t c =GetSigmaY2();
105 Double_t co=TMath::Abs(t->GetC());
106 Double_t c =TMath::Abs(GetC());
107 if (c>co) return 1;
108 else if (c<co) return -1;
109 return 0;
110}
111
112//_____________________________________________________________________________
113Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
114{
115 //-----------------------------------------------------------------
116 // This function propagates a track to a reference plane x=xk.
117 //-----------------------------------------------------------------
118 if (TMath::Abs(fC*xk - fE) >= 0.99999) {
119 if (fN>4) cerr<<fN<<" AliTPCtrack warning: Propagation failed !\n";
120 return 0;
121 }
122
123 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
124 Double_t c1=fC*x1 - fE, r1=sqrt(1.- c1*c1);
125 Double_t c2=fC*x2 - fE, r2=sqrt(1.- c2*c2);
126
127 fY += dx*(c1+c2)/(r1+r2);
128 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
129
130 //f = F - 1
131 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
132 Double_t f02= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
133 Double_t f03=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
134 Double_t cr=c1*r2+c2*r1;
135 Double_t f12= dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
136 Double_t f13=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
137 Double_t f14= dx*cc/cr;
138
139 //b = C*ft
140 Double_t b00=f02*fCcy + f03*fCey, b01=f12*fCcy + f13*fCey + f14*fCty;
141 Double_t b10=f02*fCcz + f03*fCez, b11=f12*fCcz + f13*fCez + f14*fCtz;
142 Double_t b20=f02*fCcc + f03*fCec, b21=f12*fCcc + f13*fCec + f14*fCtc;
143 Double_t b30=f02*fCec + f03*fCee, b31=f12*fCec + f13*fCee + f14*fCte;
144 Double_t b40=f02*fCtc + f03*fCte, b41=f12*fCtc + f13*fCte + f14*fCtt;
145
146 //a = f*b = f*C*ft
147 Double_t a00=f02*b20+f03*b30,a01=f02*b21+f03*b31,a11=f12*b21+f13*b31+f14*b41;
148
149 //F*C*Ft = C + (a + b + bt)
150 fCyy += a00 + 2*b00;
151 fCzy += a01 + b01 + b10;
152 fCcy += b20;
153 fCey += b30;
154 fCty += b40;
155 fCzz += a11 + 2*b11;
156 fCcz += b21;
157 fCez += b31;
158 fCtz += b41;
159
160 fX=x2;
161
162 //Multiple scattering******************
163 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
164 Double_t p2=GetPt()*GetPt()*(1.+fT*fT);
165 Double_t beta2=p2/(p2 + pm*pm);
166
167 Double_t ey=fC*fX - fE, ez=fT;
168 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
169
170 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
171 fCcc += xz*xz*theta2;
172 fCec += xz*ez*xy*theta2;
173 fCtc += xz*zz1*theta2;
174 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
175 fCte += ez*zz1*xy*theta2;
176 fCtt += zz1*zz1*theta2;
177
178 //Energy losses************************
179 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
180 if (x1 < x2) dE=-dE;
37831078 181 cc=fC;
73042f01 182 fC*=(1.- sqrt(p2+pm*pm)/p2*dE);
37831078 183 fE+=fX*(fC-cc);
73042f01 184
185 return 1;
186}
187
188//_____________________________________________________________________________
189void AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm)
190{
191 //-----------------------------------------------------------------
192 // This function propagates tracks to the "vertex".
193 //-----------------------------------------------------------------
194 Double_t c=fC*fX - fE;
195 Double_t tgf=-fE/(fC*fY + sqrt(1-c*c));
196 Double_t snf=tgf/sqrt(1.+ tgf*tgf);
197 Double_t xv=(fE+snf)/fC;
198 PropagateTo(xv,x0,rho,pm);
199}
200
201//_____________________________________________________________________________
202void AliTPCtrack::Update(const AliTPCcluster *c, Double_t chisq, UInt_t index)
203{
204 //-----------------------------------------------------------------
205 // This function associates a cluster with this track.
206 //-----------------------------------------------------------------
207 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
208 r00+=fCyy; r01+=fCzy; r11+=fCzz;
209 Double_t det=r00*r11 - r01*r01;
210 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
211
212 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
213 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
214 Double_t k20=fCcy*r00+fCcz*r01, k21=fCcy*r01+fCcz*r11;
215 Double_t k30=fCey*r00+fCez*r01, k31=fCey*r01+fCez*r11;
216 Double_t k40=fCty*r00+fCtz*r01, k41=fCty*r01+fCtz*r11;
217
218 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
219 Double_t cur=fC + k20*dy + k21*dz, eta=fE + k30*dy + k31*dz;
220 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
221 if (fN>4) cerr<<fN<<" AliTPCtrack warning: Filtering failed !\n";
222 return;
223 }
224
225 fY += k00*dy + k01*dz;
226 fZ += k10*dy + k11*dz;
227 fC = cur;
228 fE = eta;
229 fT += k40*dy + k41*dz;
230
231 Double_t c01=fCzy, c02=fCcy, c03=fCey, c04=fCty;
232 Double_t c12=fCcz, c13=fCez, c14=fCtz;
233
234 fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
235 fCcy-=k00*c02+k01*c12; fCey-=k00*c03+k01*c13;
236 fCty-=k00*c04+k01*c14;
237
238 fCzz-=k10*c01+k11*fCzz;
239 fCcz-=k10*c02+k11*c12; fCez-=k10*c03+k11*c13;
240 fCtz-=k10*c04+k11*c14;
241
242 fCcc-=k20*c02+k21*c12; fCec-=k20*c03+k21*c13;
243 fCtc-=k20*c04+k21*c14;
244
245 fCee-=k30*c03+k31*c13;
246 fCte-=k30*c04+k31*c14;
247
248 fCtt-=k40*c04+k41*c14;
249
250 fIndex[fN++]=index;
251 fChi2 += chisq;
252}
253
254//_____________________________________________________________________________
255Int_t AliTPCtrack::Rotate(Double_t alpha)
256{
257 //-----------------------------------------------------------------
258 // This function rotates this track.
259 //-----------------------------------------------------------------
260 fAlpha += alpha;
261
262 Double_t x1=fX, y1=fY;
263 Double_t ca=cos(alpha), sa=sin(alpha);
264 Double_t r1=fC*fX - fE;
265
266 fX = x1*ca + y1*sa;
267 fY=-x1*sa + y1*ca;
268 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
269
270 Double_t r2=fC*fX - fE;
271 if (TMath::Abs(r2) >= 0.99999) {
272 if (fN>4) cerr<<fN<<" AliTPCtrack warning: Rotation failed !\n";
273 return 0;
274 }
275
276 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
277 if ((fY-y0)*fC >= 0.) {
278 if (fN>4) cerr<<fN<<" AliTPCtrack warning: Rotation failed !!!\n";
279 return 0;
280 }
281
282 //f = F - 1
283 Double_t f00=ca-1, f32=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
284 f30=fC*sa, f33=(ca + sa*r1/sqrt(1.- r1*r1))-1;
285
286 //b = C*ft
287 Double_t b00=fCyy*f00, b03=fCyy*f30+fCcy*f32+fCey*f33;
288 Double_t b10=fCzy*f00, b13=fCzy*f30+fCcz*f32+fCez*f33;
289 Double_t b20=fCcy*f00, b23=fCcy*f30+fCcc*f32+fCec*f33;
290 Double_t b30=fCey*f00, b33=fCey*f30+fCec*f32+fCee*f33;
291 Double_t b40=fCty*f00, b43=fCty*f30+fCtc*f32+fCte*f33;
292
293 //a = f*b = f*C*ft
294 Double_t a00=f00*b00, a03=f00*b03, a33=f30*b03+f32*b23+f33*b33;
295
296 // *** Double_t dy2=fCyy;
297
298 //F*C*Ft = C + (a + b + bt)
299 fCyy += a00 + 2*b00;
300 fCzy += b10;
301 fCcy += b20;
302 fCey += a03+b30+b03;
303 fCty += b40;
304 fCez += b13;
305 fCec += b23;
306 fCee += a33 + 2*b33;
307 fCte += b43;
308
309 // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
310 // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
311
312 return 1;
313}
314
315//_____________________________________________________________________________
316Double_t AliTPCtrack::GetPredictedChi2(const AliTPCcluster *c) const
317{
318 //-----------------------------------------------------------------
319 // This function calculates a predicted chi2 increment.
320 //-----------------------------------------------------------------
321 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
322 r00+=fCyy; r01+=fCzy; r11+=fCzz;
323
324 Double_t det=r00*r11 - r01*r01;
325 if (TMath::Abs(det) < 1.e-10) {
326 if (fN>4) cerr<<fN<<" AliTPCtrack warning: Singular matrix !\n";
327 return 1e10;
328 }
329 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
330
331 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
332
333 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
334}
335
336//_____________________________________________________________________________
337void AliTPCtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
338{
339 //-----------------------------------------------------------------
340 // This function returns reconstructed track momentum in the global system.
341 //-----------------------------------------------------------------
342 Double_t pt=TMath::Abs(GetPt()); // GeV/c
343 Double_t r=fC*fX-fE;
344 Double_t y0=fY + sqrt(1.- r*r)/fC;
345 px=-pt*(fY-y0)*fC; //cos(phi);
346 py=-pt*(fE-fX*fC); //sin(phi);
347 pz=pt*fT;
348 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
349 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
350 px=tmp;
351}
352
353//_____________________________________________________________________________
354void AliTPCtrack::CookLabel(AliTPCClustersArray *ca) {
355 //-----------------------------------------------------------------
356 // This function cooks the track label. If label<0, this track is fake.
357 //-----------------------------------------------------------------
358 Int_t *lb=new Int_t[fN];
359 Int_t *mx=new Int_t[fN];
360 AliTPCcluster **clusters=new AliTPCcluster*[fN];
361
362 Int_t i;
363 Int_t sec,row,ncl;
364 for (i=0; i<fN; i++) {
365 lb[i]=mx[i]=0;
366 GetCluster(i,sec,row,ncl);
367 AliTPCClustersRow *clrow=ca->GetRow(sec,row);
368 clusters[i]=(AliTPCcluster*)(*clrow)[ncl];
369 }
370
371 Int_t lab=123456789;
372 for (i=0; i<fN; i++) {
373 AliTPCcluster *c=clusters[i];
374 lab=TMath::Abs(c->GetLabel(0));
375 Int_t j;
376 for (j=0; j<fN; j++)
377 if (lb[j]==lab || mx[j]==0) break;
378 lb[j]=lab;
379 (mx[j])++;
380 }
381
382 Int_t max=0;
383 for (i=0; i<fN; i++)
384 if (mx[i]>max) {max=mx[i]; lab=lb[i];}
385
386 for (i=0; i<fN; i++) {
387 AliTPCcluster *c=clusters[i];
388 if (TMath::Abs(c->GetLabel(1)) == lab ||
389 TMath::Abs(c->GetLabel(2)) == lab ) max++;
390 }
391
392 SetLabel(-lab);
393 if (1.-Float_t(max)/fN <= 0.10) {
394 //Int_t tail=Int_t(0.08*fN);
395 Int_t tail=14;
396 max=0;
397 for (i=1; i<=tail; i++) {
398 AliTPCcluster *c=clusters[fN-i];
399 if (lab == TMath::Abs(c->GetLabel(0)) ||
400 lab == TMath::Abs(c->GetLabel(1)) ||
401 lab == TMath::Abs(c->GetLabel(2))) max++;
402 }
403 if (max >= Int_t(0.5*tail)) SetLabel(lab);
404 }
405
406 delete[] lb;
407 delete[] mx;
408 delete[] clusters;
409}
410
411//____________________________________________________________________________
412void AliTPCtrack::Streamer(TBuffer &R__b)
413{
414 //-----------------------------------------------------
415 // This is AliTPCtrack streamer.
416 //-----------------------------------------------------
417 if (R__b.IsReading()) {
418 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
419 TObject::Streamer(R__b);
420 R__b >> fLab;
421 R__b >> fChi2;
422 R__b >> fdEdx;
423 R__b >> fAlpha;
424 R__b >> fX;
425 R__b >> fY;
426 R__b >> fZ;
427 R__b >> fC;
428 R__b >> fE;
429 R__b >> fT;
430 R__b >> fCyy;
431 R__b >> fCzy;
432 R__b >> fCzz;
433 R__b >> fCcy;
434 R__b >> fCcz;
435 R__b >> fCcc;
436 R__b >> fCey;
437 R__b >> fCez;
438 R__b >> fCec;
439 R__b >> fCee;
440 R__b >> fCty;
441 R__b >> fCtz;
442 R__b >> fCtc;
443 R__b >> fCte;
444 R__b >> fCtt;
445 R__b >> fN;
446 for (Int_t i=0; i<fN; i++) R__b >> fIndex[i];
447 } else {
448 R__b.WriteVersion(AliTPCtrack::IsA());
449 TObject::Streamer(R__b);
450 R__b << fLab;
451 R__b << fChi2;
452 R__b << fdEdx;
453 R__b << fAlpha;
454 R__b << fX;
455 R__b << fY;
456 R__b << fZ;
457 R__b << fC;
458 R__b << fE;
459 R__b << fT;
460 R__b << fCyy;
461 R__b << fCzy;
462 R__b << fCzz;
463 R__b << fCcy;
464 R__b << fCcz;
465 R__b << fCcc;
466 R__b << fCey;
467 R__b << fCez;
468 R__b << fCec;
469 R__b << fCee;
470 R__b << fCty;
471 R__b << fCtz;
472 R__b << fCtc;
473 R__b << fCte;
474 R__b << fCtt;
475 R__b << fN;
476 for (Int_t i=0; i<fN; i++) R__b << fIndex[i];
477 }
478}
479
480