Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:03

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2021-2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Local include(s).
0011 #include "traccc/seeding/detail/doublet.hpp"
0012 #include "traccc/seeding/detail/spacepoint_grid.hpp"
0013 #include "traccc/seeding/detail/spacepoint_type.hpp"
0014 #include "traccc/seeding/doublet_finding_helper.hpp"
0015 #include "traccc/utils/messaging.hpp"
0016 
0017 // VecMem include(s).
0018 #include <vecmem/memory/memory_resource.hpp>
0019 
0020 // System include(s).
0021 #include <functional>
0022 #include <utility>
0023 
0024 namespace traccc::host::details {
0025 
0026 /// Doublet finding to search the combinations of two compatible spacepoints
0027 /// @tparam otherSpType is whether it is for middle-bottom or middle-top doublet
0028 template <traccc::details::spacepoint_type otherSpType>
0029 struct doublet_finding : public messaging {
0030   // A small sanity check
0031   static_assert(otherSpType == traccc::details::spacepoint_type::bottom ||
0032                 otherSpType == traccc::details::spacepoint_type::top);
0033 
0034   /// Constructor for the doublet finding
0035   ///
0036   /// @param config is the configuration parameters
0037   ///
0038   doublet_finding(
0039       const seedfinder_config& config, vecmem::memory_resource& mr,
0040       std::unique_ptr<const Logger> logger = getDummyLogger().clone())
0041       : messaging(std::move(logger)), m_config{config}, m_mr{mr} {}
0042 
0043   /// Callable operator for doublet finding per middle spacepoint
0044   ///
0045   /// @param spacepoints The spacepoint container
0046   /// @param sp_grid The spacepoint grid
0047   /// @param middle_sp The middle spacepoint to find doublets for
0048   /// @return A pair of vectors of doublets and transformed coordinates
0049   ///
0050   std::pair<doublet_collection_types::host, lin_circle_collection_types::host>
0051   operator()(const edm::spacepoint_collection::const_device& spacepoints,
0052              const traccc::details::spacepoint_grid_types::host& sp_grid,
0053              const sp_location& middle_location) const {
0054     // Create the result object.
0055     auto result =
0056         std::make_pair(doublet_collection_types::host{&(m_mr.get())},
0057                        lin_circle_collection_types::host{&(m_mr.get())});
0058 
0059     // Access the middle spacepoint.
0060     const edm::spacepoint_collection::const_device::const_proxy_type middle_sp =
0061         spacepoints.at(
0062             sp_grid.bin(middle_location.bin_idx)[middle_location.sp_idx]);
0063 
0064     // Get the Phi/Z bins in which to look for the other spacepoint of the
0065     // doublet.
0066     const detray::dindex_sequence phi_bins =
0067         sp_grid.axis_p0().zone(middle_sp.phi(), m_config.neighbor_scope);
0068     const detray::dindex_sequence z_bins =
0069         sp_grid.axis_p1().zone(middle_sp.z(), m_config.neighbor_scope);
0070 
0071     // Iterate over neighbor bins.
0072     for (detray::dindex phi_bin : phi_bins) {
0073       for (detray::dindex z_bin : z_bins) {
0074         // Get the global index for this bin.
0075         const detray::dindex bin_idx =
0076             phi_bin + z_bin * sp_grid.axis_p0().bins();
0077 
0078         // Get the indices of the spacepoints in this bin.
0079         traccc::details::spacepoint_grid_types::host::serialized_storage::
0080             const_reference sp_indices = sp_grid.bin(phi_bin, z_bin);
0081         for (unsigned int i = 0; unsigned int sp_index : sp_indices) {
0082           // Access the other spacepoint.
0083           const edm::spacepoint_collection::const_device::const_proxy_type
0084               other_sp = spacepoints.at(sp_index);
0085 
0086           // Check if the spacepoints are compatible.
0087           if (doublet_finding_helper::isCompatible<otherSpType>(
0088                   middle_sp, other_sp, m_config)) {
0089             // If so, create a doublet for them.
0090             result.first.push_back(
0091                 {middle_location, {static_cast<unsigned int>(bin_idx), i}});
0092             result.second.push_back(
0093                 doublet_finding_helper::transform_coordinates<otherSpType>(
0094                     middle_sp, other_sp));
0095           }
0096           ++i;
0097         }
0098       }
0099     }
0100 
0101     // Return the result.
0102     return result;
0103   }
0104 
0105  private:
0106   /// The doublet finding configuration parameters
0107   seedfinder_config m_config;
0108   /// The memory resource
0109   std::reference_wrapper<vecmem::memory_resource> m_mr;
0110 };
0111 
0112 }  // namespace traccc::host::details