Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortalSvgConverterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PortalSvgConverterTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
20 
21 #include <fstream>
22 #include <memory>
23 #include <vector>
24 
26 
27 BOOST_AUTO_TEST_SUITE(ActSvg)
28 
29 BOOST_AUTO_TEST_CASE(CylinderPortalsSvg) {
30  // Some style parameteers
31  Acts::Svg::Style portalStyle;
32  portalStyle.fillColor = {255, 255, 255};
33  portalStyle.fillOpacity = 0.;
34  portalStyle.highlightColor = {255, 255, 255};
35  portalStyle.highlights = {};
36  portalStyle.strokeColor = {25, 25, 25};
37  portalStyle.strokeWidth = 0.5;
38  portalStyle.nSegments = 72u;
39 
40  Acts::ActsScalar rInner = 10.;
41  Acts::ActsScalar rOuter = 100.;
42  Acts::ActsScalar zHalfL = 200.;
43 
44  Acts::Transform3 nominal = Acts::Transform3::Identity();
45 
46  auto cylinderBounds =
47  std::make_unique<Acts::CylinderVolumeBounds>(rInner, rOuter, zHalfL);
48 
50 
52  portalGenerator, tContext, "CylinderVolume", nominal,
53  std::move(cylinderBounds), Acts::Experimental::tryAllPortals());
54 
56  portalOptions.volumeIndices[cylinderVolume.get()] = 0;
58  surfaceOptions.style = portalStyle;
59  portalOptions.surfaceOptions = surfaceOptions;
60 
61  std::vector<Acts::Svg::ProtoPortal> protoPortals;
62 
63  std::for_each(cylinderVolume->portals().begin(),
64  cylinderVolume->portals().end(), [&](const auto& p) {
65  protoPortals.push_back(Acts::Svg::PortalConverter::convert(
66  tContext, *p, portalOptions));
67  });
68 
69  // rz view
70  std::vector<actsvg::svg::object> zrPortals;
71  std::size_t ip = 0;
72  std::for_each(protoPortals.begin(), protoPortals.end(), [&](const auto& p) {
73  zrPortals.push_back(
74  Acts::Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
75  });
76  Acts::Svg::toFile(zrPortals, "SimpleCylinderPortals_ZR.svg");
77 
78  // xy view
79  std::vector<actsvg::svg::object> xyPortals;
80  ip = 0;
81  std::for_each(protoPortals.begin(), protoPortals.end(), [&](const auto& p) {
82  xyPortals.push_back(
83  Acts::Svg::View::xy(p, "Portal_xy" + std::to_string(ip++)));
84  });
85  Acts::Svg::toFile(xyPortals, "SimpleCylinderPortals_XY.svg");
86 }
87 
88 BOOST_AUTO_TEST_CASE(CylinderContainerPortalsSvg) {
89  // Some style parameteers
90  Acts::Svg::Style portalStyle;
91  portalStyle.fillColor = {255, 255, 255};
92  portalStyle.fillOpacity = 0.;
93  portalStyle.highlightColor = {255, 255, 255};
94  portalStyle.highlights = {};
95  portalStyle.strokeColor = {25, 25, 25};
96  portalStyle.strokeWidth = 0.5;
97  portalStyle.nSegments = 72u;
98 
99  Acts::ActsScalar rInner = 10.;
100  Acts::ActsScalar rMiddle = 100.;
101  Acts::ActsScalar rOuter = 300.;
102  Acts::ActsScalar zHalfL = 200.;
103 
104  Acts::Transform3 nominal = Acts::Transform3::Identity();
105 
107 
108  auto cylinderBoundsI =
109  std::make_unique<Acts::CylinderVolumeBounds>(rInner, rMiddle, zHalfL);
110 
111  auto cylinderBoundsO =
112  std::make_unique<Acts::CylinderVolumeBounds>(rMiddle, rOuter, zHalfL);
113 
115  portalGenerator, tContext, "CylinderVolumeI", nominal,
116  std::move(cylinderBoundsI), Acts::Experimental::tryAllPortals());
117 
119  portalGenerator, tContext, "CylinderVolumeO", nominal,
120  std::move(cylinderBoundsO), Acts::Experimental::tryAllPortals());
121 
122  std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> rVolumes = {
123  cylinderVolumeI, cylinderVolumeO};
124 
126  tContext, rVolumes, {});
127 
128  std::set<const Acts::Experimental::Portal*> portals;
129  for (auto& v : rVolumes) {
130  for (auto& p : v->portals()) {
131  portals.insert(p);
132  }
133  }
134  std::vector<Acts::Svg::ProtoPortal> protoPortals;
135 
137  portalOptions.volumeIndices[cylinderVolumeI.get()] = 0;
138  portalOptions.volumeIndices[cylinderVolumeO.get()] = 1;
139 
141  surfaceOptions.style = portalStyle;
142  portalOptions.surfaceOptions = surfaceOptions;
143 
144  for (const auto& portal : portals) {
145  protoPortals.push_back(
146  Acts::Svg::PortalConverter::convert(tContext, *portal, portalOptions));
147  }
148  // rz view
149  std::vector<actsvg::svg::object> zrPortals;
150  std::size_t ip = 0;
151  std::for_each(protoPortals.begin(), protoPortals.end(), [&](const auto& p) {
152  zrPortals.push_back(
153  Acts::Svg::View::zr(p, "Portal_zr" + std::to_string(ip++)));
154  });
155  Acts::Svg::toFile(zrPortals, "CylinderContainerPortals_ZR.svg");
156 }
157 
158 BOOST_AUTO_TEST_SUITE_END()