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.
75 ///////////////////////////////////////////////////////////////////////////
76 AliPosition::~AliPosition()
78 // Destructor to delete dynamically allocated memory
80 ///////////////////////////////////////////////////////////////////////////
81 AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
86 ///////////////////////////////////////////////////////////////////////////
87 void AliPosition::SetPosition(Double_t* r,TString f)
89 // Store position according to reference frame f
92 ///////////////////////////////////////////////////////////////////////////
93 void AliPosition::GetPosition(Double_t* r,TString f) const
95 // Provide position according to reference frame f
98 ///////////////////////////////////////////////////////////////////////////
99 void AliPosition::SetPosition(Float_t* r,TString f)
101 // Store position according to reference frame f
104 ///////////////////////////////////////////////////////////////////////////
105 void AliPosition::GetPosition(Float_t* r,TString f) const
107 // Provide position according to reference frame f
110 ///////////////////////////////////////////////////////////////////////////
111 AliPosition& AliPosition::GetPosition()
116 ///////////////////////////////////////////////////////////////////////////
117 void AliPosition::SetPosition(Ali3Vector& r)
121 r.GetVector(a,"sph");
123 r.GetErrors(a,"car");
126 ///////////////////////////////////////////////////////////////////////////
127 void AliPosition::SetPositionErrors(Double_t* r,TString f)
129 // Store position errors according to reference frame f
132 ///////////////////////////////////////////////////////////////////////////
133 void AliPosition::GetPositionErrors(Double_t* r,TString f) const
135 // Provide position errors according to reference frame f
138 ///////////////////////////////////////////////////////////////////////////
139 void AliPosition::SetPositionErrors(Float_t* r,TString f)
141 // Store position errors according to reference frame f
144 ///////////////////////////////////////////////////////////////////////////
145 void AliPosition::GetPositionErrors(Float_t* r,TString f) const
147 // Provide position errors according to reference frame f
150 ///////////////////////////////////////////////////////////////////////////
151 void AliPosition::ResetPosition()
153 // Reset the position and corresponding errors to 0.
154 Double_t r[3]={0,0,0};
158 ///////////////////////////////////////////////////////////////////////////
159 Double_t AliPosition::GetDistance(AliPosition& p)
161 // Provide distance of the current AliPosition to position p.
162 // The error on the result can be obtained as usual by invoking
163 // GetResultError() afterwards.
165 // In the case of two positions with different unit scales, the distance
166 // will be provided in the unit scale of the current AliPosition.
167 // This implies that in such cases the results of r.GetDistance(q) and
168 // q.GetDistance(r) will be numerically different.
169 // As such it is possible to obtain a correctly computed distance between
170 // positions which have different unit scales.
171 // However, it is recommended to work always with one single unit scale.
173 Ali3Vector d=(Ali3Vector)p;
174 Float_t pscale=p.GetUnitScale();
175 if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale);
176 Ali3Vector q=(Ali3Vector)(*this);
178 Double_t dist=d.GetNorm();
179 fDresult=d.GetResultError();
182 ///////////////////////////////////////////////////////////////////////////
183 void AliPosition::SetUnitScale(Float_t s)
185 // Set the unit scale for the position coordinates.
186 // The scale is normalised w.r.t. the meter, so setting the unit scale
187 // to 0.01 means that all position coordinates are in cm.
188 // By default the unit scale is set to cm in the AliPosition constructor.
189 // It is recommended to use one single unit scale throughout a complete
190 // analysis and/or simulation project.
192 // Note : This memberfunction does not modify the numerical values of
193 // the position coordinates.
194 // It only specifies their numerical meaning.
202 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
205 ///////////////////////////////////////////////////////////////////////////
206 Float_t AliPosition::GetUnitScale() const
208 // Provide the unit scale for the position coordinates.
209 // The scale is normalised w.r.t. the meter, so a unit scale of 0.01
210 // means that all position coordinates are in cm.
213 ///////////////////////////////////////////////////////////////////////////