]>
Commit | Line | Data |
---|---|---|
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 | // ------ | |
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 | // | |
261c0caf | 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 | // | |
959fbac5 | 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 | |
f531a546 | 61 | //- Modified: NvE $Date$ UU-SAP Utrecht |
959fbac5 | 62 | /////////////////////////////////////////////////////////////////////////// |
63 | ||
d88f97cc | 64 | #include "AliPosition.h" |
c72198f1 | 65 | #include "Riostream.h" |
d88f97cc | 66 | |
67 | ClassImp(AliPosition) // Class implementation to enable ROOT I/O | |
68 | ||
69 | AliPosition::AliPosition() | |
70 | { | |
261c0caf | 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; | |
a7dc0627 | 74 | fTstamp=0; |
d88f97cc | 75 | } |
76 | /////////////////////////////////////////////////////////////////////////// | |
77 | AliPosition::~AliPosition() | |
78 | { | |
79 | // Destructor to delete dynamically allocated memory | |
a7dc0627 | 80 | if (fTstamp) |
81 | { | |
82 | delete fTstamp; | |
83 | fTstamp=0; | |
84 | } | |
d88f97cc | 85 | } |
86 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 87 | AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p) |
88 | { | |
89 | // Copy constructor | |
261c0caf | 90 | fScale=p.fScale; |
f4d1f676 | 91 | fTstamp=0; |
a7dc0627 | 92 | if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp)); |
c72198f1 | 93 | } |
94 | /////////////////////////////////////////////////////////////////////////// | |
d88f97cc | 95 | void AliPosition::SetPosition(Double_t* r,TString f) |
96 | { | |
97 | // Store position according to reference frame f | |
98 | SetVector(r,f); | |
99 | } | |
100 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 101 | void AliPosition::GetPosition(Double_t* r,TString f) const |
d88f97cc | 102 | { |
103 | // Provide position according to reference frame f | |
104 | GetVector(r,f); | |
105 | } | |
106 | /////////////////////////////////////////////////////////////////////////// | |
107 | void AliPosition::SetPosition(Float_t* r,TString f) | |
108 | { | |
109 | // Store position according to reference frame f | |
110 | SetVector(r,f); | |
111 | } | |
112 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 113 | void AliPosition::GetPosition(Float_t* r,TString f) const |
d88f97cc | 114 | { |
115 | // Provide position according to reference frame f | |
116 | GetVector(r,f); | |
117 | } | |
118 | /////////////////////////////////////////////////////////////////////////// | |
119 | AliPosition& AliPosition::GetPosition() | |
120 | { | |
121 | // Provide position | |
122 | return (*this); | |
123 | } | |
124 | /////////////////////////////////////////////////////////////////////////// | |
125 | void AliPosition::SetPosition(Ali3Vector& r) | |
126 | { | |
127 | // Set position | |
128 | Double_t a[3]; | |
129 | r.GetVector(a,"sph"); | |
130 | SetVector(a,"sph"); | |
959fbac5 | 131 | r.GetErrors(a,"car"); |
132 | SetErrors(a,"car"); | |
133 | } | |
134 | /////////////////////////////////////////////////////////////////////////// | |
135 | void AliPosition::SetPositionErrors(Double_t* r,TString f) | |
136 | { | |
137 | // Store position errors according to reference frame f | |
138 | SetErrors(r,f); | |
139 | } | |
140 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 141 | void AliPosition::GetPositionErrors(Double_t* r,TString f) const |
959fbac5 | 142 | { |
143 | // Provide position errors according to reference frame f | |
144 | GetErrors(r,f); | |
145 | } | |
146 | /////////////////////////////////////////////////////////////////////////// | |
147 | void AliPosition::SetPositionErrors(Float_t* r,TString f) | |
148 | { | |
149 | // Store position errors according to reference frame f | |
150 | SetErrors(r,f); | |
151 | } | |
152 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 153 | void AliPosition::GetPositionErrors(Float_t* r,TString f) const |
959fbac5 | 154 | { |
155 | // Provide position errors according to reference frame f | |
156 | GetErrors(r,f); | |
d88f97cc | 157 | } |
158 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 159 | void AliPosition::ResetPosition() |
160 | { | |
161 | // Reset the position and corresponding errors to 0. | |
162 | Double_t r[3]={0,0,0}; | |
163 | SetVector(r,"sph"); | |
164 | SetErrors(r,"car"); | |
165 | } | |
166 | /////////////////////////////////////////////////////////////////////////// | |
43bfa5be | 167 | Double_t AliPosition::GetDistance(AliPosition& p) |
168 | { | |
261c0caf | 169 | // Provide distance of the current AliPosition to position p. |
43bfa5be | 170 | // The error on the result can be obtained as usual by invoking |
171 | // GetResultError() afterwards. | |
261c0caf | 172 | // |
173 | // In the case of two positions with different unit scales, the distance | |
174 | // will be provided in the unit scale of the current AliPosition. | |
175 | // This implies that in such cases the results of r.GetDistance(q) and | |
176 | // q.GetDistance(r) will be numerically different. | |
177 | // As such it is possible to obtain a correctly computed distance between | |
178 | // positions which have different unit scales. | |
179 | // However, it is recommended to work always with one single unit scale. | |
180 | // | |
181 | Ali3Vector d=(Ali3Vector)p; | |
182 | Float_t pscale=p.GetUnitScale(); | |
183 | if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale); | |
184 | Ali3Vector q=(Ali3Vector)(*this); | |
185 | d=d-q; | |
43bfa5be | 186 | Double_t dist=d.GetNorm(); |
187 | fDresult=d.GetResultError(); | |
188 | return dist; | |
189 | } | |
190 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 191 | void AliPosition::SetUnitScale(Float_t s) |
192 | { | |
193 | // Set the unit scale for the position coordinates. | |
194 | // The scale is normalised w.r.t. the meter, so setting the unit scale | |
195 | // to 0.01 means that all position coordinates are in cm. | |
196 | // By default the unit scale is set to cm in the AliPosition constructor. | |
197 | // It is recommended to use one single unit scale throughout a complete | |
198 | // analysis and/or simulation project. | |
199 | // | |
200 | // Note : This memberfunction does not modify the numerical values of | |
201 | // the position coordinates. | |
202 | // It only specifies their numerical meaning. | |
203 | // | |
204 | if (s>0.) | |
205 | { | |
206 | fScale=s; | |
207 | } | |
208 | else | |
209 | { | |
210 | cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl; | |
211 | } | |
212 | } | |
213 | /////////////////////////////////////////////////////////////////////////// | |
214 | Float_t AliPosition::GetUnitScale() const | |
215 | { | |
216 | // Provide the unit scale for the position coordinates. | |
217 | // The scale is normalised w.r.t. the meter, so a unit scale of 0.01 | |
218 | // means that all position coordinates are in cm. | |
219 | return fScale; | |
220 | } | |
221 | /////////////////////////////////////////////////////////////////////////// | |
a7dc0627 | 222 | void AliPosition::SetTimestamp(AliTimestamp& t) |
223 | { | |
224 | // Store the timestamp for this position. | |
225 | if (fTstamp) delete fTstamp; | |
226 | fTstamp=new AliTimestamp(t); | |
227 | } | |
228 | /////////////////////////////////////////////////////////////////////////// | |
229 | AliTimestamp* AliPosition::GetTimestamp() | |
230 | { | |
231 | // Provide the timestamp of this position. | |
232 | return fTstamp; | |
233 | } | |
234 | /////////////////////////////////////////////////////////////////////////// | |
235 | void AliPosition::RemoveTimestamp() | |
236 | { | |
237 | // Remove the timestamp from this postion. | |
238 | if (fTstamp) | |
239 | { | |
240 | delete fTstamp; | |
241 | fTstamp=0; | |
242 | } | |
243 | } | |
244 | /////////////////////////////////////////////////////////////////////////// | |
245 | void AliPosition::Data(TString f) const | |
246 | { | |
247 | // Provide all position/time information within the coordinate frame f. | |
248 | Ali3Vector::Data(f); | |
249 | if (fTstamp) fTstamp->Date(1); | |
250 | } | |
251 | /////////////////////////////////////////////////////////////////////////// |