Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProtoLayerTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProtoLayerTests.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 
13 #include "Acts/Geometry/Extent.hpp"
22 
23 #include <array>
24 #include <cmath>
25 #include <memory>
26 #include <sstream>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 namespace Acts {
32 
33 namespace Test {
34 namespace Layers {
35 
36 BOOST_AUTO_TEST_SUITE(Geometry)
37 
38 BOOST_AUTO_TEST_CASE(ProtoLayerTests) {
40 
41  // Create a proto layer with 4 surfaces on the x/y grid
42  auto recBounds = std::make_shared<RectangleBounds>(3., 6.);
43 
44  // Planar definitions to help construct the boundary surfaces
45  static const Transform3 planeYZ = AngleAxis3(0.5 * M_PI, Vector3::UnitY()) *
46  AngleAxis3(0.5 * M_PI, Vector3::UnitZ()) *
47  Transform3::Identity();
48  static const Transform3 planeZX = AngleAxis3(-0.5 * M_PI, Vector3::UnitX()) *
49  AngleAxis3(-0.5 * M_PI, Vector3::UnitZ()) *
50  Transform3::Identity();
51 
52  std::vector<std::shared_ptr<const Surface>> surfaceStore;
53  surfaceStore.reserve(100);
54 
55  auto createProtoLayer = [&](const Transform3& trf,
56  bool shared = false) -> ProtoLayer {
57  auto atNegX = Surface::makeShared<PlaneSurface>(
58  Transform3(trf * Translation3(Vector3(-3., 0., 0.)) * planeYZ),
59  recBounds);
60 
61  auto atPosX = Surface::makeShared<PlaneSurface>(
62  Transform3(trf * Translation3(Vector3(3., 0., 0.)) * planeYZ),
63  recBounds);
64 
65  auto atNegY = Surface::makeShared<PlaneSurface>(
66  Transform3(trf * Translation3(Vector3(0., -3, 0.)) * planeZX),
67  recBounds);
68 
69  auto atPosY = Surface::makeShared<PlaneSurface>(
70  Transform3(trf * Translation3(Vector3(0., 3., 0.)) * planeZX),
71  recBounds);
72 
73  std::vector<std::shared_ptr<const Surface>> sharedSurfaces = {
74  atNegX, atNegY, atPosX, atPosY};
75  surfaceStore.insert(surfaceStore.begin(), sharedSurfaces.begin(),
76  sharedSurfaces.end());
77  if (not shared) {
78  std::vector<const Surface*> surfaces = {atNegX.get(), atNegY.get(),
79  atPosX.get(), atPosY.get()};
80 
81  return ProtoLayer(tgContext, surfaces);
82  }
83  return ProtoLayer(tgContext, sharedSurfaces);
84  };
85 
86  // Test 0 - check constructor with surfaces and shared surfaces
87  auto pLayerSf = createProtoLayer(Transform3::Identity());
88  auto pLayerSfShared = createProtoLayer(Transform3::Identity());
89 
90  BOOST_CHECK(pLayerSf.extent.range() == pLayerSfShared.extent.range());
91  BOOST_CHECK(pLayerSf.envelope == pLayerSfShared.envelope);
92 
93  // CHECK That you have 4 surfaces
94  BOOST_CHECK(pLayerSf.surfaces().size() == 4);
95  // Add one surface from a detector element (to test thickness)
96  auto rB = std::make_shared<RectangleBounds>(30., 60.);
97 
98  // Create the detector element
99  auto addSurface =
100  Surface::makeShared<PlaneSurface>(Transform3::Identity(), rB);
101 
102  pLayerSf.add(tgContext, *addSurface.get());
103  // CHECK That if you now have 5 surfaces
104  BOOST_CHECK(pLayerSf.surfaces().size() == 5);
105 
106  // That should invalidate the ranges
107  BOOST_CHECK(!(pLayerSf.extent.range() == pLayerSfShared.extent.range()));
108 
109  // Test 1 - identity transform
110  auto protoLayer = createProtoLayer(Transform3::Identity());
111 
112  CHECK_CLOSE_ABS(protoLayer.range(binX), 12., 1e-8);
113  CHECK_CLOSE_ABS(protoLayer.medium(binX), 0., 1e-8);
114  CHECK_CLOSE_ABS(protoLayer.min(binX), -6., 1e-8);
115  CHECK_CLOSE_ABS(protoLayer.max(binX), 6., 1e-8);
116  CHECK_CLOSE_ABS(protoLayer.range(binY), 6., 1e-8);
117  CHECK_CLOSE_ABS(protoLayer.medium(binY), 0., 1e-8);
118  CHECK_CLOSE_ABS(protoLayer.min(binY), -3., 1e-8);
119  CHECK_CLOSE_ABS(protoLayer.max(binY), 3., 1e-8);
120  CHECK_CLOSE_ABS(protoLayer.range(binZ), 12., 1e-8);
121  CHECK_CLOSE_ABS(protoLayer.medium(binZ), 0., 1e-8);
122  CHECK_CLOSE_ABS(protoLayer.min(binZ), -6., 1e-8);
123  CHECK_CLOSE_ABS(protoLayer.max(binZ), 6., 1e-8);
124  CHECK_CLOSE_ABS(protoLayer.max(binR), std::hypot(3, 6), 1e-8);
125  CHECK_CLOSE_ABS(protoLayer.min(binR), 3., 1e-8);
126 
127  // Test 1a
128 
129  // Test 2 - rotate around Z-Axis, should leave R, Z untouched,
130  // only preserves medium values
131  auto protoLayerRot = createProtoLayer(AngleAxis3(-0.345, Vector3::UnitZ()) *
132  Transform3::Identity());
133 
134  BOOST_CHECK_NE(protoLayer.min(binX), -6.);
135  CHECK_CLOSE_ABS(protoLayerRot.medium(binX), 0., 1e-8);
136  CHECK_CLOSE_ABS(protoLayerRot.medium(binY), 0., 1e-8);
137  CHECK_CLOSE_ABS(protoLayerRot.range(binZ), 12., 1e-8);
138  CHECK_CLOSE_ABS(protoLayerRot.medium(binZ), 0., 1e-8);
139  CHECK_CLOSE_ABS(protoLayerRot.min(binZ), -6., 1e-8);
140  CHECK_CLOSE_ABS(protoLayerRot.max(binZ), 6., 1e-8);
141  CHECK_CLOSE_ABS(protoLayerRot.min(binR), 3., 1e-8);
142  CHECK_CLOSE_ABS(protoLayerRot.max(binR), std::hypot(3, 6), 1e-8);
143 
144  std::stringstream sstream;
145  protoLayerRot.toStream(sstream);
146  std::string oString = R"(ProtoLayer with dimensions (min/max) Extent in space : - value : binX | range = [-6.66104, 6.66104] - value : binY | range = [-4.85241, 4.85241] - value : binZ | range = [-6, 6] - value : binR | range = [3, 6.7082] - value : binPhi | range = [-3.02295, 2.33295] - value : binRPhi | range = [-20.2785, 15.6499] - value : binH | range = [0.61548, 2.52611] - value : binEta | range = [-1.14622, 1.14622] - value : binMag | range = [7.34847, 7.34847] )";
147  BOOST_CHECK_EQUAL(sstream.str(), oString);
148 }
149 
150 BOOST_AUTO_TEST_SUITE_END()
151 } // namespace Layers
152 } // namespace Test
153 
154 } // namespace Acts
155