File indexing completed on 2025-01-18 09:13: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/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 auto surface = Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0038 Acts::Vector3(0., 1., 0.))
0039 .planeSurface();
0040
0041 auto portal =
0042 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0043
0044 BOOST_CHECK_NE(portal, nullptr);
0045
0046 auto jPortal = Acts::PortalJsonConverter::toJson(tContext, *portal, {});
0047
0048 out.open("portal.json");
0049 out << jPortal.dump(4);
0050 out.close();
0051
0052
0053 auto in =
0054 std::ifstream("portal.json", std::ifstream::in | std::ifstream::binary);
0055 BOOST_CHECK(in.good());
0056 nlohmann::json jPortalIn;
0057 in >> jPortalIn;
0058 in.close();
0059
0060 auto portalIn = Acts::PortalJsonConverter::fromJson(tContext, jPortalIn, {});
0061
0062 BOOST_CHECK_NE(portalIn, nullptr);
0063 }
0064
0065 BOOST_AUTO_TEST_CASE(PortalSingleConnected) {
0066 std::ofstream out;
0067
0068 auto forwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0069 auto backwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0070
0071 auto surface = Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0072 Acts::Vector3(0., 1., 0.))
0073 .planeSurface();
0074
0075 auto portal =
0076 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0077 BOOST_CHECK_NE(portal, nullptr);
0078
0079 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0080 *portal, forwardVolume, Acts::Direction::Forward());
0081 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0082 *portal, backwardVolume, Acts::Direction::Backward());
0083
0084 std::vector<const Acts::Experimental::DetectorVolume*> detectorVolumes = {
0085 forwardVolume.get(), backwardVolume.get()};
0086
0087 BOOST_CHECK_THROW(Acts::PortalJsonConverter::toJson(tContext, *portal, {}),
0088 std::runtime_error);
0089 auto jPortal =
0090 Acts::PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0091
0092 out.open("portal-single-connected.json");
0093 out << jPortal.dump(4);
0094 out.close();
0095
0096
0097 auto in = std::ifstream("portal-single-connected.json",
0098 std::ifstream::in | std::ifstream::binary);
0099 BOOST_CHECK(in.good());
0100 nlohmann::json jPortalIn;
0101 in >> jPortalIn;
0102 in.close();
0103
0104 auto portalIn = Acts::PortalJsonConverter::fromJson(
0105 tContext, jPortalIn, {forwardVolume, backwardVolume});
0106 BOOST_CHECK_NE(portalIn, nullptr);
0107 }
0108
0109 BOOST_AUTO_TEST_CASE(PortalMultiConnected) {
0110 std::ofstream out;
0111
0112 auto forwardVolumeA = std::make_shared<Acts::Experimental::DetectorVolume>();
0113 auto forwardVolumeB = std::make_shared<Acts::Experimental::DetectorVolume>();
0114 auto forwardVolumeC = std::make_shared<Acts::Experimental::DetectorVolume>();
0115
0116 auto backwardVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0117
0118 auto surface = Acts::CurvilinearSurface(Acts::Vector3(0., 0., 0.),
0119 Acts::Vector3(0., 1., 0.))
0120 .planeSurface();
0121
0122 auto portal =
0123 std::make_shared<Acts::Experimental::Portal>(std::move(surface));
0124 BOOST_CHECK_NE(portal, nullptr);
0125
0126
0127 Acts::Experimental::detail::PortalHelper::attachExternalNavigationDelegate(
0128 *portal, backwardVolume, Acts::Direction::Backward());
0129
0130 Acts::Experimental::detail::PortalHelper::attachDetectorVolumesUpdater(
0131 tContext, *portal, {forwardVolumeA, forwardVolumeB, forwardVolumeC},
0132 Acts::Direction::Forward(), {-100, 10, 20, 200},
0133 Acts::AxisDirection::AxisX);
0134
0135 std::vector<const Acts::Experimental::DetectorVolume*> detectorVolumes = {
0136 forwardVolumeA.get(), forwardVolumeB.get(), forwardVolumeC.get(),
0137 backwardVolume.get()};
0138
0139 auto jPortal =
0140 Acts::PortalJsonConverter::toJson(tContext, *portal, detectorVolumes);
0141
0142 out.open("portal-multi-connected.json");
0143 out << jPortal.dump(4);
0144 out.close();
0145 }
0146
0147 BOOST_AUTO_TEST_SUITE_END()