Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorTests.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 
25 
26 #include <memory>
27 #include <stdexcept>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
39 template <typename referenced_type>
40 std::shared_ptr<referenced_type> unpackToShared(referenced_type& rt) {
41  return rt.getSharedPtr();
42 }
43 
45 
46 BOOST_AUTO_TEST_SUITE(Detector)
47 
48 BOOST_AUTO_TEST_CASE(DetectorConstruction) {
49  Acts::ActsScalar r0 = 0.;
50  Acts::ActsScalar r1 = 10.;
51  Acts::ActsScalar r2 = 100.;
52  Acts::ActsScalar r3 = 200.;
53  Acts::ActsScalar zHalfL = 200.;
54 
55  Acts::Transform3 nominal = Acts::Transform3::Identity();
56 
57  // Create a bunch of volumes
58  auto cyl0Bounds =
59  std::make_unique<Acts::CylinderVolumeBounds>(r0, r1, zHalfL);
60 
61  auto cyl0BoundsCopy =
62  std::make_unique<Acts::CylinderVolumeBounds>(r0, r1, zHalfL);
63 
64  auto cyl1Bounds =
65  std::make_unique<Acts::CylinderVolumeBounds>(r1, r2, zHalfL);
66 
67  auto cyl2Bounds =
68  std::make_unique<Acts::CylinderVolumeBounds>(r2, r3, zHalfL);
69 
71 
73  portalGenerator, tContext, "Cyl0", nominal, std::move(cyl0Bounds),
75 
77  portalGenerator, tContext, "Cyl0", nominal, std::move(cyl0BoundsCopy),
79 
81  portalGenerator, tContext, "Cyl1", nominal, std::move(cyl1Bounds),
83 
85  portalGenerator, tContext, "Cyl2", nominal, std::move(cyl2Bounds),
87 
88  std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes012 =
89  {cyl0, cyl1, cyl2};
91  "Det012", volumes012, Acts::Experimental::tryRootVolumes());
92 
93  // Check the basic return functions
94  BOOST_CHECK(det012->name() == "Det012");
95  BOOST_CHECK(det012->volumes().size() == 3u);
96  BOOST_CHECK(det012->volumePtrs().size() == 3u);
97 
98  // Check the shared pointer mechanism
99  BOOST_CHECK(det012 == unpackToShared<Acts::Experimental::Detector>(*det012));
100  BOOST_CHECK(det012 ==
101  unpackToShared<const Acts::Experimental::Detector>(*det012));
102 
103  // Check the inside function with positions
105  nState.position = Acts::Vector3(5., 0., 0.);
106  nState.currentDetector = det012.get();
107  det012->updateDetectorVolume(tContext, nState);
108  BOOST_CHECK(nState.currentVolume == cyl0.get());
109 
110  auto find1 = det012->findDetectorVolume(tContext, Acts::Vector3(15., 0., 0.));
111  BOOST_CHECK(find1 == cyl1.get());
112 
113  auto find2 =
114  det012->findDetectorVolume(tContext, Acts::Vector3(150., 0., 0.));
115  BOOST_CHECK(find2 == cyl2.get());
116 
117  auto findNull =
118  det012->findDetectorVolume(tContext, Acts::Vector3(1500., 0., 0.));
119  BOOST_CHECK(findNull == nullptr);
120 
122  auto find0 = det012->findDetectorVolume("Cyl0");
123  BOOST_CHECK(find0 == cyl0.get());
124 
125  findNull = det012->findDetectorVolume("Null");
126  BOOST_CHECK(findNull == nullptr);
127 
128  // Misconfigured - unkonnected finder
130  BOOST_CHECK_THROW(
131  Acts::Experimental::Detector::makeShared("Det012_unconnected", volumes012,
132  std::move(unconnected)),
133  std::invalid_argument);
134 
135  // Misconfigured - duplicate name
136  std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes002 =
137  {cyl0, cyl0nameDup, cyl2};
139  "Det002_name_duplicate", volumes002,
141  std::invalid_argument);
142 }
143 
144 BOOST_AUTO_TEST_CASE(DetectorConstructionWithHierarchyMap) {
146 
147  std::vector<std::unique_ptr<Acts::Test::DetectorElementStub>> detStore;
148  std::vector<Acts::ActsScalar> radii = {100, 102, 104, 106, 108, 110};
149  auto cylinderVoumeBounds =
150  std::make_unique<Acts::CylinderVolumeBounds>(80, 130, 200);
151  std::vector<std::shared_ptr<Acts::Surface>> surfaces = {};
152  for (auto [ir, r] : Acts::enumerate(radii)) {
153  auto detElement = std::make_unique<Acts::Test::DetectorElementStub>(
154  Acts::Transform3::Identity(),
155  std::make_shared<Acts::CylinderBounds>(r, 190.), 0.1);
156  auto surface = detElement->surface().getSharedPtr();
157  surface->assignGeometryId(Acts::GeometryIdentifier{}.setSensitive(ir + 1));
158  surfaces.push_back(std::move(surface));
159  detStore.push_back(std::move(detElement));
160  }
161 
163  portalGenerator, tContext, "CylinderVolume", Acts::Transform3::Identity(),
164  std::move(cylinderVoumeBounds), surfaces, {},
167 
169  "DetWithSurfaces", {cylVolume}, Acts::Experimental::tryRootVolumes());
170 
171  const auto& sensitiveHierarchyMap = det->sensitiveHierarchyMap();
172  BOOST_CHECK(sensitiveHierarchyMap.size() == 6u);
173 }
174 
175 BOOST_AUTO_TEST_SUITE_END()