Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // ------------------------------------------- 3 // 4 // This file is a part of the CLHEP - a Class 5 // 6 // SpaceVector 7 // 8 // This is the implementation of the subset of 9 // class which originated from the ZOOM SpaceV 10 // intrinsic properties or propeties relative 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 le 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 40 // << std::endl; 41 // } 42 // if (bbeta > 1) { 43 // std::cerr << "Hep3Vector::gamma() - " 44 // << "Gamma taken for Hep3Vector of more 45 // << "the sqrt function would return NAN 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 54 // << "the log should return infinity" <, 55 // } 56 // if (std::fabs(z()) > 1) { 57 // std::cerr << "Hep3Vector::rapidity() - " 58 // << "Rapidity in Z direction taken for 59 // << "the log would return a NAN" << std 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::coLinearRapidi 69 // << "Co-linear Rapidity taken for Hep3V 70 // << "the log should return infinity" << 71 // } 72 // if (b > 1) { 73 // std::cerr << "Hep3Vector::coLinearRapidi 74 // << "Co-linear Rapidity taken for Hep3V 75 // << "the log would return a NAN" << std 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 ve 83 //-******************************************* 84 85 Hep3Vector Hep3Vector::project (const Hep3Vect 86 double mag2v2 = v2.mag2(); 87 if (mag2v2 == 0) { 88 std::cerr << "Hep3Vector::project() - " 89 << "Attempt to take projection of vector 90 << std::endl; 91 return project(); 92 } 93 return ( v2 * (dot(v2)/mag2v2) ); 94 } 95 96 double Hep3Vector::rapidity(const Hep3Vector & 97 double vmag = v2.mag(); 98 if ( vmag == 0 ) { 99 std::cerr << "Hep3Vector::rapidity() - " 100 << "Rapidity taken with respect to zero 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 Hep 107 // << "-- would return infinity or NAN" < 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) 114 // Defined as -std::log ( std::tan ( .5* 115 // 116 // Quicker is to use cosTheta: 117 // std::tan (theta/2) = std::sin(theta)/(1 + 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 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 b 130 std::cerr << "Hep3Vector::eta() - " 131 << "Pseudorapidity of vector relative to 132 << "will give infinite result" << std::e 133 // We can just go on; tangent will 134 // std::log (tangent) will be -INFIN 135 // will be +INFINITY. 136 } 137 if ( c <= -1 ) { 138 std::cerr << "Hep3Vector::eta() - " 139 << "Pseudorapidity of vector relative to 140 << "will give negative infinite result"< 141 //-| We don't want to return NAN bec 142 return ( negativeInfinity() ); 143 // If we just went on, the tangent 144 // so return would be NAN. But the 145 // of tan is +Infinity, so the retur 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