Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:26

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/builders/surface_factory_interface.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/geometry.hpp"
0015 #include "detray/definitions/indexing.hpp"
0016 #include "detray/definitions/units.hpp"
0017 
0018 // Example include(s)
0019 #include "detray/tutorial/detector_metadata.hpp"
0020 #include "detray/tutorial/my_square2D.hpp"
0021 
0022 // System include(s)
0023 #include <vector>
0024 
0025 namespace detray::tutorial {
0026 
0027 /// @brief Generates a sequence of square surfaces for the tutorial detector
0028 class square_surface_generator final
0029     : public surface_factory_interface<detector<tutorial::my_metadata>> {
0030  public:
0031   using detector_t = detector<tutorial::my_metadata>;
0032   using scalar_t = dscalar<typename detector_t::algebra_type>;
0033 
0034   /// Generate @param n square surfaces with half length @param hl .
0035   DETRAY_HOST
0036   square_surface_generator(std::size_t n, scalar_t hl)
0037       : m_n_squares{static_cast<dindex>(n)}, m_half_length{hl} {}
0038 
0039   /// @returns the number of surfaces this factory will produce
0040   DETRAY_HOST
0041   auto size() const -> dindex override { return m_n_squares; }
0042 
0043   /// Generator, does not aggregate any data
0044   /// @{
0045   DETRAY_HOST
0046   void clear() override { /*Do nothing*/ };
0047 
0048   DETRAY_HOST
0049   void push_back(
0050       surface_data<detector_t> && /*unused*/) override { /*Do nothing*/ }
0051   DETRAY_HOST
0052   auto push_back(std::vector<surface_data<detector_t>> && /*unused*/)
0053       -> void override { /*Do nothing*/ }
0054   /// @}
0055 
0056   /// Generate the surfaces and add them to given data collections.
0057   ///
0058   /// @param volume the volume that will be added to the detector.
0059   /// @param surfaces the resulting surface descriptors.
0060   /// @param transforms the transforms of the surfaces.
0061   /// @param masks the masks of the surfaces (all of the same shape).
0062   /// @param ctx the geometry context.
0063   DETRAY_HOST
0064   auto operator()(typename detector_t::volume_type &volume,
0065                   typename detector_t::surface_lookup_container &surfaces,
0066                   typename detector_t::transform_container &transforms,
0067                   typename detector_t::mask_container &masks,
0068                   typename detector_t::geometry_context ctx = {})
0069       -> dindex_range override {
0070     using surface_t = typename detector_t::surface_type;
0071     using mask_link_t = typename surface_t::mask_link;
0072     using material_link_t = typename surface_t::material_link;
0073 
0074     // Position in the detector mask tuple for square surface masks
0075     constexpr auto mask_id{detector_t::masks::id::e_square2D};
0076     // The material will be added in a later step
0077     constexpr auto no_material = surface_t::material_id::e_none;
0078     // In case the surfaces container is prefilled with other surfaces
0079     auto surfaces_offset = static_cast<dindex>(surfaces.size());
0080     // No ACTS source surface
0081     constexpr auto invalid_src_link{detail::invalid_value<std::uint64_t>()};
0082 
0083     // Produce a series of square surfaces,
0084     scalar_t z_translation{0.f};
0085     for (unsigned int i = 0u; i < m_n_squares; ++i) {
0086       // Surface placement: no rotation, just translation
0087       typename detector_t::point3_type translation{0.f, 0.f, z_translation};
0088       z_translation += 10.f * unit<scalar_t>::mm;
0089       typename detector_t::transform3_type trf{translation};
0090       transforms.push_back(trf, ctx);
0091 
0092       // Construct the mask
0093       masks.template emplace_back<mask_id>(empty_context{}, volume.index(),
0094                                            m_half_length);
0095 
0096       // Add surface descriptor with all links set (relative to the given
0097       // containers)
0098       mask_link_t mask_link{mask_id, masks.template size<mask_id>() - 1u};
0099       material_link_t material_link{no_material, dindex_invalid};
0100 
0101       surfaces.push_back({transforms.size(ctx) - 1u, mask_link, material_link,
0102                           volume.index(), surface_id::e_sensitive},
0103                          invalid_src_link);
0104     }
0105 
0106     // The range of surfaces that was added to the volume builder
0107     return {surfaces_offset, static_cast<dindex>(surfaces.size())};
0108   }
0109 
0110  private:
0111   /// How many surfaces should be produced
0112   dindex m_n_squares;
0113   /// Half length of square
0114   scalar_t m_half_length;
0115 };
0116 
0117 }  // namespace detray::tutorial