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 {
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
147 virtual void vote(float rx,
148 float ry,
149 int weight = 1);
150
152 virtual void vote(float rx,
153 float ry,
154 int charge,
155 int weight = 1);
156
158 virtual void vote(float xOffset, int weight = 1);
159
161 virtual void registerPattern(unsigned id) = 0;
162
164// void smooth(void);
165
167 virtual unsigned setEntry(unsigned serialId, unsigned n) = 0;
168
170 void setRegion(std::vector<unsigned>*);
171
173 void clearRegions(void);
174
176 virtual void clear(void) = 0;
177
178 protected:
179
181 virtual void add(unsigned cellId, int weight) = 0;
182
183 private:
184
186 const std::string _name;
187
190
192 float _charge;
193
195 const unsigned _nX;
196
198 float _xMin;
199
201 float _xMax;
202
204 float _xSize;
205
207 const unsigned _nY;
208
210 float _yMin;
211
213 float _yMax;
214
216 float _ySize;
217
220
222 std::vector<std::vector<unsigned> *> _regions;
223 };
224
225//-----------------------------------------------------------------------------
226
227 inline
228 float
230 {
231 return _charge;
232 }
233
234 inline
235 float
237 {
238 return _charge = a;
239 }
240
241 inline
242 std::string
244 {
245 return _name;
246 }
247
248 inline
249 unsigned
251 {
252 return _nX;
253 }
254
255 inline
256 float
258 {
259 return _xMin;
260 }
261
262 inline
263 float
265 {
266 _xMin = a;
267 _xSize = (_xMax - _xMin) / float(_nX);
268 return _xMin;
269 }
270
271 inline
272 float
274 {
275 return _xMax;
276 }
277
278 inline
279 float
281 {
282 _xMax = a;
283 _xSize = (_xMax - _xMin) / float(_nX);
284 return _xMax;
285 }
286
287 inline
288 float
290 {
291 return _xSize;
292 }
293
294 inline
295 unsigned
297 {
298 return _nY;
299 }
300
301 inline
302 float
304 {
305 return _yMin;
306 }
307
308 inline
309 float
311 {
312 _yMin = a;
313 _ySize = (_yMax - _yMin) / float(_nY);
314 return _yMin;
315 }
316
317 inline
318 float
320 {
321 return _yMax;
322 }
323
324 inline
325 float
327 {
328 _yMax = a;
329 _ySize = (_yMax - _yMin) / float(_nY);
330 return _yMax;
331 }
332
333 inline
334 float
336 {
337 return _ySize;
338 }
339
340 inline
341 unsigned
342 TRGCDCHoughPlaneBase::serialId(unsigned x, unsigned y) const
343 {
344 return _nY * x + y;
345 }
346
347 inline
348 unsigned
350 {
351 static const unsigned invalidPoint = _nX * _nY;
352 if ((p.x() < _xMin) || (p.x() > _xMax)) return invalidPoint;
353 if ((p.y() < _yMin) || (p.y() > _yMax)) return invalidPoint;
354// unsigned x = (p.x() - _xMin) / _xSize;
355// unsigned y = (p.y() - _yMin) / _ySize;
356 unsigned x = unsigned((p.x() - _xMin) / _xSize);
357 unsigned y = unsigned((p.y() - _yMin) / _ySize);
358 return serialId(x, y);
359 }
360
361 inline
363 TRGCDCHoughPlaneBase::position(unsigned x, unsigned y) const
364 {
365#ifdef TRASAN_DEBUG_DETAIL
366// std::cout << "x,y=" << x << "," << y
367// << ":_xMin,_yMin=" << _xMin << "," << _yMin
368// << ":_xSize,_ySize=" << _xSize << "," << _ySize << std::endl;
369#endif
370
371 return TRGPoint2D(_xMin + (float(x) + 0.5) * _xSize,
372 _yMin + (float(y) + 0.5) * _ySize);
373 }
374
375 inline
376 std::vector<unsigned>
377 TRGCDCHoughPlaneBase::neighbors(unsigned a, unsigned windowSize) const
378 {
379 const int maxi = _nY * _nX;
380 std::vector<unsigned> tmp;
381
382 const int xmin = - (int) windowSize;
383 const int xmax = (int) windowSize;
384 int ymin = - (int) windowSize;
385 int ymax = (int) windowSize;
386
387 unsigned x = 0;
388 unsigned y = 0;
389 id(a, x, y);
390 if (((int) y + ymin) < 0) ymin = - (int) y;
391 if (((int) y + ymax) >= (int) _nY) ymax = _nY - (int) y;
392
393 for (int i = xmin; i <= xmax; i++) {
394 for (int j = ymin; j <= ymax; j++) {
395 int ii = a + i * _nY + j;
396 if (ii == (int) a) continue;
397 if (ii < 0) ii += maxi;
398 if (ii >= maxi) ii -= maxi;
399// tmp.append(ii);
400 tmp.push_back(ii);
401 }
402 }
403 return tmp;
404 }
405
406 inline
407 void
408 TRGCDCHoughPlaneBase::setRegion(std::vector<unsigned>* a)
409 {
410// _regions.append(a);
411 _regions.push_back(a);
412 }
413
414 inline
415 const std::vector<std::vector<unsigned> *>&
417 {
418 return _regions;
419 }
420
421 inline
422 unsigned
423 TRGCDCHoughPlaneBase::neighbor(unsigned id, unsigned dir) const
424 {
425 const unsigned maxi = _nY * _nX;
426 if (dir == 0) { // top
427 if ((id % _nY) != _nY - 1)
428 return id + 1;
429 } else if (dir == 1) { // top right
430 if ((id % _nY) != _nY - 1) {
431 const unsigned i = id + _nY + 1;
432 if (i < maxi)
433 return i;
434 else
435 return i - maxi;
436 }
437 } else if (dir == 2) { // right
438 const unsigned i = id + _nY;
439 if (i < maxi)
440 return i;
441 else
442 return i - maxi;
443 } else if (dir == 3) { // bottom right
444 if ((id % _nY) != 0) {
445 const unsigned i = id + _nY - 1;
446 if (i < maxi)
447 return i;
448 else
449 return i - maxi;
450 }
451 } else if (dir == 4) { // bottom
452 if ((id % _nY) != 0)
453 return id - 1;
454 } else if (dir == 5) { // bottom left
455 if ((id % _nY) != 0) {
456 const int i = id + _nY - 1;
457 if (i > 0)
458 return (unsigned) i;
459 else
460 return (unsigned) i + maxi;
461 }
462 } else if (dir == 6) { // left
463 const int i = id - _nY;
464 if (i > 0)
465 return (unsigned) i;
466 else
467 return (unsigned) i + maxi;
468 } else if (dir == 7) { // top left
469 if ((id % _nY) != _nY - 1) {
470 const int i = id - _nY + 1;
471 if (i > 0)
472 return (unsigned) i;
473 else
474 return (unsigned) i + maxi;
475 }
476 }
477
478 return id;
479 }
480
481 inline
482 void
483 TRGCDCHoughPlaneBase::id(unsigned serialId, unsigned& x, unsigned& y) const
484 {
485 x = serialId / _nY;
486 y = serialId % _nY;
487 }
488
489 inline
490 void
492 {
493 // HepAListDeleteAll(_regions);
494 _regions.clear();
495 }
496
497 inline
498 void
500 {
501 clearRegions();
502 }
503
504 inline
505 void
507 float ry,
508 int weight)
509 {
510 vote(rx, ry, 0, weight);
511 }
512
513 inline
514 void
516 {
517// do nothing
518 }
519
520 inline
523 {
524 return _trans;
525 }
526
528} // namespace Belle
529
530#endif
A class to represent an 2D area.
Definition: Area2D.h:21
A class to represent a Hough parameter plane.
const TRGCDCHoughTransformation & _trans
Hough transformation.
const std::string _name
Name.
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 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).
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.