CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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 #ifdef __clang__
00005 #pragma clang diagnostic push 
00006 #pragma clang diagnostic ignored "-Wunused-private-field"
00007 #endif
00008 
00009 // long double specialization
00010 template <> 
00011 class Basic3DVector<long double> {
00012 public:
00013 
00014 
00015   typedef long double                         T;
00016   typedef T                                   ScalarType;
00017   typedef Geom::Cylindrical2Cartesian<T>      Cylindrical;
00018   typedef Geom::Spherical2Cartesian<T>        Spherical;
00019   typedef Spherical                           Polar; // synonym
00020 
00021   typedef  Basic3DVector<T> MathVector;
00022     
00027   Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
00028 
00030   Basic3DVector( const Basic3DVector & p) : 
00031     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00032 
00034   template <class U>
00035   Basic3DVector( const Basic3DVector<U> & p) : 
00036     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00037 
00039   Basic3DVector( const Basic2DVector<T> & p) : 
00040     theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
00041 
00050   template <class OtherPoint> 
00051   explicit Basic3DVector( const OtherPoint& p) : 
00052     theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00053 
00054 
00055 #ifdef USE_SSEVECT
00056   // constructor from Vec4
00057   template<typename U>
00058   Basic3DVector(mathSSE::Vec4<U> const& iv) :
00059     theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
00060 #endif  
00061 #ifdef USE_EXTVECT
00062   // constructor from Vec4
00063   template<typename U>
00064   Basic3DVector(Vec4<U> const& iv) :
00065     theX(iv[0]), theY(iv[1]), theZ(iv[2]), theW(0) {}
00066 #endif
00067 
00068 
00070   Basic3DVector( const T& x, const T& y, const T& z) : 
00071     theX(x), theY(y), theZ(z), theW(0) {}
00072 
00077   template <typename U>
00078   Basic3DVector( const Geom::Theta<U>& theta, 
00079                  const Geom::Phi<U>& phi, const T& r) {
00080     Polar p( theta.value(), phi.value(), r);
00081     theX = p.x(); theY = p.y(); theZ = p.z();
00082   }
00083 
00085   T x() const { return theX;}
00086 
00088   T y() const { return theY;}
00089 
00091   T z() const { return theZ;}
00092 
00093   Basic2DVector<T> xy() const { return  Basic2DVector<T>(theX,theY);}
00094 
00095 
00096   // equality
00097   bool operator==(const Basic3DVector& rh) const {
00098     return x()==rh.x() && y()==rh.y() && z()==rh.z();
00099   }
00100 
00102   T mag2() const { return  x()*x() + y()*y()+z()*z();}
00103 
00105   T mag() const  { return std::sqrt( mag2());}
00106 
00108   T perp2() const { return x()*x() + y()*y();}
00109 
00111   T perp() const { return std::sqrt( perp2());}
00112 
00114   T transverse() const { return perp();}
00115 
00120   T barePhi() const {return std::atan2(y(),x());}
00121   Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00122 
00127   T bareTheta() const {return std::atan2(perp(),z());}
00128   Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00129 
00134   // T eta() const { return -log( tan( theta()/2.));} 
00135   T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct 
00136 
00137 
00141   Basic3DVector unit() const {
00142     T my_mag = mag2();
00143     if (my_mag==0) return *this;
00144     my_mag = T(1)/std::sqrt(my_mag);
00145     Basic3DVector ret(*this);
00146     return  ret*=my_mag;
00147   }
00148 
00151   template <class U> 
00152   Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00153     theX += p.x();
00154     theY += p.y();
00155     theZ += p.z();
00156     return *this;
00157   } 
00158 
00161   template <class U> 
00162   Basic3DVector& operator-= ( const Basic3DVector<U>& p) {
00163     theX -= p.x();
00164     theY -= p.y();
00165     theZ -= p.z();
00166     return *this;
00167   } 
00168 
00170   Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00171 
00173   Basic3DVector& operator*= ( T t) {
00174     theX *= t;
00175     theY *= t;
00176     theZ *= t;
00177     return *this;
00178   } 
00179 
00181   Basic3DVector& operator/= ( T t) {
00182     t = T(1)/t;
00183     theX *= t;
00184     theY *= t;   
00185     theZ *= t;
00186     return *this;
00187   } 
00188 
00190   T dot( const Basic3DVector& v) const { 
00191     return x()*v.x() + y()*v.y() + z()*v.z();
00192   }
00193 
00199   template <class U> 
00200   typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const { 
00201     return x()*v.x() + y()*v.y() + z()*v.z();
00202   }
00203 
00205   Basic3DVector cross( const Basic3DVector& v) const {
00206     return Basic3DVector( y()*v.z() - v.y()*z(), 
00207                           z()*v.x() - v.z()*x(), 
00208                           x()*v.y() - v.x()*y());
00209   }
00210 
00211 
00217   template <class U> 
00218   Basic3DVector<typename PreciseFloatType<T,U>::Type> 
00219   cross( const Basic3DVector<U>& v) const {
00220     return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(), 
00221                                                                 z()*v.x() - v.z()*x(), 
00222                                                                 x()*v.y() - v.x()*y());
00223   }
00224 
00225 private:
00226   T theX;
00227   T theY;
00228   T theZ;
00229   T theW;
00230 }  
00231 #ifndef __CINT__
00232 __attribute__ ((aligned (16)))
00233 #endif
00234 ;
00235 
00236 
00238 inline Basic3DVector<long double>
00239 operator+( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00240   typedef Basic3DVector<long double> RT;
00241   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00242 }
00243 inline Basic3DVector<long double>
00244 operator-( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00245   typedef Basic3DVector<long double> RT;
00246   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00247 }
00248 
00249 
00250 
00251 template <class U>
00252 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00253 operator+( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00254   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00255   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00256 }
00257 
00258 template <class U>
00259 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00260 operator+(const Basic3DVector<U>& a, const Basic3DVector<long double>& b) {
00261   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00262   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00263 }
00264 
00265 
00266 template <class U>
00267 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00268 operator-( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00269   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00270   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00271 }
00272 
00273 template <class U>
00274 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00275 operator-(const Basic3DVector<U>& a,  const Basic3DVector<long double>& b) {
00276   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00277   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00278 }
00279 
00281 // template <>
00282 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
00283   return v1.dot(v2);
00284 }
00285 
00287 template <class U>
00288 inline typename PreciseFloatType<long double,U>::Type operator*( const Basic3DVector<long double>& v1, 
00289                                                        const Basic3DVector<U>& v2) {
00290   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00291 }
00292 
00293 template <class U>
00294 inline typename PreciseFloatType<long double,U>::Type operator*(const Basic3DVector<U>& v1,
00295                                                                 const Basic3DVector<long double>& v2 ) {
00296   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00297 }
00298 
00299 
00303 //template <>
00304 inline Basic3DVector<long double> operator*( const Basic3DVector<long double>& v, long double t) {
00305   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00306 }
00307 
00309 // template <>
00310 inline Basic3DVector<long double> operator*(long double t, const Basic3DVector<long double>& v) {
00311   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00312 }
00313 
00314 template <typename S>
00315 inline Basic3DVector<long double> operator*(S t,  const Basic3DVector<long double>& v) {
00316   return static_cast<long double>(t)*v;
00317 }
00318 
00319 template <typename S>
00320 inline Basic3DVector<long double> operator*(const Basic3DVector<long double>& v, S t) {
00321   return static_cast<long double>(t)*v;
00322 }
00323 
00324 
00328 template <typename S>
00329 inline Basic3DVector<long double> operator/( const Basic3DVector<long double>& v, S s) {
00330   long double t = 1/s;
00331   return v*t;
00332 }
00333 
00334 
00335 typedef Basic3DVector<long double> Basic3DVectorLD;
00336 
00337 #ifdef __clang__
00338 #pragma clang diagnostic pop
00339 #endif
00340 
00341 #endif // GeometryVector_Basic3DVectorLD_h
00342 
00343 
00344