9 #include <boost/test/unit_test.hpp>
16 #include "actsvg/display/grids.hpp"
24 using namespace Acts::detail;
33 template <
typename local_bin_t,
size_t DIM>
34 std::string localToString(
const local_bin_t& lBin) {
36 for (
size_t ib = 0;
ib < DIM; ++
ib) {
47 BOOST_AUTO_TEST_SUITE(ActSvg)
50 using GlobalBin = size_t;
51 using LocalBin = std::array<size_t, 2u>;
57 gridXY({axisX, axisY});
61 BOOST_CHECK(pGrid._type == actsvg::proto::grid::type::e_x_y);
64 auto edgesX = axisX.getBinEdges();
65 auto edgesY = axisY.getBinEdges();
67 std::vector<actsvg::svg::object> targets = {};
70 ActsScalar xp = 0.2 * edgesX[ix] + 0.8 * edgesX[ix - 1
u];
73 ActsScalar yp = 0.8 * edgesY[iy] + 0.2 * edgesY[iy - 1
u];
74 decltype(gridXY)::point_t
p = {xp, yp};
76 auto g = gridXY.globalBinFromPosition(p);
77 auto l = gridXY.localBinsFromPosition(p);
81 localToString<decltype(gridXY)::index_t, decltype(gridXY)::DIM>(
83 std::vector<std::string> glBin = {gBin, lBin};
87 {
static_cast<actsvg::scalar
>(xp),
88 static_cast<actsvg::scalar>(yp)},
94 pGrid._connections = targets;
99 actsvg::style::stroke axis_stroke{{{0, 0, 255}}, 3};
100 actsvg::style::marker axis_marker{{
"<"}, 4, {{{0, 0, 255}}}, axis_stroke};
101 actsvg::style::font axis_font{{{0, 0, 255}},
"Andale Mono", 16};
103 auto xAxis = actsvg::draw::arrow(
"x_axis", {0, 0}, {220, 0}, axis_stroke,
104 actsvg::style::marker({
""}), axis_marker);
106 auto yAxis = actsvg::draw::arrow(
"y_axis", {0, 0}, {0, 220}, axis_stroke,
107 actsvg::style::marker({
""}), axis_marker);
110 std::vector<std::string> captionText = {
111 "Binning schema for global and local bins: ",
112 "- axis 0 : AxisBoundaryType::Bound, (-200., 200, 4), binX",
113 "- axis 1 : AxisBoundaryType::Bound, (-200, 200, 6), binY"};
117 oGrid.add_object(xAxis);
118 oGrid.add_object(xLabel);
119 oGrid.add_object(yAxis);
120 oGrid.add_object(yLabel);
121 oGrid.add_object(caption);
127 using GlobalBin = size_t;
128 using LocalBin = std::array<size_t, 2u>;
134 gridXY({axisX, axisY});
138 BOOST_CHECK(pGrid._type == actsvg::proto::grid::type::e_x_y);
141 auto edgesX = axisX.getBinEdges();
142 auto edgesY = axisY.getBinEdges();
144 std::vector<actsvg::svg::object> targets = {};
148 ActsScalar xp = 0.2 * edgesX[ix] + 0.8 * edgesX[ix - 1
u];
151 ActsScalar yp = 0.8 * edgesY[iy] + 0.2 * edgesY[iy - 1
u];
152 decltype(gridXY)::point_t
p = {xp, yp};
154 auto g = gridXY.globalBinFromPosition(p);
155 auto l = gridXY.localBinsFromPosition(p);
159 localToString<decltype(gridXY)::index_t, decltype(gridXY)::DIM>(
161 std::vector<std::string> glBin = {gBin, lBin};
165 {
static_cast<actsvg::scalar
>(xp),
166 static_cast<actsvg::scalar>(yp)},
172 pGrid._connections = targets;
175 actsvg::style::stroke axis_stroke{{{0, 0, 255}}, 3};
176 actsvg::style::marker axis_marker{{
"<"}, 4, {{{0, 0, 255}}}, axis_stroke};
177 actsvg::style::font axis_font{{{0, 0, 255}},
"Andale Mono", 16};
179 auto xAxis = actsvg::draw::arrow(
"x_axis", {0, 0}, {220, 0}, axis_stroke,
180 actsvg::style::marker({
""}), axis_marker);
182 auto yAxis = actsvg::draw::arrow(
"y_axis", {0, 0}, {0, 220}, axis_stroke,
183 actsvg::style::marker({
""}), axis_marker);
186 std::vector<std::string> captionText = {
187 "Binning schema for global and local bins: ",
188 "- axis 0 : AxisBoundaryType::Open, (-200., 200, 4), binX",
189 "- axis 1 : AxisBoundaryType::Open, (-200, 200, 6), binY"};
194 oGrid.add_object(xAxis);
195 oGrid.add_object(xLabel);
196 oGrid.add_object(yAxis);
197 oGrid.add_object(yLabel);
198 oGrid.add_object(caption);
204 using GlobalBin = size_t;
205 using LocalBin = std::array<size_t, 2u>;
211 gridZPhi({axisZ, axisPhi});
215 BOOST_CHECK(pGrid._type == actsvg::proto::grid::type::e_z_phi);
217 pGrid._reference_r = 80.;
220 auto edgesZ = axisZ.getBinEdges();
221 auto edgesPhi = axisPhi.getBinEdges();
223 std::vector<actsvg::svg::object> targets = {};
227 ActsScalar zp = 0.2 * edgesZ[iz] + 0.8 * edgesZ[iz - 1
u];
230 ActsScalar phip = 0.8 * edgesPhi[iphi] + 0.2 * edgesPhi[iphi - 1
u];
231 decltype(gridZPhi)::point_t
p = {zp, phip};
233 auto g = gridZPhi.globalBinFromPosition(p);
234 auto l = gridZPhi.localBinsFromPosition(p);
237 std::string(
"l = ") + localToString<decltype(gridZPhi)::index_t,
238 decltype(gridZPhi)::DIM>(l);
239 std::vector<std::string> glBin = {gBin, lBin};
243 {
static_cast<actsvg::scalar
>(zp),
244 static_cast<actsvg::scalar>(pGrid._reference_r * phip)},
250 pGrid._connections = targets;
253 actsvg::style::stroke axis_stroke{{{0, 0, 255}}, 3};
254 actsvg::style::marker axis_marker{{
"<"}, 4, {{{0, 0, 255}}}, axis_stroke};
255 actsvg::style::font axis_font{{{0, 0, 255}},
"Andale Mono", 16};
257 auto xAxis = actsvg::draw::arrow(
"x_axis", {0, 0}, {220, 0}, axis_stroke,
258 actsvg::style::marker({
""}), axis_marker);
260 auto yAxis = actsvg::draw::arrow(
"y_axis", {0, 0}, {0, 260}, axis_stroke,
261 actsvg::style::marker({
""}), axis_marker);
264 std::vector<std::string> captionText = {
265 "Binning schema for global and local bins: ",
266 "- axis 0 : AxisBoundaryType::Bound, (-200., 200, 3), binZ",
267 "- axis 1 : AxisBoundaryType::Closed, (-PI, PI, 6), binPhi",
268 "- draw reference radius set to 80"};
273 oGrid.add_object(xAxis);
274 oGrid.add_object(xLabel);
275 oGrid.add_object(yAxis);
276 oGrid.add_object(yLabel);
277 oGrid.add_object(caption);
283 using GlobalBin = size_t;
284 using LocalBin = std::array<size_t, 2u>;
290 gridRPhi({axisR, axisPhi});
294 BOOST_CHECK(pGrid._type == actsvg::proto::grid::type::e_r_phi);
297 auto edgesR = axisR.getBinEdges();
298 auto edgesPhi = axisPhi.getBinEdges();
300 std::vector<actsvg::svg::object> targets = {};
304 ActsScalar rp = 0.5 * (edgesR[ir] + edgesR[ir - 1
u]);
307 ActsScalar phip = 0.5 * (edgesPhi[iphi] + edgesPhi[iphi - 1
u]);
308 decltype(gridRPhi)::point_t
p = {rp, phip};
310 auto g = gridRPhi.globalBinFromPosition(p);
311 auto l = gridRPhi.localBinsFromPosition(p);
314 std::string(
"l = ") + localToString<decltype(gridRPhi)::index_t,
315 decltype(gridRPhi)::DIM>(l);
316 std::vector<std::string> glBin = {gBin, lBin};
320 {
static_cast<actsvg::scalar
>(rp * cos(phip)),
321 static_cast<actsvg::scalar>(rp * sin(phip))},
327 pGrid._connections = targets;
330 actsvg::style::stroke axis_stroke{{{0, 0, 255}}, 3};
331 actsvg::style::marker axis_marker{{
"<"}, 4, {{{0, 0, 255}}}, axis_stroke};
332 actsvg::style::font axis_font{{{0, 0, 255}},
"Andale Mono", 16};
334 auto rAxis = actsvg::draw::arrow(
"r_axis", {0, 0}, {420, 0}, axis_stroke,
335 actsvg::style::marker({
""}), axis_marker);
338 auto phiAxis = actsvg::draw::arc_measure(
339 "phi_axis", 410., {410, 0.},
340 {
static_cast<actsvg::scalar
>(410. * cos(0.25)),
341 static_cast<actsvg::scalar>(410. * sin(0.25))},
342 axis_stroke, actsvg::style::marker(), axis_marker);
347 std::vector<std::string> captionText = {
348 "Binning schema for global and local bins: ",
349 "- axis 0 : AxisBoundaryType::Bound, (100., 400, 3), binR",
350 "- axis 1 : AxisBoundaryType::Closed, (-PI, PI, 4), binPhi"};
355 oGrid.add_object(rAxis);
356 oGrid.add_object(rLabel);
357 oGrid.add_object(phiAxis);
358 oGrid.add_object(phiLabel);
359 oGrid.add_object(caption);
364 BOOST_AUTO_TEST_SUITE_END()