04-apr-2004 NvE SetMass() invoked from AliTrack::Set3Momentum to get also the energy...
[u/mrichter/AliRoot.git] / RALICE / AliPosition.cxx
CommitLineData
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
67ClassImp(AliPosition) // Class implementation to enable ROOT I/O
68
69AliPosition::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;
d88f97cc 74}
75///////////////////////////////////////////////////////////////////////////
76AliPosition::~AliPosition()
77{
78// Destructor to delete dynamically allocated memory
79}
80///////////////////////////////////////////////////////////////////////////
c72198f1 81AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
82{
83// Copy constructor
261c0caf 84 fScale=p.fScale;
c72198f1 85}
86///////////////////////////////////////////////////////////////////////////
d88f97cc 87void AliPosition::SetPosition(Double_t* r,TString f)
88{
89// Store position according to reference frame f
90 SetVector(r,f);
91}
92///////////////////////////////////////////////////////////////////////////
261c0caf 93void AliPosition::GetPosition(Double_t* r,TString f) const
d88f97cc 94{
95// Provide position according to reference frame f
96 GetVector(r,f);
97}
98///////////////////////////////////////////////////////////////////////////
99void AliPosition::SetPosition(Float_t* r,TString f)
100{
101// Store position according to reference frame f
102 SetVector(r,f);
103}
104///////////////////////////////////////////////////////////////////////////
261c0caf 105void AliPosition::GetPosition(Float_t* r,TString f) const
d88f97cc 106{
107// Provide position according to reference frame f
108 GetVector(r,f);
109}
110///////////////////////////////////////////////////////////////////////////
111AliPosition& AliPosition::GetPosition()
112{
113// Provide position
114 return (*this);
115}
116///////////////////////////////////////////////////////////////////////////
117void AliPosition::SetPosition(Ali3Vector& r)
118{
119// Set position
120 Double_t a[3];
121 r.GetVector(a,"sph");
122 SetVector(a,"sph");
959fbac5 123 r.GetErrors(a,"car");
124 SetErrors(a,"car");
125}
126///////////////////////////////////////////////////////////////////////////
127void AliPosition::SetPositionErrors(Double_t* r,TString f)
128{
129// Store position errors according to reference frame f
130 SetErrors(r,f);
131}
132///////////////////////////////////////////////////////////////////////////
261c0caf 133void AliPosition::GetPositionErrors(Double_t* r,TString f) const
959fbac5 134{
135// Provide position errors according to reference frame f
136 GetErrors(r,f);
137}
138///////////////////////////////////////////////////////////////////////////
139void AliPosition::SetPositionErrors(Float_t* r,TString f)
140{
141// Store position errors according to reference frame f
142 SetErrors(r,f);
143}
144///////////////////////////////////////////////////////////////////////////
261c0caf 145void AliPosition::GetPositionErrors(Float_t* r,TString f) const
959fbac5 146{
147// Provide position errors according to reference frame f
148 GetErrors(r,f);
d88f97cc 149}
150///////////////////////////////////////////////////////////////////////////
1c01b4f8 151void AliPosition::ResetPosition()
152{
153// Reset the position and corresponding errors to 0.
154 Double_t r[3]={0,0,0};
155 SetVector(r,"sph");
156 SetErrors(r,"car");
157}
158///////////////////////////////////////////////////////////////////////////
43bfa5be 159Double_t AliPosition::GetDistance(AliPosition& p)
160{
261c0caf 161// Provide distance of the current AliPosition to position p.
43bfa5be 162// The error on the result can be obtained as usual by invoking
163// GetResultError() afterwards.
261c0caf 164//
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.
172//
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);
177 d=d-q;
43bfa5be 178 Double_t dist=d.GetNorm();
179 fDresult=d.GetResultError();
180 return dist;
181}
182///////////////////////////////////////////////////////////////////////////
261c0caf 183void AliPosition::SetUnitScale(Float_t s)
184{
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.
191//
192// Note : This memberfunction does not modify the numerical values of
193// the position coordinates.
194// It only specifies their numerical meaning.
195//
196 if (s>0.)
197 {
198 fScale=s;
199 }
200 else
201 {
202 cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
203 }
204}
205///////////////////////////////////////////////////////////////////////////
206Float_t AliPosition::GetUnitScale() const
207{
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.
211 return fScale;
212}
213///////////////////////////////////////////////////////////////////////////