diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 0b86d999ac80c..bd309c93a764d 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -178,7 +178,7 @@ void SimTrackstersProducer::makePUTrackster(const std::vector& inputClust Trackster tmpTrackster; for (size_t i = 0; i < output_mask.size(); i++) { const float remaining_fraction = output_mask[i]; - if (remaining_fraction > 0.) { + if (remaining_fraction > std::numeric_limits::epsilon()) { tmpTrackster.vertices().push_back(i); tmpTrackster.vertex_multiplicity().push_back(1. / remaining_fraction); } diff --git a/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.cc b/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.cc index 1621521992779..8f4df46948af9 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.cc @@ -170,14 +170,30 @@ std::array TracksterLinkingbySkeletons::findSkeletonNodes( bool isInCylinder(const std::array &mySkeleton, const std::array &otherSkeleton, const float radius_sqr) { - const auto ¢er = mySkeleton[1]; + const auto &first = mySkeleton[0]; + const auto &last = mySkeleton[2]; const auto &pointToCheck = otherSkeleton[0]; - const auto distance2_xy = (pointToCheck.x() - center.x()) * (pointToCheck.x() - center.x()) + - (pointToCheck.y() - center.y()) * (pointToCheck.y() - center.y()); - LogDebug("TracksterLinkingbySkeletons") << " Distance XY " << distance2_xy << std::endl; - bool isWithinZ = std::abs(pointToCheck.z()) >= std::abs(mySkeleton[0].z()) and - std::abs(pointToCheck.z()) <= std::abs(mySkeleton[2].z()); - return (distance2_xy <= radius_sqr) && isWithinZ; + + const auto &cylAxis = last - first; + const auto &vecToPoint = pointToCheck - first; + + auto axisNorm = cylAxis.Dot(cylAxis); + auto projLength = vecToPoint.Dot(cylAxis) / axisNorm; + bool isWithinLength = projLength >= 0 && projLength <= 1; + + if (!isWithinLength) + return false; + + const auto &proj = cylAxis * projLength; + + const auto &pointOnAxis = first + proj; + + const auto &distance = pointToCheck - pointOnAxis; + auto distance2 = distance.Dot(distance); + + bool isWithinRadius = distance2 <= radius_sqr; + + return isWithinRadius; } bool TracksterLinkingbySkeletons::areCompatible(const ticl::Trackster &myTrackster,