File indexing completed on 2025-01-19 09:23:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Material/ISurfaceMaterial.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "Acts/Utilities/Delegate.hpp"
0016 #include "Acts/Utilities/GridAccessHelpers.hpp"
0017 #include "Acts/Utilities/VectorHelpers.hpp"
0018
0019 #include <ostream>
0020 #include <stdexcept>
0021 #include <vector>
0022
0023 namespace Acts {
0024
0025
0026
0027 struct GridMaterialAccessor {
0028
0029
0030
0031
0032
0033
0034 template <typename grid_type>
0035 inline const MaterialSlab& slab(
0036 grid_type& grid, const typename grid_type::point_t& point) const {
0037 return grid.atPosition(point);
0038 }
0039
0040
0041
0042
0043
0044
0045
0046 template <typename grid_type>
0047 void scale(grid_type& grid, ActsScalar scale) {
0048
0049 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0050 grid.at(ib).scaleThickness(scale);
0051 }
0052 }
0053 };
0054
0055
0056
0057 struct IndexedMaterialAccessor {
0058
0059 std::vector<MaterialSlab> material;
0060
0061
0062
0063
0064
0065
0066 template <typename grid_type>
0067 inline const MaterialSlab& slab(
0068 const grid_type& grid, const typename grid_type::point_t& point) const {
0069 auto index = grid.atPosition(point);
0070 return material[index];
0071 }
0072
0073
0074
0075
0076 template <typename grid_type>
0077 void scale(grid_type& , ActsScalar scale) {
0078 for (auto& m : material) {
0079 m.scaleThickness(scale);
0080 }
0081 }
0082 };
0083
0084
0085
0086 struct GloballyIndexedMaterialAccessor {
0087
0088 std::shared_ptr<std::vector<MaterialSlab>> globalMaterial = nullptr;
0089
0090
0091
0092
0093
0094 bool sharedEntries = false;
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 template <typename grid_type>
0105 inline const MaterialSlab& slab(
0106 const grid_type& grid, const typename grid_type::point_t& point) const {
0107 auto index = grid.atPosition(point);
0108 return (*globalMaterial)[index];
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 template <typename grid_type>
0121 void scale(grid_type& grid, ActsScalar scale) {
0122 if (sharedEntries) {
0123 throw std::invalid_argument(
0124 "GloballyIndexedMaterialAccessor: shared entry scaling is not "
0125 "supported.");
0126 }
0127
0128 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0129 auto index = grid.at(ib);
0130 (*globalMaterial)[index].scaleThickness(scale);
0131 }
0132 }
0133 };
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 template <typename grid_t, typename material_accessor_t = GridMaterialAccessor>
0146 class GridSurfaceMaterialT : public ISurfaceMaterial {
0147 public:
0148
0149 using BoundToGridLocalDelegate =
0150 OwningDelegate<typename grid_t::point_t(const Vector2&),
0151 GridAccess::IBoundToGridLocal>;
0152
0153
0154 using GlobalToGridLocalDelegate =
0155 OwningDelegate<typename grid_t::point_t(const Vector3&),
0156 GridAccess::IGlobalToGridLocal>;
0157
0158
0159 using grid_type = grid_t;
0160
0161
0162 using material_accessor_type = material_accessor_t;
0163
0164
0165
0166
0167
0168
0169
0170 GridSurfaceMaterialT(grid_type&& grid,
0171 material_accessor_type&& materialAccessor,
0172 BoundToGridLocalDelegate boundToGridLocal,
0173 GlobalToGridLocalDelegate globalToGridLocal)
0174 : m_grid(std::move(grid)),
0175 m_materialAccessor(std::move(materialAccessor)),
0176 m_globalToGridLocal(std::move(globalToGridLocal)),
0177 m_boundToGridLocal(std::move(boundToGridLocal)) {
0178 if (!m_globalToGridLocal.connected()) {
0179 throw std::invalid_argument(
0180 "GridSurfaceMaterialT: GlobalToGridLocalDelegate is not connected.");
0181 }
0182 if (!m_boundToGridLocal.connected()) {
0183 throw std::invalid_argument(
0184 "GridSurfaceMaterialT: BoundToGridLocalDelegate is not connected.");
0185 }
0186 }
0187
0188
0189 const MaterialSlab& materialSlab(const Vector2& lp) const final {
0190 return m_materialAccessor.slab(m_grid, m_boundToGridLocal(lp));
0191 }
0192
0193
0194 const MaterialSlab& materialSlab(const Vector3& gp) const final {
0195 return m_materialAccessor.slab(m_grid, m_globalToGridLocal(gp));
0196 }
0197
0198
0199
0200
0201 ISurfaceMaterial& operator*=(ActsScalar scale) final {
0202 m_materialAccessor.scale(m_grid, scale);
0203 return (*this);
0204 }
0205
0206
0207 std::ostream& toStream(std::ostream& sl) const final {
0208 sl << "GridSurfaceMaterial - material access via accessor.";
0209 return sl;
0210 }
0211
0212
0213 const grid_type& grid() const { return m_grid; }
0214
0215
0216 const material_accessor_type& materialAccessor() const {
0217 return m_materialAccessor;
0218 }
0219
0220
0221 const BoundToGridLocalDelegate& boundToGridLocal() const {
0222 return m_boundToGridLocal;
0223 }
0224
0225
0226 const GlobalToGridLocalDelegate& globalToGridLocal() const {
0227 return m_globalToGridLocal;
0228 }
0229
0230 private:
0231
0232 grid_type m_grid;
0233
0234
0235 material_accessor_type m_materialAccessor;
0236
0237
0238 GlobalToGridLocalDelegate m_globalToGridLocal;
0239
0240
0241 BoundToGridLocalDelegate m_boundToGridLocal;
0242 };
0243
0244
0245 template <typename grid_type>
0246 using IndexedSurfaceMaterial =
0247 GridSurfaceMaterialT<grid_type, IndexedMaterialAccessor>;
0248
0249
0250 template <typename grid_type>
0251 using GloballyIndexedSurfaceMaterial =
0252 GridSurfaceMaterialT<grid_type, GloballyIndexedMaterialAccessor>;
0253
0254
0255 template <typename grid_type>
0256 using GridSurfaceMaterial = GridSurfaceMaterialT<grid_type>;
0257
0258 }