File indexing completed on 2026-03-28 07:46:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010 #include <boost/test/unit_test_suite.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Geometry/TrackingVolume.hpp"
0017 #include "Acts/Navigation/IndexGridNavigationPolicy.hpp"
0018 #include "Acts/Surfaces/CylinderBounds.hpp"
0019 #include "Acts/Surfaces/CylinderSurface.hpp"
0020 #include "Acts/Surfaces/PlaneSurface.hpp"
0021 #include "Acts/Surfaces/RectangleBounds.hpp"
0022 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0023 #include "ActsPlugins/Json/IndexGridNavigationJsonConverter.hpp"
0024 #include "ActsTests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0025
0026 #include <fstream>
0027 #include <numbers>
0028
0029 #include <nlohmann/json.hpp>
0030
0031 using namespace Acts;
0032
0033 namespace ActsTests {
0034
0035 auto tContext = GeometryContext::dangerouslyDefaultConstruct();
0036 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0037 CylindricalTrackingGeometry::DetectorStore dStore;
0038
0039 auto tLogger =
0040 getDefaultLogger("IndexGridNavigationJsonConverterTests", Logging::INFO);
0041
0042 BOOST_AUTO_TEST_SUITE(JsonSuite)
0043
0044 BOOST_AUTO_TEST_CASE(RegularCylinderIndexGridNavigationPolicyToJson) {
0045 auto tContext = GeometryContext::dangerouslyDefaultConstruct();
0046 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0047 CylindricalTrackingGeometry::DetectorStore dStore;
0048
0049
0050 auto bSurfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.14, 31.,
0051 3., 2., {16, 14});
0052
0053 TrackingVolume tVolume(Transform3::Identity(),
0054 std::make_shared<CylinderVolumeBounds>(0., 50., 500.),
0055 "CylinderVolume");
0056
0057 for (const auto surface : bSurfaces) {
0058 tVolume.addSurface(surface->getSharedPtr());
0059 }
0060
0061
0062 Axis<AxisType::Equidistant, AxisBoundaryType::Closed> axisPhi(
0063 -std::numbers::pi, std::numbers::pi, 36);
0064 Axis<AxisType::Equidistant, AxisBoundaryType::Bound> axisZ(-400., 400., 30);
0065 Grid gridPhiZ(Type<std::vector<std::size_t>>, std::move(axisPhi),
0066 std::move(axisZ));
0067
0068 IndexGrid<decltype(gridPhiZ)> indexedGridPhiZ(
0069 std::move(gridPhiZ), {AxisDirection::AxisPhi, AxisDirection::AxisZ});
0070 IndexGridNavigationConfig phConfig;
0071 phConfig.referenceGenerator =
0072 std::make_shared<PolyhedronReferenceGenerator>();
0073 IndexGridNavigationPolicy<decltype(gridPhiZ)> polyNavigationPolicy(
0074 tContext, tVolume, *tLogger, phConfig, indexedGridPhiZ);
0075
0076
0077 IndexGridNavigationJsonConverter::Options options;
0078 options.writeSurfaces = true;
0079 options.writeProjectedSurfaces = true;
0080 nlohmann::json outputJson = IndexGridNavigationJsonConverter::toJson(
0081 tContext, polyNavigationPolicy, tVolume, options);
0082 BOOST_CHECK(outputJson.contains("surfaces"));
0083 BOOST_CHECK(outputJson.contains("projectedSurfaces"));
0084 BOOST_CHECK(outputJson.contains("type"));
0085 BOOST_CHECK(outputJson.contains("grid"));
0086 BOOST_CHECK_EQUAL(outputJson["type"],
0087 "RegularCylinderIndexGridNavigationPolicy");
0088
0089 std::ofstream jsonFile("RegularCylinderIndexGridNavigationPolicy.json");
0090 jsonFile << std::setw(2) << outputJson;
0091 jsonFile.close();
0092 }
0093
0094 BOOST_AUTO_TEST_CASE(RegularDiscIndexGridNavigationPolicyToJson) {
0095 TrackingVolume tVolume(Transform3::Identity(),
0096 std::make_shared<CylinderVolumeBounds>(0., 10., 2.),
0097 "DiscVolume");
0098
0099
0100 std::vector<std::shared_ptr<Surface>> discSurfaces;
0101 double rIr = 3.;
0102 auto boundsIr = std::make_shared<TrapezoidBounds>(0.2, 1.4, 2.2);
0103
0104 double rOr = 6.;
0105 auto boundsOr = std::make_shared<TrapezoidBounds>(1.2, 2.3, 2.2);
0106
0107 for (std::size_t is = 0; is < 12; ++is) {
0108 double phiIr = -std::numbers::pi + is * (std::numbers::pi / 6.0);
0109 AngleAxis3 rotationIr(phiIr - 0.5 * std::numbers::pi, Vector3::UnitZ());
0110 Transform3 transformIr(rotationIr);
0111 transformIr.translation() =
0112 Vector3(rIr * std::cos(phiIr), rIr * std::sin(phiIr), 0.);
0113 tVolume.addSurface(
0114 Surface::makeShared<PlaneSurface>(transformIr, boundsIr));
0115
0116 double phiOr = -std::numbers::pi + (is + 1) * (std::numbers::pi / 6.0);
0117 AngleAxis3 rotationOr(phiOr - 0.5 * std::numbers::pi, Vector3::UnitZ());
0118 Transform3 transformOr(rotationOr);
0119 transformOr.translation() =
0120 Vector3(rOr * std::cos(phiOr), rOr * std::sin(phiOr), 0.);
0121 tVolume.addSurface(
0122 Surface::makeShared<PlaneSurface>(transformOr, boundsOr));
0123 }
0124
0125
0126 Axis<AxisType::Equidistant, AxisBoundaryType::Bound> axisR(0.6, 8.6, 8);
0127 Axis<AxisType::Equidistant, AxisBoundaryType::Closed> axisPhi(
0128 -std::numbers::pi, std::numbers::pi, 36);
0129 Grid gridRPhi(Type<std::vector<std::size_t>>, std::move(axisR),
0130 std::move(axisPhi));
0131
0132 IndexGrid<decltype(gridRPhi)> indexedGridRPhi(
0133 std::move(gridRPhi), {AxisDirection::AxisR, AxisDirection::AxisPhi});
0134
0135 IndexGridNavigationConfig phConfig;
0136 auto referenceGenerator = std::make_shared<PolyhedronReferenceGenerator>();
0137 referenceGenerator->nSegements = 1;
0138 phConfig.referenceGenerator = referenceGenerator;
0139
0140 IndexGridNavigationPolicy<decltype(gridRPhi)> polyNavigationPolicy(
0141 tContext, tVolume, *tLogger, phConfig, indexedGridRPhi);
0142
0143
0144 IndexGridNavigationJsonConverter::Options options;
0145 options.writeSurfaces = true;
0146 options.writeProjectedSurfaces = true;
0147 nlohmann::json outputJson = IndexGridNavigationJsonConverter::toJson(
0148 tContext, polyNavigationPolicy, tVolume, options);
0149
0150 BOOST_CHECK(outputJson.contains("surfaces"));
0151 BOOST_CHECK(outputJson.contains("projectedSurfaces"));
0152 BOOST_CHECK(outputJson.contains("type"));
0153 BOOST_CHECK(outputJson.contains("grid"));
0154 BOOST_CHECK_EQUAL(outputJson["type"], "RegularDiscIndexGridNavigationPolicy");
0155
0156
0157 std::ofstream jsonFile("RegularDiscIndexGridNavigationPolicy.json");
0158 jsonFile << std::setw(2) << outputJson;
0159 jsonFile.close();
0160 }
0161
0162 BOOST_AUTO_TEST_CASE(RegularRingIndexGridNavigationPolicyToJson) {
0163
0164 TrackingVolume tVolume(Transform3::Identity(),
0165 std::make_shared<CylinderVolumeBounds>(0., 50., 5.),
0166 "RingVolume");
0167
0168 for (std::size_t is = 0; is < 16; ++is) {
0169 double phi = -std::numbers::pi + is * (std::numbers::pi / 8.0);
0170 AngleAxis3 rotation(phi - 0.5 * std::numbers::pi, Vector3::UnitZ());
0171 Transform3 transform(rotation);
0172 transform.translation() =
0173 Vector3(10 * std::cos(phi), 10 * std::sin(phi), 0.);
0174 tVolume.addSurface(Surface::makeShared<PlaneSurface>(
0175 transform, std::make_shared<TrapezoidBounds>(1.8, 3.6, 8.0)));
0176 }
0177
0178
0179 Axis<AxisType::Equidistant, AxisBoundaryType::Closed> axisPhi(
0180 -std::numbers::pi, std::numbers::pi, 8);
0181 Grid gridPhi(Type<std::vector<std::size_t>>, std::move(axisPhi));
0182
0183 IndexGrid<decltype(gridPhi)> indexedGridPhi(std::move(gridPhi),
0184 {AxisDirection::AxisPhi});
0185 IndexGridNavigationConfig phConfig;
0186 phConfig.referenceGenerator =
0187 std::make_shared<PolyhedronReferenceGenerator>();
0188 IndexGridNavigationPolicy<decltype(gridPhi)> polyNavigationPolicy(
0189 tContext, tVolume, *tLogger, phConfig, indexedGridPhi);
0190
0191
0192 IndexGridNavigationJsonConverter::Options options;
0193 options.numPolyhedronPoints = 2;
0194 options.writeSurfaces = true;
0195 options.writeProjectedSurfaces = true;
0196 nlohmann::json outputJson = IndexGridNavigationJsonConverter::toJson(
0197 tContext, polyNavigationPolicy, tVolume, options);
0198
0199 BOOST_CHECK(outputJson.contains("surfaces"));
0200 BOOST_CHECK(outputJson.contains("projectedSurfaces"));
0201 BOOST_CHECK(outputJson.contains("type"));
0202 BOOST_CHECK(outputJson.contains("grid"));
0203 BOOST_CHECK(outputJson.contains("projectedReferenceRange"));
0204 BOOST_CHECK_EQUAL(outputJson["type"], "RegularRingIndexGridNavigationPolicy");
0205
0206
0207 std::ofstream jsonFile("RegularRingIndexGridNavigationPolicy.json");
0208 jsonFile << std::setw(2) << outputJson;
0209 jsonFile.close();
0210 }
0211
0212 BOOST_AUTO_TEST_CASE(RegularPlaneIndexGridNavigationPolicyToJson) {
0213
0214 auto transform0 = Transform3::Identity();
0215 transform0.translation() = Vector3(-2., -2., 0.);
0216 auto planeSurface0 = Surface::makeShared<PlaneSurface>(
0217 transform0, std::make_shared<RectangleBounds>(2.49, 1.99));
0218
0219 auto transform1 = Transform3::Identity();
0220 transform1.translation() = Vector3(-1.5, 2., 0.);
0221 auto planeSurface1 = Surface::makeShared<PlaneSurface>(
0222 transform1, std::make_shared<RectangleBounds>(2.99, 1.99));
0223
0224 auto transform2 = Transform3::Identity();
0225 transform2.translation() = Vector3(2., 0., 0.);
0226 auto planeSurface2 = Surface::makeShared<PlaneSurface>(
0227 transform2, std::make_shared<RectangleBounds>(2.49, 3.49));
0228
0229
0230 Axis<AxisType::Equidistant, AxisBoundaryType::Bound> axisX(-4.5, 4.5, 9);
0231 Axis<AxisType::Equidistant, AxisBoundaryType::Bound> axisY(-3.5, 3.5, 7);
0232 Grid gridXY(Type<std::vector<std::size_t>>, std::move(axisX),
0233 std::move(axisY));
0234
0235 TrackingVolume tVolume(Transform3::Identity(),
0236 std::make_shared<CuboidVolumeBounds>(20., 20., 5.),
0237 "CuboidVolume");
0238 tVolume.addSurface(planeSurface0);
0239 tVolume.addSurface(planeSurface1);
0240 tVolume.addSurface(planeSurface2);
0241
0242 IndexGrid<decltype(gridXY)> indexedGridXY(
0243 std::move(gridXY), {AxisDirection::AxisX, AxisDirection::AxisY});
0244 IndexGridNavigationConfig phConfig;
0245 phConfig.referenceGenerator =
0246 std::make_shared<PolyhedronReferenceGenerator>();
0247 IndexGridNavigationPolicy<decltype(gridXY)> polyNavigationPolicy(
0248 tContext, tVolume, *tLogger, phConfig, indexedGridXY);
0249
0250 IndexGridNavigationJsonConverter::Options options;
0251 options.writeSurfaces = true;
0252 options.writeProjectedSurfaces = true;
0253 nlohmann::json outputJson = IndexGridNavigationJsonConverter::toJson(
0254 tContext, polyNavigationPolicy, tVolume, options);
0255
0256 BOOST_CHECK(outputJson.contains("surfaces"));
0257 BOOST_CHECK(outputJson.contains("projectedSurfaces"));
0258 BOOST_CHECK(outputJson.contains("type"));
0259 BOOST_CHECK(outputJson.contains("grid"));
0260 BOOST_CHECK_EQUAL(outputJson["type"],
0261 "RegularPlaneIndexGridNavigationPolicy");
0262
0263
0264 std::ofstream jsonFile("RegularPlaneIndexGridNavigationPolicy.json");
0265 jsonFile << std::setw(2) << outputJson;
0266 jsonFile.close();
0267 }
0268
0269 BOOST_AUTO_TEST_SUITE_END()
0270
0271 }