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 
CLHEP::HepLorentzVector::rapidity
double rapidity() const
Definition: LorentzVectorK.cc:124
CLHEP::ZMpvMetric_t
ZMpvMetric_t
Definition: Geometry/CLHEP/Vector/LorentzVector.h:65
CLHEP::HepLorentzVector::HepLorentzVector
HepLorentzVector()
CLHEP::Hep3Vector::dot
double dot(const Hep3Vector &) const
CLHEP::TimeNegative
@ TimeNegative
Definition: Geometry/CLHEP/Vector/LorentzVector.h:65
ee
Signatures of Hep3Vector::rotate For equivalent ZOOM axis There is no harm in leaving this axis CLHEP has implemented a first forming an identity then rotating that by axis and I leave the CLHEP code alone people are of course free to use the ZOOM originated method with signature which I believe will be faster Return types for rotateZ CLHEP and PhysicsVectors each have these three and they are identical except that the ZOOM version returns a reference to while in CLHEP they return void Having methods that alter an object return a reference to that object is convenient for certain chained and costs nothing I don t wish to potentially break ZOOM user code for no good so I have made these CLHEP method conform to this convention There are a couple of other CLHEP rotate and which use the void return but since these methods or signatures don t appear in the original ZOOM this can t break any so I leave the void return type alone for those After discussion with A P and I have modified the return types of other CLHEP methods which return void and would by the same reasoning be better returning *this These include rotate and boost methods in LorentzVector h HepLorentzVector explicit and leads to division by zero if this vector has ee
Definition: minorMergeIssues.doc:140
CLHEP::TimePositive
@ TimePositive
Definition: Geometry/CLHEP/Vector/LorentzVector.h:65
CLHEP::HepLorentzVector::t
double t() const
CLHEP::HepLorentzVector::coLinearRapidity
double coLinearRapidity() const
Definition: LorentzVectorK.cc:162
CLHEP::HepLorentzVector::invariantMass2
double invariantMass2() const
CLHEP::HepLorentzVector::m
double m() const
CLHEP::HepLorentzVector::isSpacelike
bool isSpacelike() const
CLHEP::HepLorentzVector::rest4Vector
HepLorentzVector rest4Vector() const
Definition: LorentzVectorK.cc:66
CLHEP
Definition: ClhepVersion.h:13
CLHEP::HepLorentzVector::plus
double plus() const
CLHEP::Hep3Vector::mag
double mag() const
CLHEP::HepLorentzVector::getMetric
static ZMpvMetric_t getMetric()
Definition: LorentzVectorK.cc:37
Hep3Vector
Issues Concerning the PhysicsVectors CLHEP Vector Merge The merge of ZOOM PhysicsVdectors and the CLHEP Vector package is completed The purpose of this document is to list the major issues that affected the merge of these and where relevant describe the resolutions More detailed documents describe more minor issues General Approach As agreed at the June CLHEP the approach is to combine the features of each ZOOM class with the corresponding CLHEP class expanding the interface to create a single lingua franca of what a Hep3Vector(for example) means. We are not forming SpaceVector as an class derived from Hep3Vector and enhancing it in that way. Another rule imposed by the agreement is to avoid using the Exceptions package(even though that will later go into CLHEP for other uses). A desirable goal is to avoid cluttering the interface and enlarging the code linked in when ordinary CLHEP Vector functionallity is used. To this end
CLHEP::Hep3Vector::mag2
double mag2() const
CLHEP::Hep3Vector
Definition: Geometry/CLHEP/Vector/ThreeVector.h:41
ZMthrowC
#define ZMthrowC(A)
Definition: Geometry/CLHEP/Vector/ZMxpv.h:132
CLHEP::HepLorentzVector::restMass2
double restMass2() const
CLHEP::HepLorentzVector::gamma
double gamma() const
Definition: LorentzVectorK.cc:93
CLHEP::HepLorentzVector::boostVector
Hep3Vector boostVector() const
Definition: LorentzVector.cc:173
CLHEP::HepLorentzVector::minus
double minus() const
CLHEP::HepLorentzVector::beta
double beta() const
Definition: LorentzVectorK.cc:75
CLHEP::HepLorentzVector
Definition: Geometry/CLHEP/Vector/LorentzVector.h:72
CLHEP::HepLorentzVector::setMetric
static ZMpvMetric_t setMetric(ZMpvMetric_t a1)
Definition: LorentzVectorK.cc:27
CLHEP::HepLorentzVector::invariantMass
double invariantMass() const
ZMthrowA
it has advantages For I leave the ZMthrows but substitute I replaced ZMthrow with ZMthrowA in this package ZMthrowA
Definition: keyMergeIssues.doc:69
CLHEP::Hep3Vector::getZ
double getZ() const
CLHEP::HepLorentzVector::isLightlike
bool isLightlike(double epsilon=tolerance) const
CLHEP::HepLorentzVector::findBoostToCM
Hep3Vector findBoostToCM() const
Definition: LorentzVectorK.cc:211