File indexing completed on 2025-07-12 07:53:38
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/Direction.hpp"
0013 #include "Acts/Detector/Portal.hpp"
0014 #include "Acts/Detector/detail/PortalHelper.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Plugins/Json/PortalJsonConverter.hpp"
0017 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0018 #include "Acts/Surfaces/PlaneSurface.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0021
0022 #include <fstream>
0023
0024 #include <nlohmann/json.hpp>
0025
0026 namespace Acts::Experimental {
0027 class DetectorVolume {};
0028 }
0029
0030 Acts::GeometryContext tContext;
0031
0032 BOOST_AUTO_TEST_SUITE(PortalJsonConverter)
0033
0034 BOOST_AUTO_TEST_CASE(PortalUnconnected) {
0035 std::ofstream out;
0036
0037 std::shared_ptr<Acts::PlaneSurface> surface =
0038 Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0039 Acts::Vector3(0., 1., 0.))
0040 .planeSurface();
0041
0042 auto portal =
0043 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0044
0045 BOOST_CHECK_NE(portal, nullptr);
0046
0047 auto jPortal = Acts::PortalJsonConverter::toJson(tContext, *portal, {});
0048
0049 out.open("portal.json");
0050 out << jPortal.dump(4);
0051 out.close();
0052
0053
0054 auto in =
0055 std::ifstream("portal.json", std::ifstream::in | std::ifstream::binary);
0056 BOOST_CHECK(in.good());
0057 nlohmann::json jPortalIn;
0058 in >> jPortalIn;
0059 in.close();
0060
0061 auto portalIn = Acts::PortalJsonConverter::fromJson(tContext, jPortalIn, {});
0062
0063 BOOST_CHECK_NE(portalIn, nullptr);
0064 }
0065
0066 BOOST_AUTO_TEST_CASE(PortalSingleConnected) {
0067 std::ofstream out;
0068
0069 auto forwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0070 auto backwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0071
0072 std::shared_ptr<Acts::PlaneSurface> surface =
0073 Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0074 Acts::Vector3(0., 1., 0.))
0075 .planeSurface();
0076
0077 auto portal =
0078 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0079 BOOST_CHECK_NE(portal, nullptr);
0080
0081 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0082 *portal, forwardVolume, Acts::Direction::Forward());
0083 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0084 *portal, backwardVolume, Acts::Direction::Backward());
0085
0086 std::vector<const Acts::Experimental::DetectorVolume*> detectorVolumes = {
0087 forwardVolume.get(), backwardVolume.get()};
0088
0089 BOOST_CHECK_THROW(Acts::PortalJsonConverter::toJson(tContext, *portal, {}),
0090 std::runtime_error);
0091 auto jPortal =
0092 Acts::PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0093
0094 out.open("portal-single-connected.json");
0095 out << jPortal.dump(4);
0096 out.close();
0097
0098
0099 auto in = std::ifstream("portal-single-connected.json",
0100 std::ifstream::in | std::ifstream::binary);
0101 BOOST_CHECK(in.good());
0102 nlohmann::json jPortalIn;
0103 in >> jPortalIn;
0104 in.close();
0105
0106 auto portalIn = Acts::PortalJsonConverter::fromJson(
0107 tContext, jPortalIn, {forwardVolume, backwardVolume});
0108 BOOST_CHECK_NE(portalIn, nullptr);
0109 }
0110
0111 BOOST_AUTO_TEST_CASE(PortalMultiConnected) {
0112 std::ofstream out;
0113
0114 auto forwardVolumeA = std::make_shared<Acts::Experimental::DetectorVolume>();
0115 auto forwardVolumeB = std::make_shared<Acts::Experimental::DetectorVolume>();
0116 auto forwardVolumeC = std::make_shared<Acts::Experimental::DetectorVolume>();
0117
0118 auto backwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0119
0120 std::shared_ptr<Acts::PlaneSurface> surface =
0121 Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0122 Acts::Vector3(0., 1., 0.))
0123 .planeSurface();
0124
0125 auto portal =
0126 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0127 BOOST_CHECK_NE(portal, nullptr);
0128
0129
0130 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0131 *portal, backwardVolume, Acts::Direction::Backward());
0132
0133 Acts::Experimental::detail::PortalHelper::attachDetectorVolumesUpdater(
0134 tContext, *portal, {forwardVolumeA, forwardVolumeB, forwardVolumeC},
0135 Acts::Direction::Forward(), {-100, 10, 20, 200},
0136 Acts::AxisDirection::AxisX);
0137
0138 std::vector<const Acts::Experimental::DetectorVolume*> detectorVolumes = {
0139 forwardVolumeA.get(), forwardVolumeB.get(), forwardVolumeC.get(),
0140 backwardVolume.get()};
0141
0142 auto jPortal =
0143 Acts::PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0144
0145 out.open("portal-multi-connected.json");
0146 out << jPortal.dump(4);
0147 out.close();
0148 }
0149
0150 BOOST_AUTO_TEST_SUITE_END()