Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:11

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