Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Closest forward intersection #2923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions Core/include/Acts/Utilities/Intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class Intersection {

constexpr static Intersection invalid() { return Intersection(); }

/// Comparison function for forward order i.e. intersection closest to -inf
/// will be first.
constexpr static bool forwardOrder(const Intersection& aIntersection,
const Intersection& bIntersection) {
/// Comparison function for path length order i.e. intersection closest to
/// -inf will be first.
constexpr static bool pathLengthOrder(const Intersection& aIntersection,
const Intersection& bIntersection) {
auto a = aIntersection.pathLength();
auto b = bIntersection.pathLength();
return a < b;
Expand All @@ -99,6 +99,16 @@ class Intersection {
return std::abs(a) < std::abs(b);
}

/// Comparison function for closest forward order i.e. intersection closest to
/// 0 with positive path length will be first.
constexpr static bool closestForwardOrder(const Intersection& aIntersection,
const Intersection& bIntersection) {
auto a = aIntersection.pathLength();
auto b = bIntersection.pathLength();
return std::signbit(a) == std::signbit(b) ? std::abs(a) < std::abs(b)
: a > b;
}

private:
/// Position of the intersection
Position m_position = Position::Zero();
Expand Down Expand Up @@ -157,10 +167,11 @@ class ObjectIntersection {

constexpr static ObjectIntersection invalid() { return ObjectIntersection(); }

constexpr static bool forwardOrder(const ObjectIntersection& aIntersection,
const ObjectIntersection& bIntersection) {
return Intersection3D::forwardOrder(aIntersection.intersection(),
bIntersection.intersection());
constexpr static bool pathLengthOrder(
const ObjectIntersection& aIntersection,
const ObjectIntersection& bIntersection) {
return Intersection3D::pathLengthOrder(aIntersection.intersection(),
bIntersection.intersection());
}

constexpr static bool closestOrder(const ObjectIntersection& aIntersection,
Expand All @@ -169,6 +180,13 @@ class ObjectIntersection {
bIntersection.intersection());
}

constexpr static bool closestForwardOrder(
const ObjectIntersection& aIntersection,
const ObjectIntersection& bIntersection) {
return Intersection3D::closestForwardOrder(aIntersection.intersection(),
bIntersection.intersection());
}

private:
/// The intersection itself
Intersection3D m_intersection = Intersection3D::invalid();
Expand Down Expand Up @@ -218,6 +236,13 @@ class ObjectMultiIntersection {
ObjectIntersection<object_t>::closestOrder);
}

constexpr ObjectIntersection<object_t> closestForward() const {
auto splitIntersections = split();
return *std::min_element(splitIntersections.begin(),
splitIntersections.end(),
ObjectIntersection<object_t>::closestForwardOrder);
}

private:
/// The intersections
MultiIntersection3D m_intersections;
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Digitization/PlanarModuleStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
Intersection3D(endPoint, (startPoint - endPoint).norm(),
Intersection3D::Status::reachable));
std::sort(stepIntersections.begin(), stepIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);

Vector3 lastPosition = startPoint;
// reserve the right amount
Expand Down Expand Up @@ -121,7 +121,7 @@ std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
"More than 2 Boundary Surfaces intersected, this is an edge "
"case, resolving ... ");
std::sort(boundaryIntersections.begin(), boundaryIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
}
// if for some reason the intersection does not work
if (boundaryIntersections.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Geometry/GenericApproachDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Acts::SurfaceIntersection Acts::GenericApproachDescriptor::approachSurface(
return SurfaceIntersection::invalid();
}
return *std::min_element(sIntersections.begin(), sIntersections.end(),
SurfaceIntersection::forwardOrder);
SurfaceIntersection::pathLengthOrder);
}

const std::vector<const Acts::Surface*>&
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Geometry/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Acts::Layer::compatibleSurfaces(

// sort according to the path length
std::sort(sIntersections.begin(), sIntersections.end(),
SurfaceIntersection::forwardOrder);
SurfaceIntersection::pathLengthOrder);

