Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorSvgConverterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorSvgConverterTests.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 
33 
34 #include <fstream>
35 #include <memory>
36 #include <vector>
37 
38 using namespace Acts;
39 using namespace Acts::Experimental;
40 
42 
46 template <typename surface_type, typename surface_bounds_type>
48  public:
50  const CylinderVolumeBounds& vBounds,
51  const surface_bounds_type& sBounds,
52  const std::string& vName)
54  m_transform(transform),
55  m_volumeBounds(vBounds),
56  m_surfaceBounds(sBounds),
57  m_name(vName) {}
58 
59  DetectorComponent construct(
60  [[maybe_unused]] const GeometryContext& gctx) const final {
61  // The outgoing root volumes
62  std::vector<std::shared_ptr<DetectorVolume>> rootVolumes;
63 
64  // Ingredients
65  auto surface = Surface::makeShared<surface_type>(
66  (m_transform), std::make_shared<surface_bounds_type>(m_surfaceBounds));
67 
68  auto bounds = std::make_unique<CylinderVolumeBounds>(m_volumeBounds);
70  auto volume = DetectorVolumeFactory::construct(
71  portalGenerator, tContext, m_name, m_transform, std::move(bounds),
73 
74  // Add to the roots
75  rootVolumes.push_back(volume);
76 
78  for (auto [ip, p] : enumerate(volume->portalPtrs())) {
79  dContainer[ip] = p;
80  }
81  return DetectorComponent{
82  {volume},
83  dContainer,
84  RootDetectorVolumes{rootVolumes, tryRootVolumes()}};
85  }
86 
87  private:
90  surface_bounds_type m_surfaceBounds;
92 };
93 
94 BOOST_AUTO_TEST_SUITE(ActSvg)
95 
96 BOOST_AUTO_TEST_CASE(CylindricalDetector) {
97  // Declare a barrel sub builder
98  auto beampipe = std::make_shared<
100  Transform3::Identity(), CylinderVolumeBounds(0., 50., 400.),
101  CylinderBounds(25., 380.), "BeamPipe");
102 
103  // Declare a negative disc builder
104  Transform3 negZ = Transform3::Identity();
105  negZ.pretranslate(Vector3(0., 0., -300.));
106  auto endcapN =
107  std::make_shared<CylindricalVolumeBuilder<DiscSurface, RadialBounds>>(
108  negZ, CylinderVolumeBounds(50., 140., 100.), RadialBounds(60., 120.),
109  "NegativeEndcap");
110 
111  // Declare a barrel sub builder
112  auto barrel0 = std::make_shared<
114  Transform3::Identity(), CylinderVolumeBounds(50., 80., 200.),
115  CylinderBounds(65., 180.), "Barrel0");
116 
117  // Declare a barrel sub builder
118  auto barrel1 = std::make_shared<
120  Transform3::Identity(), CylinderVolumeBounds(80., 110., 200.),
121  CylinderBounds(95., 180.), "Barrel1");
122 
123  // Declare a barrel sub builder
124  auto barrel2 = std::make_shared<
126  Transform3::Identity(), CylinderVolumeBounds(110., 140., 200.),
127  CylinderBounds(125., 180.), "Barrel2");
128 
129  // Create the barrel container builder
131  barrelRCfg.builders = {barrel0, barrel1, barrel2};
132  barrelRCfg.binning = {binR};
133 
134  auto barrel = std::make_shared<CylindricalContainerBuilder>(
135  barrelRCfg, getDefaultLogger("BarrelBuilderR", Logging::VERBOSE));
136 
137  Transform3 posZ = Transform3::Identity();
138  posZ.pretranslate(Vector3(0., 0., 300.));
139  auto endcapP =
140  std::make_shared<CylindricalVolumeBuilder<DiscSurface, RadialBounds>>(
141  posZ, CylinderVolumeBounds(50., 140., 100.), RadialBounds(60., 120.),
142  "PositiveEndcap");
143 
144  // Create the barrel container builder
145  CylindricalContainerBuilder::Config barrelEndcapCfg;
146  barrelEndcapCfg.builders = {endcapN, barrel, endcapP};
147  barrelEndcapCfg.binning = {binZ};
148 
149  auto barrelEndcap = std::make_shared<CylindricalContainerBuilder>(
150  barrelEndcapCfg,
151  getDefaultLogger("BarrelEndcapBuilder", Logging::VERBOSE));
152 
153  // Create the barrel container builder
155  detectorCfg.builders = {beampipe, barrelEndcap};
156  detectorCfg.binning = {binR};
157 
158  auto containerBuilder = std::make_shared<CylindricalContainerBuilder>(
159  detectorCfg, getDefaultLogger("DetectorBuilder", Logging::VERBOSE));
160 
161  // Detector builder
162  auto gigConfig = GeometryIdGenerator::Config();
163  auto gig = std::make_shared<GeometryIdGenerator>(gigConfig);
164 
166  dCfg.auxiliary = "*** Test : Cylindrical Detector ***";
167  dCfg.name = "CylindricalDetector";
168  dCfg.builder = containerBuilder;
169  dCfg.geoIdGenerator = gig;
170 
172 
175  detectorOptions);
176  pDetector._name = detector->name();
177 
178  // Colorize in blue
179  actsvg::style::color gray({{155, 155, 155}});
180  actsvg::style::color pink({{255, 153, 255}});
181  actsvg::style::color brown({{153, 102, 51}});
182  actsvg::style::color red({{255, 0, 0}});
183  actsvg::style::color green({{0, 255, 0}});
184  actsvg::style::color blue({{0, 0, 255}});
185  std::vector<actsvg::style::color> colors = {gray, pink, brown,
186  red, green, blue};
187  for (auto& c : colors) {
188  c._opacity = 0.1;
189  }
190 
191  pDetector.colorize(colors);
192 
193  // As sheet
194  auto dv_zr = Acts::Svg::View::zr(pDetector, pDetector._name);
195  Acts::Svg::toFile({dv_zr}, pDetector._name + "_zr.svg");
196 }
197 
198 BOOST_AUTO_TEST_SUITE_END()