14-jun-2001 NvE Memberfunction GetRapidity() introduced for AliTrack and AliJet
[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
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class Ali3Vector
20// Handling of 3-vectors in various reference frames.
21//
22// This class is meant to serve as a base class for ALICE objects
23// that have 3-dimensional vector characteristics.
24// Error propagation is performed automatically.
25//
26// Note :
27// ------
28// Vectors (v), Errors (e) and reference frames (f) are specified via
29// SetVector(Float_t* v,TString f)
30// SetErrors(Float_t* e,TString f)
31// under the following conventions :
32//
33// f="car" ==> v in Cartesian coordinates (x,y,z)
34// f="sph" ==> v in Spherical coordinates (r,theta,phi)
35// f="cyl" ==> v in Cylindrical coordinates (rho,phi,z)
36//
37// All angles are in radians.
38//
39// Example :
40// ---------
41//
42// Ali3Vector a;
43// Float_t v[3]={-1,25,7};
44// Float_t e[3]={0.03,0.5,0.21};
45// a.SetVector(v,"car");
46// a.SetErrors(e,"car");
47// a.Info();
48//
49// Float_t vec[3];
50// Float_t err[3];
51// a.GetVector(vec,"sph");
52// a.GetErrors(vec,"sph");
53//
54// Ali3Vector b;
55// Float_t v2[3]={6,-18,33};
56// Float_t e2[3]={0.19,0.45,0.93};
57// b.SetVector(v2,"car");
58// b.SetErrors(e2,"car");
59//
60// Float_t dotpro=a.Dot(b);
61// Float_t doterror=a.GetResultError();
62//
63// Ali3Vector c=a.Cross(b);
64// c.Info("sph");
65// c.GetVector(vec,"cyl");
66// c.GetErrors(err,"cyl");
67//
68// Float_t norm=c.GetNorm();
69// Float_t normerror=c.GetResultError();
70//
71// c=a+b;
72// c=a-b;
73// c=a*5;
74//
75//--- Author: Nick van Eijndhoven 30-mar-1999 UU-SAP Utrecht
f531a546 76//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 77///////////////////////////////////////////////////////////////////////////
78
d88f97cc 79#include "Ali3Vector.h"
80
81ClassImp(Ali3Vector) // Class implementation to enable ROOT I/O
82
83Ali3Vector::Ali3Vector()
84{
85// Creation of an Ali3Vector object and initialisation of parameters
959fbac5 86// All attributes initialised to 0
d88f97cc 87 fV=0;
88 fTheta=0;
89 fPhi=0;
959fbac5 90 fDx=0;
91 fDy=0;
92 fDz=0;
93 fDresult=0;
d88f97cc 94}
95///////////////////////////////////////////////////////////////////////////
96Ali3Vector::~Ali3Vector()
97{
98// Destructor to delete dynamically allocated memory
99}
100///////////////////////////////////////////////////////////////////////////
101void Ali3Vector::SetVector(Double_t* v,TString f)
102{
103// Store vector according to reference frame f
959fbac5 104// All errors will be reset to 0
105 fDx=0;
106 fDy=0;
107 fDz=0;
108 fDresult=0;
109
d88f97cc 110 Double_t pi=acos(-1.);
959fbac5 111
d88f97cc 112 Int_t frame=0;
113 if (f == "car") frame=1;
114 if (f == "sph") frame=2;
115 if (f == "cyl") frame=3;
116
117 Double_t x,y,z,rho,phi;
118
119 switch (frame)
120 {
121 case 1: // Cartesian coordinates
122 x=v[0];
123 y=v[1];
124 z=v[2];
125 fV=sqrt(x*x+y*y+z*z);
126 fTheta=0;
127 if (fV && fabs(z/fV)<=1.)
128 {
129 fTheta=acos(z/fV);
130 }
131 else
132 {
133 if (z<0.) fTheta=pi;
134 }
135 if (fTheta<0.) fTheta+=2.*pi;
136 fPhi=0;
137 if (x || y) fPhi=atan2(y,x);
138 if (fPhi<0.) fPhi+=2.*pi;
139 break;
140
141 case 2: // Spherical coordinates
142 fV=v[0];
143 fTheta=v[1];
144 fPhi=v[2];
145 break;
146
147 case 3: // Cylindrical coordinates
148 rho=v[0];
149 phi=v[1];
150 z=v[2];
151 fV=sqrt(rho*rho+z*z);
152 fPhi=phi;
153 if (fPhi<0.) fPhi+=2.*pi;
154 fTheta=0;
155 if (fV && fabs(z/fV)<=1.)
156 {
157 fTheta=acos(z/fV);
158 }
159 else
160 {
161 if (z<0.) fTheta=pi;
162 }
163 if (fTheta<0.) fTheta+=2.*pi;
164 break;
165
166 default: // Unsupported reference frame
167 cout << "*Ali3Vector::SetVector* Unsupported frame : " << f << endl
168 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
169 fV=0;
170 fTheta=0;
171 fPhi=0;
172 break;
173 }
174}
175///////////////////////////////////////////////////////////////////////////
176void Ali3Vector::GetVector(Double_t* v,TString f)
177{
178// Provide vector according to reference frame f
179 Int_t frame=0;
180 if (f == "car") frame=1;
181 if (f == "sph") frame=2;
182 if (f == "cyl") frame=3;
183
184 switch (frame)
185 {
186 case 1: // Cartesian coordinates
187 v[0]=fV*sin(fTheta)*cos(fPhi);
188 v[1]=fV*sin(fTheta)*sin(fPhi);
189 v[2]=fV*cos(fTheta);
190 break;
191
192 case 2: // Spherical coordinates
193 v[0]=fV;
194 v[1]=fTheta;
195 v[2]=fPhi;
196 break;
197
198 case 3: // Cylindrical coordinates
199 v[0]=fV*sin(fTheta);
200 v[1]=fPhi;
201 v[2]=fV*cos(fTheta);
202 break;
203
204 default: // Unsupported reference frame
205 cout << "*Ali3Vector::GetVector* Unsupported frame : " << f << endl
206 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
207 for (Int_t i=0; i<3; i++)
208 {
209 v[i]=0;
210 }
211 break;
212 }
213}
214///////////////////////////////////////////////////////////////////////////
215void Ali3Vector::SetVector(Float_t* v,TString f)
216{
217// Store vector according to reference frame f
959fbac5 218// All errors will be reset to 0
d88f97cc 219 Double_t vec[3];
220 for (Int_t i=0; i<3; i++)
221 {
222 vec[i]=v[i];
223 }
224 SetVector(vec,f);
225}
226///////////////////////////////////////////////////////////////////////////
227void Ali3Vector::GetVector(Float_t* v,TString f)
228{
229// Provide vector according to reference frame f
230 Double_t vec[3];
231 GetVector(vec,f);
232 for (Int_t i=0; i<3; i++)
233 {
234 v[i]=vec[i];
235 }
236}
237///////////////////////////////////////////////////////////////////////////
959fbac5 238void Ali3Vector::SetErrors(Double_t* e,TString f)
239{
240// Store errors according to reference frame f
241// The error on scalar results is reset to 0
242 fDresult=0;
243
244 Int_t frame=0;
245 if (f == "car") frame=1;
246 if (f == "sph") frame=2;
247 if (f == "cyl") frame=3;
248
249 Double_t dx2,dy2,dz2,rho;
250
251 switch (frame)
252 {
253 case 1: // Cartesian coordinates
254 fDx=fabs(e[0]);
255 fDy=fabs(e[1]);
256 fDz=fabs(e[2]);
257 break;
258
259 case 2: // Spherical coordinates
260 dx2=pow((cos(fPhi)*sin(fTheta)*e[0]),2)+pow((fV*cos(fTheta)*cos(fPhi)*e[1]),2)
261 +pow((fV*sin(fTheta)*sin(fPhi)*e[2]),2);
262 dy2=pow((sin(fPhi)*sin(fTheta)*e[0]),2)+pow((fV*cos(fTheta)*sin(fPhi)*e[1]),2)
263 +pow((fV*sin(fTheta)*cos(fPhi)*e[2]),2);
264 dz2=pow((cos(fTheta)*e[0]),2)+pow((fV*sin(fTheta)*e[1]),2);
265 fDx=sqrt(dx2);
266 fDy=sqrt(dy2);
267 fDz=sqrt(dz2);
268 break;
269
270 case 3: // Cylindrical coordinates
271 rho=fV*sin(fTheta);
272 dx2=pow((cos(fPhi)*e[0]),2)+pow((rho*sin(fPhi)*e[1]),2);
273 dy2=pow((sin(fPhi)*e[0]),2)+pow((rho*cos(fPhi)*e[1]),2);
274 fDx=sqrt(dx2);
275 fDy=sqrt(dy2);
276 fDz=fabs(e[2]);
277 break;
278
279 default: // Unsupported reference frame
280 cout << "*Ali3Vector::SetErrors* Unsupported frame : " << f << endl
281 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
282 fDx=0;
283 fDy=0;
284 fDz=0;
285 break;
286 }
287}
288///////////////////////////////////////////////////////////////////////////
289void Ali3Vector::GetErrors(Double_t* e,TString f)
290{
291// Provide errors according to reference frame f
292 Int_t frame=0;
293 if (f == "car") frame=1;
294 if (f == "sph") frame=2;
295 if (f == "cyl") frame=3;
296
d071d629 297 Double_t pi=acos(-1.);
298
959fbac5 299 Double_t dr2,dtheta2,dphi2,rho,drho2;
300 Double_t v[3];
d071d629 301 Double_t rxy2; // Shorthand for (x*x+y*y)
959fbac5 302
303 switch (frame)
304 {
305 case 1: // Cartesian coordinates
306 e[0]=fDx;
307 e[1]=fDy;
308 e[2]=fDz;
309 break;
310
311 case 2: // Spherical coordinates
312 GetVector(v,"car");
d071d629 313 rxy2=pow(v[0],2)+pow(v[1],2);
314 if (sqrt(rxy2)<(fV*1e-10)) rxy2=0;
959fbac5 315 if (fV)
316 {
317 dr2=(pow((v[0]*fDx),2)+pow((v[1]*fDy),2)+pow((v[2]*fDz),2))/(fV*fV);
318 }
319 else
320 {
321 dr2=0;
322 }
d071d629 323 if (fV)
959fbac5 324 {
d071d629 325 dtheta2=rxy2*pow(fDz,2)/pow(fV,4);
326 if (v[2] && rxy2)
327 {
328 dtheta2+=rxy2*pow(v[2],2)*(pow((v[0]*fDx),2)+pow((v[1]*fDy),2)) /
329 pow(((pow(v[3],2)*rxy2)+pow(rxy2,2)),2);
330 }
959fbac5 331 }
332 else
333 {
959fbac5 334 dtheta2=0;
335 }
d071d629 336 if (rxy2)
959fbac5 337 {
d071d629 338 dphi2=(pow((v[1]*fDx),2)+pow((v[0]*fDy),2))/(pow(rxy2,2));
959fbac5 339 }
340 else
341 {
342 dphi2=0;
343 }
344 e[0]=sqrt(dr2);
345 e[1]=sqrt(dtheta2);
d071d629 346 if (e[1]>pi) e[1]=pi;
959fbac5 347 e[2]=sqrt(dphi2);
d071d629 348 if (e[2]>(2.*pi)) e[2]=2.*pi;
959fbac5 349 break;
350
351 case 3: // Cylindrical coordinates
352 GetVector(v,"car");
d071d629 353 rho=fabs(fV*sin(fTheta));
354 if (rho<(fV*1e-10)) rho=0;
959fbac5 355 if (rho)
356 {
357 drho2=(pow((v[0]*fDx),2)+pow((v[1]*fDy),2))/(rho*rho);
358 }
359 else
360 {
361 drho2=0;
362 }
d071d629 363 if (rho)
959fbac5 364 {
d071d629 365 dphi2=(pow((v[1]*fDx),2)+pow((v[0]*fDy),2))/(pow(rho,4));
959fbac5 366 }
367 else
368 {
369 dphi2=0;
370 }
371 e[0]=sqrt(drho2);
372 e[1]=sqrt(dphi2);
d071d629 373 if (e[1]>(2.*pi)) e[1]=2.*pi;
959fbac5 374 e[2]=fDz;
375 break;
376
377 default: // Unsupported reference frame
378 cout << "*Ali3Vector::GetErrors* Unsupported frame : " << f << endl
379 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
380 for (Int_t i=0; i<3; i++)
381 {
382 e[i]=0;
383 }
384 break;
385 }
386}
387///////////////////////////////////////////////////////////////////////////
388void Ali3Vector::SetErrors(Float_t* e,TString f)
389{
390// Store errors according to reference frame f
391// The error on scalar results is reset to 0
392 Double_t vec[3];
393 for (Int_t i=0; i<3; i++)
394 {
395 vec[i]=e[i];
396 }
397 SetErrors(vec,f);
398}
399///////////////////////////////////////////////////////////////////////////
400void Ali3Vector::GetErrors(Float_t* e,TString f)
401{
402// Provide errors according to reference frame f
403 Double_t vec[3];
404 GetErrors(vec,f);
405 for (Int_t i=0; i<3; i++)
406 {
407 e[i]=vec[i];
408 }
409}
410///////////////////////////////////////////////////////////////////////////
d88f97cc 411void Ali3Vector::Info(TString f)
412{
413// Print vector components according to reference frame f
414 if (f=="car" || f=="sph" || f=="cyl")
415 {
959fbac5 416 Double_t vec[3],err[3];
d88f97cc 417 GetVector(vec,f);
959fbac5 418 GetErrors(err,f);
d88f97cc 419 cout << " Vector in " << f << " coordinates : "
420 << vec[0] << " " << vec[1] << " " << vec[2] << endl;
959fbac5 421 cout << " Err. in " << f << " coordinates : "
422 << err[0] << " " << err[1] << " " << err[2] << endl;
d88f97cc 423 }
424 else
425 {
426 cout << " *Ali3Vector::Info* Unsupported frame : " << f << endl
427 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
428 }
429}
430///////////////////////////////////////////////////////////////////////////
431Double_t Ali3Vector::GetNorm()
432{
959fbac5 433// Provide the norm of the current vector
434// The error on the scalar result (norm) is updated accordingly
435 Double_t e[3];
436 GetErrors(e,"sph");
437 fDresult=e[0];
d88f97cc 438 return fV;
439}
440///////////////////////////////////////////////////////////////////////////
959fbac5 441Double_t Ali3Vector::GetPseudoRapidity()
442{
443// Provide the pseudo-rapidity w.r.t. the z-axis.
444// In other words : eta=-log(tan(theta/2))
445// The error on the scalar result (pseudo-rap.) is updated accordingly
8adaf597 446 Double_t pi=acos(-1.);
959fbac5 447 Double_t v[3];
448 GetVector(v,"sph");
449 Double_t thetahalf=v[1]/2.;
8adaf597 450 Double_t arg=0;
451 if (v[1]<pi) arg=tan(thetahalf);
452 Double_t eta=9999;
959fbac5 453 if (arg>0) eta=-log(arg);
454 Double_t e[3];
455 GetErrors(e,"sph");
456 Double_t prod=cos(thetahalf)*sin(thetahalf);
457 fDresult=0;
458 if (prod) fDresult=fabs(e[1]/2.*prod);
459 return eta;
460}
461///////////////////////////////////////////////////////////////////////////
d88f97cc 462Double_t Ali3Vector::Dot(Ali3Vector& q)
463{
464// Provide the dot product of the current vector with vector q
959fbac5 465// The error on the scalar result (dotproduct) is updated accordingly
466
d88f97cc 467 Double_t dotpro=0;
468
959fbac5 469 if ((this) == &q) // Check for special case v.Dot(v)
d88f97cc 470 {
959fbac5 471 Double_t norm=GetNorm();
472 Double_t dnorm=GetResultError();
473 dotpro=pow(norm,2);
474 fDresult=2.*norm*dnorm;
d88f97cc 475 }
959fbac5 476 else
477 {
478 Double_t a[3],b[3];
479 Double_t ea[3],eb[3];
480 Double_t d2=0;
481
482 GetVector(a,"car");
483 GetErrors(ea,"car");
484 q.GetVector(b,"car");
485 q.GetErrors(eb,"car");
486 for (Int_t i=0; i<3; i++)
487 {
488 dotpro+=a[i]*b[i];
489 d2+=pow(b[i]*ea[i],2)+pow(a[i]*eb[i],2);
490 }
491 fDresult=sqrt(d2);
492 }
493
d88f97cc 494 return dotpro;
495}
496///////////////////////////////////////////////////////////////////////////
959fbac5 497Double_t Ali3Vector::GetResultError()
498{
499// Provide the error on the result of an operation yielding a scalar
500// E.g. GetNorm() or Dot()
501 return fDresult;
502}
503///////////////////////////////////////////////////////////////////////////
d88f97cc 504Ali3Vector Ali3Vector::Cross(Ali3Vector& q)
505{
506// Provide the cross product of the current vector with vector q
959fbac5 507// Error propagation is performed automatically
d88f97cc 508 Double_t a[3],b[3],c[3];
959fbac5 509 Double_t ea[3],eb[3],ec[3],d2;
d88f97cc 510
511 GetVector(a,"car");
959fbac5 512 GetErrors(ea,"car");
d88f97cc 513 q.GetVector(b,"car");
959fbac5 514 q.GetErrors(eb,"car");
d88f97cc 515
516 c[0]=a[1]*b[2]-a[2]*b[1];
517 c[1]=a[2]*b[0]-a[0]*b[2];
518 c[2]=a[0]*b[1]-a[1]*b[0];
519
959fbac5 520 d2=pow(b[2]*ea[1],2)+pow(a[1]*eb[2],2)
521 +pow(b[1]*ea[2],2)+pow(a[2]*eb[1],2);
522 ec[0]=sqrt(d2);
523
524 d2=pow(b[0]*ea[2],2)+pow(a[2]*eb[0],2)
525 +pow(b[2]*ea[0],2)+pow(a[0]*eb[2],2);
526 ec[1]=sqrt(d2);
527
528 d2=pow(b[1]*ea[0],2)+pow(a[0]*eb[1],2)
529 +pow(b[0]*ea[1],2)+pow(a[1]*eb[0],2);
530 ec[2]=sqrt(d2);
531
d88f97cc 532 Ali3Vector v;
533 v.SetVector(c,"car");
959fbac5 534 v.SetErrors(ec,"car");
d88f97cc 535
536 return v;
537}
538///////////////////////////////////////////////////////////////////////////
539Ali3Vector Ali3Vector::operator+(Ali3Vector& q)
540{
541// Add vector q to the current vector
959fbac5 542// Error propagation is performed automatically
543 Double_t a[3],b[3],ea[3],eb[3];
d88f97cc 544
545 GetVector(a,"car");
959fbac5 546 GetErrors(ea,"car");
d88f97cc 547 q.GetVector(b,"car");
959fbac5 548 q.GetErrors(eb,"car");
d88f97cc 549
550 for (Int_t i=0; i<3; i++)
551 {
552 a[i]+=b[i];
959fbac5 553 ea[i]=sqrt(pow(ea[i],2)+pow(eb[i],2));
d88f97cc 554 }
555
556 Ali3Vector v;
557 v.SetVector(a,"car");
959fbac5 558 v.SetErrors(ea,"car");
d88f97cc 559
560 return v;
561}
562///////////////////////////////////////////////////////////////////////////
563Ali3Vector Ali3Vector::operator-(Ali3Vector& q)
564{
565// Subtract vector q from the current vector
959fbac5 566// Error propagation is performed automatically
567 Double_t a[3],b[3],ea[3],eb[3];
d88f97cc 568
569 GetVector(a,"car");
959fbac5 570 GetErrors(ea,"car");
d88f97cc 571 q.GetVector(b,"car");
959fbac5 572 q.GetErrors(eb,"car");
d88f97cc 573
574 for (Int_t i=0; i<3; i++)
575 {
576 a[i]-=b[i];
959fbac5 577 ea[i]=sqrt(pow(ea[i],2)+pow(eb[i],2));
d88f97cc 578 }
579
580 Ali3Vector v;
581 v.SetVector(a,"car");
959fbac5 582 v.SetErrors(ea,"car");
d88f97cc 583
584 return v;
585}
586///////////////////////////////////////////////////////////////////////////
587Ali3Vector Ali3Vector::operator*(Double_t s)
588{
959fbac5 589// Multiply the current vector with a scalar s.
590// Error propagation is performed automatically.
591 Double_t a[3],ea[3];
d88f97cc 592
593 GetVector(a,"car");
959fbac5 594 GetErrors(ea,"car");
d88f97cc 595
596 for (Int_t i=0; i<3; i++)
597 {
598 a[i]*=s;
959fbac5 599 ea[i]*=s;
d88f97cc 600 }
601
602 Ali3Vector v;
603 v.SetVector(a,"car");
959fbac5 604 v.SetErrors(ea,"car");
d88f97cc 605
606 return v;
607}
608///////////////////////////////////////////////////////////////////////////
609Ali3Vector Ali3Vector::operator/(Double_t s)
610{
611// Divide the current vector by a scalar s
959fbac5 612// Error propagation is performed automatically
d88f97cc 613
614 if (fabs(s)<1.e-20) // Protect against division by 0
615 {
616 cout << " *Ali3Vector::/* Division by 0 detected. No action taken." << endl;
617 return *this;
618 }
619 else
620 {
959fbac5 621 Double_t a[3],ea[3];
d88f97cc 622
623 GetVector(a,"car");
959fbac5 624 GetErrors(ea,"car");
d88f97cc 625
626 for (Int_t i=0; i<3; i++)
627 {
628 a[i]/=s;
959fbac5 629 ea[i]/=s;
d88f97cc 630 }
631
632 Ali3Vector v;
633 v.SetVector(a,"car");
959fbac5 634 v.SetErrors(ea,"car");
d88f97cc 635
636 return v;
637 }
638}
639///////////////////////////////////////////////////////////////////////////
640Ali3Vector& Ali3Vector::operator+=(Ali3Vector& q)
641{
642// Add vector q to the current vector
959fbac5 643// Error propagation is performed automatically
644 Double_t a[3],b[3],ea[3],eb[3];
d88f97cc 645
646 GetVector(a,"car");
959fbac5 647 GetErrors(ea,"car");
d88f97cc 648 q.GetVector(b,"car");
959fbac5 649 q.GetErrors(eb,"car");
d88f97cc 650
651 for (Int_t i=0; i<3; i++)
652 {
653 a[i]+=b[i];
959fbac5 654 ea[i]=sqrt(pow(ea[i],2)+pow(eb[i],2));
d88f97cc 655 }
656
657 SetVector(a,"car");
959fbac5 658 SetErrors(ea,"car");
d88f97cc 659
660 return *this;
661}
662///////////////////////////////////////////////////////////////////////////
663Ali3Vector& Ali3Vector::operator-=(Ali3Vector& q)
664{
665// Subtract vector q from the current vector
959fbac5 666// Error propagation is performed automatically
667 Double_t a[3],b[3],ea[3],eb[3];
d88f97cc 668
669 GetVector(a,"car");
959fbac5 670 GetErrors(ea,"car");
d88f97cc 671 q.GetVector(b,"car");
959fbac5 672 q.GetErrors(eb,"car");
d88f97cc 673
674 for (Int_t i=0; i<3; i++)
675 {
676 a[i]-=b[i];
959fbac5 677 ea[i]=sqrt(pow(ea[i],2)+pow(eb[i],2));
d88f97cc 678 }
679
680 SetVector(a,"car");
959fbac5 681 SetErrors(ea,"car");
d88f97cc 682
683 return *this;
684}
685///////////////////////////////////////////////////////////////////////////
686Ali3Vector& Ali3Vector::operator*=(Double_t s)
687{
688// Multiply the current vector with a scalar s
959fbac5 689// Error propagation is performed automatically
690 Double_t a[3],ea[3];
d88f97cc 691
692 GetVector(a,"car");
959fbac5 693 GetErrors(ea,"car");
d88f97cc 694
695 for (Int_t i=0; i<3; i++)
696 {
697 a[i]*=s;
959fbac5 698 ea[i]*=s;
d88f97cc 699 }
700
701 SetVector(a,"car");
959fbac5 702 SetErrors(ea,"car");
d88f97cc 703
704 return *this;
705}
706///////////////////////////////////////////////////////////////////////////
707Ali3Vector& Ali3Vector::operator/=(Double_t s)
708{
709// Divide the current vector by a scalar s
959fbac5 710// Error propagation is performed automatically
d88f97cc 711
712 if (fabs(s)<1.e-20) // Protect against division by 0
713 {
714 cout << " *Ali3Vector::/=* Division by 0 detected. No action taken." << endl;
715 return *this;
716 }
717 else
718 {
959fbac5 719 Double_t a[3],ea[3];
d88f97cc 720
721 GetVector(a,"car");
959fbac5 722 GetErrors(ea,"car");
d88f97cc 723
724 for (Int_t i=0; i<3; i++)
725 {
726 a[i]/=s;
959fbac5 727 ea[i]/=s;
d88f97cc 728 }
729
730 SetVector(a,"car");
959fbac5 731 SetErrors(ea,"car");
d88f97cc 732
733 return *this;
734 }
735}
736///////////////////////////////////////////////////////////////////////////
d071d629 737Ali3Vector Ali3Vector::GetVecTrans()
738{
739// Provide the transverse vector w.r.t. z-axis.
740// Error propagation is performed automatically
741 Double_t pi=acos(-1.);
742 Double_t a[3],ea[3];
743
744 GetVector(a,"sph");
745 GetErrors(ea,"sph");
746
747 Double_t vt,dvt2;
748 vt=a[0]*sin(a[1]);
749 dvt2=pow((sin(a[1])*ea[0]),2)+pow((a[0]*cos(a[1])*ea[1]),2);
750
751 a[0]=fabs(vt);
752 a[1]=pi/2.;
753
754 ea[0]=sqrt(dvt2);
755 ea[1]=0;
756
757 Ali3Vector v;
758 v.SetVector(a,"sph");
759 v.SetErrors(ea,"sph");
760
761 return v;
762}
763///////////////////////////////////////////////////////////////////////////
764Ali3Vector Ali3Vector::GetVecLong()
765{
766// Provide the longitudinal vector w.r.t. z-axis.
767// Error propagation is performed automatically
768 Double_t pi=acos(-1.);
769 Double_t a[3],ea[3];
770
771 GetVector(a,"sph");
772 GetErrors(ea,"sph");
773
774 Double_t vl,dvl2;
775 vl=a[0]*cos(a[1]);
776 dvl2=pow((cos(a[1])*ea[0]),2)+pow((a[0]*sin(a[1])*ea[1]),2);
777
778 a[0]=fabs(vl);
779 a[1]=0;
780 if (vl<0) a[1]=pi;
781 a[2]=0;
782
783 ea[0]=sqrt(dvl2);
784 ea[1]=0;
785 ea[2]=0;
786
787 Ali3Vector v;
788 v.SetVector(a,"sph");
789 v.SetErrors(ea,"sph");
790
791 return v;
792}
793///////////////////////////////////////////////////////////////////////////