CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
LorentzVectorK.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is part of the implementation of the HepLorentzVector class:
7// Those methods which originated from ZOOM and which deal with relativistic
8// kinematic properties.
9//
10
11#include "CLHEP/Vector/defs.h"
12#include "CLHEP/Vector/LorentzVector.h"
13#include "CLHEP/Vector/ZMxpv.h"
14
15#include <cmath>
16#include <iostream>
17
18namespace CLHEP {
19
20//-******************
21// Metric flexibility
22//-******************
23
25 ZMpvMetric_t oldMetric = (metric > 0) ? TimePositive : TimeNegative;
26 if ( a1 == TimeNegative ) {
27 metric = -1.0;
28 } else {
29 metric = 1.0;
30 }
31 return oldMetric;
32}
33
35 return ( (metric > 0) ? TimePositive : TimeNegative );
36}
37
38//-********
39// plus
40// minus
41//-********
42
43double HepLorentzVector::plus (const Hep3Vector & ref) const {
44 double r = ref.mag();
45 if (r == 0) {
46 ZMthrowA (ZMxpvZeroVector(
47 "A zero vector used as reference to LorentzVector plus-part"));
48 return ee;
49 }
50 return ee + pp.dot(ref)/r;
51} /* plus */
52
53double HepLorentzVector::minus (const Hep3Vector & ref) const {
54 double r = ref.mag();
55 if (r == 0) {
56 ZMthrowA (ZMxpvZeroVector(
57 "A zero vector used as reference to LorentzVector minus-part"));
58 return ee;
59 }
60 return ee - pp.dot(ref)/r;
61} /* plus */
62
64 return HepLorentzVector (0, 0, 0, (t() < 0.0 ? -m() : m()));
65}
66
67//-********
68// beta
69// gamma
70//-********
71
72double HepLorentzVector::beta() const {
73 if (ee == 0) {
74 if (pp.mag2() == 0) {
75 return 0;
76 } else {
77 ZMthrowA (ZMxpvInfiniteVector(
78 "beta computed for HepLorentzVector with t=0 -- infinite result"));
79 return 1./ee;
80 }
81 }
82 if (restMass2() <= 0) {
83 ZMthrowC (ZMxpvTachyonic(
84 "beta computed for a non-timelike HepLorentzVector"));
85 // result will make analytic sense but is physically meaningless
86 }
87 return std::sqrt (pp.mag2() / (ee*ee)) ;
88} /* beta */
89
91 double v2 = pp.mag2();
92 double t2 = ee*ee;
93 if (ee == 0) {
94 if (pp.mag2() == 0) {
95 return 1;
96 } else {
97 ZMthrowC (ZMxpvInfiniteVector(
98 "gamma computed for HepLorentzVector with t=0 -- zero result"));
99 return 0;
100 }
101 }
102 if (t2 < v2) {
103 ZMthrowA (ZMxpvSpacelike(
104 "gamma computed for a spacelike HepLorentzVector -- imaginary result"));
105 // analytic result would be imaginary.
106 return 0;
107 } else if ( t2 == v2 ) {
108 ZMthrowA (ZMxpvInfinity(
109 "gamma computed for a lightlike HepLorentzVector -- infinite result"));
110 }
111 return 1./std::sqrt(1. - v2/t2 );
112} /* gamma */
113
114
115//-***************
116// rapidity
117// pseudorapidity
118// eta
119//-***************
120
122 double z1 = pp.getZ();
123 if (std::fabs(ee) == std::fabs(z1)) {
124 ZMthrowA (ZMxpvInfinity(
125 "rapidity for 4-vector with |E| = |Pz| -- infinite result"));
126 }
127 if (std::fabs(ee) < std::fabs(z1)) {
128 ZMthrowA (ZMxpvSpacelike(
129 "rapidity for spacelike 4-vector with |E| < |Pz| -- undefined"));
130 return 0;
131 }
132 double q = (ee + z1) / (ee - z1);
133 //-| This cannot be negative now, since both numerator
134 //-| and denominator have the same sign as ee.
135 return .5 * std::log(q);
136} /* rapidity */
137
138double HepLorentzVector::rapidity(const Hep3Vector & ref) const {
139 double r = ref.mag2();
140 if (r == 0) {
141 ZMthrowA (ZMxpvZeroVector(
142 "A zero vector used as reference to LorentzVector rapidity"));
143 return 0;
144 }
145 double vdotu = pp.dot(ref)/std::sqrt(r);
146 if (std::fabs(ee) == std::fabs(vdotu)) {
147 ZMthrowA (ZMxpvInfinity(
148 "rapidity for 4-vector with |E| = |Pu| -- infinite result"));
149 }
150 if (std::fabs(ee) < std::fabs(vdotu)) {
151 ZMthrowA (ZMxpvSpacelike(
152 "rapidity for spacelike 4-vector with |E| < |P*ref| -- undefined "));
153 return 0;
154 }
155 double q = (ee + vdotu) / (ee - vdotu);
156 return .5 * std::log(q);
157} /* rapidity(ref) */
158
160 double v1 = pp.mag();
161 if (std::fabs(ee) == std::fabs(v1)) {
162 ZMthrowA (ZMxpvInfinity(
163 "co-Linear rapidity for 4-vector with |E| = |P| -- infinite result"));
164 }
165 if (std::fabs(ee) < std::fabs(v1)) {
166 ZMthrowA (ZMxpvSpacelike(
167 "co-linear rapidity for spacelike 4-vector -- undefined"));
168 return 0;
169 }
170 double q = (ee + v1) / (ee - v1);
171 return .5 * std::log(q);
172} /* rapidity */
173
174//-*************
175// invariantMass
176//-*************
177
179 double m1 = invariantMass2(w);
180 if (m1 < 0) {
181 // We should find out why:
182 if ( ee * w.ee < 0 ) {
183 ZMthrowA (ZMxpvNegativeMass(
184 "invariant mass meaningless: \n"
185 "a negative-mass input led to spacelike 4-vector sum" ));
186 return 0;
187 } else if ( (isSpacelike() && !isLightlike()) ||
188 (w.isSpacelike() && !w.isLightlike()) ) {
189 ZMthrowA (ZMxpvSpacelike(
190 "invariant mass meaningless because of spacelike input"));
191 return 0;
192 } else {
193 // Invariant mass squared for a pair of timelike or lightlike vectors
194 // mathematically cannot be negative. If the vectors are within the
195 // tolerance of being lightlike or timelike, we can assume that prior
196 // or current roundoffs have caused the negative result, and return 0
197 // without comment.
198 return 0;
199 }
200 }
201 return (ee+w.ee >=0 ) ? std::sqrt(m1) : - std::sqrt(m1);
202} /* invariantMass */
203
204//-***************
205// findBoostToCM
206//-***************
207
209 return -boostVector();
210} /* boostToCM() */
211
213 double t1 = ee + w.ee;
214 Hep3Vector v1 = pp + w.pp;
215 if (t1 == 0) {
216 if (v1.mag2() == 0) {
217 return Hep3Vector(0,0,0);
218 } else {
219 ZMthrowA (ZMxpvInfiniteVector(
220 "boostToCM computed for two 4-vectors with combined t=0 -- "
221 "infinite result"));
222 return Hep3Vector(v1*(1./t1)); // Yup, 1/0 -- that is how we return infinity
223 }
224 }
225 if (t1*t1 - v1.mag2() <= 0) {
226 ZMthrowC (ZMxpvTachyonic(
227 "boostToCM computed for pair of HepLorentzVectors with non-timelike sum"));
228 // result will make analytic sense but is physically meaningless
229 }
230 return Hep3Vector(v1 * (-1./t1));
231} /* boostToCM(w) */
232
233} // namespace CLHEP
234
#define ZMthrowC(A)
Definition: ZMxpv.h:133
#define ZMthrowA(A)
Definition: ZMxpv.h:128
double getZ() const
double mag2() const
double dot(const Hep3Vector &) const
double mag() const
double invariantMass() const
Hep3Vector boostVector() const
HepLorentzVector rest4Vector() const
static ZMpvMetric_t getMetric()
double restMass2() const
double minus() const
bool isLightlike(double epsilon=tolerance) const
double invariantMass2() const
double coLinearRapidity() const
Hep3Vector findBoostToCM() const
bool isSpacelike() const
static ZMpvMetric_t setMetric(ZMpvMetric_t a1)
@ TimePositive
Definition: LorentzVector.h:61
@ TimeNegative
Definition: LorentzVector.h:61