]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtrack.cxx
Merging the VirtualMC branch to the main development branch (HEAD)
[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.10.2  2002/07/24 10:09:31  alibrary
19 Updating VirtualMC
20
21 Revision 1.11  2002/06/13 12:09:58  hristov
22 Minor corrections
23
24 Revision 1.10  2002/06/12 09:54:35  cblume
25 Update of tracking code provided by Sergei
26
27 Revision 1.8  2001/05/30 12:17:47  hristov
28 Loop variables declared once
29
30 Revision 1.7  2001/05/28 17:07:58  hristov
31 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)
32
33 Revision 1.4  2000/12/08 16:07:02  cblume
34 Update of the tracking by Sergei
35
36 Revision 1.3  2000/10/15 23:40:01  cblume
37 Remove AliTRDconst
38
39 Revision 1.2  2000/10/06 16:49:46  cblume
40 Made Getters const
41
42 Revision 1.1.2.1  2000/09/22 14:47:52  cblume
43 Add the tracking code
44
45 */                                                        
46
47 #include <iostream.h>
48 #include <TObject.h>   
49
50 #include "AliTRDgeometry.h" 
51 #include "AliTRDcluster.h" 
52 #include "AliTRDtrack.h"
53 #include "../TPC/AliTPCtrack.h" 
54
55 ClassImp(AliTRDtrack)
56
57
58 //_____________________________________________________________________________
59
60 AliTRDtrack::AliTRDtrack(const AliTRDcluster *c, UInt_t index, 
61                          const Double_t xx[5], const Double_t cc[15], 
62                          Double_t xref, Double_t alpha) : AliKalmanTrack() {
63   //-----------------------------------------------------------------
64   // This is the main track constructor.
65   //-----------------------------------------------------------------
66
67   fSeedLab = -1;
68
69   fAlpha=alpha;
70   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
71   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();   
72
73   fX=xref;
74
75   fY=xx[0]; fZ=xx[1]; fC=xx[2]; fE=xx[3]; fT=xx[4];
76
77   fCyy=cc[0];
78   fCzy=cc[1];  fCzz=cc[2];
79   fCcy=cc[3];  fCcz=cc[4];  fCcc=cc[5];
80   fCey=cc[6];  fCez=cc[7];  fCec=cc[8];  fCee=cc[9];
81   fCty=cc[10]; fCtz=cc[11]; fCtc=cc[12]; fCte=cc[13]; fCtt=cc[14];
82
83   fIndex[0]=index;
84   SetNumberOfClusters(1);
85
86   fdEdx=0.;
87
88   Double_t q = TMath::Abs(c->GetQ());
89   Double_t s = fX*fC - fE, t=fT;
90   if(s*s < 1) q *= TMath::Sqrt((1-s*s)/(1+t*t));
91
92   fdQdl[0] = q;
93 }                              
94            
95 //_____________________________________________________________________________
96 AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) : AliKalmanTrack(t) {
97   //
98   // Copy constructor.
99   //
100
101   SetLabel(t.GetLabel());
102   fSeedLab=t.GetSeedLabel();
103
104   SetChi2(t.GetChi2());
105   fdEdx=t.fdEdx;
106
107   fAlpha=t.fAlpha;
108   fX=t.fX;
109
110   fY=t.fY; fZ=t.fZ; fC=t.fC; fE=t.fE; fT=t.fT;
111
112   fCyy=t.fCyy;
113   fCzy=t.fCzy;  fCzz=t.fCzz;
114   fCcy=t.fCcy;  fCcz=t.fCcz;  fCcc=t.fCcc;
115   fCey=t.fCey;  fCez=t.fCez;  fCec=t.fCec;  fCee=t.fCee;
116   fCty=t.fCty;  fCtz=t.fCtz;  fCtc=t.fCtc;  fCte=t.fCte;  fCtt=t.fCtt;
117
118   Int_t n=t.GetNumberOfClusters(); 
119   SetNumberOfClusters(n);
120   for (Int_t i=0; i<n; i++) {
121     fIndex[i]=t.fIndex[i];
122     fdQdl[i]=t.fdQdl[i];
123   }
124 }                                
125
126 //_____________________________________________________________________________
127 AliTRDtrack::AliTRDtrack(const AliKalmanTrack& t, Double_t alpha) {
128   //
129   // Constructor from AliTPCtrack or AliITStrack .
130   //
131
132   SetLabel(t.GetLabel());
133   SetChi2(0.);
134   SetNumberOfClusters(0);
135
136   fdEdx=0;
137
138   fAlpha = alpha;
139   if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
140   else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
141
142   Double_t x, p[5]; t.GetExternalParameters(x,p);
143
144   fX=x;
145
146   x = GetConvConst();  
147
148   fY=p[0]; fZ=p[1]; fC=p[4]/x;
149   fE=fX*fC-p[2]; fT=p[3];
150
151   //Conversion of the covariance matrix
152   Double_t c[15]; t.GetExternalCovariance(c);
153
154   c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
155
156   Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
157   Double_t c32=fX*c[13] - c[8];
158   Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
159
160   fCyy=c[0 ];
161   fCzy=c[1 ];   fCzz=c[2 ];
162   fCcy=c[10];   fCcz=c[11];   fCcc=c[14];
163   fCey=c20;     fCez=c21;     fCec=c42;     fCee=c22;
164   fCty=c[6 ];   fCtz=c[7 ];   fCtc=c[13];   fCte=c32;   fCtt=c[9 ];
165
166 }              
167
168 //____________________________________________________________________________
169 void AliTRDtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
170   //
171   // This function returns external TRD track representation
172   //
173      xr=fX;
174      x[0]=GetY();
175      x[1]=GetZ();
176      x[2]=GetSnp();
177      x[3]=GetTgl();
178      x[4]=fC*GetConvConst();
179 }           
180
181 //_____________________________________________________________________________
182 void AliTRDtrack::GetExternalCovariance(Double_t cc[15]) const {
183   //
184   // This function returns external representation of the covriance matrix.
185   //
186   Double_t a=GetConvConst();
187
188   Double_t c22=fX*fX*fCcc-2*fX*fCec+fCee;
189   Double_t c32=fX*fCtc-fCte;
190   Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCec;
191
192   cc[0 ]=fCyy;
193   cc[1 ]=fCzy;   cc[2 ]=fCzz;
194   cc[3 ]=c20;    cc[4 ]=c21;    cc[5 ]=c22;
195   cc[6 ]=fCty;   cc[7 ]=fCtz;   cc[8 ]=c32;   cc[9 ]=fCtt;
196   cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCtc*a; cc[14]=fCcc*a*a;
197 }               
198                        
199
200 //_____________________________________________________________________________
201 void AliTRDtrack::GetCovariance(Double_t cc[15]) const {
202   cc[0]=fCyy;
203   cc[1]=fCzy;  cc[2]=fCzz;
204   cc[3]=fCcy;  cc[4]=fCcz;  cc[5]=fCcc;
205   cc[6]=fCey;  cc[7]=fCez;  cc[8]=fCec;  cc[9]=fCee;
206   cc[10]=fCty; cc[11]=fCtz; cc[12]=fCtc; cc[13]=fCte; cc[14]=fCtt;
207 }    
208
209 //_____________________________________________________________________________
210 Int_t AliTRDtrack::Compare(const TObject *o) const {
211
212 // Compares tracks according to their Y2 or curvature
213
214   AliTRDtrack *t=(AliTRDtrack*)o;
215   //  Double_t co=t->GetSigmaY2();
216   //  Double_t c =GetSigmaY2();
217
218   Double_t co=TMath::Abs(t->GetC());
219   Double_t c =TMath::Abs(GetC());  
220
221   if (c>co) return 1;
222   else if (c<co) return -1;
223   return 0;
224 }                
225
226 //_____________________________________________________________________________
227 void AliTRDtrack::CookdEdx(Double_t low, Double_t up) {
228   //-----------------------------------------------------------------
229   // Calculates dE/dX within the "low" and "up" cuts.
230   //-----------------------------------------------------------------
231
232   Int_t i;
233   Int_t nc=GetNumberOfClusters(); 
234
235   Float_t sorted[kMAX_CLUSTERS_PER_TRACK];
236   for (i=0; i < nc; i++) {
237     sorted[i]=fdQdl[i];
238   }
239
240   Int_t swap; 
241
242   do {
243     swap=0;
244     for (i=0; i<nc-1; i++) {
245       if (sorted[i]<=sorted[i+1]) continue;
246       Float_t tmp=sorted[i];
247       sorted[i]=sorted[i+1]; sorted[i+1]=tmp;
248       swap++;
249     }
250   } while (swap);
251
252   Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
253   Float_t dedx=0;
254   for (i=nl; i<=nu; i++) dedx += sorted[i];
255   dedx /= (nu-nl+1);
256
257   SetdEdx(dedx);
258 }                     
259
260
261
262 //_____________________________________________________________________________
263 Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
264 {
265   // Propagates a track of particle with mass=pm to a reference plane 
266   // defined by x=xk through media of density=rho and radiationLength=x0
267
268   
269   if (TMath::Abs(fC*xk - fE) >= 0.99999) {
270     Int_t n=GetNumberOfClusters(); 
271     if (n>4) cerr<<n<<" AliTRDtrack warning: Propagation failed !\n";
272     return 0;
273   }
274
275   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
276   Double_t c1=fC*x1 - fE;
277   if((c1*c1) > 1) return 0;
278   Double_t r1=sqrt(1.- c1*c1);
279   Double_t c2=fC*x2 - fE;
280   if((c2*c2) > 1) return 0;
281   Double_t r2=sqrt(1.- c2*c2);
282
283   fY += dx*(c1+c2)/(r1+r2);
284   fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
285
286   //f = F - 1
287   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
288   Double_t f02= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
289   Double_t f03=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
290   Double_t cr=c1*r2+c2*r1;
291   Double_t f12= dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
292   Double_t f13=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
293   Double_t f14= dx*cc/cr;
294
295   //b = C*ft
296   Double_t b00=f02*fCcy + f03*fCey, b01=f12*fCcy + f13*fCey + f14*fCty;
297   Double_t b10=f02*fCcz + f03*fCez, b11=f12*fCcz + f13*fCez + f14*fCtz;
298   Double_t b20=f02*fCcc + f03*fCec, b21=f12*fCcc + f13*fCec + f14*fCtc;
299   Double_t b30=f02*fCec + f03*fCee, b31=f12*fCec + f13*fCee + f14*fCte;
300   Double_t b40=f02*fCtc + f03*fCte, b41=f12*fCtc + f13*fCte + f14*fCtt;
301
302   //a = f*b = f*C*ft
303   Double_t a00=f02*b20+f03*b30,a01=f02*b21+f03*b31,a11=f12*b21+f13*b31+f14*b41;
304
305   //F*C*Ft = C + (a + b + bt)
306   fCyy += a00 + 2*b00;
307   fCzy += a01 + b01 + b10;
308   fCcy += b20;
309   fCey += b30;
310   fCty += b40;
311   fCzz += a11 + 2*b11;
312   fCcz += b21;
313   fCez += b31;
314   fCtz += b41;                  
315
316   fX=x2;
317
318
319   //Multiple scattering  ******************
320
321   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
322   Double_t p2=GetPt()*GetPt()*(1.+fT*fT);
323   p2 = TMath::Min(p2,1e+08);  // to avoid division by (1-1) for stiff tracks
324   Double_t beta2=p2/(p2 + pm*pm);
325
326   Double_t ey=fC*fX - fE, ez=fT;
327   Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
328
329   Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
330   fCcc += xz*xz*theta2;
331   fCec += xz*ez*xy*theta2;
332   fCtc += xz*zz1*theta2;
333   fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
334   fCte += ez*zz1*xy*theta2;
335   fCtt += zz1*zz1*theta2;
336
337
338   //Energy losses************************
339   if (x1 < x2) d=-d;
340   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
341   //PH  SetLength(GetLength()+d);
342
343   cc = fC;
344   fC*=(1.- sqrt(p2+pm*pm)/p2*dE);
345   fE+=fX*(fC-cc);
346
347   return 1;        
348
349 }     
350
351 //_____________________________________________________________________________
352 Int_t AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index)
353 {
354   // Assignes found cluster to the track and updates track information
355
356   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
357   r00+=fCyy; r01+=fCzy; r11+=fCzz;
358   Double_t det=r00*r11 - r01*r01;
359   Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
360
361   Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
362   Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
363   Double_t k20=fCcy*r00+fCcz*r01, k21=fCcy*r01+fCcz*r11;
364   Double_t k30=fCey*r00+fCez*r01, k31=fCey*r01+fCez*r11;
365   Double_t k40=fCty*r00+fCtz*r01, k41=fCty*r01+fCtz*r11;
366
367   Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
368   Double_t cur=fC + k20*dy + k21*dz, eta=fE + k30*dy + k31*dz;
369   if (TMath::Abs(cur*fX-eta) >= 0.99999) {
370     Int_t n=GetNumberOfClusters(); 
371     if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
372     return 0;
373   }
374
375   fY += k00*dy + k01*dz;
376   fZ += k10*dy + k11*dz;
377   fC  = cur;
378   fE  = eta;
379   fT += k40*dy + k41*dz;
380
381   Double_t c01=fCzy, c02=fCcy, c03=fCey, c04=fCty;
382   Double_t c12=fCcz, c13=fCez, c14=fCtz;
383
384   fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
385   fCcy-=k00*c02+k01*c12; fCey-=k00*c03+k01*c13;
386   fCty-=k00*c04+k01*c14;
387
388   fCzz-=k10*c01+k11*fCzz;
389   fCcz-=k10*c02+k11*c12; fCez-=k10*c03+k11*c13;
390   fCtz-=k10*c04+k11*c14;
391
392   fCcc-=k20*c02+k21*c12; fCec-=k20*c03+k21*c13;
393   fCtc-=k20*c04+k21*c14;
394
395   fCee-=k30*c03+k31*c13;
396   fCte-=k30*c04+k31*c14;        
397
398   fCtt-=k40*c04+k41*c14;
399
400   Int_t n=GetNumberOfClusters();  
401   fIndex[n]=index;
402   SetNumberOfClusters(n+1);  
403
404   SetChi2(GetChi2()+chisq); 
405   //  cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
406
407   return 1;
408 }                     
409
410 //_____________________________________________________________________________
411 Int_t AliTRDtrack::Rotate(Double_t alpha)
412 {
413   // Rotates track parameters in R*phi plane
414
415   fAlpha += alpha;
416
417   Double_t x1=fX, y1=fY;
418   Double_t ca=cos(alpha), sa=sin(alpha);
419   Double_t r1=fC*fX - fE;
420
421   if (TMath::Abs(r1) >= 0.99999) {
422     Int_t n=GetNumberOfClusters(); 
423     if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
424     return 0;
425   }
426
427   fX = x1*ca + y1*sa;
428   fY=-x1*sa + y1*ca;
429   fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
430
431   Double_t r2=fC*fX - fE;
432   if (TMath::Abs(r2) >= 0.99999) {
433     Int_t n=GetNumberOfClusters(); 
434     if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
435     return 0;
436   }
437
438   Double_t y0=fY + sqrt(1.- r2*r2)/fC;
439   if ((fY-y0)*fC >= 0.) {
440     Int_t n=GetNumberOfClusters(); 
441     if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !!!\n";
442     return 0;
443   }
444
445   //f = F - 1
446   Double_t f00=ca-1,    f32=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
447            f30=fC*sa, f33=(ca + sa*r1/sqrt(1.- r1*r1))-1;
448
449   //b = C*ft
450   Double_t b00=fCyy*f00, b03=fCyy*f30+fCcy*f32+fCey*f33;
451   Double_t b10=fCzy*f00, b13=fCzy*f30+fCcz*f32+fCez*f33;
452   Double_t b20=fCcy*f00, b23=fCcy*f30+fCcc*f32+fCec*f33;
453   Double_t b30=fCey*f00, b33=fCey*f30+fCec*f32+fCee*f33;
454   Double_t b40=fCty*f00, b43=fCty*f30+fCtc*f32+fCte*f33;
455
456   //a = f*b = f*C*ft
457   Double_t a00=f00*b00, a03=f00*b03, a33=f30*b03+f32*b23+f33*b33;
458
459   // *** Double_t dy2=fCyy;  
460           
461   //F*C*Ft = C + (a + b + bt)
462   fCyy += a00 + 2*b00;
463   fCzy += b10;
464   fCcy += b20;
465   fCey += a03+b30+b03;
466   fCty += b40;
467   fCez += b13;
468   fCec += b23;
469   fCee += a33 + 2*b33;
470   fCte += b43;
471
472   // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
473   // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);   
474
475   return 1;
476 }                         
477
478
479 //_____________________________________________________________________________
480 Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c) const
481 {
482   /*
483   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
484   r00+=fCyy; r01+=fCzy; r11+=fCzz;
485
486   Double_t det=r00*r11 - r01*r01;
487   if (TMath::Abs(det) < 1.e-10) {
488     if (fN>4) cerr<<fN<<" AliTRDtrack warning: Singular matrix !\n";
489     return 1e10;
490   }
491   Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
492
493   Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
494
495   return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;  
496   */
497
498   Double_t dy=c->GetY() - fY;
499   Double_t r00=c->GetSigmaY2();
500
501   return (dy*dy)/r00;
502
503 }            
504
505
506 //_________________________________________________________________________
507 void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
508 {
509   // Returns reconstructed track momentum in the global system.
510
511   Double_t pt=TMath::Abs(GetPt()); // GeV/c
512   Double_t r=fC*fX-fE;
513
514   Double_t y0; 
515   if(r > 1) { py = pt; px = 0; }
516   else if(r < -1) { py = -pt; px = 0; }
517   else {
518     y0=fY + sqrt(1.- r*r)/fC;  
519     px=-pt*(fY-y0)*fC;    //cos(phi);
520     py=-pt*(fE-fX*fC);   //sin(phi);
521   }
522   pz=pt*fT;
523   Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
524   py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
525   px=tmp;            
526
527 }                                
528
529 //_________________________________________________________________________
530 void AliTRDtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
531 {
532   // Returns reconstructed track coordinates in the global system.
533
534   x = fX; y = fY; z = fZ; 
535   Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
536   y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
537   x=tmp;            
538
539 }                                
540
541 //_________________________________________________________________________
542 void AliTRDtrack::ResetCovariance() {
543   //
544   // Resets covariance matrix
545   //
546
547   fCyy*=10.;
548   fCzy=0.;   fCzz*=10.;
549   fCcy=0.;   fCcz=0.;   fCcc*=10.;
550   fCey=0.;   fCez=0.;   fCec=0.;   fCee*=10.;
551   fCty=0.;   fCtz=0.;   fCtc=0.;   fCte=0.;   fCtt*=10.;
552
553 }