File indexing completed on 2026-11-12 09:43:56
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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "ActsExamples/Alignment/ExampleAlignedTransformUpdater.hpp"
0016 #include "ActsExamples/DetectorCommons/AlignmentContext.hpp"
0017 #include "ActsTests/CommonHelpers/DetectorElementStub.hpp"
0018
0019 #include <memory>
0020 #include <stdexcept>
0021 #include <unordered_map>
0022
0023 using namespace Acts;
0024 using namespace ActsExamples;
0025
0026 namespace ActsTests {
0027
0028 namespace {
0029
0030 std::unique_ptr<DetectorElementStub> makeElement(GeometryIdentifier geoId) {
0031 auto bounds = std::make_shared<const RectangleBounds>(10., 20.);
0032 auto element =
0033 std::make_unique<DetectorElementStub>(Transform3::Identity(), bounds, 1.);
0034 element->surface().assignGeometryId(geoId);
0035 return element;
0036 }
0037
0038 Transform3 placed(double x, double y, double z, double angle) {
0039 Transform3 transform = Transform3::Identity();
0040 transform.pretranslate(Vector3{x, y, z});
0041 transform.prerotate(Eigen::AngleAxisd(angle, Vector3::UnitZ()));
0042 return transform;
0043 }
0044
0045 bool sameTransform(const Transform3& lhs, const Transform3& rhs) {
0046 return lhs.matrix().isApprox(rhs.matrix(), 1e-9);
0047 }
0048
0049 std::shared_ptr<GeoIdAlignmentStore> makeStore() {
0050 return std::make_shared<GeoIdAlignmentStore>(
0051 std::unordered_map<GeometryIdentifier, Transform3>{});
0052 }
0053
0054 }
0055
0056 BOOST_AUTO_TEST_SUITE(ExampleAlignedTransformUpdaterSuite)
0057
0058 BOOST_AUTO_TEST_CASE(StoreUpdaterWritesAndReadsBack) {
0059 GeometryContext gctx = GeometryContext::dangerouslyDefaultConstruct();
0060 auto geoId = GeometryIdentifier().withVolume(1).withLayer(2).withSensitive(3);
0061 auto element = makeElement(geoId);
0062 auto store = makeStore();
0063 auto updater = makeAlignedTransformUpdater(store);
0064
0065 Transform3 aligned = placed(1., 2., 3., 0.3);
0066 BOOST_CHECK(updater(element.get(), gctx, aligned));
0067
0068 const Transform3* stored = store->contextualTransform(element->surface());
0069 BOOST_REQUIRE(stored != nullptr);
0070 BOOST_CHECK(sameTransform(*stored, aligned));
0071
0072 const auto& transforms = store->getTransformMap();
0073 BOOST_REQUIRE_EQUAL(transforms.count(geoId), 1u);
0074 BOOST_CHECK(sameTransform(transforms.at(geoId), aligned));
0075
0076 Transform3 updated = placed(4., 5., 6., -0.4);
0077 BOOST_CHECK(updater(element.get(), gctx, updated));
0078 stored = store->contextualTransform(element->surface());
0079 BOOST_REQUIRE(stored != nullptr);
0080 BOOST_CHECK(sameTransform(*stored, updated));
0081 BOOST_CHECK_EQUAL(store->getTransformMap().size(), 1u);
0082 }
0083
0084 BOOST_AUTO_TEST_CASE(StoreUpdaterRejectsNullInputs) {
0085 GeometryContext gctx = GeometryContext::dangerouslyDefaultConstruct();
0086 Transform3 aligned = placed(1., 0., 0., 0.2);
0087
0088 std::shared_ptr<GeoIdAlignmentStore> nullStore;
0089 BOOST_CHECK_THROW(makeAlignedTransformUpdater(nullStore),
0090 std::invalid_argument);
0091
0092 auto store = makeStore();
0093 auto updater = makeAlignedTransformUpdater(store);
0094 BOOST_CHECK(!updater(nullptr, gctx, aligned));
0095 BOOST_CHECK(store->getTransformMap().empty());
0096 }
0097
0098 BOOST_AUTO_TEST_SUITE_END()
0099
0100 }