Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayerSvgConverterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LayerSvgConverterTests.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 
14 #include "Acts/Geometry/Layer.hpp"
24 
25 #include <fstream>
26 #include <memory>
27 #include <vector>
28 
29 BOOST_AUTO_TEST_SUITE(ActSvg)
30 
31 namespace {
32 
34 
35 std::shared_ptr<const Acts::LayerCreator> lCreator(nullptr);
36 
37 void setupTools() {
38  if (lCreator == nullptr) {
39  Acts::LayerCreator::Config lCreatorCfg;
40  lCreatorCfg.surfaceArrayCreator =
41  std::make_shared<const Acts::SurfaceArrayCreator>();
42  lCreator = std::make_shared<const Acts::LayerCreator>(lCreatorCfg);
43  }
44 }
45 
46 std::shared_ptr<Acts::Layer> generateDiscLayer(Acts::ActsScalar rInner,
47  Acts::ActsScalar rOuter,
48  unsigned int nSegments,
49  unsigned int nRings,
50  bool useTrapezoids = false) {
51  // Some preparations
52  setupTools();
53  std::vector<std::shared_ptr<const Acts::Surface>> moduleSurfaces;
54  Acts::ActsScalar phiStep = 2 * M_PI / nSegments;
55  Acts::ActsScalar rStep = (rOuter - rInner) / nRings;
56  // Reserve & fill
57  moduleSurfaces.reserve(nSegments * nRings);
58  // Radial disc
59  if (not useTrapezoids) {
60  for (unsigned int ir = 0; ir < nRings; ++ir) {
61  std::shared_ptr<const Acts::RadialBounds> rBounds = nullptr;
62  rBounds = std::make_shared<Acts::RadialBounds>(
63  rInner + ir * rStep - 0.025 * rInner,
64  rInner + (ir + 1u) * rStep + 0.025 * rInner, 0.55 * phiStep, 0.);
65  for (unsigned int is = 0; is < nSegments; ++is) {
66  // Place the module
67  auto placement = Acts::Transform3::Identity();
68  if (is % 2) {
69  placement.pretranslate(Acts::Vector3{0., 0., 2.});
70  }
71  placement.rotate(
72  Eigen::AngleAxisd(is * phiStep, Acts::Vector3(0, 0, 1)));
73  auto dModule =
74  Acts::Surface::makeShared<Acts::DiscSurface>(placement, rBounds);
75  moduleSurfaces.push_back(dModule);
76  }
77  }
78  } else {
79  for (unsigned int ir = 0; ir < nRings; ++ir) {
80  // Trapezoid parameters
81  Acts::ActsScalar radius = rInner + (ir + 0.5) * rStep;
82  Acts::ActsScalar yHalf = rStep * 0.5125;
83 
84  Acts::ActsScalar xHalfMin =
85  1.15 * (rInner + ir * rStep) * M_PI / nSegments;
86  Acts::ActsScalar xHalfMax =
87  1.15 * (rInner + (ir + 1) * rStep) * M_PI / nSegments;
88 
89  std::shared_ptr<const Acts::TrapezoidBounds> tBounds =
90  std::make_shared<const Acts::TrapezoidBounds>(xHalfMin, xHalfMax,
91  yHalf);
92  for (unsigned int is = 0; is < nSegments; ++is) {
93  // Setting the phi
94  Acts::ActsScalar cphi = -M_PI + is * phiStep;
95  Acts::Vector3 center(radius * std::cos(cphi), radius * std::sin(cphi),
96  (is % 2) * 2 + (ir % 2) * 5);
97  // Local axis system
98  Acts::Vector3 localY(std::cos(cphi), std::sin(cphi), 0.);
99  Acts::Vector3 localZ(0., 0., 1.);
100  Acts::Vector3 localX = localY.cross(localZ);
101  Acts::RotationMatrix3 rotation;
102  rotation.col(0) = localX;
103  rotation.col(1) = localY;
104  rotation.col(2) = localZ;
105  Acts::Transform3 placement(Acts::Translation3(center) * rotation);
106  // Create the module surface
107  auto dModule =
108  Acts::Surface::makeShared<Acts::PlaneSurface>(placement, tBounds);
109  moduleSurfaces.push_back(dModule);
110  }
111  }
112  }
113  // Let's create the disc layer
114  return lCreator->discLayer(tgContext, moduleSurfaces, nRings, nSegments);
115 }
116 
117 } // namespace
118 
119 BOOST_AUTO_TEST_CASE(DiscLayerRadialSvg) {
120  // Planar style
121  Acts::Svg::Style discLayerStyle;
122  discLayerStyle.fillColor = {51, 153, 255};
123  discLayerStyle.fillOpacity = 0.75;
124  discLayerStyle.highlightColor = {255, 153, 51};
125  discLayerStyle.highlights = {"mouseover", "mouseout"};
126  discLayerStyle.strokeColor = {25, 25, 25};
127  discLayerStyle.strokeWidth = 0.5;
128  discLayerStyle.nSegments = 72u;
129 
130  Acts::GeometryIdentifier geoID{0};
131 
132  // Get the layer
133  auto discLayer = generateDiscLayer(100, 250, 32u, 4u);
134 
136  lOptions.name = "disc_layer_sectors";
137  lOptions.surfaceStyles =
138  Acts::GeometryHierarchyMap<Acts::Svg::Style>({{geoID, discLayerStyle}});
139 
140  // Get the layer sheets
141  auto discLayerSheets =
142  Acts::Svg::LayerConverter::convert(tgContext, *discLayer, lOptions);
143 
144  for (const auto& s : discLayerSheets) {
145  Acts::Svg::toFile({s}, s._id + ".svg");
146  }
147 }
148 
149 BOOST_AUTO_TEST_CASE(DiscLayerTrapezoidSvg) {
150  // Planar style
151  Acts::Svg::Style discLayerStyle;
152  discLayerStyle.fillColor = {51, 153, 255};
153  discLayerStyle.fillOpacity = 0.75;
154  discLayerStyle.highlightColor = {255, 153, 51};
155  discLayerStyle.highlights = {"mouseover", "mouseout"};
156  discLayerStyle.strokeColor = {25, 25, 25};
157  discLayerStyle.strokeWidth = 0.5;
158  discLayerStyle.nSegments = 72u;
159 
160  Acts::GeometryIdentifier geoID{0};
161 
162  // Get the layer
163  auto discLayer = generateDiscLayer(100, 250, 32u, 4u, true);
164 
166  lOptions.name = "disc_layer_trapezoid";
167  lOptions.surfaceStyles =
168  Acts::GeometryHierarchyMap<Acts::Svg::Style>({{geoID, discLayerStyle}});
169 
170  // Get the layer sheets
171  auto discLayerSheets =
172  Acts::Svg::LayerConverter::convert(tgContext, *discLayer, lOptions);
173 
174  for (const auto& s : discLayerSheets) {
175  Acts::Svg::toFile({s}, s._id + ".svg");
176  }
177 }
178 
179 BOOST_AUTO_TEST_CASE(CylinderLayerSvg) {
180  // Planar style
181  Acts::Svg::Style cylinderLayerStyle;
182  cylinderLayerStyle.fillColor = {51, 153, 255};
183  cylinderLayerStyle.fillOpacity = 0.75;
184  cylinderLayerStyle.highlightColor = {255, 153, 51};
185  cylinderLayerStyle.highlights = {"mouseover", "mouseout"};
186  cylinderLayerStyle.strokeColor = {25, 25, 25};
187  cylinderLayerStyle.strokeWidth = 0.5;
188  cylinderLayerStyle.nSegments = 72u;
189 
190  Acts::GeometryIdentifier geoID{0};
191 
193  auto tGeometry = cGeometry();
194  auto pixelVolume =
195  tGeometry->lowestTrackingVolume(tgContext, Acts::Vector3(50., 0., 0.));
196  if (pixelVolume != nullptr and pixelVolume->confinedLayers() != nullptr) {
197  auto layers = pixelVolume->confinedLayers()->arrayObjects();
198  size_t il = 0;
199  for (const auto& layer : layers) {
200  if (layer->surfaceArray() != nullptr) {
202  lOptions.name = "cylinder_layer_" + std::to_string(il++);
204  {{geoID, cylinderLayerStyle}});
205 
206  // Get the layer sheets
207  auto layerSheets =
208  Acts::Svg::LayerConverter::convert(tgContext, *layer, lOptions);
209  for (const auto& s : layerSheets) {
210  Acts::Svg::toFile({s}, s._id + ".svg");
211  }
212  }
213  }
214  }
215 }
216 
217 BOOST_AUTO_TEST_CASE(PlaeyLayerSvg) {}
218 
219 BOOST_AUTO_TEST_SUITE_END()