CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DataFormats/GeometryVector/interface/Basic3DVectorLD.h

Go to the documentation of this file.
00001 #ifndef GeometryVector_Basic3DVectorLD_h
00002 #define GeometryVector_Basic3DVectorLD_h
00003 
00004 
00005 // long double specialization
00006 template <> 
00007 class Basic3DVector<long double> {
00008 public:
00009 
00010 
00011   typedef long double                         T;
00012   typedef T                                   ScalarType;
00013   typedef Geom::Cylindrical2Cartesian<T>      Cylindrical;
00014   typedef Geom::Spherical2Cartesian<T>        Spherical;
00015   typedef Spherical                           Polar; // synonym
00016 
00017   typedef  Basic3DVector<T> MathVector;
00018     
00023   Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
00024 
00026   Basic3DVector( const Basic3DVector & p) : 
00027     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00028 
00030   template <class U>
00031   Basic3DVector( const Basic3DVector<U> & p) : 
00032     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00033 
00035   Basic3DVector( const Basic2DVector<T> & p) : 
00036     theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
00037 
00046   template <class OtherPoint> 
00047   explicit Basic3DVector( const OtherPoint& p) : 
00048     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00049 
00050 
00051 #ifndef __REFLEX__
00052   // constructor from Vec4
00053   template<typename U>
00054   Basic3DVector(mathSSE::Vec4<U> const& iv) :
00055     theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
00056 #endif  
00057 
00059   Basic3DVector( const T& x, const T& y, const T& z) : 
00060     theX(x), theY(y), theZ(z), theW(0) {}
00061 
00066   template <typename U>
00067   Basic3DVector( const Geom::Theta<U>& theta, 
00068                  const Geom::Phi<U>& phi, const T& r) {
00069     Polar p( theta.value(), phi.value(), r);
00070     theX = p.x(); theY = p.y(); theZ = p.z();
00071   }
00072 
00074   T x() const { return theX;}
00075 
00077   T y() const { return theY;}
00078 
00080   T z() const { return theZ;}
00081 
00082   Basic2DVector<T> xy() const { return  Basic2DVector<T>(theX,theY);}
00083 
00084 
00085   // equality
00086   bool operator==(const Basic3DVector& rh) const {
00087     return x()==rh.x() && y()==rh.y() && z()==rh.z();
00088   }
00089 
00091   T mag2() const { return  x()*x() + y()*y()+z()*z();}
00092 
00094   T mag() const  { return std::sqrt( mag2());}
00095 
00097   T perp2() const { return x()*x() + y()*y();}
00098 
00100   T perp() const { return std::sqrt( perp2());}
00101 
00103   T transverse() const { return perp();}
00104 
00109   T barePhi() const {return std::atan2(y(),x());}
00110   Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00111 
00116   T bareTheta() const {return std::atan2(perp(),z());}
00117   Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00118 
00123   // T eta() const { return -log( tan( theta()/2.));} 
00124   T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct 
00125 
00126 
00130   Basic3DVector unit() const {
00131     T my_mag = mag2();
00132     if (my_mag==0) return *this;
00133     my_mag = T(1)/std::sqrt(my_mag);
00134     Basic3DVector ret(*this);
00135     return  ret*=my_mag;
00136   }
00137 
00140   template <class U> 
00141   Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00142     theX += p.x();
00143     theY += p.y();
00144     theZ += p.z();
00145     return *this;
00146   } 
00147 
00150   template <class U> 
00151   Basic3DVector& operator-= ( const Basic3DVector<U>& p) {
00152     theX -= p.x();
00153     theY -= p.y();
00154     theZ -= p.z();
00155     return *this;
00156   } 
00157 
00159   Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00160 
00162   Basic3DVector& operator*= ( T t) {
00163     theX *= t;
00164     theY *= t;
00165     theZ *= t;
00166     return *this;
00167   } 
00168 
00170   Basic3DVector& operator/= ( T t) {
00171     t = T(1)/t;
00172     theX *= t;
00173     theY *= t;   
00174     theZ *= t;
00175     return *this;
00176   } 
00177 
00179   T dot( const Basic3DVector& v) const { 
00180     return x()*v.x() + y()*v.y() + z()*v.z();
00181   }
00182 
00188   template <class U> 
00189   typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const { 
00190     return x()*v.x() + y()*v.y() + z()*v.z();
00191   }
00192 
00194   Basic3DVector cross( const Basic3DVector& v) const {
00195     return Basic3DVector( y()*v.z() - v.y()*z(), 
00196                           z()*v.x() - v.z()*x(), 
00197                           x()*v.y() - v.x()*y());
00198   }
00199 
00200 
00206   template <class U> 
00207   Basic3DVector<typename PreciseFloatType<T,U>::Type> 
00208   cross( const Basic3DVector<U>& v) const {
00209     return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(), 
00210                                                                 z()*v.x() - v.z()*x(), 
00211                                                                 x()*v.y() - v.x()*y());
00212   }
00213 
00214 private:
00215   T theX;
00216   T theY;
00217   T theZ;
00218   T theW;
00219 }  
00220 #ifndef __CINT__
00221 __attribute__ ((aligned (16)))
00222 #endif
00223 ;
00224 
00225 
00227 inline Basic3DVector<long double>
00228 operator+( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00229   typedef Basic3DVector<long double> RT;
00230   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00231 }
00232 inline Basic3DVector<long double>
00233 operator-( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00234   typedef Basic3DVector<long double> RT;
00235   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00236 }
00237 
00238 
00239 
00240 template <class U>
00241 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00242 operator+( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00243   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00244   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00245 }
00246 
00247 template <class U>
00248 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00249 operator+(const Basic3DVector<U>& a, const Basic3DVector<long double>& b) {
00250   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00251   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00252 }
00253 
00254 
00255 template <class U>
00256 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00257 operator-( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00258   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00259   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00260 }
00261 
00262 template <class U>
00263 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00264 operator-(const Basic3DVector<U>& a,  const Basic3DVector<long double>& b) {
00265   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00266   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00267 }
00268 
00270 // template <>
00271 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
00272   return v1.dot(v2);
00273 }
00274 
00276 template <class U>
00277 inline typename PreciseFloatType<long double,U>::Type operator*( const Basic3DVector<long double>& v1, 
00278                                                        const Basic3DVector<U>& v2) {
00279   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00280 }
00281 
00282 template <class U>
00283 inline typename PreciseFloatType<long double,U>::Type operator*(const Basic3DVector<U>& v1,
00284                                                                 const Basic3DVector<long double>& v2 ) {
00285   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00286 }
00287 
00288 
00292 //template <>
00293 inline Basic3DVector<long double> operator*( const Basic3DVector<long double>& v, long double t) {
00294   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00295 }
00296 
00298 // template <>
00299 inline Basic3DVector<long double> operator*(long double t, const Basic3DVector<long double>& v) {
00300   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00301 }
00302 
00303 template <typename S>
00304 inline Basic3DVector<long double> operator*(S t,  const Basic3DVector<long double>& v) {
00305   return static_cast<long double>(t)*v;
00306 }
00307 
00308 template <typename S>
00309 inline Basic3DVector<long double> operator*(const Basic3DVector<long double>& v, S t) {
00310   return static_cast<long double>(t)*v;
00311 }
00312 
00313 
00317 template <typename S>
00318 inline Basic3DVector<long double> operator/( const Basic3DVector<long double>& v, S s) {
00319   long double t = 1/s;
00320   return v*t;
00321 }
00322 
00323 
00324 typedef Basic3DVector<long double> Basic3DVectorLD;
00325 
00326 
00327 #endif // GeometryVector_Basic3DVectorLD_h
00328 
00329 
00330