]>
Commit | Line | Data |
---|---|---|
4c039060 | 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 | ||
f531a546 | 16 | // $Id$ |
4c039060 | 17 | |
959fbac5 | 18 | /////////////////////////////////////////////////////////////////////////// |
19 | // Class AliPosition | |
20 | // Handling of positions in various reference frames. | |
21 | // | |
22 | // This class is meant to serve as a base class for ALICE objects | |
23 | // that have a unique position in 3-dimensional space. | |
24 | // | |
25 | // Note : | |
26 | // ------ | |
1f241680 | 27 | // Positions (r), errors (e), reference frames (f) and angular units (u) |
28 | // are specified via | |
959fbac5 | 29 | // |
1f241680 | 30 | // SetPosition(Float_t* r,TString f,TString u) |
31 | // SetPositionErrors(Float_t* e,TString f,TString u) | |
959fbac5 | 32 | // |
33 | // under the following conventions : | |
34 | // | |
35 | // f="car" ==> r in Cartesian coordinates (x,y,z) | |
36 | // f="sph" ==> r in Spherical coordinates (r,theta,phi) | |
37 | // f="cyl" ==> r in Cylindrical coordinates (rho,phi,z) | |
38 | // | |
1f241680 | 39 | // u="rad" ==> angles in radians |
40 | // u="deg" ==> angles in degrees | |
959fbac5 | 41 | // |
1f241680 | 42 | // The "f" and "u" facilities only serve as a convenient user interface. |
43 | // Internally the actual storage of the various components is performed | |
44 | // in a unique way. This allows setting/retrieval of vector components in a | |
45 | // user selected frame/unit convention at any time. | |
46 | // | |
47 | // The metric unit scale for the coordinates can be defined by the user | |
261c0caf | 48 | // via the SetUnitScale() memberfunction. |
49 | // This enables standardised expressions using numerical values of | |
50 | // physical constants by means of the GetUnitScale() memberfunction. | |
25eefd00 | 51 | // By default the unit scale is set to meter, corresponding to invokation |
52 | // of SetUnitScale(1). | |
53 | // The user can specify a certain required metric unit scale in retreiving | |
54 | // position components and/or distances. | |
55 | // Please refer to the corresponding member functions for further details. | |
261c0caf | 56 | // |
57 | // | |
959fbac5 | 58 | // Example : |
59 | // --------- | |
60 | // | |
61 | // AliPosition q; | |
62 | // Float_t pos[3]={-1,25,7}; | |
63 | // Float_t err[3]={0.08,1.85,0.5}; | |
64 | // q.SetPosition(pos,"car"); | |
65 | // q.SetPositionErrors(pos,"car"); | |
66 | // Float_t loc[3],dloc[3]; | |
1f241680 | 67 | // q.GetPosition(loc,"sph","deg"); |
68 | // q.GetPositionErrors(dloc,"sph","deg"); | |
959fbac5 | 69 | // |
70 | //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht | |
f531a546 | 71 | //- Modified: NvE $Date$ UU-SAP Utrecht |
959fbac5 | 72 | /////////////////////////////////////////////////////////////////////////// |
73 | ||
d88f97cc | 74 | #include "AliPosition.h" |
c72198f1 | 75 | #include "Riostream.h" |
d88f97cc | 76 | |
77 | ClassImp(AliPosition) // Class implementation to enable ROOT I/O | |
78 | ||
79 | AliPosition::AliPosition() | |
80 | { | |
261c0caf | 81 | // Creation of an AliPosition object and initialisation of parameters. |
82 | // The unit scale for position coordinates is initialised to cm. | |
25eefd00 | 83 | fScale=1; |
a7dc0627 | 84 | fTstamp=0; |
d88f97cc | 85 | } |
86 | /////////////////////////////////////////////////////////////////////////// | |
87 | AliPosition::~AliPosition() | |
88 | { | |
89 | // Destructor to delete dynamically allocated memory | |
a7dc0627 | 90 | if (fTstamp) |
91 | { | |
92 | delete fTstamp; | |
93 | fTstamp=0; | |
94 | } | |
d88f97cc | 95 | } |
96 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 97 | AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p) |
98 | { | |
99 | // Copy constructor | |
261c0caf | 100 | fScale=p.fScale; |
f4d1f676 | 101 | fTstamp=0; |
a7dc0627 | 102 | if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp)); |
c72198f1 | 103 | } |
104 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 105 | void AliPosition::SetPosition(Double_t* r,TString f,TString u) |
d88f97cc | 106 | { |
107 | // Store position according to reference frame f | |
1f241680 | 108 | // |
109 | // The string argument "u" allows to choose between different angular units | |
110 | // in case e.g. a spherical frame is selected. | |
111 | // u = "rad" : angles provided in radians | |
112 | // "deg" : angles provided in degrees | |
113 | // | |
114 | // The default is u="rad". | |
115 | ||
116 | SetVector(r,f,u); | |
d88f97cc | 117 | } |
118 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 119 | void AliPosition::GetPosition(Double_t* r,TString f,TString u,Float_t scale) const |
d88f97cc | 120 | { |
121 | // Provide position according to reference frame f | |
1f241680 | 122 | // |
123 | // The string argument "u" allows to choose between different angular units | |
124 | // in case e.g. a spherical frame is selected. | |
125 | // u = "rad" : angles provided in radians | |
126 | // "deg" : angles provided in degrees | |
127 | // | |
128 | // The default is u="rad". | |
25eefd00 | 129 | // |
130 | // By default the coordinates will be provided in the metric unit scale as | |
131 | // stored in the AliPosition object. | |
132 | // However, the user can select a different metric unit scale by | |
133 | // specification of the scale parameter. | |
134 | // The convention is that scale=1 corresponds to meter, so specification | |
135 | // of scale=0.01 will provide the position coordinates in cm. | |
1f241680 | 136 | |
25eefd00 | 137 | Ali3Vector v=(Ali3Vector)(*this); |
138 | if (scale>0) v*=fScale/scale; | |
139 | v.GetVector(r,f,u); | |
d88f97cc | 140 | } |
141 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 142 | void AliPosition::SetPosition(Float_t* r,TString f,TString u) |
d88f97cc | 143 | { |
144 | // Store position according to reference frame f | |
1f241680 | 145 | // |
146 | // The string argument "u" allows to choose between different angular units | |
147 | // in case e.g. a spherical frame is selected. | |
148 | // u = "rad" : angles provided in radians | |
149 | // "deg" : angles provided in degrees | |
150 | // | |
151 | // The default is u="rad". | |
152 | ||
153 | SetVector(r,f,u); | |
d88f97cc | 154 | } |
155 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 156 | void AliPosition::GetPosition(Float_t* r,TString f,TString u,Float_t scale) const |
d88f97cc | 157 | { |
158 | // Provide position according to reference frame f | |
1f241680 | 159 | // |
160 | // The string argument "u" allows to choose between different angular units | |
161 | // in case e.g. a spherical frame is selected. | |
162 | // u = "rad" : angles provided in radians | |
163 | // "deg" : angles provided in degrees | |
164 | // | |
165 | // The default is u="rad". | |
25eefd00 | 166 | // |
167 | // By default the coordinates will be provided in the metric unit scale as | |
168 | // stored in the AliPosition object. | |
169 | // However, the user can select a different metric unit scale by | |
170 | // specification of the scale parameter. | |
171 | // The convention is that scale=1 corresponds to meter, so specification | |
172 | // of scale=0.01 will provide the position coordinates in cm. | |
1f241680 | 173 | |
25eefd00 | 174 | Ali3Vector v=(Ali3Vector)(*this); |
175 | if (scale>0) v*=fScale/scale; | |
176 | v.GetVector(r,f,u); | |
d88f97cc | 177 | } |
178 | /////////////////////////////////////////////////////////////////////////// | |
179 | AliPosition& AliPosition::GetPosition() | |
180 | { | |
181 | // Provide position | |
182 | return (*this); | |
183 | } | |
184 | /////////////////////////////////////////////////////////////////////////// | |
185 | void AliPosition::SetPosition(Ali3Vector& r) | |
186 | { | |
187 | // Set position | |
188 | Double_t a[3]; | |
189 | r.GetVector(a,"sph"); | |
190 | SetVector(a,"sph"); | |
959fbac5 | 191 | r.GetErrors(a,"car"); |
192 | SetErrors(a,"car"); | |
193 | } | |
194 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 195 | void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u) |
959fbac5 | 196 | { |
197 | // Store position errors according to reference frame f | |
1f241680 | 198 | // |
199 | // The string argument "u" allows to choose between different angular units | |
200 | // in case e.g. a spherical frame is selected. | |
201 | // u = "rad" : angles provided in radians | |
202 | // "deg" : angles provided in degrees | |
203 | // | |
204 | // The default is u="rad". | |
205 | ||
206 | SetErrors(r,f,u); | |
959fbac5 | 207 | } |
208 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 209 | void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u,Float_t scale) const |
959fbac5 | 210 | { |
211 | // Provide position errors according to reference frame f | |
1f241680 | 212 | // |
213 | // The string argument "u" allows to choose between different angular units | |
214 | // in case e.g. a spherical frame is selected. | |
215 | // u = "rad" : angles provided in radians | |
216 | // "deg" : angles provided in degrees | |
217 | // | |
218 | // The default is u="rad". | |
25eefd00 | 219 | // |
220 | // By default the coordinate errors will be provided in the metric unit scale as | |
221 | // stored in the AliPosition object. | |
222 | // However, the user can select a different metric unit scale by | |
223 | // specification of the scale parameter. | |
224 | // The convention is that scale=1 corresponds to meter, so specification | |
225 | // of scale=0.01 will provide the position coordinate errors in cm. | |
1f241680 | 226 | |
25eefd00 | 227 | Ali3Vector v=(Ali3Vector)(*this); |
228 | if (scale>0) v*=fScale/scale; | |
229 | v.GetErrors(r,f,u); | |
959fbac5 | 230 | } |
231 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 232 | void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u) |
959fbac5 | 233 | { |
234 | // Store position errors according to reference frame f | |
1f241680 | 235 | // |
236 | // The string argument "u" allows to choose between different angular units | |
237 | // in case e.g. a spherical frame is selected. | |
238 | // u = "rad" : angles provided in radians | |
239 | // "deg" : angles provided in degrees | |
240 | // | |
241 | // The default is u="rad". | |
242 | ||
243 | SetErrors(r,f,u); | |
959fbac5 | 244 | } |
245 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 246 | void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u,Float_t scale) const |
959fbac5 | 247 | { |
248 | // Provide position errors according to reference frame f | |
1f241680 | 249 | // |
250 | // The string argument "u" allows to choose between different angular units | |
251 | // in case e.g. a spherical frame is selected. | |
252 | // u = "rad" : angles provided in radians | |
253 | // "deg" : angles provided in degrees | |
254 | // | |
255 | // The default is u="rad". | |
25eefd00 | 256 | // |
257 | // By default the coordinate errors will be provided in the metric unit scale as | |
258 | // stored in the AliPosition object. | |
259 | // However, the user can select a different metric unit scale by | |
260 | // specification of the scale parameter. | |
261 | // The convention is that scale=1 corresponds to meter, so specification | |
262 | // of scale=0.01 will provide the position coordinate errors in cm. | |
1f241680 | 263 | |
25eefd00 | 264 | Ali3Vector v=(Ali3Vector)(*this); |
265 | if (scale>0) v*=fScale/scale; | |
266 | v.GetErrors(r,f,u); | |
d88f97cc | 267 | } |
268 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 269 | void AliPosition::ResetPosition() |
270 | { | |
271 | // Reset the position and corresponding errors to 0. | |
272 | Double_t r[3]={0,0,0}; | |
273 | SetVector(r,"sph"); | |
274 | SetErrors(r,"car"); | |
275 | } | |
276 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 277 | Double_t AliPosition::GetDistance(AliPosition& p,Float_t scale) |
43bfa5be | 278 | { |
261c0caf | 279 | // Provide distance of the current AliPosition to position p. |
43bfa5be | 280 | // The error on the result can be obtained as usual by invoking |
281 | // GetResultError() afterwards. | |
261c0caf | 282 | // |
25eefd00 | 283 | // By default the distance will be provided in the metric unit scale of |
284 | // the current AliPosition. | |
285 | // This implies that the results of r1.GetDistance(r2) and r2.GetDistance(r1) | |
286 | // may be numerically different in case r1 and r2 have different metric units. | |
287 | // However, the user can specify a required metric unit scale by specification | |
288 | // of the scale parameter. | |
289 | // The convention is that scale=1 corresponds to meter, so specification | |
290 | // of scale=0.01 will provide the distance in cm. | |
291 | // As such it is possible to obtain a correctly computed distance even in case | |
292 | // the position coordinates have a different unit scale. | |
261c0caf | 293 | // However, it is recommended to work always with one single unit scale. |
294 | // | |
295 | Ali3Vector d=(Ali3Vector)p; | |
296 | Float_t pscale=p.GetUnitScale(); | |
297 | if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale); | |
298 | Ali3Vector q=(Ali3Vector)(*this); | |
299 | d=d-q; | |
43bfa5be | 300 | Double_t dist=d.GetNorm(); |
301 | fDresult=d.GetResultError(); | |
25eefd00 | 302 | |
303 | if (scale>0) | |
304 | { | |
305 | dist*=fScale/scale; | |
306 | fDresult*=fScale/scale; | |
307 | } | |
43bfa5be | 308 | return dist; |
309 | } | |
310 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 311 | void AliPosition::SetUnitScale(Float_t s) |
312 | { | |
313 | // Set the unit scale for the position coordinates. | |
314 | // The scale is normalised w.r.t. the meter, so setting the unit scale | |
315 | // to 0.01 means that all position coordinates are in cm. | |
25eefd00 | 316 | // By default the unit scale is set to meter in the AliPosition constructor. |
261c0caf | 317 | // It is recommended to use one single unit scale throughout a complete |
318 | // analysis and/or simulation project. | |
319 | // | |
320 | // Note : This memberfunction does not modify the numerical values of | |
321 | // the position coordinates. | |
322 | // It only specifies their numerical meaning. | |
323 | // | |
324 | if (s>0.) | |
325 | { | |
326 | fScale=s; | |
327 | } | |
328 | else | |
329 | { | |
330 | cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl; | |
331 | } | |
332 | } | |
333 | /////////////////////////////////////////////////////////////////////////// | |
334 | Float_t AliPosition::GetUnitScale() const | |
335 | { | |
336 | // Provide the unit scale for the position coordinates. | |
337 | // The scale is normalised w.r.t. the meter, so a unit scale of 0.01 | |
338 | // means that all position coordinates are in cm. | |
339 | return fScale; | |
340 | } | |
341 | /////////////////////////////////////////////////////////////////////////// | |
a7dc0627 | 342 | void AliPosition::SetTimestamp(AliTimestamp& t) |
343 | { | |
344 | // Store the timestamp for this position. | |
345 | if (fTstamp) delete fTstamp; | |
346 | fTstamp=new AliTimestamp(t); | |
347 | } | |
348 | /////////////////////////////////////////////////////////////////////////// | |
349 | AliTimestamp* AliPosition::GetTimestamp() | |
350 | { | |
351 | // Provide the timestamp of this position. | |
352 | return fTstamp; | |
353 | } | |
354 | /////////////////////////////////////////////////////////////////////////// | |
355 | void AliPosition::RemoveTimestamp() | |
356 | { | |
357 | // Remove the timestamp from this postion. | |
358 | if (fTstamp) | |
359 | { | |
360 | delete fTstamp; | |
361 | fTstamp=0; | |
362 | } | |
363 | } | |
364 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 365 | void AliPosition::Data(TString f,TString u) const |
a7dc0627 | 366 | { |
367 | // Provide all position/time information within the coordinate frame f. | |
1f241680 | 368 | // |
369 | // The string argument "u" allows to choose between different angular units | |
370 | // in case e.g. a spherical frame is selected. | |
371 | // u = "rad" : angles provided in radians | |
372 | // "deg" : angles provided in degrees | |
373 | // | |
374 | // The defaults are f="car" and u="rad". | |
375 | ||
376 | Ali3Vector::Data(f,u); | |
25eefd00 | 377 | cout << " Metric unit : " << fScale << " meter" << endl; |
a7dc0627 | 378 | if (fTstamp) fTstamp->Date(1); |
379 | } | |
380 | /////////////////////////////////////////////////////////////////////////// |