18 #ifndef ROOT_Math_GenVector_LorentzVector
19 #define ROOT_Math_GenVector_LorentzVector 1
58 template<
class CoordSystem >
65 typedef typename CoordSystem::Scalar Scalar;
66 typedef CoordSystem CoordinateType;
71 LorentzVector ( ) : fCoordinates() { }
82 LorentzVector(
const Scalar & a,
86 fCoordinates(a , b, c, d) { }
92 template<
class Coords >
93 explicit LorentzVector(
const LorentzVector<Coords> & v ) :
94 fCoordinates( v.Coordinates() ) { }
100 template<
class ForeignLorentzVector>
101 explicit LorentzVector(
const ForeignLorentzVector & v) :
102 fCoordinates(PxPyPzE4D<Scalar>( v.x(), v.y(), v.z(), v.t() ) ) { }
113 template<
class LAVector >
114 explicit LorentzVector(
const LAVector & v,
size_t index0 ) {
115 fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2], v[index0+3] );
125 template<
class OtherCoords >
126 LorentzVector & operator= (
const LorentzVector<OtherCoords> & v) {
127 fCoordinates = v.Coordinates();
135 template<
class ForeignLorentzVector>
136 LorentzVector & operator = (
const ForeignLorentzVector & v) {
137 SetXYZT( v.x(), v.y(), v.z(), v.t() );
150 template<
class LAVector >
151 LorentzVector & AssignFrom(
const LAVector & v,
size_t index0=0 ) {
152 fCoordinates.SetCoordinates( v[index0], v[index0+1], v[index0+2], v[index0+3] );
162 const CoordSystem & Coordinates()
const {
169 LorentzVector<CoordSystem>& SetCoordinates(
const Scalar src[] ) {
170 fCoordinates.SetCoordinates(src);
177 LorentzVector<CoordSystem>& SetCoordinates( Scalar a, Scalar b, Scalar c, Scalar d ) {
178 fCoordinates.SetCoordinates(a, b, c, d);
192 LorentzVector<CoordSystem>& SetCoordinates( IT begin, IT end ) {
194 LorentzVector<CoordSystem>& SetCoordinates( IT begin, IT ) {
196 IT a = begin; IT b = ++begin; IT c = ++begin; IT d = ++begin;
197 assert (++begin==end);
198 SetCoordinates (*a,*b,*c,*d);
205 void GetCoordinates( Scalar& a, Scalar& b, Scalar& c, Scalar & d )
const
206 { fCoordinates.GetCoordinates(a, b, c, d); }
211 void GetCoordinates( Scalar dest[] )
const
212 { fCoordinates.GetCoordinates(dest); }
219 void GetCoordinates( IT begin, IT end )
const
221 void GetCoordinates( IT begin, IT ) const
223 { IT a = begin; IT b = ++begin; IT c = ++begin; IT d = ++begin;
224 assert (++begin==end);
225 GetCoordinates (*a,*b,*c,*d);
232 void GetCoordinates( IT begin )
const {
234 GetCoordinates (a,b,c,d);
246 LorentzVector<CoordSystem>& SetXYZT (Scalar xx, Scalar yy, Scalar zz, Scalar tt) {
247 fCoordinates.SetPxPyPzE(xx,yy,zz,tt);
250 LorentzVector<CoordSystem>& SetPxPyPzE (Scalar xx, Scalar yy, Scalar zz, Scalar ee) {
251 fCoordinates.SetPxPyPzE(xx,yy,zz,ee);
260 bool operator==(
const LorentzVector & rhs)
const {
261 return fCoordinates==rhs.fCoordinates;
263 bool operator!= (
const LorentzVector & rhs)
const {
264 return !(operator==(rhs));
274 Scalar Px()
const {
return fCoordinates.Px(); }
275 Scalar X()
const {
return fCoordinates.Px(); }
279 Scalar Py()
const {
return fCoordinates.Py(); }
280 Scalar Y()
const {
return fCoordinates.Py(); }
284 Scalar Pz()
const {
return fCoordinates.Pz(); }
285 Scalar Z()
const {
return fCoordinates.Pz(); }
289 Scalar E()
const {
return fCoordinates.E(); }
290 Scalar T()
const {
return fCoordinates.E(); }
295 Scalar M2()
const {
return fCoordinates.M2(); }
301 Scalar M()
const {
return fCoordinates.M();}
305 Scalar R()
const {
return fCoordinates.R(); }
306 Scalar P()
const {
return fCoordinates.R(); }
310 Scalar P2()
const {
return P() * P(); }
314 Scalar Perp2( )
const {
return fCoordinates.Perp2();}
319 Scalar Pt()
const {
return fCoordinates.Pt(); }
320 Scalar Rho()
const {
return fCoordinates.Pt(); }
326 Scalar Mt2()
const {
return fCoordinates.Mt2(); }
332 Scalar Mt()
const {
return fCoordinates.Mt(); }
338 Scalar Et2()
const {
return fCoordinates.Et2(); }
344 Scalar Et()
const {
return fCoordinates.Et(); }
349 Scalar Phi()
const {
return fCoordinates.Phi();}
354 Scalar Theta()
const {
return fCoordinates.Theta(); }
360 Scalar Eta()
const {
return fCoordinates.Eta(); }
366 ::ROOT::Math::DisplacementVector3D<Cartesian3D<Scalar> > Vect()
const {
367 return ::ROOT::Math::DisplacementVector3D<Cartesian3D<Scalar> >( X(), Y(), Z() );
381 template<
class OtherLorentzVector >
382 Scalar Dot(
const OtherLorentzVector & q)
const {
383 return t()*q.t() - x()*q.x() - y()*q.y() - z()*q.z();
392 template<
class OtherLorentzVector >
393 inline LorentzVector & operator += (
const OtherLorentzVector & q)
395 SetXYZT( x() + q.x(), y() + q.y(), z() + q.z(), t() + q.t() );
405 template<
class OtherLorentzVector >
406 LorentzVector & operator -= (
const OtherLorentzVector & q) {
407 SetXYZT( x() - q.x(), y() - q.y(), z() - q.z(), t() - q.t() );
418 template<
class OtherLorentzVector>
419 LorentzVector operator + (
const OtherLorentzVector & v2)
const
421 LorentzVector<CoordinateType> v3(*
this);
433 template<
class OtherLorentzVector>
434 LorentzVector operator - (
const OtherLorentzVector & v2)
const {
435 LorentzVector<CoordinateType> v3(*
this);
445 LorentzVector & operator *= (Scalar a) {
446 fCoordinates.Scale(a);
453 LorentzVector & operator /= (Scalar a) {
454 fCoordinates.Scale(1/a);
463 LorentzVector operator * (
const Scalar & a)
const {
464 LorentzVector tmp(*
this);
474 LorentzVector<CoordSystem> operator / (
const Scalar & a)
const {
475 LorentzVector<CoordSystem> tmp(*
this);
484 LorentzVector operator - ()
const {
487 return operator*( Scalar(-1) );
489 LorentzVector operator + ()
const {
498 Scalar Rapidity()
const {
502 const Scalar ee = E();
503 const Scalar ppz = Pz();
504 return Scalar(0.5) * log((ee + ppz) / (ee - ppz));
510 Scalar ColinearRapidity()
const {
513 const Scalar ee = E();
514 const Scalar pp = P();
515 return Scalar(0.5) * log((ee + pp) / (ee - pp));
521 bool isTimelike( )
const {
522 Scalar ee = E(); Scalar pp = P();
return ee*ee > pp*pp;
528 bool isLightlike( Scalar tolerance
529 = 100*std::numeric_limits<Scalar>::epsilon() )
const {
530 Scalar ee = E(); Scalar pp = P(); Scalar delta = ee-pp;
531 if ( ee==0 )
return pp==0;
532 return delta*delta < tolerance * ee*ee;
538 bool isSpacelike( )
const {
539 Scalar ee = E(); Scalar pp = P();
return ee*ee < pp*pp;
542 typedef DisplacementVector3D< Cartesian3D<Scalar> > BetaVector;
548 BetaVector BoostToCM( )
const {
569 template <
class Other4Vector>
570 BetaVector BoostToCM(
const Other4Vector& v )
const {
571 Scalar eSum = E() + v.E();
572 DisplacementVector3D< Cartesian3D<Scalar> > vecSum = Vect() + v.Vect();
574 if (vecSum.Mag2() == 0) {
579 return BetaVector(vecSum/eSum);
584 return BetaVector (vecSum * (-1./eSum));
592 Scalar Beta()
const {
598 GenVector::Throw (
"LorentzVector::Beta() - beta computed for LorentzVector with t = 0. Return an Infinite result");
603 GenVector::Throw (
"LorentzVector::Beta() - beta computed for non-timelike LorentzVector . Result is physically meaningless" );
610 Scalar Gamma()
const {
611 const Scalar v2 = P2();
612 const Scalar t2 = E() * E();
617 GenVector::Throw (
"LorentzVector::Gamma() - gamma computed for LorentzVector with t = 0. Return a zero result");
622 GenVector::Throw (
"LorentzVector::Gamma() - gamma computed for a spacelike LorentzVector. Imaginary result");
625 else if ( t2 == v2 ) {
626 GenVector::Throw (
"LorentzVector::Gamma() - gamma computed for a lightlike LorentzVector. Infinite result");
628 return Scalar(1) / sqrt(Scalar(1) - v2 / t2);
634 Scalar x()
const {
return fCoordinates.Px(); }
635 Scalar y()
const {
return fCoordinates.Py(); }
636 Scalar z()
const {
return fCoordinates.Pz(); }
637 Scalar t()
const {
return fCoordinates.E(); }
638 Scalar px()
const {
return fCoordinates.Px(); }
639 Scalar py()
const {
return fCoordinates.Py(); }
640 Scalar pz()
const {
return fCoordinates.Pz(); }
641 Scalar e()
const {
return fCoordinates.E(); }
642 Scalar r()
const {
return fCoordinates.R(); }
643 Scalar theta()
const {
return fCoordinates.Theta(); }
644 Scalar phi()
const {
return fCoordinates.Phi(); }
645 Scalar rho()
const {
return fCoordinates.Rho(); }
646 Scalar eta()
const {
return fCoordinates.Eta(); }
647 Scalar pt()
const {
return fCoordinates.Pt(); }
648 Scalar perp2()
const {
return fCoordinates.Perp2(); }
649 Scalar mag2()
const {
return fCoordinates.M2(); }
650 Scalar mag()
const {
return fCoordinates.M(); }
651 Scalar mt()
const {
return fCoordinates.Mt(); }
652 Scalar mt2()
const {
return fCoordinates.Mt2(); }
656 Scalar energy()
const {
return fCoordinates.E(); }
657 Scalar mass()
const {
return fCoordinates.M(); }
658 Scalar mass2()
const {
return fCoordinates.M2(); }
666 LorentzVector<CoordSystem>& SetE ( Scalar a ) { fCoordinates.SetE (a);
return *
this; }
667 LorentzVector<CoordSystem>& SetEta( Scalar a ) { fCoordinates.SetEta(a);
return *
this; }
668 LorentzVector<CoordSystem>& SetM ( Scalar a ) { fCoordinates.SetM (a);
return *
this; }
669 LorentzVector<CoordSystem>& SetPhi( Scalar a ) { fCoordinates.SetPhi(a);
return *
this; }
670 LorentzVector<CoordSystem>& SetPt ( Scalar a ) { fCoordinates.SetPt (a);
return *
this; }
671 LorentzVector<CoordSystem>& SetPx ( Scalar a ) { fCoordinates.SetPx (a);
return *
this; }
672 LorentzVector<CoordSystem>& SetPy ( Scalar a ) { fCoordinates.SetPy (a);
return *
this; }
673 LorentzVector<CoordSystem>& SetPz ( Scalar a ) { fCoordinates.SetPz (a);
return *
this; }
677 CoordSystem fCoordinates;
692 template<
class CoordSystem >
693 inline LorentzVector<CoordSystem>
operator *
694 (
const typename LorentzVector<CoordSystem>::Scalar & a,
695 const LorentzVector<CoordSystem>& v) {
696 LorentzVector<CoordSystem> tmp(v);
703 template<
class char_t,
class traits_t,
class Coords >
705 std::basic_ostream<char_t,traits_t> &
706 operator << ( std::basic_ostream<char_t,traits_t> & os
707 , LorentzVector<Coords>
const & v
712 typename Coords::Scalar a, b, c, d;
713 v.GetCoordinates(a, b, c, d);
715 if( detail::get_manip( os, detail::bitforbit ) ) {
716 detail::set_manip( os, detail::bitforbit,
'\00' );
720 os << detail::get_manip( os, detail::open ) << a
721 << detail::get_manip( os, detail::sep ) << b
722 << detail::get_manip( os, detail::sep ) << c
723 << detail::get_manip( os, detail::sep ) << d
724 << detail::get_manip( os, detail::close );
732 template<
class char_t,
class traits_t,
class Coords >
734 std::basic_istream<char_t,traits_t> &
735 operator >> ( std::basic_istream<char_t,traits_t> & is
736 , LorentzVector<Coords> & v
741 typename Coords::Scalar a, b, c, d;
743 if( detail::get_manip( is, detail::bitforbit ) ) {
744 detail::set_manip( is, detail::bitforbit,
'\00' );
748 detail::require_delim( is, detail::open ); is >> a;
749 detail::require_delim( is, detail::sep ); is >> b;
750 detail::require_delim( is, detail::sep ); is >> c;
751 detail::require_delim( is, detail::sep ); is >> d;
752 detail::require_delim( is, detail::close );
756 v.SetCoordinates(a, b, c, d);
770 template<
typename CoordSystem>
771 std::string printValue(
const ROOT::Math::LorentzVector<CoordSystem> *v)