]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/Ali3Vector.cxx
Have ProdProcess return const char*
[u/mrichter/AliRoot.git] / RALICE / Ali3Vector.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
16/*
17$Log$
18*/
19
d88f97cc 20#include "Ali3Vector.h"
21
22ClassImp(Ali3Vector) // Class implementation to enable ROOT I/O
23
24Ali3Vector::Ali3Vector()
25{
26// Creation of an Ali3Vector object and initialisation of parameters
27 fV=0;
28 fTheta=0;
29 fPhi=0;
30}
31///////////////////////////////////////////////////////////////////////////
32Ali3Vector::~Ali3Vector()
33{
34// Destructor to delete dynamically allocated memory
35}
36///////////////////////////////////////////////////////////////////////////
37void Ali3Vector::SetVector(Double_t* v,TString f)
38{
39// Store vector according to reference frame f
40 Double_t pi=acos(-1.);
41 Int_t frame=0;
42 if (f == "car") frame=1;
43 if (f == "sph") frame=2;
44 if (f == "cyl") frame=3;
45
46 Double_t x,y,z,rho,phi;
47
48 switch (frame)
49 {
50 case 1: // Cartesian coordinates
51 x=v[0];
52 y=v[1];
53 z=v[2];
54 fV=sqrt(x*x+y*y+z*z);
55 fTheta=0;
56 if (fV && fabs(z/fV)<=1.)
57 {
58 fTheta=acos(z/fV);
59 }
60 else
61 {
62 if (z<0.) fTheta=pi;
63 }
64 if (fTheta<0.) fTheta+=2.*pi;
65 fPhi=0;
66 if (x || y) fPhi=atan2(y,x);
67 if (fPhi<0.) fPhi+=2.*pi;
68 break;
69
70 case 2: // Spherical coordinates
71 fV=v[0];
72 fTheta=v[1];
73 fPhi=v[2];
74 break;
75
76 case 3: // Cylindrical coordinates
77 rho=v[0];
78 phi=v[1];
79 z=v[2];
80 fV=sqrt(rho*rho+z*z);
81 fPhi=phi;
82 if (fPhi<0.) fPhi+=2.*pi;
83 fTheta=0;
84 if (fV && fabs(z/fV)<=1.)
85 {
86 fTheta=acos(z/fV);
87 }
88 else
89 {
90 if (z<0.) fTheta=pi;
91 }
92 if (fTheta<0.) fTheta+=2.*pi;
93 break;
94
95 default: // Unsupported reference frame
96 cout << "*Ali3Vector::SetVector* Unsupported frame : " << f << endl
97 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
98 fV=0;
99 fTheta=0;
100 fPhi=0;
101 break;
102 }
103}
104///////////////////////////////////////////////////////////////////////////
105void Ali3Vector::GetVector(Double_t* v,TString f)
106{
107// Provide vector according to reference frame f
108 Int_t frame=0;
109 if (f == "car") frame=1;
110 if (f == "sph") frame=2;
111 if (f == "cyl") frame=3;
112
113 switch (frame)
114 {
115 case 1: // Cartesian coordinates
116 v[0]=fV*sin(fTheta)*cos(fPhi);
117 v[1]=fV*sin(fTheta)*sin(fPhi);
118 v[2]=fV*cos(fTheta);
119 break;
120
121 case 2: // Spherical coordinates
122 v[0]=fV;
123 v[1]=fTheta;
124 v[2]=fPhi;
125 break;
126
127 case 3: // Cylindrical coordinates
128 v[0]=fV*sin(fTheta);
129 v[1]=fPhi;
130 v[2]=fV*cos(fTheta);
131 break;
132
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++)
137 {
138 v[i]=0;
139 }
140 break;
141 }
142}
143///////////////////////////////////////////////////////////////////////////
144void Ali3Vector::SetVector(Float_t* v,TString f)
145{
146// Store vector according to reference frame f
147 Double_t vec[3];
148 for (Int_t i=0; i<3; i++)
149 {
150 vec[i]=v[i];
151 }
152 SetVector(vec,f);
153}
154///////////////////////////////////////////////////////////////////////////
155void Ali3Vector::GetVector(Float_t* v,TString f)
156{
157// Provide vector according to reference frame f
158 Double_t vec[3];
159 GetVector(vec,f);
160 for (Int_t i=0; i<3; i++)
161 {
162 v[i]=vec[i];
163 }
164}
165///////////////////////////////////////////////////////////////////////////
166void Ali3Vector::Info(TString f)
167{
168// Print vector components according to reference frame f
169 if (f=="car" || f=="sph" || f=="cyl")
170 {
171 Double_t vec[3];
172 GetVector(vec,f);
173 cout << " Vector in " << f << " coordinates : "
174 << vec[0] << " " << vec[1] << " " << vec[2] << endl;
175 }
176 else
177 {
178 cout << " *Ali3Vector::Info* Unsupported frame : " << f << endl
179 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
180 }
181}
182///////////////////////////////////////////////////////////////////////////
183Double_t Ali3Vector::GetNorm()
184{
185 return fV;
186}
187///////////////////////////////////////////////////////////////////////////
188Double_t Ali3Vector::Dot(Ali3Vector& q)
189{
190// Provide the dot product of the current vector with vector q
191 Double_t a[3],b[3];
192 Double_t dotpro=0;
193
194 GetVector(a,"car");
195 q.GetVector(b,"car");
196 for (Int_t i=0; i<3; i++)
197 {
198 dotpro+=a[i]*b[i];
199 }
200
201 return dotpro;
202}
203///////////////////////////////////////////////////////////////////////////
204Ali3Vector Ali3Vector::Cross(Ali3Vector& q)
205{
206// Provide the cross product of the current vector with vector q
207 Double_t a[3],b[3],c[3];
208
209 GetVector(a,"car");
210 q.GetVector(b,"car");
211
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];
215
216 Ali3Vector v;
217 v.SetVector(c,"car");
218
219 return v;
220}
221///////////////////////////////////////////////////////////////////////////
222Ali3Vector Ali3Vector::operator+(Ali3Vector& q)
223{
224// Add vector q to the current vector
225 Double_t a[3],b[3];
226
227 GetVector(a,"car");
228 q.GetVector(b,"car");
229
230 for (Int_t i=0; i<3; i++)
231 {
232 a[i]+=b[i];
233 }
234
235 Ali3Vector v;
236 v.SetVector(a,"car");
237
238 return v;
239}
240///////////////////////////////////////////////////////////////////////////
241Ali3Vector Ali3Vector::operator-(Ali3Vector& q)
242{
243// Subtract vector q from the current vector
244 Double_t a[3],b[3];
245
246 GetVector(a,"car");
247 q.GetVector(b,"car");
248
249 for (Int_t i=0; i<3; i++)
250 {
251 a[i]-=b[i];
252 }
253
254 Ali3Vector v;
255 v.SetVector(a,"car");
256
257 return v;
258}
259///////////////////////////////////////////////////////////////////////////
260Ali3Vector Ali3Vector::operator*(Double_t s)
261{
262// Multiply the current vector with a scalar s
263 Double_t a[3];
264
265 GetVector(a,"car");
266
267 for (Int_t i=0; i<3; i++)
268 {
269 a[i]*=s;
270 }
271
272 Ali3Vector v;
273 v.SetVector(a,"car");
274
275 return v;
276}
277///////////////////////////////////////////////////////////////////////////
278Ali3Vector Ali3Vector::operator/(Double_t s)
279{
280// Divide the current vector by a scalar s
281
282 if (fabs(s)<1.e-20) // Protect against division by 0
283 {
284 cout << " *Ali3Vector::/* Division by 0 detected. No action taken." << endl;
285 return *this;
286 }
287 else
288 {
289 Double_t a[3];
290
291 GetVector(a,"car");
292
293 for (Int_t i=0; i<3; i++)
294 {
295 a[i]/=s;
296 }
297
298 Ali3Vector v;
299 v.SetVector(a,"car");
300
301 return v;
302 }
303}
304///////////////////////////////////////////////////////////////////////////
305Ali3Vector& Ali3Vector::operator+=(Ali3Vector& q)
306{
307// Add vector q to the current vector
308 Double_t a[3],b[3];
309
310 GetVector(a,"car");
311 q.GetVector(b,"car");
312
313 for (Int_t i=0; i<3; i++)
314 {
315 a[i]+=b[i];
316 }
317
318 SetVector(a,"car");
319
320 return *this;
321}
322///////////////////////////////////////////////////////////////////////////
323Ali3Vector& Ali3Vector::operator-=(Ali3Vector& q)
324{
325// Subtract vector q from the current vector
326 Double_t a[3],b[3];
327
328 GetVector(a,"car");
329 q.GetVector(b,"car");
330
331 for (Int_t i=0; i<3; i++)
332 {
333 a[i]-=b[i];
334 }
335
336 SetVector(a,"car");
337
338 return *this;
339}
340///////////////////////////////////////////////////////////////////////////
341Ali3Vector& Ali3Vector::operator*=(Double_t s)
342{
343// Multiply the current vector with a scalar s
344 Double_t a[3];
345
346 GetVector(a,"car");
347
348 for (Int_t i=0; i<3; i++)
349 {
350 a[i]*=s;
351 }
352
353 SetVector(a,"car");
354
355 return *this;
356}
357///////////////////////////////////////////////////////////////////////////
358Ali3Vector& Ali3Vector::operator/=(Double_t s)
359{
360// Divide the current vector by a scalar s
361
362 if (fabs(s)<1.e-20) // Protect against division by 0
363 {
364 cout << " *Ali3Vector::/=* Division by 0 detected. No action taken." << endl;
365 return *this;
366 }
367 else
368 {
369 Double_t a[3];
370
371 GetVector(a,"car");
372
373 for (Int_t i=0; i<3; i++)
374 {
375 a[i]/=s;
376 }
377
378 SetVector(a,"car");
379
380 return *this;
381 }
382}
383///////////////////////////////////////////////////////////////////////////