BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Reconstruction/TrkReco/include/TrkReco/TPoint2D.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TPoint2D.h,v 1.6 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TPoint2D.h
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A class to represent a point in 2D.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#ifndef TPOINT2D_FLAG_
14#define TPOINT2D_FLAG_
15
16#ifdef TRKRECO_DEBUG_DETAIL
17# ifndef TRKRECO_DEBUG
18# define TRKRECO_DEBUG
19# endif
20#endif
21#include <math.h>
22// #define HEP_SHORT_NAMES
23#include "CLHEP/Geometry/Vector3D.h"
24#ifndef ENABLE_BACKWARDS_COMPATIBILITY
25typedef HepGeom::Vector3D<double> HepVector3D;
26#endif
27#ifndef CLHEP_POINT3D_H
28# include "CLHEP/Geometry/Point3D.h"
29#endif
30#ifndef ENABLE_BACKWARDS_COMPATIBILITY
31typedef HepGeom::Point3D<double> HepPoint3D;
32#endif
33
34// class HepPoint3D;
35
36/// A class to represent a point in 2D.
37class TPoint2D {
38
39public:
40 /// Constructors
42 TPoint2D( double, double );
45
46 /// Destructor
47 virtual ~TPoint2D();
48
49public: // Selectors
50 double x( void ) const;
51 double y( void ) const;
52 double mag( void ) const;
53 double mag2( void ) const;
54 double phi( void ) const;
55
56public: // Modifiers
57 double x( double );
58 double y( double );
59
60public: // Operators
61 double dot( const TPoint2D& ) const;
62 double cross( const TPoint2D& ) const;
63 TPoint2D unit( void ) const;
64 TPoint2D operator+( const TPoint2D& ) const;
65 TPoint2D operator-( const TPoint2D& ) const;
67 bool operator==( const TPoint2D& ) const;
68
69private:
70 double _p[2];
71};
72
73std::ostream& operator<<( std::ostream&, const TPoint2D& );
74
75//-----------------------------------------------------------------------------
76
77#ifdef TPOINT2D_NO_INLINE
78# define inline
79#else
80# undef inline
81# define TPOINT2D_INLINE_DEFINE_HERE
82#endif
83#ifdef TPOINT2D_INLINE_DEFINE_HERE
84
85inline double TPoint2D::x( void ) const { return _p[0]; }
86
87inline double TPoint2D::y( void ) const { return _p[1]; }
88
89inline double TPoint2D::x( double a ) { return _p[0] = a; }
90
91inline double TPoint2D::y( double a ) { return _p[1] = a; }
92
93inline double TPoint2D::mag( void ) const { return sqrt( _p[0] * _p[0] + _p[1] * _p[1] ); }
94
95inline double TPoint2D::mag2( void ) const { return _p[0] * _p[0] + _p[1] * _p[1]; }
96
97inline double TPoint2D::phi( void ) const {
98 if ( _p[0] == 0.0 && _p[1] == 0.0 ) return 0.;
99 double a = atan2( _p[1], _p[0] );
100 if ( a > 0 ) return a;
101 return a + 2. * M_PI;
102}
103
104inline double TPoint2D::dot( const TPoint2D& a ) const {
105 return _p[0] * a.x() + _p[1] * a.y();
106}
107
108inline double TPoint2D::cross( const TPoint2D& a ) const {
109 return _p[0] * a.y() - a.x() * _p[1];
110}
111
112inline TPoint2D TPoint2D::operator+( const TPoint2D& a ) const {
113 return TPoint2D( _p[0] + a.x(), _p[1] + a.y() );
114}
115
116inline TPoint2D TPoint2D::operator-( const TPoint2D& a ) const {
117 return TPoint2D( _p[0] - a.x(), _p[1] - a.y() );
118}
119
120inline TPoint2D TPoint2D::operator-() const { return TPoint2D( -_p[0], -_p[1] ); }
121
122inline bool TPoint2D::operator==( const TPoint2D& a ) const {
123 if ( a.x() == _p[0] && a.y() == _p[1] ) return true;
124 return false;
125}
126
127inline TPoint2D TPoint2D::unit( void ) const {
128 double sum2 = _p[0] * _p[0] + _p[1] * _p[1];
129 if ( sum2 == 0. ) return TPoint2D( 0., 0. );
130 double sum = sqrt( sum2 );
131 return TPoint2D( _p[0] / sum, _p[1] / sum );
132}
133
134#endif
135#undef inline
136
137#endif /* TPOINT2D_FLAG_ */
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
std::ostream & operator<<(std::ostream &, const TPoint2D &)
Definition TPoint2D.cxx:41
HepGeom::Point3D< double > HepPoint3D
HepGeom::Vector3D< double > HepVector3D
#define M_PI
Definition TConstant.h:4
double mag2(void) const
TPoint2D operator-() const
double dot(const TPoint2D &) const
double cross(const TPoint2D &) const
double phi(void) const
double y(void) const
bool operator==(const TPoint2D &) const
double y(double)
TPoint2D(const HepPoint3D &)
virtual ~TPoint2D()
Destructor.
double x(double)
double mag(void) const
TPoint2D operator-(const TPoint2D &) const
double x(void) const
TPoint2D()
Constructors.
TPoint2D(const HepVector3D &)
TPoint2D(double, double)
TPoint2D unit(void) const
TPoint2D operator+(const TPoint2D &) const