Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:45

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