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