CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // --------------------------------------------------------------------------- 00003 // 00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00005 // 00006 // SpaceVector 00007 // 00008 // This is the implementation of the subset of those methods of the Hep3Vector 00009 // class which originated from the ZOOM SpaceVector class *and* which involve 00010 // intrinsic properties or propeties relative to a second vector. 00011 // 00012 00013 #ifdef GNUPRAGMA 00014 #pragma implementation 00015 #endif 00016 00017 #include "CLHEP/Vector/defs.h" 00018 #include "CLHEP/Vector/ThreeVector.h" 00019 #include "CLHEP/Vector/ZMxpv.h" 00020 00021 #include <cmath> 00022 00023 namespace CLHEP { 00024 00025 //-******************************** 00026 // - 5 - 00027 // Intrinsic properties of a vector 00028 // and properties relative to a direction 00029 // 00030 //-******************************** 00031 00032 double Hep3Vector::beta() const { 00033 double b = std::sqrt(mag2()); 00034 if (b >= 1) { 00035 ZMthrowA (ZMxpvTachyonic( 00036 "Beta taken for Hep3Vector of at least unit length")); 00037 } 00038 return b; 00039 } 00040 00041 double Hep3Vector::gamma() const { 00042 double bbeta = std::sqrt(mag2()); 00043 if (bbeta == 1) { 00044 ZMthrowA (ZMxpvTachyonic( 00045 "Gamma taken for Hep3Vector of unit magnitude -- infinite result")); 00046 } 00047 if (bbeta > 1) { 00048 ZMthrowA (ZMxpvTachyonic( 00049 "Gamma taken for Hep3Vector of more than unit magnitude -- " 00050 "the sqrt function would return NAN" )); 00051 } 00052 return 1/std::sqrt(1-bbeta*bbeta); 00053 } 00054 00055 double Hep3Vector::rapidity() const { 00056 if (std::fabs(dz) == 1) { 00057 ZMthrowC (ZMxpvTachyonic( 00058 "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n" 00059 "the log should return infinity")); 00060 } 00061 if (std::fabs(dz) > 1) { 00062 ZMthrowA (ZMxpvTachyonic( 00063 "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n" 00064 "the log would return a NAN" )); 00065 } 00066 // Want inverse std::tanh(dz): 00067 return (.5 * std::log((1+dz)/(1-dz)) ); 00068 } 00069 00070 double Hep3Vector::coLinearRapidity() const { 00071 double b = beta(); 00072 if (b == 1) { 00073 ZMthrowA (ZMxpvTachyonic( 00074 "Co-linear Rapidity taken for Hep3Vector of unit length -- " 00075 "the log should return infinity")); 00076 } 00077 if (b > 1) { 00078 ZMthrowA (ZMxpvTachyonic( 00079 "Co-linear Rapidity taken for Hep3Vector of more than unit length -- " 00080 "the log would return a NAN" )); 00081 } 00082 // Want inverse std::tanh(b): 00083 return (.5 * std::log((1+b)/(1-b)) ); 00084 } 00085 00086 //-*********************************************** 00087 // Other properties relative to a reference vector 00088 //-*********************************************** 00089 00090 Hep3Vector Hep3Vector::project (const Hep3Vector & v2) const { 00091 double mag2v2 = v2.mag2(); 00092 if (mag2v2 == 0) { 00093 ZMthrowA (ZMxpvZeroVector( 00094 "Attempt to take projection of vector against zero reference vector ")); 00095 return project(); 00096 } 00097 return ( v2 * (dot(v2)/mag2v2) ); 00098 } 00099 00100 double Hep3Vector::rapidity(const Hep3Vector & v2) const { 00101 double vmag = v2.mag(); 00102 if ( vmag == 0 ) { 00103 ZMthrowA (ZMxpvZeroVector( 00104 "Rapidity taken with respect to zero vector" )); 00105 return 0; 00106 } 00107 double z1 = dot(v2)/vmag; 00108 if (std::fabs(z1) >= 1) { 00109 ZMthrowA (ZMxpvTachyonic( 00110 "Rapidity taken for too large a Hep3Vector " 00111 "-- would return infinity or NAN")); 00112 } 00113 // Want inverse std::tanh(z1): 00114 return (.5 * std::log((1+z1)/(1-z1)) ); 00115 } 00116 00117 double Hep3Vector::eta(const Hep3Vector & v2) const { 00118 // Defined as -std::log ( std::tan ( .5* theta(u) ) ); 00119 // 00120 // Quicker is to use cosTheta: 00121 // std::tan (theta/2) = std::sin(theta)/(1 + std::cos(theta)) 00122 00123 double r1 = getR(); 00124 double v2r = v2.mag(); 00125 if ( (r1 == 0) || (v2r == 0) ) { 00126 ZMthrowA (ZMxpvAmbiguousAngle( 00127 "Cannot find pseudorapidity of a zero vector relative to a vector")); 00128 return 0.; 00129 } 00130 double c = dot(v2)/(r1*v2r); 00131 if ( c >= 1 ) { 00132 c = 1; //-| We don't want to return NAN because of roundoff 00133 ZMthrowC (ZMxpvInfinity( 00134 "Pseudorapidity of vector relative to parallel vector -- " 00135 "will give infinite result")); 00136 // We can just go on; tangent will be 0, so 00137 // std::log (tangent) will be -INFINITY, so result 00138 // will be +INFINITY. 00139 } 00140 if ( c <= -1 ) { 00141 ZMthrowC (ZMxpvInfinity( 00142 "Pseudorapidity of vector relative to anti-parallel vector -- " 00143 "will give negative infinite result")); 00144 //-| We don't want to return NAN because of roundoff 00145 return ( negativeInfinity() ); 00146 // If we just went on, the tangent would be NAN 00147 // so return would be NAN. But the proper limit 00148 // of tan is +Infinity, so the return should be 00149 // -INFINITY. 00150 } 00151 00152 double tangent = std::sqrt (1-c*c) / ( 1 + c ); 00153 return (- std::log (tangent)); 00154 00155 } /* eta (u) */ 00156 00157 00158 } // namespace CLHEP