File indexing completed on 2025-01-18 09:12:36
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 AlignmentContext(std::shared_ptr<const std::array<Transform3, 2>> aStore,
0044 unsigned int aIndex = 0)
0045 : alignmentStore(std::move(aStore)), alignmentIndex(aIndex) {}
0046 };
0047
0048
0049
0050
0051
0052 class AlignableDetectorElement : public DetectorElementBase {
0053 public:
0054
0055 AlignableDetectorElement() = delete;
0056
0057
0058
0059
0060
0061
0062
0063 AlignableDetectorElement(std::shared_ptr<const Transform3> transform,
0064 const std::shared_ptr<const PlanarBounds>& pBounds,
0065 double thickness)
0066 : DetectorElementBase(),
0067 m_elementTransform(std::move(transform)),
0068 m_elementThickness(thickness) {
0069 m_elementSurface = Surface::makeShared<PlaneSurface>(pBounds, *this);
0070 }
0071
0072
0073 ~AlignableDetectorElement() override = default;
0074
0075
0076
0077
0078
0079
0080 const Transform3& transform(const GeometryContext& gctx) const override;
0081
0082
0083 const Surface& surface() const override;
0084
0085
0086 Surface& surface() override;
0087
0088
0089 double thickness() const override;
0090
0091 private:
0092
0093 std::shared_ptr<const Transform3> m_elementTransform;
0094
0095 std::shared_ptr<Surface> m_elementSurface{nullptr};
0096
0097 double m_elementThickness{0.};
0098 };
0099
0100 inline const Transform3& AlignableDetectorElement::transform(
0101 const GeometryContext& gctx) const {
0102 auto alignContext = gctx.get<AlignmentContext>();
0103 if (alignContext.alignmentStore != nullptr &&
0104 alignContext.alignmentIndex < 2) {
0105 return (*(alignContext.alignmentStore))[alignContext.alignmentIndex];
0106 }
0107 return (*m_elementTransform);
0108 }
0109
0110 inline const Surface& AlignableDetectorElement::surface() const {
0111 return *m_elementSurface;
0112 }
0113
0114 inline Surface& AlignableDetectorElement::surface() {
0115 return *m_elementSurface;
0116 }
0117
0118 inline double AlignableDetectorElement::thickness() const {
0119 return m_elementThickness;
0120 }
0121
0122
0123 BOOST_AUTO_TEST_CASE(AlignmentContextTests) {
0124
0125 Vector3 nominalCenter(0., 0., 0.);
0126 Vector3 negativeCenter(0., 0., -1.);
0127 Vector3 positiveCenter(0., 0., 1.);
0128
0129
0130 Vector3 onNominal(3., 3., 0.);
0131 Vector3 onNegative(3., 3., -1.);
0132 Vector3 onPositive(3., 3., 1.);
0133
0134
0135 Vector2 localPosition(3., 3.);
0136
0137
0138 Vector3 globalPosition(100_cm, 100_cm, 100_cm);
0139 Vector3 dummyMomentum(4., 4., 4.);
0140
0141 Transform3 negativeTransform = Transform3::Identity();
0142 negativeTransform.translation() = negativeCenter;
0143
0144 Transform3 positiveTransform = Transform3::Identity();
0145 positiveTransform.translation() = positiveCenter;
0146
0147 std::array<Transform3, 2> alignmentArray = {negativeTransform,
0148 positiveTransform};
0149
0150 std::shared_ptr<const std::array<Transform3, 2>> alignmentStore =
0151 std::make_shared<const std::array<Transform3, 2>>(alignmentArray);
0152
0153
0154 AlignableDetectorElement alignedElement(
0155 std::make_shared<const Transform3>(Transform3::Identity()),
0156 std::make_shared<const RectangleBounds>(100_cm, 100_cm), 1_mm);
0157
0158 const auto& alignedSurface = alignedElement.surface();
0159
0160
0161 GeometryContext defaultContext{AlignmentContext{}};
0162 GeometryContext negativeContext{AlignmentContext{alignmentStore, 0}};
0163 GeometryContext positiveContext{AlignmentContext{alignmentStore, 1}};
0164
0165
0166 BOOST_CHECK(alignedSurface.transform(defaultContext)
0167 .isApprox(Transform3::Identity()));
0168 BOOST_CHECK(
0169 alignedSurface.transform(negativeContext).isApprox(negativeTransform));
0170 BOOST_CHECK(
0171 alignedSurface.transform(positiveContext).isApprox(positiveTransform));
0172
0173
0174 BOOST_CHECK_EQUAL(alignedSurface.center(defaultContext), nominalCenter);
0175 BOOST_CHECK_EQUAL(alignedSurface.center(negativeContext), negativeCenter);
0176 BOOST_CHECK_EQUAL(alignedSurface.center(positiveContext), positiveCenter);
0177
0178
0179 BOOST_CHECK(
0180 alignedSurface.isOnSurface(defaultContext, onNominal, dummyMomentum));
0181 BOOST_CHECK(
0182 alignedSurface.isOnSurface(negativeContext, onNegative, dummyMomentum));
0183 BOOST_CHECK(
0184 alignedSurface.isOnSurface(positiveContext, onPositive, dummyMomentum));
0185
0186
0187 globalPosition = alignedSurface.localToGlobal(defaultContext, localPosition,
0188 dummyMomentum);
0189 BOOST_CHECK_EQUAL(globalPosition, onNominal);
0190 localPosition =
0191 alignedSurface.globalToLocal(defaultContext, onNominal, dummyMomentum)
0192 .value();
0193 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0194
0195 globalPosition = alignedSurface.localToGlobal(negativeContext, localPosition,
0196 dummyMomentum);
0197 BOOST_CHECK_EQUAL(globalPosition, onNegative);
0198 localPosition =
0199 alignedSurface.globalToLocal(negativeContext, onNegative, dummyMomentum)
0200 .value();
0201 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0202
0203 globalPosition = alignedSurface.localToGlobal(positiveContext, localPosition,
0204 dummyMomentum);
0205 BOOST_CHECK_EQUAL(globalPosition, onPositive);
0206 localPosition =
0207 alignedSurface.globalToLocal(positiveContext, onPositive, dummyMomentum)
0208 .value();
0209 BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0210 }
0211
0212 }