SpaceVectorP.cc

Go to the documentation of this file.
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/ThreeVector.h"
00018 
00019 #include <cmath>
00020 
00021 namespace CLHEP  {
00022 
00023 //-********************************
00024 //              - 5 -
00025 // Intrinsic properties of a vector
00026 // and properties relative to a direction
00027 //
00028 //-********************************
00029 
00030 double Hep3Vector::beta() const {
00031   double b = std::sqrt(mag2());
00032 //  if (b >= 1) {
00033 //    std::cerr << "Hep3Vector::beta() - "
00034 //      << "Beta taken for Hep3Vector of at least unit length" << std::endl;
00035 //  }
00036   return b;
00037 }
00038 
00039 double Hep3Vector::gamma() const {
00040   double bbeta = std::sqrt(mag2());
00041 //  if (bbeta == 1) {
00042 //    std::cerr << "Hep3Vector::gamma() - "
00043 //      << "Gamma taken for Hep3Vector of unit magnitude -- infinite result"
00044 //      << std::endl;
00045 //  }
00046 //  if (bbeta > 1) {
00047 //    std::cerr << "Hep3Vector::gamma() - "
00048 //      << "Gamma taken for Hep3Vector of more than unit magnitude -- \n"
00049 //      << "the sqrt function would return NAN" << std::endl;
00050 //  }
00051   return 1/std::sqrt(1-bbeta*bbeta);
00052 }
00053 
00054 double Hep3Vector::rapidity() const {
00055 //  if (std::fabs(dz) == 1) {
00056 //    std::cerr << "Hep3Vector::rapidity() - "
00057 //      << "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n"
00058 //      << "the log should return infinity" <, std::endl;
00059 //  }
00060 //  if (std::fabs(dz) > 1) {
00061 //    std::cerr << "Hep3Vector::rapidity() - "
00062 //      << "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n"
00063 //      << "the log would return a NAN" << std::endl;
00064 //  }
00065   // Want inverse std::tanh(dz):
00066   return (.5 * std::log((1+dz)/(1-dz)) );
00067 }
00068 
00069 double Hep3Vector::coLinearRapidity() const {
00070   double b = beta();
00071 //  if (b == 1) {
00072 //    std::cerr << "Hep3Vector::coLinearRapidity() - "
00073 //      << "Co-linear Rapidity taken for Hep3Vector of unit length -- \n"
00074 //      << "the log should return infinity" << std::endl;
00075 //  }
00076 //  if (b > 1) {
00077 //    std::cerr << "Hep3Vector::coLinearRapidity() - "
00078 //      << "Co-linear Rapidity taken for Hep3Vector of more than unit length -- \n"
00079 //      << "the log would return a NAN" << std::endl;
00080 //  }
00081   // Want inverse std::tanh(b):
00082   return (.5 * std::log((1+b)/(1-b)) );
00083 }
00084 
00085 //-***********************************************
00086 // Other properties relative to a reference vector
00087 //-***********************************************
00088 
00089 Hep3Vector Hep3Vector::project (const Hep3Vector & v2) const {
00090   double mag2v2 = v2.mag2();
00091   if (mag2v2 == 0) {
00092     std::cerr << "Hep3Vector::project() - "
00093       << "Attempt to take projection of vector against zero reference vector"
00094       << std::endl;
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     std::cerr << "Hep3Vector::rapidity() - "
00104       << "Rapidity taken with respect to zero vector" << std::endl;
00105     return 0;    
00106   }
00107   double z1 = dot(v2)/vmag;
00108 //  if (std::fabs(z1) >= 1) {
00109 //    std::cerr << "Hep3Vector::rapidity() - "
00110 //      << "Rapidity taken for too large a Hep3Vector "
00111 //      << "-- would return infinity or NAN" << std::endl;
00112 //  }
00113   // Want inverse std::tanh(z):
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     std::cerr << "Hep3Vector::eta() - "
00127       << "Cannot find pseudorapidity of a zero vector relative to a vector"
00128       << std::endl;
00129     return 0.;
00130   }
00131   double c  = dot(v2)/(r1*v2r);
00132   if ( c >= 1 ) {
00133     c = 1;      //-| We don't want to return NAN because of roundoff
00134     std::cerr << "Hep3Vector::eta() - "
00135       << "Pseudorapidity of vector relative to parallel vector -- \n"
00136       << "will give infinite result" << std::endl;
00137                             // We can just go on; tangent will be 0, so
00138                             // std::log (tangent) will be -INFINITY, so result
00139                             // will be +INFINITY.
00140   }
00141   if ( c <= -1 ) {
00142     std::cerr << "Hep3Vector::eta() - "
00143       << "Pseudorapidity of vector relative to anti-parallel vector -- \n"
00144       << "will give negative infinite result"<< std::endl;
00145                         //-| We don't want to return NAN because of roundoff
00146     return ( negativeInfinity() );
00147                             //  If we just went on, the tangent would be NAN
00148                             //  so return would be NAN.  But the proper limit
00149                             // of tan is +Infinity, so the return should be
00150                             // -INFINITY.
00151   }
00152 
00153   double tangent = std::sqrt (1-c*c) / ( 1 + c );
00154   return (- std::log (tangent));
00155 
00156 } /* eta (u) */
00157 
00158 
00159 }  // namespace CLHEP

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7