CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
SpaceVectorP.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// SpaceVector
7//
8// This is the implementation of the subset of those methods of the Hep3Vector
9// class which originated from the ZOOM SpaceVector class *and* which involve
10// intrinsic properties or propeties relative to a second vector.
11//
12
13#include "CLHEP/Vector/defs.h"
14#include "CLHEP/Vector/ThreeVector.h"
15#include "CLHEP/Vector/ZMxpv.h"
16
17#include <cmath>
18
19namespace CLHEP {
20
21//-********************************
22// - 5 -
23// Intrinsic properties of a vector
24// and properties relative to a direction
25//
26//-********************************
27
28double Hep3Vector::beta() const {
29 double b = std::sqrt(mag2());
30 if (b >= 1) {
31 ZMthrowA (ZMxpvTachyonic(
32 "Beta taken for Hep3Vector of at least unit length"));
33 }
34 return b;
35}
36
37double Hep3Vector::gamma() const {
38 double bbeta = std::sqrt(mag2());
39 if (bbeta == 1) {
40 ZMthrowA (ZMxpvTachyonic(
41 "Gamma taken for Hep3Vector of unit magnitude -- infinite result"));
42 }
43 if (bbeta > 1) {
44 ZMthrowA (ZMxpvTachyonic(
45 "Gamma taken for Hep3Vector of more than unit magnitude -- "
46 "the sqrt function would return NAN" ));
47 }
48 return 1/std::sqrt(1-bbeta*bbeta);
49}
50
51double Hep3Vector::rapidity() const {
52 if (std::fabs(z()) == 1) {
53 ZMthrowC (ZMxpvTachyonic(
54 "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n"
55 "the log should return infinity"));
56 }
57 if (std::fabs(z()) > 1) {
58 ZMthrowA (ZMxpvTachyonic(
59 "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n"
60 "the log would return a NAN" ));
61 }
62 // Want inverse std::tanh(z()):
63 return (.5 * std::log((1+z())/(1-z())) );
64}
65
67 double b = beta();
68 if (b == 1) {
69 ZMthrowA (ZMxpvTachyonic(
70 "Co-linear Rapidity taken for Hep3Vector of unit length -- "
71 "the log should return infinity"));
72 }
73 if (b > 1) {
74 ZMthrowA (ZMxpvTachyonic(
75 "Co-linear Rapidity taken for Hep3Vector of more than unit length -- "
76 "the log would return a NAN" ));
77 }
78 // Want inverse std::tanh(b):
79 return (.5 * std::log((1+b)/(1-b)) );
80}
81
82//-***********************************************
83// Other properties relative to a reference vector
84//-***********************************************
85
87 double mag2v2 = v2.mag2();
88 if (mag2v2 == 0) {
89 ZMthrowA (ZMxpvZeroVector(
90 "Attempt to take projection of vector against zero reference vector "));
91 return project();
92 }
93 return ( v2 * (dot(v2)/mag2v2) );
94}
95
96double Hep3Vector::rapidity(const Hep3Vector & v2) const {
97 double vmag = v2.mag();
98 if ( vmag == 0 ) {
99 ZMthrowA (ZMxpvZeroVector(
100 "Rapidity taken with respect to zero vector" ));
101 return 0;
102 }
103 double z1 = dot(v2)/vmag;
104 if (std::fabs(z1) >= 1) {
105 ZMthrowA (ZMxpvTachyonic(
106 "Rapidity taken for too large a Hep3Vector "
107 "-- would return infinity or NAN"));
108 }
109 // Want inverse std::tanh(z1):
110 return (.5 * std::log((1+z1)/(1-z1)) );
111}
112
113double Hep3Vector::eta(const Hep3Vector & v2) const {
114 // Defined as -std::log ( std::tan ( .5* theta(u) ) );
115 //
116 // Quicker is to use cosTheta:
117 // std::tan (theta/2) = std::sin(theta)/(1 + std::cos(theta))
118
119 double r1 = getR();
120 double v2r = v2.mag();
121 if ( (r1 == 0) || (v2r == 0) ) {
122 ZMthrowA (ZMxpvAmbiguousAngle(
123 "Cannot find pseudorapidity of a zero vector relative to a vector"));
124 return 0.;
125 }
126 double c = dot(v2)/(r1*v2r);
127 if ( c >= 1 ) {
128 c = 1; //-| We don't want to return NAN because of roundoff
129 ZMthrowC (ZMxpvInfinity(
130 "Pseudorapidity of vector relative to parallel vector -- "
131 "will give infinite result"));
132 // We can just go on; tangent will be 0, so
133 // std::log (tangent) will be -INFINITY, so result
134 // will be +INFINITY.
135 }
136 if ( c <= -1 ) {
137 ZMthrowC (ZMxpvInfinity(
138 "Pseudorapidity of vector relative to anti-parallel vector -- "
139 "will give negative infinite result"));
140 //-| We don't want to return NAN because of roundoff
141 return ( negativeInfinity() );
142 // If we just went on, the tangent would be NAN
143 // so return would be NAN. But the proper limit
144 // of tan is +Infinity, so the return should be
145 // -INFINITY.
146 }
147
148 double tangent = std::sqrt (1-c*c) / ( 1 + c );
149 return (- std::log (tangent));
150
151} /* eta (u) */
152
153
154} // namespace CLHEP
#define ZMthrowC(A)
Definition: ZMxpv.h:133
#define ZMthrowA(A)
Definition: ZMxpv.h:128
double beta() const
Definition: SpaceVectorP.cc:28
double z() const
double eta() const
double mag2() const
double getR() const
double dot(const Hep3Vector &) const
double negativeInfinity() const
Definition: SpaceVector.cc:284
double mag() const
double rapidity() const
Definition: SpaceVectorP.cc:51
double coLinearRapidity() const
Definition: SpaceVectorP.cc:66
double gamma() const
Definition: SpaceVectorP.cc:37
Hep3Vector project() const