1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Handling of positions in various reference frames.
22 // This class is meant to serve as a base class for ALICE objects
23 // that have a unique position in 3-dimensional space.
27 // Positions (r), errors (e), reference frames (f) and angular units (u)
30 // SetPosition(Float_t* r,TString f,TString u)
31 // SetPositionErrors(Float_t* e,TString f,TString u)
33 // under the following conventions :
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)
39 // u="rad" ==> angles in radians
40 // u="deg" ==> angles in degrees
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.
47 // The metric unit scale for the coordinates can be defined by the user
48 // via the SetUnitScale() memberfunction.
49 // This enables standardised expressions using numerical values of
50 // physical constants by means of the GetUnitScale() memberfunction.
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.
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];
67 // q.GetPosition(loc,"sph","deg");
68 // q.GetPositionErrors(dloc,"sph","deg");
70 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
71 //- Modified: NvE $Date$ UU-SAP Utrecht
72 ///////////////////////////////////////////////////////////////////////////
74 #include "AliPosition.h"
75 #include "Riostream.h"
77 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
79 AliPosition::AliPosition()
81 // Creation of an AliPosition object and initialisation of parameters.
82 // The unit scale for position coordinates is initialised to cm.
86 ///////////////////////////////////////////////////////////////////////////
87 AliPosition::~AliPosition()
89 // Destructor to delete dynamically allocated memory
96 ///////////////////////////////////////////////////////////////////////////
97 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
102 if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
104 ///////////////////////////////////////////////////////////////////////////
105 void AliPosition::SetPosition(Double_t* r,TString f,TString u)
107 // Store position according to reference frame f
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
114 // The default is u="rad".
118 ///////////////////////////////////////////////////////////////////////////
119 void AliPosition::GetPosition(Double_t* r,TString f,TString u,Float_t scale) const
121 // Provide position according to reference frame f
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
128 // The default is u="rad".
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.
137 Ali3Vector v=(Ali3Vector)(*this);
138 if (scale>0) v*=fScale/scale;
141 ///////////////////////////////////////////////////////////////////////////
142 void AliPosition::SetPosition(Float_t* r,TString f,TString u)
144 // Store position according to reference frame f
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
151 // The default is u="rad".
155 ///////////////////////////////////////////////////////////////////////////
156 void AliPosition::GetPosition(Float_t* r,TString f,TString u,Float_t scale) const
158 // Provide position according to reference frame f
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
165 // The default is u="rad".
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.
174 Ali3Vector v=(Ali3Vector)(*this);
175 if (scale>0) v*=fScale/scale;
178 ///////////////////////////////////////////////////////////////////////////
179 AliPosition& AliPosition::GetPosition()
184 ///////////////////////////////////////////////////////////////////////////
185 void AliPosition::SetPosition(Ali3Vector& r)
189 r.GetVector(a,"sph");
191 r.GetErrors(a,"car");
194 ///////////////////////////////////////////////////////////////////////////
195 void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
197 // Store position errors according to reference frame f
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
204 // The default is u="rad".
208 ///////////////////////////////////////////////////////////////////////////
209 void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u,Float_t scale) const
211 // Provide position errors according to reference frame f
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
218 // The default is u="rad".
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.
227 Ali3Vector v=(Ali3Vector)(*this);
228 if (scale>0) v*=fScale/scale;
231 ///////////////////////////////////////////////////////////////////////////
232 void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
234 // Store position errors according to reference frame f
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
241 // The default is u="rad".
245 ///////////////////////////////////////////////////////////////////////////
246 void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u,Float_t scale) const
248 // Provide position errors according to reference frame f
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
255 // The default is u="rad".
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.
264 Ali3Vector v=(Ali3Vector)(*this);
265 if (scale>0) v*=fScale/scale;
268 ///////////////////////////////////////////////////////////////////////////
269 void AliPosition::ResetPosition()
271 // Reset the position and corresponding errors to 0.
272 Double_t r[3]={0,0,0};
276 ///////////////////////////////////////////////////////////////////////////
277 Double_t AliPosition::GetDistance(AliPosition& p,Float_t scale)
279 // Provide distance of the current AliPosition to position p.
280 // The error on the result can be obtained as usual by invoking
281 // GetResultError() afterwards.
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.
293 // However, it is recommended to work always with one single unit scale.
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);
300 Double_t dist=d.GetNorm();
301 fDresult=d.GetResultError();
306 fDresult*=fScale/scale;
310 ///////////////////////////////////////////////////////////////////////////
311 void AliPosition::SetUnitScale(Float_t s)
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.
316 // By default the unit scale is set to meter in the AliPosition constructor.
317 // It is recommended to use one single unit scale throughout a complete
318 // analysis and/or simulation project.
320 // Note : This memberfunction does not modify the numerical values of
321 // the position coordinates.
322 // It only specifies their numerical meaning.
330 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
333 ///////////////////////////////////////////////////////////////////////////
334 Float_t AliPosition::GetUnitScale() const
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.
341 ///////////////////////////////////////////////////////////////////////////
342 void AliPosition::SetTimestamp(AliTimestamp& t)
344 // Store the timestamp for this position.
345 if (fTstamp) delete fTstamp;
346 fTstamp=new AliTimestamp(t);
348 ///////////////////////////////////////////////////////////////////////////
349 AliTimestamp* AliPosition::GetTimestamp()
351 // Provide the timestamp of this position.
354 ///////////////////////////////////////////////////////////////////////////
355 void AliPosition::RemoveTimestamp()
357 // Remove the timestamp from this postion.
364 ///////////////////////////////////////////////////////////////////////////
365 void AliPosition::Data(TString f,TString u) const
367 // Provide all position/time information within the coordinate frame f.
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
374 // The defaults are f="car" and u="rad".
376 Ali3Vector::Data(f,u);
377 cout << " Metric unit : " << fScale << " meter" << endl;
378 if (fTstamp) fTstamp->Date(1);
380 ///////////////////////////////////////////////////////////////////////////