00001 #ifndef GeometryVector_Basic3DVectorLD_h
00002 #define GeometryVector_Basic3DVectorLD_h
00003
00004
00005
00006 template <>
00007 class Basic3DVector<long double> {
00008 public:
00009 typedef long double T;
00010 typedef T ScalarType;
00011 typedef Geom::Cylindrical2Cartesian<T> Cylindrical;
00012 typedef Geom::Spherical2Cartesian<T> Spherical;
00013 typedef Spherical Polar;
00014
00019 Basic3DVector() : theX(0), theY(0), theZ(0), theW(0) {}
00020
00022 Basic3DVector( const Basic3DVector & p) :
00023 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00024
00026 template <class U>
00027 Basic3DVector( const Basic3DVector<U> & p) :
00028 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00029
00031 Basic3DVector( const Basic2DVector<T> & p) :
00032 theX(p.x()), theY(p.y()), theZ(0), theW(0) {}
00033
00042 template <class OtherPoint>
00043 explicit Basic3DVector( const OtherPoint& p) :
00044 theX(p.x()), theY(p.y()), theZ(p.z()), theW(0) {}
00045
00046
00047 #ifndef __REFLEX__
00048
00049 template<typename U>
00050 Basic3DVector(mathSSE::Vec4<U> const& iv) :
00051 theX(iv.arr[0]), theY(iv.arr[1]), theZ(iv.arr[2]), theW(0) {}
00052 #endif
00053
00055 Basic3DVector( const T& x, const T& y, const T& z) :
00056 theX(x), theY(y), theZ(z), theW(0) {}
00057
00062 template <typename U>
00063 Basic3DVector( const Geom::Theta<U>& theta,
00064 const Geom::Phi<U>& phi, const T& r) {
00065 Polar p( theta.value(), phi.value(), r);
00066 theX = p.x(); theY = p.y(); theZ = p.z();
00067 }
00068
00070 T x() const { return theX;}
00071
00073 T y() const { return theY;}
00074
00076 T z() const { return theZ;}
00077
00078 Basic2DVector<T> xy() const { return Basic2DVector<T>(theX,theY);}
00079
00080
00081
00082 bool operator==(const Basic3DVector& rh) const {
00083 return x()==rh.x() && y()==rh.y() && z()==rh.z();
00084 }
00085
00087 T mag2() const { return x()*x() + y()*y()+z()*z();}
00088
00090 T mag() const { return std::sqrt( mag2());}
00091
00093 T perp2() const { return x()*x() + y()*y();}
00094
00096 T perp() const { return std::sqrt( perp2());}
00097
00099 T transverse() const { return perp();}
00100
00105 T barePhi() const {return std::atan2(y(),x());}
00106 Geom::Phi<T> phi() const {return Geom::Phi<T>(barePhi());}
00107
00112 T bareTheta() const {return std::atan2(perp(),z());}
00113 Geom::Theta<T> theta() const {return Geom::Theta<T>(std::atan2(perp(),z()));}
00114
00119
00120 T eta() const { return detailsBasic3DVector::eta(x(),y(),z());}
00121
00122
00126 Basic3DVector unit() const {
00127 T my_mag = mag2();
00128 if (my_mag==0) return *this;
00129 my_mag = T(1)/std::sqrt(my_mag);
00130 Basic3DVector ret(*this);
00131 return ret*=my_mag;
00132 }
00133
00136 template <class U>
00137 Basic3DVector& operator+= ( const Basic3DVector<U>& p) {
00138 theX += p.x();
00139 theY += p.y();
00140 theZ += p.z();
00141 return *this;
00142 }
00143
00146 template <class U>
00147 Basic3DVector& operator-= ( const Basic3DVector<U>& p) {
00148 theX -= p.x();
00149 theY -= p.y();
00150 theZ -= p.z();
00151 return *this;
00152 }
00153
00155 Basic3DVector operator-() const { return Basic3DVector(-x(),-y(),-z());}
00156
00158 Basic3DVector& operator*= ( T t) {
00159 theX *= t;
00160 theY *= t;
00161 theZ *= t;
00162 return *this;
00163 }
00164
00166 Basic3DVector& operator/= ( T t) {
00167 t = T(1)/t;
00168 theX *= t;
00169 theY *= t;
00170 theZ *= t;
00171 return *this;
00172 }
00173
00175 T dot( const Basic3DVector& v) const {
00176 return x()*v.x() + y()*v.y() + z()*v.z();
00177 }
00178
00184 template <class U>
00185 typename PreciseFloatType<T,U>::Type dot( const Basic3DVector<U>& v) const {
00186 return x()*v.x() + y()*v.y() + z()*v.z();
00187 }
00188
00190 Basic3DVector cross( const Basic3DVector& v) const {
00191 return Basic3DVector( y()*v.z() - v.y()*z(),
00192 z()*v.x() - v.z()*x(),
00193 x()*v.y() - v.x()*y());
00194 }
00195
00196
00202 template <class U>
00203 Basic3DVector<typename PreciseFloatType<T,U>::Type>
00204 cross( const Basic3DVector<U>& v) const {
00205 return Basic3DVector<typename PreciseFloatType<T,U>::Type>( y()*v.z() - v.y()*z(),
00206 z()*v.x() - v.z()*x(),
00207 x()*v.y() - v.x()*y());
00208 }
00209
00210 private:
00211 T theX;
00212 T theY;
00213 T theZ;
00214 T theW;
00215 }
00216 #ifndef __CINT__
00217 __attribute__ ((aligned (16)))
00218 #endif
00219 ;
00220
00221
00223 inline Basic3DVector<long double>
00224 operator+( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00225 typedef Basic3DVector<long double> RT;
00226 return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00227 }
00228 inline Basic3DVector<long double>
00229 operator-( const Basic3DVector<long double>& a, const Basic3DVector<long double>& b) {
00230 typedef Basic3DVector<long double> RT;
00231 return RT(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
00232 }
00233
00234
00235
00236 template <class U>
00237 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00238 operator+( const Basic3DVector<long double>& a, const Basic3DVector<U>& b) {
00239 typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00240 return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
00241 }
00242
00243 template <class U>
00244 inline Basic3DVector<typename PreciseFloatType<long double,U>::Type>
00245 operator+(const Basic3DVector<U>& a, const Basic3DVector<long double>& b) {
00246 typedef Basic3DVector<typename PreciseFloatType<long double,U>::Type> RT;
00247 return RT(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
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
00266
00267 inline long double operator*( const Basic3DVector<long double>& v1, const Basic3DVector<long double>& v2) {
00268 return v1.dot(v2);
00269 }
00270
00272 template <class U>
00273 inline typename PreciseFloatType<long double,U>::Type operator*( const Basic3DVector<long double>& v1,
00274 const Basic3DVector<U>& v2) {
00275 return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00276 }
00277
00278 template <class U>
00279 inline typename PreciseFloatType<long double,U>::Type operator*(const Basic3DVector<U>& v1,
00280 const Basic3DVector<long double>& v2 ) {
00281 return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
00282 }
00283
00284
00288
00289 inline Basic3DVector<long double> operator*( const Basic3DVector<long double>& v, long double t) {
00290 return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00291 }
00292
00294
00295 inline Basic3DVector<long double> operator*(long double t, const Basic3DVector<long double>& v) {
00296 return Basic3DVector<long double>(v.x()*t, v.y()*t, v.z()*t);
00297 }
00298
00299 template <typename S>
00300 inline Basic3DVector<long double> operator*(S t, const Basic3DVector<long double>& v) {
00301 return static_cast<long double>(t)*v;
00302 }
00303
00304 template <typename S>
00305 inline Basic3DVector<long double> operator*(const Basic3DVector<long double>& v, S t) {
00306 return static_cast<long double>(t)*v;
00307 }
00308
00309
00313 template <typename S>
00314 inline Basic3DVector<long double> operator/( const Basic3DVector<long double>& v, S s) {
00315 long double t = 1/s;
00316 return v*t;
00317 }
00318
00319
00320 typedef Basic3DVector<long double> Basic3DVectorLD;
00321
00322
00323 #endif // GeometryVector_Basic3DVectorLD_h
00324
00325
00326