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 template < typename T>
00018 class Basic3DVector {
00019 public:
00020
00021 typedef T ScalarType;
00022 typedef Geom::Cylindrical2Cartesian<T> Cylindrical;
00023 typedef Geom::Spherical2Cartesian<T> Spherical;
00024 typedef Spherical Polar;
00025
00030 Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
00031
00033 Basic3DVector( const Basic3DVector & p) :
00034 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00035
00037 template <class U>
00038 Basic3DVector( const Basic3DVector<U> & p) :
00039 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00040
00042 Basic3DVector( const Basic2DVector<T> & p) :
00043 theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
00044
00053 template <class OtherPoint>
00054 explicit Basic3DVector( const OtherPoint& p) :
00055 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00056
00057
00058 #ifndef __REFLEX__
00059
00060 template<typename U>
00061 Basic3DVector(mathSSE::Vec4<U> const& iv) :
00062 theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
00063 #endif
00064
00066 Basic3DVector( const T& x, const T& y, const T& z) :
00067 theX(x), theY(y), theZ(z), theW(0) {}
00068
00073 template <typename U>
00074 Basic3DVector( const Geom::Theta<U>& theta,
00075 const Geom::Phi<U>& phi, const T& r) {
00076 Polar p( theta.value(), phi.value(), r);
00077 theX = p.x(); theY = p.y(); theZ = p.z();
00078 }
00079
00081 T x() const { return theX;}
00082
00084 T y() const { return theY;}
00085
00087 T z() const { return theZ;}
00088
00089 Basic2DVector<T> xy() const { return Basic2DVector<T>(theX,theY);}
00090
00091
00092
00093 bool operator==(const Basic3DVector& rh) const {
00094 return x()==rh.x() && y()==rh.y() && z()==rh.z();
00095 }
00096
00098 T mag2() const { return x()*x() + y()*y()+z()*z();}
00099
00101 T mag() const { return std::sqrt( mag2());}
00102
00104 T perp2() const { return x()*x() + y()*y();}
00105
00107 T perp() const { return std::sqrt( perp2());}
00108
00110 T transverse() const { return perp();}
00111
00116 T barePhi() const {return std::atan2(y(),x());}
00117 Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00118
00123 T bareTheta() const {return std::atan2(perp(),z());}
00124 Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00125
00130
00131 T eta() const { T x(z()/perp()); return std::log(x+std::sqrt(x*x+T(1)));}
00132
00136 Basic3DVector unit() const {
00137 T my_mag = mag2();
00138 if (my_mag==0) return *this;
00139 my_mag = T(1)/std::sqrt(my_mag);
00140 return *this * my_mag;
00141 }
00142
00145 template <class U>
00146 Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00147 theX += p.x();
00148 theY += p.y();
00149 theZ += p.z();
00150 return *this;
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
00164 Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00165
00167 Basic3DVector& operator*= ( T t) {
00168 theX *= t;
00169 theY *= t;
00170 theZ *= t;
00171 return *this;
00172 }
00173
00175 Basic3DVector& operator/= ( T t) {
00176 t = T(1)/t;
00177 theX *= t;
00178 theY *= t;
00179 theZ *= t;
00180 return *this;
00181 }
00182
00184 T dot( const Basic3DVector& v) const {
00185 return x()*v.x() + y()*v.y() + z()*v.z();
00186 }
00187
00193 template <class U>
00194 typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const {
00195 return x()*v.x() + y()*v.y() + z()*v.z();
00196 }
00197
00199 Basic3DVector cross( const Basic3DVector& v) const {
00200 return Basic3DVector( y()*v.z() - v.y()*z(),
00201 z()*v.x() - v.z()*x(),
00202 x()*v.y() - v.x()*y());
00203 }
00204
00205
00211 template <class U>
00212 Basic3DVector<typename PreciseFloatType<T,U>::Type>
00213 cross( const Basic3DVector<U>& v) const {
00214 return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
00215 z()*v.x() - v.z()*x(),
00216 x()*v.y() - v.x()*y());
00217 }
00218
00219 private:
00220 T theX;
00221 T theY;
00222 T theZ;
00223 T theW;
00224 }
00225 #ifndef __CINT__
00226 __attribute__ ((aligned (16)))
00227 #endif
00228 ;
00229
00230
00231 namespace geometryDetails {
00232 std::ostream & print3D(std::ostream& s, double x, double y, double z);
00233 }
00234
00236 template <class T>
00237 inline std::ostream & operator<<( std::ostream& s, const Basic3DVector<T>& v) {
00238 return geometryDetails::print3D(s, v.x(),v.y(), v.z());
00239 }
00240
00241
00243 template <class T, class U>
00244 inline Basic3DVector<typename PreciseFloatType<T,U>::Type>
00245 operator+( const Basic3DVector<T>& a, const Basic3DVector<U>& b) {
00246 typedef Basic3DVector<typename PreciseFloatType<T,U>::Type> RT;
00247 return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00248 }
00249
00250 template <class T, class U>
00251 inline Basic3DVector<typename PreciseFloatType<T,U>::Type>
00252 operator-( const Basic3DVector<T>& a, const Basic3DVector<U>& b) {
00253 typedef Basic3DVector<typename PreciseFloatType<T,U>::Type> RT;
00254 return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00255 }
00256
00258 template <class T>
00259 inline T operator*( const Basic3DVector<T>& v1, const Basic3DVector<T>& v2) {
00260 return v1.dot(v2);
00261 }
00262
00264 template <class T, class U>
00265 inline typename PreciseFloatType<T,U>::Type operator*( const Basic3DVector<T>& v1,
00266 const Basic3DVector<U>& v2) {
00267 return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00268 }
00269
00273 template <class T>
00274 inline Basic3DVector<T> operator*( const Basic3DVector<T>& v, T t) {
00275 return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
00276 }
00277
00279 template <class T>
00280 inline Basic3DVector<T> operator*(T t, const Basic3DVector<T>& v) {
00281 return Basic3DVector<T>(v.x()*t, v.y()*t, v.z()*t);
00282 }
00283
00284 template <class T, typename S>
00285 inline Basic3DVector<T> operator*(S t, const Basic3DVector<T>& v) {
00286 return static_cast<T>(t)*v;
00287 }
00288
00289 template <class T, typename S>
00290 inline Basic3DVector<T> operator*(const Basic3DVector<T>& v, S t) {
00291 return static_cast<T>(t)*v;
00292 }
00293
00294
00298 template <class T, typename S>
00299 inline Basic3DVector<T> operator/( const Basic3DVector<T>& v, S s) {
00300 T t = T(1)/s;
00301 return v*t;
00302 }
00303
00304
00305 typedef Basic3DVector<float> Basic3DVectorF;
00306 typedef Basic3DVector<double> Basic3DVectorD;
00307
00308
00309 #endif // GeometryVector_Basic3DVector_h
00310
00311