Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-19 07:59:04

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/Navigation/NavigationDelegates.hpp"
0014 #include "Acts/Navigation/NavigationState.hpp"
0015 #include "Acts/Navigation/PortalNavigation.hpp"
0016 #include "Acts/Utilities/BinningType.hpp"
0017 
0018 #include <memory>
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 namespace Acts::Experimental {
0023 class DetectorVolume {};
0024 }  // namespace Acts::Experimental
0025 
0026 using namespace Acts;
0027 
0028 // A test context
0029 GeometryContext tContext;
0030 
0031 auto volumeA = std::make_shared<Experimental::DetectorVolume>();
0032 auto volumeB = std::make_shared<Experimental::DetectorVolume>();
0033 auto volumeC = std::make_shared<Experimental::DetectorVolume>();
0034 auto volumeD = std::make_shared<Experimental::DetectorVolume>();
0035 
0036 Experimental::NavigationState nState;
0037 
0038 namespace ActsTests {
0039 
0040 BOOST_AUTO_TEST_SUITE(NavigationSuite)
0041 
0042 // These tests check the behavior of the volume updators, i.e. the
0043 // helper delegates that set/reset the volume raw pointer in the
0044 // NavigaitonState according to some given information.
0045 //
0046 BOOST_AUTO_TEST_CASE(UnconnectedUpdate) {
0047   Experimental::ExternalNavigationDelegate ucUpdater;
0048   BOOST_CHECK(!ucUpdater.connected());
0049 }
0050 
0051 // The end of world is reached
0052 BOOST_AUTO_TEST_CASE(EndOfWorldUpdate) {
0053   nState.currentVolume = volumeA.get();
0054   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0055 
0056   Experimental::EndOfWorld eow;
0057   eow.update(tContext, nState);
0058 
0059   BOOST_CHECK_EQUAL(nState.currentVolume, nullptr);
0060 }
0061 
0062 // A single link exists and this is set
0063 BOOST_AUTO_TEST_CASE(SingleVolumeUpdate) {
0064   nState.currentVolume = volumeA.get();
0065   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0066 
0067   Experimental::SingleDetectorVolumeNavigation svu(volumeB.get());
0068   svu.update(tContext, nState);
0069 
0070   BOOST_CHECK_EQUAL(nState.currentVolume, volumeB.get());
0071 
0072   BOOST_CHECK_THROW(Experimental::SingleDetectorVolumeNavigation(nullptr),
0073                     std::invalid_argument);
0074 }
0075 
0076 // A typlical volume array in 1 dimension (bound, not closed)
0077 BOOST_AUTO_TEST_CASE(VolumeArrayUpdate) {
0078   std::vector<double> zArray = {-200, -100, 100, 400, 1000};
0079 
0080   std::vector<const Experimental::DetectorVolume*> volumes = {
0081       volumeA.get(), volumeB.get(), volumeC.get(), volumeD.get()};
0082   Experimental::BoundVolumesGrid1Navigation bvg(zArray, AxisDirection::AxisZ,
0083                                                 volumes);
0084   // Reset the navigation state
0085   nState.currentVolume = nullptr;
0086 
0087   // Check the volume retrieval
0088   nState.position = Vector3(0., 0., -150.);
0089   bvg.update(tContext, nState);
0090   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0091 
0092   nState.position = Vector3(0., 0., 600.);
0093   bvg.update(tContext, nState);
0094   BOOST_CHECK_EQUAL(nState.currentVolume, volumeD.get());
0095 
0096   // Check a shifted one
0097   Transform3 shift300 = Transform3::Identity();
0098   shift300.pretranslate(Vector3(0, 0, 300));
0099 
0100   Experimental::BoundVolumesGrid1Navigation bvgs(zArray, AxisDirection::AxisZ,
0101                                                  volumes, shift300.inverse());
0102 
0103   // 150 (-300) -> transforms to -150, hence it yields A
0104   nState.position = Vector3(0., 0., 150.);
0105   bvgs.update(tContext, nState);
0106   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0107 }
0108 
0109 BOOST_AUTO_TEST_SUITE_END()
0110 
0111 }  // namespace ActsTests