CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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 #ifndef __REFLEX__
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 
00063   Basic3DVector( const T& x, const T& y, const T& z) : 
00064     theX(x), theY(y), theZ(z), theW(0) {}
00065 
00070   template <typename U>
00071   Basic3DVector( const Geom::Theta<U>& theta, 
00072                  const Geom::Phi<U>& phi, const T& r) {
00073     Polar p( theta.value(), phi.value(), r);
00074     theX = p.x(); theY = p.y(); theZ = p.z();
00075   }
00076 
00078   T x() const { return theX;}
00079 
00081   T y() const { return theY;}
00082 
00084   T z() const { return theZ;}
00085 
00086   Basic2DVector<T> xy() const { return  Basic2DVector<T>(theX,theY);}
00087 
00088 
00089   // equality
00090   bool operator==(const Basic3DVector& rh) const {
00091     return x()==rh.x() && y()==rh.y() && z()==rh.z();
00092   }
00093 
00095   T mag2() const { return  x()*x() + y()*y()+z()*z();}
00096 
00098   T mag() const  { return std::sqrt( mag2());}
00099 
00101   T perp2() const { return x()*x() + y()*y();}
00102 
00104   T perp() const { return std::sqrt( perp2());}
00105 
00107   T transverse() const { return perp();}
00108 
00113   T barePhi() const {return std::atan2(y(),x());}
00114   Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00115 
00120   T bareTheta() const {return std::atan2(perp(),z());}
00121   Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00122 
00127   // T eta() const { return -log( tan( theta()/2.));} 
00128   T eta() const { return detailsBasic3DVector::eta(x(),y(),z());} // correct 
00129 
00130 
00134   Basic3DVector unit() const {
00135     T my_mag = mag2();
00136     if (my_mag==0) return *this;
00137     my_mag = T(1)/std::sqrt(my_mag);
00138     Basic3DVector ret(*this);
00139     return  ret*=my_mag;
00140   }
00141 
00144   template <class U> 
00145   Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00146     theX += p.x();
00147     theY += p.y();
00148     theZ += p.z();
00149     return *this;
00150   } 
00151 
00154   template <class U> 
00155   Basic3DVector& operator-= ( const Basic3DVector<U>& p) {
00156     theX -= p.x();
00157     theY -= p.y();
00158     theZ -= p.z();
00159     return *this;
00160   } 
00161 
00163   Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00164 
00166   Basic3DVector& operator*= ( T t) {
00167     theX *= t;
00168     theY *= t;
00169     theZ *= t;
00170     return *this;
00171   } 
00172 
00174   Basic3DVector& operator/= ( T t) {
00175     t = T(1)/t;
00176     theX *= t;
00177     theY *= t;   
00178     theZ *= t;
00179     return *this;
00180   } 
00181 
00183   T dot( const Basic3DVector& v) const { 
00184     return x()*v.x() + y()*v.y() + z()*v.z();
00185   }
00186 
00192   template <class U> 
00193   typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const { 
00194     return x()*v.x() + y()*v.y() + z()*v.z();
00195   }
00196 
00198   Basic3DVector cross( const Basic3DVector& v) const {
00199     return Basic3DVector( y()*v.z() - v.y()*z(), 
00200                           z()*v.x() - v.z()*x(), 
00201                           x()*v.y() - v.x()*y());
00202   }
00203 
00204 
00210   template <class U> 
00211   Basic3DVector<typename PreciseFloatType<T,U>::Type> 
00212   cross( const Basic3DVector<U>& v) const {
00213     return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(), 
00214                                                                 z()*v.x() - v.z()*x(), 
00215                                                                 x()*v.y() - v.x()*y());
00216   }
00217 
00218 private:
00219   T theX;
00220   T theY;
00221   T theZ;
00222   T theW;
00223 }  
00224 #ifndef __CINT__
00225 __attribute__ ((aligned (16)))
00226 #endif
00227 ;
00228 
00229 
00231 inline Basic3DVector<long double>
00232 operator+( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00233   typedef Basic3DVector<long double> RT;
00234   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00235 }
00236 inline Basic3DVector<long double>
00237 operator-( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00238   typedef Basic3DVector<long double> RT;
00239   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00240 }
00241 
00242 
00243 
00244 template <class U>
00245 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00246 operator+( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00247   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00248   return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00249 }
00250 
00251 template <class U>
00252 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00253 operator+(const Basic3DVector<U>& a, const Basic3DVector<long double>& 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 
00259 template <class U>
00260 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00261 operator-( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00262   typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00263   return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00264 }
00265 
00266 template <class U>
00267 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00268 operator-(const Basic3DVector<U>& a,  const Basic3DVector<long double>& 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 
00274 // template <>
00275 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
00276   return v1.dot(v2);
00277 }
00278 
00280 template <class U>
00281 inline typename PreciseFloatType<long double,U>::Type operator*( const Basic3DVector<long double>& v1, 
00282                                                        const Basic3DVector<U>& v2) {
00283   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00284 }
00285 
00286 template <class U>
00287 inline typename PreciseFloatType<long double,U>::Type operator*(const Basic3DVector<U>& v1,
00288                                                                 const Basic3DVector<long double>& v2 ) {
00289   return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00290 }
00291 
00292 
00296 //template <>
00297 inline Basic3DVector<long double> operator*( const Basic3DVector<long double>& v, long double t) {
00298   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00299 }
00300 
00302 // template <>
00303 inline Basic3DVector<long double> operator*(long double t, const Basic3DVector<long double>& v) {
00304   return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00305 }
00306 
00307 template <typename S>
00308 inline Basic3DVector<long double> operator*(S t,  const Basic3DVector<long double>& v) {
00309   return static_cast<long double>(t)*v;
00310 }
00311 
00312 template <typename S>
00313 inline Basic3DVector<long double> operator*(const Basic3DVector<long double>& v, S t) {
00314   return static_cast<long double>(t)*v;
00315 }
00316 
00317 
00321 template <typename S>
00322 inline Basic3DVector<long double> operator/( const Basic3DVector<long double>& v, S s) {
00323   long double t = 1/s;
00324   return v*t;
00325 }
00326 
00327 
00328 typedef Basic3DVector<long double> Basic3DVectorLD;
00329 
00330 #ifdef __clang__
00331 #pragma clang diagnostic pop
00332 #endif
00333 
00334 #endif // GeometryVector_Basic3DVectorLD_h
00335 
00336 
00337