]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliPosition.cxx
Pedestals in OCDB + minors
[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 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.
56 //   
57 //
58 // Example :
59 // ---------
60 //
61 // AliPosition q;
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");
69 //
70 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
71 //- Modified: NvE $Date$ UU-SAP Utrecht
72 ///////////////////////////////////////////////////////////////////////////
73
74 #include "AliPosition.h"
75 #include "Riostream.h"
76  
77 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
78  
79 AliPosition::AliPosition()
80 {
81 // Creation of an AliPosition object and initialisation of parameters.
82 // The unit scale for position coordinates is initialised to cm.
83  fScale=1;
84  fTstamp=0;
85 }
86 ///////////////////////////////////////////////////////////////////////////
87 AliPosition::~AliPosition()
88 {
89 // Destructor to delete dynamically allocated memory
90  if (fTstamp)
91  {
92   delete fTstamp;
93   fTstamp=0;
94  }
95 }
96 ///////////////////////////////////////////////////////////////////////////
97 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
98 {
99 // Copy constructor
100  fScale=p.fScale;
101  fTstamp=0;
102  if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
103 }
104 ///////////////////////////////////////////////////////////////////////////
105 void AliPosition::SetPosition(Double_t* r,TString f,TString u)
106 {
107 // Store position according to reference frame f
108 //
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
113 //
114 // The default is u="rad".
115
116  SetVector(r,f,u);
117 }
118 ///////////////////////////////////////////////////////////////////////////
119 void AliPosition::GetPosition(Double_t* r,TString f,TString u,Float_t scale) const
120 {
121 // Provide position according to reference frame f
122 //
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
127 //
128 // The default is u="rad".
129 //
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.
136
137  Ali3Vector v=(Ali3Vector)(*this);
138  if (scale>0) v*=fScale/scale;
139  v.GetVector(r,f,u);
140 }
141 ///////////////////////////////////////////////////////////////////////////
142 void AliPosition::SetPosition(Float_t* r,TString f,TString u)
143 {
144 // Store position according to reference frame f
145 //
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
150 //
151 // The default is u="rad".
152
153  SetVector(r,f,u);
154 }
155 ///////////////////////////////////////////////////////////////////////////
156 void AliPosition::GetPosition(Float_t* r,TString f,TString u,Float_t scale) const
157 {
158 // Provide position according to reference frame f
159 //
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
164 //
165 // The default is u="rad".
166 //
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.
173
174  Ali3Vector v=(Ali3Vector)(*this);
175  if (scale>0) v*=fScale/scale;
176  v.GetVector(r,f,u);
177 }
178 ///////////////////////////////////////////////////////////////////////////
179 AliPosition& AliPosition::GetPosition()
180 {
181 // Provide position
182  return (*this);
183 }
184 ///////////////////////////////////////////////////////////////////////////
185 void AliPosition::SetPosition(Ali3Vector& r)
186 {
187 // Set position
188  Double_t a[3];
189  r.GetVector(a,"sph");
190  SetVector(a,"sph");
191  r.GetErrors(a,"car");
192  SetErrors(a,"car");
193 }
194 ///////////////////////////////////////////////////////////////////////////
195 void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
196 {
197 // Store position errors according to reference frame f
198 //
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
203 //
204 // The default is u="rad".
205
206  SetErrors(r,f,u);
207 }
208 ///////////////////////////////////////////////////////////////////////////
209 void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u,Float_t scale) const
210 {
211 // Provide position errors according to reference frame f
212 //
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
217 //
218 // The default is u="rad".
219 //
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.
226
227  Ali3Vector v=(Ali3Vector)(*this);
228  if (scale>0) v*=fScale/scale;
229  v.GetErrors(r,f,u);
230 }
231 ///////////////////////////////////////////////////////////////////////////
232 void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
233 {
234 // Store position errors according to reference frame f
235 //
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
240 //
241 // The default is u="rad".
242
243  SetErrors(r,f,u);
244 }
245 ///////////////////////////////////////////////////////////////////////////
246 void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u,Float_t scale) const
247 {
248 // Provide position errors according to reference frame f
249 //
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
254 //
255 // The default is u="rad".
256 //
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.
263
264  Ali3Vector v=(Ali3Vector)(*this);
265  if (scale>0) v*=fScale/scale;
266  v.GetErrors(r,f,u);
267 }
268 ///////////////////////////////////////////////////////////////////////////
269 void AliPosition::ResetPosition()
270 {
271 // Reset the position and corresponding errors to 0.
272  Double_t r[3]={0,0,0};
273  SetVector(r,"sph");
274  SetErrors(r,"car");
275 }
276 ///////////////////////////////////////////////////////////////////////////
277 Double_t AliPosition::GetDistance(AliPosition& p,Float_t scale)
278 {
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. 
282 //
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.
294 //
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);
299  d=d-q;
300  Double_t dist=d.GetNorm();
301  fDresult=d.GetResultError();
302
303  if (scale>0)
304  {
305   dist*=fScale/scale;
306   fDresult*=fScale/scale;
307  }
308  return dist;
309 }
310 ///////////////////////////////////////////////////////////////////////////
311 void AliPosition::SetUnitScale(Float_t s)
312 {
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.
319 //
320 // Note : This memberfunction does not modify the numerical values of
321 //        the position coordinates.
322 //        It only specifies their numerical meaning.
323 // 
324  if (s>0.)
325  {
326   fScale=s;
327  }
328  else
329  {
330   cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
331  }
332 }
333 ///////////////////////////////////////////////////////////////////////////
334 Float_t AliPosition::GetUnitScale() const
335 {
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.
339  return fScale;
340 }
341 ///////////////////////////////////////////////////////////////////////////
342 void AliPosition::SetTimestamp(AliTimestamp& t)
343 {
344 // Store the timestamp for this position.
345  if (fTstamp) delete fTstamp;
346  fTstamp=new AliTimestamp(t);
347 }
348 ///////////////////////////////////////////////////////////////////////////
349 AliTimestamp* AliPosition::GetTimestamp()
350 {
351 // Provide the timestamp of this position.
352  return fTstamp;
353 }
354 ///////////////////////////////////////////////////////////////////////////
355 void AliPosition::RemoveTimestamp()
356 {
357 // Remove the timestamp from this postion.
358  if (fTstamp)
359  {
360   delete fTstamp;
361   fTstamp=0;
362  }
363 }
364 ///////////////////////////////////////////////////////////////////////////
365 void AliPosition::Data(TString f,TString u) const
366 {
367 // Provide all position/time information within the coordinate frame f.
368 //
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
373 //
374 // The defaults are f="car" and u="rad".
375
376  Ali3Vector::Data(f,u);
377  cout << "   Metric unit : " << fScale << " meter" << endl;
378  if (fTstamp) fTstamp->Date(1);
379
380 ///////////////////////////////////////////////////////////////////////////