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