/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/TrkReco/TrkReco-00-08-59-patch4-slc6tag/TrkReco/TPoint2D.h

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // $Id: TPoint2D.h,v 1.6 2010/03/31 09:58:59 liucy Exp $
00003 //-----------------------------------------------------------------------------
00004 // Filename : TPoint2D.h
00005 // Section  : Tracking
00006 // Owner    : Yoshi Iwasaki
00007 // Email    : yoshihito.iwasaki@kek.jp
00008 //-----------------------------------------------------------------------------
00009 // Description : A class to represent a point in 2D.
00010 //               See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifndef TPOINT2D_FLAG_
00014 #define TPOINT2D_FLAG_
00015 
00016 #ifdef TRKRECO_DEBUG_DETAIL
00017 #ifndef TRKRECO_DEBUG
00018 #define TRKRECO_DEBUG
00019 #endif
00020 #endif
00021 #include <math.h>
00022 #define HEP_SHORT_NAMES
00023 #include "CLHEP/Geometry/Vector3D.h"
00024 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00025     typedef HepGeom::Vector3D<double> HepVector3D;
00026 #endif
00027 #ifndef CLHEP_POINT3D_H
00028 #include "CLHEP/Geometry/Point3D.h"
00029 #endif
00030 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00031     typedef HepGeom::Point3D<double> HepPoint3D;
00032 #endif
00033 
00034 //class HepPoint3D;
00035 
00037 class TPoint2D {
00038 
00039   public:
00041     TPoint2D();
00042     TPoint2D(double, double);
00043     TPoint2D(const HepPoint3D &);
00044     TPoint2D(const HepVector3D &);
00045 
00047     virtual ~TPoint2D();
00048 
00049   public:// Selectors
00050     double x(void) const;
00051     double y(void) const;
00052     double mag(void) const;
00053     double mag2(void) const;
00054     double phi(void) const;
00055 
00056   public:// Modifiers
00057     double x(double);
00058     double y(double);
00059 
00060   public:// Operators
00061     double dot(const TPoint2D &) const;
00062     double cross(const TPoint2D &) const;
00063     TPoint2D unit(void) const;
00064     TPoint2D operator + (const TPoint2D &) const;
00065     TPoint2D operator - (const TPoint2D &) const;
00066     TPoint2D operator - () const;
00067     bool operator == (const TPoint2D &) const;
00068 
00069   private:
00070     double _p[2];
00071 };
00072 
00073 std::ostream &
00074 operator << (std::ostream &, const TPoint2D &);
00075 
00076 //-----------------------------------------------------------------------------
00077 
00078 #ifdef TPOINT2D_NO_INLINE
00079 #define inline
00080 #else
00081 #undef inline
00082 #define TPOINT2D_INLINE_DEFINE_HERE
00083 #endif
00084 #ifdef TPOINT2D_INLINE_DEFINE_HERE
00085 
00086 inline
00087 double
00088 TPoint2D::x(void) const {
00089     return _p[0];
00090 }
00091 
00092 inline
00093 double
00094 TPoint2D::y(void) const {
00095     return _p[1];
00096 }
00097 
00098 inline
00099 double
00100 TPoint2D::x(double a) {
00101     return _p[0] = a;
00102 }
00103 
00104 inline
00105 double
00106 TPoint2D::y(double a) {
00107     return _p[1] = a;
00108 }
00109 
00110 inline
00111 double
00112 TPoint2D::mag(void) const {
00113     return sqrt(_p[0] * _p[0] + _p[1] * _p[1]);
00114 }
00115 
00116 inline
00117 double
00118 TPoint2D::mag2(void) const {
00119     return _p[0] * _p[0] + _p[1] * _p[1];
00120 }
00121 
00122 inline
00123 double
00124 TPoint2D::phi(void) const {
00125     if (_p[0] == 0.0 && _p[1] == 0.0) return 0.;
00126     double a = atan2(_p[1], _p[0]);
00127     if (a > 0) return a;
00128     return a + 2. * M_PI;
00129 }
00130 
00131 inline
00132 double
00133 TPoint2D::dot(const TPoint2D & a) const {
00134     return _p[0] * a.x() + _p[1] * a.y();
00135 }
00136 
00137 inline
00138 double
00139 TPoint2D::cross(const TPoint2D & a) const {
00140     return _p[0] * a.y() - a.x() * _p[1];
00141 }
00142 
00143 inline
00144 TPoint2D
00145 TPoint2D::operator + (const TPoint2D & a) const {
00146     return TPoint2D(_p[0] + a.x(), _p[1] + a.y());
00147 }
00148 
00149 inline
00150 TPoint2D
00151 TPoint2D::operator - (const TPoint2D & a) const {
00152     return TPoint2D(_p[0] - a.x(), _p[1] - a.y());
00153 }
00154 
00155 inline
00156 TPoint2D
00157 TPoint2D::operator - () const {
00158     return TPoint2D(- _p[0], - _p[1]);
00159 }
00160 
00161 inline
00162 bool
00163 TPoint2D::operator == (const TPoint2D & a) const {
00164     if (a.x() == _p[0] && a.y() == _p[1]) return true;
00165     return false;
00166 }
00167 
00168 inline
00169 TPoint2D
00170 TPoint2D::unit(void) const {
00171     double sum2 = _p[0] * _p[0] + _p[1] * _p[1];
00172     if (sum2 == 0.) return TPoint2D(0., 0.);
00173     double sum = sqrt(sum2);
00174     return TPoint2D(_p[0] / sum, _p[1] / sum);
00175 }
00176 
00177 #endif
00178 #undef inline
00179 
00180 #endif /* TPOINT2D_FLAG_ */

Generated on Tue Nov 29 23:14:17 2016 for BOSS_7.0.2 by  doxygen 1.4.7