1 ///////////////////////////////////////////////////////////////////////////
5 // This file is part of starlight.
7 // starlight is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // starlight is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with starlight. If not, see <http://www.gnu.org/licenses/>.
20 ///////////////////////////////////////////////////////////////////////////
22 // File and Version Information:
23 // $Rev:: $: revision of last commit
24 // $Author:: $: author of last commit
25 // $Date:: $: date of last commit
31 ///////////////////////////////////////////////////////////////////////////
34 #ifndef LORENTZVECTOR_H
35 #define LORENTZVECTOR_H
47 virtual ~lorentzVector();
49 lorentzVector(double x, double y, double z, double t);
50 //lorentzVector(double px, double py, double pz, double e);
52 void SetXYZT(double x, double y, double z, double t);
53 void SetPxPyPzE(double px, double py, double pz, double e) { SetXYZT(px, py, pz, e); };
55 double GetPx() const { return fSpaceVec.GetVector()[0]; }
56 double GetPy() const { return fSpaceVec.GetVector()[1]; }
57 double GetPz() const { return fSpaceVec.GetVector()[2]; }
58 double GetE() const { return fTime; }
60 lorentzVector& operator +=(const lorentzVector& vec)
62 fSpaceVec += vec.fSpaceVec;
66 lorentzVector& operator -=(const lorentzVector& vec)
68 fSpaceVec -= vec.fSpaceVec;
73 double M2() const { return fTime * fTime - fSpaceVec.Mag2(); }
76 const double mag2 = M2();
77 return (mag2 < 0) ? -sqrt(-mag2) : sqrt(mag2);
80 vector3 BoostVector() const
81 { return vector3(fSpaceVec.X() / fTime, fSpaceVec.Y() / fTime, fSpaceVec.Z() / fTime); }
82 void Boost(const vector3& beta)
84 const double beta2 = beta.Mag2();
85 const double gamma = 1 / sqrt(1 - beta2);
86 const double betaTimesMom = beta.X() * fSpaceVec.X() + beta.Y() * fSpaceVec.Y() + beta.Z() * fSpaceVec.Z();
87 const double gamma2 = (beta2 > 0) ? (gamma - 1) / beta2 : 0;
88 SetXYZT(fSpaceVec.X() + gamma2 * betaTimesMom * beta.X() + gamma * beta.X() * fTime,
89 fSpaceVec.Y() + gamma2 * betaTimesMom * beta.Y() + gamma * beta.Y() * fTime,
90 fSpaceVec.Z() + gamma2 * betaTimesMom * beta.Z() + gamma * beta.Z() * fTime,
91 gamma * (fTime + betaTimesMom));
94 friend std::ostream& operator << (std::ostream& out,
95 const lorentzVector& vec)
97 out << "(" << vec.GetPx() << ", " << vec.GetPy() << ", " << vec.GetPz()
98 << "; " << vec.GetE() << ")";
110 #endif // LORENTZVECTOR_H