return sIntersections;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Geometry/TrackingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ Acts::TrackingVolume::compatibleLayers(
}
std::sort(lIntersections.begin(), lIntersections.end(),
[](const LayerIntersection& a, const LayerIntersection& b) {
return SurfaceIntersection::forwardOrder(a.first, b.first);
return SurfaceIntersection::pathLengthOrder(a.first, b.first);
});
}
// and return
Expand Down Expand Up @@ -709,7 +709,7 @@ Acts::TrackingVolume::compatibleSurfacesFromHierarchy(

// Sort according to the path length
std::sort(sIntersections.begin(), sIntersections.end(),
SurfaceIntersection::forwardOrder);
SurfaceIntersection::pathLengthOrder);

return sIntersections;
}
2 changes: 1 addition & 1 deletion Fatras/src/Digitization/PlanarSurfaceMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Acts::Result<ActsFatras::PlanarSurfaceMask::Segment2D> maskAndReturn(
std::vector<Acts::Intersection2D>& intersections,
const ActsFatras::PlanarSurfaceMask::Segment2D& segment, bool firstInside) {
std::sort(intersections.begin(), intersections.end(),
Acts::Intersection2D::forwardOrder);
Acts::Intersection2D::pathLengthOrder);
if (intersections.size() >= 2) {
return ActsFatras::PlanarSurfaceMask::Segment2D{
intersections[0].position(), intersections[1].position()};
Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/Core/Geometry/BVHDataTestCase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BOOST_DATA_TEST_CASE(
}

// sort by path length
std::sort(hits.begin(), hits.end(), SurfaceIntersection::forwardOrder);
std::sort(hits.begin(), hits.end(), SurfaceIntersection::pathLengthOrder);
std::vector<const Surface*> expHits;
expHits.reserve(hits.size());
for (const auto& hit : hits) {
Expand Down
16 changes: 8 additions & 8 deletions Tests/UnitTests/Core/Utilities/IntersectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {

// let's sort the tsf intersection, it should give fst
std::sort(tsfpIntersections.begin(), tsfpIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
tsfpIntersections[0].pathLength());
BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
Expand All @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {

// shuffle the intersections
std::sort(ntfspIntersections.begin(), ntfspIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
ntfspIntersections[0].pathLength());
BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
Expand All @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {
ntfspIntersections[2].pathLength());

std::sort(tfnsnpIntersections.begin(), tfnsnpIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
tfnsnpIntersections[0].pathLength());
BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
Expand All @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {

// this time around, sort the f-s-t-n to match the t-s-f-n
std::sort(fstnIntersections.begin(), fstnIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(fstnIntersections[0].pathLength(),
tsfnIntersections[0].pathLength());
BOOST_CHECK_EQUAL(fstnIntersections[1].pathLength(),
Expand All @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {
// shuffle negative and positive solutions
std::vector<Intersection3D> pnsolutions = {tIp, sIn, sIp, fIn, tIn, fIp};
std::sort(pnsolutions.begin(), pnsolutions.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);

BOOST_CHECK_EQUAL(pnsolutions[0].pathLength(), -3.);
BOOST_CHECK_EQUAL(pnsolutions[1].pathLength(), -2.);
Expand All @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {
std::vector<Intersection3D> tszfpIntersections = {tIp, sIp, zI, fIp};

std::sort(tszfpIntersections.begin(), tszfpIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(tszfpIntersections[0].pathLength(), 0.);
BOOST_CHECK_EQUAL(tszfpIntersections[1].pathLength(), 1.);
BOOST_CHECK_EQUAL(tszfpIntersections[2].pathLength(), 2.);
Expand All @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(IntersectionTest) {
std::vector<Intersection3D> ztfsnIntersections = {zI, tIn, fIn, sIn};

std::sort(tfsznIntersections.begin(), tfsznIntersections.end(),
Intersection3D::forwardOrder);
Intersection3D::pathLengthOrder);
BOOST_CHECK_EQUAL(tfsznIntersections[0].pathLength(), -3.);
BOOST_CHECK_EQUAL(tfsznIntersections[1].pathLength(), -2.);
BOOST_CHECK_EQUAL(tfsznIntersections[2].pathLength(), -1.);
Expand Down Expand Up @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(ObjectIntersectionTest) {
// This should give 6 different intersections
std::set_union(firstSet.begin(), firstSet.end(), secondSet.begin(),
secondSet.end(), std::back_inserter(unionSetStd),
PlaneIntersection::forwardOrder);
PlaneIntersection::pathLengthOrder);
BOOST_CHECK_EQUAL(unionSetStd.size(), 6u);
}

Expand Down
Loading