Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorVolumeUpdatorsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorVolumeUpdatorsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
17 
18 #include <memory>
19 #include <stdexcept>
20 #include <vector>
21 
22 // A test context
24 
25 namespace Acts {
26 namespace Experimental {
27 class DetectorVolume {};
28 } // namespace Experimental
29 } // namespace Acts
30 
31 auto volumeA = std::make_shared<Acts::Experimental::DetectorVolume>();
32 auto volumeB = std::make_shared<Acts::Experimental::DetectorVolume>();
33 auto volumeC = std::make_shared<Acts::Experimental::DetectorVolume>();
34 auto volumeD = std::make_shared<Acts::Experimental::DetectorVolume>();
35 
37 
38 BOOST_AUTO_TEST_SUITE(Experimental)
39 
40 // These tests check the behavior of the volume updators, i.e. the
41 // helper delegates that set/reset the volume raw pointer in the
42 // NavigaitonState according to some given information.
43 //
44 BOOST_AUTO_TEST_CASE(UnconnectedUpdate) {
46  BOOST_CHECK(not ucUpdator.connected());
47 }
48 
49 // The end of world is reached
50 BOOST_AUTO_TEST_CASE(EndOfWorldUpdate) {
51  nState.currentVolume = volumeA.get();
52  BOOST_CHECK(nState.currentVolume == volumeA.get());
53 
55  eow.update(tContext, nState);
56 
57  BOOST_CHECK(nState.currentVolume == nullptr);
58 }
59 
60 // A single link exists and this is set
61 BOOST_AUTO_TEST_CASE(SingleVolumeUpdate) {
62  nState.currentVolume = volumeA.get();
63  BOOST_CHECK(nState.currentVolume == volumeA.get());
64 
66  svu.update(tContext, nState);
67 
68  BOOST_CHECK(nState.currentVolume == volumeB.get());
69 
70  BOOST_CHECK_THROW(Acts::Experimental::SingleDetectorVolumeImpl(nullptr),
71  std::invalid_argument);
72 }
73 
74 // A typlical volume array in 1 dimension (bound, not closed)
75 BOOST_AUTO_TEST_CASE(VolumeArrayUpdate) {
76  std::vector<Acts::ActsScalar> zArray = {-200, -100, 100, 400, 1000};
77 
78  std::vector<const Acts::Experimental::DetectorVolume*> volumes = {
79  volumeA.get(), volumeB.get(), volumeC.get(), volumeD.get()};
81  // Reset the navigation state
82  nState.currentVolume = nullptr;
83 
84  // Check the volume retrieval
85  nState.position = Acts::Vector3(0., 0., -150.);
86  bvg.update(tContext, nState);
87  BOOST_CHECK(nState.currentVolume == volumeA.get());
88 
89  nState.position = Acts::Vector3(0., 0., 600.);
90  bvg.update(tContext, nState);
91  BOOST_CHECK(nState.currentVolume == volumeD.get());
92 
93  // Check a shifted one
94  Acts::Transform3 shift300 = Acts::Transform3::Identity();
95  shift300.pretranslate(Acts::Vector3(0, 0, 300));
96 
98  shift300.inverse());
99 
100  // 150 (-300) -> transforms to -150, hence it yields A
101  nState.position = Acts::Vector3(0., 0., 150.);
102  bvgs.update(tContext, nState);
103  BOOST_CHECK(nState.currentVolume == volumeA.get());
104 }
105 
106 BOOST_AUTO_TEST_SUITE_END()