]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCtrack.cxx
Seting the default cotg range to +-1.05
[u/mrichter/AliRoot.git] / TPC / AliTPCtrack.cxx
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 /* $Id$ */
17
18 //-----------------------------------------------------------------
19 //           Implementation of the TPC track class
20 //        This class is used by the AliTPCtracker class
21 //      Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-----------------------------------------------------------------
23
24 #include <Riostream.h>
25
26 #include "AliTPCtrack.h"
27 #include "AliCluster.h"
28 #include "AliESDtrack.h"
29
30 ClassImp(AliTPCtrack)
31
32 //_________________________________________________________________________
33 AliTPCtrack::AliTPCtrack(): AliKalmanTrack() 
34 {
35   //-------------------------------------------------
36   // default constructor
37   //-------------------------------------------------
38   fX = fP0 = fP1 = fP2 = fP3 = fP3 = fP4 = 0.0;
39   fAlpha = fdEdx = 0.0;
40   fNumber = 0;  // [SR, 01.04.2003]
41   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=0;
42 }
43
44 //_________________________________________________________________________
45
46
47
48 AliTPCtrack::AliTPCtrack(UInt_t index, const Double_t xx[5],
49 const Double_t cc[15], Double_t xref, Double_t alpha) : AliKalmanTrack() {
50   //-----------------------------------------------------------------
51   // This is the main track constructor.
52   //-----------------------------------------------------------------
53   fX=xref;
54   fAlpha=alpha;
55   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
56   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
57   fdEdx=0.;
58
59   fP0=xx[0]; fP1=xx[1]; fP2=xx[2]; fP3=xx[3]; fP4=xx[4];
60
61   SaveLocalConvConst();
62
63   fC00=cc[0];
64   fC10=cc[1];  fC11=cc[2];
65   fC20=cc[3];  fC21=cc[4];  fC22=cc[5];
66   fC30=cc[6];  fC31=cc[7];  fC32=cc[8];  fC33=cc[9];
67   fC40=cc[10]; fC41=cc[11]; fC42=cc[12]; fC43=cc[13]; fC44=cc[14];
68
69   fIndex[0]=index;
70   SetNumberOfClusters(1);
71   //
72   //MI
73   fSdEdx      = 0;
74   fNFoundable = 0;
75   fBConstrain = 0;
76   fLastPoint  = 0;
77   fFirstPoint = 0;
78   fRemoval    = 0;
79   fTrackType  = 0;
80   fLab2       = 0;
81   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=0;
82   for (Int_t i=0; i<3;i++) fV0Indexes[i]=0;
83 }
84
85 //_____________________________________________________________________________
86 AliTPCtrack::AliTPCtrack(const AliESDtrack& t) : AliKalmanTrack() {
87   //-----------------------------------------------------------------
88   // Conversion AliESDtrack -> AliTPCtrack.
89   //-----------------------------------------------------------------
90   SetNumberOfClusters(t.GetTPCclusters(fIndex));
91   SetLabel(t.GetLabel());
92   SetMass(t.GetMass());
93   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=t.GetKinkIndex(i);
94   for (Int_t i=0; i<3;i++) fV0Indexes[i]=t.GetV0Index(i);
95
96   fdEdx  = t.GetTPCsignal();
97   fAlpha = t.GetAlpha();
98   if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
99   else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
100
101   //Conversion of the track parameters
102   Double_t x,p[5]; t.GetExternalParameters(x,p);
103   Double_t c[15]; t.GetExternalCovariance(c);
104
105   fX=x;    
106   fP0=p[0];
107   fP1=p[1];    SaveLocalConvConst();
108   fP3=p[3];    x=GetLocalConvConst();
109   fP4=p[4]/x;
110   fP2=fP4*fX - p[2];
111
112   //Conversion of the covariance matrix
113   c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
114
115   Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
116   Double_t c32=fX*c[13] - c[8];
117   Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
118
119   fC00=c[0 ];
120   fC10=c[1 ];   fC11=c[2 ];
121   fC20=c20;     fC21=c21;     fC22=c22;
122   fC30=c[6 ];   fC31=c[7 ];   fC32=c32;   fC33=c[9 ];
123   fC40=c[10];   fC41=c[11];   fC42=c42;   fC43=c[13]; fC44=c[14];
124
125   if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
126   StartTimeIntegral();
127   Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
128   SetIntegratedLength(t.GetIntegratedLength());
129   //
130   //MI
131   fSdEdx      = 0;
132   fNFoundable = 0;
133   fBConstrain = 0;
134   fLastPoint  = 0;
135   fFirstPoint = 0;
136   fRemoval    = 0;
137   fTrackType  = 0;
138   fLab2       = 0;
139   //  SetFakeRatio(t.GetTPCFakeRatio());
140 }
141
142 //_____________________________________________________________________________
143 AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) : AliKalmanTrack(t) {
144   //-----------------------------------------------------------------
145   // This is a track copy constructor.
146   //-----------------------------------------------------------------
147   fX=t.fX;
148   fAlpha=t.fAlpha;
149   fdEdx=t.fdEdx;
150
151   fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;
152
153   fC00=t.fC00;
154   fC10=t.fC10;  fC11=t.fC11;
155   fC20=t.fC20;  fC21=t.fC21;  fC22=t.fC22;
156   fC30=t.fC30;  fC31=t.fC31;  fC32=t.fC32;  fC33=t.fC33;
157   fC40=t.fC40;  fC41=t.fC41;  fC42=t.fC42;  fC43=t.fC43;  fC44=t.fC44;
158
159   //Int_t n=GetNumberOfClusters();
160   for (Int_t i=0; i<kMaxRow; i++) fIndex[i]=t.fIndex[i];
161   //
162   //MI 
163   fSdEdx      = t.fSdEdx;
164   fNFoundable = t.fNFoundable;
165   fBConstrain = t.fBConstrain;
166   fLastPoint  = t.fLastPoint;
167   fFirstPoint = t.fFirstPoint;
168   fRemoval    = t.fRemoval ;
169   fTrackType  = t.fTrackType;
170   fLab2       = t.fLab2;
171   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=t.fKinkIndexes[i];
172   for (Int_t i=0; i<3;i++) fV0Indexes[i]=t.fV0Indexes[i];
173 }
174
175 //_____________________________________________________________________________
176 Int_t AliTPCtrack::Compare(const TObject *o) const {
177   //-----------------------------------------------------------------
178   // This function compares tracks according to the their curvature
179   //-----------------------------------------------------------------
180   AliTPCtrack *t=(AliTPCtrack*)o;
181   //Double_t co=TMath::Abs(t->Get1Pt());
182   //Double_t c =TMath::Abs(Get1Pt());
183   Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
184   Double_t c =GetSigmaY2()*GetSigmaZ2();
185   if (c>co) return 1;
186   else if (c<co) return -1;
187   return 0;
188 }
189
190 //_____________________________________________________________________________
191 void AliTPCtrack::GetExternalCovariance(Double_t cc[15]) const {
192  //-------------------------------------------------------------------------
193   // This function returns an external representation of the covriance matrix.
194   //   (See comments in AliTPCtrack.h about external track representation)
195   //-------------------------------------------------------------------------
196   Double_t a=GetLocalConvConst();
197
198   Double_t c22=fX*fX*fC44-2*fX*fC42+fC22;
199   Double_t c32=fX*fC43-fC32;
200   Double_t c20=fX*fC40-fC20, c21=fX*fC41-fC21, c42=fX*fC44-fC42;
201   
202   cc[0 ]=fC00;
203   cc[1 ]=fC10;   cc[2 ]=fC11;
204   cc[3 ]=c20;    cc[4 ]=c21;    cc[5 ]=c22;
205   cc[6 ]=fC30;   cc[7 ]=fC31;   cc[8 ]=c32;   cc[9 ]=fC33; 
206   cc[10]=fC40*a; cc[11]=fC41*a; cc[12]=c42*a; cc[13]=fC43*a; cc[14]=fC44*a*a;
207
208 }
209
210 //_____________________________________________________________________________
211 Double_t AliTPCtrack::GetPredictedChi2(const AliCluster *c) const 
212 {
213   //-----------------------------------------------------------------
214   // This function calculates a predicted chi2 increment.
215   //-----------------------------------------------------------------
216   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
217   r00+=fC00; r01+=fC10; r11+=fC11;
218
219   Double_t det=r00*r11 - r01*r01;
220   if (TMath::Abs(det) < 1.e-10) {
221     Int_t n=GetNumberOfClusters();
222     if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
223     return 1e10;
224   }
225   Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
226   
227   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
228   
229   return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
230 }
231
232 Double_t AliTPCtrack::GetYat(Double_t xk) const {
233 //-----------------------------------------------------------------
234 // This function calculates the Y-coordinate of a track at the plane x=xk.
235 //-----------------------------------------------------------------
236     Double_t c1=fP4*fX - fP2, r1=TMath::Sqrt(1.- c1*c1);
237     Double_t c2=fP4*xk - fP2;
238     if (c2*c2>0.99999) {
239        Int_t n=GetNumberOfClusters();
240        if (n>4) cerr<<n<<"AliTPCtrack::GetYat: can't evaluate the y-coord !\n";
241        return 1e10;
242     } 
243     Double_t r2=TMath::Sqrt(1.- c2*c2);
244     return fP0 + (xk-fX)*(c1+c2)/(r1+r2);
245 }
246
247 //_____________________________________________________________________________
248 Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t /*x0*/,Double_t rho) {
249   //-----------------------------------------------------------------
250   // This function propagates a track to a reference plane x=xk.
251   //-----------------------------------------------------------------
252   if (TMath::Abs(fP4*xk - fP2) >= 0.9) {
253     //    Int_t n=GetNumberOfClusters();
254     //if (n>4) cerr<<n<<" AliTPCtrack warning: Propagation failed !\n";
255     return 0;
256   }
257   Double_t lcc=GetLocalConvConst();  
258
259   // old position for time [SR, GSI 17.02.2003]
260   Double_t oldX = fX;
261   Double_t oldY = fP0;
262   Double_t oldZ = fP1;
263   //
264
265   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
266   Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
267   Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
268   
269   fP0 += dx*(c1+c2)/(r1+r2);
270   fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
271
272   //f = F - 1
273   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
274   Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
275   Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
276   Double_t cr=c1*r2+c2*r1;
277   Double_t f12=-dx*fP3*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
278   Double_t f13= dx*cc/cr; 
279   Double_t f14=dx*fP3*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
280
281   //b = C*ft
282   Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
283   Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
284   Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
285   Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
286   Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
287   
288   //a = f*b = f*C*ft
289   Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
290
291   //F*C*Ft = C + (a + b + bt)
292   fC00 += a00 + 2*b00;
293   fC10 += a01 + b01 + b10; 
294   fC20 += b20;
295   fC30 += b30;
296   fC40 += b40;
297   fC11 += a11 + 2*b11;
298   fC21 += b21; 
299   fC31 += b31; 
300   fC41 += b41; 
301
302   fX=x2;
303
304   //Change of the magnetic field *************
305   SaveLocalConvConst();
306   cc=fP4;
307   fP4*=lcc/GetLocalConvConst();
308   fP2+=fX*(fP4-cc);
309
310   //Multiple scattering ******************
311   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fP0)*(y1-fP0)+(z1-fP1)*(z1-fP1));
312   Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
313   Double_t beta2=p2/(p2 + GetMass()*GetMass());
314   beta2 = TMath::Min(beta2,0.99999999999);
315   //Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
316   Double_t theta2=1.0259e-6*10*10/20/(beta2*p2)*d*rho;
317
318   Double_t ey=fP4*fX - fP2, ez=fP3;
319   Double_t xz=fP4*ez, zz1=ez*ez+1, xy=fP2+ey;
320     
321   fC22 += (2*ey*ez*ez*fP2+1-ey*ey+ez*ez+fP2*fP2*ez*ez)*theta2;
322   fC32 += ez*zz1*xy*theta2;
323   fC33 += zz1*zz1*theta2;
324   fC42 += xz*ez*xy*theta2;
325   fC43 += xz*zz1*theta2;
326   fC44 += xz*xz*theta2;
327   /*
328   //
329   //MI coeficints
330   Double_t dc22 = (1-ey*ey+xz*xz*fX*fX)*theta2;
331   Double_t dc32 = (xz*fX*zz1)*theta2;
332   Double_t dc33 = (zz1*zz1)*theta2;
333   Double_t dc42 = (xz*fX*xz)*theta2;
334   Double_t dc43 = (zz1*xz)*theta2;
335   Double_t dc44 = (xz*xz)*theta2; 
336   fC22 += dc22;
337   fC32 += dc32;
338   fC33 += dc33;
339   fC42 += dc42;
340   fC43 += dc43;
341   fC44 += dc44;
342   */
343   //Energy losses ************************
344   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
345   if (x1 < x2) dE=-dE;
346   cc=fP4;
347
348   //Double_t E = sqrt(p2+GetMass()*GetMass());
349   //Double_t mifac  = TMath::Sqrt(1.+dE*dE/p2+2*E*dE/p2)-1;
350   //Double_t belfac = E*dE/p2;
351                                //
352   fP4*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
353   fP2+=fX*(fP4-cc);
354
355   // Integrated Time [SR, GSI, 17.02.2003]
356  if (x1 < x2)
357  if (IsStartedTimeIntegral()) {
358     Double_t l2 = (fX-oldX)*(fX-oldX)+(fP0-oldY)*(fP0-oldY)+(fP1-oldZ)*(fP1-oldZ);
359     AddTimeStep(TMath::Sqrt(l2));
360   }
361   //
362
363   return 1;
364 }
365
366 //_____________________________________________________________________________
367 Int_t AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho) 
368 {
369   //-----------------------------------------------------------------
370   // This function propagates tracks to the "vertex".
371   //-----------------------------------------------------------------
372   Double_t c=fP4*fX - fP2;
373   Double_t tgf=-fP2/(fP4*fP0 + sqrt(1-c*c));
374   Double_t snf=tgf/sqrt(1.+ tgf*tgf);
375   Double_t xv=(fP2+snf)/fP4;
376   return PropagateTo(xv,x0,rho);
377 }
378
379 //_____________________________________________________________________________
380 Int_t AliTPCtrack::Update(const AliCluster *c, Double_t chisq, UInt_t index) {
381   //-----------------------------------------------------------------
382   // This function associates a cluster with this track.
383   //-----------------------------------------------------------------
384   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
385   r00+=fC00; r01+=fC10; r11+=fC11;
386   Double_t det=r00*r11 - r01*r01;
387   Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
388
389   Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
390   Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
391   Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
392   Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
393   Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
394
395   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
396   Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
397   if (TMath::Abs(cur*fX-eta) >= 0.9) {
398     //    Int_t n=GetNumberOfClusters();
399     //if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
400     return 0;
401   }
402
403   fP0 += k00*dy + k01*dz;
404   fP1 += k10*dy + k11*dz;
405   fP2  = eta;
406   fP3 += k30*dy + k31*dz;
407   fP4  = cur;
408
409   Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
410   Double_t c12=fC21, c13=fC31, c14=fC41;
411
412   fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
413   fC20-=k00*c02+k01*c12;   fC30-=k00*c03+k01*c13;
414   fC40-=k00*c04+k01*c14; 
415
416   fC11-=k10*c01+k11*fC11;
417   fC21-=k10*c02+k11*c12;   fC31-=k10*c03+k11*c13;
418   fC41-=k10*c04+k11*c14; 
419
420   fC22-=k20*c02+k21*c12;   fC32-=k20*c03+k21*c13;
421   fC42-=k20*c04+k21*c14; 
422
423   fC33-=k30*c03+k31*c13;
424   fC43-=k40*c03+k41*c13; 
425
426   fC44-=k40*c04+k41*c14; 
427
428   Int_t n=GetNumberOfClusters();
429   fIndex[n]=index;
430   SetNumberOfClusters(n+1);
431   SetChi2(GetChi2()+chisq);
432
433   return 1;
434 }
435
436 //_____________________________________________________________________________
437 Int_t AliTPCtrack::Rotate(Double_t alpha)
438 {
439   //-----------------------------------------------------------------
440   // This function rotates this track.
441   //-----------------------------------------------------------------
442   fAlpha += alpha;
443   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
444   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
445   
446   Double_t x1=fX, y1=fP0;
447   Double_t ca=cos(alpha), sa=sin(alpha);
448   Double_t r1=fP4*fX - fP2;
449   
450   fX = x1*ca + y1*sa;
451   fP0=-x1*sa + y1*ca;
452   fP2=fP2*ca + (fP4*y1 + sqrt(1.- r1*r1))*sa;
453   
454   Double_t r2=fP4*fX - fP2;
455   if (TMath::Abs(r2) >= 0.99999) {
456     Int_t n=GetNumberOfClusters();
457     if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !\n";
458     return 0;
459   }
460   
461   Double_t y0=fP0 + sqrt(1.- r2*r2)/fP4;
462   if ((fP0-y0)*fP4 >= 0.) {
463     Int_t n=GetNumberOfClusters();
464     if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !!!\n";
465     return 0;
466   }
467
468   //f = F - 1
469   Double_t f00=ca-1,    f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa, 
470            f20=fP4*sa,  f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
471
472   //b = C*ft
473   Double_t b00=fC00*f00, b02=fC00*f20+fC40*f24+fC20*f22;
474   Double_t b10=fC10*f00, b12=fC10*f20+fC41*f24+fC21*f22;
475   Double_t b20=fC20*f00, b22=fC20*f20+fC42*f24+fC22*f22;
476   Double_t b30=fC30*f00, b32=fC30*f20+fC43*f24+fC32*f22;
477   Double_t b40=fC40*f00, b42=fC40*f20+fC44*f24+fC42*f22;
478
479   //a = f*b = f*C*ft
480   Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
481
482   // *** Double_t dy2=fCyy;
483
484   //F*C*Ft = C + (a + b + bt)
485   fC00 += a00 + 2*b00;
486   fC10 += b10;
487   fC20 += a02+b20+b02;
488   fC30 += b30;
489   fC40 += b40;
490   fC21 += b12;
491   fC32 += b32;
492   fC22 += a22 + 2*b22;
493   fC42 += b42; 
494
495   // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
496   // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
497
498   return 1;
499 }
500
501 void AliTPCtrack::ResetCovariance() {
502   //------------------------------------------------------------------
503   //This function makes a track forget its history :)  
504   //------------------------------------------------------------------
505
506   fC00*=10.;
507   fC10=0.;  fC11*=10.;
508   fC20=0.;  fC21=0.;  fC22*=10.;
509   fC30=0.;  fC31=0.;  fC32=0.;  fC33*=10.;
510   fC40=0.;  fC41=0.;  fC42=0.;  fC43=0.;  fC44*=10.;
511
512 }
513
514 ////////////////////////////////////////////////////////////////////////
515 Double_t AliTPCtrack::Phi() const {
516 //
517 //
518 //
519   Double_t phi =  TMath::ASin(GetSnp()) + fAlpha;
520   if (phi<0) phi+=2*TMath::Pi();
521   if (phi>=2*TMath::Pi()) phi-=2*TMath::Pi();
522   return phi;
523 }
524 ////////////////////////////////////////////////////////////////////////
525
526
527
528 ////////////////////////////////////////////////////////////////////////
529 // MI ADDITION
530
531 Float_t AliTPCtrack::Density(Int_t row0, Int_t row1)
532 {
533   //
534   // calculate cluster density
535   Int_t good  = 0;
536   Int_t found = 0;
537   //if (row0<fFirstPoint) row0 = fFirstPoint;
538   if (row1>fLastPoint) row1 = fLastPoint;
539
540   
541   for (Int_t i=row0;i<=row1;i++){ 
542     //    Int_t index = fClusterIndex[i];
543     Int_t index = fIndex[i];
544     if (index!=-1)  good++;
545     if (index>0)    found++;
546   }
547   Float_t density=0;
548   if (good>0) density = Float_t(found)/Float_t(good);
549   return density;
550 }
551
552
553 Float_t AliTPCtrack::Density2(Int_t row0, Int_t row1)
554 {
555   //
556   // calculate cluster density
557   Int_t good  = 0;
558   Int_t found = 0;
559   //  
560   for (Int_t i=row0;i<=row1;i++){     
561     Int_t index = fIndex[i];
562     if (index!=-1)  good++;
563     if (index>0)    found++;
564   }
565   Float_t density=0;
566   if (good>0) density = Float_t(found)/Float_t(good);
567   return density;
568 }
569
570
571 Double_t AliTPCtrack::GetZat0() const
572 {
573   //
574   // return virtual z - supposing that x = 0
575   if (TMath::Abs(fP2)>1) return 0;
576   if (TMath::Abs(fX*fP4-fP2)>1) return 0;
577   Double_t vz = fP1+fP3/fP4*(asin(-fP2)-asin(fX*fP4-fP2));
578   return vz;
579 }
580
581
582 Double_t AliTPCtrack::GetD(Double_t x, Double_t y) const {
583   //------------------------------------------------------------------
584   // This function calculates the transverse impact parameter
585   // with respect to a point with global coordinates (x,y)
586   //------------------------------------------------------------------
587   //Double_t xt=fX, yt=fP0;
588
589   Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
590   Double_t a = x*cs + y*sn;
591   y = -x*sn + y*cs; x=a;
592   //
593   Double_t r  = TMath::Abs(1/fP4);
594   Double_t x0 = TMath::Abs(fP2*r);
595   Double_t y0 = fP0;
596   y0= fP0+TMath::Sqrt(1-(fP4*fX-fP2)*(fP4*fX-fP2))/fP4;
597   
598   Double_t  delta = TMath::Sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));  
599   //  Double_t  delta = TMath::Sqrt(TMath::Abs(x*x-2*x0*x+x0*x0+ y*y-2*y*y0+y0*y0));
600   delta -= TMath::Abs(r);
601   return delta;  
602 }
603
604 //
605 //
606
607 void  AliTPCtrack::UpdatePoints()
608 {
609   //--------------------------------------------------
610   //calculates first ,amx dens and last points
611   //--------------------------------------------------
612   Float_t density[160];
613   for (Int_t i=0;i<160;i++) density[i]=-1.;
614   fPoints[0]= 160;
615   fPoints[1] = -1;
616   //
617   Int_t ngood=0;
618   Int_t undeff=0;
619   Int_t nall =0;
620   Int_t range=20;
621   for (Int_t i=0;i<160;i++){
622     Int_t last = i-range;
623     if (nall<range) nall++;
624     if (last>=0){
625       if (fIndex[last]>0&& (fIndex[last]&0x8000)==0) ngood--;
626       if (fIndex[last]==-1) undeff--;
627     }
628     if (fIndex[i]>0&& (fIndex[i]&0x8000)==0)   ngood++;
629     if (fIndex[i]==-1) undeff++;
630     if (nall==range &&undeff<range/2) density[i-range/2] = Float_t(ngood)/Float_t(nall-undeff);
631   }
632   Float_t maxdens=0;
633   Int_t indexmax =0;
634   for (Int_t i=0;i<160;i++){
635     if (density[i]<0) continue;
636     if (density[i]>maxdens){
637       maxdens=density[i];
638       indexmax=i;
639     }
640   }
641   //
642   //max dens point
643   fPoints[3] = maxdens;
644   fPoints[1] = indexmax;
645   //
646   // last point
647   for (Int_t i=indexmax;i<160;i++){
648     if (density[i]<0) continue;
649     if (density[i]<maxdens/2.) {
650       break;
651     }
652     fPoints[2]=i;
653   }
654   //
655   // first point
656   for (Int_t i=indexmax;i>0;i--){
657     if (density[i]<0) continue;
658     if (density[i]<maxdens/2.) {
659       break;
660     }
661     fPoints[0]=i;
662   }
663   //
664 }