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 **************************************************************************/
20 #include "Ali3Vector.h"
22 ClassImp(Ali3Vector) // Class implementation to enable ROOT I/O
24 Ali3Vector::Ali3Vector()
26 // Creation of an Ali3Vector object and initialisation of parameters
31 ///////////////////////////////////////////////////////////////////////////
32 Ali3Vector::~Ali3Vector()
34 // Destructor to delete dynamically allocated memory
36 ///////////////////////////////////////////////////////////////////////////
37 void Ali3Vector::SetVector(Double_t* v,TString f)
39 // Store vector according to reference frame f
40 Double_t pi=acos(-1.);
42 if (f == "car") frame=1;
43 if (f == "sph") frame=2;
44 if (f == "cyl") frame=3;
46 Double_t x,y,z,rho,phi;
50 case 1: // Cartesian coordinates
56 if (fV && fabs(z/fV)<=1.)
64 if (fTheta<0.) fTheta+=2.*pi;
66 if (x || y) fPhi=atan2(y,x);
67 if (fPhi<0.) fPhi+=2.*pi;
70 case 2: // Spherical coordinates
76 case 3: // Cylindrical coordinates
82 if (fPhi<0.) fPhi+=2.*pi;
84 if (fV && fabs(z/fV)<=1.)
92 if (fTheta<0.) fTheta+=2.*pi;
95 default: // Unsupported reference frame
96 cout << "*Ali3Vector::SetVector* Unsupported frame : " << f << endl
97 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
104 ///////////////////////////////////////////////////////////////////////////
105 void Ali3Vector::GetVector(Double_t* v,TString f)
107 // Provide vector according to reference frame f
109 if (f == "car") frame=1;
110 if (f == "sph") frame=2;
111 if (f == "cyl") frame=3;
115 case 1: // Cartesian coordinates
116 v[0]=fV*sin(fTheta)*cos(fPhi);
117 v[1]=fV*sin(fTheta)*sin(fPhi);
121 case 2: // Spherical coordinates
127 case 3: // Cylindrical coordinates
133 default: // Unsupported reference frame
134 cout << "*Ali3Vector::GetVector* Unsupported frame : " << f << endl
135 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
136 for (Int_t i=0; i<3; i++)
143 ///////////////////////////////////////////////////////////////////////////
144 void Ali3Vector::SetVector(Float_t* v,TString f)
146 // Store vector according to reference frame f
148 for (Int_t i=0; i<3; i++)
154 ///////////////////////////////////////////////////////////////////////////
155 void Ali3Vector::GetVector(Float_t* v,TString f)
157 // Provide vector according to reference frame f
160 for (Int_t i=0; i<3; i++)
165 ///////////////////////////////////////////////////////////////////////////
166 void Ali3Vector::Info(TString f)
168 // Print vector components according to reference frame f
169 if (f=="car" || f=="sph" || f=="cyl")
173 cout << " Vector in " << f << " coordinates : "
174 << vec[0] << " " << vec[1] << " " << vec[2] << endl;
178 cout << " *Ali3Vector::Info* Unsupported frame : " << f << endl
179 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
182 ///////////////////////////////////////////////////////////////////////////
183 Double_t Ali3Vector::GetNorm()
187 ///////////////////////////////////////////////////////////////////////////
188 Double_t Ali3Vector::Dot(Ali3Vector& q)
190 // Provide the dot product of the current vector with vector q
195 q.GetVector(b,"car");
196 for (Int_t i=0; i<3; i++)
203 ///////////////////////////////////////////////////////////////////////////
204 Ali3Vector Ali3Vector::Cross(Ali3Vector& q)
206 // Provide the cross product of the current vector with vector q
207 Double_t a[3],b[3],c[3];
210 q.GetVector(b,"car");
212 c[0]=a[1]*b[2]-a[2]*b[1];
213 c[1]=a[2]*b[0]-a[0]*b[2];
214 c[2]=a[0]*b[1]-a[1]*b[0];
217 v.SetVector(c,"car");
221 ///////////////////////////////////////////////////////////////////////////
222 Ali3Vector Ali3Vector::operator+(Ali3Vector& q)
224 // Add vector q to the current vector
228 q.GetVector(b,"car");
230 for (Int_t i=0; i<3; i++)
236 v.SetVector(a,"car");
240 ///////////////////////////////////////////////////////////////////////////
241 Ali3Vector Ali3Vector::operator-(Ali3Vector& q)
243 // Subtract vector q from the current vector
247 q.GetVector(b,"car");
249 for (Int_t i=0; i<3; i++)
255 v.SetVector(a,"car");
259 ///////////////////////////////////////////////////////////////////////////
260 Ali3Vector Ali3Vector::operator*(Double_t s)
262 // Multiply the current vector with a scalar s
267 for (Int_t i=0; i<3; i++)
273 v.SetVector(a,"car");
277 ///////////////////////////////////////////////////////////////////////////
278 Ali3Vector Ali3Vector::operator/(Double_t s)
280 // Divide the current vector by a scalar s
282 if (fabs(s)<1.e-20) // Protect against division by 0
284 cout << " *Ali3Vector::/* Division by 0 detected. No action taken." << endl;
293 for (Int_t i=0; i<3; i++)
299 v.SetVector(a,"car");
304 ///////////////////////////////////////////////////////////////////////////
305 Ali3Vector& Ali3Vector::operator+=(Ali3Vector& q)
307 // Add vector q to the current vector
311 q.GetVector(b,"car");
313 for (Int_t i=0; i<3; i++)
322 ///////////////////////////////////////////////////////////////////////////
323 Ali3Vector& Ali3Vector::operator-=(Ali3Vector& q)
325 // Subtract vector q from the current vector
329 q.GetVector(b,"car");
331 for (Int_t i=0; i<3; i++)
340 ///////////////////////////////////////////////////////////////////////////
341 Ali3Vector& Ali3Vector::operator*=(Double_t s)
343 // Multiply the current vector with a scalar s
348 for (Int_t i=0; i<3; i++)
357 ///////////////////////////////////////////////////////////////////////////
358 Ali3Vector& Ali3Vector::operator/=(Double_t s)
360 // Divide the current vector by a scalar s
362 if (fabs(s)<1.e-20) // Protect against division by 0
364 cout << " *Ali3Vector::/=* Division by 0 detected. No action taken." << endl;
373 for (Int_t i=0; i<3; i++)
383 ///////////////////////////////////////////////////////////////////////////