17 #include "GaudiKernel/MsgStream.h"
42 m_baseSurfaces.clear();
43 m_tempSurfaces.clear();
55 evaluateInputDistance(
tt, position, direction,
true);
57 if (m_baseSurfaces.empty() ||
58 (m_baseSurfaces.back().distanceAlongPath < 0 &&
59 !
sf->isOnSurface(position, bcheck, m_tolerance)))
63 if (initFrameVolume(position, direction, fVol))
90 m_baseSurfaces.clear();
91 m_tempSurfaces.clear();
103 evaluateInputDistance(
tt, position, direction,
true);
105 if (m_baseSurfaces.empty() ||
106 (m_baseSurfaces.back().distanceAlongPath < 0 &&
107 !
sf->isOnSurface(position, bcheck, m_tolerance)))
111 if (initFrameVolume(position, direction, fVol))
112 return orderIntersections();
124 m_currentFrame = fVol;
125 m_currentDense = fVol;
128 std::cout <<
"DEBUG:input frame volume:" << fVol->
volumeName()
129 <<
" at position z:" << fVol->
center().z() << std::endl;
139 while (is != m_baseSurfaces.end() &&
142 if (is != m_baseSurfaces.end())
143 m_baseSurfaces.erase(is, m_baseSurfaces.end());
144 m_tempSurfaces.clear();
148 for (
unsigned int ib = 0;
ib < bounds.size(); ++
ib) {
156 evaluateInputDistance(bb,
pos,
dir,
true);
158 std::cout <<
"DEBUG:frame input:id:status:distance:" <<
ib <<
":"
169 is = m_baseSurfaces.begin();
170 while (is != m_baseSurfaces.end()) {
172 double dist = (*is).distanceAlongPath;
173 if (dist < m_tolerance && dist > dExit) {
175 if ((*is).surf->isOnSurface(probe,
true, m_tolerance, m_tolerance)) {
177 bounds[(*is).index]->attachedVolume(
179 if (nextVolume != fVol) {
198 m_distanceToNext = dExit;
200 std::cout <<
"DEBUG:early exit detected at boundary index:" << m_nextSf
201 <<
"," << dExit << std::endl;
211 std::cout <<
"DEBUG:volume exit resolved (SL estimate):" << m_nextSf <<
","
212 << m_distanceToNext << std::endl;
224 tt.surf->straightLineDistanceEstimate(
pos,
mom);
226 double dist = distSol.
first();
230 distSol.
second() > m_tolerance) {
234 !
tt.surf->isOnSurface(posi,
tt.bcheck, m_tolerance, m_tolerance))
241 tt.setPosition(posi);
242 if (fabs(dAbs) < m_tolerance)
250 if (!m_orderTrue || dist > m_tolerance) {
256 tt.setPosition(posi);
257 if (fabs(dAbs) < m_tolerance)
259 else if (dist > m_tolerance)
269 if (
tt.surf->isOnSurface(posi,
tt.bcheck, m_tolerance, m_tolerance)) {
275 tt.setPosition(posi);
276 if (fabs(dAbs) < m_tolerance)
291 double previousDistance =
tt.distanceAlongPath;
294 tt.surf->straightLineDistanceEstimate(
pos,
dir);
300 dist = distSol.
first();
302 fabs(distSol.
first() + m_lastStep - previousDistance) >
303 fabs(distSol.
second() + m_lastStep - previousDistance) &&
310 if (previousDistance * dist < 0. && fabs(dist) > m_tolerance) {
315 tt.distance < m_tolerance ||
320 if (
index == m_nextSf) {
322 std::cout <<
"DEBUG:flipping intersection:signed ? true dist:"
326 m_flipDirection =
true;
327 m_flipDistance = dist;
328 }
else if (
tt.distance > m_tolerance &&
331 if (
index > m_nextSf) {
332 if (dist < (m_flipDistance - m_tolerance) &&
tt.status != -1) {
333 m_flipDirection =
true;
334 m_flipDistance = dist;
337 }
else if (m_distanceToNext > 0.) {
339 if (
tt.status != -1) {
340 m_flipDirection =
true;
341 m_flipDistance = dist;
350 if (
index == m_nextSf && dist < 0. && previousDistance < dist)
351 m_distanceToNext = dist;
360 tt.setPosition(posi);
361 if (
tt.status == -1 && fabs(dAbs) > m_tolerance)
362 tt.status = dist > 0 ? 1 : 0;
372 m_baseSurfaces.push_back(
tt);
374 if (m_tempSurfaces.empty() ||
375 tt.assocVol != m_tempSurfaces.back()[0].assocVol) {
378 m_tempSurfaces.push_back(
local);
380 m_tempSurfaces.back().push_back(
tt);
391 if (m_baseSurfaces.empty())
394 std::vector<unsigned int> sols(m_baseSurfaces.size());
395 for (
unsigned int i = 0;
i < m_baseSurfaces.size(); ++
i) {
399 unsigned int itest = 1;
400 while (itest < sols.size()) {
401 if (m_baseSurfaces[sols[itest]].distanceAlongPath <
402 m_baseSurfaces[sols[itest - 1]].distanceAlongPath) {
403 unsigned int iex = sols[itest - 1];
404 sols[itest - 1] = sols[itest];
411 for (
unsigned int i = 0;
i < m_baseSurfaces.size(); ++
i)
412 tsOrd.push_back(m_baseSurfaces[sols[
i]]);
422 m_distanceToNext = 1.e06;
429 while (is != m_baseSurfaces.end()) {
430 if ((*is).status == -1 && (*is).distanceAlongPath > m_tolerance) {
432 double dd = (*is).distanceAlongPath;
433 if (
dd < m_distanceToNext) {
435 m_distanceToNext =
dd;
438 if ((*is).status != -1 && (*is).distanceAlongPath > m_tolerance) {
440 double dd = (*is).distanceAlongPath;
441 if (
dd > m_tolerance &&
dd < (*is).distance)
443 if (
dd < m_distanceToNext) {
445 m_distanceToNext =
dd;
451 for (
auto & tempSurface : m_tempSurfaces) {
452 is = tempSurface.begin();
453 while (is != tempSurface.end()) {
454 if ((*is).status != -1 && (*is).distanceAlongPath > m_tolerance) {
456 double dd = (*is).distanceAlongPath;
457 if (
dd > m_tolerance &&
dd < (*is).distance)
459 if (
dd < m_distanceToNext) {
461 m_distanceToNext =
dd;
476 m_lastStep = (
pos - m_probePos).
mag();
478 if (not(m_lastStep > 0.)) {
480 std::cout <<
"DEBUG:check distance with 0 step:"
481 <<
"next,dist:" << m_nextSf <<
"," << m_distanceToNext
489 int nextSfCandidate = -1;
490 m_distanceToNext = 1.e08;
492 m_flipDirection =
false;
499 while (is != m_baseSurfaces.end()) {
507 if ((*is).status == -1 ||
508 (fabs((*is).distance) - m_lastStep) < 2 * fabs(nextStep) || m_absDist) {
509 if (m_lastStep > m_tolerance)
513 (*is).fastDistanceUpdate(m_lastStep);
517 std::cout <<
"DEBUG:check distance:" <<
index <<
":" << (*is).status
518 <<
"," << (*is).distanceAlongPath <<
"," << (*is).distance
519 <<
"," << (*is).signAbsDist
520 <<
":flip dir,dist:" << m_flipDirection <<
"," << m_flipDistance
522 if ((*is).status != -1 || (*is).distanceAlongPath > m_tolerance) {
523 if ((*is).distanceAlongPath > -m_tolerance) {
525 double dd = (*is).distanceAlongPath;
526 if (
dd > m_tolerance &&
dd < (*is).distance)
528 if (
dd < m_distanceToNext) {
529 nextSfCandidate =
index;
530 m_distanceToNext =
dd;
542 if (nextSfCandidate < 0 && m_distanceToNext > 0.) {
543 if (!m_currentFrame->inside(
pos, 0.001)) {
544 std::cout <<
"ERROR:frame volume left, aborting:"
545 << m_currentFrame->volumeName() << std::endl;
549 is = m_baseSurfaces.begin();
550 while (is != m_baseSurfaces.end()) {
552 if ((*is).status != -1 || (*is).distance > m_tolerance) {
553 if ((*is).distance > -m_tolerance) {
555 double dd = (*is).distance;
556 if (
dd < m_distanceToNext) {
557 nextSfCandidate =
index;
558 m_distanceToNext =
dd;
566 std::cout <<
"DEBUG:closest frame estimate based on absolute distance:"
567 << nextSfCandidate <<
":" << m_distanceToNext
568 <<
", inside frame volume?" << m_currentFrame->inside(
pos, 0.)
573 for (
auto & tempSurface : m_tempSurfaces) {
574 is = tempSurface.begin();
576 while (is != tempSurface.end()) {
578 if ((*is).status == -1 ||
579 (fabs((*is).distance) - m_lastStep) < 2 * fabs(nextStep)) {
582 (*is).fastDistanceUpdate(m_lastStep);
585 if ((*is).status != -1 || (*is).distanceAlongPath > m_tolerance) {
586 if ((*is).distanceAlongPath > -m_tolerance) {
588 double dd = (*is).distanceAlongPath;
589 if (
dd > m_tolerance &&
dd < (*is).distance)
591 if (
dd < m_distanceToNext) {
592 nextSfCandidate =
index;
593 m_distanceToNext =
dd;
604 if (!m_flipDirection && nextSfCandidate != m_nextSf)
605 m_nextSf = nextSfCandidate;
611 m_distanceToNext = m_flipDistance;
617 std::cout <<
"DEBUG:check distance returns:next,dist:" << m_nextSf <<
","
618 << m_distanceToNext << std::endl;
632 std::cout <<
"fill solutions at R,z,phi:" << gp.perp() <<
"," << gp.z()
633 <<
"," << gp.phi() << std::endl;
636 while (is != m_baseSurfaces.end()) {
638 if ((*is).status != -1) {
640 if (
index == hitSf ||
641 fabs((*is).distanceAlongPath) < 0.01) {
643 std::cout <<
"DEBUG: onSurface, without bcheck, twice tolerance:"
644 << (*is).surf->isOnSurface(
645 gp, (*is).bcheck, m_tolerance, m_tolerance)
647 << (*is).surf->isOnSurface(
648 gp,
false, m_tolerance, m_tolerance)
650 << (*is).surf->isOnSurface(
651 gp, (*is).bcheck, 2 * m_tolerance, 2 * m_tolerance)
653 if ((*is).surf->isOnSurface(gp, (*is).bcheck, m_tolerance, m_tolerance))
654 solutions.push_back((*is));
655 else if ((*is).surf->isOnSurface(
660 solutions.push_back((*is));
661 if (m_debugMode && !m_currentFrame->inside(
663 std::cout <<
"DEBUG: frame boundary crossed outside volume "
664 << m_currentFrame->volumeName() << std::endl;
665 }
else if (
index == hitSf)
674 for (
auto & tempSurface : m_tempSurfaces) {
675 is = tempSurface.begin();
677 while (is != tempSurface.end()) {
679 if ((*is).status != -1) {
681 if (
index == hitSf ||
682 (*is).distanceAlongPath < 0.01) {
683 if ((*is).surf->isOnSurface(
684 gp, (*is).bcheck, m_tolerance, m_tolerance))
685 solutions.push_back((*is));
686 else if (
index == hitSf)