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