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