Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayerSvgConverter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LayerSvgConverter.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 
10 
11 #include "Acts/Geometry/Layer.hpp"
14 
15 #include <set>
16 #include <sstream>
17 
18 std::vector<actsvg::svg::object> Acts::Svg::LayerConverter::convert(
19  const GeometryContext& gctx, const Layer& layer,
20  const LayerConverter::Options& cOptions) {
21  // The sheets
22  std::vector<actsvg::svg::object> sheets;
23 
24  // The volume
26  volume._name = cOptions.name;
27 
29  if (layer.surfaceArray() != nullptr) {
31  sacOptions.surfaceStyles = cOptions.surfaceStyles;
32  auto [surfaces, grid, associations] = SurfaceArrayConverter::convert(
33  gctx, *(layer.surfaceArray()), sacOptions);
34  volume._surfaces = surfaces;
35  volume._surface_grid = grid;
36  volume._grid_associations = associations;
37  }
38 
39  // The sheet
40  actsvg::svg::object module_sheet;
41  actsvg::svg::object grid_sheet;
42  actsvg::svg::object xy_layer;
43  actsvg::svg::object zr_layer;
44 
45  // The module / grid information
46  const auto& layerSurface = layer.surfaceRepresentation();
47  if (layerSurface.type() == Acts::Surface::Disc) {
48  if (cOptions.moduleInfo) {
49  module_sheet = actsvg::display::endcap_sheet(
50  cOptions.name + "_modules", volume, {800, 800},
51  actsvg::display::e_module_info);
52  }
53  if (cOptions.gridInfo) {
54  grid_sheet = actsvg::display::endcap_sheet(cOptions.name + "_grid",
55  volume, {800, 800},
56  actsvg::display::e_grid_info);
57  }
58  } else if (layerSurface.type() == Acts::Surface::Cylinder) {
59  if (cOptions.moduleInfo) {
60  module_sheet = actsvg::display::barrel_sheet(
61  cOptions.name + "_modules", volume, {800, 800},
62  actsvg::display::e_module_info);
63  }
64  if (cOptions.gridInfo) {
65  grid_sheet = actsvg::display::barrel_sheet(cOptions.name + "_grid",
66  volume, {800, 800},
67  actsvg::display::e_grid_info);
68  }
69  }
70 
71  // The z_r view of things
72  actsvg::views::z_r z_r_view;
73  actsvg::views::x_y x_y_view;
74 
75  if (layer.surfaceArray() != nullptr) {
76  // The x_y view of things
77  xy_layer._tag = "g";
78  xy_layer._id = cOptions.name + "_xy_view";
79  // The x_r view of things
80  zr_layer._tag = "g";
81  zr_layer._id = cOptions.name + "_zr_view";
82  unsigned int m = 0;
83  // Potential labels
84  Acts::ActsScalar avgRadius = 0.;
85 
86  for (const auto& sf : layer.surfaceArray()->surfaces()) {
87  // Surface center
88  const Acts::Vector3 rCenter = sf->binningPosition(gctx, Acts::binR);
89  const Acts::Vector3 sfCenter = sf->center(gctx);
92  Acts::ActsScalar z = sfCenter.z();
93  // Get the average radius
94  avgRadius += radius;
95  // Raw display surfaces for projects
96  actsvg::proto::surface<std::vector<Acts::Vector3>> projSurface;
97  projSurface._vertices = sf->polyhedronRepresentation(gctx, 1u).vertices;
98  // Draw only if they fall into the range restriction - for phi
99  if (phi >= cOptions.phiRange[0] and phi <= cOptions.phiRange[1]) {
100  std::string m_zr_id = std::string("zr_") + std::to_string(m++);
101  zr_layer.add_object(Acts::Svg::View::zr(projSurface, m_zr_id));
102  }
103  // for z
104  if (z >= cOptions.zRange[0] and z <= cOptions.zRange[1]) {
105  std::string m_xy_id = std::string("xy_") + std::to_string(m++);
106  xy_layer.add_object(Acts::Svg::View::xy(projSurface, m_xy_id));
107  }
108  }
109  // Do the average
110  avgRadius /= layer.surfaceArray()->surfaces().size();
111 
112  // Add a measure iuf requested
113  if (cOptions.labelProjection) {
114  ActsScalar xEnd = avgRadius * std::cos(cOptions.labelGauge);
115  ActsScalar yEnd = avgRadius * std::sin(cOptions.labelGauge);
116  xy_layer.add_object(measure(0., 0., xEnd, yEnd, "r", avgRadius, "mm"));
117  }
118  }
119 
120  // Register according to the enums
121  sheets.push_back(module_sheet);
122  sheets.push_back(grid_sheet);
123  sheets.push_back(xy_layer);
124  sheets.push_back(zr_layer);
125 
126  // Return the created sheets
127  return sheets;
128 }