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 cm, corresponding to invokation
52 // of SetUnitScale(0.01).
59 // Float_t pos[3]={-1,25,7};
60 // Float_t err[3]={0.08,1.85,0.5};
61 // q.SetPosition(pos,"car");
62 // q.SetPositionErrors(pos,"car");
63 // Float_t loc[3],dloc[3];
64 // q.GetPosition(loc,"sph","deg");
65 // q.GetPositionErrors(dloc,"sph","deg");
67 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
68 //- Modified: NvE $Date$ UU-SAP Utrecht
69 ///////////////////////////////////////////////////////////////////////////
71 #include "AliPosition.h"
72 #include "Riostream.h"
74 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
76 AliPosition::AliPosition()
78 // Creation of an AliPosition object and initialisation of parameters.
79 // The unit scale for position coordinates is initialised to cm.
83 ///////////////////////////////////////////////////////////////////////////
84 AliPosition::~AliPosition()
86 // Destructor to delete dynamically allocated memory
93 ///////////////////////////////////////////////////////////////////////////
94 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
99 if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
101 ///////////////////////////////////////////////////////////////////////////
102 void AliPosition::SetPosition(Double_t* r,TString f,TString u)
104 // Store position according to reference frame f
106 // The string argument "u" allows to choose between different angular units
107 // in case e.g. a spherical frame is selected.
108 // u = "rad" : angles provided in radians
109 // "deg" : angles provided in degrees
111 // The default is u="rad".
115 ///////////////////////////////////////////////////////////////////////////
116 void AliPosition::GetPosition(Double_t* r,TString f,TString u) const
118 // Provide position according to reference frame f
120 // The string argument "u" allows to choose between different angular units
121 // in case e.g. a spherical frame is selected.
122 // u = "rad" : angles provided in radians
123 // "deg" : angles provided in degrees
125 // The default is u="rad".
129 ///////////////////////////////////////////////////////////////////////////
130 void AliPosition::SetPosition(Float_t* r,TString f,TString u)
132 // Store position according to reference frame f
134 // The string argument "u" allows to choose between different angular units
135 // in case e.g. a spherical frame is selected.
136 // u = "rad" : angles provided in radians
137 // "deg" : angles provided in degrees
139 // The default is u="rad".
143 ///////////////////////////////////////////////////////////////////////////
144 void AliPosition::GetPosition(Float_t* r,TString f,TString u) const
146 // Provide position according to reference frame f
148 // The string argument "u" allows to choose between different angular units
149 // in case e.g. a spherical frame is selected.
150 // u = "rad" : angles provided in radians
151 // "deg" : angles provided in degrees
153 // The default is u="rad".
157 ///////////////////////////////////////////////////////////////////////////
158 AliPosition& AliPosition::GetPosition()
163 ///////////////////////////////////////////////////////////////////////////
164 void AliPosition::SetPosition(Ali3Vector& r)
168 r.GetVector(a,"sph");
170 r.GetErrors(a,"car");
173 ///////////////////////////////////////////////////////////////////////////
174 void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
176 // Store position errors according to reference frame f
178 // The string argument "u" allows to choose between different angular units
179 // in case e.g. a spherical frame is selected.
180 // u = "rad" : angles provided in radians
181 // "deg" : angles provided in degrees
183 // The default is u="rad".
187 ///////////////////////////////////////////////////////////////////////////
188 void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u) const
190 // Provide position errors according to reference frame f
192 // The string argument "u" allows to choose between different angular units
193 // in case e.g. a spherical frame is selected.
194 // u = "rad" : angles provided in radians
195 // "deg" : angles provided in degrees
197 // The default is u="rad".
201 ///////////////////////////////////////////////////////////////////////////
202 void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
204 // Store position errors according to reference frame f
206 // The string argument "u" allows to choose between different angular units
207 // in case e.g. a spherical frame is selected.
208 // u = "rad" : angles provided in radians
209 // "deg" : angles provided in degrees
211 // The default is u="rad".
215 ///////////////////////////////////////////////////////////////////////////
216 void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u) const
218 // Provide position errors according to reference frame f
220 // The string argument "u" allows to choose between different angular units
221 // in case e.g. a spherical frame is selected.
222 // u = "rad" : angles provided in radians
223 // "deg" : angles provided in degrees
225 // The default is u="rad".
229 ///////////////////////////////////////////////////////////////////////////
230 void AliPosition::ResetPosition()
232 // Reset the position and corresponding errors to 0.
233 Double_t r[3]={0,0,0};
237 ///////////////////////////////////////////////////////////////////////////
238 Double_t AliPosition::GetDistance(AliPosition& p)
240 // Provide distance of the current AliPosition to position p.
241 // The error on the result can be obtained as usual by invoking
242 // GetResultError() afterwards.
244 // In the case of two positions with different unit scales, the distance
245 // will be provided in the unit scale of the current AliPosition.
246 // This implies that in such cases the results of r.GetDistance(q) and
247 // q.GetDistance(r) will be numerically different.
248 // As such it is possible to obtain a correctly computed distance between
249 // positions which have different unit scales.
250 // However, it is recommended to work always with one single unit scale.
252 Ali3Vector d=(Ali3Vector)p;
253 Float_t pscale=p.GetUnitScale();
254 if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale);
255 Ali3Vector q=(Ali3Vector)(*this);
257 Double_t dist=d.GetNorm();
258 fDresult=d.GetResultError();
261 ///////////////////////////////////////////////////////////////////////////
262 void AliPosition::SetUnitScale(Float_t s)
264 // Set the unit scale for the position coordinates.
265 // The scale is normalised w.r.t. the meter, so setting the unit scale
266 // to 0.01 means that all position coordinates are in cm.
267 // By default the unit scale is set to cm in the AliPosition constructor.
268 // It is recommended to use one single unit scale throughout a complete
269 // analysis and/or simulation project.
271 // Note : This memberfunction does not modify the numerical values of
272 // the position coordinates.
273 // It only specifies their numerical meaning.
281 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
284 ///////////////////////////////////////////////////////////////////////////
285 Float_t AliPosition::GetUnitScale() const
287 // Provide the unit scale for the position coordinates.
288 // The scale is normalised w.r.t. the meter, so a unit scale of 0.01
289 // means that all position coordinates are in cm.
292 ///////////////////////////////////////////////////////////////////////////
293 void AliPosition::SetTimestamp(AliTimestamp& t)
295 // Store the timestamp for this position.
296 if (fTstamp) delete fTstamp;
297 fTstamp=new AliTimestamp(t);
299 ///////////////////////////////////////////////////////////////////////////
300 AliTimestamp* AliPosition::GetTimestamp()
302 // Provide the timestamp of this position.
305 ///////////////////////////////////////////////////////////////////////////
306 void AliPosition::RemoveTimestamp()
308 // Remove the timestamp from this postion.
315 ///////////////////////////////////////////////////////////////////////////
316 void AliPosition::Data(TString f,TString u) const
318 // Provide all position/time information within the coordinate frame f.
320 // The string argument "u" allows to choose between different angular units
321 // in case e.g. a spherical frame is selected.
322 // u = "rad" : angles provided in radians
323 // "deg" : angles provided in degrees
325 // The defaults are f="car" and u="rad".
327 Ali3Vector::Data(f,u);
328 if (fTstamp) fTstamp->Date(1);
330 ///////////////////////////////////////////////////////////////////////////