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 Lorentz 4-vectors in various reference frames.
22 // This class is meant to serve as a base class for ALICE objects
23 // that have Lorentz 4-vector characteristics.
24 // Error propagation is performed automatically.
26 // All 4-vectors are treated in the contravariant form and the convention
27 // for the metric and the 4-vector components is according to the one
28 // used in the book "Classical Electrodynamics" by J.D. Jackson.
30 // A 4-vector is said to have a scalar part and a 3-vector part,
31 // which is indicated by the notation
33 // x^i = (x^0,x^1,x^2,x^3)
35 // The scalar part = x^0
36 // The 3-vector part = (x^1,x^2,x^3)
38 // In view of accuracy and the fact that e.g. particle identity (mass)
39 // is preserved in many physics processes, the Lorentz invariant
40 // (x^i*x_i) is internally saved together with the scalar part.
42 // This allows the following two modes of functionality :
44 // Scalar mode : The scalar part and the 3-vector part are considered
45 // as basic quantities and the invariant with its error
46 // is derived from these.
47 // Invariant mode : The invariant and the 3-vector part are considered
48 // as basic quantities and the scalar with its error
49 // is derived from these.
51 // The philosophy followed here is the following :
52 // ===============================================
54 // 1) Invokation of SetVector() sets the scalar and 3-vector parts
55 // and the invariant is calculated from these.
56 // Automatically the scalar mode is selected and invokation of
57 // SetErrors() will calculate the error on the invariant.
59 // 2) In case the scalar part is modified via SetScalar(), scalar mode is
60 // automatically selected and the Lorentz invariant (x^i*x_i) and its
61 // error are updated accordingly.
62 // The 3-vector part is NOT modified.
63 // This situation arises when one e.g. precisely determines the time
66 // 3) In case the Lorentz invariant (x^i*x_i) is modified via SetInvariant(),
67 // invariant mode is selected automatically and the scalar part and its
68 // error are updated accordingly.
69 // The 3-vector part is NOT modified.
70 // This situation arises when one e.g. precisely determines the mass.
72 // 4) In case the vector part is modified via Set3Vector(), then the
73 // current mode determines whether the scalar or the invariant is updated.
74 // Scalar mode : The Lorentz invariant (x^i*x_i) and its error are updated;
75 // the scalar part and its error are NOT modified.
76 // This situation arises when one e.g. improves the 3-position
77 // vector for a particle with a very precise timing.
78 // Invariant mode : The scalar part and its error are updated;
79 // the Lorentz invariant (x^i*x_i) and its error are NOT modified.
80 // This situation arises when one e.g. improves the 3-momentum
81 // vector for a particle with known mass.
83 // The dotproduct is defined such that p.Dot(p) yields the Lorentz invariant
84 // scalar of the 4-vector p (i.e. m**2 in case p is a 4-momentum).
88 // Vectors (v), Errors (e) and reference frames (f) are specified via
89 // SetVector(Float_t* v,TString f)
90 // SetErrors(Float_t* e,TString f)
91 // under the following conventions :
93 // f="car" ==> 3-vector part of v in Cartesian coordinates (x,y,z)
94 // f="sph" ==> 3-vector part of v in Spherical coordinates (r,theta,phi)
95 // f="cyl" ==> 3-vector part of v in Cylindrical coordinates (rho,phi,z)
97 // All angles are in radians.
104 // Float_t v[4]={25,-1,3,7};
105 // a.SetVector(v,"car");
108 // a.GetVector(vec,"sph");
111 // Float_t v2[4]={33,6,-18,2};
112 // b.SetVector(v2,"car");
114 // Float_t dotpro=a.Dot(b);
118 // Float_t vec2[3]={1,2,3};
119 // x.SetVector(vec2,"car");
122 // c.SetVector(x0,x);
123 // c.GetVector(vec,"car");
129 //--- Author: Nick van Eijndhoven 01-apr-1999 UU-SAP Utrecht
130 //- Modified: NvE $Date$ UU-SAP Utrecht
131 ///////////////////////////////////////////////////////////////////////////
133 #include "Ali4Vector.h"
135 ClassImp(Ali4Vector) // Class implementation to enable ROOT I/O
137 Ali4Vector::Ali4Vector()
139 // Creation of a contravariant 4-vector and initialisation of parameters.
140 // All values are initialised to 0.
141 // Scalar mode is initially selected.
148 Double_t a[3]={0,0,0};
149 fV.SetVector(a,"sph");
151 ///////////////////////////////////////////////////////////////////////////
152 Ali4Vector::~Ali4Vector()
154 // Destructor to delete dynamically allocated memory
156 ///////////////////////////////////////////////////////////////////////////
157 void Ali4Vector::SetVector(Double_t v0,Ali3Vector v)
159 // Store contravariant vector.
160 // The error on the scalar part is initialised to 0.
161 // The errors on the vector part are taken from the input Ali3Vector.
162 // Scalar mode is automatically selected.
163 // The error on scalar result operations is reset to 0.
167 fV2=pow(v0,2)-fV.Dot(fV);
170 ///////////////////////////////////////////////////////////////////////////
171 void Ali4Vector::SetVector(Double_t* v,TString f)
173 // Store vector according to reference frame f.
174 // All errors are initialised to 0.
175 // Scalar mode is automatically selected.
176 // The error on scalar result operations is reset to 0.
179 for (Int_t i=0; i<3; i++)
185 fV2=pow(fV0,2)-fV.Dot(fV);
190 ///////////////////////////////////////////////////////////////////////////
191 void Ali4Vector::GetVector(Double_t* v,TString f)
193 // Provide 4-vector components according to reference frame f
194 // and according to the current mode.
195 // Scalar mode : The scalar part is directly returned via v[0].
196 // Invariant mode : The scalar part is re-calculated via the value
197 // of the Lorentz invariant and then returned via v[0].
204 v[0]=sqrt(fV.Dot(fV)+fV2);
208 for (Int_t i=0; i<3; i++)
213 ///////////////////////////////////////////////////////////////////////////
214 void Ali4Vector::SetVector(Float_t* v,TString f)
216 // Store vector according to reference frame f.
217 // All errors are initialised to 0.
218 // Scalar mode is automatically selected.
219 // The error on scalar result operations is reset to 0.
221 for (Int_t i=0; i<4; i++)
227 ///////////////////////////////////////////////////////////////////////////
228 void Ali4Vector::GetVector(Float_t* v,TString f)
230 // Provide 4-vector components according to reference frame f
231 // and according to the current mode.
232 // Scalar mode : The scalar part is directly returned via v[0].
233 // Invariant mode : The scalar part is re-calculated via the value
234 // of the Lorentz invariant and then returned via v[0].
237 for (Int_t i=0; i<4; i++)
242 ///////////////////////////////////////////////////////////////////////////
243 Double_t Ali4Vector::GetScalar()
245 // Provide the scalar part.
246 // The error on the scalar value is available via GetResultError()
247 // after invokation of GetScalar().
255 Double_t dot=fV.Dot(fV);
256 Double_t ddot=fV.GetResultError();
257 Double_t v02=dot+fV2;
258 Double_t dv02=sqrt(pow(ddot,2)+pow(fDv2,2));
259 Double_t v0=sqrt(fabs(v02));
261 if (v0) dv0=dv02/(2.*v0);
266 ///////////////////////////////////////////////////////////////////////////
267 Double_t Ali4Vector::GetResultError()
269 // Provide the error on the result of an operation yielding a scalar
270 // E.g. GetScalar(), GetInvariant() or Dot()
273 ///////////////////////////////////////////////////////////////////////////
274 void Ali4Vector::SetScalar(Double_t v0,Double_t dv0)
276 // Modify the scalar part (v0) and its error (dv0).
277 // The default value for dv0 is 0.
278 // The vector part is not modified.
279 // Scalar mode is automatically selected
280 // ==> Lorentz invariant and its error are updated.
281 // The error on scalar result operations is reset to 0.
284 fV2=pow(v0,2)-fV.Dot(fV);
287 ///////////////////////////////////////////////////////////////////////////
288 void Ali4Vector::SetScalarError(Double_t dv0)
290 // Set the error on the scalar part.
291 // If in scalar mode, update error on the invariant accordingly.
292 // The error on scalar result operations is reset to 0.
296 Double_t norm=fV.GetNorm();
297 Double_t dnorm=fV.GetResultError();
298 fDv2=sqrt(pow(2.*fV0*fDv0,2)+pow(2.*norm*dnorm,2));
302 ///////////////////////////////////////////////////////////////////////////
303 void Ali4Vector::Set3Vector(Ali3Vector v)
305 // Set the 3-vector part, the errors are taken from the input Ali3Vector
306 // Scalar mode : The scalar part and its error are not modified,
307 // the Lorentz invariantand its error are re-calculated.
308 // Invariant mode : The Lorentz invariant and its error are not modified,
309 // the scalar part and its error are re-calculated.
310 // The error on scalar result operations is reset to 0.
318 SetInvariant(fV2,fDv2);
321 ///////////////////////////////////////////////////////////////////////////
322 void Ali4Vector::Set3Vector(Double_t* v,TString f)
324 // Set the 3-vector part according to reference frame f
325 // The errors on the vector part are initialised to 0
326 // Scalar mode : The scalar part and its error are not modified,
327 // the Lorentz invariantand its error are re-calculated.
328 // Invariant mode : The Lorentz invariant and its error are not modified,
329 // the scalar part and its error are re-calculated.
330 // The error on scalar result operations is reset to 0.
332 for (Int_t i=0; i<3; i++)
344 SetInvariant(fV2,fDv2);
347 ///////////////////////////////////////////////////////////////////////////
348 void Ali4Vector::Set3Vector(Float_t* v,TString f)
350 // Set the 3-vector part according to reference frame f
351 // The errors on the vector part are initialised to 0
352 // The Lorentz invariant is not modified
353 // The error on scalar result operations is reset to 0.
355 for (Int_t i=0; i<3; i++)
361 ///////////////////////////////////////////////////////////////////////////
362 void Ali4Vector::SetInvariant(Double_t v2,Double_t dv2)
364 // Modify the Lorentz invariant (v2) quantity v^i*v_i and its error (dv2).
365 // The default value for the error dv2 is 0.
366 // The vector part is not modified.
367 // Invariant mode is automatically selected
368 // ==> the scalar part and its error are updated.
369 // The error on scalar result operations is reset to 0.
375 fDv0=GetResultError();
378 ///////////////////////////////////////////////////////////////////////////
379 void Ali4Vector::SetInvariantError(Double_t dv2)
381 // Set the error on the Lorentz invariant.
382 // If in invariant mode, update error on the scalar part accordingly.
383 // The error on scalar result operations is reset to 0.
387 fDv0=GetResultError();
391 ///////////////////////////////////////////////////////////////////////////
392 Double_t Ali4Vector::GetInvariant()
394 // Provide the Lorentz invariant v^i*v_i.
395 // The error on the Lorentz invariant is available via GetResultError()
396 // after invokation of GetInvariant().
404 Double_t inv=Dot(*this);
408 ///////////////////////////////////////////////////////////////////////////
409 Ali3Vector Ali4Vector::Get3Vector()
411 // Provide the 3-vector part
414 ///////////////////////////////////////////////////////////////////////////
415 void Ali4Vector::SetErrors(Double_t* e,TString f)
417 // Store errors for vector v^i according to reference frame f
418 // If in scalar mode, update error on the invariant accordingly.
419 // The error on scalar result operations is reset to 0.
421 for (Int_t i=0; i<3; i++)
425 SetScalarError(e[0]);
428 ///////////////////////////////////////////////////////////////////////////
429 void Ali4Vector::SetErrors(Float_t* e,TString f)
431 // Store errors for vector v^i according to reference frame f
432 // If in scalar mode, update error on the invariant accordingly.
433 // The error on scalar result operations is reset to 0.
435 for (Int_t i=0; i<4; i++)
441 ///////////////////////////////////////////////////////////////////////////
442 void Ali4Vector::GetErrors(Double_t* e,TString f)
444 // Provide errors for vector v^i according to reference frame f
445 // and according to the current mode.
446 // Scalar mode : The error on the scalar part is directly returned via e[0].
447 // Invariant mode : The error on the scalar part is re-calculated via the error
448 // value on the Lorentz invariant and then returned via e[0].
452 e[0]=GetResultError();
453 for (Int_t i=0; i<3; i++)
458 ///////////////////////////////////////////////////////////////////////////
459 void Ali4Vector::GetErrors(Float_t* e,TString f)
461 // Provide errors for vector v^i according to reference frame f
462 // and according to the current mode.
463 // Scalar mode : The error on the scalar part is directly returned via e[0].
464 // Invariant mode : The error on the scalar part is re-calculated via the error
465 // value on the Lorentz invariant and then returned via e[0].
468 for (Int_t i=0; i<4; i++)
473 ///////////////////////////////////////////////////////////////////////////
474 void Ali4Vector::Data(TString f)
476 // Print contravariant vector components and errors according to
477 // reference frame f and according to the current mode.
478 // Scalar mode : The scalar part and its error are directly returned.
479 // Invariant mode : The scalar part and its error are re-calculated via the
480 // value (and error) of the Lorentz invariant.
482 if (f=="car" || f=="sph" || f=="cyl")
484 Double_t vec[4],err[4];
487 Double_t inv=GetInvariant();
488 Double_t dinv=GetResultError();
489 cout << " Contravariant vector in " << f << " coordinates : "
490 << vec[0] << " " << vec[1] << " " << vec[2] << " " << vec[3] << endl;
491 cout << " ------------- Errors in " << f << " coordinates : "
492 << err[0] << " " << err[1] << " " << err[2] << " " << err[3] << endl;
493 cout << " --- Lorentz invariant (v^i*v_i) : " << inv << " error : " << dinv << endl;
497 cout << " *Ali4Vector::Data* Unsupported frame : " << f << endl
498 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
501 ///////////////////////////////////////////////////////////////////////////
502 Double_t Ali4Vector::Dot(Ali4Vector& q)
504 // Provide the dot product of the current vector with vector q
506 Double_t a0=GetScalar();
507 Double_t da0=GetResultError();
508 if ((this) == &q) // Check for special case v.Dot(v)
510 Double_t norm=fV.GetNorm();
511 Double_t dnorm=fV.GetResultError();
512 dotpro=pow(a0,2)-pow(norm,2);
513 fDresult=sqrt(pow(2.*a0*da0,2)+pow(2.*norm*dnorm,2));
517 Double_t b0=q.GetScalar();
518 Double_t db0=q.GetResultError();
519 Ali3Vector b=q.Get3Vector();
521 Double_t dot=fV.Dot(b);
522 Double_t ddot=fV.GetResultError();
526 fDresult=sqrt(pow(b0*da0,2)+pow(a0*db0,2)+pow(ddot,2));
531 ///////////////////////////////////////////////////////////////////////////
532 Ali4Vector Ali4Vector::operator+(Ali4Vector& q)
534 // Add 4-vector q to the current 4-vector
535 // Error propagation is performed automatically
536 Double_t a0=GetScalar();
537 Double_t da0=GetResultError();
538 Ali3Vector a=Get3Vector();
539 Double_t b0=q.GetScalar();
540 Double_t db0=q.GetResultError();
541 Ali3Vector b=q.Get3Vector();
545 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
549 v.SetScalarError(dc0);
552 ///////////////////////////////////////////////////////////////////////////
553 Ali4Vector Ali4Vector::operator-(Ali4Vector& q)
555 // Subtract 4-vector q from the current 4-vector
556 // Error propagation is performed automatically
557 Double_t a0=GetScalar();
558 Double_t da0=GetResultError();
559 Ali3Vector a=Get3Vector();
560 Double_t b0=q.GetScalar();
561 Double_t db0=q.GetResultError();
562 Ali3Vector b=q.Get3Vector();
566 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
570 v.SetScalarError(dc0);
573 ///////////////////////////////////////////////////////////////////////////
574 Ali4Vector Ali4Vector::operator*(Double_t s)
576 // Multiply the current 4-vector with a scalar s
577 // Error propagation is performed automatically
578 Double_t a0=GetScalar();
579 Double_t da0=GetResultError();
580 Ali3Vector a=Get3Vector();
588 v.SetScalarError(da0);
592 ///////////////////////////////////////////////////////////////////////////
593 Ali4Vector Ali4Vector::operator/(Double_t s)
595 // Divide the current vector by a scalar s
596 // Error propagation is performed automatically
598 if (fabs(s)<1.e-20) // Protect against division by 0
600 cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl;
605 Double_t a0=GetScalar();
606 Double_t da0=GetResultError();
607 Ali3Vector a=Get3Vector();
615 v.SetScalarError(da0);
620 ///////////////////////////////////////////////////////////////////////////
621 Ali4Vector& Ali4Vector::operator+=(Ali4Vector& q)
623 // Add 4-vector q to the current 4-vector
624 // Error propagation is performed automatically
625 Double_t a0=GetScalar();
626 Double_t da0=GetResultError();
627 Ali3Vector a=Get3Vector();
628 Double_t b0=q.GetScalar();
629 Double_t db0=q.GetResultError();
630 Ali3Vector b=q.Get3Vector();
634 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
641 ///////////////////////////////////////////////////////////////////////////
642 Ali4Vector& Ali4Vector::operator-=(Ali4Vector& q)
644 // Subtract 4-vector q from the current 4-vector
645 // Error propagation is performed automatically
646 Double_t a0=GetScalar();
647 Double_t da0=GetResultError();
648 Ali3Vector a=Get3Vector();
649 Double_t b0=q.GetScalar();
650 Double_t db0=q.GetResultError();
651 Ali3Vector b=q.Get3Vector();
655 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
662 ///////////////////////////////////////////////////////////////////////////
663 Ali4Vector& Ali4Vector::operator*=(Double_t s)
665 // Multiply the current 4-vector with a scalar s
666 // Error propagation is performed automatically
667 Double_t a0=GetScalar();
668 Double_t da0=GetResultError();
669 Ali3Vector a=Get3Vector();
680 ///////////////////////////////////////////////////////////////////////////
681 Ali4Vector& Ali4Vector::operator/=(Double_t s)
683 // Divide the current vector by a scalar s
684 // Error propagation is performed automatically
686 if (fabs(s)<1.e-20) // Protect against division by 0
688 cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl;
693 Double_t a0=GetScalar();
694 Double_t da0=GetResultError();
695 Ali3Vector a=Get3Vector();
707 ///////////////////////////////////////////////////////////////////////////
708 Int_t Ali4Vector::GetScalarFlag()
710 // Provide the value of the fScalar flag (for internal use only).
713 ///////////////////////////////////////////////////////////////////////////
714 Ali3Vector Ali4Vector::GetVecTrans()
716 // Provide the transverse vector part w.r.t. z-axis.
717 // Error propagation is performed automatically
719 return fV.GetVecTrans();
721 ///////////////////////////////////////////////////////////////////////////
722 Ali3Vector Ali4Vector::GetVecLong()
724 // Provide the longitudinal vector part w.r.t. z-axis.
725 // Error propagation is performed automatically
727 return fV.GetVecLong();
729 ///////////////////////////////////////////////////////////////////////////
730 Double_t Ali4Vector::GetScaTrans()
732 // Provide the "transverse value" of the scalar part w.r.t. z-axis.
733 // This provides a basis for e.g. E_trans calculation.
734 // Note : the returned value is always positive or zero.
735 // The error on the value is available via GetResultError()
736 // after invokation of GetScaTrans().
739 fV.GetVector(a,"sph");
740 fV.GetErrors(ea,"sph");
742 Double_t s=GetScalar();
743 Double_t ds=GetResultError();
747 dst2=pow((sin(a[1])*ds),2)+pow((s*cos(a[1])*ea[1]),2);
752 ///////////////////////////////////////////////////////////////////////////
753 Double_t Ali4Vector::GetScaLong()
755 // Provide the "longitudinal value" of the scalar part w.r.t. z-axis.
756 // This provides a basis for e.g. E_long calculation.
757 // Note : the returned value can also be negative.
758 // The error on the value is available via GetResultError()
759 // after invokation of GetScaLong().
762 fV.GetVector(a,"sph");
763 fV.GetErrors(ea,"sph");
765 Double_t s=GetScalar();
766 Double_t ds=GetResultError();
770 dsl2=pow((cos(a[1])*ds),2)+pow((s*sin(a[1])*ea[1]),2);
775 ///////////////////////////////////////////////////////////////////////////
776 Double_t Ali4Vector::GetPseudoRapidity()
778 // Provide the pseudorapidity value of the vector part w.r.t. z-axis.
779 // The error on the value is available via GetResultError()
780 // after invokation of GetPseudoRapidity().
781 Double_t eta=fV.GetPseudoRapidity();
782 fDresult=fV.GetResultError();
785 ///////////////////////////////////////////////////////////////////////////