]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliPosition.cxx
AliITSgeom taken from AliITSLoader
[u/mrichter/AliRoot.git] / RALICE / AliPosition.cxx
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
16 // $Id$
17
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 // ------
27 // Positions (r), errors (e), reference frames (f) and angular units (u)
28 // are specified via
29 //
30 //    SetPosition(Float_t* r,TString f,TString u)
31 //    SetPositionErrors(Float_t* e,TString f,TString u)
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 //
39 // u="rad" ==> angles in radians
40 // u="deg" ==> angles in degrees
41 //
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
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 //
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];
64 // q.GetPosition(loc,"sph","deg");
65 // q.GetPositionErrors(dloc,"sph","deg");
66 //
67 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
68 //- Modified: NvE $Date$ UU-SAP Utrecht
69 ///////////////////////////////////////////////////////////////////////////
70
71 #include "AliPosition.h"
72 #include "Riostream.h"
73  
74 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
75  
76 AliPosition::AliPosition()
77 {
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;
81  fTstamp=0;
82 }
83 ///////////////////////////////////////////////////////////////////////////
84 AliPosition::~AliPosition()
85 {
86 // Destructor to delete dynamically allocated memory
87  if (fTstamp)
88  {
89   delete fTstamp;
90   fTstamp=0;
91  }
92 }
93 ///////////////////////////////////////////////////////////////////////////
94 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
95 {
96 // Copy constructor
97  fScale=p.fScale;
98  fTstamp=0;
99  if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
100 }
101 ///////////////////////////////////////////////////////////////////////////
102 void AliPosition::SetPosition(Double_t* r,TString f,TString u)
103 {
104 // Store position according to reference frame f
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);
114 }
115 ///////////////////////////////////////////////////////////////////////////
116 void AliPosition::GetPosition(Double_t* r,TString f,TString u) const
117 {
118 // Provide position according to reference frame f
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);
128 }
129 ///////////////////////////////////////////////////////////////////////////
130 void AliPosition::SetPosition(Float_t* r,TString f,TString u)
131 {
132 // Store position according to reference frame f
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);
142 }
143 ///////////////////////////////////////////////////////////////////////////
144 void AliPosition::GetPosition(Float_t* r,TString f,TString u) const
145 {
146 // Provide position according to reference frame f
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);
156 }
157 ///////////////////////////////////////////////////////////////////////////
158 AliPosition& AliPosition::GetPosition()
159 {
160 // Provide position
161  return (*this);
162 }
163 ///////////////////////////////////////////////////////////////////////////
164 void AliPosition::SetPosition(Ali3Vector& r)
165 {
166 // Set position
167  Double_t a[3];
168  r.GetVector(a,"sph");
169  SetVector(a,"sph");
170  r.GetErrors(a,"car");
171  SetErrors(a,"car");
172 }
173 ///////////////////////////////////////////////////////////////////////////
174 void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
175 {
176 // Store position errors according to reference frame f
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);
186 }
187 ///////////////////////////////////////////////////////////////////////////
188 void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u) const
189 {
190 // Provide position errors according to reference frame f
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);
200 }
201 ///////////////////////////////////////////////////////////////////////////
202 void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
203 {
204 // Store position errors according to reference frame f
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);
214 }
215 ///////////////////////////////////////////////////////////////////////////
216 void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u) const
217 {
218 // Provide position errors according to reference frame f
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);
228 }
229 ///////////////////////////////////////////////////////////////////////////
230 void 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 ///////////////////////////////////////////////////////////////////////////
238 Double_t AliPosition::GetDistance(AliPosition& p)
239 {
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. 
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;
257  Double_t dist=d.GetNorm();
258  fDresult=d.GetResultError();
259  return dist;
260 }
261 ///////////////////////////////////////////////////////////////////////////
262 void 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 ///////////////////////////////////////////////////////////////////////////
285 Float_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 ///////////////////////////////////////////////////////////////////////////
293 void AliPosition::SetTimestamp(AliTimestamp& t)
294 {
295 // Store the timestamp for this position.
296  if (fTstamp) delete fTstamp;
297  fTstamp=new AliTimestamp(t);
298 }
299 ///////////////////////////////////////////////////////////////////////////
300 AliTimestamp* AliPosition::GetTimestamp()
301 {
302 // Provide the timestamp of this position.
303  return fTstamp;
304 }
305 ///////////////////////////////////////////////////////////////////////////
306 void AliPosition::RemoveTimestamp()
307 {
308 // Remove the timestamp from this postion.
309  if (fTstamp)
310  {
311   delete fTstamp;
312   fTstamp=0;
313  }
314 }
315 ///////////////////////////////////////////////////////////////////////////
316 void AliPosition::Data(TString f,TString u) const
317 {
318 // Provide all position/time information within the coordinate frame f.
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);
328  if (fTstamp) fTstamp->Date(1);
329
330 ///////////////////////////////////////////////////////////////////////////