Coding conventions
[u/mrichter/AliRoot.git] / STEER / AliExternalTrackParam.cxx
CommitLineData
51ad6848 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// track parameters in "external" format //
21// //
22// The track parameters are: //
23// - local y coordinate //
24// - local z coordinate //
25// - sin of azimutal angle //
26// - tan of dip angle //
27// - charge/pt //
28// The parametrisation is given at the local x coordinate fX and the //
29// azimuthal angle fAlpha. //
30// //
31// The external parametrisation can be used to exchange track parameters //
32// between different detectors. //
33// //
34///////////////////////////////////////////////////////////////////////////////
51ad6848 35#include "AliExternalTrackParam.h"
36#include "AliKalmanTrack.h"
37
38ClassImp(AliExternalTrackParam)
39
51ad6848 40//_____________________________________________________________________________
90e48c0c 41AliExternalTrackParam::AliExternalTrackParam() :
90e48c0c 42 fX(0),
c9ec41e8 43 fAlpha(0)
51ad6848 44{
90e48c0c 45 //
46 // default constructor
47 //
c9ec41e8 48 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
49 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
51ad6848 50}
51
52//_____________________________________________________________________________
53AliExternalTrackParam::AliExternalTrackParam(Double_t x, Double_t alpha,
54 const Double_t param[5],
90e48c0c 55 const Double_t covar[15]) :
90e48c0c 56 fX(x),
c9ec41e8 57 fAlpha(alpha)
51ad6848 58{
90e48c0c 59 //
60 // create external track parameters from given arguments
61 //
c9ec41e8 62 for (Int_t i = 0; i < 5; i++) fP[i] = param[i];
63 for (Int_t i = 0; i < 15; i++) fC[i] = covar[i];
51ad6848 64}
65
90e48c0c 66//_____________________________________________________________________________
67AliExternalTrackParam::AliExternalTrackParam(const AliKalmanTrack& track) :
c9ec41e8 68 fAlpha(track.GetAlpha())
51ad6848 69{
70 //
71 //
c9ec41e8 72 track.GetExternalParameters(fX,fP);
73 track.GetExternalCovariance(fC);
51ad6848 74}
75
51ad6848 76//_____________________________________________________________________________
c9ec41e8 77void AliExternalTrackParam::Set(const AliKalmanTrack& track) {
78 //
79 //
80 fAlpha=track.GetAlpha();
81 track.GetExternalParameters(fX,fP);
82 track.GetExternalCovariance(fC);
51ad6848 83}
84
85//_____________________________________________________________________________
c9ec41e8 86void AliExternalTrackParam::Reset() {
87 fX=fAlpha=0.;
88 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
89 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
51ad6848 90}
91
c9ec41e8 92Double_t AliExternalTrackParam::GetP() const {
93 //---------------------------------------------------------------------
94 // This function returns the track momentum
95 // Results for (nearly) straight tracks are meaningless !
96 //---------------------------------------------------------------------
97 if (TMath::Abs(fP[4])<=0) return 0;
98 return TMath::Sqrt(1.+ fP[3]*fP[3])/TMath::Abs(fP[4]);
51ad6848 99}
100
c9ec41e8 101//_______________________________________________________________________
102Double_t AliExternalTrackParam::GetD(Double_t b,Double_t x,Double_t y) const {
103 //------------------------------------------------------------------
104 // This function calculates the transverse impact parameter
105 // with respect to a point with global coordinates (x,y)
106 // in the magnetic field "b" (kG)
107 //------------------------------------------------------------------
108 Double_t convconst=0.299792458*b/1000.;
109 Double_t rp4=fP[4]*convconst;
110
111 Double_t xt=fX, yt=fP[0];
112
113 Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
114 Double_t a = x*cs + y*sn;
115 y = -x*sn + y*cs; x=a;
116 xt-=x; yt-=y;
117
118 sn=rp4*xt - fP[2]; cs=rp4*yt + TMath::Sqrt(1.- fP[2]*fP[2]);
119 a=2*(xt*fP[2] - yt*TMath::Sqrt(1.- fP[2]*fP[2]))-rp4*(xt*xt + yt*yt);
120 if (rp4<0) a=-a;
121 return a/(1 + TMath::Sqrt(sn*sn + cs*cs));
51ad6848 122}
123
c9ec41e8 124Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
125 //----------------------------------------------------------------
126 // This function performs local->global transformation of the
127 // track momentum.
128 // When called, the arguments are:
129 // p[0] = 1/pt of the track;
130 // p[1] = sine of local azim. angle of the track momentum;
131 // p[2] = tangent of the track momentum dip angle;
132 // alpha - rotation angle.
133 // The result is returned as:
134 // p[0] = px
135 // p[1] = py
136 // p[2] = pz
137 // Results for (nearly) straight tracks are meaningless !
138 //----------------------------------------------------------------
139 if (TMath::Abs(p[0])<=0) return kFALSE;
140 if (TMath::Abs(p[1])> 0.999999) return kFALSE;
141
142 Double_t pt=1./TMath::Abs(p[0]);
143 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
144 Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
145 p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
a5e407e9 146
147 return kTRUE;
148}
149
c9ec41e8 150Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
151 //----------------------------------------------------------------
152 // This function performs local->global transformation of the
153 // track position.
154 // When called, the arguments are:
155 // r[0] = local x
156 // r[1] = local y
157 // r[2] = local z
158 // alpha - rotation angle.
159 // The result is returned as:
160 // r[0] = global x
161 // r[1] = global y
162 // r[2] = global z
163 //----------------------------------------------------------------
164 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
165 r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
a5e407e9 166
a5e407e9 167 return kTRUE;
51ad6848 168}
169
c9ec41e8 170Bool_t AliExternalTrackParam::GetPxPyPz(Double_t *p) const {
171 //---------------------------------------------------------------------
172 // This function returns the global track momentum components
173 // Results for (nearly) straight tracks are meaningless !
174 //---------------------------------------------------------------------
175 p[0]=fP[4]; p[1]=fP[2]; p[2]=fP[3];
176 return Local2GlobalMomentum(p,fAlpha);
177}
a5e407e9 178
c9ec41e8 179Bool_t AliExternalTrackParam::GetXYZ(Double_t *r) const {
180 //---------------------------------------------------------------------
181 // This function returns the global track position
182 //---------------------------------------------------------------------
183 r[0]=fX; r[1]=fP[0]; r[2]=fP[1];
184 return Local2GlobalPosition(r,fAlpha);
51ad6848 185}
186
c9ec41e8 187Bool_t AliExternalTrackParam::GetCovarianceXYZPxPyPz(Double_t cv[21]) const {
188 //---------------------------------------------------------------------
189 // This function returns the global covariance matrix of the track params
190 //
191 // Cov(x,x) ... : cv[0]
192 // Cov(y,x) ... : cv[1] cv[2]
193 // Cov(z,x) ... : cv[3] cv[4] cv[5]
194 // Cov(px,x)... : cv[6] cv[7] cv[8] cv[9]
195 // Cov(py,x)... : cv[10] cv[11] cv[12] cv[13] cv[14]
196 // Cov(pz,x)... : cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
a5e407e9 197 //
c9ec41e8 198 // Results for (nearly) straight tracks are meaningless !
199 //---------------------------------------------------------------------
200 if (TMath::Abs(fP[4])<=0) {
201 for (Int_t i=0; i<21; i++) cv[i]=0.;
202 return kFALSE;
a5e407e9 203 }
c9ec41e8 204 if (TMath::Abs(fP[2]) > 0.999999) {
205 for (Int_t i=0; i<21; i++) cv[i]=0.;
206 return kFALSE;
207 }
208 Double_t pt=1./TMath::Abs(fP[4]);
209 Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
210 Double_t r=TMath::Sqrt(1-fP[2]*fP[2]);
211
212 Double_t m00=-sn, m10=cs;
213 Double_t m23=-pt*(sn + fP[2]*cs/r), m43=-pt*pt*(r*cs - fP[2]*sn);
214 Double_t m24= pt*(cs - fP[2]*sn/r), m44=-pt*pt*(r*sn + fP[2]*cs);
215 Double_t m35=pt, m45=-pt*pt*fP[3];
216
217 cv[0 ] = fC[0]*m00*m00;
218 cv[1 ] = fC[0]*m00*m10;
219 cv[2 ] = fC[0]*m10*m10;
220 cv[3 ] = fC[1]*m00;
221 cv[4 ] = fC[1]*m10;
222 cv[5 ] = fC[2];
223 cv[6 ] = m00*(fC[3]*m23 + fC[10]*m43);
224 cv[7 ] = m10*(fC[3]*m23 + fC[10]*m43);
225 cv[8 ] = fC[4]*m23 + fC[11]*m43;
226 cv[9 ] = m23*(fC[5]*m23 + fC[12]*m43) + m43*(fC[12]*m23 + fC[14]*m43);
227 cv[10] = m00*(fC[3]*m24 + fC[10]*m44);
228 cv[11] = m10*(fC[3]*m24 + fC[10]*m44);
229 cv[12] = fC[4]*m24 + fC[11]*m44;
230 cv[13] = m23*(fC[5]*m24 + fC[12]*m44) + m43*(fC[12]*m24 + fC[14]*m44);
231 cv[14] = m24*(fC[5]*m24 + fC[12]*m44) + m44*(fC[12]*m24 + fC[14]*m44);
232 cv[15] = m00*(fC[6]*m35 + fC[10]*m45);
233 cv[16] = m10*(fC[6]*m35 + fC[10]*m45);
234 cv[17] = fC[7]*m35 + fC[11]*m45;
235 cv[18] = m23*(fC[8]*m35 + fC[12]*m45) + m43*(fC[13]*m35 + fC[14]*m45);
236 cv[19] = m24*(fC[8]*m35 + fC[12]*m45) + m44*(fC[13]*m35 + fC[14]*m45);
237 cv[20] = m35*(fC[9]*m35 + fC[13]*m45) + m45*(fC[13]*m35 + fC[14]*m45);
51ad6848 238
c9ec41e8 239 return kTRUE;
51ad6848 240}
241
51ad6848 242
c9ec41e8 243Bool_t
244AliExternalTrackParam::GetPxPyPzAt(Double_t x, Double_t b, Double_t *p) const {
245 //---------------------------------------------------------------------
246 // This function returns the global track momentum extrapolated to
247 // the radial position "x" (cm) in the magnetic field "b" (kG)
248 //---------------------------------------------------------------------
249 Double_t convconst=0.299792458*b/1000.;
250 p[0]=fP[4];
251 p[1]=fP[2]+(x-fX)*fP[4]*convconst;
252 p[2]=fP[3];
253 return Local2GlobalMomentum(p,fAlpha);
51ad6848 254}
255
c9ec41e8 256Bool_t
257AliExternalTrackParam::GetXYZAt(Double_t x, Double_t b, Double_t *r) const {
258 //---------------------------------------------------------------------
259 // This function returns the global track position extrapolated to
260 // the radial position "x" (cm) in the magnetic field "b" (kG)
261 //---------------------------------------------------------------------
262 Double_t convconst=0.299792458*b/1000.;
263 Double_t dx=x-fX;
264 Double_t f1=fP[2], f2=f1 + dx*fP[4]*convconst;
265
266 if (TMath::Abs(f2) >= 0.9999) return kFALSE;
267
268 Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
269 r[0] = x;
270 r[1] = fP[0] + dx*(f1+f2)/(r1+r2);
271 r[2] = fP[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fP[3];
272 return Local2GlobalPosition(r,fAlpha);
51ad6848 273}
274
275
276//_____________________________________________________________________________
277void AliExternalTrackParam::Print(Option_t* /*option*/) const
278{
279// print the parameters and the covariance matrix
280
281 printf("AliExternalTrackParam: x = %-12g alpha = %-12g\n", fX, fAlpha);
282 printf(" parameters: %12g %12g %12g %12g %12g\n",
c9ec41e8 283 fP[0], fP[1], fP[2], fP[3], fP[4]);
284 printf(" covariance: %12g\n", fC[0]);
285 printf(" %12g %12g\n", fC[1], fC[2]);
286 printf(" %12g %12g %12g\n", fC[3], fC[4], fC[5]);
51ad6848 287 printf(" %12g %12g %12g %12g\n",
c9ec41e8 288 fC[6], fC[7], fC[8], fC[9]);
51ad6848 289 printf(" %12g %12g %12g %12g %12g\n",
c9ec41e8 290 fC[10], fC[11], fC[12], fC[13], fC[14]);
51ad6848 291}