Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortalGeneratorsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PortalGeneratorsTests.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 
13 #include "Acts/Detector/Portal.hpp"
20 
21 #include <cmath>
22 #include <memory>
23 #include <vector>
24 
25 using namespace Acts::Experimental;
26 
27 // A test context
29 
30 BOOST_AUTO_TEST_SUITE(Detector)
31 
32 BOOST_AUTO_TEST_CASE(CylindricalPortalGenerator) {
33  // Access Vectors, they should yield the detector volume
34  // as a return on nextVolume(...) call
35  Acts::Vector3 negPos(-200., 0., 0.);
36  Acts::Vector3 negDir(0., 0., 1.);
37 
38  Acts::Vector3 posPos(200., 0., 0.);
39  Acts::Vector3 posDir(0., 0., -1.);
40 
41  Acts::Vector3 outerPos(100., 0., 0.);
42  Acts::Vector3 outerDir(-1., 0., 0.);
43 
44  Acts::Vector3 innerPos(10., 0., 0.);
45  Acts::Vector3 innerDir(1., 0., 0.);
46 
47  // Filled Cylinder
48  Acts::CylinderVolumeBounds cBar(0., 100, 200.);
49 
50  auto dTransform = Acts::Transform3::Identity();
51  auto pGenerator = defaultPortalGenerator();
52  auto dVolume = DetectorVolumeFactory::construct(
53  pGenerator, tContext, "dummy", dTransform,
54  std::make_unique<Acts::CuboidVolumeBounds>(1, 1, 1),
56 
57  auto cBarPortals = generatePortals(dTransform, cBar, dVolume);
58 
59  BOOST_CHECK(cBarPortals.size() == 3u);
60  // Check they are not nullptrs
61  for (const auto& p : cBarPortals) {
62  BOOST_CHECK(p != nullptr);
63  }
64 
65  // Pointing inside the volume
67 
68  auto testDetectorVolumeUpdate =
69  [&](const Acts::Experimental::Portal& portal,
70  const Acts::Vector3& position, const Acts::Vector3& direction,
71  const Acts::Experimental::DetectorVolume* expected) -> void {
72  nState.position = position;
73  nState.direction = direction;
74  portal.updateDetectorVolume(tContext, nState);
75  BOOST_CHECK(nState.currentVolume == expected);
76  };
77 
78  testDetectorVolumeUpdate(*cBarPortals[0], negPos, negDir, dVolume.get());
79  testDetectorVolumeUpdate(*cBarPortals[1], posPos, posDir, dVolume.get());
80  testDetectorVolumeUpdate(*cBarPortals[2], outerPos, outerDir, dVolume.get());
81 
82  testDetectorVolumeUpdate(*cBarPortals[0], negPos, -negDir, nullptr);
83  testDetectorVolumeUpdate(*cBarPortals[1], posPos, -posDir, nullptr);
84  testDetectorVolumeUpdate(*cBarPortals[2], outerPos, -outerDir, nullptr);
85 
86  // Tube Cylinder
87  Acts::CylinderVolumeBounds cTube(10., 100, 200.);
88  auto cTubePortals = generatePortals(dTransform, cTube, dVolume);
89  BOOST_CHECK(cTubePortals.size() == 4u);
90  // Check they are not nullptrs
91  for (const auto& p : cTubePortals) {
92  BOOST_CHECK(p != nullptr);
93  }
94 
95  testDetectorVolumeUpdate(*cTubePortals[0], negPos, negDir, dVolume.get());
96  testDetectorVolumeUpdate(*cTubePortals[1], posPos, posDir, dVolume.get());
97  testDetectorVolumeUpdate(*cTubePortals[2], outerPos, outerDir, dVolume.get());
98  testDetectorVolumeUpdate(*cTubePortals[3], innerPos, innerDir, dVolume.get());
99 
100  testDetectorVolumeUpdate(*cTubePortals[0], negPos, -negDir, nullptr);
101  testDetectorVolumeUpdate(*cTubePortals[1], posPos, -posDir, nullptr);
102  testDetectorVolumeUpdate(*cTubePortals[2], outerPos, -outerDir, nullptr);
103  testDetectorVolumeUpdate(*cTubePortals[3], innerPos, -innerDir, nullptr);
104 
105  // Sectoral tube cylinder
106  Acts::ActsScalar alpha = 0.25 * M_PI;
107  Acts::ActsScalar r = 50;
108 
109  Acts::Vector3 negPhiSecPos(r * std::cos(-alpha), r * std::sin(-alpha), 0.);
110  Acts::Vector3 negPhiSecDir(-r * std::cos(-alpha), r * std::sin(-alpha), 0.);
111  Acts::Vector3 posPhiSecPos(r * std::cos(alpha), r * std::sin(alpha), 0.);
112  Acts::Vector3 posPhiSecDir(r * std::cos(alpha), -r * std::sin(alpha), 0.);
113 
114  Acts::CylinderVolumeBounds cTubeSector(10., 100., 200., alpha, 0.);
115  auto cTubeSectorPortals = generatePortals(dTransform, cTubeSector, dVolume);
116  BOOST_CHECK(cTubeSectorPortals.size() == 6u);
117  // Check they are not nullptrs
118  for (const auto& p : cTubeSectorPortals) {
119  BOOST_CHECK(p != nullptr);
120  }
121 
122  // Pointing inside the volume
123  testDetectorVolumeUpdate(*cTubeSectorPortals[0], negPos, negDir,
124  dVolume.get());
125  testDetectorVolumeUpdate(*cTubeSectorPortals[1], posPos, posDir,
126  dVolume.get());
127  testDetectorVolumeUpdate(*cTubeSectorPortals[2], outerPos, outerDir,
128  dVolume.get());
129  testDetectorVolumeUpdate(*cTubeSectorPortals[3], innerPos, innerDir,
130  dVolume.get());
131  testDetectorVolumeUpdate(*cTubeSectorPortals[4], negPhiSecPos, negPhiSecDir,
132  dVolume.get());
133  testDetectorVolumeUpdate(*cTubeSectorPortals[5], posPhiSecPos, posPhiSecDir,
134  dVolume.get());
135 
136  // Pointing to nowhere land
137  testDetectorVolumeUpdate(*cTubeSectorPortals[0], negPos, -negDir, nullptr);
138  testDetectorVolumeUpdate(*cTubeSectorPortals[1], posPos, -posDir, nullptr);
139  testDetectorVolumeUpdate(*cTubeSectorPortals[2], outerPos, -outerDir,
140  nullptr);
141  testDetectorVolumeUpdate(*cTubeSectorPortals[3], innerPos, -innerDir,
142  nullptr);
143  testDetectorVolumeUpdate(*cTubeSectorPortals[4], negPhiSecPos, -negPhiSecDir,
144  nullptr);
145  testDetectorVolumeUpdate(*cTubeSectorPortals[5], posPhiSecPos, -posPhiSecDir,
146  nullptr);
147 }
148 
149 BOOST_AUTO_TEST_SUITE_END()