]>
Commit | Line | Data |
---|---|---|
da32329d AM |
1 | /////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // Copyright 2010 | |
4 | // | |
5 | // This file is part of starlight. | |
6 | // | |
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. | |
11 | // | |
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. | |
16 | // | |
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/>. | |
19 | // | |
20 | /////////////////////////////////////////////////////////////////////////// | |
21 | // | |
22 | // File and Version Information: | |
23 | // $Rev:: 28 $: revision of last commit | |
24 | // $Author:: bgrube $: author of last commit | |
25 | // $Date:: 2010-12-10 19:30:01 +0100 #$: date of last commit | |
26 | // | |
27 | // Description: | |
28 | // | |
29 | // | |
30 | // | |
31 | /////////////////////////////////////////////////////////////////////////// | |
32 | ||
33 | ||
34 | #ifndef LORENTZVECTOR_H | |
35 | #define LORENTZVECTOR_H | |
36 | ||
37 | ||
38 | #include "vector3.h" | |
39 | #include <vector> | |
40 | ||
41 | ||
42 | class lorentzVector | |
43 | { | |
44 | public: | |
45 | ||
46 | lorentzVector(); | |
47 | virtual ~lorentzVector(); | |
48 | ||
49 | lorentzVector(double x, double y, double z, double t); | |
50 | //lorentzVector(double px, double py, double pz, double e); | |
51 | ||
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); }; | |
54 | ||
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; } | |
59 | ||
60 | lorentzVector& operator +=(const lorentzVector& vec) | |
61 | { | |
62 | fSpaceVec += vec.fSpaceVec; | |
63 | fTime += vec.fTime; | |
64 | return *this; | |
65 | } | |
66 | lorentzVector& operator -=(const lorentzVector& vec) | |
67 | { | |
68 | fSpaceVec -= vec.fSpaceVec; | |
69 | fTime -= vec.fTime; | |
70 | return *this; | |
71 | } | |
72 | ||
73 | double M2() const { return fTime * fTime - fSpaceVec.Mag2(); } | |
74 | double M () const | |
75 | { | |
76 | const double mag2 = M2(); | |
77 | return (mag2 < 0) ? -sqrt(-mag2) : sqrt(mag2); | |
78 | } | |
79 | ||
80 | vector3 BoostVector() const | |
81 | { return vector3(fSpaceVec.X() / fTime, fSpaceVec.Y() / fTime, fSpaceVec.Z() / fTime); } | |
82 | void Boost(const vector3& beta) | |
83 | { | |
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)); | |
92 | } | |
93 | ||
94 | friend std::ostream& operator << (std::ostream& out, | |
95 | const lorentzVector& vec) | |
96 | { | |
97 | out << "(" << vec.GetPx() << ", " << vec.GetPy() << ", " << vec.GetPz() | |
98 | << "; " << vec.GetE() << ")"; | |
99 | return out; | |
100 | } | |
101 | ||
102 | private: | |
103 | ||
104 | vector3 fSpaceVec; | |
105 | double fTime; | |
106 | ||
107 | }; | |
108 | ||
109 | ||
110 | #endif // LORENTZVECTOR_H |