]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFtrack.cxx
Split library correction (F. Ar
[u/mrichter/AliRoot.git] / TOF / AliTOFtrack.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 // AliTOFtrack class
18 //
19 // Authors: Bologna-CERN-ITEP-Salerno Group
20 //
21 // Description: class for handling ESD extracted tracks for TOF matching.
22 /* $Id$ */
23
24 #include <Riostream.h>
25 #include <TObject.h>   
26 #include "AliLog.h" 
27 #include "AliTOFtrack.h" 
28 #include "AliESDtrack.h" 
29
30 ClassImp(AliTOFtrack)
31
32 //_____________________________________________________________________________
33 AliTOFtrack::AliTOFtrack(const AliTOFtrack& t) : AliKalmanTrack(t) {
34   //
35   // Copy constructor.
36   //
37   
38   SetSeedIndex(t.GetSeedIndex());
39   SetLabel(t.GetLabel());
40   fSeedLab=t.GetSeedLabel();
41   SetChi2(t.GetChi2());
42
43   fAlpha=t.fAlpha;
44   fX=t.fX;
45
46   fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
47
48   fCyy=t.fCyy;
49   fCzy=t.fCzy;  fCzz=t.fCzz;
50   fCey=t.fCey;  fCez=t.fCez;  fCee=t.fCee;
51   fCty=t.fCty;  fCtz=t.fCtz;  fCte=t.fCte;  fCtt=t.fCtt;
52   fCcy=t.fCcy;  fCcz=t.fCcz;  fCce=t.fCce;  fCct=t.fCct;  fCcc=t.fCcc;  
53
54
55 }                                
56
57 //_____________________________________________________________________________
58 AliTOFtrack::AliTOFtrack(const AliESDtrack& t) 
59            :AliKalmanTrack() {
60   //
61   // Constructor from AliESDtrack
62   //
63
64   SetSeedIndex(-1);
65   SetLabel(t.GetLabel());
66   SetChi2(0.);
67   SetMass(t.GetMass());
68
69   fAlpha = t.GetAlpha();
70   if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
71   else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
72   Double_t x, p[5]; t.GetExternalParameters(x,p);
73
74   fX=x;
75
76   x = GetConvConst();  
77
78   fY=p[0];
79   fZ=p[1];
80   fT=p[3];
81   fC=p[4]/x;
82   fE=fC*fX - p[2];   
83
84   //Conversion of the covariance matrix
85   Double_t c[15]; t.GetExternalCovariance(c);
86
87   c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
88
89   Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
90   Double_t c32=fX*c[13] - c[8];
91   Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
92
93   fCyy=c[0 ];
94   fCzy=c[1 ];   fCzz=c[2 ];
95   fCey=c20;     fCez=c21;     fCee=c22;
96   fCty=c[6 ];   fCtz=c[7 ];   fCte=c32;   fCtt=c[9 ];
97   fCcy=c[10];   fCcz=c[11];   fCce=c42;   fCct=c[13]; fCcc=c[14];  
98
99   if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
100   StartTimeIntegral();
101   Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
102   SetIntegratedLength(t.GetIntegratedLength());
103
104
105 }              
106 //____________________________________________________________________________
107 void AliTOFtrack::GetExternalParameters(Double_t& xr, Double_t x[5]) const {
108   //
109   // This function returns external TOF track representation
110   //
111      xr=fX;
112      x[0]=GetY();
113      x[1]=GetZ();
114      x[2]=GetSnp();
115      x[3]=GetTgl();
116      x[4]=Get1Pt();
117 }           
118
119 //_____________________________________________________________________________
120 void AliTOFtrack::GetExternalCovariance(Double_t cc[15]) const {
121   //
122   // This function returns external representation of the covriance matrix.
123   //
124   Double_t a=GetConvConst();
125   Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
126   Double_t c32=fX*fCct-fCte;
127   Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
128
129   cc[0 ]=fCyy;
130   cc[1 ]=fCzy;   cc[2 ]=fCzz;
131   cc[3 ]=c20;    cc[4 ]=c21;    cc[5 ]=c22;
132   cc[6 ]=fCty;   cc[7 ]=fCtz;   cc[8 ]=c32;   cc[9 ]=fCtt;
133   cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a; 
134   
135 }               
136                        
137
138 //_____________________________________________________________________________
139 void AliTOFtrack::GetCovariance(Double_t cc[15]) const {
140   //
141   // Returns the covariance matrix.
142   //
143
144   cc[0]=fCyy;
145   cc[1]=fCzy;  cc[2]=fCzz;
146   cc[3]=fCey;  cc[4]=fCez;  cc[5]=fCee;
147   cc[6]=fCcy;  cc[7]=fCcz;  cc[8]=fCce;  cc[9]=fCcc;
148   cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
149   
150 }    
151
152
153 //_____________________________________________________________________________
154 Int_t AliTOFtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
155 {
156   // Propagates a track of particle with mass=pm to a reference plane 
157   // defined by x=xk through media of density=rho and radiationLength=x0
158
159   if (xk == fX) return 1;
160   
161   if (TMath::Abs(fC*xk - fE) >= 0.90000) {
162     return 0;
163   }
164
165   // track Length measurement [SR, GSI, 17.02.2003]
166
167   Double_t oldX = fX, oldY = fY, oldZ = fZ;  
168
169   Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
170   Double_t c1=fC*x1 - fE;
171   if((c1*c1) > 1){
172     return 0;}
173   Double_t r1=sqrt(1.- c1*c1);
174   Double_t c2=fC*x2 - fE; 
175   if((c2*c2) > 1) {
176     return 0;
177   }
178   Double_t r2=sqrt(1.- c2*c2);
179
180   fY += dx*(c1+c2)/(r1+r2);
181   fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
182
183   //f = F - 1
184   Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
185   Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
186   Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
187   Double_t cr=c1*r2+c2*r1;
188   Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
189   Double_t f13= dx*cc/cr;
190   Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
191
192   //b = C*ft
193   Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
194   Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
195   Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
196   Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
197   Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
198
199   //a = f*b = f*C*ft
200   Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
201
202   //F*C*Ft = C + (a + b + bt)
203   fCyy += a00 + 2*b00;
204   fCzy += a01 + b01 + b10;
205   fCey += b20;
206   fCty += b30;
207   fCcy += b40;
208   fCzz += a11 + 2*b11;
209   fCez += b21;
210   fCtz += b31;
211   fCcz += b41;
212
213   fX=x2;                                                     
214
215   //Multiple scattering  ******************
216   Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
217   Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
218   Double_t beta2=p2/(p2 + GetMass()*GetMass());
219   Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
220
221   Double_t ey=fC*fX - fE, ez=fT;
222   Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
223   
224   fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
225   fCte += ez*zz1*xy*theta2;
226   fCtt += zz1*zz1*theta2;
227   fCce += xz*ez*xy*theta2;
228   fCct += xz*zz1*theta2;
229   fCcc += xz*xz*theta2;
230   /*
231   Double_t dc22 = (1-ey*ey+xz*xz*fX*fX)*theta2;
232   Double_t dc32 = (xz*fX*zz1)*theta2;
233   Double_t dc33 = (zz1*zz1)*theta2;
234   Double_t dc42 = (xz*fX*xz)*theta2;
235   Double_t dc43 = (zz1*xz)*theta2;
236   Double_t dc44 = (xz*xz)*theta2; 
237   fCee += dc22;
238   fCte += dc32;
239   fCtt += dc33;
240   fCce += dc42;
241   fCct += dc43;
242   fCcc += dc44;
243   */
244   //Energy losses************************
245   if((5940*beta2/(1-beta2+1e-10) - beta2) < 0){return 0;}
246
247   Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
248   if (x1 < x2) dE=-dE;
249   cc=fC;
250   fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
251   fE+=fX*(fC-cc);    
252
253   // track time measurement [SR, GSI 17.02.2002]
254   if (x1 < x2)
255   if (IsStartedTimeIntegral()) {
256     Double_t l2 = (fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ);
257     AddTimeStep(TMath::Sqrt(l2));
258   }
259
260   return 1;            
261 }     
262
263 //_____________________________________________________________________________
264 Int_t AliTOFtrack::PropagateToInnerTOF( Bool_t holes)
265 {
266   // Propagates a track of particle with mass=pm to a reference plane 
267   // defined by x=xk through media of density=rho and radiationLength=x0
268
269
270   Double_t ymax=AliTOFGeometry::RinTOF()*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
271   Bool_t skip = kFALSE;
272   Double_t y=GetYat(AliTOFGeometry::RinTOF(),skip);
273   if(skip){
274     return 0;
275   }
276   if (y > ymax) {
277     if (!Rotate(AliTOFGeometry::GetAlpha())) {
278       return 0;
279     }
280   } else if (y <-ymax) {
281     if (!Rotate(-AliTOFGeometry::GetAlpha())) {
282       return 0;
283     }
284   }
285   
286   
287   Double_t x = GetX();
288   Int_t nsteps=Int_t((370.-x)/0.5); // 0.5 cm Steps
289   for (Int_t istep=0;istep<nsteps;istep++){
290     Float_t xp = x+istep*0.5; 
291     Double_t param[2];  
292     GetPropagationParameters(holes,param);  
293     PropagateTo(xp,param[0],param[1]);
294     
295   }
296   
297   if(!PropagateTo(AliTOFGeometry::RinTOF()))return 0;
298   
299   return 1;
300   
301 }     
302
303 //_____________________________________________________________________________
304 Int_t AliTOFtrack::Rotate(Double_t alpha)
305 {
306   // Rotates track parameters in R*phi plane
307   
308
309   fAlpha += alpha;
310   if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
311   if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
312
313   Double_t x1=fX, y1=fY;
314   Double_t ca=cos(alpha), sa=sin(alpha);
315   Double_t r1=fC*fX - fE;
316
317   fX = x1*ca + y1*sa;
318   fY =-x1*sa + y1*ca;
319   if((r1*r1) > 1) return 0;
320   fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
321
322   Double_t r2=fC*fX - fE;
323   if (TMath::Abs(r2) >= 0.90000) {
324     AliWarning("Rotation failed !");
325     return 0;
326   }
327
328   if((r2*r2) > 1) return 0;
329   Double_t y0=fY + sqrt(1.- r2*r2)/fC;
330   if ((fY-y0)*fC >= 0.) {
331     AliWarning("Rotation failed !!!");
332     return 0;
333   }
334
335   //f = F - 1
336   Double_t f00=ca-1,    f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
337            f20=fC*sa,  f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
338
339   //b = C*ft
340   Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
341   Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
342   Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
343   Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
344   Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
345
346   //a = f*b = f*C*ft
347   Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
348
349   //F*C*Ft = C + (a + b + bt)
350   fCyy += a00 + 2*b00;
351   fCzy += b10;
352   fCey += a02+b20+b02;
353   fCty += b30;
354   fCcy += b40;
355   fCez += b12;
356   fCte += b32;
357   fCee += a22 + 2*b22;
358   fCce += b42;
359
360   return 1;                            
361 }                         
362
363 //_________________________________________________________________________
364 Double_t AliTOFtrack::GetYat(Double_t xk, Bool_t skip) const {     
365 //-----------------------------------------------------------------
366 // This function calculates the Y-coordinate of a track at the plane x=xk.
367 // Needed for matching with the TOF (I.Belikov)
368 //-----------------------------------------------------------------
369      skip=kFALSE;
370      Double_t c1=fC*fX - fE, r1=TMath::Sqrt(TMath::Abs(1.- c1*c1));
371      Double_t c2=fC*xk - fE, r2=TMath::Sqrt(TMath::Abs(1.- c2*c2));
372       if( ((1.- c2*c2)<0) || ((1.- c1*c1)<0) ) skip=kTRUE;
373       return fY + (xk-fX)*(c1+c2)/(r1+r2);
374 }
375 //_________________________________________________________________________
376 void AliTOFtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
377 {
378   // Returns reconstructed track momentum in the global system.
379
380   Double_t pt=TMath::Abs(GetPt()); // GeV/c
381   Double_t r=fC*fX-fE;
382
383   Double_t y0; 
384   if(r > 1) { py = pt; px = 0; }
385   else if(r < -1) { py = -pt; px = 0; }
386   else {
387     y0=fY + sqrt(1.- r*r)/fC;  
388     px=-pt*(fY-y0)*fC;    //cos(phi);
389     py=-pt*(fE-fX*fC);    //sin(phi);
390   }
391   pz=pt*fT;
392   Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
393   py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
394   px=tmp;            
395
396 }                                
397
398 //_________________________________________________________________________
399 void AliTOFtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
400 {
401   // Returns reconstructed track coordinates in the global system.
402
403   x = fX; y = fY; z = fZ; 
404   Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
405   y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
406   x=tmp;            
407
408 }                                
409
410 //_________________________________________________________________________
411 void AliTOFtrack::ResetCovariance() {
412   //
413   // Resets covariance matrix
414   //
415
416   fCyy*=10.;
417   fCzy=0.;  fCzz*=10.;
418   fCey=0.;  fCez=0.;  fCee*=10.;
419   fCty=0.;  fCtz=0.;  fCte=0.;  fCtt*=10.;
420   fCcy=0.;  fCcz=0.;  fCce=0.;  fCct=0.;  fCcc*=10.;  
421 }                                                         
422
423
424 //_________________________________________________________________________
425 void AliTOFtrack::ResetCovariance(Float_t mult) {
426   //
427   // Resets covariance matrix
428   //
429
430   fCyy*=mult;
431   fCzy*=0.;  fCzz*=mult;
432   fCey*=0.;  fCez*=0.;  fCee*=mult;
433   fCty*=0.;  fCtz*=0.;  fCte*=0.;  fCtt*=mult;
434   fCcy*=0.;  fCcz*=0.;  fCce*=0.;  fCct*=0.;  fCcc*=mult;  
435 }                                                         
436
437 //_____________________________________________________________________________
438 Int_t AliTOFtrack::Compare(const TObject *o) const {
439   //-----------------------------------------------------------------
440   // This function compares tracks according to the their curvature
441   //-----------------------------------------------------------------
442   AliTOFtrack *t=(AliTOFtrack*)o;
443   Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
444   Double_t c =GetSigmaY2()*GetSigmaZ2();
445   if (c>co) return 1;
446   else if (c<co) return -1;
447   return 0;
448 }
449
450 //_____________________________________________________________________________
451 void AliTOFtrack::GetPropagationParameters(Bool_t holes, Double_t *param) {
452
453  //Get average medium density, x0 while propagating the track
454
455   //For TRD holes description
456
457   Double_t thetamin = (90.-31.1) * TMath::Pi()/180.;
458   Double_t thetamax = (90.+31.1) * TMath::Pi()/180.;
459
460   Double_t zmin = -55.;
461   Double_t zmax =  55.;
462
463   // Detector inner/outer radii
464   Double_t rTPC    = 261.53;
465   Double_t rTPCTRD = 294.5;
466   Double_t rTRD    = 369.1;
467
468   // Medium parameters
469   Double_t x0TPC = 40.;
470   Double_t rhoTPC =0.06124;
471
472   Double_t x0Air = 36.66;
473   Double_t rhoAir =1.2931e-3;
474
475   Double_t x0TRD = 171.7;
476   Double_t rhoTRD =0.33;
477
478   Int_t isec = GetSector();
479   Double_t xtr,ytr,ztr;
480   GetGlobalXYZ(xtr,ytr,ztr);
481   Float_t thetatr = TMath::ATan2(TMath::Sqrt(xtr*xtr+ytr*ytr),ztr);
482
483   if(holes){
484     if (isec == 0 || isec == 1 || isec == 2 ) {
485       if( thetatr>=thetamin && thetatr<=thetamax){ 
486         x0TRD= x0Air;
487         rhoTRD = rhoAir;
488       }
489     }
490     if (isec == 11 || isec == 12 || isec == 13 || isec == 14 || isec == 15 ) {
491       if( ztr>=zmin && ztr<=zmax){ 
492         x0TRD= x0Air;
493         rhoTRD = rhoAir;
494       }
495     }
496   }
497
498   if(GetX() <= rTPC)
499     {param[0]=x0TPC;param[1]=rhoTPC;}
500   else if(GetX() > rTPC &&  GetX() < rTPCTRD)
501     {param[0]=x0Air;param[1]=rhoAir;}
502   else if(GetX() >= rTPCTRD &&  GetX() < rTRD)
503     {param[0]=x0TRD;param[1]=rhoTRD;}
504   else if(GetX() >= rTRD )
505     {param[0]=x0Air;param[1]=rhoAir;}
506 }