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

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