File indexing completed on 2025-08-06 08:11:44
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/Plugins/Json/SurfaceJsonConverter.hpp"
0015 #include "Acts/Surfaces/ConeBounds.hpp"
0016 #include "Acts/Surfaces/ConeSurface.hpp"
0017 #include "Acts/Surfaces/CylinderBounds.hpp"
0018 #include "Acts/Surfaces/CylinderSurface.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/LineBounds.hpp"
0021 #include "Acts/Surfaces/PerigeeSurface.hpp"
0022 #include "Acts/Surfaces/PlaneSurface.hpp"
0023 #include "Acts/Surfaces/RadialBounds.hpp"
0024 #include "Acts/Surfaces/StrawSurface.hpp"
0025 #include "Acts/Surfaces/Surface.hpp"
0026 #include "Acts/Surfaces/SurfaceBounds.hpp"
0027 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0028
0029 #include <fstream>
0030 #include <memory>
0031 #include <string>
0032
0033 #include <nlohmann/json.hpp>
0034
0035 using namespace Acts;
0036
0037 std::ofstream out;
0038
0039 Acts::GeometryContext gctx;
0040
0041 BOOST_AUTO_TEST_SUITE(SurfaceJsonConversion)
0042
0043 BOOST_AUTO_TEST_CASE(ConeSurfaceRoundTripTests) {
0044 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0045 auto cone = std::make_shared<ConeBounds>(0.123, 10., 100.);
0046 auto coneRef = Surface::makeShared<ConeSurface>(trf, cone);
0047 coneRef->assignGeometryId(GeometryIdentifier(13u));
0048
0049
0050 nlohmann::json coneOut = SurfaceJsonConverter::toJson(gctx, *coneRef);
0051 out.open("ConeSurface.json");
0052 out << coneOut.dump(2);
0053 out.close();
0054
0055 auto in = std::ifstream("ConeSurface.json",
0056 std::ifstream::in | std::ifstream::binary);
0057 BOOST_CHECK(in.good());
0058 nlohmann::json coneIn;
0059 in >> coneIn;
0060 in.close();
0061
0062 auto coneTest = SurfaceJsonConverter::fromJson(coneIn);
0063
0064 BOOST_CHECK(coneTest->transform(gctx).isApprox(coneRef->transform(gctx)));
0065 BOOST_CHECK_EQUAL(coneTest->geometryId(), coneRef->geometryId());
0066 BOOST_CHECK_EQUAL(coneTest->bounds(), coneRef->bounds());
0067 }
0068
0069 BOOST_AUTO_TEST_CASE(DiscSurfaceRoundTripTests) {
0070 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0071 auto ring = std::make_shared<RadialBounds>(0., 4.);
0072 auto ringDiscRef = Surface::makeShared<DiscSurface>(trf, ring);
0073 ringDiscRef->assignGeometryId(GeometryIdentifier(10u));
0074
0075
0076 nlohmann::json discOut = SurfaceJsonConverter::toJson(gctx, *ringDiscRef);
0077 out.open("DiscSurface.json");
0078 out << discOut.dump(2);
0079 out.close();
0080
0081 auto in = std::ifstream("DiscSurface.json",
0082 std::ifstream::in | std::ifstream::binary);
0083 BOOST_CHECK(in.good());
0084 nlohmann::json discIn;
0085 in >> discIn;
0086 in.close();
0087
0088 auto ringDiscTest = SurfaceJsonConverter::fromJson(discIn);
0089
0090 BOOST_CHECK(
0091 ringDiscTest->transform(gctx).isApprox(ringDiscRef->transform(gctx)));
0092 BOOST_CHECK_EQUAL(ringDiscTest->geometryId(), ringDiscRef->geometryId());
0093 BOOST_CHECK_EQUAL(ringDiscTest->bounds(), ringDiscRef->bounds());
0094 }
0095
0096 BOOST_AUTO_TEST_CASE(CylinderSurfaceRoundTripTests) {
0097 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0098 auto tube = std::make_shared<CylinderBounds>(5., 20.);
0099 auto cylinderRef = Surface::makeShared<CylinderSurface>(trf, tube);
0100 cylinderRef->assignGeometryId(GeometryIdentifier(11u));
0101
0102
0103 nlohmann::json cylinderOut = SurfaceJsonConverter::toJson(gctx, *cylinderRef);
0104 out.open("CylinderSurface.json");
0105 out << cylinderOut.dump(2);
0106 out.close();
0107
0108 auto in = std::ifstream("CylinderSurface.json",
0109 std::ifstream::in | std::ifstream::binary);
0110 BOOST_CHECK(in.good());
0111 nlohmann::json cylinderIn;
0112 in >> cylinderIn;
0113 in.close();
0114
0115 auto cylinderTest = SurfaceJsonConverter::fromJson(cylinderIn);
0116
0117 BOOST_CHECK(
0118 cylinderTest->transform(gctx).isApprox(cylinderRef->transform(gctx)));
0119 BOOST_CHECK_EQUAL(cylinderTest->geometryId(), cylinderRef->geometryId());
0120 BOOST_CHECK_EQUAL(cylinderTest->bounds(), cylinderRef->bounds());
0121 }
0122
0123 BOOST_AUTO_TEST_CASE(PlaneSurfaceRoundTripTests) {
0124 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0125 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
0126 auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
0127 trapezoidPlaneRef->assignGeometryId(GeometryIdentifier(9u));
0128
0129
0130 nlohmann::json planeOut =
0131 SurfaceJsonConverter::toJson(gctx, *trapezoidPlaneRef);
0132 to_json(planeOut, *trapezoidPlaneRef);
0133 out.open("PlaneSurface.json");
0134 out << planeOut.dump(2);
0135 out.close();
0136
0137 auto in = std::ifstream("PlaneSurface.json",
0138 std::ifstream::in | std::ifstream::binary);
0139 BOOST_CHECK(in.good());
0140 nlohmann::json planeIn;
0141 in >> planeIn;
0142 in.close();
0143
0144 auto trapezoidPlaneTest = SurfaceJsonConverter::fromJson(planeIn);
0145
0146 BOOST_CHECK(trapezoidPlaneTest->transform(gctx).isApprox(
0147 trapezoidPlaneRef->transform(gctx)));
0148 BOOST_CHECK_EQUAL(trapezoidPlaneTest->geometryId(),
0149 trapezoidPlaneRef->geometryId());
0150 BOOST_CHECK_EQUAL(trapezoidPlaneTest->bounds(), trapezoidPlaneRef->bounds());
0151 }
0152
0153 BOOST_AUTO_TEST_CASE(StrawSurfaceRoundTripTests) {
0154 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0155 auto straw = std::make_shared<LineBounds>(1., 100.);
0156 auto strawRef = Surface::makeShared<StrawSurface>(trf, straw);
0157 strawRef->assignGeometryId(GeometryIdentifier(12u));
0158
0159
0160 nlohmann::json strawOut = SurfaceJsonConverter::toJson(gctx, *strawRef);
0161 out.open("StrawSurface.json");
0162 out << strawOut.dump(2);
0163 out.close();
0164
0165 auto in = std::ifstream("StrawSurface.json",
0166 std::ifstream::in | std::ifstream::binary);
0167 BOOST_CHECK(in.good());
0168 nlohmann::json strawIn;
0169 in >> strawIn;
0170 in.close();
0171
0172 auto strawTest = SurfaceJsonConverter::fromJson(strawIn);
0173
0174 BOOST_CHECK(strawTest->transform(gctx).isApprox(strawRef->transform(gctx)));
0175 BOOST_CHECK_EQUAL(strawTest->geometryId(), strawRef->geometryId());
0176 BOOST_CHECK_EQUAL(strawTest->bounds(), strawRef->bounds());
0177 }
0178
0179 BOOST_AUTO_TEST_CASE(PerigeeRoundTripTests) {
0180 Transform3 trf(Transform3::Identity() * Translation3(-1., -2., -7.));
0181 auto perigeeRef = Surface::makeShared<PerigeeSurface>(trf);
0182 perigeeRef->assignGeometryId(GeometryIdentifier(99u));
0183
0184
0185 nlohmann::json perigeeOut = SurfaceJsonConverter::toJson(gctx, *perigeeRef);
0186 out.open("PerigeeSurface.json");
0187 out << perigeeOut.dump(2);
0188 out.close();
0189
0190 auto in = std::ifstream("PerigeeSurface.json",
0191 std::ifstream::in | std::ifstream::binary);
0192 BOOST_CHECK(in.good());
0193 nlohmann::json perigeeIn;
0194 in >> perigeeIn;
0195 in.close();
0196
0197 auto perigeeTest = SurfaceJsonConverter::fromJson(perigeeIn);
0198
0199 BOOST_CHECK(
0200 perigeeTest->transform(gctx).isApprox(perigeeRef->transform(gctx)));
0201 BOOST_CHECK_EQUAL(perigeeTest->geometryId(), perigeeRef->geometryId());
0202 }
0203
0204 BOOST_AUTO_TEST_CASE(SurfacesDetrayTests) {
0205 Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0206 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
0207 auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
0208 trapezoidPlaneRef->assignGeometryId(GeometryIdentifier(9u));
0209
0210
0211 nlohmann::json trapOut =
0212 SurfaceJsonConverter::toJsonDetray(gctx, *trapezoidPlaneRef);
0213 out.open("Surfaces-detray.json");
0214 out << trapOut.dump(2);
0215 out.close();
0216 }
0217
0218 BOOST_AUTO_TEST_SUITE_END()