Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorBuilderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorBuilderTests.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 
29 
30 #include <memory>
31 #include <stdexcept>
32 #include <vector>
33 
35  public:
37  const std::vector<std::shared_ptr<Acts::Surface>>& sensitives = {})
38  : m_sensitives(sensitives) {}
39 
41  const Acts::GeometryContext& gctx) const final {
42  auto bounds = std::make_unique<Acts::CuboidVolumeBounds>(10., 10., 10.);
43  // Construct the DetectorVolume
44  auto dVolume =
45  m_sensitives.empty()
48  "TestVolume", Acts::Transform3::Identity(), std::move(bounds),
52  "TestVolumeWithSurfaces", Acts::Transform3::Identity(),
56 
57  // Fill the portal container
59  for (auto [ip, p] : Acts::enumerate(dVolume->portalPtrs())) {
60  portalContainer[ip] = p;
61  }
62 
64  {dVolume},
65  portalContainer,
66  {{dVolume}, Acts::Experimental::tryRootVolumes()}};
67  }
68 
69  private:
70  std::vector<std::shared_ptr<Acts::Surface>> m_sensitives;
71 };
72 
74  public:
76  const final {
77  return std::any();
78  }
79 
82  Acts::Experimental::DetectorVolume& dVolume) const final {
83  for (auto [is, s] : Acts::enumerate(dVolume.surfacePtrs())) {
85  geoID.setSensitive(is + 1);
86  s->assignGeometryId(geoID);
87  }
88  }
89 
92  Acts::Experimental::Portal& /*portal*/) const final {}
93 
96  Acts::Surface& /*surface*/) const final {}
97 };
98 
100 
101 BOOST_AUTO_TEST_SUITE(Detector)
102 
103 BOOST_AUTO_TEST_CASE(DetectorBuilder_Misconfigured) {
104  // Detector builder
106  dCfg.auxiliary = "*** Test X * Misconfigued ***";
107  dCfg.name = "EmptyCylinder";
108  dCfg.builder = nullptr;
109 
110  BOOST_CHECK_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg),
111  std::invalid_argument);
112 
113  // Detector builder with sensitives but no assigned geometry ids to them
115  Acts::Transform3::Identity(),
116  std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
118  Acts::Transform3::Identity(),
119  std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
120 
121  std::vector<std::shared_ptr<Acts::Surface>> sensitives;
122  sensitives.push_back(detElement0.surface().getSharedPtr());
123  sensitives.push_back(detElement1.surface().getSharedPtr());
124  dCfg.builder = std::make_shared<CompBuilder>(sensitives);
125 
126  BOOST_CHECK_THROW(
127  Acts::Experimental::DetectorBuilder(dCfg).construct(tContext),
128  std::invalid_argument);
129 }
130 
131 BOOST_AUTO_TEST_CASE(DetectorBuilder_test) {
132  // Detector builder
134  dCfg.auxiliary = "*** Test : Detector ***";
135  dCfg.name = "TestDetector";
136  dCfg.builder = std::make_shared<CompBuilder>();
137 
138  BOOST_CHECK_NO_THROW(auto a = Acts::Experimental::DetectorBuilder(dCfg));
139 
141 
142  BOOST_CHECK_EQUAL(detector->name(), "TestDetector");
143  BOOST_CHECK(detector->rootVolumes().size() == 1);
144 }
145 
146 BOOST_AUTO_TEST_CASE(DetectorBuilder_testWithSurfaces) {
147  // Detector builder
149  dCfg.auxiliary = "*** Test : Detector ***";
150  dCfg.name = "TestDetectorWithSurfaces";
151  dCfg.builder = std::make_shared<CompBuilder>();
152 
153  // Test detector with surfaces
155  Acts::Transform3::Identity(),
156  std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
158  Acts::Transform3::Identity(),
159  std::make_shared<Acts::RectangleBounds>(5., 5.), 0.1);
160 
161  std::vector<std::shared_ptr<Acts::Surface>> sensitives;
162  sensitives.push_back(detElement0.surface().getSharedPtr());
163  sensitives.push_back(detElement1.surface().getSharedPtr());
164  dCfg.builder = std::make_shared<CompBuilder>(sensitives);
165  dCfg.geoIdGenerator = std::make_shared<SurfaceGeoIdGenerator>();
166 
168  BOOST_CHECK_EQUAL(detector->name(), "TestDetectorWithSurfaces");
169  BOOST_CHECK(detector->volumes()[0]->surfaces()[0]->geometryId().sensitive() ==
170  1);
171  BOOST_CHECK(detector->volumes()[0]->surfaces()[1]->geometryId().sensitive() ==
172  2);
173 }
174 
175 BOOST_AUTO_TEST_SUITE_END()