Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-26 09:26:09

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 "traccc/definitions/qualifiers.hpp"
0013 #include "traccc/edm/measurement_collection.hpp"
0014 #include "traccc/seeding/detail/strip_geometry.hpp"
0015 #include "traccc/seeding/detail/strip_pair.hpp"
0016 
0017 // Detray include(s).
0018 #include <detray/geometry/identifier.hpp>
0019 
0020 // System include(s).
0021 #include <cstdint>
0022 
0023 namespace traccc::details {
0024 
0025 struct measurement_surface_before {
0026   template <typename measurement_t>
0027   TRACCC_HOST_DEVICE bool operator()(const measurement_t& measurement,
0028                                      const unsigned int surface_index) const {
0029     return measurement.surface_link().index() < surface_index;
0030   }
0031 };
0032 
0033 struct measurement_surface_before_or_equal {
0034   template <typename measurement_t>
0035   TRACCC_HOST_DEVICE bool operator()(const measurement_t& measurement,
0036                                      const unsigned int surface_index) const {
0037     return measurement.surface_link().index() <= surface_index;
0038   }
0039 };
0040 
0041 struct strip_rule_before {
0042   TRACCC_HOST_DEVICE bool operator()(const strip_pairing_rule& rule,
0043                                      const std::uint64_t surface_link) const {
0044     return rule.reference_surface_link < surface_link;
0045   }
0046 };
0047 
0048 template <typename measurement_collection_t>
0049 TRACCC_HOST_DEVICE inline unsigned int lower_measurement_bound(
0050     const measurement_collection_t& measurements,
0051     const std::uint64_t surface_link) {
0052   // Measurement sorting compares detray barcodes by surface index, not by
0053   // their full encoded value. Use the same key for this binary search.
0054   const auto surface_index = detray::geometry::identifier{surface_link}.index();
0055   return collection_bound(measurements, surface_index,
0056                           measurement_surface_before{});
0057 }
0058 
0059 template <typename measurement_collection_t>
0060 TRACCC_HOST_DEVICE inline unsigned int upper_measurement_bound(
0061     const measurement_collection_t& measurements,
0062     const std::uint64_t surface_link) {
0063   const auto surface_index = detray::geometry::identifier{surface_link}.index();
0064   return collection_bound(measurements, surface_index,
0065                           measurement_surface_before_or_equal{});
0066 }
0067 
0068 /// Rules are sorted by the full reference barcode, independently of measurement
0069 /// sorting (which uses the surface index).
0070 template <typename rules_t>
0071 TRACCC_HOST_DEVICE inline unsigned int lower_strip_rule_bound(
0072     const rules_t& rules, const std::uint64_t surface_link) {
0073   return collection_bound(rules, surface_link, strip_rule_before{});
0074 }
0075 
0076 template <typename measurement_t>
0077 TRACCC_HOST_DEVICE inline bool strip_pairing_value(
0078     const measurement_t& measurement,
0079     const strip_measurement_surface_info& info,
0080     strip_pairing_coordinate coordinate, scalar& value) {
0081   switch (coordinate) {
0082     case strip_pairing_coordinate::local0:
0083       value = measurement.local_position()[0];
0084       return true;
0085     case strip_pairing_coordinate::local1:
0086       value = measurement.local_position()[1];
0087       return true;
0088     case strip_pairing_coordinate::strip_index: {
0089       const int index = measured_strip_index(measurement, info.index_mapping);
0090       if (index < 0) {
0091         return false;
0092       }
0093       value = static_cast<scalar>(index);
0094       return true;
0095     }
0096     default:
0097       return false;
0098   }
0099 }
0100 
0101 template <typename measurement_t>
0102 TRACCC_HOST_DEVICE inline bool match_strip_pair(
0103     const measurement_t& reference, const measurement_t& candidate,
0104     const strip_measurement_surface_info& reference_info,
0105     const strip_measurement_surface_info& candidate_info,
0106     const strip_pairing_rule& rule) {
0107   if (reference.dimensions() != 1u || candidate.dimensions() != 1u ||
0108       reference.surface_link().value() != rule.reference_surface_link ||
0109       candidate.surface_link().value() != rule.candidate_surface_link) {
0110     return false;
0111   }
0112   scalar reference_value{}, candidate_value{};
0113   if (!strip_pairing_value(reference, reference_info, rule.reference_coordinate,
0114                            reference_value) ||
0115       !strip_pairing_value(candidate, candidate_info, rule.candidate_coordinate,
0116                            candidate_value)) {
0117     return false;
0118   }
0119   switch (rule.mode) {
0120     case strip_pairing_mode::difference: {
0121       const scalar difference =
0122           (candidate_value - reference_value) * rule.difference_scale;
0123       return difference >= rule.difference_min &&
0124              difference <= rule.difference_max;
0125     }
0126     case strip_pairing_mode::windows:
0127       return reference_value >= rule.reference_min &&
0128              reference_value <= rule.reference_max &&
0129              candidate_value >= rule.candidate_min &&
0130              candidate_value <= rule.candidate_max;
0131     default:
0132       return false;
0133   }
0134 }
0135 
0136 /// Shared enumeration keeps the count and write passes' pair selection logic in
0137 /// one place. Their callers must nevertheless guard against a floating-point
0138 /// cut-boundary disagreement between the separately compiled kernels. Geometry
0139 /// and rules must be immutable for both passes. Rules must contain exactly one
0140 /// entry per directed surface pair; reverse pairs are not implicit.
0141 template <typename measurements_t, typename surfaces_t, typename rules_t,
0142           typename visitor_t>
0143 TRACCC_HOST_DEVICE inline void visit_strip_pairs(
0144     unsigned int reference_index, const measurements_t& measurements,
0145     const surfaces_t& surfaces, const rules_t& rules, const point3& beam_spot,
0146     visitor_t& visitor) {
0147   if (reference_index >= measurements.size()) {
0148     return;
0149   }
0150   const auto reference = measurements.at(reference_index);
0151   const auto link = reference.surface_link().value();
0152   const auto rule_begin = lower_strip_rule_bound(rules, link);
0153   if (reference.dimensions() != 1u || rule_begin == rules.size() ||
0154       rules.at(rule_begin).reference_surface_link != link) {
0155     return;
0156   }
0157   strip_measurement_surface_info reference_info{};
0158   if (!find_strip_surface_info(surfaces, link, reference_info) ||
0159       make_strip_material(reference, reference_info, beam_spot).valid == 0u) {
0160     return;
0161   }
0162   for (auto i = rule_begin; i < rules.size(); ++i) {
0163     const auto& rule = rules.at(i);
0164     if (rule.reference_surface_link != link) {
0165       break;
0166     }
0167     if (rule.category != strip_pair_category::standard &&
0168         rule.category != strip_pair_category::overlap) {
0169       continue;
0170     }
0171     strip_measurement_surface_info candidate_info{};
0172     if (!find_strip_surface_info(surfaces, rule.candidate_surface_link,
0173                                  candidate_info)) {
0174       continue;
0175     }
0176     const auto begin =
0177         lower_measurement_bound(measurements, rule.candidate_surface_link);
0178     const auto end =
0179         upper_measurement_bound(measurements, rule.candidate_surface_link);
0180     for (auto candidate_index = begin; candidate_index < end;
0181          ++candidate_index) {
0182       if (candidate_index == reference_index) {
0183         continue;
0184       }
0185       const auto candidate = measurements.at(candidate_index);
0186       if (match_strip_pair(reference, candidate, reference_info, candidate_info,
0187                            rule) &&
0188           make_strip_material(candidate, candidate_info, beam_spot).valid !=
0189               0u) {
0190         visitor(candidate_index, rule);
0191       }
0192     }
0193   }
0194 }
0195 
0196 }  // namespace traccc::details