File indexing completed on 2025-07-11 07:51:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Surfaces/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Utilities/Result.hpp"
0018
0019 #include <array>
0020 #include <memory>
0021 #include <utility>
0022
0023 namespace Acts {
0024 class PlanarBounds;
0025 }
0026
0027 using namespace Acts::UnitLiterals;
0028
0029 namespace Acts::Test {
0030
0031
0032 struct AlignmentContext {
0033
0034 std::shared_ptr<const std::array<Transform3, 2>> alignmentStore = nullptr;
0035
0036
0037 unsigned int alignmentIndex{0};
0038
0039
0040 AlignmentContext() = default;
0041
0042
0043 explicit AlignmentContext(
0044 std::shared_ptr<const std::array<Transform3, 2>> aStore,
0045 unsigned int aIndex = 0)
0046 : alignmentStore(std::move(aStore)), alignmentIndex(aIndex) {}
0047 };
0048
0049
0050
0051
0052
0053 class AlignableDetectorElement : public DetectorElementBase {
0054 public:
0055
0056 AlignableDetectorElement() = delete;
0057
0058
0059
0060
0061
0062
0063
0064 AlignableDetectorElement(std::shared_ptr<const Transform3> transform,
0065 const std::shared_ptr<const PlanarBounds>& pBounds,
0066 double thickness)
0067 : DetectorElementBase(),
0068 m_elementTransform(std::move(transform)),
0069 m_elementThickness(thickness) {
0070 m_elementSurface = Surface::makeShared<PlaneSurface>(pBounds, *this);
0071 }
0072
0073
0074 ~AlignableDetectorElement() override = default;
0075
0076
0077
0078
0079
0080
0081 const Transform3& transform(const GeometryContext& gctx) const override;
0082
0083
0084 const Surface& surface() const override;
0085
0086
0087 Surface& surface() override;
0088
0089
0090 double thickness() const override;
0091
0092 private:
0093
0094 std::shared_ptr<const Transform3> m_elementTransform;
0095
0096 std::shared_ptr<Surface> m_elementSurface{nullptr};
0097
0098 double m_elementThickness{0.};
0099 };
0100
0101 inline const Transform3& AlignableDetectorElement::transform(
0102 const GeometryContext& gctx) const {
0103 auto alignContext = gctx.get<AlignmentContext>();
0104 if (alignContext.alignmentStore != nullptr &&
0105 alignContext.alignmentIndex < 2) {
0106 return (*(alignContext.alignmentStore))[alignContext.alignmentIndex];
0107 }
0108 return (*m_elementTransform);
0109 }
0110
0111 inline const Surface& AlignableDetectorElement::surface() const {
0112 return *m_elementSurface;
0113 }
0114
0115 inline Surface& AlignableDetectorElement::surface() {
0116 return *m_elementSurface;
0117 }
0118
0119 inline double AlignableDetectorElement::thickness() const {
0120 return m_elementThickness;
0121 }
0122
0123
0124 BOOST_AUTO_TEST_CASE(AlignmentContextTests) {
0125
0126 Vector3 nominalCenter(0., 0., 0.);
0127 Vector3 negativeCenter(0., 0., -1.);
0128 Vector3 positiveCenter(0., 0., 1.);
0129
0130
0131 Vector3 onNominal(3., 3., 0.);
0132 Vector3 onNegative(3., 3., -1.);
0133 Vector3 onPositive(3., 3., 1.);
0134
0135
0136 Vector2 localPosition(3., 3.);
0137
0138
0139 Vector3 globalPosition(100_cm, 100_cm, 100_cm);
0140 Vector3 dummyMomentum(4., 4., 4.);
0141
0142 Transform3 negativeTransform = Transform3::Identity();
0143 negativeTransform.translation() = negativeCenter;
0144
0145 Transform3 positiveTransform = Transform3::Identity();
0146 positiveTransform.translation() = positiveCenter;
0147
0148 std::array<Transform3, 2> alignmentArray = {negativeTransform,
0149 positiveTransform};
0150
0151 std::shared_ptr<const std::array<Transform3, 2>> alignmentStore =
0152 std::make_shared<const std::array<Transform3, 2>>(alignmentArray);
0153
0154
0155 AlignableDetectorElement alignedElement(
0156 std::make_shared<const Transform3>(Transform3::Identity()),
0157 std::make_shared<const RectangleBounds>(100_cm, 100_cm), 1_mm);
0158
0159 const auto& alignedSurface = alignedElement.surface();
0160
0161
0162 GeometryContext defaultContext{AlignmentContext{}};
0163 GeometryContext negativeContext{AlignmentContext{alignmentStore, 0}};
0164 GeometryContext positiveContext{AlignmentContext{alignmentStore, 1}};
0165
0166
0167 BOOST_CHECK(alignedSurface.transform(defaultContext)
0168 .isApprox(Transform3::Identity()));
0169 BOOST_CHECK(
0170 alignedSurface.transform(negativeContext).isApprox(negativeTransform));
0171 BOOST_CHECK(
0172 alignedSurface.transform(positiveContext).isApprox(positiveTransform));
0173
0174
0175 BOOST_CHECK_EQUAL(alignedSurface.center(defaultContext), nominalCenter);
0176 BOOST_CHECK_EQUAL(alignedSurface.center(negativeContext), negativeCenter);
0177 BOOST_CHECK_EQUAL(alignedSurface.center(positiveContext), positiveCenter);
0178
0179
0180 BOOST_CHECK(
0181 alignedSurface.isOnSurface(defaultContext, onNominal, dummyMomentum));
0182 BOOST_CHECK(
0183 alignedSurface.isOnSurface(negativeContext, onNegative, dummyMomentum));
0184 BOOST_CHECK(
0185 alignedSurface.isOnSurface(positiveContext, onPositive, dummyMomentum));
0186
0187
0188 globalPosition = alignedSurface.localToGlobal(defaultContext, localPosition,
0189 dummyMomentum);
0190 BOOST_CHECK_EQUAL(globalPosition, onNominal);
0191 localPosition =
0192 alignedSurface.globalToLocal(defaultContext, onNominal, dummyMomentum)
0193 .value();
0194 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0195
0196 globalPosition = alignedSurface.localToGlobal(negativeContext, localPosition,
0197 dummyMomentum);
0198 BOOST_CHECK_EQUAL(globalPosition, onNegative);
0199 localPosition =
0200 alignedSurface.globalToLocal(negativeContext, onNegative, dummyMomentum)
0201 .value();
0202 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0203
0204 globalPosition = alignedSurface.localToGlobal(positiveContext, localPosition,
0205 dummyMomentum);
0206 BOOST_CHECK_EQUAL(globalPosition, onPositive);
0207 localPosition =
0208 alignedSurface.globalToLocal(positiveContext, onPositive, dummyMomentum)
0209 .value();
0210 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0211 }
0212
0213 }