Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-04 09:24:25

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/Navigation/DetectorVolumeFinders.hpp"
0012 #include "Acts/Navigation/PortalNavigation.hpp"
0013 #include "Acts/Utilities/GridAxisGenerators.hpp"
0014 #include "ActsPlugins/Json/DetectorVolumeFinderJsonConverter.hpp"
0015 
0016 #include <fstream>
0017 #include <memory>
0018 #include <vector>
0019 
0020 #include <nlohmann/json.hpp>
0021 
0022 using namespace Acts;
0023 
0024 namespace ActsTests {
0025 
0026 BOOST_AUTO_TEST_SUITE(JsonSuite)
0027 
0028 BOOST_AUTO_TEST_CASE(RzVolumes) {
0029   std::vector<double> zBoundaries = {-1000., -500, 150.};
0030   std::vector<double> rBoundaries = {0., 10., 30., 35.};
0031 
0032   using AxesGeneratorType = GridAxisGenerators::VarBoundVarBound;
0033 
0034   AxesGeneratorType zrAxes{zBoundaries, rBoundaries};
0035 
0036   // Create the grid with the provided axis generator
0037   using GridType = typename AxesGeneratorType::template grid_type<std::size_t>;
0038   GridType grid(zrAxes());
0039 
0040   using PointType = typename GridType::point_t;
0041 
0042   PointType p11 = {-800., 5.};
0043   PointType p12 = {-800., 20.};
0044   PointType p13 = {-800., 32.};
0045 
0046   grid.atPosition(p11) = 11u;
0047   grid.atPosition(p12) = 12u;
0048   grid.atPosition(p13) = 13u;
0049 
0050   PointType p21 = {0., 5.};
0051   PointType p22 = {0., 20.};
0052   PointType p23 = {0., 32.};
0053 
0054   grid.atPosition(p21) = 21u;
0055   grid.atPosition(p22) = 22u;
0056   grid.atPosition(p23) = 23u;
0057 
0058   auto casts =
0059       std::array<AxisDirection, 2u>{AxisDirection::AxisZ, AxisDirection::AxisR};
0060 
0061   using IndexedDetectorVolumesImpl = Experimental::IndexedGridNavigation<
0062       Experimental::IExternalNavigation, GridType,
0063       Experimental::IndexedDetectorVolumeExtractor,
0064       Experimental::DetectorVolumeFiller>;
0065 
0066   auto indexedDetectorVolumesImpl =
0067       std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid),
0068                                                          casts);
0069 
0070   // Return the root volume finder
0071   Experimental::ExternalNavigationDelegate rootVolumeFinder;
0072   rootVolumeFinder.connect<&IndexedDetectorVolumesImpl::update>(
0073       std::move(indexedDetectorVolumesImpl));
0074 
0075   nlohmann::json rFinderJson =
0076       DetectorVolumeFinderJsonConverter::toJson(rootVolumeFinder);
0077 
0078   auto readInRootVolumeFinder =
0079       DetectorVolumeFinderJsonConverter::fromJson(rFinderJson);
0080 
0081   BOOST_REQUIRE(readInRootVolumeFinder.instance() != nullptr);
0082 
0083   auto readInIndexedDetectorVolumesImpl =
0084       dynamic_cast<const IndexedDetectorVolumesImpl*>(
0085           readInRootVolumeFinder.instance());
0086 
0087   BOOST_REQUIRE(readInIndexedDetectorVolumesImpl != nullptr);
0088 
0089   const auto& gridRead = readInIndexedDetectorVolumesImpl->grid;
0090 
0091   BOOST_CHECK_EQUAL(gridRead.atPosition(p11), 11u);
0092   BOOST_CHECK_EQUAL(gridRead.atPosition(p12), 12u);
0093   BOOST_CHECK_EQUAL(gridRead.atPosition(p13), 13u);
0094   BOOST_CHECK_EQUAL(gridRead.atPosition(p21), 21u);
0095   BOOST_CHECK_EQUAL(gridRead.atPosition(p22), 22u);
0096   BOOST_CHECK_EQUAL(gridRead.atPosition(p23), 23u);
0097 }
0098 
0099 BOOST_AUTO_TEST_SUITE_END()
0100 
0101 }  // namespace ActsTests