ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
homogeneous_material_reader.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/builders/detector_builder.hpp"
13#include "detray/builders/homogeneous_material_builder.hpp"
14#include "detray/builders/homogeneous_material_factory.hpp"
15#include "detray/core/concepts.hpp"
16#include "detray/definitions/algebra.hpp"
17#include "detray/definitions/indexing.hpp"
18#include "detray/io/backend/detail/basic_converter.hpp"
19#include "detray/io/backend/detail/type_info.hpp"
20#include "detray/io/frontend/payloads.hpp"
21#include "detray/material/material.hpp"
22
23// System include(s)
24#include <memory>
25#include <stdexcept>
26#include <string_view>
27#include <vector>
28
29namespace detray::io {
30
37 using material_type = io::material_id;
38
39 public:
41 static constexpr std::string_view tag = "homogeneous_material";
42
45
51 template <class detector_t>
52 static void from_payload(detector_builder<typename detector_t::metadata,
53 volume_builder>& det_builder,
54 const payload_type& det_mat_data) {
55 DETRAY_VERBOSE_HOST("Reading payload object...");
56
58 using mat_id = typename detector_t::material::id;
59
60 DETRAY_DEBUG_HOST("Converting material for " << det_mat_data.volumes.size()
61 << " volumes");
62
63 // Convert the material volume by volume
64 for (const auto& mv_data : det_mat_data.volumes) {
65 const auto vol_idx{
66 detail::basic_converter::from_payload(mv_data.volume_link)};
67
68 DETRAY_DEBUG_HOST(" - volume index from payload is " << vol_idx);
69
70 if (!det_builder.has_volume(vol_idx)) {
71 std::stringstream err_stream;
72 err_stream << "Volume " << vol_idx << ": "
73 << "Cannot build homogeneous material for volume "
74 << "(volume not registered in detector builder)";
75 DETRAY_FATAL_HOST(err_stream.str());
76 throw std::invalid_argument(err_stream.str());
77 }
78
79 // Decorate the current volume builder with material
80 auto vm_builder =
81 det_builder
82 .template decorate<homogeneous_material_builder<detector_t>>(
83 vol_idx);
84 DETRAY_DEBUG_HOST(
85 "Retrieved volume builder from detector build using vol_idx="
86 << vol_idx);
87
88 // Add the material data to the factory
89 auto mat_factory =
90 std::make_shared<homogeneous_material_factory<detector_t>>();
91
92 DETRAY_DEBUG_HOST("Adding " << mv_data.surface_mat.size()
93 << " material slabs to material factory");
94 for (const auto& mat_data : mv_data.surface_mat) {
95 // Determine the material type id
96 mat_id mat_type{mat_id::e_none};
98 if (mat_data.type == io::material_id::rod) {
99 mat_type = mat_id::e_material_rod;
100 }
101 }
103 if (mat_data.type == io::material_id::slab) {
104 mat_type = mat_id::e_material_slab;
105 }
106 }
107 assert(mat_type != mat_id::e_none);
108
109 const auto mat_idx{mat_data.index_in_coll.has_value()
110 ? mat_data.index_in_coll.value()
111 : detray::detail::invalid_value<std::size_t>()};
112
113 DETRAY_DEBUG_HOST("-> Surface link is: " << mat_idx);
114
115 mat_factory->add_material(mat_type, from_payload<scalar_t>(mat_data),
116 mat_idx);
117 }
118
119 // Add the material to the volume
120 DETRAY_DEBUG_HOST("Adding material factory to the builder");
121 vm_builder->add_surfaces(mat_factory);
122 }
123 }
124
127 template <detray::concepts::scalar scalar_t>
129 const surface_material_payload& slab_data) {
130 return {static_cast<scalar_t>(slab_data.thickness),
131 from_payload<scalar_t>(slab_data.mat),
132 detail::basic_converter::from_payload(slab_data.surface)};
133 }
134
136 template <detray::concepts::scalar scalar_t>
137 static auto from_payload(const material_param_payload& mat_data) {
138 return material<scalar_t>{
139 static_cast<scalar_t>(mat_data.params[0]),
140 static_cast<scalar_t>(mat_data.params[1]),
141 static_cast<scalar_t>(mat_data.params[2]),
142 static_cast<scalar_t>(mat_data.params[3]),
143 static_cast<scalar_t>(mat_data.params[4]),
144 // The molar density (params[5]) is calculated on the fly
145 static_cast<material_state>(mat_data.params[6])};
146 }
147};
148
149} // namespace detray::io
Provides functionality to build a detray detector volume by volume.
Definition detector_builder.hpp:40
Homogeneous material reader backend.
Definition homogeneous_material_reader.hpp:34
detector_homogeneous_material_payload payload_type
Payload type that the reader processes.
Definition homogeneous_material_reader.hpp:44
static constexpr std::string_view tag
Tag the reader as "homogeneous material".
Definition homogeneous_material_reader.hpp:41
static auto from_payload(const material_param_payload &mat_data)
Definition homogeneous_material_reader.hpp:137
static void from_payload(detector_builder< typename detector_t::metadata, volume_builder > &det_builder, const payload_type &det_mat_data)
Convert the detector material det_mat_data from its IO payload.
Definition homogeneous_material_reader.hpp:52
static material_data< scalar_t > from_payload(const surface_material_payload &slab_data)
Definition homogeneous_material_reader.hpp:128
Bind components for material together.
Definition homogeneous_material_factory.hpp:35
Provides basic functionality to build detector volumes.
Definition volume_builder.hpp:36
Check for the the presence of material rods in a detector definition.
Definition concepts.hpp:146
Check for the the presence of material slabs in a detector definition.
Definition concepts.hpp:141
The following enums are global for all detectors.
Definition concepts.hpp:18
material_id
Enumerate the different material types.
Definition definitions.hpp:59
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
material_state
Material State.
Definition material.hpp:27
A payload for the homogeneous material description of a detector.
Definition payloads.hpp:257
std::vector< material_volume_payload > volumes
Material payloads grouped by detector volume.
Definition payloads.hpp:259
A payload object for a material parametrization.
Definition payloads.hpp:210
std::array< io::scalar, 7u > params
Material parametrization 0: X0 1: L0 2: Ar 3: Z 4: Mass density 5: Molar densitty (unused) 6: materia...
Definition payloads.hpp:219
A payload object for a material slab/rod.
Definition payloads.hpp:223
io::scalar thickness
Thickness of the material slab.
Definition payloads.hpp:235
single_link_payload surface
Index of the surface in the volume the material belongs to.
Definition payloads.hpp:233
material_param_payload mat
Material parameters.
Definition payloads.hpp:237
Material composition properties and density data used by interactions.
Definition material.hpp:36