BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
TLine2D.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TLine2D.cxx,v 1.5 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TLine2D.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to represent a line in 2D.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12// $Log: TLine2D.cxx,v $
13// Revision 1.5 2010/03/31 09:58:59 liucy
14// CLHEP based on 05.17
15//
16// Revision 1.2 2005/09/09 07:47:07 zangsl
17// 20050909 boss4.2 freeze
18//
19// Revision 1.1 1999/11/19 09:13:08 yiwasaki
20// Trasan 1.65d : new conf. finder updates, no change in default conf. finder
21//
22//
23//-----------------------------------------------------------------------------
24
25#define TLINE2D_INLINE_DEFINE_HERE
26#define HEP_SHORT_NAMES
27#include "CLHEP/Alist/ConstAList.h"
28#include "TrkReco/TPoint2D.h"
29#include "TrkReco/TLine2D.h"
30
31TLine2D::TLine2D() : _slope(1), _yOffset(0), _det(0), _list(0) {
32}
33
34TLine2D::TLine2D(double a, double b)
35: _slope(a),
36 _yOffset(b),
37 _det(0),
38 _list(0) {
39}
40
41TLine2D::TLine2D(const AList<TPoint2D> & a) : _slope(1), _yOffset(0), _det(0) {
42 _list = new CAList<TPoint2D>();
43 _list->append(a);
44}
45
47 if (_list) delete _list;
48}
49
50void
52 if (! _list)
53 _list = new CAList<TPoint2D>();
54 _list->append(a);
55}
56
57void
59 if (! _list) return;
60 _list->remove(a);
61}
62
63const CAList<TPoint2D> &
64TLine2D::list(void) const {
65 if (! _list)
66 _list = new CAList<TPoint2D>();
67 return * _list;
68}
69
70int
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}
110
111double
112TLine2D::distance(const TPoint2D & p) const {
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}
const Int_t n
Double_t x[10]
Definition: TLine2D.h:22
TLine2D()
Constructors.
Definition: TLine2D.cxx:31
double distance(const TPoint2D &) const
Definition: TLine2D.cxx:112
const CAList< TPoint2D > & list(void) const
Definition: TLine2D.cxx:64
void append(const TPoint2D &)
Definition: TLine2D.cxx:51
virtual ~TLine2D()
Destructor.
Definition: TLine2D.cxx:46
void remove(const TPoint2D &)
Definition: TLine2D.cxx:58
int fit(void)
Definition: TLine2D.cxx:71
A class to represent a point in 2D.
Definition: TPoint2D.h:37
double y(void) const
Definition: TPoint2D.h:94
double x(void) const
Definition: TPoint2D.h:88