Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-02 07:33:37

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0041 }  // namespace
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   // Test a cone
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->localToGlobalTransform(gctx).isApprox(
0069       coneRef->localToGlobalTransform(gctx)));
0070   BOOST_CHECK_EQUAL(coneTest->geometryId(), coneRef->geometryId());
0071   BOOST_CHECK_EQUAL(coneTest->bounds(), coneRef->bounds());
0072 }
0073 
0074 BOOST_AUTO_TEST_CASE(DiscSurfaceRoundTripTests) {
0075   Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0076   auto ring = std::make_shared<RadialBounds>(0., 4.);
0077   auto ringDiscRef = Surface::makeShared<DiscSurface>(trf, ring);
0078   ringDiscRef->assignGeometryId(GeometryIdentifier(10u));
0079 
0080   // Test a disc
0081   nlohmann::json discOut = SurfaceJsonConverter::toJson(gctx, *ringDiscRef);
0082   out.open("DiscSurface.json");
0083   out << discOut.dump(2);
0084   out.close();
0085 
0086   auto in = std::ifstream("DiscSurface.json",
0087                           std::ifstream::in | std::ifstream::binary);
0088   BOOST_CHECK(in.good());
0089   nlohmann::json discIn;
0090   in >> discIn;
0091   in.close();
0092 
0093   auto ringDiscTest = SurfaceJsonConverter::fromJson(discIn);
0094 
0095   BOOST_CHECK(ringDiscTest->localToGlobalTransform(gctx).isApprox(
0096       ringDiscRef->localToGlobalTransform(gctx)));
0097   BOOST_CHECK_EQUAL(ringDiscTest->geometryId(), ringDiscRef->geometryId());
0098   BOOST_CHECK_EQUAL(ringDiscTest->bounds(), ringDiscRef->bounds());
0099 }
0100 
0101 BOOST_AUTO_TEST_CASE(CylinderSurfaceRoundTripTests) {
0102   Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0103   auto tube = std::make_shared<CylinderBounds>(5., 20.);
0104   auto cylinderRef = Surface::makeShared<CylinderSurface>(trf, tube);
0105   cylinderRef->assignGeometryId(GeometryIdentifier(11u));
0106 
0107   // Test a cyoinder
0108   nlohmann::json cylinderOut = SurfaceJsonConverter::toJson(gctx, *cylinderRef);
0109   out.open("CylinderSurface.json");
0110   out << cylinderOut.dump(2);
0111   out.close();
0112 
0113   auto in = std::ifstream("CylinderSurface.json",
0114                           std::ifstream::in | std::ifstream::binary);
0115   BOOST_CHECK(in.good());
0116   nlohmann::json cylinderIn;
0117   in >> cylinderIn;
0118   in.close();
0119 
0120   auto cylinderTest = SurfaceJsonConverter::fromJson(cylinderIn);
0121 
0122   BOOST_CHECK(cylinderTest->localToGlobalTransform(gctx).isApprox(
0123       cylinderRef->localToGlobalTransform(gctx)));
0124   BOOST_CHECK_EQUAL(cylinderTest->geometryId(), cylinderRef->geometryId());
0125   BOOST_CHECK_EQUAL(cylinderTest->bounds(), cylinderRef->bounds());
0126 }
0127 
0128 BOOST_AUTO_TEST_CASE(PlaneSurfaceRoundTripTests) {
0129   Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0130   auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
0131   auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
0132   trapezoidPlaneRef->assignGeometryId(GeometryIdentifier(9u));
0133 
0134   // Test a plane
0135   nlohmann::json planeOut =
0136       SurfaceJsonConverter::toJson(gctx, *trapezoidPlaneRef);
0137   to_json(planeOut, *trapezoidPlaneRef);
0138   out.open("PlaneSurface.json");
0139   out << planeOut.dump(2);
0140   out.close();
0141 
0142   auto in = std::ifstream("PlaneSurface.json",
0143                           std::ifstream::in | std::ifstream::binary);
0144   BOOST_CHECK(in.good());
0145   nlohmann::json planeIn;
0146   in >> planeIn;
0147   in.close();
0148 
0149   auto trapezoidPlaneTest = SurfaceJsonConverter::fromJson(planeIn);
0150 
0151   BOOST_CHECK(trapezoidPlaneTest->localToGlobalTransform(gctx).isApprox(
0152       trapezoidPlaneRef->localToGlobalTransform(gctx)));
0153   BOOST_CHECK_EQUAL(trapezoidPlaneTest->geometryId(),
0154                     trapezoidPlaneRef->geometryId());
0155   BOOST_CHECK_EQUAL(trapezoidPlaneTest->bounds(), trapezoidPlaneRef->bounds());
0156 }
0157 
0158 BOOST_AUTO_TEST_CASE(StrawSurfaceRoundTripTests) {
0159   Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0160   auto straw = std::make_shared<LineBounds>(1., 100.);
0161   auto strawRef = Surface::makeShared<StrawSurface>(trf, straw);
0162   strawRef->assignGeometryId(GeometryIdentifier(12u));
0163 
0164   // Test a straw
0165   nlohmann::json strawOut = SurfaceJsonConverter::toJson(gctx, *strawRef);
0166   out.open("StrawSurface.json");
0167   out << strawOut.dump(2);
0168   out.close();
0169 
0170   auto in = std::ifstream("StrawSurface.json",
0171                           std::ifstream::in | std::ifstream::binary);
0172   BOOST_CHECK(in.good());
0173   nlohmann::json strawIn;
0174   in >> strawIn;
0175   in.close();
0176 
0177   auto strawTest = SurfaceJsonConverter::fromJson(strawIn);
0178 
0179   BOOST_CHECK(strawTest->localToGlobalTransform(gctx).isApprox(
0180       strawRef->localToGlobalTransform(gctx)));
0181   BOOST_CHECK_EQUAL(strawTest->geometryId(), strawRef->geometryId());
0182   BOOST_CHECK_EQUAL(strawTest->bounds(), strawRef->bounds());
0183 }
0184 
0185 BOOST_AUTO_TEST_CASE(PerigeeRoundTripTests) {
0186   Transform3 trf(Transform3::Identity() * Translation3(-1., -2., -7.));
0187   auto perigeeRef = Surface::makeShared<PerigeeSurface>(trf);
0188   perigeeRef->assignGeometryId(GeometryIdentifier(99u));
0189 
0190   // Test a perigee
0191   nlohmann::json perigeeOut = SurfaceJsonConverter::toJson(gctx, *perigeeRef);
0192   out.open("PerigeeSurface.json");
0193   out << perigeeOut.dump(2);
0194   out.close();
0195 
0196   auto in = std::ifstream("PerigeeSurface.json",
0197                           std::ifstream::in | std::ifstream::binary);
0198   BOOST_CHECK(in.good());
0199   nlohmann::json perigeeIn;
0200   in >> perigeeIn;
0201   in.close();
0202 
0203   auto perigeeTest = SurfaceJsonConverter::fromJson(perigeeIn);
0204 
0205   BOOST_CHECK(perigeeTest->localToGlobalTransform(gctx).isApprox(
0206       perigeeRef->localToGlobalTransform(gctx)));
0207   BOOST_CHECK_EQUAL(perigeeTest->geometryId(), perigeeRef->geometryId());
0208 }
0209 
0210 BOOST_AUTO_TEST_CASE(SurfacesDetrayTests) {
0211   Transform3 trf(Transform3::Identity() * Translation3(0., 0., -7.));
0212   auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
0213   auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
0214   trapezoidPlaneRef->assignGeometryId(GeometryIdentifier(9u));
0215 
0216   // Test a rectangle
0217   nlohmann::json trapOut =
0218       SurfaceJsonConverter::toJsonDetray(gctx, *trapezoidPlaneRef);
0219   out.open("Surfaces-detray.json");
0220   out << trapOut.dump(2);
0221   out.close();
0222 }
0223 
0224 BOOST_AUTO_TEST_SUITE_END()
0225 
0226 }  // namespace ActsTests