BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TLine2D Class Reference

A class to represent a line in 2D. More...

#include <TLine2D.h>

Public Member Functions

 TLine2D ()
 Constructors.
 
 TLine2D (double slope, double yOffset)
 
 TLine2D (const AList< TPoint2D > &)
 
virtual ~TLine2D ()
 Destructor.
 
double slope (void) const
 
double yOffset (void) const
 
double xOffset (void) const
 
double slope (double)
 
double yOffset (double)
 
int fit (void)
 
double det (void) const
 
double distance (const TPoint2D &) const
 
void append (const TPoint2D &)
 
void remove (const TPoint2D &)
 
const CAList< TPoint2D > & list (void) const
 
 TLine2D ()
 Constructors.
 
 TLine2D (double slope, double yOffset)
 
 TLine2D (const AList< TPoint2D > &)
 
virtual ~TLine2D ()
 Destructor.
 
double slope (void) const
 
double yOffset (void) const
 
double xOffset (void) const
 
double slope (double)
 
double yOffset (double)
 
int fit (void)
 
double det (void) const
 
double distance (const TPoint2D &) const
 
void append (const TPoint2D &)
 
void remove (const TPoint2D &)
 
const CAList< TPoint2D > & list (void) const
 

Detailed Description

A class to represent a line in 2D.

Definition at line 25 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

Constructor & Destructor Documentation

◆ TLine2D() [1/6]

TLine2D::TLine2D ( )

Constructors.

Definition at line 31 of file TLine2D.cxx.

31 : _slope(1), _yOffset(0), _det(0), _list(0) {
32}

◆ TLine2D() [2/6]

TLine2D::TLine2D ( double  slope,
double  yOffset 
)

Definition at line 34 of file TLine2D.cxx.

35: _slope(a),
36 _yOffset(b),
37 _det(0),
38 _list(0) {
39}

◆ TLine2D() [3/6]

TLine2D::TLine2D ( const AList< TPoint2D > &  a)

Definition at line 41 of file TLine2D.cxx.

41 : _slope(1), _yOffset(0), _det(0) {
42 _list = new CAList<TPoint2D>();
43 _list->append(a);
44}

◆ ~TLine2D() [1/2]

TLine2D::~TLine2D ( )
virtual

Destructor.

Definition at line 46 of file TLine2D.cxx.

46 {
47 if (_list) delete _list;
48}

◆ TLine2D() [4/6]

TLine2D::TLine2D ( )

Constructors.

◆ TLine2D() [5/6]

TLine2D::TLine2D ( double  slope,
double  yOffset 
)

◆ TLine2D() [6/6]

TLine2D::TLine2D ( const AList< TPoint2D > &  )

◆ ~TLine2D() [2/2]

virtual TLine2D::~TLine2D ( )
virtual

Destructor.

Member Function Documentation

◆ append() [1/2]

void TLine2D::append ( const TPoint2D a)

Definition at line 51 of file TLine2D.cxx.

51 {
52 if (! _list)
53 _list = new CAList<TPoint2D>();
54 _list->append(a);
55}

◆ append() [2/2]

void TLine2D::append ( const TPoint2D )

◆ det() [1/2]

double TLine2D::det ( void  ) const

◆ det() [2/2]

double TLine2D::det ( void  ) const

◆ distance() [1/2]

double TLine2D::distance ( const TPoint2D p) const

Definition at line 112 of file TLine2D.cxx.

112 {
113 double ydif = p.y() - _yOffset;
114 double vmag = sqrt(1. + _slope * _slope);
115 double dot = (p.x() + ydif * _slope) / vmag;
116 double xmag2 = p.x() * p.x() + ydif * ydif;
117 return sqrt(xmag2 - dot * dot);
118}

◆ distance() [2/2]

double TLine2D::distance ( const TPoint2D ) const

◆ fit() [1/2]

int TLine2D::fit ( void  )

Definition at line 71 of file TLine2D.cxx.

71 {
72 if (! _list) return -1;
73
74 unsigned n = _list->length();
75 if (! n) return -1;
76
77 if (n == 2) {
78 double x0 = (* _list)[0]->x();
79 double y0 = (* _list)[0]->y();
80 double x1 = (* _list)[1]->x();
81 double y1 = (* _list)[1]->y();
82 if (x0 == x1) return -2;
83 _slope = (y0 - y1) / (x0 - x1);
84 _yOffset = - _slope * x1 + y1;
85
86 return 0;
87 }
88
89 double sum = double(n);
90 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
91 for (unsigned i = 0; i < n; i++) {
92 const TPoint2D & p = * (* _list)[i];
93 double x = p.x();
94 double y = p.y();
95 sumX += x;
96 sumY += y;
97 sumX2 += x * x;
98 sumXY += x * y;
99 sumY2 += y * y;
100 }
101
102 _det = sum * sumX2 - sumX * sumX;
103 if (_det == 0.) return -3;
104
105 _slope = (sumXY * sum - sumX * sumY) / _det;
106 _yOffset = (sumX2 * sumY - sumX * sumXY) / _det;
107
108 return 0;
109}
const Int_t n
Double_t x[10]
A class to represent a point in 2D.

◆ fit() [2/2]

int TLine2D::fit ( void  )

◆ list() [1/2]

const CAList< TPoint2D > & TLine2D::list ( void  ) const

Definition at line 64 of file TLine2D.cxx.

64 {
65 if (! _list)
66 _list = new CAList<TPoint2D>();
67 return * _list;
68}

◆ list() [2/2]

const CAList< TPoint2D > & TLine2D::list ( void  ) const

◆ remove() [1/2]

void TLine2D::remove ( const TPoint2D a)

Definition at line 58 of file TLine2D.cxx.

58 {
59 if (! _list) return;
60 _list->remove(a);
61}

◆ remove() [2/2]

void TLine2D::remove ( const TPoint2D )

◆ slope() [1/4]

double TLine2D::slope ( double  a)
inline

Definition at line 94 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

94 {
95 return _slope = a;
96}

◆ slope() [2/4]

double TLine2D::slope ( double  )

◆ slope() [3/4]

double TLine2D::slope ( void  ) const
inline

Definition at line 76 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

76 {
77 return _slope;
78}

◆ slope() [4/4]

double TLine2D::slope ( void  ) const

◆ xOffset() [1/2]

double TLine2D::xOffset ( void  ) const
inline

Definition at line 88 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

88 {
89 return - _yOffset / _slope;
90}

◆ xOffset() [2/2]

double TLine2D::xOffset ( void  ) const

◆ yOffset() [1/4]

double TLine2D::yOffset ( double  a)
inline

Definition at line 100 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

100 {
101 return _yOffset = a;
102}

◆ yOffset() [2/4]

double TLine2D::yOffset ( double  )

◆ yOffset() [3/4]

double TLine2D::yOffset ( void  ) const
inline

Definition at line 82 of file InstallArea/include/TrkReco/TrkReco/TLine2D.h.

82 {
83 return _yOffset;
84}

◆ yOffset() [4/4]

double TLine2D::yOffset ( void  ) const

The documentation for this class was generated from the following files: