12#include "detray/builders/cuboid_portal_generator.hpp"
13#include "detray/builders/detector_builder.hpp"
14#include "detray/builders/homogeneous_material_builder.hpp"
15#include "detray/builders/homogeneous_material_generator.hpp"
16#include "detray/builders/homogeneous_volume_material_builder.hpp"
17#include "detray/core/detector.hpp"
18#include "detray/definitions/algebra.hpp"
19#include "detray/definitions/units.hpp"
20#include "detray/detectors/telescope_metadata.hpp"
21#include "detray/geometry/mask.hpp"
22#include "detray/material/predefined_materials.hpp"
23#include "detray/tracks/trajectories.hpp"
24#include "detray/utils/consistency_checker.hpp"
25#include "detray/utils/print_detector.hpp"
28#include "detray/test/common/factories/telescope_generator.hpp"
31#include <vecmem/memory/memory_resource.hpp>
43 template <
typename>
class trajectory_t =
detail::ray>
52 const trajectory_t<algebra_t> &t = {})
65 const trajectory_t<algebra_t> &t = {})
70 template <
typename... Args>
71 requires(std::is_same_v<Args, scalar_t> && ...)
74 mask<mask_shape_t, algebra_t>{0u, std::forward<Args>(args)...}) {}
119 assert((l > 0.f) &&
"Telescope detector length must be greater than zero");
128 std::ranges::copy_if(dists, std::back_inserter(
m_positions),
129 [](
scalar_t d) {
return (d >= 0.f); });
150 assert(t >= 0.f &&
"Material thickness must be non-negative");
165 assert(e > 0.f &&
"Portal envelope must be greater than zero");
236template <concepts::algebra algebra_t,
typename shape_t,
237 template <
typename>
class trajectory_t>
239 const trajectory_t<algebra_t> &)
255 template <
typename>
class trajectory_t =
detail::ray>
257 vecmem::memory_resource &resource,
263 using metadata_t = telescope_metadata<algebra_t, mask_shape_t>;
264 using builder_t = detector_builder<metadata_t, volume_builder>;
265 using detector_t =
typename builder_t::detector_type;
267 builder_t det_builder;
268 det_builder.set_name(
"telescope_detector");
271 auto v_builder = det_builder.new_volume(volume_id::e_cuboid);
272 v_builder->set_name(
"telescope_world_0");
275 v_builder->add_volume_placement();
278 using telescope_factory =
279 telescope_generator<detector_t, mask_shape_t, trajectory_t<algebra_t>>;
280 std::unique_ptr<surface_factory_interface<detector_t>> tel_generator;
282 if (cfg.positions().empty()) {
284 tel_generator = std::make_unique<telescope_factory>(
285 cfg.length(), cfg.n_surfaces(), cfg.module_mask().values(),
289 tel_generator = std::make_unique<telescope_factory>(
290 cfg.positions(), cfg.module_mask().values(), cfg.pilot_track());
295 std::shared_ptr<surface_factory_interface<detector_t>> module_generator;
297 if (cfg.module_material() != detray::vacuum<scalar_t>{}) {
300 det_builder.template decorate<homogeneous_material_builder<detector_t>>(
304 throw std::runtime_error(
"Surface material decoration failed");
307 auto tel_mat_generator =
308 std::make_shared<homogeneous_material_generator<detector_t>>(
309 std::move(tel_generator), cfg.material_config());
311 module_generator = std::move(tel_mat_generator);
314 module_generator = std::move(tel_generator);
318 auto portal_generator =
319 std::make_shared<cuboid_portal_generator<detector_t>>(cfg.envelope());
321 vm_builder->add_surfaces(module_generator);
323 vm_builder->add_surfaces(portal_generator);
328 if (cfg.volume_material() != detray::vacuum<scalar_t>{}) {
329 auto full_v_builder =
331 .template decorate<homogeneous_volume_material_builder<detector_t>>(
334 if (full_v_builder) {
335 full_v_builder->set_material(cfg.volume_material());
337 throw std::runtime_error(
"Volume material decoration failed");
342 typename detector_t::name_map
name_map{};
343 auto det = det_builder.build(resource, cfg.builder_options(),
name_map);
345 if (cfg.do_check()) {
346 const bool verbose_check{
false};
347 detray::detail::check_consistency(det, verbose_check,
name_map);
350 DETRAY_DEBUG_HOST(
"\n" << detray::utils::print_detector(det,
name_map));
352 return std::make_pair(std::move(det), std::move(
name_map));
describes a straight-line trajectory
Definition ray.hpp:22
Mask a region on a surface and link it to a volume.
Definition mask.hpp:46
Geometrical shape of a rectangle2D.
Definition rectangle2D.hpp:30
Interface for volume builders (and volume builder decorators).
Definition volume_builder_interface.hpp:66
Algebra plugin concept.
Definition concepts.hpp:147
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
tel_det_config(const mask< shape_t, algebra_t > &, const trajectory_t< algebra_t > &) -> tel_det_config< algebra_t, shape_t, trajectory_t >
Deduce the type of telescope config.
auto build_telescope_detector(vecmem::memory_resource &resource, const tel_det_config< algebra_t, mask_shape_t, trajectory_t > &cfg=tel_det_config< algebra_t, mask_shape_t, trajectory_t >{ 20.f *unit< dscalar< algebra_t > >::mm, 20.f *unit< dscalar< algebra_t > >::mm})
Builds a detray geometry that contains only one volume with one type of surfaces.
Definition build_telescope_detector.hpp:256
Configuration for the homogeneous material generator.
Definition homogeneous_material_generator.hpp:33
Material composition properties and density data used by interactions.
Definition material.hpp:36
Map volume indices to volume names and vice versa.
Definition name_map.hpp:23
Predefined silicon material using TrackML bulk properties.
Definition predefined_materials.hpp:212
Configure the toy detector.
Definition build_telescope_detector.hpp:44
std::vector< scalar_t > m_positions
Concrete positions where to place the surfaces along the pilot track.
Definition build_telescope_detector.hpp:83
constexpr scalar_t length() const
Return the length.
Definition build_telescope_detector.hpp:193
constexpr tel_det_config & positions(const std::vector< scalar_t > &dists)
Set the positions.
Definition build_telescope_detector.hpp:126
constexpr tel_det_config & mat_thickness(const scalar_t t)
Set the mat thickness.
Definition build_telescope_detector.hpp:149
constexpr tel_det_config & pilot_track(const trajectory_t< algebra_t > &traj)
Set the pilot track.
Definition build_telescope_detector.hpp:157
unsigned int m_n_surfaces
No. of test surfaces in the telescope.
Definition build_telescope_detector.hpp:79
constexpr const material< scalar_t > & volume_material() const
Return the volume material.
Definition build_telescope_detector.hpp:210
constexpr scalar_t mat_thickness() const
Return the mat thickness.
Definition build_telescope_detector.hpp:215
hom_material_config< scalar_t > m_material_config
Configuration for the homogeneous material generator.
Definition build_telescope_detector.hpp:85
constexpr const mask< mask_shape_t, algebra_t > & module_mask() const
Getters.
Definition build_telescope_detector.hpp:185
tel_det_config & do_check(const bool check)
Set the do check.
Definition build_telescope_detector.hpp:175
constexpr tel_det_config & n_surfaces(const unsigned int n)
Set the n surfaces.
Definition build_telescope_detector.hpp:111
constexpr tel_det_config & module_material(const material< scalar_t > &mat)
Set the module material.
Definition build_telescope_detector.hpp:135
volume_builder_options & builder_options()
Return the builder options.
Definition build_telescope_detector.hpp:171
volume_builder_options m_builder_opts
Volume builder configuration.
Definition build_telescope_detector.hpp:93
constexpr tel_det_config & volume_material(const material< scalar_t > &mat)
Set the volume material.
Definition build_telescope_detector.hpp:142
constexpr tel_det_config & envelope(const scalar_t e)
Set the envelope.
Definition build_telescope_detector.hpp:164
mask< mask_shape_t, algebra_t > m_mask
Mask of the test surfaces.
Definition build_telescope_detector.hpp:77
constexpr unsigned int n_surfaces() const
Return the n surfaces.
Definition build_telescope_detector.hpp:190
scalar_t m_envelope
Safety envelope between the test surfaces and the portals.
Definition build_telescope_detector.hpp:91
const trajectory_t< algebra_t > & pilot_track() const
Return the pilot track.
Definition build_telescope_detector.hpp:220
constexpr tel_det_config & module_mask(const mask< mask_shape_t, algebra_t > &m)
Setters.
Definition build_telescope_detector.hpp:103
tel_det_config(const std::vector< scalar_t > ¶ms, const trajectory_t< algebra_t > &t={})
Construct from from mask parameter vector.
Definition build_telescope_detector.hpp:64
scalar_t m_length
Length of the telescope.
Definition build_telescope_detector.hpp:81
const volume_builder_options & builder_options() const
Return the builder options.
Definition build_telescope_detector.hpp:226
tel_det_config(const mask< mask_shape_t, algebra_t > &m, const trajectory_t< algebra_t > &t={})
Construct from existing mask.
Definition build_telescope_detector.hpp:51
trajectory_t< algebra_t > m_trajectory
Pilot track along which to place the surfaces.
Definition build_telescope_detector.hpp:89
constexpr const auto & material_config() const
Return the material config.
Definition build_telescope_detector.hpp:199
constexpr const material< scalar_t > & module_material() const
Return the module material.
Definition build_telescope_detector.hpp:205
constexpr tel_det_config & length(const scalar_t l)
Set the length.
Definition build_telescope_detector.hpp:118
bool m_do_check
Run detector consistency check after reading.
Definition build_telescope_detector.hpp:96
material< scalar_t > m_volume_material
Material for volume.
Definition build_telescope_detector.hpp:87
constexpr auto & material_config()
Return the material configuration.
Definition build_telescope_detector.hpp:202
const std::vector< scalar_t > & positions() const
Return the positions.
Definition build_telescope_detector.hpp:196
bool do_check() const
Return the do check.
Definition build_telescope_detector.hpp:231
constexpr scalar_t envelope() const
Return the envelope.
Definition build_telescope_detector.hpp:223
dscalar< algebra_t > scalar_t
Scalar type used by this configuration.
Definition build_telescope_detector.hpp:46
Unit conversion factors.
Definition units.hpp:22
static constexpr scalar_t um
Length, native unit mm.
Definition units.hpp:25
static constexpr scalar_t mm
Native length unit, the millimetre.
Definition units.hpp:27
Elements Declaration.
Definition predefined_materials.hpp:34
Options for the volume builder classes.
Definition volume_builder_interface.hpp:29