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"
134 #include "Riostream.h"
136 ClassImp(Ali4Vector) // Class implementation to enable ROOT I/O
138 Ali4Vector::Ali4Vector()
140 // Creation of a contravariant 4-vector and initialisation of parameters.
141 // All values are initialised to 0.
142 // Scalar mode is initially selected.
146 ///////////////////////////////////////////////////////////////////////////
147 Ali4Vector::~Ali4Vector()
149 // Destructor to delete dynamically allocated memory
151 ///////////////////////////////////////////////////////////////////////////
152 Ali4Vector::Ali4Vector(const Ali4Vector& v)
163 ///////////////////////////////////////////////////////////////////////////
164 void Ali4Vector::SetZero()
166 // (Re)set all attributes to zero.
167 // Note : The (de)selection of the scalar mode is not modified.
175 ///////////////////////////////////////////////////////////////////////////
176 void Ali4Vector::SetVector(Double_t v0,Ali3Vector& v)
178 // Store contravariant vector.
179 // The error on the scalar part is initialised to 0.
180 // The errors on the vector part are taken from the input Ali3Vector.
181 // Scalar mode is automatically selected.
182 // The error on scalar result operations is reset to 0.
186 fV2=pow(v0,2)-fV.Dot(fV);
189 ///////////////////////////////////////////////////////////////////////////
190 void Ali4Vector::SetVector(Double_t* v,TString f)
192 // Store vector according to reference frame f.
193 // All errors are initialised to 0.
194 // Scalar mode is automatically selected.
195 // The error on scalar result operations is reset to 0.
198 for (Int_t i=0; i<3; i++)
204 fV2=pow(fV0,2)-fV.Dot(fV);
209 ///////////////////////////////////////////////////////////////////////////
210 void Ali4Vector::GetVector(Double_t* v,TString f)
212 // Provide 4-vector components according to reference frame f
213 // and according to the current mode.
214 // Scalar mode : The scalar part is directly returned via v[0].
215 // Invariant mode : The scalar part is re-calculated via the value
216 // of the Lorentz invariant and then returned via v[0].
223 v[0]=sqrt(fV.Dot(fV)+fV2);
227 for (Int_t i=0; i<3; i++)
232 ///////////////////////////////////////////////////////////////////////////
233 void Ali4Vector::SetVector(Float_t* v,TString f)
235 // Store vector according to reference frame f.
236 // All errors are initialised to 0.
237 // Scalar mode is automatically selected.
238 // The error on scalar result operations is reset to 0.
240 for (Int_t i=0; i<4; i++)
246 ///////////////////////////////////////////////////////////////////////////
247 void Ali4Vector::GetVector(Float_t* v,TString f)
249 // Provide 4-vector components according to reference frame f
250 // and according to the current mode.
251 // Scalar mode : The scalar part is directly returned via v[0].
252 // Invariant mode : The scalar part is re-calculated via the value
253 // of the Lorentz invariant and then returned via v[0].
256 for (Int_t i=0; i<4; i++)
261 ///////////////////////////////////////////////////////////////////////////
262 Double_t Ali4Vector::GetScalar()
264 // Provide the scalar part.
265 // The error on the scalar value is available via GetResultError()
266 // after invokation of GetScalar().
274 Double_t dot=fV.Dot(fV);
275 Double_t ddot=fV.GetResultError();
276 Double_t v02=dot+fV2;
277 Double_t dv02=sqrt(pow(ddot,2)+pow(fDv2,2));
278 Double_t v0=sqrt(fabs(v02));
280 if (v0) dv0=dv02/(2.*v0);
285 ///////////////////////////////////////////////////////////////////////////
286 Double_t Ali4Vector::GetResultError()
288 // Provide the error on the result of an operation yielding a scalar
289 // E.g. GetScalar(), GetInvariant() or Dot()
292 ///////////////////////////////////////////////////////////////////////////
293 void Ali4Vector::SetScalar(Double_t v0,Double_t dv0)
295 // Modify the scalar part (v0) and its error (dv0).
296 // The default value for dv0 is 0.
297 // The vector part is not modified.
298 // Scalar mode is automatically selected
299 // ==> Lorentz invariant and its error are updated.
300 // The error on scalar result operations is reset to 0.
303 fV2=pow(v0,2)-fV.Dot(fV);
306 ///////////////////////////////////////////////////////////////////////////
307 void Ali4Vector::SetScalarError(Double_t dv0)
309 // Set the error on the scalar part.
310 // If in scalar mode, update error on the invariant accordingly.
311 // The error on scalar result operations is reset to 0.
315 Double_t norm=fV.GetNorm();
316 Double_t dnorm=fV.GetResultError();
317 fDv2=sqrt(pow(2.*fV0*fDv0,2)+pow(2.*norm*dnorm,2));
321 ///////////////////////////////////////////////////////////////////////////
322 void Ali4Vector::Set3Vector(Ali3Vector& v)
324 // Set the 3-vector part, the errors are taken from the input Ali3Vector
325 // Scalar mode : The scalar part and its error are not modified,
326 // the Lorentz invariantand its error are re-calculated.
327 // Invariant mode : The Lorentz invariant and its error are not modified,
328 // the scalar part and its error are re-calculated.
329 // The error on scalar result operations is reset to 0.
337 SetInvariant(fV2,fDv2);
340 ///////////////////////////////////////////////////////////////////////////
341 void Ali4Vector::Set3Vector(Double_t* v,TString f)
343 // Set the 3-vector part according to reference frame f
344 // The errors on the vector part are initialised to 0
345 // Scalar mode : The scalar part and its error are not modified,
346 // the Lorentz invariantand its error are re-calculated.
347 // Invariant mode : The Lorentz invariant and its error are not modified,
348 // the scalar part and its error are re-calculated.
349 // The error on scalar result operations is reset to 0.
351 for (Int_t i=0; i<3; i++)
363 SetInvariant(fV2,fDv2);
366 ///////////////////////////////////////////////////////////////////////////
367 void Ali4Vector::Set3Vector(Float_t* v,TString f)
369 // Set the 3-vector part according to reference frame f
370 // The errors on the vector part are initialised to 0
371 // The Lorentz invariant is not modified
372 // The error on scalar result operations is reset to 0.
374 for (Int_t i=0; i<3; i++)
380 ///////////////////////////////////////////////////////////////////////////
381 void Ali4Vector::SetInvariant(Double_t v2,Double_t dv2)
383 // Modify the Lorentz invariant (v2) quantity v^i*v_i and its error (dv2).
384 // The default value for the error dv2 is 0.
385 // The vector part is not modified.
386 // Invariant mode is automatically selected
387 // ==> the scalar part and its error are updated.
388 // The error on scalar result operations is reset to 0.
394 fDv0=GetResultError();
397 ///////////////////////////////////////////////////////////////////////////
398 void Ali4Vector::SetInvariantError(Double_t dv2)
400 // Set the error on the Lorentz invariant.
401 // If in invariant mode, update error on the scalar part accordingly.
402 // The error on scalar result operations is reset to 0.
406 fDv0=GetResultError();
410 ///////////////////////////////////////////////////////////////////////////
411 Double_t Ali4Vector::GetInvariant()
413 // Provide the Lorentz invariant v^i*v_i.
414 // The error on the Lorentz invariant is available via GetResultError()
415 // after invokation of GetInvariant().
423 Double_t inv=Dot(*this);
427 ///////////////////////////////////////////////////////////////////////////
428 Ali3Vector Ali4Vector::Get3Vector()
430 // Provide the 3-vector part
433 ///////////////////////////////////////////////////////////////////////////
434 void Ali4Vector::SetErrors(Double_t* e,TString f)
436 // Store errors for vector v^i according to reference frame f
437 // If in scalar mode, update error on the invariant accordingly.
438 // The error on scalar result operations is reset to 0.
440 for (Int_t i=0; i<3; i++)
444 SetScalarError(e[0]);
447 ///////////////////////////////////////////////////////////////////////////
448 void Ali4Vector::SetErrors(Float_t* e,TString f)
450 // Store errors for vector v^i according to reference frame f
451 // If in scalar mode, update error on the invariant accordingly.
452 // The error on scalar result operations is reset to 0.
454 for (Int_t i=0; i<4; i++)
460 ///////////////////////////////////////////////////////////////////////////
461 void Ali4Vector::GetErrors(Double_t* e,TString f)
463 // Provide errors for vector v^i according to reference frame f
464 // and according to the current mode.
465 // Scalar mode : The error on the scalar part is directly returned via e[0].
466 // Invariant mode : The error on the scalar part is re-calculated via the error
467 // value on the Lorentz invariant and then returned via e[0].
471 e[0]=GetResultError();
472 for (Int_t i=0; i<3; i++)
477 ///////////////////////////////////////////////////////////////////////////
478 void Ali4Vector::GetErrors(Float_t* e,TString f)
480 // Provide errors for vector v^i according to reference frame f
481 // and according to the current mode.
482 // Scalar mode : The error on the scalar part is directly returned via e[0].
483 // Invariant mode : The error on the scalar part is re-calculated via the error
484 // value on the Lorentz invariant and then returned via e[0].
487 for (Int_t i=0; i<4; i++)
492 ///////////////////////////////////////////////////////////////////////////
493 void Ali4Vector::Data(TString f)
495 // Print contravariant vector components and errors according to
496 // reference frame f and according to the current mode.
497 // Scalar mode : The scalar part and its error are directly returned.
498 // Invariant mode : The scalar part and its error are re-calculated via the
499 // value (and error) of the Lorentz invariant.
501 if (f=="car" || f=="sph" || f=="cyl")
503 Double_t vec[4],err[4];
506 Double_t inv=GetInvariant();
507 Double_t dinv=GetResultError();
508 cout << " Contravariant vector in " << f.Data() << " coordinates : "
509 << vec[0] << " " << vec[1] << " " << vec[2] << " " << vec[3] << endl;
510 cout << " ------------- Errors in " << f.Data() << " coordinates : "
511 << err[0] << " " << err[1] << " " << err[2] << " " << err[3] << endl;
512 cout << " --- Lorentz invariant (v^i*v_i) : " << inv << " error : " << dinv << endl;
516 cout << " *Ali4Vector::Data* Unsupported frame : " << f.Data() << endl
517 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
520 ///////////////////////////////////////////////////////////////////////////
521 Double_t Ali4Vector::Dot(Ali4Vector& q)
523 // Provide the dot product of the current vector with vector q
525 Double_t a0=GetScalar();
526 Double_t da0=GetResultError();
527 if ((this) == &q) // Check for special case v.Dot(v)
529 Double_t norm=fV.GetNorm();
530 Double_t dnorm=fV.GetResultError();
531 dotpro=pow(a0,2)-pow(norm,2);
532 fDresult=sqrt(pow(2.*a0*da0,2)+pow(2.*norm*dnorm,2));
536 Double_t b0=q.GetScalar();
537 Double_t db0=q.GetResultError();
538 Ali3Vector b=q.Get3Vector();
540 Double_t dot=fV.Dot(b);
541 Double_t ddot=fV.GetResultError();
545 fDresult=sqrt(pow(b0*da0,2)+pow(a0*db0,2)+pow(ddot,2));
550 ///////////////////////////////////////////////////////////////////////////
551 Ali4Vector Ali4Vector::operator+(Ali4Vector& q)
553 // Add 4-vector q to the current 4-vector
554 // Error propagation is performed automatically
555 Double_t a0=GetScalar();
556 Double_t da0=GetResultError();
557 Ali3Vector a=Get3Vector();
558 Double_t b0=q.GetScalar();
559 Double_t db0=q.GetResultError();
560 Ali3Vector b=q.Get3Vector();
564 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
568 v.SetScalarError(dc0);
571 ///////////////////////////////////////////////////////////////////////////
572 Ali4Vector Ali4Vector::operator-(Ali4Vector& q)
574 // Subtract 4-vector q from the current 4-vector
575 // Error propagation is performed automatically
576 Double_t a0=GetScalar();
577 Double_t da0=GetResultError();
578 Ali3Vector a=Get3Vector();
579 Double_t b0=q.GetScalar();
580 Double_t db0=q.GetResultError();
581 Ali3Vector b=q.Get3Vector();
585 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
589 v.SetScalarError(dc0);
592 ///////////////////////////////////////////////////////////////////////////
593 Ali4Vector Ali4Vector::operator*(Double_t s)
595 // Multiply the current 4-vector with a scalar s
596 // Error propagation is performed automatically
597 Double_t a0=GetScalar();
598 Double_t da0=GetResultError();
599 Ali3Vector a=Get3Vector();
607 v.SetScalarError(da0);
611 ///////////////////////////////////////////////////////////////////////////
612 Ali4Vector Ali4Vector::operator/(Double_t s)
614 // Divide the current vector by a scalar s
615 // Error propagation is performed automatically
617 if (fabs(s)<1.e-20) // Protect against division by 0
619 cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl;
624 Double_t a0=GetScalar();
625 Double_t da0=GetResultError();
626 Ali3Vector a=Get3Vector();
634 v.SetScalarError(da0);
639 ///////////////////////////////////////////////////////////////////////////
640 Ali4Vector& Ali4Vector::operator+=(Ali4Vector& q)
642 // Add 4-vector q to the current 4-vector
643 // Error propagation is performed automatically
644 Double_t a0=GetScalar();
645 Double_t da0=GetResultError();
646 Ali3Vector a=Get3Vector();
647 Double_t b0=q.GetScalar();
648 Double_t db0=q.GetResultError();
649 Ali3Vector b=q.Get3Vector();
653 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
660 ///////////////////////////////////////////////////////////////////////////
661 Ali4Vector& Ali4Vector::operator-=(Ali4Vector& q)
663 // Subtract 4-vector q from the current 4-vector
664 // Error propagation is performed automatically
665 Double_t a0=GetScalar();
666 Double_t da0=GetResultError();
667 Ali3Vector a=Get3Vector();
668 Double_t b0=q.GetScalar();
669 Double_t db0=q.GetResultError();
670 Ali3Vector b=q.Get3Vector();
674 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
681 ///////////////////////////////////////////////////////////////////////////
682 Ali4Vector& Ali4Vector::operator*=(Double_t s)
684 // Multiply the current 4-vector with a scalar s
685 // Error propagation is performed automatically
686 Double_t a0=GetScalar();
687 Double_t da0=GetResultError();
688 Ali3Vector a=Get3Vector();
699 ///////////////////////////////////////////////////////////////////////////
700 Ali4Vector& Ali4Vector::operator/=(Double_t s)
702 // Divide the current vector by a scalar s
703 // Error propagation is performed automatically
705 if (fabs(s)<1.e-20) // Protect against division by 0
707 cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl;
712 Double_t a0=GetScalar();
713 Double_t da0=GetResultError();
714 Ali3Vector a=Get3Vector();
726 ///////////////////////////////////////////////////////////////////////////
727 Int_t Ali4Vector::GetScalarFlag()
729 // Provide the value of the fScalar flag (for internal use only).
732 ///////////////////////////////////////////////////////////////////////////
733 Ali3Vector Ali4Vector::GetVecTrans()
735 // Provide the transverse vector part w.r.t. z-axis.
736 // Error propagation is performed automatically
738 return fV.GetVecTrans();
740 ///////////////////////////////////////////////////////////////////////////
741 Ali3Vector Ali4Vector::GetVecLong()
743 // Provide the longitudinal vector part w.r.t. z-axis.
744 // Error propagation is performed automatically
746 return fV.GetVecLong();
748 ///////////////////////////////////////////////////////////////////////////
749 Double_t Ali4Vector::GetScaTrans()
751 // Provide the "transverse value" of the scalar part w.r.t. z-axis.
752 // This provides a basis for e.g. E_trans calculation.
753 // Note : the returned value is always positive or zero.
754 // The error on the value is available via GetResultError()
755 // after invokation of GetScaTrans().
758 fV.GetVector(a,"sph");
759 fV.GetErrors(ea,"sph");
761 Double_t s=GetScalar();
762 Double_t ds=GetResultError();
766 dst2=pow((sin(a[1])*ds),2)+pow((s*cos(a[1])*ea[1]),2);
771 ///////////////////////////////////////////////////////////////////////////
772 Double_t Ali4Vector::GetScaLong()
774 // Provide the "longitudinal value" of the scalar part w.r.t. z-axis.
775 // This provides a basis for e.g. E_long calculation.
776 // Note : the returned value can also be negative.
777 // The error on the value is available via GetResultError()
778 // after invokation of GetScaLong().
781 fV.GetVector(a,"sph");
782 fV.GetErrors(ea,"sph");
784 Double_t s=GetScalar();
785 Double_t ds=GetResultError();
789 dsl2=pow((cos(a[1])*ds),2)+pow((s*sin(a[1])*ea[1]),2);
794 ///////////////////////////////////////////////////////////////////////////
795 Double_t Ali4Vector::GetPseudoRapidity()
797 // Provide the pseudorapidity value of the vector part w.r.t. z-axis.
798 // The error on the value is available via GetResultError()
799 // after invokation of GetPseudoRapidity().
800 Double_t eta=fV.GetPseudoRapidity();
801 fDresult=fV.GetResultError();
804 ///////////////////////////////////////////////////////////////////////////