]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliPosition.cxx
10-may-2005 NvE Support for timestamps introduced in AliTrack and AliPosition.
[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) and reference frames (f) are specified via
28 //
29 //    SetPosition(Float_t* r,TString f)
30 //    SetPositionErrors(Float_t* e,TString f)
31 //
32 // under the following conventions :
33 //
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)
37 //
38 // All angles are in radians.
39 //
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).
46 //   
47 //
48 // Example :
49 // ---------
50 //
51 // AliPosition q;
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");
59 //
60 //--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
61 //- Modified: NvE $Date$ UU-SAP Utrecht
62 ///////////////////////////////////////////////////////////////////////////
63
64 #include "AliPosition.h"
65 #include "Riostream.h"
66  
67 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
68  
69 AliPosition::AliPosition()
70 {
71 // Creation of an AliPosition object and initialisation of parameters.
72 // The unit scale for position coordinates is initialised to cm.
73  fScale=0.01;
74  fTstamp=0;
75 }
76 ///////////////////////////////////////////////////////////////////////////
77 AliPosition::~AliPosition()
78 {
79 // Destructor to delete dynamically allocated memory
80  if (fTstamp)
81  {
82   delete fTstamp;
83   fTstamp=0;
84  }
85 }
86 ///////////////////////////////////////////////////////////////////////////
87 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
88 {
89 // Copy constructor
90  fScale=p.fScale;
91  if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
92 }
93 ///////////////////////////////////////////////////////////////////////////
94 void AliPosition::SetPosition(Double_t* r,TString f)
95 {
96 // Store position according to reference frame f
97  SetVector(r,f);
98 }
99 ///////////////////////////////////////////////////////////////////////////
100 void AliPosition::GetPosition(Double_t* r,TString f) const
101 {
102 // Provide position according to reference frame f
103  GetVector(r,f);
104 }
105 ///////////////////////////////////////////////////////////////////////////
106 void AliPosition::SetPosition(Float_t* r,TString f)
107 {
108 // Store position according to reference frame f
109  SetVector(r,f);
110 }
111 ///////////////////////////////////////////////////////////////////////////
112 void AliPosition::GetPosition(Float_t* r,TString f) const
113 {
114 // Provide position according to reference frame f
115  GetVector(r,f);
116 }
117 ///////////////////////////////////////////////////////////////////////////
118 AliPosition& AliPosition::GetPosition()
119 {
120 // Provide position
121  return (*this);
122 }
123 ///////////////////////////////////////////////////////////////////////////
124 void AliPosition::SetPosition(Ali3Vector& r)
125 {
126 // Set position
127  Double_t a[3];
128  r.GetVector(a,"sph");
129  SetVector(a,"sph");
130  r.GetErrors(a,"car");
131  SetErrors(a,"car");
132 }
133 ///////////////////////////////////////////////////////////////////////////
134 void AliPosition::SetPositionErrors(Double_t* r,TString f)
135 {
136 // Store position errors according to reference frame f
137  SetErrors(r,f);
138 }
139 ///////////////////////////////////////////////////////////////////////////
140 void AliPosition::GetPositionErrors(Double_t* r,TString f) const
141 {
142 // Provide position errors according to reference frame f
143  GetErrors(r,f);
144 }
145 ///////////////////////////////////////////////////////////////////////////
146 void AliPosition::SetPositionErrors(Float_t* r,TString f)
147 {
148 // Store position errors according to reference frame f
149  SetErrors(r,f);
150 }
151 ///////////////////////////////////////////////////////////////////////////
152 void AliPosition::GetPositionErrors(Float_t* r,TString f) const
153 {
154 // Provide position errors according to reference frame f
155  GetErrors(r,f);
156 }
157 ///////////////////////////////////////////////////////////////////////////
158 void AliPosition::ResetPosition()
159 {
160 // Reset the position and corresponding errors to 0.
161  Double_t r[3]={0,0,0};
162  SetVector(r,"sph");
163  SetErrors(r,"car");
164 }
165 ///////////////////////////////////////////////////////////////////////////
166 Double_t AliPosition::GetDistance(AliPosition& p)
167 {
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. 
171 //
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.
179 //
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);
184  d=d-q;
185  Double_t dist=d.GetNorm();
186  fDresult=d.GetResultError();
187  return dist;
188 }
189 ///////////////////////////////////////////////////////////////////////////
190 void AliPosition::SetUnitScale(Float_t s)
191 {
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.
198 //
199 // Note : This memberfunction does not modify the numerical values of
200 //        the position coordinates.
201 //        It only specifies their numerical meaning.
202 // 
203  if (s>0.)
204  {
205   fScale=s;
206  }
207  else
208  {
209   cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
210  }
211 }
212 ///////////////////////////////////////////////////////////////////////////
213 Float_t AliPosition::GetUnitScale() const
214 {
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.
218  return fScale;
219 }
220 ///////////////////////////////////////////////////////////////////////////
221 void AliPosition::SetTimestamp(AliTimestamp& t)
222 {
223 // Store the timestamp for this position.
224  if (fTstamp) delete fTstamp;
225  fTstamp=new AliTimestamp(t);
226 }
227 ///////////////////////////////////////////////////////////////////////////
228 AliTimestamp* AliPosition::GetTimestamp()
229 {
230 // Provide the timestamp of this position.
231  return fTstamp;
232 }
233 ///////////////////////////////////////////////////////////////////////////
234 void AliPosition::RemoveTimestamp()
235 {
236 // Remove the timestamp from this postion.
237  if (fTstamp)
238  {
239   delete fTstamp;
240   fTstamp=0;
241  }
242 }
243 ///////////////////////////////////////////////////////////////////////////
244 void AliPosition::Data(TString f) const
245 {
246 // Provide all position/time information within the coordinate frame f.
247  Ali3Vector::Data(f);
248  if (fTstamp) fTstamp->Date(1);
249
250 ///////////////////////////////////////////////////////////////////////////