Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorVolumeFindersTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorVolumeFindersTests.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 
24 
25 #include <array>
26 #include <cstddef>
27 #include <memory>
28 #include <stdexcept>
29 #include <tuple>
30 #include <utility>
31 #include <vector>
32 
33 // A test context
35 
37 
43 
44 Acts::Transform3 nominal = Acts::Transform3::Identity();
45 
46 // Create a bunch of volumes
47 auto cyl0Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r0, r1, zHalfL);
48 
49 auto cyl1Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r1, r2, zHalfL);
50 
51 auto cyl2Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r2, r3, zHalfL);
52 
54 
56  portalGenerator, tContext, "Cyl0", nominal, std::move(cyl0Bounds),
58 
60  portalGenerator, tContext, "Cyl1", nominal, std::move(cyl1Bounds),
62 
64  portalGenerator, tContext, "Cyl2", nominal, std::move(cyl2Bounds),
66 
67 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes012 = {
68  cyl0, cyl1, cyl2};
70  "Det012", volumes012, Acts::Experimental::tryRootVolumes());
71 
72 BOOST_AUTO_TEST_SUITE(Experimental)
73 
74 // Test finding detectors by trial and error
75 BOOST_AUTO_TEST_CASE(RootVolumeFinder) {
76  nState.currentDetector = det012.get();
78  // Cylinder 0
79  nState.position = Acts::Vector3(5., 0., 0.);
80  rvf.update(tContext, nState);
81  BOOST_CHECK(nState.currentVolume == cyl0.get());
82  // Cylinder 1
83  nState.position = Acts::Vector3(50., 0., 0.);
84  rvf.update(tContext, nState);
85  BOOST_CHECK(nState.currentVolume == cyl1.get());
86  // Cylinder 2
87  nState.position = Acts::Vector3(150., 0., 0.);
88  rvf.update(tContext, nState);
89  BOOST_CHECK(nState.currentVolume == cyl2.get());
90 
91  nState.currentDetector = nullptr;
92  BOOST_CHECK_THROW(rvf.update(tContext, nState), std::runtime_error);
93 }
94 
95 // Test finding detectors beu trial and error
96 BOOST_AUTO_TEST_CASE(IndexedDetectorVolumeFinder) {
97  nState.currentDetector = det012.get();
98 
99  using SingleIndex = std::size_t;
100 
101  using Axis = Acts::detail::Axis<Acts::detail::AxisType::Variable,
102  Acts::detail::AxisBoundaryType::Bound>;
104 
105  std::vector<Acts::ActsScalar> b = {r0, r1, r2, r3};
106  Axis a(b);
107  Grid g(std::make_tuple(a));
108 
109  g.atPosition(std::array<Acts::ActsScalar, 1u>{5.}) = 0u;
110  g.atPosition(std::array<Acts::ActsScalar, 1u>{50.}) = 1u;
111  g.atPosition(std::array<Acts::ActsScalar, 1u>{150.}) = 2u;
112 
114  {Acts::binR});
115 
116  // Cylinder 0
117  nState.position = Acts::Vector3(5., 0., 0.);
118  idv.update(tContext, nState);
119  BOOST_CHECK(nState.currentVolume == cyl0.get());
120  // Cylinder 1
121  nState.position = Acts::Vector3(50., 0., 0.);
122  idv.update(tContext, nState);
123  BOOST_CHECK(nState.currentVolume == cyl1.get());
124  // Cylinder 2
125  nState.position = Acts::Vector3(150., 0., 0.);
126  idv.update(tContext, nState);
127  BOOST_CHECK(nState.currentVolume == cyl2.get());
128 
129  nState.currentDetector = nullptr;
130  BOOST_CHECK_THROW(idv.update(tContext, nState), std::runtime_error);
131 }
132 
133 BOOST_AUTO_TEST_SUITE_END()