Belle II Software  release-05-01-25
HoughPlaneBase.h
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : HoughPlaneBase.h
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A base class to represent a Hough parameter plane
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #ifndef TRGCDCHoughPlaneBase_FLAG_
15 #define TRGCDCHoughPlaneBase_FLAG_
16 
17 #include <string>
18 #include <vector>
19 #include "trg/trg/Point2D.h"
20 #include "trg/trg/Area2D.h"
21 #include "trg/cdc/HoughTransformation.h"
22 
23 #ifdef TRGCDC_SHORT_NAMES
24 #define TCHPlaneBase TRGCDCHoughPlaneBase
25 #endif
26 
27 namespace Belle2 {
33  class TRGCDCHoughPlaneBase {
35 
36  public:
37 
39  TRGCDCHoughPlaneBase(const std::string& name,
40  const TRGCDCHoughTransformation& transformation,
41  unsigned nX,
42  float xMin,
43  float xMax,
44  unsigned nY,
45  float yMin,
46  float yMax);
47 
49  virtual ~TRGCDCHoughPlaneBase();
50 
51  public:// Selectors
52 
54  std::string name(void) const;
55 
57  const TRGCDCHoughTransformation& transformation(void) const;
58 
60  float charge(void) const;
61 
63  unsigned nX(void) const;
64 
66  float xMin(void) const;
67 
69  float xMax(void) const;
70 
72  float xSize(void) const;
73 
75  unsigned nY(void) const;
76 
78  float yMin(void) const;
79 
81  float yMax(void) const;
82 
84  float ySize(void) const;
85 
87  virtual unsigned entry(unsigned id) const = 0;
88 
90  virtual unsigned entry(unsigned x, unsigned y) const = 0;
91 
93  virtual int maxEntry(void) const = 0;
94 
96  int maxEntryInRegion(unsigned id) const;
97 
99  unsigned serialId(unsigned x, unsigned y) const;
100 
102  unsigned serialId(const TRGPoint2D& p) const;
103 
105  void id(unsigned serialId, unsigned& x, unsigned& y) const;
106 
108  TRGPoint2D position(unsigned x, unsigned y) const;
109 
111  unsigned neighbor(unsigned serialID, unsigned direction) const;
112 
114  std::vector<unsigned> neighbors(unsigned serialID,
115  unsigned windowSize = 1) const;
116 
118  const std::vector<std::vector<unsigned> *>& regions(void) const;
119 
121  void locationInPlane(float x0, float y0, float x1, float y1,
122  unsigned& nFound,
123  unsigned& iX0, unsigned& iY0,
124  unsigned& iX1, unsigned& iY1) const;
125 
127  virtual void dump(const std::string& message = std::string(""),
128  const std::string& prefix = std::string("")) const;
129 
130  public:// Modifiers
131 
133  float charge(float charge);
134 
136  float xMin(float newXMin);
137 
139  float xMax(float newXMax);
140 
142  float yMin(float newYMin);
143 
145  float yMax(float newYMax);
146 
148  virtual void vote(float rx,
149  float ry,
150  int weight = 1);
151 
153  virtual void vote(float rx,
154  float ry,
155  int charge,
156  int weight = 1);
157 
159  virtual void vote(float xOffset, int weight = 1);
160 
162  virtual void registerPattern(unsigned id) = 0;
163 
165 // void smooth(void);
166 
168  virtual unsigned setEntry(unsigned serialId, unsigned n) = 0;
169 
171  void setRegion(std::vector<unsigned>*);
172 
174  void clearRegions(void);
175 
177  virtual void clear(void) = 0;
178 
179  protected:
180 
182  virtual void add(unsigned cellId, int weight) = 0;
183 
184  private:
185 
187  const std::string _name;
188 
191 
193  float _charge;
194 
196  const unsigned _nX;
197 
199  float _xMin;
200 
202  float _xMax;
203 
205  float _xSize;
206 
208  const unsigned _nY;
209 
211  float _yMin;
212 
214  float _yMax;
215 
217  float _ySize;
218 
221 
223  std::vector<std::vector<unsigned> *> _regions;
224  };
225 
226 //-----------------------------------------------------------------------------
227 
228  inline
229  float
231  {
232  return _charge;
233  }
234 
235  inline
236  float
238  {
239  return _charge = a;
240  }
241 
242  inline
243  std::string
245  {
246  return _name;
247  }
248 
249  inline
250  unsigned
252  {
253  return _nX;
254  }
255 
256  inline
257  float
259  {
260  return _xMin;
261  }
262 
263  inline
264  float
266  {
267  _xMin = a;
268  _xSize = (_xMax - _xMin) / float(_nX);
269  return _xMin;
270  }
271 
272  inline
273  float
275  {
276  return _xMax;
277  }
278 
279  inline
280  float
282  {
283  _xMax = a;
284  _xSize = (_xMax - _xMin) / float(_nX);
285  return _xMax;
286  }
287 
288  inline
289  float
291  {
292  return _xSize;
293  }
294 
295  inline
296  unsigned
298  {
299  return _nY;
300  }
301 
302  inline
303  float
305  {
306  return _yMin;
307  }
308 
309  inline
310  float
312  {
313  _yMin = a;
314  _ySize = (_yMax - _yMin) / float(_nY);
315  return _yMin;
316  }
317 
318  inline
319  float
321  {
322  return _yMax;
323  }
324 
325  inline
326  float
328  {
329  _yMax = a;
330  _ySize = (_yMax - _yMin) / float(_nY);
331  return _yMax;
332  }
333 
334  inline
335  float
337  {
338  return _ySize;
339  }
340 
341  inline
342  unsigned
343  TRGCDCHoughPlaneBase::serialId(unsigned x, unsigned y) const
344  {
345  return _nY * x + y;
346  }
347 
348  inline
349  unsigned
351  {
352  static const unsigned invalidPoint = _nX * _nY;
353  if ((p.x() < _xMin) || (p.x() > _xMax)) return invalidPoint;
354  if ((p.y() < _yMin) || (p.y() > _yMax)) return invalidPoint;
355 // unsigned x = (p.x() - _xMin) / _xSize;
356 // unsigned y = (p.y() - _yMin) / _ySize;
357  unsigned x = unsigned((p.x() - _xMin) / _xSize);
358  unsigned y = unsigned((p.y() - _yMin) / _ySize);
359  return serialId(x, y);
360  }
361 
362  inline
363  TRGPoint2D
364  TRGCDCHoughPlaneBase::position(unsigned x, unsigned y) const
365  {
366 #ifdef TRASAN_DEBUG_DETAIL
367 // std::cout << "x,y=" << x << "," << y
368 // << ":_xMin,_yMin=" << _xMin << "," << _yMin
369 // << ":_xSize,_ySize=" << _xSize << "," << _ySize << std::endl;
370 #endif
371 
372  return TRGPoint2D(_xMin + (float(x) + 0.5) * _xSize,
373  _yMin + (float(y) + 0.5) * _ySize);
374  }
375 
376  inline
377  std::vector<unsigned>
378  TRGCDCHoughPlaneBase::neighbors(unsigned a, unsigned windowSize) const
379  {
380  const int maxi = _nY * _nX;
381  std::vector<unsigned> tmp;
382 
383  const int xmin = - (int) windowSize;
384  const int xmax = (int) windowSize;
385  int ymin = - (int) windowSize;
386  int ymax = (int) windowSize;
387 
388  unsigned x = 0;
389  unsigned y = 0;
390  id(a, x, y);
391  if (((int) y + ymin) < 0) ymin = - (int) y;
392  if (((int) y + ymax) >= (int) _nY) ymax = _nY - (int) y;
393 
394  for (int i = xmin; i <= xmax; i++) {
395  for (int j = ymin; j <= ymax; j++) {
396  int ii = a + i * _nY + j;
397  if (ii == (int) a) continue;
398  if (ii < 0) ii += maxi;
399  if (ii >= maxi) ii -= maxi;
400 // tmp.append(ii);
401  tmp.push_back(ii);
402  }
403  }
404  return tmp;
405  }
406 
407  inline
408  void
409  TRGCDCHoughPlaneBase::setRegion(std::vector<unsigned>* a)
410  {
411 // _regions.append(a);
412  _regions.push_back(a);
413  }
414 
415  inline
416  const std::vector<std::vector<unsigned> *>&
418  {
419  return _regions;
420  }
421 
422  inline
423  unsigned
424  TRGCDCHoughPlaneBase::neighbor(unsigned id, unsigned dir) const
425  {
426  const unsigned maxi = _nY * _nX;
427  if (dir == 0) { // top
428  if ((id % _nY) != _nY - 1)
429  return id + 1;
430  } else if (dir == 1) { // top right
431  if ((id % _nY) != _nY - 1) {
432  const unsigned i = id + _nY + 1;
433  if (i < maxi)
434  return i;
435  else
436  return i - maxi;
437  }
438  } else if (dir == 2) { // right
439  const unsigned i = id + _nY;
440  if (i < maxi)
441  return i;
442  else
443  return i - maxi;
444  } else if (dir == 3) { // bottom right
445  if ((id % _nY) != 0) {
446  const unsigned i = id + _nY - 1;
447  if (i < maxi)
448  return i;
449  else
450  return i - maxi;
451  }
452  } else if (dir == 4) { // bottom
453  if ((id % _nY) != 0)
454  return id - 1;
455  } else if (dir == 5) { // bottom left
456  if ((id % _nY) != 0) {
457  const int i = id + _nY - 1;
458  if (i > 0)
459  return (unsigned) i;
460  else
461  return (unsigned) i + maxi;
462  }
463  } else if (dir == 6) { // left
464  const int i = id - _nY;
465  if (i > 0)
466  return (unsigned) i;
467  else
468  return (unsigned) i + maxi;
469  } else if (dir == 7) { // top left
470  if ((id % _nY) != _nY - 1) {
471  const int i = id - _nY + 1;
472  if (i > 0)
473  return (unsigned) i;
474  else
475  return (unsigned) i + maxi;
476  }
477  }
478 
479  return id;
480  }
481 
482  inline
483  void
484  TRGCDCHoughPlaneBase::id(unsigned serialId, unsigned& x, unsigned& y) const
485  {
486  x = serialId / _nY;
487  y = serialId % _nY;
488  }
489 
490  inline
491  void
493  {
494  // HepAListDeleteAll(_regions);
495  _regions.clear();
496  }
497 
498  inline
499  void
501  {
502  clearRegions();
503  }
504 
505  inline
506  void
508  float ry,
509  int weight)
510  {
511  vote(rx, ry, 0, weight);
512  }
513 
514  inline
515  void
517  {
518 // do nothing
519  }
520 
521  inline
524  {
525  return _trans;
526  }
527 
529 } // namespace Belle
530 
531 #endif
Belle2::TRGCDCHoughPlaneBase::_xMax
float _xMax
x max.
Definition: HoughPlaneBase.h:202
Belle2::TRGCDCHoughPlaneBase::dump
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: HoughPlaneBase.cc:224
Belle2::TRGPoint2D
A class to represent a point in 2D.
Definition: Point2D.h:32
Belle2::TRGCDCHoughPlaneBase::_yMin
float _yMin
y min.
Definition: HoughPlaneBase.h:211
Belle2::TRGCDCHoughPlaneBase::yMax
float yMax(void) const
returns max. of y.
Definition: HoughPlaneBase.h:320
Belle2::TRGCDCHoughPlaneBase::serialId
unsigned serialId(unsigned x, unsigned y) const
returns serial ID for position (x, y).
Definition: HoughPlaneBase.h:343
Belle2::TRGCDCHoughPlaneBase::_yMax
float _yMax
y max.
Definition: HoughPlaneBase.h:214
Belle2::TRGCDCHoughPlaneBase::name
std::string name(void) const
returns name.
Definition: HoughPlaneBase.h:244
Belle2::TRGCDCHoughPlaneBase::id
void id(unsigned serialId, unsigned &x, unsigned &y) const
returns x and y for serialID.
Definition: HoughPlaneBase.h:484
Belle2::TRGCDCHoughPlaneBase::charge
float charge(void) const
returns charge for this plane.
Definition: HoughPlaneBase.h:230
Belle2::TRGCDCHoughPlaneBase::neighbors
std::vector< unsigned > neighbors(unsigned serialID, unsigned windowSize=1) const
returns neighbors.
Definition: HoughPlaneBase.h:378
Belle2::TRGCDCHoughPlaneBase::maxEntry
virtual int maxEntry(void) const =0
returns max. count in a plane.
Belle2::TRGCDCHoughTransformation
An abstract class to represent a Hough transformation.
Definition: HoughTransformation.h:32
Belle2::TRGCDCHoughPlaneBase::clearRegions
void clearRegions(void)
Clears regions.
Definition: HoughPlaneBase.h:492
Belle2::TRGCDCHoughPlaneBase::_nX
const unsigned _nX
# of x bins.
Definition: HoughPlaneBase.h:196
Belle2::TRGCDCHoughPlaneBase::add
virtual void add(unsigned cellId, int weight)=0
Add to a cell.
Belle2::TRGCDCHoughPlaneBase::neighbor
unsigned neighbor(unsigned serialID, unsigned direction) const
returns neighbor cell.
Definition: HoughPlaneBase.h:424
Belle2::TRGCDCHoughPlaneBase::TRGCDCHoughPlaneBase
TRGCDCHoughPlaneBase(const std::string &name, const TRGCDCHoughTransformation &transformation, unsigned nX, float xMin, float xMax, unsigned nY, float yMin, float yMax)
Contructor.
Definition: HoughPlaneBase.cc:24
Belle2::TRGCDCHoughPlaneBase::entry
virtual unsigned entry(unsigned id) const =0
returns count of a cell.
Belle2::TRGCDCHoughPlaneBase::nY
unsigned nY(void) const
return # of y bins.
Definition: HoughPlaneBase.h:297
Belle2::TRGCDCHoughPlaneBase::clear
virtual void clear(void)=0
Clears all entries.
Definition: HoughPlaneBase.h:500
Belle2::TRGCDCHoughPlaneBase::_regions
std::vector< std::vector< unsigned > * > _regions
Regions.
Definition: HoughPlaneBase.h:223
Belle2::TRGCDCHoughPlaneBase::_xSize
float _xSize
Size of x bin.
Definition: HoughPlaneBase.h:205
Belle2::TRGCDCHoughPlaneBase::regions
const std::vector< std::vector< unsigned > * > & regions(void) const
returns regions.
Definition: HoughPlaneBase.h:417
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCHoughPlaneBase::maxEntryInRegion
int maxEntryInRegion(unsigned id) const
returns max. count in region.
Definition: HoughPlaneBase.cc:121
Belle2::TRGCDCHoughPlaneBase::position
TRGPoint2D position(unsigned x, unsigned y) const
returns position in Hough plain for a cell (x, y)..
Definition: HoughPlaneBase.h:364
Belle2::TRGCDCHoughPlaneBase::transformation
const TRGCDCHoughTransformation & transformation(void) const
returns Hough transformation object.
Definition: HoughPlaneBase.h:523
Belle2::TRGCDCHoughPlaneBase::_nY
const unsigned _nY
# of y bins.
Definition: HoughPlaneBase.h:208
Belle2::TRGCDCHoughPlaneBase::_charge
float _charge
Track charge for this plane.
Definition: HoughPlaneBase.h:193
Belle2::TRGCDCHoughPlaneBase::setRegion
void setRegion(std::vector< unsigned > *)
Sets region.
Definition: HoughPlaneBase.h:409
Belle2::TRGCDCHoughPlaneBase::ySize
float ySize(void) const
returns size of y bin.
Definition: HoughPlaneBase.h:336
Belle2::TRGCDCHoughPlaneBase::xMin
float xMin(void) const
returns min. of x.
Definition: HoughPlaneBase.h:258
Belle2::TRGCDCHoughPlaneBase::xMax
float xMax(void) const
returns max. of x.
Definition: HoughPlaneBase.h:274
Belle2::TRGCDCHoughPlaneBase::vote
virtual void vote(float rx, float ry, int weight=1)
Voring.
Definition: HoughPlaneBase.h:507
Belle2::TRGCDCHoughPlaneBase::setEntry
virtual unsigned setEntry(unsigned serialId, unsigned n)=0
smoothing
Belle2::TRGCDCHoughPlaneBase::_area
const TRGArea2D _area
Area.
Definition: HoughPlaneBase.h:220
Belle2::TRGArea2D
A class to represent an 2D area.
Definition: Area2D.h:26
Belle2::TRGCDCHoughPlaneBase::locationInPlane
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.
Definition: HoughPlaneBase.cc:54
Belle2::TRGCDCHoughPlaneBase::_name
const std::string _name
Name.
Definition: HoughPlaneBase.h:187
Belle2::TRGCDCHoughPlaneBase::_ySize
float _ySize
Size of y bin.
Definition: HoughPlaneBase.h:217
Belle2::TRGCDCHoughPlaneBase::nX
unsigned nX(void) const
returns # of x bins.
Definition: HoughPlaneBase.h:251
Belle2::TRGCDCHoughPlaneBase::_trans
const TRGCDCHoughTransformation & _trans
Hough transformation.
Definition: HoughPlaneBase.h:190
Belle2::TRGCDCHoughPlaneBase::yMin
float yMin(void) const
returns min. of y.
Definition: HoughPlaneBase.h:304
Belle2::TRGCDCHoughPlaneBase::xSize
float xSize(void) const
returns size of x bin.
Definition: HoughPlaneBase.h:290
Belle2::TRGCDCHoughPlaneBase::registerPattern
virtual void registerPattern(unsigned id)=0
registers a pattern..
Belle2::TRGCDCHoughPlaneBase::_xMin
float _xMin
x min.
Definition: HoughPlaneBase.h:199
Belle2::TRGCDCHoughPlaneBase::~TRGCDCHoughPlaneBase
virtual ~TRGCDCHoughPlaneBase()
Destructor.
Definition: HoughPlaneBase.cc:47