/*************************************************************************** * * $Id$ * * Author: Brian Lasiuk, Thomas Ullrich, April 1998 *************************************************************************** * * Description: * * Remarks: Since not all compilers support member templates * we have to specialize the templated member on these * platforms. If member templates are not supported the * ST_NO_MEMBER_TEMPLATES flag has to be set. tu. * * In the near future when all compilers can handle member * templates this class should be cleaned up. A lot of * redundant code can be removed as soon as the compilers * are up-to-date. tu * *************************************************************************** * * $Log$ * Revision 1.1.1.1 2007/04/25 15:38:41 panos * Importing the HBT code dir * * Revision 1.1.1.1 2007/03/07 10:14:49 mchojnacki * First version on CVS * * Revision 1.11 2005/09/22 20:09:20 fisyak * Make AliFmLorentzVector persistent * * Revision 1.10 2005/07/06 18:49:56 fisyak * Replace AliFmHelixD, AliFmLorentzVectorD,AliFmLorentzVectorF,AliFmMatrixD,AliFmMatrixF,AliFmPhysicalHelixD,AliFmThreeVectorD,AliFmThreeVectorF by templated version * * Revision 1.9 2005/03/28 06:02:45 perev * Defence FPE added * * Revision 1.8 2003/09/02 17:59:35 perev * gcc 3.2 updates + WarnOff * * Revision 1.7 2003/05/01 19:24:31 ullrich * Corrected problem in boost(). * * Revision 1.6 1999/10/15 15:56:36 ullrich * Changed output format in operator<<, added operator>> * * Revision 1.5 1999/06/04 18:01:36 ullrich * New operators operator() and operator[] which can be used * as lvalues. * * Revision 1.4 1999/04/14 23:12:07 fisyak * Add __CINT__ to handle references * * Revision 1.3 1999/02/17 11:38:36 ullrich * Removed specialization for 'long double'. * * Revision 1.2 1999/02/14 23:11:42 fisyak * Fixes for Rootcint * * Revision 1.1 1999/01/30 03:59:02 fisyak * Root Version of AliFmarClassLibrary * * Revision 1.1 1999/01/23 00:27:52 ullrich * Initial Revision * **************************************************************************/ /*// //// General class for a Lorentz four-vector ///*/ #ifndef ST_LORENTZ_VECTOR_HH #define ST_LORENTZ_VECTOR_HH #include "AliFmThreeVector.h" template class AliFmLorentzVector { public: AliFmLorentzVector(T = 0, T = 0, T = 0, T = 0); virtual ~AliFmLorentzVector(); #ifndef ST_NO_MEMBER_TEMPLATES template AliFmLorentzVector(const AliFmThreeVector&, T); template AliFmLorentzVector(T, const AliFmThreeVector&); template AliFmLorentzVector(const AliFmLorentzVector&); template AliFmLorentzVector& operator=(const AliFmLorentzVector&); // AliFmLorentzVector(const AliFmLorentzVector&); use default // AliFmLorentzVector& operator=(const AliFmLorentzVector&); use default #else AliFmLorentzVector(const AliFmThreeVector&, T); AliFmLorentzVector(T, const AliFmThreeVector&); AliFmLorentzVector(const AliFmLorentzVector&); AliFmLorentzVector(const AliFmThreeVector&, T); AliFmLorentzVector(T, const AliFmThreeVector&); AliFmLorentzVector(const AliFmLorentzVector&); AliFmLorentzVector& operator=(const AliFmLorentzVector&); AliFmLorentzVector& operator=(const AliFmLorentzVector&); #endif T x() const; T y() const; T z() const; T t() const; T px() const; T py() const; T pz() const; T e() const; T operator() (size_t) const; T operator[] (size_t) const; T& operator() (size_t); T& operator[] (size_t); const AliFmThreeVector& vect() const; void SetX(T); void SetY(T); void SetZ(T); void SetPx(T); void SetPy(T); void SetPz(T); void SetE(T); void SetT(T); #ifndef ST_NO_MEMBER_TEMPLATES template void SetVect(const AliFmThreeVector&); #else void SetVect(const AliFmThreeVector&); void SetVect(const AliFmThreeVector&); #endif T Perp() const; T Perp2() const; T PseudoRapidity() const; T Phi() const; T Theta() const; T CosTheta() const; T Plus() const; T Minus() const; T m() const; T m2() const; T mt() const; T mt2() const; T Rapidity() const; #ifndef ST_NO_MEMBER_TEMPLATES template AliFmLorentzVector boost(const AliFmLorentzVector&) const; #else AliFmLorentzVector boost(const AliFmLorentzVector&) const; AliFmLorentzVector boost(const AliFmLorentzVector&) const; #endif AliFmLorentzVector operator- (); AliFmLorentzVector operator+ (); AliFmLorentzVector& operator*= (double); AliFmLorentzVector& operator/= (double); #ifndef ST_NO_MEMBER_TEMPLATES template bool operator == (const AliFmLorentzVector&) const; template bool operator != (const AliFmLorentzVector&) const; template AliFmLorentzVector& operator+= (const AliFmLorentzVector&); template AliFmLorentzVector& operator-= (const AliFmLorentzVector&); #else bool operator == (const AliFmLorentzVector&) const; bool operator != (const AliFmLorentzVector&) const; bool operator == (const AliFmLorentzVector&) const; bool operator != (const AliFmLorentzVector&) const; AliFmLorentzVector& operator+= (const AliFmLorentzVector&); AliFmLorentzVector& operator-= (const AliFmLorentzVector&); AliFmLorentzVector& operator+= (const AliFmLorentzVector&); AliFmLorentzVector& operator-= (const AliFmLorentzVector&); #endif protected: AliFmThreeVector fThreeVector; // The spatial three-vector T fX4; // The fourth components #ifdef __ROOT__ ClassDef(AliFmLorentzVector,3) #endif }; #ifndef __CINT__ // // Implementation of member functions // template AliFmLorentzVector::AliFmLorentzVector(T ax, T ay, T az, T at) : fThreeVector(ax, ay, az), fX4(at) { /* nop */ } template AliFmLorentzVector::~AliFmLorentzVector() { /* nopt */ } template const AliFmThreeVector& AliFmLorentzVector::vect() const { return fThreeVector; } template T AliFmLorentzVector::m2() const { return (fX4*fX4 - fThreeVector*fThreeVector); } template T AliFmLorentzVector::Plus() const { return (e() + pz()); } template T AliFmLorentzVector::Minus() const { return (e() - pz()); } template T AliFmLorentzVector::m() const { T mass2 = m2(); if (mass2 < 0) return -::sqrt(-mass2); else return ::sqrt(mass2); } template T AliFmLorentzVector::mt2() const { return this->Perp2() + m2(); } template T AliFmLorentzVector::mt() const { // // change to more optimal code ? // return e()*e() - pz()*pz(); T massPerp2 = mt2(); if (massPerp2 < 0) return -::sqrt(-massPerp2); else return ::sqrt(massPerp2); } template void AliFmLorentzVector::SetPx(T ax) {fThreeVector.SetX(ax);} template void AliFmLorentzVector::SetPy(T ay) {fThreeVector.SetY(ay);} template void AliFmLorentzVector::SetPz(T az) {fThreeVector.SetZ(az);} template void AliFmLorentzVector::SetX(T ax) {fThreeVector.SetX(ax);} template void AliFmLorentzVector::SetY(T ay) {fThreeVector.SetY(ay);} template void AliFmLorentzVector::SetZ(T az) {fThreeVector.SetZ(az);} template void AliFmLorentzVector::SetT(T at) {fX4 = at;} template void AliFmLorentzVector::SetE(T ae) {fX4 = ae;} template T AliFmLorentzVector::x() const {return fThreeVector.x();} template T AliFmLorentzVector::y() const {return fThreeVector.y();} template T AliFmLorentzVector::z() const {return fThreeVector.z();} template T AliFmLorentzVector::px() const {return fThreeVector.x();} template T AliFmLorentzVector::py() const {return fThreeVector.y();} template T AliFmLorentzVector::pz() const {return fThreeVector.z();} template T AliFmLorentzVector::e() const {return fX4;} template T AliFmLorentzVector::t() const {return fX4;} template T AliFmLorentzVector::Perp() const {return fThreeVector.Perp();} template T AliFmLorentzVector::Perp2() const {return fThreeVector.Perp2();} template T AliFmLorentzVector::PseudoRapidity() const {return fThreeVector.PseudoRapidity();} template T AliFmLorentzVector::Phi() const {return fThreeVector.Phi();} template T AliFmLorentzVector::Theta() const {return fThreeVector.Theta();} template T AliFmLorentzVector::CosTheta() const {return fThreeVector.CosTheta();} template T AliFmLorentzVector::operator() (size_t i) const { if (i < 3) return fThreeVector(i); else if (i == 3) return fX4; else { #ifndef ST_NO_EXCEPTIONS throw out_of_range("AliFmLorentzVector::operator(): bad index"); #else cerr << "AliFmLorentzVector::operator(): bad index." << endl; #endif return 0; } } template T& AliFmLorentzVector::operator() (size_t i) { if (i < 3) return fThreeVector(i); else if (i == 3) return fX4; else { #ifndef ST_NO_EXCEPTIONS throw out_of_range("AliFmLorentzVector::operator(): bad index"); #else cerr << "AliFmLorentzVector::operator(): bad index." << endl; return fX4; #endif } } template T AliFmLorentzVector::operator[] (size_t i) const { if (i < 3) return fThreeVector[i]; else if (i == 3) return fX4; else { #ifndef ST_NO_EXCEPTIONS throw out_of_range("AliFmLorentzVector::operator[]: bad index"); #else cerr << "AliFmLorentzVector::operator[]: bad index." << endl; return 0; #endif } } template T& AliFmLorentzVector::operator[] (size_t i) { if (i < 3) return fThreeVector[i]; else if (i == 3) return fX4; else { #ifndef ST_NO_EXCEPTIONS throw out_of_range("AliFmLorentzVector::operator[]: bad index"); #else cerr << "AliFmLorentzVector::operator[]: bad index." << endl; return fX4; #endif } } template T AliFmLorentzVector::Rapidity() const { return 0.5*::log((fX4+fThreeVector.z())/(fX4-fThreeVector.z())+1e-20); } template AliFmLorentzVector AliFmLorentzVector::operator- () { return AliFmLorentzVector(-fX4,-fThreeVector); } template AliFmLorentzVector AliFmLorentzVector::operator+ () { return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator*= (double c) { fThreeVector *= c; fX4 *= c; return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator/= (double c) { fThreeVector /= c; fX4 /= c; return *this; } #ifndef ST_NO_MEMBER_TEMPLATES #ifndef WIN32 template template AliFmLorentzVector::AliFmLorentzVector(const AliFmThreeVector &vec, T at) : fThreeVector(vec), fX4(at) { /* nop */ } template template AliFmLorentzVector::AliFmLorentzVector(T at, const AliFmThreeVector &vec) : fThreeVector(vec), fX4(at) { /* nop */ } template template AliFmLorentzVector::AliFmLorentzVector(const AliFmLorentzVector &vec) : fThreeVector(vec.vect()), fX4(vec.t()) { /* nop */ } template template AliFmLorentzVector AliFmLorentzVector::boost(const AliFmLorentzVector& pframe) const { T mass = abs(pframe); AliFmThreeVector eta = (-1./mass)*pframe.vect(); // gamma*beta T gamma = fabs(pframe.e())/mass; AliFmThreeVector pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum return AliFmLorentzVector(gamma*this->e() - this->vect()*eta, this->vect() + (gamma-1.)*pl - this->e()*eta); } template template void AliFmLorentzVector::SetVect(const AliFmThreeVector& v) { fThreeVector = v; } template template AliFmLorentzVector& AliFmLorentzVector::operator=(const AliFmLorentzVector& vec) { fThreeVector = vec.vect(); fX4 = vec.t(); return *this; } template template bool AliFmLorentzVector::operator== (const AliFmLorentzVector& v) const { return (fThreeVector == v.vect()) && (fX4 == v.t()); } template template bool AliFmLorentzVector::operator!= (const AliFmLorentzVector& v) const { return !(*this == v); } template template AliFmLorentzVector& AliFmLorentzVector::operator+= (const AliFmLorentzVector& v) { fThreeVector += v.vect(); fX4 += v.t(); return *this; } template template AliFmLorentzVector& AliFmLorentzVector::operator-= (const AliFmLorentzVector& v) { fThreeVector -= v.vect(); fX4 -= v.t(); return *this; } #endif #else template AliFmLorentzVector::AliFmLorentzVector(const AliFmThreeVector &vec, T t) : fThreeVector(vec), fX4(t) { /* nop */ } template AliFmLorentzVector::AliFmLorentzVector(const AliFmThreeVector &vec, T t) : fThreeVector(vec), fX4(t) { /* nop */ } template AliFmLorentzVector::AliFmLorentzVector(T t, const AliFmThreeVector &vec) : fThreeVector(vec), fX4(t) { /* nop */ } template AliFmLorentzVector::AliFmLorentzVector(T t, const AliFmThreeVector &vec) : fThreeVector(vec), fX4(t) { /* nop */ } template AliFmLorentzVector::AliFmLorentzVector(const AliFmLorentzVector &vec) : fThreeVector(vec.vect()), fX4(vec.t()) { /* nop */ } template AliFmLorentzVector::AliFmLorentzVector(const AliFmLorentzVector &vec) : fThreeVector(vec.vect()), fX4(vec.t()) { /* nop */ } template AliFmLorentzVector AliFmLorentzVector::boost(const AliFmLorentzVector& pframe) const { T mass = abs(pframe); AliFmThreeVector eta = (-1./mass)*pframe.vect(); // gamma*beta T gamma = fabs(pframe.e())/mass; AliFmThreeVector pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum return AliFmLorentzVector(gamma*this->e() - this->vect()*eta, this->vect() + (gamma-1.)*pl - this->e()*eta); } template AliFmLorentzVector AliFmLorentzVector::boost(const AliFmLorentzVector& pframe) const { T mass = abs(pframe); AliFmThreeVector eta = (-1./mass)*pframe.vect(); // gamma*beta T gamma = fabs(pframe.e())/mass; AliFmThreeVector pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum return AliFmLorentzVector(gamma*this->e() - this->vect()*eta, this->vect() + (gamma-1.)*pl - this->e()*eta); } template void AliFmLorentzVector::SetVect(const AliFmThreeVector& v) { fThreeVector = v; } template void AliFmLorentzVector::SetVect(const AliFmThreeVector& v) { fThreeVector = v; } template AliFmLorentzVector& AliFmLorentzVector::operator=(const AliFmLorentzVector& vec) { fThreeVector = vec.vect(); fX4 = vec.t(); return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator=(const AliFmLorentzVector& vec) { fThreeVector = vec.vect(); fX4 = vec.t(); return *this; } template bool AliFmLorentzVector::operator== (const AliFmLorentzVector& v) const { return (this->vect() == v.vect()) && (fX4 == v.t()); } template bool AliFmLorentzVector::operator== (const AliFmLorentzVector& v) const { return (fThreeVector == v.vect()) && (fX4 == v.t()); } template bool AliFmLorentzVector::operator!= (const AliFmLorentzVector& v) const { return !(*this == v); } template bool AliFmLorentzVector::operator!= (const AliFmLorentzVector& v) const { return !(*this == v); } template AliFmLorentzVector& AliFmLorentzVector::operator+= (const AliFmLorentzVector& v) { fThreeVector += v.vect(); fX4 += v.t(); return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator+= (const AliFmLorentzVector& v) { fThreeVector += v.vect(); fX4 += v.t(); return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator-= (const AliFmLorentzVector& v) { fThreeVector -= v.vect(); fX4 -= v.t(); return *this; } template AliFmLorentzVector& AliFmLorentzVector::operator-= (const AliFmLorentzVector& v) { fThreeVector -= v.vect(); fX4 -= v.t(); return *this; } #endif // ST_NO_MEMBER_TEMPLATES #endif /* ! __CINT__ */ #ifdef __CINT__ template<> AliFmLorentzVector operator+ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator+ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator+ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator+ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator- (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator- (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator- (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator- (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const double v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const double v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const double v2); template<> AliFmLorentzVector operator* (const AliFmLorentzVector& v1, const double v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const double v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const double v1, const AliFmLorentzVector& v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const double v2); template<> AliFmLorentzVector operator/ (const AliFmLorentzVector& v1, const double v2); template<> istream& operator>> (istream& is, const AliFmLorentzVector& v); template<> ostream& operator<< (ostream& os, const AliFmLorentzVector& v); template<> istream& operator>> (istream& is, const AliFmLorentzVector& v); template<> ostream& operator<< (ostream& os, const AliFmLorentzVector& v); template<> double abs(const AliFmLorentzVector& v); template<> float abs(const AliFmLorentzVector& v); #else // // Non-member operators // template AliFmLorentzVector operator+ (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2) { return AliFmLorentzVector(v1) += v2; } template AliFmLorentzVector operator- (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2) { return AliFmLorentzVector(v1) -= v2; } template T operator* (const AliFmLorentzVector& v1, const AliFmLorentzVector& v2) { return v1.t()*v2.t() - v1.vect()*v2.vect(); } template AliFmLorentzVector operator* (const AliFmLorentzVector& v, double c) { return AliFmLorentzVector(v) *= c; } template AliFmLorentzVector operator* (double c, const AliFmLorentzVector& v) { return AliFmLorentzVector(v) *= c; } template AliFmLorentzVector operator/ (const AliFmLorentzVector& v, X c) { return AliFmLorentzVector(v) /= c; } template ostream& operator<< (ostream& os, const AliFmLorentzVector& v) { return os << v.vect() << "\t\t" << v.t(); } template istream& operator>>(istream& is, AliFmLorentzVector& v) { T x, y, z, t; is >> x >> y >> z >> t; v.SetX(x); v.SetY(y); v.SetZ(z); v.SetT(t); return is; } // // Non-member functions // template T abs(const AliFmLorentzVector& v) {return v.m();} #endif /* __CINT__ */ #endif