Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProtoDetectorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProtoDetectorTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
14 #include "Acts/Geometry/Extent.hpp"
19 
20 #include <iostream>
21 #include <limits>
22 #include <memory>
23 #include <optional>
24 #include <string>
25 #include <vector>
26 
27 namespace {
28 
35 Acts::ProtoDetector createProtoDetector() {
36  // Container
37  Acts::ProtoVolume detectorVolume;
38  detectorVolume.name = "detector-container";
39  detectorVolume.extent.set(Acts::binZ, -2000., 2000);
40 
41  // Beam Pipe volume
42  Acts::ProtoVolume beamPipe;
43  beamPipe.name = "beam-pipe";
44  beamPipe.extent.set(Acts::binR, 0., 30.);
45 
46  // Pixel section
47  Acts::ProtoVolume pixelContainer;
48  pixelContainer.name = "pixel-container";
49  pixelContainer.extent.set(Acts::binR, 40., 200);
50 
51  // Pixel volume sub structure
52  Acts::ProtoVolume pixelNec;
53  pixelNec.name = "pixel-nec";
54  pixelNec.extent.set(Acts::binZ, -1900., -600);
55 
56  Acts::ProtoVolume pixelBarrel;
57  pixelBarrel.name = "pixel-barrel";
58  pixelBarrel.extent.set(Acts::binR, 41., 199.);
59  pixelBarrel.extent.set(Acts::binZ, -550., 550.);
60 
61  Acts::ProtoVolume pixelBarrelL0;
62  pixelBarrelL0.name = "pixel-barrel-l0";
63  pixelBarrelL0.extent.set(Acts::binR, 45., 50.);
65  Acts::Surface::SurfaceType::Cylinder};
66 
67  Acts::ProtoVolume pixelBarrelL1;
68  pixelBarrelL1.name = "pixel-barrel-l1";
69  pixelBarrelL1.extent.set(Acts::binR, 70., 80.);
71  Acts::Surface::SurfaceType::Cylinder};
72 
74  {pixelBarrelL0, pixelBarrelL1},
76  true};
77 
78  Acts::ProtoVolume pixelPec;
79  pixelPec.name = "pixel-pec";
80  pixelPec.extent.set(Acts::binZ, 600., 1900.);
81 
83  {pixelNec, pixelBarrel, pixelPec},
85 
87  {beamPipe, pixelContainer},
89 
91  detector.name = "detector";
92  detector.worldVolume = detectorVolume;
93 
94  return detector;
95 }
96 
97 } // namespace
98 
99 namespace Acts {
100 
101 namespace Test {
102 
103 BOOST_AUTO_TEST_SUITE(Detector)
104 
105 BOOST_AUTO_TEST_CASE(ProtoTrackingGeometryTests) {
106  // Get the raw proto detector description
107  auto detector = createProtoDetector();
108  detector.harmonize(true);
109 
110  // Get the top detector volume
111  auto& detectorVolume = detector.worldVolume;
112 
113  // The detector volume should have received maximum dimensions
114  CHECK_CLOSE_ABS(detectorVolume.extent.min(Acts::binR), 0,
115  std::numeric_limits<ActsScalar>::epsilon());
116 
117  CHECK_CLOSE_ABS(detectorVolume.extent.max(Acts::binR), 200.,
118  std::numeric_limits<ActsScalar>::epsilon());
119 
120  // The detector container should have binning in R
121  BOOST_CHECK(detectorVolume.container.has_value());
122  BOOST_CHECK(not detectorVolume.internal.has_value());
123 
124  auto& cts = detectorVolume.container.value();
125 
126  BOOST_CHECK(cts.constituentBinning.size() == 1u);
127  BOOST_CHECK(cts.constituentBinning[0].type == Acts::arbitrary);
128  BOOST_CHECK(cts.constituentBinning[0].binvalue == Acts::binR);
129 
130  const auto& binBoundaries = cts.constituentBinning[0].boundaries();
131  BOOST_CHECK(binBoundaries.size() == 3u);
132  CHECK_CLOSE_ABS(binBoundaries[0u], 0.,
133  std::numeric_limits<ActsScalar>::epsilon());
134  CHECK_CLOSE_ABS(binBoundaries[1u], 35.,
135  std::numeric_limits<ActsScalar>::epsilon());
136  CHECK_CLOSE_ABS(binBoundaries[2u], 200.,
137  std::numeric_limits<ActsScalar>::epsilon());
138 
139  // The first volume is the beam pipe, it should have gotten the
140  // z dimension
141  auto& beamPipe = cts.constituentVolumes[0u];
142 
143  BOOST_CHECK(beamPipe.name == "beam-pipe");
144  CHECK_CLOSE_ABS(beamPipe.extent.min(Acts::binZ), -2000.,
145  std::numeric_limits<ActsScalar>::epsilon());
146 
147  CHECK_CLOSE_ABS(beamPipe.extent.max(Acts::binZ), 2000.,
148  std::numeric_limits<ActsScalar>::epsilon());
149 
150  // The new beam pipe radius should have been applied
151  CHECK_CLOSE_ABS(beamPipe.extent.max(Acts::binR), 35.,
152  std::numeric_limits<ActsScalar>::epsilon());
153 
154  // The second volume is the pixel detector
155  auto& pixelContainer = cts.constituentVolumes[1u];
156  BOOST_CHECK(pixelContainer.name == "pixel-container");
157 
158  // Pixel container should have fitting boundaries
159  CHECK_CLOSE_ABS(pixelContainer.extent.min(Acts::binR), 35.,
160  std::numeric_limits<ActsScalar>::epsilon());
161  CHECK_CLOSE_ABS(pixelContainer.extent.max(Acts::binR), 200.,
162  std::numeric_limits<ActsScalar>::epsilon());
163  CHECK_CLOSE_ABS(pixelContainer.extent.min(Acts::binZ), -2000.,
164  std::numeric_limits<ActsScalar>::epsilon());
165  CHECK_CLOSE_ABS(pixelContainer.extent.max(Acts::binZ), 2000.,
166  std::numeric_limits<ActsScalar>::epsilon());
167 
168  // The Pixel container has constituents
169  BOOST_CHECK(pixelContainer.container.has_value());
170  auto& cts1 = pixelContainer.container.value();
171 
172  // All of the internal containers should now have synchronized
173  // inner & outer boundaries
174  for (auto& pv : cts1.constituentVolumes) {
175  CHECK_CLOSE_ABS(pv.extent.min(Acts::binR), 35.,
176  std::numeric_limits<ActsScalar>::epsilon());
177 
178  CHECK_CLOSE_ABS(pv.extent.max(Acts::binR), 200.,
179  std::numeric_limits<ActsScalar>::epsilon());
180  }
181 
182  // The binning should have been estimated
183  BOOST_CHECK(cts1.constituentBinning.size() == 1u);
184  BOOST_CHECK(cts1.constituentBinning[0].type == Acts::arbitrary);
185  BOOST_CHECK(cts1.constituentBinning[0].binvalue == Acts::binZ);
186 
187  const auto& binBoundariesZ = cts1.constituentBinning[0].boundaries();
188  BOOST_CHECK(binBoundariesZ.size() == 4u);
189  CHECK_CLOSE_ABS(binBoundariesZ[0u], -2000.,
190  std::numeric_limits<ActsScalar>::epsilon());
191  CHECK_CLOSE_ABS(binBoundariesZ[1u], -575,
192  std::numeric_limits<ActsScalar>::epsilon());
193  CHECK_CLOSE_ABS(binBoundariesZ[2u], 575.,
194  std::numeric_limits<ActsScalar>::epsilon());
195  CHECK_CLOSE_ABS(binBoundariesZ[3u], 2000.,
196  std::numeric_limits<ActsScalar>::epsilon());
197 
198  // The second volume is the pixel barrel
199  auto& pixelBarrel = cts1.constituentVolumes[1u];
200  BOOST_CHECK(pixelBarrel.name == "pixel-barrel");
201 
202  // It is a container volume value
203  BOOST_CHECK(pixelBarrel.container.has_value());
204  auto& cts2 = pixelBarrel.container.value();
205  // It is, however, a layer container
206  BOOST_CHECK(cts2.layerContainer);
207  for (auto& lVolume : cts2.constituentVolumes) {
208  BOOST_CHECK(lVolume.internal.has_value());
209  }
210 }
211 
212 BOOST_AUTO_TEST_CASE(ProtoDetectorTests) {
213  // Get the raw proto detector description
214  auto detector = createProtoDetector();
215  detector.harmonize(false);
216  std::cout << detector.toString() << std::endl;
217 }
218 
219 BOOST_AUTO_TEST_SUITE_END()
220 
221 } // namespace Test
222 
223 } // namespace Acts