CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
LorentzVector.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: LorentzVector.cc,v 1.2 2003/08/13 20:00:14 garren Exp $
3// ---------------------------------------------------------------------------
4//
5// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6//
7// This is the implementation of that portion of the HepLorentzVector class
8// which was in the original CLHEP and which does not force loading of either
9// Rotation.cc or LorentzRotation.cc
10//
11
12#include "CLHEP/Vector/defs.h"
13#include "CLHEP/Vector/LorentzVector.h"
14#include "CLHEP/Vector/ZMxpv.h"
15
16#include <cmath>
17#include <iostream>
18
19namespace CLHEP {
20
21double HepLorentzVector::operator () (int i) const {
22 switch(i) {
23 case X:
24 case Y:
25 case Z:
26 return pp(i);
27 case T:
28 return e();
29 default:
30 std::cerr << "HepLorentzVector subscripting: bad index (" << i << ")"
31 << std::endl;
32 }
33 return 0.;
34}
35
37 static double dummy;
38 switch(i) {
39 case X:
40 case Y:
41 case Z:
42 return pp(i);
43 case T:
44 return ee;
45 default:
46 std::cerr
47 << "HepLorentzVector subscripting: bad index (" << i << ")"
48 << std::endl;
49 return dummy;
50 }
51}
52
54 (double bx, double by, double bz){
55 double b2 = bx*bx + by*by + bz*bz;
56 double ggamma = 1.0 / std::sqrt(1.0 - b2);
57 double bp = bx*x() + by*y() + bz*z();
58 double gamma2 = b2 > 0 ? (ggamma - 1.0)/b2 : 0.0;
59
60 setX(x() + gamma2*bp*bx + ggamma*bx*t());
61 setY(y() + gamma2*bp*by + ggamma*by*t());
62 setZ(z() + gamma2*bp*bz + ggamma*bz*t());
63 setT(ggamma*(t() + bp));
64 return *this;
65}
66
68 pp.rotateX(a);
69 return *this;
70}
72 pp.rotateY(a);
73 return *this;
74}
76 pp.rotateZ(a);
77 return *this;
78}
79
81 pp.rotateUz(v1);
82 return *this;
83}
84
85std::ostream & operator<< (std::ostream & os, const HepLorentzVector & v1)
86{
87 return os << "(" << v1.x() << "," << v1.y() << "," << v1.z()
88 << ";" << v1.t() << ")";
89}
90
91std::istream & operator>> (std::istream & is, HepLorentzVector & v1) {
92
93// Required format is ( a, b, c; d ) that is, four numbers, preceded by
94// (, followed by ), components of the spatial vector separated by commas,
95// time component separated by semicolon. The four numbers are taken
96// as x, y, z, t.
97
98 double x, y, z, t;
99 char c;
100
101 is >> std::ws >> c;
102 // ws is defined to invoke eatwhite(istream & )
103 // see (Stroustrup gray book) page 333 and 345.
104 if (is.fail() || c != '(' ) {
105 std::cerr << "Could not find required opening parenthesis "
106 << "in input of a HepLorentzVector" << std::endl;
107 return is;
108 }
109
110 is >> x >> std::ws >> c;
111 if (is.fail() || c != ',' ) {
112 std::cerr << "Could not find x value and required trailing comma "
113 << "in input of a HepLorentzVector" << std::endl;
114 return is;
115 }
116
117 is >> y >> std::ws >> c;
118 if (is.fail() || c != ',' ) {
119 std::cerr << "Could not find y value and required trailing comma "
120 << "in input of a HepLorentzVector" << std::endl;
121 return is;
122 }
123
124 is >> z >> std::ws >> c;
125 if (is.fail() || c != ';' ) {
126 std::cerr << "Could not find z value and required trailing semicolon "
127 << "in input of a HepLorentzVector" << std::endl;
128 return is;
129 }
130
131 is >> t >> std::ws >> c;
132 if (is.fail() || c != ')' ) {
133 std::cerr << "Could not find t value and required close parenthesis "
134 << "in input of a HepLorentzVector" << std::endl;
135 return is;
136 }
137
138 v1.setX(x);
139 v1.setY(y);
140 v1.setZ(z);
141 v1.setT(t);
142 return is;
143}
144
145// The following were added when ZOOM classes were merged in:
146
148 if (c == 0) {
149 ZMthrowA (ZMxpvInfiniteVector(
150 "Attempt to do LorentzVector /= 0 -- \n"
151 "division by zero would produce infinite or NAN components"));
152 }
153 double oneOverC = 1.0/c;
154 pp *= oneOverC;
155 ee *= oneOverC;
156 return *this;
157} /* w /= c */
158
160if (c == 0) {
161 ZMthrowA (ZMxpvInfiniteVector(
162 "Attempt to do LorentzVector / 0 -- \n"
163 "division by zero would produce infinite or NAN components"));
164 }
165 double oneOverC = 1.0/c;
166 return HepLorentzVector (w.getV() * oneOverC,
167 w.getT() * oneOverC);
168} /* LV = w / c */
169
171 if (ee == 0) {
172 if (pp.mag2() == 0) {
173 return Hep3Vector(0,0,0);
174 } else {
175 ZMthrowA (ZMxpvInfiniteVector(
176 "boostVector computed for LorentzVector with t=0 -- infinite result"));
177 return pp/ee;
178 }
179 }
180 if (restMass2() <= 0) {
181 ZMthrowC (ZMxpvTachyonic(
182 "boostVector computed for a non-timelike LorentzVector "));
183 // result will make analytic sense but is physically meaningless
184 }
185 return pp * (1./ee);
186} /* boostVector */
187
188
190 double b2 = bbeta*bbeta;
191 if (b2 >= 1) {
192 ZMthrowA (ZMxpvTachyonic(
193 "boost along X with beta >= 1 (speed of light) -- no boost done"));
194 } else {
195 double ggamma = std::sqrt(1./(1-b2));
196 double tt = ee;
197 ee = ggamma*(ee + bbeta*pp.getX());
198 pp.setX(ggamma*(pp.getX() + bbeta*tt));
199 }
200 return *this;
201} /* boostX */
202
204 double b2 = bbeta*bbeta;
205 if (b2 >= 1) {
206 ZMthrowA (ZMxpvTachyonic(
207 "boost along Y with beta >= 1 (speed of light) -- \nno boost done"));
208 } else {
209 double ggamma = std::sqrt(1./(1-b2));
210 double tt = ee;
211 ee = ggamma*(ee + bbeta*pp.getY());
212 pp.setY(ggamma*(pp.getY() + bbeta*tt));
213 }
214 return *this;
215} /* boostY */
216
218 double b2 = bbeta*bbeta;
219 if (b2 >= 1) {
220 ZMthrowA (ZMxpvTachyonic(
221 "boost along Z with beta >= 1 (speed of light) -- \nno boost done"));
222 } else {
223 double ggamma = std::sqrt(1./(1-b2));
224 double tt = ee;
225 ee = ggamma*(ee + bbeta*pp.getZ());
226 pp.setZ(ggamma*(pp.getZ() + bbeta*tt));
227 }
228 return *this;
229} /* boostZ */
230
231double HepLorentzVector::setTolerance ( double tol ) {
232// Set the tolerance for two LorentzVectors to be considered near each other
233 double oldTolerance (tolerance);
234 tolerance = tol;
235 return oldTolerance;
236}
237
239// Get the tolerance for two LorentzVectors to be considered near each other
240 return tolerance;
241}
242
243double HepLorentzVector::tolerance =
244 Hep3Vector::ToleranceTicks * 2.22045e-16;
245double HepLorentzVector::metric = 1.0;
246
247
248} // namespace CLHEP
#define ZMthrowC(A)
Definition: ZMxpv.h:133
#define ZMthrowA(A)
Definition: ZMxpv.h:128
Hep3Vector & rotateY(double)
Definition: ThreeVector.cc:100
Hep3Vector & rotateX(double)
Definition: ThreeVector.cc:90
double getZ() const
void setY(double)
double mag2() const
Hep3Vector & rotateZ(double)
Definition: ThreeVector.cc:110
static const int ToleranceTicks
Definition: ThreeVector.h:295
void setZ(double)
double getX() const
void setX(double)
Hep3Vector & rotateUz(const Hep3Vector &)
Definition: ThreeVector.cc:36
double getY() const
Hep3Vector boostVector() const
HepLorentzVector & boost(double, double, double)
HepLorentzVector & boostZ(double beta)
Hep3Vector getV() const
static double setTolerance(double tol)
double restMass2() const
HepLorentzVector & boostX(double beta)
HepLorentzVector & rotateZ(double)
HepLorentzVector & boostY(double beta)
HepLorentzVector & rotateX(double)
HepLorentzVector & operator/=(double)
HepLorentzVector & rotateUz(const Hep3Vector &)
static double getTolerance()
HepLorentzVector & rotateY(double)
double operator()(int) const
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:225
std::ostream & operator<<(std::ostream &s, const HepDiagMatrix &q)
Definition: DiagMatrix.cc:560
HepDiagMatrix operator/(const HepDiagMatrix &hm1, double t)
Definition: DiagMatrix.cc:335