]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCtrack.cxx
Load/UnloadClusters added to the base class and the derived classes changed correspon...
[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.18  2003/02/19 08:57:04  hristov
19 Control^M removed
20
21 Revision 1.17  2003/02/19 08:49:46  hristov
22 Track time measurement (S.Radomski)
23
24 Revision 1.16  2003/02/06 11:11:36  kowal2
25 Added a few get methods by Jiri Chudoba
26
27 Revision 1.15  2002/11/25 09:33:30  hristov
28 Tracking of secondaries (M.Ivanov)
29
30 Revision 1.14  2002/10/23 13:45:00  hristov
31 Fatal if no magnetic field set for the reconstruction (Y.Belikov)
32
33 Revision 1.13  2002/10/23 07:17:34  alibrary
34 Introducing Riostream.h
35
36 Revision 1.12  2002/10/14 14:57:43  hristov
37 Merging the VirtualMC branch to the main development branch (HEAD)
38
39 Revision 1.9.6.1  2002/10/11 08:34:48  hristov
40 Updating VirtualMC to v3-09-02
41
42 Revision 1.11  2002/07/19 07:34:42  kowal2
43 Logs added
44
45 */
46
47
48 //-----------------------------------------------------------------
49 //           Implementation of the TPC track class
50 //        This class is used by the AliTPCtracker class
51 //      Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
52 //-----------------------------------------------------------------
53
54 #include <Riostream.h>
55
56 #include "AliTPCtrack.h"
57 #include "AliCluster.h"
58
59 ClassImp(AliTPCtrack)
60
61 //_________________________________________________________________________
62 AliTPCtrack::AliTPCtrack(): AliKalmanTrack() 
63 {
64   fX = fP0 = fP1 = fP2 = fP3 = fP3 = fP4 = 0.0;
65   fAlpha = fdEdx = 0.0;
66 }
67
68 //_________________________________________________________________________
69 AliTPCtrack::AliTPCtrack(UInt_t index, const Double_t xx[5],
70 const Double_t cc[15], Double_t xref, Double_t alpha) : AliKalmanTrack() {
71   //-----------------------------------------------------------------
72   // This is the main track constructor.
73   //-----------------------------------------------------------------
74   fX=xref;
75   fAlpha=alpha;
76   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
77   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
78   fdEdx=0.;
79
80   fP0=xx[0]; fP1=xx[1]; fP2=xx[2]; fP3=xx[3]; fP4=xx[4];
81
82   fC00=cc[0];
83   fC10=cc[1];  fC11=cc[2];
84   fC20=cc[3];  fC21=cc[4];  fC22=cc[5];
85   fC30=cc[6];  fC31=cc[7];  fC32=cc[8];  fC33=cc[9];
86   fC40=cc[10]; fC41=cc[11]; fC42=cc[12]; fC43=cc[13]; fC44=cc[14];
87
88   fIndex[0]=index;
89   SetNumberOfClusters(1);
90
91 }
92
93 //_____________________________________________________________________________
94 AliTPCtrack::AliTPCtrack(const AliKalmanTrack& t,Double_t alpha) :
95 AliKalmanTrack(t) {
96   //-----------------------------------------------------------------
97   // Conversion AliKalmanTrack -> AliTPCtrack.
98   //-----------------------------------------------------------------
99   SetChi2(0.);
100   SetNumberOfClusters(0);
101
102   fdEdx  = 0.;
103   fAlpha = alpha;
104   if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
105   else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
106
107   //Conversion of the track parameters
108   Double_t x,p[5]; t.GetExternalParameters(x,p);
109   fX=x;    x=GetConvConst();
110   fP0=p[0]; 
111   fP1=p[1]; 
112   fP3=p[3];
113   fP4=p[4]/x; 
114   fP2=fP4*fX - p[2];
115
116   //Conversion of the covariance matrix
117   Double_t c[15]; t.GetExternalCovariance(c);
118   c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
119
120   Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
121   Double_t c32=fX*c[13] - c[8];
122   Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
123   
124   fC00=c[0 ];
125   fC10=c[1 ];   fC11=c[2 ];
126   fC20=c20;     fC21=c21;     fC22=c22;
127   fC30=c[6 ];   fC31=c[7 ];   fC32=c32;   fC33=c[9 ];
128   fC40=c[10];   fC41=c[11];   fC42=c42;   fC43=c[13]; fC44=c[14];
129
130 }
131
132 //_____________________________________________________________________________
133 AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) : AliKalmanTrack(t) {
134   //-----------------------------------------------------------------
135   // This is a track copy constructor.
136   //-----------------------------------------------------------------
137   fX=t.fX;
138   fAlpha=t.fAlpha;
139   fdEdx=t.fdEdx;
140
141   fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;
142
143   fC00=t.fC00;
144   fC10=t.fC10;  fC11=t.fC11;
145   fC20=t.fC20;  fC21=t.fC21;  fC22=t.fC22;
146   fC30=t.fC30;  fC31=t.fC31;  fC32=t.fC32;  fC33=t.fC33;
147   fC40=t.fC40;  fC41=t.fC41;  fC42=t.fC42;  fC43=t.fC43;  fC44=t.fC44;
148
149   Int_t n=GetNumberOfClusters();
150   for (Int_t i=0; i<n; i++) fIndex[i]=t.fIndex[i];
151 }
152
153 //_____________________________________________________________________________
154 Int_t AliTPCtrack::Compare(const TObject *o) const {
155   //-----------------------------------------------------------------
156   // This function compares tracks according to the their curvature
157   //-----------------------------------------------------------------
158   AliTPCtrack *t=(AliTPCtrack*)o;
159   //Double_t co=TMath::Abs(t->Get1Pt());
160   //Double_t c =TMath::Abs(Get1Pt());
161   Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
162   Double_t c =GetSigmaY2()*GetSigmaZ2();
163   if (c>co) return 1;
164   else if (c<co) return -1;
165   return 0;
166 }
167
168 //_____________________________________________________________________________
169 void AliTPCtrack::GetExternalCovariance(Double_t cc[15]) const {
170   //-------------------------------------------------------------------------
171   // This function returns an external representation of the covriance matrix.
172   //   (See comments in AliTPCtrack.h about external track representation)
173   //-------------------------------------------------------------------------
174   Double_t a=GetConvConst();
175
176   Double_t c22=fX*fX*fC44-2*fX*fC42+fC22;
177   Double_t c32=fX*fC43-fC32;
178   Double_t c20=fX*fC40-fC20, c21=fX*fC41-fC21, c42=fX*fC44-fC42;
179   
180   cc[0 ]=fC00;
181   cc[1 ]=fC10;   cc[2 ]=fC11;
182   cc[3 ]=c20;    cc[4 ]=c21;    cc[5 ]=c22;
183   cc[6 ]=fC30;   cc[7 ]=fC31;   cc[8 ]=c32;   cc[9 ]=fC33; 
184   cc[10]=fC40*a; cc[11]=fC41*a; cc[12]=c42*a; cc[13]=fC43*a; cc[14]=fC44*a*a;
185
186 }
187
188 //_____________________________________________________________________________
189 Double_t AliTPCtrack::GetPredictedChi2(const AliCluster *c) const 
190 {
191   //-----------------------------------------------------------------
192   // This function calculates a predicted chi2 increment.
193   //-----------------------------------------------------------------
194   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
195   r00+=fC00; r01+=fC10; r11+=fC11;
196
197   Double_t det=r00*r11 - r01*r01;
198   if (TMath::Abs(det) < 1.e-10) {
199     Int_t n=GetNumberOfClusters();
200     if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
201     return 1e10;
202   }
203   Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
204   
205   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
206   
207   return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
208 }
209
210 //_____________________________________________________________________________
211 Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho) {
212   //-----------------------------------------------------------------
213   // This function propagates a track to a reference plane x=xk.
214   //-----------------------------------------------------------------
215   if (TMath::Abs(fP4*xk - fP2) >= 0.9) {
216     //    Int_t n=GetNumberOfClusters();
217     //if (n>4) cerr<<n<<" AliTPCtrack warning: Propagation failed !\n";
218     return 0;
219   }
220   
221   // old position for time [SR, GSI 17.02.2003]
222   Double_t oldX = fX;
223   Double_t oldY = fP0;
224   Double_t oldZ = fP1;
225   //
226
227   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
228   Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
229   Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
230   
231   fP0 += dx*(c1+c2)/(r1+r2);
232   fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
233
234   //f = F - 1
235   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
236   Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
237   Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
238   Double_t cr=c1*r2+c2*r1;
239   Double_t f12=-dx*fP3*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
240   Double_t f13= dx*cc/cr; 
241   Double_t f14=dx*fP3*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
242
243   //b = C*ft
244   Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
245   Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
246   Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
247   Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
248   Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
249   
250   //a = f*b = f*C*ft
251   Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
252
253   //F*C*Ft = C + (a + b + bt)
254   fC00 += a00 + 2*b00;
255   fC10 += a01 + b01 + b10; 
256   fC20 += b20;
257   fC30 += b30;
258   fC40 += b40;
259   fC11 += a11 + 2*b11;
260   fC21 += b21; 
261   fC31 += b31; 
262   fC41 += b41; 
263
264   fX=x2;
265
266   //Multiple scattering******************
267   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fP0)*(y1-fP0)+(z1-fP1)*(z1-fP1));
268   Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
269   Double_t beta2=p2/(p2 + GetMass()*GetMass());
270   //Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
271   Double_t theta2=1.0259e-6*10*10/20/(beta2*p2)*d*rho;
272
273   Double_t ey=fP4*fX - fP2, ez=fP3;
274   Double_t xz=fP4*ez, zz1=ez*ez+1, xy=fP2+ey;
275
276   fC22 += (2*ey*ez*ez*fP2+1-ey*ey+ez*ez+fP2*fP2*ez*ez)*theta2;
277   fC32 += ez*zz1*xy*theta2;
278   fC33 += zz1*zz1*theta2;
279   fC42 += xz*ez*xy*theta2;
280   fC43 += xz*zz1*theta2;
281   fC44 += xz*xz*theta2;
282
283   //Energy losses************************
284   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
285   if (x1 < x2) dE=-dE;
286   cc=fP4;
287   fP4*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
288   fP2+=fX*(fP4-cc);
289
290   // Integrated Time [SR, GSI, 17.02.2003]
291   if (IsStartedTimeIntegral()) {
292     Double_t l2 = (fX-oldX)*(fX-oldX)+(fP0-oldY)*(fP0-oldY)+(fP1-oldZ)*(fP1-oldZ);
293     AddTimeStep(TMath::Sqrt(l2));
294   }
295   //
296
297   return 1;
298 }
299
300 //_____________________________________________________________________________
301 Int_t AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho) 
302 {
303   //-----------------------------------------------------------------
304   // This function propagates tracks to the "vertex".
305   //-----------------------------------------------------------------
306   Double_t c=fP4*fX - fP2;
307   Double_t tgf=-fP2/(fP4*fP0 + sqrt(1-c*c));
308   Double_t snf=tgf/sqrt(1.+ tgf*tgf);
309   Double_t xv=(fP2+snf)/fP4;
310   return PropagateTo(xv,x0,rho);
311 }
312
313 //_____________________________________________________________________________
314 Int_t AliTPCtrack::Update(const AliCluster *c, Double_t chisq, UInt_t index) {
315   //-----------------------------------------------------------------
316   // This function associates a cluster with this track.
317   //-----------------------------------------------------------------
318   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
319   r00+=fC00; r01+=fC10; r11+=fC11;
320   Double_t det=r00*r11 - r01*r01;
321   Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
322
323   Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
324   Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
325   Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
326   Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
327   Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
328
329   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
330   Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
331   if (TMath::Abs(cur*fX-eta) >= 0.9) {
332     //    Int_t n=GetNumberOfClusters();
333     //if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
334     return 0;
335   }
336
337   fP0 += k00*dy + k01*dz;
338   fP1 += k10*dy + k11*dz;
339   fP2  = eta;
340   fP3 += k30*dy + k31*dz;
341   fP4  = cur;
342
343   Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
344   Double_t c12=fC21, c13=fC31, c14=fC41;
345
346   fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
347   fC20-=k00*c02+k01*c12;   fC30-=k00*c03+k01*c13;
348   fC40-=k00*c04+k01*c14; 
349
350   fC11-=k10*c01+k11*fC11;
351   fC21-=k10*c02+k11*c12;   fC31-=k10*c03+k11*c13;
352   fC41-=k10*c04+k11*c14; 
353
354   fC22-=k20*c02+k21*c12;   fC32-=k20*c03+k21*c13;
355   fC42-=k20*c04+k21*c14; 
356
357   fC33-=k30*c03+k31*c13;
358   fC43-=k40*c03+k41*c13; 
359
360   fC44-=k40*c04+k41*c14; 
361
362   Int_t n=GetNumberOfClusters();
363   fIndex[n]=index;
364   SetNumberOfClusters(n+1);
365   SetChi2(GetChi2()+chisq);
366
367   return 1;
368 }
369
370 //_____________________________________________________________________________
371 Int_t AliTPCtrack::Rotate(Double_t alpha)
372 {
373   //-----------------------------------------------------------------
374   // This function rotates this track.
375   //-----------------------------------------------------------------
376   fAlpha += alpha;
377   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
378   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
379   
380   Double_t x1=fX, y1=fP0;
381   Double_t ca=cos(alpha), sa=sin(alpha);
382   Double_t r1=fP4*fX - fP2;
383   
384   fX = x1*ca + y1*sa;
385   fP0=-x1*sa + y1*ca;
386   fP2=fP2*ca + (fP4*y1 + sqrt(1.- r1*r1))*sa;
387   
388   Double_t r2=fP4*fX - fP2;
389   if (TMath::Abs(r2) >= 0.99999) {
390     Int_t n=GetNumberOfClusters();
391     if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !\n";
392     return 0;
393   }
394   
395   Double_t y0=fP0 + sqrt(1.- r2*r2)/fP4;
396   if ((fP0-y0)*fP4 >= 0.) {
397     Int_t n=GetNumberOfClusters();
398     if (n>4) cerr<<n<<" AliTPCtrack warning: Rotation failed !!!\n";
399     return 0;
400   }
401
402   //f = F - 1
403   Double_t f00=ca-1,    f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa, 
404            f20=fP4*sa,  f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
405
406   //b = C*ft
407   Double_t b00=fC00*f00, b02=fC00*f20+fC40*f24+fC20*f22;
408   Double_t b10=fC10*f00, b12=fC10*f20+fC41*f24+fC21*f22;
409   Double_t b20=fC20*f00, b22=fC20*f20+fC42*f24+fC22*f22;
410   Double_t b30=fC30*f00, b32=fC30*f20+fC43*f24+fC32*f22;
411   Double_t b40=fC40*f00, b42=fC40*f20+fC44*f24+fC42*f22;
412
413   //a = f*b = f*C*ft
414   Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
415
416   // *** Double_t dy2=fCyy;
417
418   //F*C*Ft = C + (a + b + bt)
419   fC00 += a00 + 2*b00;
420   fC10 += b10;
421   fC20 += a02+b20+b02;
422   fC30 += b30;
423   fC40 += b40;
424   fC21 += b12;
425   fC32 += b32;
426   fC22 += a22 + 2*b22;
427   fC42 += b42; 
428
429   // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
430   // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
431
432   return 1;
433 }
434
435 void AliTPCtrack::ResetCovariance() {
436   //------------------------------------------------------------------
437   //This function makes a track forget its history :)  
438   //------------------------------------------------------------------
439
440   fC00*=10.;
441   fC10=0.;  fC11*=10.;
442   fC20=0.;  fC21=0.;  fC22*=10.;
443   fC30=0.;  fC31=0.;  fC32=0.;  fC33*=10.;
444   fC40=0.;  fC41=0.;  fC42=0.;  fC43=0.;  fC44*=10.;
445
446 }
447
448 ////////////////////////////////////////////////////////////////////////
449 Double_t AliTPCtrack::Phi() const {
450 //
451 //
452 //
453   Double_t phi =  TMath::ASin(GetSnp()) + fAlpha;
454   if (phi<0) phi+=2*TMath::Pi();
455   if (phi>=2*TMath::Pi()) phi-=2*TMath::Pi();
456   return phi;
457 }
458 ////////////////////////////////////////////////////////////////////////
459