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 **************************************************************************/
68 //// General class for a Lorentz four-vector
70 #ifndef ST_LORENTZ_VECTOR_HH
71 #define ST_LORENTZ_VECTOR_HH
73 #include "AliFemtoThreeVector.h"
74 template<class T> class AliFemtoLorentzVector {
76 AliFemtoLorentzVector(T = 0, T = 0, T = 0, T = 0);
77 virtual ~AliFemtoLorentzVector();
79 #ifndef ST_NO_MEMBER_TEMPLATES
80 template<class X> AliFemtoLorentzVector(const AliFemtoThreeVector<X>&, T);
81 template<class X> AliFemtoLorentzVector(T, const AliFemtoThreeVector<X>&);
83 template<class X> AliFemtoLorentzVector(const AliFemtoLorentzVector<X>&);
84 template<class X> AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<X>&);
85 // AliFemtoLorentzVector(const AliFemtoLorentzVector<T>&); use default
86 // AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<T>&); use default
88 AliFemtoLorentzVector(const AliFemtoThreeVector<float>&, T);
89 AliFemtoLorentzVector(T, const AliFemtoThreeVector<float>&);
90 AliFemtoLorentzVector(const AliFemtoLorentzVector<float>&);
92 AliFemtoLorentzVector(const AliFemtoThreeVector<double>&, T);
93 AliFemtoLorentzVector(T, const AliFemtoThreeVector<double>&);
94 AliFemtoLorentzVector(const AliFemtoLorentzVector<double>&);
96 AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<float>&);
97 AliFemtoLorentzVector<T>& operator=(const AliFemtoLorentzVector<double>&);
108 T operator() (size_t) const;
109 T operator[] (size_t) const;
111 T& operator() (size_t);
112 T& operator[] (size_t);
114 const AliFemtoThreeVector<T>& vect() const;
125 #ifndef ST_NO_MEMBER_TEMPLATES
126 template <class X> void SetVect(const AliFemtoThreeVector<X>&);
128 void SetVect(const AliFemtoThreeVector<float>&);
129 void SetVect(const AliFemtoThreeVector<double>&);
134 T PseudoRapidity() const;
148 #ifndef ST_NO_MEMBER_TEMPLATES
149 template<class X> AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<X>&) const;
151 AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<float>&) const;
152 AliFemtoLorentzVector<T> boost(const AliFemtoLorentzVector<double>&) const;
155 AliFemtoLorentzVector<T> operator- ();
156 AliFemtoLorentzVector<T> operator+ ();
157 AliFemtoLorentzVector<T>& operator*= (double);
158 AliFemtoLorentzVector<T>& operator/= (double);
160 #ifndef ST_NO_MEMBER_TEMPLATES
161 template<class X> bool operator == (const AliFemtoLorentzVector<X>&) const;
162 template<class X> bool operator != (const AliFemtoLorentzVector<X>&) const;
163 template<class X> AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<X>&);
164 template<class X> AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<X>&);
166 bool operator == (const AliFemtoLorentzVector<float>&) const;
167 bool operator != (const AliFemtoLorentzVector<float>&) const;
168 bool operator == (const AliFemtoLorentzVector<double>&) const;
169 bool operator != (const AliFemtoLorentzVector<double>&) const;
171 AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<float>&);
172 AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<float>&);
173 AliFemtoLorentzVector<T>& operator+= (const AliFemtoLorentzVector<double>&);
174 AliFemtoLorentzVector<T>& operator-= (const AliFemtoLorentzVector<double>&);
178 AliFemtoThreeVector<T> mThreeVector;
181 ClassDef(AliFemtoLorentzVector,3)
186 // Implementation of member functions
189 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T x, T y, T z, T t)
190 : mThreeVector(x, y, z), mX4(t) { /* nop */ }
193 AliFemtoLorentzVector<T>::~AliFemtoLorentzVector() { /* nopt */ }
196 const AliFemtoThreeVector<T>& AliFemtoLorentzVector<T>::vect() const
202 T AliFemtoLorentzVector<T>::m2() const
204 return (mX4*mX4 - mThreeVector*mThreeVector);
208 T AliFemtoLorentzVector<T>::Plus() const { return (e() + pz()); }
211 T AliFemtoLorentzVector<T>::Minus() const { return (e() - pz()); }
214 T AliFemtoLorentzVector<T>::m() const
218 return -::sqrt(-mass2);
220 return ::sqrt(mass2);
224 T AliFemtoLorentzVector<T>::mt2() const
226 return this->Perp2() + m2();
230 T AliFemtoLorentzVector<T>::mt() const
233 // change to more optimal code ?
234 // return e()*e() - pz()*pz();
237 return -::sqrt(-massPerp2);
239 return ::sqrt(massPerp2);
243 void AliFemtoLorentzVector<T>::SetPx(T x) {mThreeVector.SetX(x);}
246 void AliFemtoLorentzVector<T>::SetPy(T y) {mThreeVector.SetY(y);}
249 void AliFemtoLorentzVector<T>::SetPz(T z) {mThreeVector.SetZ(z);}
252 void AliFemtoLorentzVector<T>::SetX(T x) {mThreeVector.SetX(x);}
255 void AliFemtoLorentzVector<T>::SetY(T y) {mThreeVector.SetY(y);}
258 void AliFemtoLorentzVector<T>::SetZ(T z) {mThreeVector.SetZ(z);}
261 void AliFemtoLorentzVector<T>::SetT(T t) {mX4 = t;}
264 void AliFemtoLorentzVector<T>::SetE(T e) {mX4 = e;}
267 T AliFemtoLorentzVector<T>::x() const {return mThreeVector.x();}
270 T AliFemtoLorentzVector<T>::y() const {return mThreeVector.y();}
273 T AliFemtoLorentzVector<T>::z() const {return mThreeVector.z();}
276 T AliFemtoLorentzVector<T>::px() const {return mThreeVector.x();}
279 T AliFemtoLorentzVector<T>::py() const {return mThreeVector.y();}
282 T AliFemtoLorentzVector<T>::pz() const {return mThreeVector.z();}
285 T AliFemtoLorentzVector<T>::e() const {return mX4;}
288 T AliFemtoLorentzVector<T>::t() const {return mX4;}
291 T AliFemtoLorentzVector<T>::Perp() const {return mThreeVector.Perp();}
294 T AliFemtoLorentzVector<T>::Perp2() const {return mThreeVector.Perp2();}
297 T AliFemtoLorentzVector<T>::PseudoRapidity() const {return mThreeVector.PseudoRapidity();}
300 T AliFemtoLorentzVector<T>::Phi() const {return mThreeVector.Phi();}
303 T AliFemtoLorentzVector<T>::Theta() const {return mThreeVector.Theta();}
306 T AliFemtoLorentzVector<T>::CosTheta() const {return mThreeVector.CosTheta();}
309 T AliFemtoLorentzVector<T>::operator() (size_t i) const
312 return mThreeVector(i);
316 #ifndef ST_NO_EXCEPTIONS
317 throw out_of_range("AliFemtoLorentzVector<T>::operator(): bad index");
319 cerr << "AliFemtoLorentzVector<T>::operator(): bad index." << endl;
326 T& AliFemtoLorentzVector<T>::operator() (size_t i)
329 return mThreeVector(i);
333 #ifndef ST_NO_EXCEPTIONS
334 throw out_of_range("AliFemtoLorentzVector<T>::operator(): bad index");
336 cerr << "AliFemtoLorentzVector<T>::operator(): bad index." << endl;
343 T AliFemtoLorentzVector<T>::operator[] (size_t i) const
346 return mThreeVector[i];
350 #ifndef ST_NO_EXCEPTIONS
351 throw out_of_range("AliFemtoLorentzVector<T>::operator[]: bad index");
353 cerr << "AliFemtoLorentzVector<T>::operator[]: bad index." << endl;
360 T& AliFemtoLorentzVector<T>::operator[] (size_t i)
363 return mThreeVector[i];
367 #ifndef ST_NO_EXCEPTIONS
368 throw out_of_range("AliFemtoLorentzVector<T>::operator[]: bad index");
370 cerr << "AliFemtoLorentzVector<T>::operator[]: bad index." << endl;
377 T AliFemtoLorentzVector<T>::Rapidity() const
379 return 0.5*::log((mX4+mThreeVector.z())/(mX4-mThreeVector.z())+1e-20);
383 AliFemtoLorentzVector<T> AliFemtoLorentzVector<T>::operator- ()
385 return AliFemtoLorentzVector<T>(-mX4,-mThreeVector);
389 AliFemtoLorentzVector<T> AliFemtoLorentzVector<T>::operator+ ()
395 AliFemtoLorentzVector<T>& AliFemtoLorentzVector<T>::operator*= (double c)
403 AliFemtoLorentzVector<T>& AliFemtoLorentzVector<T>::operator/= (double c)
410 #ifndef ST_NO_MEMBER_TEMPLATES
415 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<X> &vec, T t)
416 : mThreeVector(vec), mX4(t) { /* nop */ }
420 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<X> &vec)
421 : mThreeVector(vec), mX4(t) { /* nop */ }
425 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<X> &vec)
426 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
430 AliFemtoLorentzVector<T>
431 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<X>& pframe) const
433 T mass = abs(pframe);
434 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
435 T gamma = fabs(pframe.e())/mass;
436 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
437 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
438 this->vect() + (gamma-1.)*pl - this->e()*eta);
443 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<X>& v)
450 AliFemtoLorentzVector<T>&
451 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<X>& vec)
453 mThreeVector = vec.vect();
461 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<X>& v) const
463 return (mThreeVector == v.vect()) && (mX4 == v.t());
469 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<X>& v) const
471 return !(*this == v);
476 AliFemtoLorentzVector<T>&
477 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<X>& v)
479 mThreeVector += v.vect();
486 AliFemtoLorentzVector<T>&
487 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<X>& v)
489 mThreeVector -= v.vect();
498 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<float> &vec, T t)
499 : mThreeVector(vec), mX4(t) { /* nop */ }
502 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoThreeVector<double> &vec, T t)
503 : mThreeVector(vec), mX4(t) { /* nop */ }
506 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<float> &vec)
507 : mThreeVector(vec), mX4(t) { /* nop */ }
510 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(T t, const AliFemtoThreeVector<double> &vec)
511 : mThreeVector(vec), mX4(t) { /* nop */ }
514 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<float> &vec)
515 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
518 AliFemtoLorentzVector<T>::AliFemtoLorentzVector(const AliFemtoLorentzVector<double> &vec)
519 : mThreeVector(vec.vect()), mX4(vec.t()) { /* nop */ }
522 AliFemtoLorentzVector<T>
523 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<float>& pframe) const
525 T mass = abs(pframe);
526 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
527 T gamma = fabs(pframe.e())/mass;
528 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
529 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
530 this->vect() + (gamma-1.)*pl - this->e()*eta);
534 AliFemtoLorentzVector<T>
535 AliFemtoLorentzVector<T>::boost(const AliFemtoLorentzVector<double>& pframe) const
537 T mass = abs(pframe);
538 AliFemtoThreeVector<T> eta = (-1./mass)*pframe.vect(); // gamma*beta
539 T gamma = fabs(pframe.e())/mass;
540 AliFemtoThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta; // longitudinal momentum
541 return AliFemtoLorentzVector<T>(gamma*this->e() - this->vect()*eta,
542 this->vect() + (gamma-1.)*pl - this->e()*eta);
546 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<float>& v)
552 void AliFemtoLorentzVector<T>::SetVect(const AliFemtoThreeVector<double>& v)
558 AliFemtoLorentzVector<T>&
559 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<float>& vec)
561 mThreeVector = vec.vect();
567 AliFemtoLorentzVector<T>&
568 AliFemtoLorentzVector<T>::operator=(const AliFemtoLorentzVector<double>& vec)
570 mThreeVector = vec.vect();
577 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<float>& v) const
579 return (this->vect() == v.vect()) && (mX4 == v.t());
584 AliFemtoLorentzVector<T>::operator== (const AliFemtoLorentzVector<double>& v) const
586 return (mThreeVector == v.vect()) && (mX4 == v.t());
591 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<float>& v) const
593 return !(*this == v);
598 AliFemtoLorentzVector<T>::operator!= (const AliFemtoLorentzVector<double>& v) const
600 return !(*this == v);
604 AliFemtoLorentzVector<T>&
605 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<float>& v)
607 mThreeVector += v.vect();
613 AliFemtoLorentzVector<T>&
614 AliFemtoLorentzVector<T>::operator+= (const AliFemtoLorentzVector<double>& v)
616 mThreeVector += v.vect();
622 AliFemtoLorentzVector<T>&
623 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<float>& v)
625 mThreeVector -= v.vect();
631 AliFemtoLorentzVector<T>&
632 AliFemtoLorentzVector<T>::operator-= (const AliFemtoLorentzVector<double>& v)
634 mThreeVector -= v.vect();
639 #endif // ST_NO_MEMBER_TEMPLATES
640 #endif /* ! __CINT__ */
642 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
643 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
644 template<> AliFemtoLorentzVector<double> operator+ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
645 template<> AliFemtoLorentzVector<float> operator+ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
646 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
647 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
648 template<> AliFemtoLorentzVector<double> operator- (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
649 template<> AliFemtoLorentzVector<float> operator- (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
650 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
651 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
652 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
653 template<> AliFemtoLorentzVector<float> operator* (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
654 template<> AliFemtoLorentzVector<double> operator* (const double v1, const AliFemtoLorentzVector<double>& v2);
655 template<> AliFemtoLorentzVector<double> operator* (const double v1, const AliFemtoLorentzVector<float>& v2);
656 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<double>& v1, const double v2);
657 template<> AliFemtoLorentzVector<double> operator* (const AliFemtoLorentzVector<float>& v1, const double v2);
658 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<double>& v2);
659 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const AliFemtoLorentzVector<float>& v2);
660 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<double>& v2);
661 template<> AliFemtoLorentzVector<float> operator/ (const AliFemtoLorentzVector<float>& v1, const AliFemtoLorentzVector<float>& v2);
662 template<> AliFemtoLorentzVector<double> operator/ (const double v1, const AliFemtoLorentzVector<double>& v2);
663 template<> AliFemtoLorentzVector<double> operator/ (const double v1, const AliFemtoLorentzVector<float>& v2);
664 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<double>& v1, const double v2);
665 template<> AliFemtoLorentzVector<double> operator/ (const AliFemtoLorentzVector<float>& v1, const double v2);
666 template<> istream& operator>> (istream& is, const AliFemtoLorentzVector<double>& v);
667 template<> ostream& operator<< (ostream& os, const AliFemtoLorentzVector<double>& v);
668 template<> istream& operator>> (istream& is, const AliFemtoLorentzVector<float>& v);
669 template<> ostream& operator<< (ostream& os, const AliFemtoLorentzVector<float>& v);
670 template<> double abs(const AliFemtoLorentzVector<double>& v);
671 template<> float abs(const AliFemtoLorentzVector<float>& v);
674 // Non-member operators
676 template<class T, class X>
677 AliFemtoLorentzVector<T>
678 operator+ (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
680 return AliFemtoLorentzVector<T>(v1) += v2;
683 template<class T, class X>
684 AliFemtoLorentzVector<T>
685 operator- (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
687 return AliFemtoLorentzVector<T>(v1) -= v2;
690 template<class T, class X>
692 operator* (const AliFemtoLorentzVector<T>& v1, const AliFemtoLorentzVector<X>& v2)
694 return v1.t()*v2.t() - v1.vect()*v2.vect();
698 AliFemtoLorentzVector<T>
699 operator* (const AliFemtoLorentzVector<T>& v, double c)
701 return AliFemtoLorentzVector<T>(v) *= c;
705 AliFemtoLorentzVector<T> operator* (double c, const AliFemtoLorentzVector<T>& v)
707 return AliFemtoLorentzVector<T>(v) *= c;
710 template<class T, class X>
711 AliFemtoLorentzVector<T> operator/ (const AliFemtoLorentzVector<T>& v, X c)
713 return AliFemtoLorentzVector<T>(v) /= c;
717 ostream& operator<< (ostream& os, const AliFemtoLorentzVector<T>& v)
719 return os << v.vect() << "\t\t" << v.t();
723 istream& operator>>(istream& is, AliFemtoLorentzVector<T>& v)
726 is >> x >> y >> z >> t;
735 // Non-member functions
738 T abs(const AliFemtoLorentzVector<T>& v) {return v.m();}
740 #endif /* __CINT__ */