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: Add possibility to rotate the trapezoid bounds #2583

Merged
merged 15 commits into from
Mar 12, 2024
21 changes: 19 additions & 2 deletions Core/include/Acts/Surfaces/TrapezoidBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class TrapezoidBounds : public PlanarBounds {
eHalfLengthXnegY = 0,
eHalfLengthXposY = 1,
eHalfLengthY = 2,
eSize = 3
eRotationAngle = 3,
eSize = 4
};

TrapezoidBounds() = delete;
Expand All @@ -54,14 +55,29 @@ class TrapezoidBounds : public PlanarBounds {
checkConsistency();
}

/// Constructor for symmetric Trapezoid with rotation
///
/// @param halfXnegY minimal half length X, definition at negative Y
/// @param halfXposY maximal half length X, definition at positive Y
/// @param halfY half length Y - defined at x=0
/// @param rotAngle: rotation angle of the bounds w.r.t coordinate axes
TrapezoidBounds(double halfXnegY, double halfXposY, double halfY,
double rotAngle) noexcept(false)
andiwand marked this conversation as resolved.
Show resolved Hide resolved
: m_values({halfXnegY, halfXposY, halfY, rotAngle}),
m_boundingBox(std::max(halfXnegY, halfXposY), halfY),
m_rotMat{Eigen::Rotation2D<double>(rotAngle)} {
checkConsistency();
}

/// Constructor for symmetric Trapezoid - from fixed size array
///
/// @param values the values to be stream in
TrapezoidBounds(const std::array<double, eSize>& values) noexcept(false)
: m_values(values),
m_boundingBox(
std::max(values[eHalfLengthXnegY], values[eHalfLengthXposY]),
andiwand marked this conversation as resolved.
Show resolved Hide resolved
values[eHalfLengthY]) {
values[eHalfLengthY]),
m_rotMat{Eigen::Rotation2D<double>(values[eRotationAngle])} {
checkConsistency();
}

Expand Down Expand Up @@ -140,6 +156,7 @@ class TrapezoidBounds : public PlanarBounds {
private:
std::array<double, eSize> m_values;
RectangleBounds m_boundingBox;
RotationMatrix2 m_rotMat{RotationMatrix2::Identity()};
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// Check the input values for consistency, will throw a logic_exception
/// if consistency is not given
Expand Down
9 changes: 5 additions & 4 deletions Core/src/Surfaces/TrapezoidBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Acts::SurfaceBounds::BoundsType Acts::TrapezoidBounds::type() const {

bool Acts::TrapezoidBounds::inside(const Acts::Vector2& lposition,
const Acts::BoundaryCheck& bcheck) const {
const double x = lposition[0];
const double y = lposition[1];
const Acts::Vector2 extPosition = m_rotMat * lposition;
const double x = extPosition[0];
const double y = extPosition[1];

const double hlY = get(TrapezoidBounds::eHalfLengthY);
const double hlXnY = get(TrapezoidBounds::eHalfLengthXnegY);
Expand Down Expand Up @@ -70,9 +71,9 @@ const Acts::RectangleBounds& Acts::TrapezoidBounds::boundingBox() const {
std::ostream& Acts::TrapezoidBounds::toStream(std::ostream& sl) const {
sl << std::setiosflags(std::ios::fixed);
sl << std::setprecision(7);
sl << "Acts::TrapezoidBounds: (halfXnegY, halfXposY, halfY) = "
sl << "Acts::TrapezoidBounds: (halfXnegY, halfXposY, halfY, rotAngle) = "
<< "(" << get(eHalfLengthXnegY) << ", " << get(eHalfLengthXposY) << ", "
<< get(eHalfLengthY) << ")";
<< get(eHalfLengthY) << ", " << get(eRotationAngle) ")";
sl << std::setprecision(-1);
return sl;
}
14 changes: 14 additions & 0 deletions Tests/UnitTests/Core/Surfaces/PlaneSurfaceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"
#include "Acts/Surfaces/TrapezoidBounds.hpp"
#include "Acts/Tests/CommonHelpers/DetectorElementStub.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/BinningType.hpp"
Expand Down Expand Up @@ -269,6 +270,19 @@ BOOST_AUTO_TEST_CASE(PlaneSurfaceExtent) {
s_onSurfaceTolerance);
}

BOOST_AUTO_TEST_CASE(RotatedTrapezoid) {
double shortHalfX{100.}, longHalfX{200.}, halfY{300.},
rotAngle{45. * (M_PI / 180)};
std::shared_ptr<TrapezoidBounds> bounds =
std::make_shared<TrapezoidBounds>(shortHalfX, longHalfX, halfY, rotAngle);

Vector2 edgePoint{longHalfX - 10., halfY};

BOOST_CHECK_EQUAL(bounds->inside(edgePoint, true), false);
BOOST_CHECK_EQUAL(
bounds->inside(Eigen::Rotation2D{-rotAngle} * edgePoint, true), true);
}

/// Unit test for testing PlaneSurface alignment derivatives
BOOST_AUTO_TEST_CASE(PlaneSurfaceAlignment) {
// bounds object, rectangle type
Expand Down
Loading