File indexing completed on 2026-12-03 09:44:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Surfaces/DiscTrapezoidBounds.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0013 #include "Acts/Utilities/MathHelpers.hpp"
0014 #include "Acts/Utilities/detail/OstreamStateGuard.hpp"
0015 #include "Acts/Utilities/detail/periodic.hpp"
0016
0017 #include <cmath>
0018 #include <iomanip>
0019 #include <iostream>
0020 #include <stdexcept>
0021
0022 namespace Acts {
0023
0024 DiscTrapezoidBounds::DiscTrapezoidBounds(double halfXminR, double halfXmaxR,
0025 double minR, double maxR,
0026 double avgPhi,
0027 double stereo) noexcept(false)
0028 : m_values({halfXminR, halfXmaxR, minR, maxR, avgPhi, stereo}) {
0029 checkConsistency();
0030 m_ymax = fastCathetus(get(eMaxR), get(eHalfLengthXmaxR));
0031 }
0032
0033 std::vector<double> DiscTrapezoidBounds::values() const {
0034 return {m_values.begin(), m_values.end()};
0035 }
0036
0037 void DiscTrapezoidBounds::checkConsistency() noexcept(false) {
0038 if (get(eMinR) < 0. || get(eMaxR) <= 0. || get(eMinR) > get(eMaxR)) {
0039 throw std::invalid_argument("DiscTrapezoidBounds: invalid radial setup.");
0040 }
0041 if (get(eHalfLengthXminR) < 0. || get(eHalfLengthXmaxR) <= 0.) {
0042 throw std::invalid_argument("DiscTrapezoidBounds: negative length given.");
0043 }
0044 if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
0045 throw std::invalid_argument(
0046 "DiscTrapezoidBounds: invalid phi positioning.");
0047 }
0048 }
0049
0050 Vector2 DiscTrapezoidBounds::toLocalCartesian(const Vector2& lposition) const {
0051 return {lposition[0] * std::sin(lposition[1] - get(eAveragePhi)),
0052 lposition[0] * std::cos(lposition[1] - get(eAveragePhi))};
0053 }
0054
0055 SquareMatrix2 DiscTrapezoidBounds::boundToCartesianJacobian(
0056 const Vector2& lposition) const {
0057
0058
0059
0060 const double cosPhi = std::cos(lposition[1]);
0061 const double sinPhi = std::sin(lposition[1]);
0062 SquareMatrix2 j;
0063 j(0, 0) = cosPhi;
0064 j(0, 1) = -lposition[0] * sinPhi;
0065 j(1, 0) = sinPhi;
0066 j(1, 1) = lposition[0] * cosPhi;
0067 return j;
0068 }
0069
0070 SquareMatrix2 DiscTrapezoidBounds::boundToCartesianMetric(
0071 const Vector2& lposition) const {
0072 SquareMatrix2 m;
0073 m(0, 0) = 1;
0074 m(0, 1) = 0;
0075 m(1, 0) = 0;
0076 m(1, 1) = lposition[0] * lposition[0];
0077 return m;
0078 }
0079
0080 bool DiscTrapezoidBounds::inside(const Vector2& lposition) const {
0081 const std::array<Vector2, 4> vertices{{{get(eHalfLengthXminR), get(eMinR)},
0082 {get(eHalfLengthXmaxR), m_ymax},
0083 {-get(eHalfLengthXmaxR), m_ymax},
0084 {-get(eHalfLengthXminR), get(eMinR)}}};
0085 return detail::VerticesHelper::isInsidePolygon(toLocalCartesian(lposition),
0086 vertices);
0087 }
0088
0089 Vector2 DiscTrapezoidBounds::closestPoint(const Vector2& lposition,
0090 const SquareMatrix2& metric) const {
0091 const std::array<Vector2, 4> vertices{{{get(eHalfLengthXminR), get(eMinR)},
0092 {get(eHalfLengthXmaxR), m_ymax},
0093 {-get(eHalfLengthXmaxR), m_ymax},
0094 {-get(eHalfLengthXminR), get(eMinR)}}};
0095 return detail::VerticesHelper::computeClosestPointOnPolygon(
0096 toLocalCartesian(lposition), vertices, metric);
0097 }
0098
0099 std::vector<Vector2> DiscTrapezoidBounds::vertices(
0100 unsigned int ) const {
0101 const Vector2 cAxis(std::cos(get(eAveragePhi)), std::sin(get(eAveragePhi)));
0102 const Vector2 nAxis(cAxis.y(), -cAxis.x());
0103 const double ymin = fastCathetus(get(eMinR), get(eHalfLengthXminR));
0104 const double halfY = (m_ymax - ymin) / 2;
0105 return {-halfY * cAxis - get(eHalfLengthXminR) * nAxis,
0106 -halfY * cAxis + get(eHalfLengthXminR) * nAxis,
0107 halfY * cAxis + get(eHalfLengthXmaxR) * nAxis,
0108 halfY * cAxis - get(eHalfLengthXmaxR) * nAxis};
0109 }
0110
0111 Vector2 DiscTrapezoidBounds::center() const {
0112
0113
0114 const double rCentroid = 0.5 * (get(eMinR) + get(eMaxR));
0115 const double phiCentroid = get(eAveragePhi);
0116 return Vector2(rCentroid, phiCentroid);
0117 }
0118
0119 std::ostream& DiscTrapezoidBounds::toStream(std::ostream& sl) const {
0120 detail::OstreamStateGuard guard{sl};
0121 sl << std::fixed << std::setprecision(7);
0122 sl << "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, "
0123 "halfLengthXminR, "
0124 "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
0125 "stereo) = ";
0126 sl << "(" << get(eMinR) << ", " << get(eMaxR) << ", " << get(eHalfLengthXminR)
0127 << ", " << get(eHalfLengthXmaxR) << ", " << halfLengthY() << ", "
0128 << halfPhiSector() << ", " << get(eAveragePhi) << ", " << rCenter() << ", "
0129 << stereo() << ")";
0130 return sl;
0131 }
0132
0133 }