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