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) and reference frames (f) are specified via
29 // SetPosition(Float_t* r,TString f)
30 // SetPositionErrors(Float_t* e,TString f)
32 // under the following conventions :
34 // f="car" ==> r in Cartesian coordinates (x,y,z)
35 // f="sph" ==> r in Spherical coordinates (r,theta,phi)
36 // f="cyl" ==> r in Cylindrical coordinates (rho,phi,z)
38 // All angles are in radians.
40 // The unit scale for the coordinates can be defined by the user
41 // via the SetUnitScale() memberfunction.
42 // This enables standardised expressions using numerical values of
43 // physical constants by means of the GetUnitScale() memberfunction.
44 // By default the unit scale is set to cm, corresponding to invokation
45 // of SetUnitScale(0.01).
52 // Float_t pos[3]={-1,25,7};
53 // Float_t err[3]={0.08,1.85,0.5};
54 // q.SetPosition(pos,"car");
55 // q.SetPositionErrors(pos,"car");
56 // Float_t loc[3],dloc[3];
57 // q.GetPosition(loc,"sph");
58 // q.GetPositionErrors(dloc,"sph");
60 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
61 //- Modified: NvE $Date$ UU-SAP Utrecht
62 ///////////////////////////////////////////////////////////////////////////
64 #include "AliPosition.h"
65 #include "Riostream.h"
67 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
69 AliPosition::AliPosition()
71 // Creation of an AliPosition object and initialisation of parameters.
72 // The unit scale for position coordinates is initialised to cm.
76 ///////////////////////////////////////////////////////////////////////////
77 AliPosition::~AliPosition()
79 // Destructor to delete dynamically allocated memory
86 ///////////////////////////////////////////////////////////////////////////
87 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
91 if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
93 ///////////////////////////////////////////////////////////////////////////
94 void AliPosition::SetPosition(Double_t* r,TString f)
96 // Store position according to reference frame f
99 ///////////////////////////////////////////////////////////////////////////
100 void AliPosition::GetPosition(Double_t* r,TString f) const
102 // Provide position according to reference frame f
105 ///////////////////////////////////////////////////////////////////////////
106 void AliPosition::SetPosition(Float_t* r,TString f)
108 // Store position according to reference frame f
111 ///////////////////////////////////////////////////////////////////////////
112 void AliPosition::GetPosition(Float_t* r,TString f) const
114 // Provide position according to reference frame f
117 ///////////////////////////////////////////////////////////////////////////
118 AliPosition& AliPosition::GetPosition()
123 ///////////////////////////////////////////////////////////////////////////
124 void AliPosition::SetPosition(Ali3Vector& r)
128 r.GetVector(a,"sph");
130 r.GetErrors(a,"car");
133 ///////////////////////////////////////////////////////////////////////////
134 void AliPosition::SetPositionErrors(Double_t* r,TString f)
136 // Store position errors according to reference frame f
139 ///////////////////////////////////////////////////////////////////////////
140 void AliPosition::GetPositionErrors(Double_t* r,TString f) const
142 // Provide position errors according to reference frame f
145 ///////////////////////////////////////////////////////////////////////////
146 void AliPosition::SetPositionErrors(Float_t* r,TString f)
148 // Store position errors according to reference frame f
151 ///////////////////////////////////////////////////////////////////////////
152 void AliPosition::GetPositionErrors(Float_t* r,TString f) const
154 // Provide position errors according to reference frame f
157 ///////////////////////////////////////////////////////////////////////////
158 void AliPosition::ResetPosition()
160 // Reset the position and corresponding errors to 0.
161 Double_t r[3]={0,0,0};
165 ///////////////////////////////////////////////////////////////////////////
166 Double_t AliPosition::GetDistance(AliPosition& p)
168 // Provide distance of the current AliPosition to position p.
169 // The error on the result can be obtained as usual by invoking
170 // GetResultError() afterwards.
172 // In the case of two positions with different unit scales, the distance
173 // will be provided in the unit scale of the current AliPosition.
174 // This implies that in such cases the results of r.GetDistance(q) and
175 // q.GetDistance(r) will be numerically different.
176 // As such it is possible to obtain a correctly computed distance between
177 // positions which have different unit scales.
178 // However, it is recommended to work always with one single unit scale.
180 Ali3Vector d=(Ali3Vector)p;
181 Float_t pscale=p.GetUnitScale();
182 if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale);
183 Ali3Vector q=(Ali3Vector)(*this);
185 Double_t dist=d.GetNorm();
186 fDresult=d.GetResultError();
189 ///////////////////////////////////////////////////////////////////////////
190 void AliPosition::SetUnitScale(Float_t s)
192 // Set the unit scale for the position coordinates.
193 // The scale is normalised w.r.t. the meter, so setting the unit scale
194 // to 0.01 means that all position coordinates are in cm.
195 // By default the unit scale is set to cm in the AliPosition constructor.
196 // It is recommended to use one single unit scale throughout a complete
197 // analysis and/or simulation project.
199 // Note : This memberfunction does not modify the numerical values of
200 // the position coordinates.
201 // It only specifies their numerical meaning.
209 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
212 ///////////////////////////////////////////////////////////////////////////
213 Float_t AliPosition::GetUnitScale() const
215 // Provide the unit scale for the position coordinates.
216 // The scale is normalised w.r.t. the meter, so a unit scale of 0.01
217 // means that all position coordinates are in cm.
220 ///////////////////////////////////////////////////////////////////////////
221 void AliPosition::SetTimestamp(AliTimestamp& t)
223 // Store the timestamp for this position.
224 if (fTstamp) delete fTstamp;
225 fTstamp=new AliTimestamp(t);
227 ///////////////////////////////////////////////////////////////////////////
228 AliTimestamp* AliPosition::GetTimestamp()
230 // Provide the timestamp of this position.
233 ///////////////////////////////////////////////////////////////////////////
234 void AliPosition::RemoveTimestamp()
236 // Remove the timestamp from this postion.
243 ///////////////////////////////////////////////////////////////////////////
244 void AliPosition::Data(TString f) const
246 // Provide all position/time information within the coordinate frame f.
248 if (fTstamp) fTstamp->Date(1);
250 ///////////////////////////////////////////////////////////////////////////