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