Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryIdGeneratorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryIdGeneratorTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
14 #include "Acts/Detector/Portal.hpp"
24 
25 #include <iostream>
26 #include <memory>
27 #include <vector>
28 
29 using namespace Acts;
30 using namespace Acts::Experimental;
31 
33 
34 namespace {
35 
36 std::vector<std::shared_ptr<DetectorVolume>> createVolumes(
37  std::vector<std::shared_ptr<Test::DetectorElementStub>>& detectorStore) {
39 
40  auto gap0VoumeBounds = std::make_unique<CylinderVolumeBounds>(0, 80, 200);
41 
42  auto gap0Volume = DetectorVolumeFactory::construct(
43  portalGenerator, tContext, "Gap0Volume", Transform3::Identity(),
44  std::move(gap0VoumeBounds), {}, {}, tryNoVolumes(), tryAllPortals());
45 
46  std::vector<ActsScalar> layer0Radii = {100, 102, 104, 106, 108, 110};
47  auto layer0VolumeBounds =
48  std::make_unique<CylinderVolumeBounds>(80, 130, 200);
49  std::vector<std::shared_ptr<Surface>> layer0Surfaces = {};
50  for (const auto [ir, r] : enumerate(layer0Radii)) {
51  // First 4 surfaces are active
52  if (ir < 4u) {
53  auto detElement = std::make_shared<Test::DetectorElementStub>(
54  Transform3::Identity(), std::make_shared<CylinderBounds>(r, 190),
55  0.1);
56  detectorStore.push_back(detElement);
57  layer0Surfaces.push_back(detElement->surface().getSharedPtr());
58  } else {
59  // Last 2 surfaces are passive
60  layer0Surfaces.push_back(Surface::makeShared<CylinderSurface>(
61  Transform3::Identity(), std::make_shared<CylinderBounds>(r, 190)));
62  }
63  }
64 
65  auto layer0Volume = DetectorVolumeFactory::construct(
66  portalGenerator, tContext, "CylinderVolume", Transform3::Identity(),
67  std::move(layer0VolumeBounds), layer0Surfaces, {}, tryNoVolumes(),
69 
70  auto gap1VoumeBounds = std::make_unique<CylinderVolumeBounds>(130, 200, 200);
71 
72  auto gap1Volume = DetectorVolumeFactory::construct(
73  portalGenerator, tContext, "Gap1Volume", Transform3::Identity(),
74  std::move(gap1VoumeBounds), {}, {}, tryNoVolumes(), tryAllPortals());
75 
76  return {gap0Volume, layer0Volume, gap1Volume};
77 }
78 } // namespace
79 
80 BOOST_AUTO_TEST_SUITE(Detector)
81 
82 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorReset) {
83  std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
84 
85  auto volumes = createVolumes(detectorStore);
86 
89  cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
90 
91  auto cache = generator.generateCache();
92  for (auto& volume : volumes) {
93  generator.assignGeometryId(cache, *volume);
94  }
95 
96  // Checking the volume
97  BOOST_CHECK(volumes[0]->geometryId().volume() == 1);
98  for (auto [ip, p] : enumerate(volumes[0]->portals())) {
99  BOOST_CHECK(p->surface().geometryId().boundary() == ip + 1);
100  }
101 
102  BOOST_CHECK(volumes[1]->geometryId().volume() == 2);
103  for (auto [ip, p] : enumerate(volumes[1]->portals())) {
104  BOOST_CHECK(p->surface().geometryId().boundary() == ip + 1);
105  }
106  for (auto [is, s] : enumerate(volumes[1]->surfaces())) {
107  if (is < 4u) {
108  BOOST_CHECK(s->geometryId().sensitive() == is + 1);
109  } else {
110  BOOST_CHECK(s->geometryId().passive() == is - 3);
111  }
112  }
113 
114  BOOST_CHECK(volumes[2]->geometryId().volume() == 3);
115  for (auto [ip, p] : enumerate(volumes[2]->portals())) {
116  BOOST_CHECK(p->surface().geometryId().boundary() == ip + 1);
117  }
118 }
119 
120 BOOST_AUTO_TEST_CASE(SequentialGeoIdGeneratorNoReset) {
121  std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
122 
123  auto volumes = createVolumes(detectorStore);
124 
126  cfg.resetSubCounters = false;
128  cfg, getDefaultLogger("SequentialIdGenerator", Logging::VERBOSE));
129 
130  auto cache = generator.generateCache();
131  for (auto& volume : volumes) {
132  generator.assignGeometryId(cache, *volume);
133  }
134 
135  // Checking the volume
136  BOOST_CHECK(volumes[0]->geometryId().volume() == 1);
137  unsigned int portalCounter = 1;
138  for (auto [ip, p] : enumerate(volumes[0]->portals())) {
139  BOOST_CHECK(p->surface().geometryId().boundary() == portalCounter++);
140  }
141 
142  BOOST_CHECK(volumes[1]->geometryId().volume() == 2);
143  for (auto [ip, p] : enumerate(volumes[1]->portals())) {
144  BOOST_CHECK(p->surface().geometryId().boundary() == portalCounter++);
145  }
146 
147  BOOST_CHECK(volumes[2]->geometryId().volume() == 3);
148  for (auto [ip, p] : enumerate(volumes[2]->portals())) {
149  BOOST_CHECK(p->surface().geometryId().boundary() == portalCounter++);
150  }
151 }
152 
153 BOOST_AUTO_TEST_CASE(ContainerGeoIdGenerator) {
154  std::vector<std::shared_ptr<Test::DetectorElementStub>> detectorStore;
155 
156  auto volumes = createVolumes(detectorStore);
157 
159  cfg.containerMode = true;
160  cfg.containerId = 15;
162  cfg, getDefaultLogger("ContainerIdGenerator", Logging::VERBOSE));
163 
164  auto cache = generator.generateCache();
165  for (auto& volume : volumes) {
166  generator.assignGeometryId(cache, *volume);
167  }
168 
169  BOOST_CHECK(volumes[0]->geometryId().volume() == 15);
170  BOOST_CHECK(volumes[0]->geometryId().layer() == 1);
171  BOOST_CHECK(volumes[1]->geometryId().volume() == 15);
172  BOOST_CHECK(volumes[1]->geometryId().layer() == 2);
173  BOOST_CHECK(volumes[2]->geometryId().volume() == 15);
174  BOOST_CHECK(volumes[2]->geometryId().layer() == 3);
175 }
176 
177 BOOST_AUTO_TEST_SUITE_END()