CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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 #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 
21 namespace CLHEP {
22 
23 //-******************
24 // Metric flexibility
25 //-******************
26 
28  ZMpvMetric_t oldMetric = (metric > 0) ? TimePositive : TimeNegative;
29  if ( a1 == TimeNegative ) {
30  metric = -1.0;
31  } else {
32  metric = 1.0;
33  }
34  return oldMetric;
35 }
36 
38  return ( (metric > 0) ? TimePositive : TimeNegative );
39 }
40 
41 //-********
42 // plus
43 // minus
44 //-********
45 
46 double 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 
56 double 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 
67  return HepLorentzVector (0, 0, 0, (t() < 0.0 ? -m() : m()));
68 }
69 
70 //-********
71 // beta
72 // gamma
73 //-********
74 
75 double 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 std::sqrt (pp.mag2() / (ee*ee)) ;
91 } /* beta */
92 
93 double 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./std::sqrt(1. - v2/t2 );
115 } /* gamma */
116 
117 
118 //-***************
119 // rapidity
120 // pseudorapidity
121 // eta
122 //-***************
123 
125  register double z1 = pp.getZ();
126  if (std::fabs(ee) == std::fabs(z1)) {
127  ZMthrowA (ZMxpvInfinity(
128  "rapidity for 4-vector with |E| = |Pz| -- infinite result"));
129  }
130  if (std::fabs(ee) < std::fabs(z1)) {
131  ZMthrowA (ZMxpvSpacelike(
132  "rapidity for spacelike 4-vector with |E| < |Pz| -- undefined"));
133  return 0;
134  }
135  double q = (ee + z1) / (ee - z1);
136  //-| This cannot be negative now, since both numerator
137  //-| and denominator have the same sign as ee.
138  return .5 * std::log(q);
139 } /* rapidity */
140 
141 double 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)/std::sqrt(r);
149  if (std::fabs(ee) == std::fabs(vdotu)) {
150  ZMthrowA (ZMxpvInfinity(
151  "rapidity for 4-vector with |E| = |Pu| -- infinite result"));
152  }
153  if (std::fabs(ee) < std::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 * std::log(q);
160 } /* rapidity(ref) */
161 
163  register double v1 = pp.mag();
164  if (std::fabs(ee) == std::fabs(v1)) {
165  ZMthrowA (ZMxpvInfinity(
166  "co-Linear rapidity for 4-vector with |E| = |P| -- infinite result"));
167  }
168  if (std::fabs(ee) < std::fabs(v1)) {
169  ZMthrowA (ZMxpvSpacelike(
170  "co-linear rapidity for spacelike 4-vector -- undefined"));
171  return 0;
172  }
173  double q = (ee + v1) / (ee - v1);
174  return .5 * std::log(q);
175 } /* rapidity */
176 
177 //-*************
178 // invariantMass
179 //-*************
180 
182  double m1 = invariantMass2(w);
183  if (m1 < 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 ) ? std::sqrt(m1) : - std::sqrt(m1);
205 } /* invariantMass */
206 
207 //-***************
208 // findBoostToCM
209 //-***************
210 
212  return -boostVector();
213 } /* boostToCM() */
214 
216  double t1 = ee + w.ee;
217  Hep3Vector v1 = pp + w.pp;
218  if (t1 == 0) {
219  if (v1.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(v1*(1./t1)); // Yup, 1/0 -- that is how we return infinity
226  }
227  }
228  if (t1*t1 - v1.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(v1 * (-1./t1));
234 } /* boostToCM(w) */
235 
236 } // namespace CLHEP
237 
double invariantMass2() const
double invariantMass() const
double plus() const
double getZ() const
static ZMpvMetric_t setMetric(ZMpvMetric_t a1)
Hep3Vector findBoostToCM() const
double dot(const Hep3Vector &) const
#define ZMthrowC(A)
double rapidity() const
double minus() const
bool isSpacelike() const
double mag2() const
#define ZMthrowA(A)
HepLorentzVector rest4Vector() const
double restMass2() const
double mag() const
static ZMpvMetric_t getMetric()
double coLinearRapidity() const
Hep3Vector boostVector() const
bool isLightlike(double epsilon=tolerance) const