]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtrack.cxx
Protection against division by 0 in Binaries().
[u/mrichter/AliRoot.git] / TRD / AliTRDtrack.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.17  2003/02/19 09:02:28  hristov
19 Track time measurement (S.Radomski)
20
21 Revision 1.16  2003/02/10 14:06:10  cblume
22 Add tracking without tilted pads as option
23
24 Revision 1.15  2003/01/27 16:34:49  cblume
25 Update of tracking by Sergei and Chuncheng
26
27 Revision 1.14  2002/11/07 15:52:09  cblume
28 Update of tracking code for tilted pads
29
30 Revision 1.13  2002/10/22 15:53:08  alibrary
31 Introducing Riostream.h
32
33 Revision 1.12  2002/10/14 14:57:44  hristov
34 Merging the VirtualMC branch to the main development branch (HEAD)
35
36 Revision 1.8.10.2  2002/07/24 10:09:31  alibrary
37 Updating VirtualMC
38
39 RRevision 1.11  2002/06/13 12:09:58  hristov
40 Minor corrections
41
42 Revision 1.10  2002/06/12 09:54:35  cblume
43 Update of tracking code provided by Sergei
44
45 Revision 1.8  2001/05/30 12:17:47  hristov
46 Loop variables declared once
47
48 Revision 1.7  2001/05/28 17:07:58  hristov
49 Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
50
51 Revision 1.4  2000/12/08 16:07:02  cblume
52 Update of the tracking by Sergei
53
54 Revision 1.3  2000/10/15 23:40:01  cblume
55 Remove AliTRDconst
56
57 Revision 1.2  2000/10/06 16:49:46  cblume
58 Made Getters const
59
60 Revision 1.1.2.1  2000/09/22 14:47:52  cblume
61 Add the tracking code
62
63 */                                                        
64
65 #include <Riostream.h>
66 #include <TObject.h>   
67
68 #include "AliTRDgeometry.h" 
69 #include "AliTRDcluster.h" 
70 #include "AliTRDtrack.h"
71 #include "../TPC/AliTPCtrack.h" 
72
73
74 ClassImp(AliTRDtrack)
75
76
77 //_____________________________________________________________________________
78
79 AliTRDtrack::AliTRDtrack(const AliTRDcluster *c, UInt_t index, 
80                          const Double_t xx[5], const Double_t cc[15], 
81                          Double_t xref, Double_t alpha) : AliKalmanTrack() {
82   //-----------------------------------------------------------------
83   // This is the main track constructor.
84   //-----------------------------------------------------------------
85
86   fSeedLab = -1;
87
88   fAlpha=alpha;
89   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
90   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();   
91
92   fX=xref;
93
94   fY=xx[0]; fZ=xx[1]; fE=xx[2]; fT=xx[3]; fC=xx[4];
95
96   fCyy=cc[0];
97   fCzy=cc[1];  fCzz=cc[2];
98   fCey=cc[3];  fCez=cc[4];  fCee=cc[5];
99   fCty=cc[6];  fCtz=cc[7];  fCte=cc[8];  fCtt=cc[9];
100   fCcy=cc[10]; fCcz=cc[11]; fCce=cc[12]; fCct=cc[13]; fCcc=cc[14];  
101   
102   fIndex[0]=index;
103   SetNumberOfClusters(1);
104
105   fdEdx=0.;
106
107   fLhElectron = 0.0;
108   fNWrong = 0;
109   fNRotate = 0;
110
111   Double_t q = TMath::Abs(c->GetQ());
112   Double_t s = fX*fC - fE, t=fT;
113   if(s*s < 1) q *= TMath::Sqrt((1-s*s)/(1+t*t));
114
115   fdQdl[0] = q;
116   
117   // initialisation [SR, GSI 18.02.2003] (i startd for 1)
118   for(Int_t i=1; i<kMAX_CLUSTERS_PER_TRACK; i++) {
119     fdQdl[i] = 0;
120     fIndex[i] = 0;
121   }
122 }                              
123            
124 //_____________________________________________________________________________
125 AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) : AliKalmanTrack(t) {
126   //
127   // Copy constructor.
128   //
129   
130   SetLabel(t.GetLabel());
131   fSeedLab=t.GetSeedLabel();
132
133   SetChi2(t.GetChi2());
134   fdEdx=t.fdEdx;
135
136   fLhElectron = 0.0;
137   fNWrong = t.fNWrong;
138   fNRotate = t.fNRotate;
139
140   fAlpha=t.fAlpha;
141   fX=t.fX;
142
143   fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
144
145   fCyy=t.fCyy;
146   fCzy=t.fCzy;  fCzz=t.fCzz;
147   fCey=t.fCey;  fCez=t.fCez;  fCee=t.fCee;
148   fCty=t.fCty;  fCtz=t.fCtz;  fCte=t.fCte;  fCtt=t.fCtt;
149   fCcy=t.fCcy;  fCcz=t.fCcz;  fCce=t.fCce;  fCct=t.fCct;  fCcc=t.fCcc;  
150
151   Int_t n=t.GetNumberOfClusters(); 
152   SetNumberOfClusters(n);
153   for (Int_t i=0; i<n; i++) {
154     fIndex[i]=t.fIndex[i];
155     fdQdl[i]=t.fdQdl[i];
156   }
157
158   // initialisation (i starts from n) [SR, GSI, 18.02.2003]
159   for(Int_t i=n; i<kMAX_CLUSTERS_PER_TRACK; i++) {
160     fdQdl[i] = 0;
161     fIndex[i] = 0;
162   }
163 }                                
164
165 //_____________________________________________________________________________
166 AliTRDtrack::AliTRDtrack(const AliKalmanTrack& t, Double_t alpha) 
167            :AliKalmanTrack(t) {
168   //
169   // Constructor from AliTPCtrack or AliITStrack .
170   //
171
172   SetLabel(t.GetLabel());
173   SetChi2(0.);
174   SetMass(t.GetMass());
175   SetNumberOfClusters(0);
176
177   fdEdx=0;
178
179   fLhElectron = 0.0;
180   fNWrong = 0;
181   fNRotate = 0;
182
183   fAlpha = alpha;
184   if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
185   else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
186
187   Double_t x, p[5]; t.GetExternalParameters(x,p);
188
189   fX=x;
190
191   x = GetConvConst();  
192
193   fY=p[0];
194   fZ=p[1];
195   fT=p[3];
196   fC=p[4]/x;
197   fE=fC*fX - p[2];   
198
199   //Conversion of the covariance matrix
200   Double_t c[15]; t.GetExternalCovariance(c);
201
202   c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
203
204   Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
205   Double_t c32=fX*c[13] - c[8];
206   Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
207
208   fCyy=c[0 ];
209   fCzy=c[1 ];   fCzz=c[2 ];
210   fCey=c20;     fCez=c21;     fCee=c22;
211   fCty=c[6 ];   fCtz=c[7 ];   fCte=c32;   fCtt=c[9 ];
212   fCcy=c[10];   fCcz=c[11];   fCce=c42;   fCct=c[13]; fCcc=c[14];  
213
214   // Initialization [SR, GSI, 18.02.2003]
215   for(Int_t i=0; i<kMAX_CLUSTERS_PER_TRACK; i++) {
216     fdQdl[i] = 0;
217     fIndex[i] = 0;
218   }
219 }              
220 //_____________________________________________________________________________
221
222 void  AliTRDtrack::GetBarrelTrack(AliBarrelTrack *track) {
223   //
224   //
225   //
226   
227   if (!track) return;
228   Double_t xr, vec[5], cov[15];
229
230   track->SetLabel(GetLabel());
231   track->SetX(fX, fAlpha);
232   track->SetNClusters(GetNumberOfClusters(), GetChi2());
233   track->SetNWrongClusters(fNWrong);
234   track->SetNRotate(fNRotate);
235   track->SetTime(fIntegratedTime, fIntegratedLength);
236
237   track->SetMass(fMass);
238   track->SetdEdX(fdEdx);
239
240   GetExternalParameters(xr, vec);
241   track->SetStateVector(vec);
242
243   GetExternalCovariance(cov);
244   track->SetCovarianceMatrix(cov);
245 }
246 //____________________________________________________________________________
247 void AliTRDtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
248   //
249   // This function returns external TRD track representation
250   //
251      xr=fX;
252      x[0]=GetY();
253      x[1]=GetZ();
254      x[2]=GetSnp();
255      x[3]=GetTgl();
256      x[4]=Get1Pt();
257 }           
258
259 //_____________________________________________________________________________
260 void AliTRDtrack::GetExternalCovariance(Double_t cc[15]) const {
261   //
262   // This function returns external representation of the covriance matrix.
263   //
264   Double_t a=GetConvConst();
265
266   Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
267   Double_t c32=fX*fCct-fCte;
268   Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
269
270   cc[0 ]=fCyy;
271   cc[1 ]=fCzy;   cc[2 ]=fCzz;
272   cc[3 ]=c20;    cc[4 ]=c21;    cc[5 ]=c22;
273   cc[6 ]=fCty;   cc[7 ]=fCtz;   cc[8 ]=c32;   cc[9 ]=fCtt;
274   cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a; 
275   
276 }               
277                        
278
279 //_____________________________________________________________________________
280 void AliTRDtrack::GetCovariance(Double_t cc[15]) const {
281
282   cc[0]=fCyy;
283   cc[1]=fCzy;  cc[2]=fCzz;
284   cc[3]=fCey;  cc[4]=fCez;  cc[5]=fCee;
285   cc[6]=fCcy;  cc[7]=fCcz;  cc[8]=fCce;  cc[9]=fCcc;
286   cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
287   
288 }    
289
290 //_____________________________________________________________________________
291 Int_t AliTRDtrack::Compare(const TObject *o) const {
292
293 // Compares tracks according to their Y2 or curvature
294
295   AliTRDtrack *t=(AliTRDtrack*)o;
296   //  Double_t co=t->GetSigmaY2();
297   //  Double_t c =GetSigmaY2();
298
299   Double_t co=TMath::Abs(t->GetC());
300   Double_t c =TMath::Abs(GetC());  
301
302   if (c>co) return 1;
303   else if (c<co) return -1;
304   return 0;
305 }                
306
307 //_____________________________________________________________________________
308 void AliTRDtrack::CookdEdx(Double_t low, Double_t up) {
309   //-----------------------------------------------------------------
310   // Calculates dE/dX within the "low" and "up" cuts.
311   //-----------------------------------------------------------------
312
313   Int_t i;
314   Int_t nc=GetNumberOfClusters(); 
315
316   Float_t sorted[kMAX_CLUSTERS_PER_TRACK];
317   for (i=0; i < nc; i++) {
318     sorted[i]=fdQdl[i];
319   }
320
321   Int_t swap; 
322
323   do {
324     swap=0;
325     for (i=0; i<nc-1; i++) {
326       if (sorted[i]<=sorted[i+1]) continue;
327       Float_t tmp=sorted[i];
328       sorted[i]=sorted[i+1]; sorted[i+1]=tmp;
329       swap++;
330     }
331   } while (swap);
332
333   Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
334   Float_t dedx=0;
335   for (i=nl; i<=nu; i++) dedx += sorted[i];
336   dedx /= (nu-nl+1);
337
338   SetdEdx(dedx);
339 }                     
340
341
342 //_____________________________________________________________________________
343 Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
344 {
345   // Propagates a track of particle with mass=pm to a reference plane 
346   // defined by x=xk through media of density=rho and radiationLength=x0
347
348   if (xk == fX) return 1;
349
350   if (TMath::Abs(fC*xk - fE) >= 0.99999) {
351     Int_t n=GetNumberOfClusters();
352     if (n>4) cerr << n << " AliTRDtrack: Propagation failed, \tPt = " 
353                   << GetPt() << "\t" << GetLabel() << "\t" << GetMass() << endl;
354     return 0;
355   }
356
357   // track Length measurement [SR, GSI, 17.02.2003]
358   Double_t oldX = fX, oldY = fY, oldZ = fZ;  
359
360   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
361   Double_t c1=fC*x1 - fE;
362   if((c1*c1) > 1) return 0;
363   Double_t r1=sqrt(1.- c1*c1);
364   Double_t c2=fC*x2 - fE; 
365   if((c2*c2) > 1) return 0;
366   Double_t r2=sqrt(1.- c2*c2);
367
368   fY += dx*(c1+c2)/(r1+r2);
369   fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
370
371   //f = F - 1
372   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
373   Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
374   Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
375   Double_t cr=c1*r2+c2*r1;
376   Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
377   Double_t f13= dx*cc/cr;
378   Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
379
380   //b = C*ft
381   Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
382   Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
383   Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
384   Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
385   Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
386
387   //a = f*b = f*C*ft
388   Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
389
390   //F*C*Ft = C + (a + b + bt)
391   fCyy += a00 + 2*b00;
392   fCzy += a01 + b01 + b10;
393   fCey += b20;
394   fCty += b30;
395   fCcy += b40;
396   fCzz += a11 + 2*b11;
397   fCez += b21;
398   fCtz += b31;
399   fCcz += b41;
400
401   fX=x2;                                                     
402
403   //Multiple scattering  ******************
404   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
405   Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
406   Double_t beta2=p2/(p2 + GetMass()*GetMass());
407   Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
408
409   Double_t ey=fC*fX - fE, ez=fT;
410   Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
411
412   fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
413   fCte += ez*zz1*xy*theta2;
414   fCtt += zz1*zz1*theta2;
415   fCce += xz*ez*xy*theta2;
416   fCct += xz*zz1*theta2;
417   fCcc += xz*xz*theta2;
418
419   //Energy losses************************
420   if((5940*beta2/(1-beta2+1e-10) - beta2) < 0) return 0;
421
422   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
423   if (x1 < x2) dE=-dE;
424   cc=fC;
425   fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
426   fE+=fX*(fC-cc);    
427
428   // track time measurement [SR, GSI 17.02.2002]
429   if (IsStartedTimeIntegral()) {
430     Double_t l2 = (fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ);
431     AddTimeStep(TMath::Sqrt(l2));
432   }
433
434   return 1;            
435 }     
436
437
438 //_____________________________________________________________________________
439 Int_t AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index,                          Double_t h01)
440 {
441   // Assignes found cluster to the track and updates track information
442
443   Bool_t fNoTilt = kTRUE;
444   if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
445
446   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
447   r00+=fCyy; r01+=fCzy; r11+=fCzz;
448   Double_t det=r00*r11 - r01*r01;
449   Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
450
451   Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
452   Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
453   Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
454   Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
455   Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
456
457   Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
458   Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
459
460   Double_t c01=fCzy, c02=fCey, c03=fCty, c04=fCcy;
461   Double_t c12=fCez, c13=fCtz, c14=fCcz;
462
463   if(fNoTilt) {
464     if (TMath::Abs(cur*fX-eta) >= 0.99999) {
465       Int_t n=GetNumberOfClusters();
466       if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
467       return 0;
468     }
469     fY += k00*dy + k01*dz;
470     fZ += k10*dy + k11*dz;
471     fE  = eta;
472     //fT += k30*dy + k31*dz;
473     fC  = cur;
474   }
475   else {
476     Double_t xu_factor = 100.;  // empirical factor set by C.Xu
477                                 // in the first tilt version      
478     r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2()*xu_factor; 
479     r00+=(fCyy+2.0*h01*fCzy+h01*h01*fCzz);
480     r01+=(fCzy+h01*fCzz);  
481     det=r00*r11 - r01*r01;
482     tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
483
484     k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
485     k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
486     k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
487     k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
488     k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);  
489
490     dy=c->GetY() - fY; dz=c->GetZ() - fZ; 
491     dy=dy+h01*dz;
492
493     cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
494     if (TMath::Abs(cur*fX-eta) >= 0.99999) {
495       Int_t n=GetNumberOfClusters();
496       if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
497       return 0;
498     }                           
499     fY += k00*dy + k01*dz;
500     fZ += k10*dy + k11*dz;
501     fE  = eta;
502     //fT += k30*dy + k31*dz;
503     fC  = cur;
504     
505     k01+=h01*k00;
506     k11+=h01*k10;
507     k21+=h01*k20;
508     k31+=h01*k30;
509     k41+=h01*k40;  
510   }
511
512   fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
513   fCey-=k00*c02+k01*c12;   fCty-=k00*c03+k01*c13;
514   fCcy-=k00*c04+k01*c14;
515   
516   fCzz-=k10*c01+k11*fCzz;
517   fCez-=k10*c02+k11*c12;   fCtz-=k10*c03+k11*c13;
518   fCcz-=k10*c04+k11*c14;
519   
520   fCee-=k20*c02+k21*c12;   fCte-=k20*c03+k21*c13;
521   fCce-=k20*c04+k21*c14;
522   
523   fCtt-=k30*c03+k31*c13;
524   fCct-=k40*c03+k41*c13;
525   
526   fCcc-=k40*c04+k41*c14;                 
527
528   Int_t n=GetNumberOfClusters();
529   fIndex[n]=index;
530   SetNumberOfClusters(n+1);
531
532   SetChi2(GetChi2()+chisq);
533   //  cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
534
535   return 1;     
536 }                     
537
538
539 //_____________________________________________________________________________
540 Int_t AliTRDtrack::Rotate(Double_t alpha)
541 {
542   // Rotates track parameters in R*phi plane
543   
544   fNRotate++;
545
546   fAlpha += alpha;
547   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
548   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
549
550   Double_t x1=fX, y1=fY;
551   Double_t ca=cos(alpha), sa=sin(alpha);
552   Double_t r1=fC*fX - fE;
553
554   fX = x1*ca + y1*sa;
555   fY =-x1*sa + y1*ca;
556   if((r1*r1) > 1) return 0;
557   fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
558
559   Double_t r2=fC*fX - fE;
560   if (TMath::Abs(r2) >= 0.99999) {
561     Int_t n=GetNumberOfClusters();
562     if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
563     return 0;
564   }
565
566   if((r2*r2) > 1) return 0;
567   Double_t y0=fY + sqrt(1.- r2*r2)/fC;
568   if ((fY-y0)*fC >= 0.) {
569     Int_t n=GetNumberOfClusters();
570     if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !!!\n";
571     return 0;
572   }
573
574   //f = F - 1
575   Double_t f00=ca-1,    f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
576            f20=fC*sa,  f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
577
578   //b = C*ft
579   Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
580   Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
581   Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
582   Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
583   Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
584
585   //a = f*b = f*C*ft
586   Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
587
588   //F*C*Ft = C + (a + b + bt)
589   fCyy += a00 + 2*b00;
590   fCzy += b10;
591   fCey += a02+b20+b02;
592   fCty += b30;
593   fCcy += b40;
594   fCez += b12;
595   fCte += b32;
596   fCee += a22 + 2*b22;
597   fCce += b42;
598
599   return 1;                            
600 }                         
601
602
603 //_____________________________________________________________________________
604 Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c, Double_t h01) const
605 {
606   
607   Bool_t fNoTilt = kTRUE;
608   if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
609   Double_t chi2, dy, r00, r01, r11;
610
611   if(fNoTilt) {
612     dy=c->GetY() - fY;
613     r00=c->GetSigmaY2();    
614     chi2 = (dy*dy)/r00;    
615   }
616   else {
617     r00=c->GetSigmaY2(); r01=0.; r11=c->GetSigmaZ2();
618     r00+=fCyy; r01+=fCzy; r11+=fCzz;
619
620     Double_t det=r00*r11 - r01*r01;
621     if (TMath::Abs(det) < 1.e-10) {
622       Int_t n=GetNumberOfClusters(); 
623       if (n>4) cerr<<n<<" AliTRDtrack warning: Singular matrix !\n";
624       return 1e10;
625     }
626     Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
627     Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
628     dy=dy+h01*dz;
629
630     chi2 = (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det; 
631   }
632   return chi2;
633 }      
634
635
636 //_________________________________________________________________________
637 void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
638 {
639   // Returns reconstructed track momentum in the global system.
640
641   Double_t pt=TMath::Abs(GetPt()); // GeV/c
642   Double_t r=fC*fX-fE;
643
644   Double_t y0; 
645   if(r > 1) { py = pt; px = 0; }
646   else if(r < -1) { py = -pt; px = 0; }
647   else {
648     y0=fY + sqrt(1.- r*r)/fC;  
649     px=-pt*(fY-y0)*fC;    //cos(phi);
650     py=-pt*(fE-fX*fC);   //sin(phi);
651   }
652   pz=pt*fT;
653   Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
654   py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
655   px=tmp;            
656
657 }                                
658
659 //_________________________________________________________________________
660 void AliTRDtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
661 {
662   // Returns reconstructed track coordinates in the global system.
663
664   x = fX; y = fY; z = fZ; 
665   Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
666   y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
667   x=tmp;            
668
669 }                                
670
671 //_________________________________________________________________________
672 void AliTRDtrack::ResetCovariance() {
673   //
674   // Resets covariance matrix
675   //
676
677   fCyy*=10.;
678   fCzy=0.;  fCzz*=10.;
679   fCey=0.;  fCez=0.;  fCee*=10.;
680   fCty=0.;  fCtz=0.;  fCte=0.;  fCtt*=10.;
681   fCcy=0.;  fCcz=0.;  fCce=0.;  fCct=0.;  fCcc*=10.;  
682 }                                                         
683