source: trunk/CLHEP/src/LorentzVectorK.cc@ 16

Last change on this file since 16 was 4, checked in by Pavel Demin, 16 years ago

first commit

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