EIC 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 
18 
19 #include <cmath>
20 #include <sstream>
21 
22 namespace Acts {
23 
24 namespace Test {
25 namespace Layers {
26 
27 BOOST_AUTO_TEST_SUITE(Geometry)
28 
29 BOOST_AUTO_TEST_CASE(ProtoLayerTests) {
31 
32  // Create a proto layer with 4 surfaces on the x/y grid
33  auto recBounds = std::make_shared<RectangleBounds>(3., 6.);
34 
35  // Planar definitions to help construct the boundary surfaces
36  static const Transform3D planeYZ =
37  AngleAxis3D(0.5 * M_PI, Vector3D::UnitY()) *
38  AngleAxis3D(0.5 * M_PI, Vector3D::UnitZ()) * Transform3D::Identity();
39  static const Transform3D planeZX =
40  AngleAxis3D(-0.5 * M_PI, Vector3D::UnitX()) *
41  AngleAxis3D(-0.5 * M_PI, Vector3D::UnitZ()) * Transform3D::Identity();
42 
43  std::vector<std::shared_ptr<const Surface>> surfaceStore;
44  surfaceStore.reserve(100);
45 
46  auto createProtoLayer = [&](const Transform3D& trf,
47  bool shared = false) -> ProtoLayer {
48  auto atNegX = Surface::makeShared<PlaneSurface>(
49  Transform3D(trf * Translation3D(Vector3D(-3., 0., 0.)) * planeYZ),
50  recBounds);
51 
52  auto atPosX = Surface::makeShared<PlaneSurface>(
53  Transform3D(trf * Translation3D(Vector3D(3., 0., 0.)) * planeYZ),
54  recBounds);
55 
56  auto atNegY = Surface::makeShared<PlaneSurface>(
57  Transform3D(trf * Translation3D(Vector3D(0., -3, 0.)) * planeZX),
58  recBounds);
59 
60  auto atPosY = Surface::makeShared<PlaneSurface>(
61  Transform3D(trf * Translation3D(Vector3D(0., 3., 0.)) * planeZX),
62  recBounds);
63 
64  std::vector<std::shared_ptr<const Surface>> sharedSurfaces = {
65  atNegX, atNegY, atPosX, atPosY};
66  surfaceStore.insert(surfaceStore.begin(), sharedSurfaces.begin(),
67  sharedSurfaces.end());
68  if (not shared) {
69  std::vector<const Surface*> surfaces = {atNegX.get(), atNegY.get(),
70  atPosX.get(), atPosY.get()};
71 
72  return ProtoLayer(tgContext, surfaces);
73  }
74  return ProtoLayer(tgContext, sharedSurfaces);
75  };
76 
77  // Test 0 - check constructor with surfaces and shared surfaces
78  auto pLayerSf = createProtoLayer(Transform3D::Identity());
79  auto pLayerSfShared = createProtoLayer(Transform3D::Identity());
80 
81  BOOST_CHECK(pLayerSf.extent.ranges == pLayerSfShared.extent.ranges);
82  BOOST_CHECK(pLayerSf.envelope == pLayerSfShared.envelope);
83 
84  // CHECK That you have 4 surfaces
85  BOOST_CHECK(pLayerSf.surfaces().size() == 4);
86  // Add one surface from a detector element (to test thickness)
87  auto rB = std::make_shared<RectangleBounds>(30., 60.);
88 
89  // Create the detector element
90  auto addSurface =
91  Surface::makeShared<PlaneSurface>(Transform3D::Identity(), rB);
92 
93  pLayerSf.add(tgContext, *addSurface.get());
94  // CHECK That if you now have 5 surfaces
95  BOOST_CHECK(pLayerSf.surfaces().size() == 5);
96 
97  // That should invalidate the ranges
98  BOOST_CHECK(pLayerSf.extent.ranges != pLayerSfShared.extent.ranges);
99 
100  // Test 1 - identity transform
101  auto protoLayer = createProtoLayer(Transform3D::Identity());
102 
103  CHECK_CLOSE_ABS(protoLayer.range(binX), 12., 1e-8);
104  CHECK_CLOSE_ABS(protoLayer.medium(binX), 0., 1e-8);
105  CHECK_CLOSE_ABS(protoLayer.min(binX), -6., 1e-8);
106  CHECK_CLOSE_ABS(protoLayer.max(binX), 6., 1e-8);
107  CHECK_CLOSE_ABS(protoLayer.range(binY), 6., 1e-8);
108  CHECK_CLOSE_ABS(protoLayer.medium(binY), 0., 1e-8);
109  CHECK_CLOSE_ABS(protoLayer.min(binY), -3., 1e-8);
110  CHECK_CLOSE_ABS(protoLayer.max(binY), 3., 1e-8);
111  CHECK_CLOSE_ABS(protoLayer.range(binZ), 12., 1e-8);
112  CHECK_CLOSE_ABS(protoLayer.medium(binZ), 0., 1e-8);
113  CHECK_CLOSE_ABS(protoLayer.min(binZ), -6., 1e-8);
114  CHECK_CLOSE_ABS(protoLayer.max(binZ), 6., 1e-8);
115  CHECK_CLOSE_ABS(protoLayer.max(binR), std::sqrt(3 * 3 + 6 * 6), 1e-8);
116  CHECK_CLOSE_ABS(protoLayer.min(binR), 3., 1e-8);
117 
118  // Test 1a
119 
120  // Test 2 - rotate around Z-Axis, should leave R, Z untouched,
121  // only preserves medium values
122  auto protoLayerRot = createProtoLayer(AngleAxis3D(-0.345, Vector3D::UnitZ()) *
123  Transform3D::Identity());
124 
125  BOOST_CHECK_NE(protoLayer.min(binX), -6.);
126  CHECK_CLOSE_ABS(protoLayerRot.medium(binX), 0., 1e-8);
127  CHECK_CLOSE_ABS(protoLayerRot.medium(binY), 0., 1e-8);
128  CHECK_CLOSE_ABS(protoLayerRot.range(binZ), 12., 1e-8);
129  CHECK_CLOSE_ABS(protoLayerRot.medium(binZ), 0., 1e-8);
130  CHECK_CLOSE_ABS(protoLayerRot.min(binZ), -6., 1e-8);
131  CHECK_CLOSE_ABS(protoLayerRot.max(binZ), 6., 1e-8);
132  CHECK_CLOSE_ABS(protoLayerRot.min(binR), 3., 1e-8);
133  CHECK_CLOSE_ABS(protoLayerRot.max(binR), std::sqrt(3 * 3 + 6 * 6), 1e-8);
134 
135  std::stringstream sstream;
136  protoLayerRot.toStream(sstream);
137  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] )";
138  BOOST_CHECK_EQUAL(sstream.str(), oString);
139 }
140 
141 BOOST_AUTO_TEST_SUITE_END()
142 } // namespace Layers
143 } // namespace Test
144 
145 } // namespace Acts
146