]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliPosition.cxx
Additional protection
[u/mrichter/AliRoot.git] / RALICE / AliPosition.cxx
CommitLineData
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.
51// By default the unit scale is set to cm, corresponding to invokation
52// of SetUnitScale(0.01).
53//
54//
959fbac5 55// Example :
56// ---------
57//
58// AliPosition q;
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];
1f241680 64// q.GetPosition(loc,"sph","deg");
65// q.GetPositionErrors(dloc,"sph","deg");
959fbac5 66//
67//--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
f531a546 68//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 69///////////////////////////////////////////////////////////////////////////
70
d88f97cc 71#include "AliPosition.h"
c72198f1 72#include "Riostream.h"
d88f97cc 73
74ClassImp(AliPosition) // Class implementation to enable ROOT I/O
75
76AliPosition::AliPosition()
77{
261c0caf 78// Creation of an AliPosition object and initialisation of parameters.
79// The unit scale for position coordinates is initialised to cm.
80 fScale=0.01;
a7dc0627 81 fTstamp=0;
d88f97cc 82}
83///////////////////////////////////////////////////////////////////////////
84AliPosition::~AliPosition()
85{
86// Destructor to delete dynamically allocated memory
a7dc0627 87 if (fTstamp)
88 {
89 delete fTstamp;
90 fTstamp=0;
91 }
d88f97cc 92}
93///////////////////////////////////////////////////////////////////////////
c72198f1 94AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
95{
96// Copy constructor
261c0caf 97 fScale=p.fScale;
f4d1f676 98 fTstamp=0;
a7dc0627 99 if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
c72198f1 100}
101///////////////////////////////////////////////////////////////////////////
1f241680 102void AliPosition::SetPosition(Double_t* r,TString f,TString u)
d88f97cc 103{
104// Store position according to reference frame f
1f241680 105//
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
110//
111// The default is u="rad".
112
113 SetVector(r,f,u);
d88f97cc 114}
115///////////////////////////////////////////////////////////////////////////
1f241680 116void AliPosition::GetPosition(Double_t* r,TString f,TString u) const
d88f97cc 117{
118// Provide position according to reference frame f
1f241680 119//
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
124//
125// The default is u="rad".
126
127 GetVector(r,f,u);
d88f97cc 128}
129///////////////////////////////////////////////////////////////////////////
1f241680 130void AliPosition::SetPosition(Float_t* r,TString f,TString u)
d88f97cc 131{
132// Store position according to reference frame f
1f241680 133//
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
138//
139// The default is u="rad".
140
141 SetVector(r,f,u);
d88f97cc 142}
143///////////////////////////////////////////////////////////////////////////
1f241680 144void AliPosition::GetPosition(Float_t* r,TString f,TString u) const
d88f97cc 145{
146// Provide position according to reference frame f
1f241680 147//
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
152//
153// The default is u="rad".
154
155 GetVector(r,f,u);
d88f97cc 156}
157///////////////////////////////////////////////////////////////////////////
158AliPosition& AliPosition::GetPosition()
159{
160// Provide position
161 return (*this);
162}
163///////////////////////////////////////////////////////////////////////////
164void AliPosition::SetPosition(Ali3Vector& r)
165{
166// Set position
167 Double_t a[3];
168 r.GetVector(a,"sph");
169 SetVector(a,"sph");
959fbac5 170 r.GetErrors(a,"car");
171 SetErrors(a,"car");
172}
173///////////////////////////////////////////////////////////////////////////
1f241680 174void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
959fbac5 175{
176// Store position errors according to reference frame f
1f241680 177//
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
182//
183// The default is u="rad".
184
185 SetErrors(r,f,u);
959fbac5 186}
187///////////////////////////////////////////////////////////////////////////
1f241680 188void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u) const
959fbac5 189{
190// Provide position errors according to reference frame f
1f241680 191//
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
196//
197// The default is u="rad".
198
199 GetErrors(r,f,u);
959fbac5 200}
201///////////////////////////////////////////////////////////////////////////
1f241680 202void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
959fbac5 203{
204// Store position errors according to reference frame f
1f241680 205//
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
210//
211// The default is u="rad".
212
213 SetErrors(r,f,u);
959fbac5 214}
215///////////////////////////////////////////////////////////////////////////
1f241680 216void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u) const
959fbac5 217{
218// Provide position errors according to reference frame f
1f241680 219//
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
224//
225// The default is u="rad".
226
227 GetErrors(r,f,u);
d88f97cc 228}
229///////////////////////////////////////////////////////////////////////////
1c01b4f8 230void AliPosition::ResetPosition()
231{
232// Reset the position and corresponding errors to 0.
233 Double_t r[3]={0,0,0};
234 SetVector(r,"sph");
235 SetErrors(r,"car");
236}
237///////////////////////////////////////////////////////////////////////////
43bfa5be 238Double_t AliPosition::GetDistance(AliPosition& p)
239{
261c0caf 240// Provide distance of the current AliPosition to position p.
43bfa5be 241// The error on the result can be obtained as usual by invoking
242// GetResultError() afterwards.
261c0caf 243//
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.
251//
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);
256 d=d-q;
43bfa5be 257 Double_t dist=d.GetNorm();
258 fDresult=d.GetResultError();
259 return dist;
260}
261///////////////////////////////////////////////////////////////////////////
261c0caf 262void AliPosition::SetUnitScale(Float_t s)
263{
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.
270//
271// Note : This memberfunction does not modify the numerical values of
272// the position coordinates.
273// It only specifies their numerical meaning.
274//
275 if (s>0.)
276 {
277 fScale=s;
278 }
279 else
280 {
281 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
282 }
283}
284///////////////////////////////////////////////////////////////////////////
285Float_t AliPosition::GetUnitScale() const
286{
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.
290 return fScale;
291}
292///////////////////////////////////////////////////////////////////////////
a7dc0627 293void AliPosition::SetTimestamp(AliTimestamp& t)
294{
295// Store the timestamp for this position.
296 if (fTstamp) delete fTstamp;
297 fTstamp=new AliTimestamp(t);
298}
299///////////////////////////////////////////////////////////////////////////
300AliTimestamp* AliPosition::GetTimestamp()
301{
302// Provide the timestamp of this position.
303 return fTstamp;
304}
305///////////////////////////////////////////////////////////////////////////
306void AliPosition::RemoveTimestamp()
307{
308// Remove the timestamp from this postion.
309 if (fTstamp)
310 {
311 delete fTstamp;
312 fTstamp=0;
313 }
314}
315///////////////////////////////////////////////////////////////////////////
1f241680 316void AliPosition::Data(TString f,TString u) const
a7dc0627 317{
318// Provide all position/time information within the coordinate frame f.
1f241680 319//
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
324//
325// The defaults are f="car" and u="rad".
326
327 Ali3Vector::Data(f,u);
a7dc0627 328 if (fTstamp) fTstamp->Date(1);
329}
330///////////////////////////////////////////////////////////////////////////