CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/GeometryVector/interface/oldBasic3DVector.h

Go to the documentation of this file.
00001 #ifndef GeometryVector_oldBasic3DVector_h
00002 #define GeometryVector_oldBasic3DVector_h
00003 #if defined(__CINT__)  && !defined(__REFLEX__)
00004 #define __REFLEX__
00005 #endif
00006 #include "DataFormats/GeometryVector/interface/Basic2DVector.h"
00007 #include "DataFormats/GeometryVector/interface/Theta.h"
00008 #include "DataFormats/GeometryVector/interface/Phi.h"
00009 #include "DataFormats/GeometryVector/interface/PreciseFloatType.h"
00010 #include "DataFormats/GeometryVector/interface/CoordinateSets.h"
00011 #ifndef __REFLEX__ 
00012 #include "DataFormats/Math/interface/SSEVec.h"
00013 #endif
00014 #include <iosfwd>
00015 #include <cmath>
00016 
00017 namespace detailsBasic3DVector {
00018   inline float __attribute__((always_inline)) __attribute__ ((pure))
00019   eta(float x, float y, float z) { float t(z/std::sqrt(x*x+y*y)); return ::asinhf(t);} 
00020   inline double __attribute__((always_inline)) __attribute__ ((pure))
00021   eta(double x, double y, double z) { double t(z/std::sqrt(x*x+y*y)); return ::asinh(t);} 
00022   inline long double __attribute__((always_inline)) __attribute__ ((pure))
00023   eta(long double x, long double y, long double z) { long double t(z/std::sqrt(x*x+y*y)); return ::asinhl(t);} 
00024 }
00025 
00026 
00027 template < typename T> 
00028 class Basic3DVector {
00029 public:
00030 
00031   typedef T                                   ScalarType;
00032   typedef Geom::Cylindrical2Cartesian<T>      Cylindrical;
00033   typedef Geom::Spherical2Cartesian<T>        Spherical;
00034   typedef Spherical                           Polar; // synonym
00035     
00040   Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
00041 
00043   Basic3DVector( const Basic3DVector & p) : 
00044     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00045 
00047   template <class U>
00048   Basic3DVector( const Basic3DVector<U> & p) : 
00049     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00050 
00052   Basic3DVector( const Basic2DVector<T> & p) : 
00053     theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
00054 
00063   template <class OtherPoint> 
00064   explicit Basic3DVector( const OtherPoint& p) : 
00065     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00066 
00067 
00068 #ifndef __REFLEX__
00069   // constructor from Vec4
00070   template<typename U>
00071   Basic3DVector(mathSSE::Vec4<U> const& iv) :
00072     theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
00073 #endif  
00074 
00076   Basic3DVector( const T& x, const T& y, const T& z) : 
00077     theX(x), theY(y), theZ(z), theW(0) {}
00078 
00083   template <typename U>
00084   Basic3DVector( const Geom::Theta<U>& theta, 
00085                  const Geom::Phi<U>& phi, const T& r) {
00086     Polar p( theta.value(), phi.value(), r);
00087     theX = p.x(); theY = p.y(); theZ = p.z();
00088   }
00089 
00091   T x() const { return theX;}
00092 
00094   T y() const { return theY;}
00095 
00097   T z() const { return theZ;}
00098 
00099   Basic2DVector<T> xy() const { return  Basic2DVector<T>(theX,theY);}
00100 
00101 
00102   // equality
00103   bool operator==(const Basic3DVector& rh) const {
00104     return x()==rh.x() && y()==rh.y() && z()==rh.z();
00105   }
00106 
00108   T mag2() const { return  x()*x() + y()*y()+z()*z();}
00109 
00111   T mag() const  { return std::sqrt( mag2());}
00112 
00114   T perp2() const { return x()*x() + y()*y();}
00115 
00117   T perp() const { return std::sqrt( perp2());}
00118 
00120   T transverse() const { return perp();}
00121 
00126   T barePhi() const {return std::atan2(y(),x());}
00127   Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00128 
00133   T bareTheta() const {return std::atan2(perp(),z());}
00134   Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00135 
00140   // T eta() const { return -log( tan( theta()/2.));} 
00141   T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct 
00142 
00146   Basic3DVector unit() const {
00147     T my_mag = mag2();
00148     if (my_mag==0) return *this;
00149     my_mag = T(1)/std::sqrt(my_mag);
00150     return *this * my_mag;
00151   }
00152 
00155   template <class U> 
00156   Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00157     theX += p.x();
00158     theY += p.y();
00159     theZ += p.z();
00160     return *this;
00161   } 
00162 
00165   template <class U> 
00166   Basic3DVector& operator-= ( const Basic3DVector<U>& p) {
00167     theX -= p.x();
00168     theY -= p.y();
00169     theZ -= p.z();
00170     return *this;
00171   } 
00172 
00174   Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00175 
00177   Basic3DVector& operator*= ( T t) {
00178     theX *= t;
00179     theY *= t;
00180     theZ *= t;
00181     return *this;
00182   } 
00183 
00185   Basic3DVector& operator/= ( T t) {
00186     t = T(1)/t;
00187     theX *= t;
00188     theY *= t;   
00189     theZ *= t;
00190     return *this;
00191   } 
00192 
00194   T dot( const Basic3DVector& v) const { 
00195     return x()*v.x() + y()*v.y() + z()*v.z();
00196   }
00197 
00203   template <class U> 
00204   typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const { 
00205     return x()*v.x() + y()*v.y() + z()*v.z();
00206   }
00207 
00209   Basic3DVector cross( const Basic3DVector& v) const {
00210     return Basic3DVector( y()*v.z() - v.y()*z(), 
00211                           z()*v.x() - v.z()*x(), 
00212                           x()*v.y() - v.x()*y());
00213   }
00214 
00215 
00221   template <class U> 
00222   Basic3DVector<typename PreciseFloatType<T,U>::Type> 
00223   cross( const Basic3DVector<U>& v) const {
00224     return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(), 
00225                                                                 z()*v.x() - v.z()*x(), 
00226                                                                 x()*v.y() - v.x()*y());
00227   }
00228 
00229 private:
00230   T theX;
00231   T theY;
00232   T theZ;
00233   T theW;
00234 }  
00235 #ifndef __CINT__
00236 __attribute__ ((aligned (16)))
00237 #endif
00238 ;
00239 
00240 
00241 namespace geometryDetails {
00242   std::ostream & print3D(std::ostream& s, double x, double y, double z);
00243 }
00244 
00246 template <class T>
00247 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
00248   return geometryDetails::print3D(s, v.x(),v.y(), v.z());
00249 }
00250 
00251 
00253 template <class T, class U>
00254 inline Basic3DVector<typename PreciseFloatType<T,U>::Type>
00255 operator+( const Basic3DVector<T>& a, const Basic3DVector<U>& b) {
00256   typedef Basic3DVector<typename PreciseFloatType<T,U>::Type> RT;
00257   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00258 }
00259 
00260 template <class T, class U>
00261 inline Basic3DVector<typename PreciseFloatType<T,U>::Type>
00262 operator-( const Basic3DVector<T>& a, const Basic3DVector<U>& b) {
00263   typedef Basic3DVector<typename PreciseFloatType<T,U>::Type> RT;
00264   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00265 }
00266 
00268 template <class T>
00269 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
00270   return v1.dot(v2);
00271 }
00272 
00274 template <class T, class U>
00275 inline typename PreciseFloatType<T,U>::Type operator*( const Basic3DVector<T>& v1, 
00276                                                        const Basic3DVector<U>& v2) {
00277   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00278 }
00279 
00283 template <class T>
00284 inline Basic3DVector<T> operator*( const Basic3DVector<T>& v, T t) {
00285   return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
00286 }
00287 
00289 template <class T>
00290 inline Basic3DVector<T> operator*(T t, const Basic3DVector<T>& v) {
00291   return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
00292 }
00293 
00294 template <class T, typename S>
00295 inline Basic3DVector<T> operator*(S t,  const Basic3DVector<T>& v) {
00296   return static_cast<T>(t)*v;
00297 }
00298 
00299 template <class T, typename S>
00300 inline Basic3DVector<T> operator*(const Basic3DVector<T>& v, S t) {
00301   return static_cast<T>(t)*v;
00302 }
00303 
00304 
00308 template <class T, typename S>
00309 inline Basic3DVector<T> operator/( const Basic3DVector<T>& v, S s) {
00310   T t = T(1)/s;
00311   return v*t;
00312 }
00313 
00314 
00315 typedef Basic3DVector<float> Basic3DVectorF;
00316 typedef Basic3DVector<double> Basic3DVectorD;
00317 typedef Basic3DVector<long double> Basic3DVectorLD;
00318 
00319 
00320 #endif // GeometryVector_Basic3DVector_h
00321 
00322