Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:24

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://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/DetectorVolumeUpdaters.hpp"
0014 #include "Acts/Navigation/NavigationDelegates.hpp"
0015 #include "Acts/Navigation/NavigationState.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::DetectorVolumeUpdater 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::EndOfWorldImpl 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::SingleDetectorVolumeImpl svu(volumeB.get());
0064   svu.update(tContext, nState);
0065 
0066   BOOST_CHECK_EQUAL(nState.currentVolume, volumeB.get());
0067 
0068   BOOST_CHECK_THROW(Acts::Experimental::SingleDetectorVolumeImpl(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<Acts::ActsScalar> 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::BoundVolumesGrid1Impl bvg(zArray, Acts::binZ, volumes);
0079   // Reset the navigation state
0080   nState.currentVolume = nullptr;
0081 
0082   // Check the volume retrieval
0083   nState.position = Acts::Vector3(0., 0., -150.);
0084   bvg.update(tContext, nState);
0085   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0086 
0087   nState.position = Acts::Vector3(0., 0., 600.);
0088   bvg.update(tContext, nState);
0089   BOOST_CHECK_EQUAL(nState.currentVolume, volumeD.get());
0090 
0091   // Check a shifted one
0092   Acts::Transform3 shift300 = Acts::Transform3::Identity();
0093   shift300.pretranslate(Acts::Vector3(0, 0, 300));
0094 
0095   Acts::Experimental::BoundVolumesGrid1Impl bvgs(zArray, Acts::binZ, volumes,
0096                                                  shift300.inverse());
0097 
0098   // 150 (-300) -> transforms to -150, hence it yields A
0099   nState.position = Acts::Vector3(0., 0., 150.);
0100   bvgs.update(tContext, nState);
0101   BOOST_CHECK_EQUAL(nState.currentVolume, volumeA.get());
0102 }
0103 
0104 BOOST_AUTO_TEST_SUITE_END()