Belle II Software development
HoughPlaneBase.h
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#ifndef TRGCDCHoughPlaneBase_FLAG_
14#define TRGCDCHoughPlaneBase_FLAG_
15
16#include <string>
17#include <vector>
18#include "trg/trg/Point2D.h"
19#include "trg/trg/Area2D.h"
20#include "trg/cdc/HoughTransformation.h"
21
22#ifdef TRGCDC_SHORT_NAMES
23#define TCHPlaneBase TRGCDCHoughPlaneBase
24#endif
25
26namespace Belle2 {
31
34
35 public:
36
38 TRGCDCHoughPlaneBase(const std::string& name,
40 unsigned nX,
41 float xMin,
42 float xMax,
43 unsigned nY,
44 float yMin,
45 float yMax);
46
48 virtual ~TRGCDCHoughPlaneBase();
49
50 public:// Selectors
51
53 std::string name(void) const;
54
57
59 float charge(void) const;
60
62 unsigned nX(void) const;
63
65 float xMin(void) const;
66
68 float xMax(void) const;
69
71 float xSize(void) const;
72
74 unsigned nY(void) const;
75
77 float yMin(void) const;
78
80 float yMax(void) const;
81
83 float ySize(void) const;
84
86 virtual unsigned entry(unsigned id) const = 0;
87
89 virtual unsigned entry(unsigned x, unsigned y) const = 0;
90
92 virtual int maxEntry(void) const = 0;
93
95 int maxEntryInRegion(unsigned id) const;
96
98 unsigned serialId(unsigned x, unsigned y) const;
99
101 unsigned serialId(const TRGPoint2D& p) const;
102
104 void id(unsigned serialId, unsigned& x, unsigned& y) const;
105
107 TRGPoint2D position(unsigned x, unsigned y) const;
108
110 unsigned neighbor(unsigned serialID, unsigned direction) const;
111
113 std::vector<unsigned> neighbors(unsigned serialID,
114 unsigned windowSize = 1) const;
115
117 const std::vector<std::vector<unsigned> *>& regions(void) const;
118
120 void locationInPlane(float x0, float y0, float x1, float y1,
121 unsigned& nFound,
122 unsigned& iX0, unsigned& iY0,
123 unsigned& iX1, unsigned& iY1) const;
124
126 virtual void dump(const std::string& message = std::string(""),
127 const std::string& prefix = std::string("")) const;
128
129 public:// Modifiers
130
132 float charge(float charge);
133
135 float xMin(float newXMin);
136
138 float xMax(float newXMax);
139
141 float yMin(float newYMin);
142
144 float yMax(float newYMax);
145
146 // vote() is an intentional overload set. Derived planes such as
147 // TRGCDCHoughPlaneBoolean deliberately override only a subset and rely on a
148 // 'float charge' overload to disambiguate the 3- vs 4-argument forms (a
149 // plain 'using TRGCDCHoughPlaneBase::vote;' is not usable because the
150 // defaulted 'weight' argument would make vote(rx, ry, weight) ambiguous).
151 // The remaining base overloads are therefore hidden on purpose, so silence
152 // GCC's -Woverloaded-virtual here.
153#if defined(__GNUC__) && !defined(__clang__)
154#pragma GCC diagnostic push
155#pragma GCC diagnostic ignored "-Woverloaded-virtual"
156#endif
157
159 virtual void vote(float rx,
160 float ry,
161 int weight = 1);
162
164 virtual void vote(float rx,
165 float ry,
166 int charge,
167 int weight = 1);
168
170 virtual void vote(float xOffset, int weight = 1);
171
172#if defined(__GNUC__) && !defined(__clang__)
173#pragma GCC diagnostic pop
174#endif
175
177 virtual void registerPattern(unsigned id) = 0;
178
180// void smooth(void);
181
183 virtual unsigned setEntry(unsigned serialId, unsigned n) = 0;
184
186 void setRegion(std::vector<unsigned>*);
187
189 void clearRegions(void);
190
192 virtual void clear(void) = 0;
193
194 protected:
195
197 virtual void add(unsigned cellId, int weight) = 0;
198
199 private:
200
202 const std::string _name;
203
206
208 float _charge;
209
211 const unsigned _nX;
212
214 float _xMin;
215
217 float _xMax;
218
220 float _xSize;
221
223 const unsigned _nY;
224
226 float _yMin;
227
229 float _yMax;
230
232 float _ySize;
233
236
238 std::vector<std::vector<unsigned> *> _regions;
239 };
240
241//-----------------------------------------------------------------------------
242
243 inline
244 float
246 {
247 return _charge;
248 }
249
250 inline
251 float
253 {
254 return _charge = a;
255 }
256
257 inline
258 std::string
260 {
261 return _name;
262 }
263
264 inline
265 unsigned
267 {
268 return _nX;
269 }
270
271 inline
272 float
274 {
275 return _xMin;
276 }
277
278 inline
279 float
281 {
282 _xMin = a;
283 _xSize = (_xMax - _xMin) / float(_nX);
284 return _xMin;
285 }
286
287 inline
288 float
290 {
291 return _xMax;
292 }
293
294 inline
295 float
297 {
298 _xMax = a;
299 _xSize = (_xMax - _xMin) / float(_nX);
300 return _xMax;
301 }
302
303 inline
304 float
306 {
307 return _xSize;
308 }
309
310 inline
311 unsigned
313 {
314 return _nY;
315 }
316
317 inline
318 float
320 {
321 return _yMin;
322 }
323
324 inline
325 float
327 {
328 _yMin = a;
329 _ySize = (_yMax - _yMin) / float(_nY);
330 return _yMin;
331 }
332
333 inline
334 float
336 {
337 return _yMax;
338 }
339
340 inline
341 float
343 {
344 _yMax = a;
345 _ySize = (_yMax - _yMin) / float(_nY);
346 return _yMax;
347 }
348
349 inline
350 float
352 {
353 return _ySize;
354 }
355
356 inline
357 unsigned
358 TRGCDCHoughPlaneBase::serialId(unsigned x, unsigned y) const
359 {
360 return _nY * x + y;
361 }
362
363 inline
364 unsigned
366 {
367 static const unsigned invalidPoint = _nX * _nY;
368 if ((p.x() < _xMin) || (p.x() > _xMax)) return invalidPoint;
369 if ((p.y() < _yMin) || (p.y() > _yMax)) return invalidPoint;
370// unsigned x = (p.x() - _xMin) / _xSize;
371// unsigned y = (p.y() - _yMin) / _ySize;
372 unsigned x = unsigned((p.x() - _xMin) / _xSize);
373 unsigned y = unsigned((p.y() - _yMin) / _ySize);
374 return serialId(x, y);
375 }
376
377 inline
379 TRGCDCHoughPlaneBase::position(unsigned x, unsigned y) const
380 {
381#ifdef TRASAN_DEBUG_DETAIL
382// std::cout << "x,y=" << x << "," << y
383// << ":_xMin,_yMin=" << _xMin << "," << _yMin
384// << ":_xSize,_ySize=" << _xSize << "," << _ySize << std::endl;
385#endif
386
387 return TRGPoint2D(_xMin + (float(x) + 0.5) * _xSize,
388 _yMin + (float(y) + 0.5) * _ySize);
389 }
390
391 inline
392 std::vector<unsigned>
393 TRGCDCHoughPlaneBase::neighbors(unsigned a, unsigned windowSize) const
394 {
395 const int maxi = _nY * _nX;
396 std::vector<unsigned> tmp;
397
398 const int xmin = - (int) windowSize;
399 const int xmax = (int) windowSize;
400 int ymin = - (int) windowSize;
401 int ymax = (int) windowSize;
402
403 unsigned x = 0;
404 unsigned y = 0;
405 id(a, x, y);
406 if (((int) y + ymin) < 0) ymin = - (int) y;
407 if (((int) y + ymax) >= (int) _nY) ymax = _nY - (int) y;
408
409 for (int i = xmin; i <= xmax; i++) {
410 for (int j = ymin; j <= ymax; j++) {
411 int ii = a + i * _nY + j;
412 if (ii == (int) a) continue;
413 if (ii < 0) ii += maxi;
414 if (ii >= maxi) ii -= maxi;
415// tmp.append(ii);
416 tmp.push_back(ii);
417 }
418 }
419 return tmp;
420 }
421
422 inline
423 void
424 TRGCDCHoughPlaneBase::setRegion(std::vector<unsigned>* a)
425 {
426// _regions.append(a);
427 _regions.push_back(a);
428 }
429
430 inline
431 const std::vector<std::vector<unsigned> *>&
433 {
434 return _regions;
435 }
436
437 inline
438 unsigned
439 TRGCDCHoughPlaneBase::neighbor(unsigned id, unsigned dir) const
440 {
441 const unsigned maxi = _nY * _nX;
442 if (dir == 0) { // top
443 if ((id % _nY) != _nY - 1)
444 return id + 1;
445 } else if (dir == 1) { // top right
446 if ((id % _nY) != _nY - 1) {
447 const unsigned i = id + _nY + 1;
448 if (i < maxi)
449 return i;
450 else
451 return i - maxi;
452 }
453 } else if (dir == 2) { // right
454 const unsigned i = id + _nY;
455 if (i < maxi)
456 return i;
457 else
458 return i - maxi;
459 } else if (dir == 3) { // bottom right
460 if ((id % _nY) != 0) {
461 const unsigned i = id + _nY - 1;
462 if (i < maxi)
463 return i;
464 else
465 return i - maxi;
466 }
467 } else if (dir == 4) { // bottom
468 if ((id % _nY) != 0)
469 return id - 1;
470 } else if (dir == 5) { // bottom left
471 if ((id % _nY) != 0) {
472 const int i = id + _nY - 1;
473 if (i > 0)
474 return (unsigned) i;
475 else
476 return (unsigned) i + maxi;
477 }
478 } else if (dir == 6) { // left
479 const int i = id - _nY;
480 if (i > 0)
481 return (unsigned) i;
482 else
483 return (unsigned) i + maxi;
484 } else if (dir == 7) { // top left
485 if ((id % _nY) != _nY - 1) {
486 const int i = id - _nY + 1;
487 if (i > 0)
488 return (unsigned) i;
489 else
490 return (unsigned) i + maxi;
491 }
492 }
493
494 return id;
495 }
496
497 inline
498 void
499 TRGCDCHoughPlaneBase::id(unsigned serialId, unsigned& x, unsigned& y) const
500 {
501 x = serialId / _nY;
502 y = serialId % _nY;
503 }
504
505 inline
506 void
508 {
509 // HepAListDeleteAll(_regions);
510 _regions.clear();
511 }
512
513 inline
514 void
519
520 inline
521 void
523 float ry,
524 int weight)
525 {
526 vote(rx, ry, 0, weight);
527 }
528
529 // intentional overload set (see the vote() declarations above): silence
530 // GCC's -Woverloaded-virtual for this inline definition as well
531#if defined(__GNUC__) && !defined(__clang__)
532#pragma GCC diagnostic push
533#pragma GCC diagnostic ignored "-Woverloaded-virtual"
534#endif
535
536 inline
537 void
539 {
540// do nothing
541 }
542
543#if defined(__GNUC__) && !defined(__clang__)
544#pragma GCC diagnostic pop
545#endif
546
547 inline
550 {
551 return _trans;
552 }
553
555} // namespace Belle
556
557#endif
A class to represent an 2D area.
Definition Area2D.h:21
const TRGCDCHoughTransformation & _trans
Hough transformation.
const std::string _name
Name.
const unsigned _nX
# of x bins.
virtual void add(unsigned cellId, int weight)=0
Add to a cell.
virtual void registerPattern(unsigned id)=0
registers a pattern..
virtual unsigned entry(unsigned x, unsigned y) const =0
returns count of a cell.
virtual unsigned setEntry(unsigned serialId, unsigned n)=0
smoothing
virtual unsigned entry(unsigned id) const =0
returns count of a cell.
const TRGArea2D _area
Area.
float _charge
Track charge for this plane.
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.
An abstract class to represent a Hough transformation.
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.
virtual void clear(void)=0
Clears all entries.
float ySize(void) const
returns size of y bin.
virtual void vote(float rx, float ry, int weight=1)
Voring.
float xMin(void) const
returns min. of x.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
void setRegion(std::vector< unsigned > *)
Sets region.
unsigned nY(void) const
return # of y bins.
float xMax(void) const
returns max. of x.
float charge(void) const
returns charge for this plane.
void id(unsigned serialId, unsigned &x, unsigned &y) const
returns x and y for serialID.
const std::vector< std::vector< unsigned > * > & regions(void) const
returns regions.
unsigned serialId(unsigned x, unsigned y) const
returns serial ID for position (x, y).
TRGCDCHoughPlaneBase(const std::string &name, const TRGCDCHoughTransformation &transformation, unsigned nX, float xMin, float xMax, unsigned nY, float yMin, float yMax)
Constructor.
std::vector< unsigned > neighbors(unsigned serialID, unsigned windowSize=1) const
returns neighbors.
void clearRegions(void)
Clears regions.
float yMax(void) const
returns max. of y.
const TRGCDCHoughTransformation & transformation(void) const
returns Hough transformation object.
std::string name(void) const
returns name.
float xSize(void) const
returns size of x bin.
int maxEntryInRegion(unsigned id) const
returns max. count in region.
unsigned neighbor(unsigned serialID, unsigned direction) const
returns neighbor cell.
unsigned nX(void) const
returns # of x bins.
float yMin(void) const
returns min. of y.
TRGPoint2D position(unsigned x, unsigned y) const
returns position in Hough plain for a cell (x, y)..
Abstract base class for different kinds of events.