Belle II Software development
HoughPlaneBase.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9//-----------------------------------------------------------------------------
10// Description : A base class to represent a Hough parameter plane
11//-----------------------------------------------------------------------------
12
13#define TRGCDC_SHORT_NAMES
14
15#include "trg/cdc/HoughPlaneBase.h"
16
17namespace Belle2 {
24 const TCHTransformation& trans,
25 unsigned nX,
26 float xMin,
27 float xMax,
28 unsigned nY,
29 float yMin,
30 float yMax)
31 : _name(name),
32 _trans(trans),
33 _charge(0),
34 _nX(nX),
35 _xMin(xMin),
36 _xMax(xMax),
37 _xSize((xMax - xMin) / float(nX)),
38 _nY(nY),
39 _yMin(yMin),
40 _yMax(yMax),
41 _ySize((yMax - yMin) / float(nY)),
42 _area(TRGPoint2D(xMin, yMin), TRGPoint2D(xMax, yMax))
43 {
44 }
45
47 {
48 // HepAListDeleteAll(_regions);
50 }
51
52 void
53 TRGCDCHoughPlaneBase::locationInPlane(float x0, float y0, float x1, float y1,
54 unsigned& nFound,
55 unsigned& X0, unsigned& Y0,
56 unsigned& X1, unsigned& Y1) const
57 {
58
59 const TRGPoint2D p(x0, y0);
60 const TRGPoint2D q(x1, y1);
61
62 //...Boundary check...
63 if (_area.inArea(p) && _area.inArea(q)) {
64 X0 = unsigned((x0 - _xMin) / _xSize);
65 Y0 = unsigned((y0 - _yMin) / _ySize);
66 X1 = unsigned((x1 - _xMin) / _xSize);
67 Y1 = unsigned((y1 - _yMin) / _ySize);
68 nFound = 2;
69 return;
70 }
71
72 nFound = 0;
73 TRGPoint2D c[2];
74 _area.cross(p, q, nFound, c);
75 if (nFound == 2) {
76 X0 = unsigned((c[0].x() - _xMin) / _xSize);
77 Y0 = unsigned((c[0].y() - _yMin) / _ySize);
78 X1 = unsigned((c[1].x() - _xMin) / _xSize);
79 Y1 = unsigned((c[1].y() - _yMin) / _ySize);
80 }
81 }
82
83// void
84// TRGCDCHoughPlaneBase::smooth(void) {
85// unsigned * newCell = new unsigned[_nX * _nY];
86
87// for (unsigned i = 0; i < _nX; i++) {
88// for (unsigned j = 0; j < _nY; j++) {
89// unsigned il = i - 1;
90// if (i == 0) il = _nX - 1;
91// unsigned ir = i + 1;
92// if (ir == _nX) ir = 0;
93// unsigned jt = j + 1;
94// if (jt == _nY) jt = j;
95// unsigned jb = j - 1;
96// if (j == 0) jb = 0;
97
98// // const unsigned sum
99// // = entry(il, jt) + entry(i, jt) + entry(ir, jt)
100// // + entry(il, j) + entry(i, j) + entry(ir, j)
101// // + entry(il, jb) + entry(i, jb) + entry(ir, jb);
102// // const unsigned average = sum / 9;
103// const unsigned sum
104// = entry(i, jt) + entry(i, j) + entry(i, jb);
105// const unsigned average = sum / 3;
106
107// newCell[_nY * i + j] = average;
108// }
109// }
110
111// for (unsigned i = 0; i < _nX * _nY; i++) {
112// std::cout << "??? " << _cell[i] << " -> " << newCell[i] << std::endl;
113// _cell[i] = newCell[i];
114// }
115
116// delete[] newCell;
117// }
118
119 int
121 {
122#ifdef TRASAN_DEBUG
123 const std::string stage = "THghPlnBase::maxEntryInRegion";
124 EnterStage(stage);
125#endif
126#ifdef TRASAN_DEBUG_DETAIL
127 std::cout << Tab() << "target id=" << targetId << ",#regions="
128 << _regions.length() << std::endl;
129#endif
130// for (unsigned i = 0; i < (unsigned) _regions.length(); i++) {
131 for (unsigned i = 0; i < (unsigned) _regions.size(); i++) {
132 const std::vector<unsigned>& region = * _regions[i];
133 unsigned maxEntry = 0;
134 bool idFound = false;
135// for (unsigned j = 0; j < (unsigned) region.length(); j++) {
136 for (unsigned j = 0; j < (unsigned) region.size(); j++) {
137// const unsigned id = * region[j];
138 const unsigned id = region[j];
139 if (id == targetId) idFound = true;
140 if (maxEntry < entry(id))
141 maxEntry = entry(id);
142 }
143 if (idFound) {
144#ifdef TRASAN_DEBUG
145 LeaveStage(stage);
146#endif
147 return maxEntry;
148 }
149 }
150
151#ifdef TRASAN_DEBUG
152 LeaveStage(stage);
153#endif
154 return 0;
155 }
156
157 void
159 float ry,
160 int targetCharge,
161 int weight)
162 {
163
164 const HepGeom::Point3D<double> r(rx, ry, 0);
165
166 //...phi loop...
167 for (unsigned i = 0; i < _nX; i++) {
168 const float x0 = xSize() * float(i);
169 const HepGeom::Point3D<double> phi(cos(x0), sin(x0), 0);
170 float charge = r.cross(phi).z();
171 if (targetCharge != 0)
172 if (targetCharge * charge > 0)
173 continue;
174
175 const float y0 = _trans.y(rx, ry, x0);
176 const float x1 = xSize() * float(i + 1);
177 const float y1 = _trans.y(rx, ry, x1);
178
179 //...Location in the plane...
180 int iY0 = int((y0 - yMin()) / ySize());
181 int iY1 = int((y1 - yMin()) / ySize());
182
183 //...This is special implementation for Circle Hough...
184 if (_trans.diverge(rx, ry, x0, x1)) {
185 if (iY0 > 0) {
186 if (iY0 >= (int) _nY) continue;
187 iY1 = _nY - 1;
188 } else {
189 if (iY1 >= (int) _nY) continue;
190 iY0 = iY1;
191 iY1 = _nY - 1;
192 }
193 }
194
195 //...Sorting...
196 if (iY0 > iY1) {
197 const int tmp = iY0;
198 iY0 = iY1;
199 iY1 = tmp;
200 }
201
202 //...Both out of region ?...
203 if (iY1 < 0) continue;
204 if (iY0 >= (int) _nY) continue;
205
206 //...In region ?...
207 if (iY0 < 0) iY0 = 0;
208 if (iY0 >= (int) _nY) iY0 = _nY - 1;
209 //if (iY1 < 0) iY1 = 0; //redundant condition
210 if (iY1 >= (int) _nY) iY1 = _nY - 1;
211
212 //...Voting...
213 for (unsigned j = (unsigned) iY0; j < (unsigned)(iY1 + 1); j++) {
214// _cell[i * _nY + j] += weight;
215 add(i * _nY + j, weight);
216// if (_cell[i * _nY + j] < 0)
217// _cell[i * _nY + j] = 0;
218 }
219 }
220 }
221
222 void
223 TRGCDCHoughPlaneBase::dump(const std::string& message,
224 const std::string& prefix) const
225 {
226 std::cout << prefix << "dump of " << name() << ":" << message;
227 if (message != "region") {
228 bool first = true;
229 const unsigned n = _nX * _nY;
230 unsigned nDump = 0;
231 for (unsigned i = 0; i < n; i++) {
232 if (entry(i)) {
233 if (first)
234 first = false;
235 else
236 std::cout << ",";
237 if (!(nDump % 10)) std::cout << std::endl;
238 std::cout << i << "-" << entry(i);
239 ++nDump;
240 }
241 }
242 if (first)
243 std::cout << "no active cell";
244 }
245 std::cout << std::endl;
246// for (unsigned i = 0; i < _regions.length(); i++) {
247 for (unsigned i = 0; i < _regions.size(); i++) {
248 std::cout << prefix << " region " << i << ":";
249// for (unsigned j = 0; j < _regions[i]->length(); j++) {
250 for (unsigned j = 0; j < _regions[i]->size(); j++) {
251// const unsigned id = * (* _regions[i])[j];
252 const unsigned id = (* _regions[i])[j];
253 std::cout << id << "(" << entry(id) << "),";
254 }
255 std::cout << std::endl;
256 }
257// if (_regions.length())
258 if (_regions.size())
259 std::cout << std::endl;
260 }
261
263} // namespace Belle
const TRGCDCHoughTransformation & _trans
Hough transformation.
const unsigned _nX
# of x bins.
float _xSize
Size of x bin.
virtual void add(unsigned cellId, int weight)=0
Add to a cell.
float _ySize
Size of y bin.
virtual unsigned entry(unsigned id) const =0
returns count of a cell.
const TRGArea2D _area
Area.
std::vector< std::vector< unsigned > * > _regions
Regions.
virtual int maxEntry(void) const =0
returns max. count in a plane.
const unsigned _nY
# of y bins.
virtual float y(float xReal, float yReal, float x) const =0
returns Y coordinate in a Hough parameter plane.
virtual bool diverge(float xReal, float yReal, float x0, float x1) const =0
returns true if Y diverges in given region.
A class to represent a point in 2D.
Definition: Point2D.h:27
void locationInPlane(float x0, float y0, float x1, float y1, unsigned &nFound, unsigned &iX0, unsigned &iY0, unsigned &iX1, unsigned &iY1) const
returns cell positions in the region.
virtual ~TRGCDCHoughPlaneBase()
Destructor.
float ySize(void) const
returns size of y bin.
virtual void vote(float rx, float ry, int weight=1)
Voring.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
float charge(void) const
returns charge for this plane.
TRGCDCHoughPlaneBase(const std::string &name, const TRGCDCHoughTransformation &transformation, unsigned nX, float xMin, float xMax, unsigned nY, float yMin, float yMax)
Contructor.
void clearRegions(void)
Clears regions.
std::string name(void) const
returns name.
bool inArea(const TRGPoint2D &x) const
returns true if give point is in the area.
Definition: Area2D.h:50
float xSize(void) const
returns size of x bin.
int maxEntryInRegion(unsigned id) const
returns max. count in region.
void cross(const TRGPoint2D &x0, const TRGPoint2D &x1, unsigned &nFound, TRGPoint2D crossPoint[2]) const
returns cross-points.
Definition: Area2D.cc:29
float yMin(void) const
returns min. of y.
Abstract base class for different kinds of events.