1 /***************************************************************************
5 * Author: Brian Lasiuk, Thomas Ullrich, April 1998
6 ***************************************************************************
10 * Remarks: Since not all compilers support member templates
11 * we have to specialize the templated member on these
12 * platforms. If member templates are not supported the
13 * ST_NO_MEMBER_TEMPLATES flag has to be set. tu.
15 * In the near future when all compilers can handle member
16 * templates this class should be cleaned up. A lot of
17 * redundant code can be removed as soon as the compilers
20 ***************************************************************************
23 * Revision 1.1.1.1 2007/04/25 15:38:41 panos
24 * Importing the HBT code dir
26 * Revision 1.1.1.1 2007/03/07 10:14:49 mchojnacki
27 * First version on CVS
29 * Revision 1.11 2005/09/22 20:09:20 fisyak
30 * Make AliFemtoLorentzVector persistent
32 * Revision 1.10 2005/07/06 18:49:56 fisyak
33 * Replace AliFemtoHelixD, AliFemtoLorentzVectorD,AliFemtoLorentzVectorF,AliFemtoMatrixD,AliFemtoMatrixF,AliFemtoPhysicalHelixD,AliFemtoThreeVectorD,AliFemtoThreeVectorF by templated version
35 * Revision 1.9 2005/03/28 06:02:45 perev
38 * Revision 1.8 2003/09/02 17:59:35 perev
39 * gcc 3.2 updates + WarnOff
41 * Revision 1.7 2003/05/01 19:24:31 ullrich
42 * Corrected problem in boost().
44 * Revision 1.6 1999/10/15 15:56:36 ullrich
45 * Changed output format in operator<<, added operator>>
47 * Revision 1.5 1999/06/04 18:01:36 ullrich
48 * New operators operator() and operator[] which can be used
51 * Revision 1.4 1999/04/14 23:12:07 fisyak
52 * Add __CINT__ to handle references
54 * Revision 1.3 1999/02/17 11:38:36 ullrich
55 * Removed specialization for 'long double'.
57 * Revision 1.2 1999/02/14 23:11:42 fisyak
60 * Revision 1.1 1999/01/30 03:59:02 fisyak
61 * Root Version of AliFemtoarClassLibrary
63 * Revision 1.1 1999/01/23 00:27:52 ullrich
66 **************************************************************************/
67 #ifndef ST_LORENTZ_VECTOR_HH
68 #define ST_LORENTZ_VECTOR_HH
70 #include "AliFemtoThreeVector.h"
71 template<class T> class AliFemtoLorentzVector {
73 AliFemtoLorentzVector(T = 0, T = 0, T = 0, T = 0);
74 virtual ~AliFemtoLorentzVector();
76 #ifndef ST_NO_MEMBER_TEMPLATES
77 template<class X> AliFemtoLorentzVector(const AliFemtoThreeVector<X>&, T);
78 template<class X> AliFemtoLorentzVector(T, const AliFemtoThreeVector<X>&);
80 template<class X> AliFemtoLorentzVector(const AliFemtoLorentzVector<X>&);
81 template<class X> AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<X>&);
82 // AliFemtoLorentzVector(const AliFemtoLorentzVector<T>&); use default
83 // AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<T>&); use default
85 AliFemtoLorentzVector(const AliFemtoThreeVector<float>&, T);
86 AliFemtoLorentzVector(T, const AliFemtoThreeVector<float>&);
87 AliFemtoLorentzVector(const AliFemtoLorentzVector<float>&);
89 AliFemtoLorentzVector(const AliFemtoThreeVector<double>&, T);
90 AliFemtoLorentzVector(T, const AliFemtoThreeVector<double>&);
91 AliFemtoLorentzVector(const AliFemtoLorentzVector<double>&);
93 AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<float>&);
94 AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<double>&);
105 T operator() (size_t) const;
106 T operator[] (size_t) const;
108 T& operator() (size_t);
109 T& operator[] (size_t);
111 const AliFemtoThreeVector<T>& vect() const;
122 #ifndef ST_NO_MEMBER_TEMPLATES
123 template <class X> void SetVect(const AliFemtoThreeVector<X>&);
125 void SetVect(const AliFemtoThreeVector<float>&);
126 void SetVect(const AliFemtoThreeVector<double>&);
131 T pseudoRapidity() const;
145 #ifndef ST_NO_MEMBER_TEMPLATES
146 template<class X> AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<X>&) const;
148 AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<float>&) const;
149 AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<double>&) const;
152 AliFemtoLorentzVector<T> operator- ();
153 AliFemtoLorentzVector<T> operator+ ();
154 AliFemtoLorentzVector<T>& operator*= (double);
155 AliFemtoLorentzVector<T>& operator/= (double);
157 #ifndef ST_NO_MEMBER_TEMPLATES
158 template<class X> bool operator == (const AliFemtoLorentzVector<X>&) const;
159 template<class X> bool operator != (const AliFemtoLorentzVector<X>&) const;
160 template<class X> AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<X>&);
161 template<class X> AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<X>&);
163 bool operator == (const AliFemtoLorentzVector<float>&) const;
164 bool operator != (const AliFemtoLorentzVector<float>&) const;
165 bool operator == (const AliFemtoLorentzVector<double>&) const;
166 bool operator != (const AliFemtoLorentzVector<double>&) const;
168 AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<float>&);
169 AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<float>&);
170 AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<double>&);
171 AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<double>&);
175 AliFemtoThreeVector<T> mThreeVector;
178 ClassDef(AliFemtoLorentzVector,3)
183 // Implementation of member functions
186 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T x, T y, T z, T t)
187 : mThreeVector(x, y, z), mX4(t) { /* nop */ }
190 AliFemtoLorentzVector<T>::~AliFemtoLorentzVector() { /* nopt */ }
193 const AliFemtoThreeVector<T>& AliFemtoLorentzVector<T>::vect() const
199 T AliFemtoLorentzVector<T>::m2() const
201 return (mX4*mX4 - mThreeVector*mThreeVector);
205 T AliFemtoLorentzVector<T>::plus() const { return (e() + pz()); }
208 T AliFemtoLorentzVector<T>::minus() const { return (e() - pz()); }
211 T AliFemtoLorentzVector<T>::m() const
215 return -::sqrt(-mass2);
217 return ::sqrt(mass2);
221 T AliFemtoLorentzVector<T>::mt2() const
223 return this->perp2() + m2();
227 T AliFemtoLorentzVector<T>::mt() const
230 // change to more optimal code ?
231 // return e()*e() - pz()*pz();
234 return -::sqrt(-massPerp2);
236 return ::sqrt(massPerp2);
240 void AliFemtoLorentzVector<T>::SetPx(T x) {mThreeVector.SetX(x);}
243 void AliFemtoLorentzVector<T>::SetPy(T y) {mThreeVector.SetY(y);}
246 void AliFemtoLorentzVector<T>::SetPz(T z) {mThreeVector.SetZ(z);}
249 void AliFemtoLorentzVector<T>::SetX(T x) {mThreeVector.SetX(x);}
252 void AliFemtoLorentzVector<T>::SetY(T y) {mThreeVector.SetY(y);}
255 void AliFemtoLorentzVector<T>::SetZ(T z) {mThreeVector.SetZ(z);}
258 void AliFemtoLorentzVector<T>::SetT(T t) {mX4 = t;}
261 void AliFemtoLorentzVector<T>::SetE(T e) {mX4 = e;}
264 T AliFemtoLorentzVector<T>::x() const {return mThreeVector.x();}
267 T AliFemtoLorentzVector<T>::y() const {return mThreeVector.y();}
270 T AliFemtoLorentzVector<T>::z() const {return mThreeVector.z();}
273 T AliFemtoLorentzVector<T>::px() const {return mThreeVector.x();}
276 T AliFemtoLorentzVector<T>::py() const {return mThreeVector.y();}
279 T AliFemtoLorentzVector<T>::pz() const {return mThreeVector.z();}
282 T AliFemtoLorentzVector<T>::e() const {return mX4;}
285 T AliFemtoLorentzVector<T>::t() const {return mX4;}
288 T AliFemtoLorentzVector<T>::perp() const {return mThreeVector.perp();}
291 T AliFemtoLorentzVector<T>::perp2() const {return mThreeVector.perp2();}
294 T AliFemtoLorentzVector<T>::pseudoRapidity() const {return mThreeVector.pseudoRapidity();}
297 T AliFemtoLorentzVector<T>::phi() const {return mThreeVector.phi();}
300 T AliFemtoLorentzVector<T>::theta() const {return mThreeVector.theta();}
303 T AliFemtoLorentzVector<T>::cosTheta() const {return mThreeVector.cosTheta();}
306 T AliFemtoLorentzVector<T>::operator() (size_t i) const
309 return mThreeVector(i);
313 #ifndef ST_NO_EXCEPTIONS
314 throw out_of_range("AliFemtoLorentzVector<T>::operator(): bad index");
316 cerr << "AliFemtoLorentzVector<T>::operator(): bad index." << endl;
323 T& AliFemtoLorentzVector<T>::operator() (size_t i)
326 return mThreeVector(i);
330 #ifndef ST_NO_EXCEPTIONS
331 throw out_of_range("AliFemtoLorentzVector<T>::operator(): bad index");
333 cerr << "AliFemtoLorentzVector<T>::operator(): bad index." << endl;
340 T AliFemtoLorentzVector<T>::operator[] (size_t i) const
343 return mThreeVector[i];
347 #ifndef ST_NO_EXCEPTIONS
348 throw out_of_range("AliFemtoLorentzVector<T>::operator[]: bad index");
350 cerr << "AliFemtoLorentzVector<T>::operator[]: bad index." << endl;
357 T& AliFemtoLorentzVector<T>::operator[] (size_t i)
360 return mThreeVector[i];
364 #ifndef ST_NO_EXCEPTIONS
365 throw out_of_range("AliFemtoLorentzVector<T>::operator[]: bad index");
367 cerr << "AliFemtoLorentzVector<T>::operator[]: bad index." << endl;
374 T AliFemtoLorentzVector<T>::rapidity() const
376 return 0.5*::log((mX4+mThreeVector.z())/(mX4-mThreeVector.z())+1e-20);
380 AliFemtoLorentzVector<T> AliFemtoLorentzVector<T>::operator- ()
382 return AliFemtoLorentzVector<T>(-mX4,-mThreeVector);
386 AliFemtoLorentzVector<T> AliFemtoLorentzVector<T>::operator+ ()
392 AliFemtoLorentzVector<T>& AliFemtoLorentzVector<T>::operator*= (double c)
400 AliFemtoLorentzVector<T>& AliFemtoLorentzVector<T>::operator/= (double c)
407 #ifndef ST_NO_MEMBER_TEMPLATES
412 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<X> &vec, T t)
413 : mThreeVector(vec), mX4(t) { /* nop */ }
417 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<X> &vec)
418 : mThreeVector(vec), mX4(t) { /* nop */ }
422 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<X> &vec)
423 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
427 AliFemtoLorentzVector<T>
428 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<X>& pframe) const
430 T mass = abs(pframe);
431 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
432 T gamma = fabs(pframe.e())/mass;
433 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
434 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
435 this->vect() + (gamma-1.)*pl - this->e()*eta);
440 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<X>& v)
447 AliFemtoLorentzVector<T>&
448 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<X>& vec)
450 mThreeVector = vec.vect();
458 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<X>& v) const
460 return (mThreeVector == v.vect()) && (mX4 == v.t());
466 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<X>& v) const
468 return !(*this == v);
473 AliFemtoLorentzVector<T>&
474 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<X>& v)
476 mThreeVector += v.vect();
483 AliFemtoLorentzVector<T>&
484 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<X>& v)
486 mThreeVector -= v.vect();
495 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<float> &vec, T t)
496 : mThreeVector(vec), mX4(t) { /* nop */ }
499 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<double> &vec, T t)
500 : mThreeVector(vec), mX4(t) { /* nop */ }
503 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<float> &vec)
504 : mThreeVector(vec), mX4(t) { /* nop */ }
507 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<double> &vec)
508 : mThreeVector(vec), mX4(t) { /* nop */ }
511 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<float> &vec)
512 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
515 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<double> &vec)
516 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
519 AliFemtoLorentzVector<T>
520 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<float>& pframe) const
522 T mass = abs(pframe);
523 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
524 T gamma = fabs(pframe.e())/mass;
525 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
526 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
527 this->vect() + (gamma-1.)*pl - this->e()*eta);
531 AliFemtoLorentzVector<T>
532 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<double>& pframe) const
534 T mass = abs(pframe);
535 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
536 T gamma = fabs(pframe.e())/mass;
537 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
538 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
539 this->vect() + (gamma-1.)*pl - this->e()*eta);
543 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<float>& v)
549 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<double>& v)
555 AliFemtoLorentzVector<T>&
556 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<float>& vec)
558 mThreeVector = vec.vect();
564 AliFemtoLorentzVector<T>&
565 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<double>& vec)
567 mThreeVector = vec.vect();
574 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<float>& v) const
576 return (this->vect() == v.vect()) && (mX4 == v.t());
581 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<double>& v) const
583 return (mThreeVector == v.vect()) && (mX4 == v.t());
588 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<float>& v) const
590 return !(*this == v);
595 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<double>& v) const
597 return !(*this == v);
601 AliFemtoLorentzVector<T>&
602 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<float>& v)
604 mThreeVector += v.vect();
610 AliFemtoLorentzVector<T>&
611 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<double>& v)
613 mThreeVector += v.vect();
619 AliFemtoLorentzVector<T>&
620 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<float>& v)
622 mThreeVector -= v.vect();
628 AliFemtoLorentzVector<T>&
629 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<double>& v)
631 mThreeVector -= v.vect();
636 #endif // ST_NO_MEMBER_TEMPLATES
637 #endif /* ! __CINT__ */
639 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
640 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
641 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
642 template<> AliFemtoLorentzVector<float> operator+ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
643 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
644 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
645 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
646 template<> AliFemtoLorentzVector<float> operator- (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
647 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
648 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
649 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
650 template<> AliFemtoLorentzVector<float> operator* (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
651 template<> AliFemtoLorentzVector<double> operator* (const double v1, const AliFemtoLorentzVector<double>& v2);
652 template<> AliFemtoLorentzVector<double> operator* (const double v1, const AliFemtoLorentzVector<float>& v2);
653 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const double v2);
654 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<float>& v1, const double v2);
655 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
656 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
657 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
658 template<> AliFemtoLorentzVector<float> operator/ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
659 template<> AliFemtoLorentzVector<double> operator/ (const double v1, const AliFemtoLorentzVector<double>& v2);
660 template<> AliFemtoLorentzVector<double> operator/ (const double v1, const AliFemtoLorentzVector<float>& v2);
661 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const double v2);
662 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<float>& v1, const double v2);
663 template<> istream& operator>> (istream& is, const AliFemtoLorentzVector<double>& v);
664 template<> ostream& operator<< (ostream& os, const AliFemtoLorentzVector<double>& v);
665 template<> istream& operator>> (istream& is, const AliFemtoLorentzVector<float>& v);
666 template<> ostream& operator<< (ostream& os, const AliFemtoLorentzVector<float>& v);
667 template<> double abs(const AliFemtoLorentzVector<double>& v);
668 template<> float abs(const AliFemtoLorentzVector<float>& v);
671 // Non-member operators
673 template<class T, class X>
674 AliFemtoLorentzVector<T>
675 operator+ (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
677 return AliFemtoLorentzVector<T>(v1) += v2;
680 template<class T, class X>
681 AliFemtoLorentzVector<T>
682 operator- (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
684 return AliFemtoLorentzVector<T>(v1) -= v2;
687 template<class T, class X>
689 operator* (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
691 return v1.t()*v2.t() - v1.vect()*v2.vect();
695 AliFemtoLorentzVector<T>
696 operator* (const AliFemtoLorentzVector<T>& v, double c)
698 return AliFemtoLorentzVector<T>(v) *= c;
702 AliFemtoLorentzVector<T> operator* (double c, const AliFemtoLorentzVector<T>& v)
704 return AliFemtoLorentzVector<T>(v) *= c;
707 template<class T, class X>
708 AliFemtoLorentzVector<T> operator/ (const AliFemtoLorentzVector<T>& v, X c)
710 return AliFemtoLorentzVector<T>(v) /= c;
714 ostream& operator<< (ostream& os, const AliFemtoLorentzVector<T>& v)
716 return os << v.vect() << "\t\t" << v.t();
720 istream& operator>>(istream& is, AliFemtoLorentzVector<T>& v)
723 is >> x >> y >> z >> t;
732 // Non-member functions
735 T abs(const AliFemtoLorentzVector<T>& v) {return v.m();}
737 #endif /* __CINT__ */