14 #define TRGCDC_SHORT_NAMES
17 #include "trg/cdc/HoughPlaneBoolean.h"
27 TRGCDCHoughPlaneBoolean::TRGCDCHoughPlaneBoolean(
const std::string& name,
28 const TCHTransformation& trans,
35 : TRGCDCHoughPlaneBase(name, trans, nX, xMin, xMax, nY, yMin, yMax),
37 _cell(new unsigned[_n]),
46 TRGCDCHoughPlaneBoolean::~TRGCDCHoughPlaneBoolean()
48 for (
unsigned i = 0; i < _nPatterns; i++)
49 delete [] _patterns[i];
57 TRGCDCHoughPlaneBoolean::vote(
float rx,
70 for (
unsigned i = 0; i < nX(); i++) {
71 const float x0 = xSize() * float(i);
73 float charge = r.cross(center).z();
74 if (targetCharge != 0)
75 if (targetCharge * charge > 0)
78 float y0 = transformation().y(rx, ry, x0);
79 const float x1 = xSize() * float(i + 1);
80 float y1 = transformation().y(rx, ry, x1);
88 if ((y0 == 0) && (y1 == 0))
90 else if ((y0 > yMax()) && (y1 > yMax()))
92 else if ((y0 < yMin()) && (y1 < yMin()))
96 if ((y0 == 0) && (y1 != 0))
98 else if ((y0 != 0) && (y1 == 0))
112 int iY0 = int((y0 - yMin()) / ySize());
113 int iY1 = int((y1 - yMin()) / ySize());
128 for (
unsigned j = (
unsigned) iY0; j < (unsigned)(iY1 + 1); j++) {
129 const unsigned k = i * nY() + j;
130 const unsigned b0 = k / 32;
131 const unsigned b1 = k % 32;
133 _cell[b0] |= (1 << b1);
135 _cell[b0] &= (~(1 << b1));
141 TRGCDCHoughPlaneBoolean::voteUsedInTrasan(
float rx,
150 for (
unsigned i = 0; i < nX(); i++) {
151 const float x0 = xSize() * float(i);
153 float charge = r.cross(phi).z();
154 if (targetCharge != 0)
155 if (targetCharge * charge > 0)
158 const float y0 = transformation().y(rx, ry, x0);
159 const float x1 = xSize() * float(i + 1);
160 const float y1 = transformation().y(rx, ry, x1);
163 int iY0 = int((y0 - yMin()) / ySize());
164 int iY1 = int((y1 - yMin()) / ySize());
167 if (transformation().diverge(rx, ry, x0, x1)) {
169 if (iY0 >= (
int) nY())
continue;
172 if (iY1 >= (
int) nY())
continue;
186 if (iY1 < 0)
continue;
187 if (iY0 >= (
int) nY())
continue;
190 if (iY0 < 0) iY0 = 0;
191 if (iY0 >= (
int) nY()) iY0 = nY() - 1;
193 if (iY1 >= (
int) nY()) iY1 = nY() - 1;
196 for (
unsigned j = (
unsigned) iY0; j < (unsigned)(iY1 + 1); j++) {
197 const unsigned k = i * nY() + j;
198 const unsigned b0 = k / 32;
199 const unsigned b1 = k % 32;
201 _cell[b0] |= (1 << b1);
203 _cell[b0] &= (~(1 << b1));
209 TRGCDCHoughPlaneBoolean::registerPattern(
unsigned id)
214 std::cout <<
"TRGCDCHoughPlaneBoolean::registerPattern !!! "
215 <<
"a pattern(id=" <<
id <<
") was already registered"
219 if (
id >= _nPatterns) {
220 std::cout <<
"TRGCDCHoughPlaneBoolean::registerPattern !!! "
221 <<
"given id(" <<
id <<
") is over range(" << _nPatterns <<
")"
225 const unsigned n = nX() * nY();
228 unsigned nActive = 0;
229 for (
unsigned i = 0; i < n; i++) {
230 const unsigned j = i / 32;
231 const unsigned k = i % 32;
232 if ((_cell[j] >> k) & 1) {
234 _reverse[i].push_back(
id);
237 _nActive[id] = nActive;
240 _patterns[id] =
new unsigned[nActive];
244 for (
unsigned i = 0; i < n; i++) {
245 const unsigned j = i / 32;
246 const unsigned k = i % 32;
247 if ((_cell[j] >> k) & 1) {
248 _patterns[id][l] = i;
255 TRGCDCHoughPlaneBoolean::preparePatterns(
unsigned nPatterns)
258 std::cout <<
"TRGCDCHoughPlaneBoolean::preparePatterns !!! "
259 <<
"patterns were already allocated" << std::endl;
263 _nPatterns = nPatterns;
264 _patterns =
new unsigned * [_nPatterns];
265 _nActive =
new unsigned[_nPatterns];
266 memset(_patterns, 0, _nPatterns *
sizeof(
unsigned*));
267 _reverse =
new vector<unsigned>[nX() * nY()];
271 TRGCDCHoughPlaneBoolean::vote(
unsigned patternId,
int weight)
273 const unsigned n = _nActive[patternId];
274 for (
unsigned i = 0; i < n; i++) {
275 add(_patterns[patternId][i], weight);
Abstract base class for different kinds of events.