9 #include "CbmRichRingLight.h"
11 #include "../../littrack/std/utils/CbmLitMemoryManagment.h"
98 cout << endl << endl <<
"-E- CbmRichRingFinderHoughImpl::DoFind"
99 <<
". Number of hits is more than " <<
MAX_NOF_HITS << endl << endl;
149 unsigned int size =
fData.size();
150 for (
unsigned int iHit = 0; iHit < size; iHit++){
151 if (
fData[iHit].fIsUsed ==
true)
continue;
169 vector<CbmRichHoughHit>::iterator itmin, itmax;
178 *indmin = itmin -
fData.begin();
179 *indmax = itmax -
fData.begin();
181 int arSize = *indmax - *indmin + 1;
184 for (
unsigned short i = 0; i <
fNofParts; i++){
186 fHitInd[i].reserve( (*indmax-*indmin) / fNofParts);
189 unsigned short indmin1 = (
unsigned short)(*indmin);
190 unsigned short indmax1 = (
unsigned short)(*indmax);
192 for (
unsigned short i = indmin1; i <= indmax1; i++) {
193 if (
fData[i].fIsUsed ==
true)
continue;
194 float ry = y0 -
fData[i].fHit.fY;
196 float rx = x0 -
fData[i].fHit.fX;
197 float d = rx * rx + ry * ry;
202 for (
unsigned short j = 0; j <
fNofBinsXY; j++){
212 unsigned short int indmin,
213 unsigned short int indmax)
215 for (
int iPart = 0; iPart <
fNofParts; iPart++){
221 unsigned short int indmin,
222 unsigned short int indmax,
225 unsigned short nofHits =
fHitInd[iPart].size();
229 vector<CbmRichHoughHit>
data;
230 data.resize(nofHits);
231 for (
int i = 0; i < nofHits; i++){
235 typedef vector<CbmRichHoughHit>::iterator iH;
237 for (iH iHit1 = data.begin(); iHit1 != data.end(); iHit1++) {
238 float iH1X = iHit1->fHit.fX;
239 float iH1Y = iHit1->fHit.fY;
241 for (iH iHit2 = iHit1 + 1; iHit2 != data.end(); iHit2++) {
242 float iH2X = iHit2->fHit.fX;
243 float iH2Y = iHit2->fHit.fY;
245 float rx0 = iH1X - iH2X;
246 float ry0 = iH1Y- iH2Y;
247 float r12 = rx0 * rx0 + ry0 * ry0;
250 float t10 = iHit1->fX2plusY2 - iHit2->fX2plusY2;
251 for (iH iHit3 = iHit2 + 1; iHit3 != data.end(); iHit3++) {
252 float iH3X = iHit3->fHit.fX;
253 float iH3Y = iHit3->fHit.fY;
255 float rx1 = iH1X - iH3X;
256 float ry1 = iH1Y - iH3Y;
257 float r13 = rx1 * rx1 + ry1 * ry1;
258 if (r13 < fMinDistanceSq || r13 > fMaxDistanceSq)
continue;
260 float rx2 = iH2X - iH3X;
261 float ry2 = iH2Y - iH3Y;
262 float r23 = rx2 * rx2 + ry2 * ry2;
263 if (r23 < fMinDistanceSq || r23 > fMaxDistanceSq)
continue;
265 float det = rx2*ry0 - rx0*ry2;
266 if (det == 0.0f)
continue;
267 float t19 = 0.5f / det;
268 float t5 = iHit2->fX2plusY2 - iHit3->fX2plusY2;
270 float xc = (t5 * ry0 - t10 * ry2) * t19;
272 int intX = int( xcs *dx);
273 if (intX < 0 || intX >=
fNofBinsX )
continue;
275 float yc = (t10 * rx2 - t5 * rx0) * t19;
277 int intY = int( ycs *dy);
278 if (intY < 0 || intY >=
fNofBinsY )
continue;
281 float t6 = iH1X - xc;
282 float t7 = iH1Y - yc;
284 float r = sqrt(t6 * t6 + t7 * t7);
286 int intR = int(r *dr);
287 if (intR < 0 || intR >=
fNofBinsR)
continue;
302 int maxBinR = -1, maxR = -1;
303 unsigned int size =
fHistR.size();
304 for (
unsigned int k = 0;
k < size;
k++){
313 int maxBinXY = -1, maxXY = -1;
315 for (
unsigned int k = 0;
k < size;
k++){
321 if (maxBinXY <
fHTCut)
return;
330 r = (maxR + 0.5f) *
fDr;
331 for (
int j = indmin; j < indmax + 1; j++) {
332 rx =
fData[j].fHit.fX - xc;
333 ry =
fData[j].fHit.fY - yc;
335 dr = fabs(sqrt(rx * rx + ry * ry) - r);
336 if (dr > 0.6f)
continue;
356 for (
int j = indmin; j < indmax + 1; j++) {
357 rx =
fData[j].fHit.fX - xc;
358 ry =
fData[j].fHit.fY - yc;
360 dr = fabs(sqrt(rx * rx + ry * ry) - r);
361 if (dr > drCOPCut)
continue;
397 for (
int j = indmin; j < indmax + 1; j++) {
401 float dr = fabs(sqrt(rx * rx + ry * ry) - ring->
GetRadius());
403 fData[j].fIsUsed =
true;
412 set<unsigned short> usedHitsAll;
413 vector<unsigned short> goodRingIndex;
414 goodRingIndex.reserve(nofRings);
417 for (
int iRing = 0; iRing < nofRings; iRing++){
421 bool isGoodRingAll =
true;
422 int nofUsedHitsAll = 0;
423 for(
int iHit = 0; iHit < nofHits; iHit++){
424 set<unsigned short>::iterator
it = usedHitsAll.find(ring->
GetHitId(iHit));
425 if(it != usedHitsAll.end()){
430 isGoodRingAll =
false;
435 for (
int iRSet = 0; iRSet < goodRingIndex.size(); iRSet++){
438 goodRingIndex.push_back(iRing);
439 for(
int iHit = 0; iHit < nofHits; iHit++){
440 usedHitsAll.insert(ring->
GetHitId(iHit));
447 goodRingIndex.clear();
459 for(
int iHit1 = 0; iHit1 < nofHits1; iHit1++){
460 unsigned short hitInd1 = ring1->
GetHitId(iHit1);
461 for(
int iHit2 = 0; iHit2 < nofHits2; iHit2++){
462 unsigned short hitInd2 = ring2->
GetHitId(iHit2);
463 if(hitInd1 != hitInd2)
continue;
465 float hitX =
fData[hitIndData].fHit.fX;
466 float hitY =
fData[hitIndData].fHit.fY;
469 float dr1 = fabs(sqrt(rx1 * rx1 + ry1 * ry1) - ring1->
GetRadius());
473 float dr2 = fabs(sqrt(rx2 * rx2 + ry2 * ry2) - ring2->
GetRadius());
485 unsigned short hitInd)
487 unsigned short size =
fData.size();
488 for (
unsigned short i = 0; i < size; i++){
489 if (
fData[i].fId == hitInd)
return i;
501 register float t1,
t2, t3, t4, t5, t6, t8, t9,
502 t10, t11, t14, t16, t19, t21, t41;
508 t5 = t1 - t2 + t3 - t4;
512 t10 = t8 - t1 + t9 - t3;
516 t19 = 1.0f / (t14 * t6 - t16 * t11);
518 *xc = 0.5e0 * (t5 * t6 - t10 * t11) * t19;
519 *yc = 0.5e0 * (t10 * t14 - t5 * t16) * t19;
521 t21 = (x[0] - *xc)*(x[0] - *xc);
522 t41 = (y[0] - *yc)*(y[0] - *yc);
523 *r = sqrt(t21 + t41);