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