]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCtrack.cxx
Changes suggested by Alessandra and Paolo to avoid overlapped
[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 //-----------------------------------------------------------------
17 //           Implementation of the TPC track class
18 //
19 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
20 //-----------------------------------------------------------------
21
22 #include <iostream.h>
23
24 #include "AliCluster.h"
25 #include "AliTPCtrack.h"
26 #include "AliTPCcluster.h"
27 #include "AliTPCClustersRow.h"
28 #include "AliTPCClustersArray.h"
29
30 ClassImp(AliTPCtrack)
31 //_________________________________________________________________________
32 AliTPCtrack::AliTPCtrack(UInt_t index, const Double_t xx[5],
33 const Double_t cc[15], Double_t xref, Double_t alpha) : AliKalmanTrack() {
34   //-----------------------------------------------------------------
35   // This is the main track constructor.
36   //-----------------------------------------------------------------
37   fdEdx=0.;
38
39   fAlpha=alpha;
40   fX=xref;
41
42   fP0=xx[0]; fP1=xx[1]; fP2=xx[2]; fP3=xx[3]; fP4=xx[4];
43
44   fC00=cc[0];
45   fC10=cc[1];  fC11=cc[2];
46   fC20=cc[3];  fC21=cc[4];  fC22=cc[5];
47   fC30=cc[6];  fC31=cc[7];  fC32=cc[8];  fC33=cc[9];
48   fC40=cc[10]; fC41=cc[11]; fC42=cc[12]; fC43=cc[13]; fC44=cc[14];
49
50   fIndex[fN++]=index;
51 }
52
53 //_____________________________________________________________________________
54 AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) : AliKalmanTrack(t) {
55   //-----------------------------------------------------------------
56   // This is a track copy constructor.
57   //-----------------------------------------------------------------
58   for (Int_t i=0; i<fN; i++) fIndex[i]=t.fIndex[i];
59
60   fdEdx=t.fdEdx;
61
62   fAlpha=t.fAlpha;
63   fX=t.fX;
64 }
65
66 //_____________________________________________________________________________
67 Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
68 {
69   //-----------------------------------------------------------------
70   // This function propagates a track to a reference plane x=xk.
71   //-----------------------------------------------------------------
72   if (TMath::Abs(fP3*xk - fP2) >= 0.99999) {
73     if (fN>4) cerr<<fN<<" AliTPCtrack warning: Propagation failed !\n";
74     return 0;
75   }
76
77   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
78   Double_t c1=fP3*x1 - fP2, r1=sqrt(1.- c1*c1);
79   Double_t c2=fP3*x2 - fP2, r2=sqrt(1.- c2*c2);
80   
81   fP0 += dx*(c1+c2)/(r1+r2);
82   fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP4;
83
84   //f = F - 1
85   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
86   Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
87   Double_t f03= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
88   Double_t cr=c1*r2+c2*r1;
89   Double_t f12=-dx*fP4*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
90   Double_t f13=dx*fP4*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
91   Double_t f14= dx*cc/cr; 
92
93   //b = C*ft
94   Double_t b00=f02*fC20 + f03*fC30, b01=f12*fC20 + f13*fC30 + f14*fC40;
95   Double_t b10=f02*fC21 + f03*fC31, b11=f12*fC21 + f13*fC31 + f14*fC41;
96   Double_t b20=f02*fC22 + f03*fC32, b21=f12*fC22 + f13*fC32 + f14*fC42;
97   Double_t b30=f02*fC32 + f03*fC33, b31=f12*fC32 + f13*fC33 + f14*fC43;
98   Double_t b40=f02*fC42 + f03*fC43, b41=f12*fC42 + f13*fC43 + f14*fC44;
99   
100   //a = f*b = f*C*ft
101   Double_t a00=f02*b20+f03*b30,a01=f02*b21+f03*b31,a11=f12*b21+f13*b31+f14*b41;
102
103   //F*C*Ft = C + (a + b + bt)
104   fC00 += a00 + 2*b00;
105   fC10 += a01 + b01 + b10; 
106   fC20 += b20;
107   fC30 += b30;
108   fC40 += b40;
109   fC11 += a11 + 2*b11;
110   fC21 += b21; 
111   fC31 += b31; 
112   fC41 += b41; 
113
114   fX=x2;
115
116   //Multiple scattering******************
117   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fP0)*(y1-fP0)+(z1-fP1)*(z1-fP1));
118   Double_t p2=GetP()*GetP();
119   Double_t beta2=p2/(p2 + pm*pm);
120   Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho/2.;
121   //Double_t theta2=1.0259e-6*10*10/20/(beta2*p2)*d*rho;
122
123   Double_t ey=fP3*fX - fP2, ez=fP4;
124   Double_t xz=fP3*ez, zz1=ez*ez+1, xy=fP2+ey;
125
126   fC33 += xz*xz*theta2;
127   fC32 += xz*ez*xy*theta2;
128   fC43 += xz*zz1*theta2;
129   fC22 += (2*ey*ez*ez*fP2+1-ey*ey+ez*ez+fP2*fP2*ez*ez)*theta2;
130   fC42 += ez*zz1*xy*theta2;
131   fC44 += zz1*zz1*theta2;
132
133   //Energy losses************************
134   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
135   if (x1 < x2) dE=-dE;
136   cc=fP3;
137   fP3*=(1.- sqrt(p2+pm*pm)/p2*dE);
138   fP2+=fX*(fP3-cc);
139
140   return 1;
141 }
142
143 //_____________________________________________________________________________
144 Int_t AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm) 
145 {
146   //-----------------------------------------------------------------
147   // This function propagates tracks to the "vertex".
148   //-----------------------------------------------------------------
149   Double_t c=fP3*fX - fP2;
150   Double_t tgf=-fP2/(fP3*fP0 + sqrt(1-c*c));
151   Double_t snf=tgf/sqrt(1.+ tgf*tgf);
152   Double_t xv=(fP2+snf)/fP3;
153   return PropagateTo(xv,x0,rho,pm);
154 }
155
156 //_____________________________________________________________________________
157 void AliTPCtrack::Update(const AliCluster *c, Double_t chisq, UInt_t index)
158 {
159   //-----------------------------------------------------------------
160   // This function associates a cluster with this track.
161   //-----------------------------------------------------------------
162   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
163   r00+=fC00; r01+=fC10; r11+=fC11;
164   Double_t det=r00*r11 - r01*r01;
165   Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
166
167   Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
168   Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
169   Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
170   Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
171   Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
172
173   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
174   Double_t cur=fP3 + k30*dy + k31*dz, eta=fP2 + k20*dy + k21*dz;
175   if (TMath::Abs(cur*fX-eta) >= 0.99999) {
176     if (fN>4) cerr<<fN<<" AliTPCtrack warning: Filtering failed !\n";
177     return;
178   }
179
180   fP0 += k00*dy + k01*dz;
181   fP1 += k10*dy + k11*dz;
182   fP2  = eta;
183   fP3  = cur;
184   fP4 += k40*dy + k41*dz;
185
186   Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
187   Double_t c12=fC21, c13=fC31, c14=fC41;
188
189   fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
190   fC20-=k00*c02+k01*c12;   fC30-=k00*c03+k01*c13;
191   fC40-=k00*c04+k01*c14; 
192
193   fC11-=k10*c01+k11*fC11;
194   fC21-=k10*c02+k11*c12;   fC31-=k10*c03+k11*c13;
195   fC41-=k10*c04+k11*c14; 
196
197   fC22-=k20*c02+k21*c12;   fC32-=k20*c03+k21*c13;
198   fC42-=k20*c04+k21*c14; 
199
200   fC33-=k30*c03+k31*c13;
201   fC43-=k30*c04+k31*c14; 
202
203   fC44-=k40*c04+k41*c14; 
204
205   fIndex[fN++]=index;
206   fChi2 += chisq;
207 }
208
209 //_____________________________________________________________________________
210 Int_t AliTPCtrack::Rotate(Double_t alpha)
211 {
212   //-----------------------------------------------------------------
213   // This function rotates this track.
214   //-----------------------------------------------------------------
215   fAlpha += alpha;
216   
217   Double_t x1=fX, y1=fP0;
218   Double_t ca=cos(alpha), sa=sin(alpha);
219   Double_t r1=fP3*fX - fP2;
220   
221   fX = x1*ca + y1*sa;
222   fP0=-x1*sa + y1*ca;
223   fP2=fP2*ca + (fP3*y1 + sqrt(1.- r1*r1))*sa;
224   
225   Double_t r2=fP3*fX - fP2;
226   if (TMath::Abs(r2) >= 0.99999) {
227     if (fN>4) cerr<<fN<<" AliTPCtrack warning: Rotation failed !\n";
228     return 0;
229   }
230   
231   Double_t y0=fP0 + sqrt(1.- r2*r2)/fP3;
232   if ((fP0-y0)*fP3 >= 0.) {
233     if (fN>4) cerr<<fN<<" AliTPCtrack warning: Rotation failed !!!\n";
234     return 0;
235   }
236
237   //f = F - 1
238   Double_t f00=ca-1,    f23=(y1 - r1*x1/sqrt(1.- r1*r1))*sa, 
239            f20=fP3*sa,  f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
240
241   //b = C*ft
242   Double_t b00=fC00*f00, b02=fC00*f20+fC30*f23+fC20*f22;
243   Double_t b10=fC10*f00, b12=fC10*f20+fC31*f23+fC21*f22;
244   Double_t b20=fC20*f00, b22=fC20*f20+fC32*f23+fC22*f22;
245   Double_t b30=fC30*f00, b32=fC30*f20+fC33*f23+fC32*f22;
246   Double_t b40=fC40*f00, b42=fC40*f20+fC43*f23+fC42*f22;
247
248   //a = f*b = f*C*ft
249   Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f23*b32+f22*b22;
250
251   // *** Double_t dy2=fCyy;
252
253   //F*C*Ft = C + (a + b + bt)
254   fC00 += a00 + 2*b00;
255   fC10 += b10;
256   fC20 += a02+b20+b02;
257   fC30 += b30;
258   fC40 += b40;
259   fC21 += b12;
260   fC32 += b32;
261   fC22 += a22 + 2*b22;
262   fC42 += b42; 
263
264   // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
265   // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
266
267   return 1;
268 }
269
270 //_____________________________________________________________________________
271 void AliTPCtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const 
272 {
273   //-----------------------------------------------------------------
274   // This function returns reconstructed track momentum in the global system.
275   //-----------------------------------------------------------------
276   Double_t pt=TMath::Abs(GetPt()); // GeV/c
277   Double_t r=fP3*fX-fP2;
278   Double_t y0=fP0 + sqrt(1.- r*r)/fP3;
279   px=-pt*(fP0-y0)*fP3;    //cos(phi);
280   py=-pt*(fP2-fX *fP3);   //sin(phi);
281   pz=pt*fP4;
282   Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
283   py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
284   px=tmp;  
285 }
286
287 //_____________________________________________________________________________
288 void AliTPCtrack::CookLabel(AliTPCClustersArray *ca) {
289   //-----------------------------------------------------------------
290   // This function cooks the track label. If label<0, this track is fake.
291   //-----------------------------------------------------------------
292   Int_t *lb=new Int_t[fN];
293   Int_t *mx=new Int_t[fN];
294   AliTPCcluster **clusters=new AliTPCcluster*[fN];
295
296   Int_t i;
297   Int_t sec,row,ncl;
298   for (i=0; i<fN; i++) {
299      lb[i]=mx[i]=0;
300      GetCluster(i,sec,row,ncl);
301      AliTPCClustersRow *clrow=ca->GetRow(sec,row);
302      clusters[i]=(AliTPCcluster*)(*clrow)[ncl];      
303   }
304   
305   Int_t lab=123456789;
306   for (i=0; i<fN; i++) {
307     AliTPCcluster *c=clusters[i];
308     lab=TMath::Abs(c->GetLabel(0));
309     Int_t j;
310     for (j=0; j<fN; j++)
311       if (lb[j]==lab || mx[j]==0) break;
312     lb[j]=lab;
313     (mx[j])++;
314   }
315   
316   Int_t max=0;
317   for (i=0; i<fN; i++) 
318     if (mx[i]>max) {max=mx[i]; lab=lb[i];}
319     
320   for (i=0; i<fN; i++) {
321     AliTPCcluster *c=clusters[i];
322     if (TMath::Abs(c->GetLabel(1)) == lab ||
323         TMath::Abs(c->GetLabel(2)) == lab ) max++;
324   }
325   
326   SetLabel(-lab);
327   if (1.-Float_t(max)/fN <= 0.10) {
328     //Int_t tail=Int_t(0.08*fN);
329      Int_t tail=14;
330      max=0;
331      for (i=1; i<=tail; i++) {
332        AliTPCcluster *c=clusters[fN-i];
333        if (lab == TMath::Abs(c->GetLabel(0)) ||
334            lab == TMath::Abs(c->GetLabel(1)) ||
335            lab == TMath::Abs(c->GetLabel(2))) max++;
336      }
337      if (max >= Int_t(0.5*tail)) SetLabel(lab);
338   }
339
340   delete[] lb;
341   delete[] mx;
342   delete[] clusters;
343 }