Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2023 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #include <optional>
0009 #include <set>
0010 #include <string>
0011 #include <vector>
0012 
0013 #include <traccc/definitions/primitives.hpp>
0014 #include <traccc/edm/particle.hpp>
0015 #include <traccc/efficiency/track_matcher.hpp>
0016 
0017 namespace traccc {
0018 stepped_percentage::stepped_percentage(scalar ratio) : m_min_ratio(ratio) {}
0019 
0020 std::string stepped_percentage::get_name() const {
0021   char buffer[512];
0022   snprintf(buffer, 512, "Stepped with ≥ %.1f%% similarity",
0023            100.f * m_min_ratio);
0024   return std::string(buffer);
0025 }
0026 
0027 std::optional<uint64_t> stepped_percentage::operator()(
0028     const std::vector<std::vector<uint64_t>>& p) const {
0029   std::multiset<uint64_t> cnt;
0030 
0031   /*
0032    * Record all the particle identifiers in a multiset in order to count
0033    * them.
0034    */
0035   for (const std::vector<uint64_t>& i : p) {
0036     for (uint64_t j : i) {
0037       cnt.insert(j);
0038     }
0039   }
0040 
0041   /*
0042    * From the maximum size, decrease the matching count required until we
0043    * find a match or we dip below the threshold.
0044    */
0045   for (std::size_t n = p.size();
0046        n <= p.size() &&
0047        (static_cast<float>(n) / static_cast<float>(p.size())) > m_min_ratio;
0048        --n) {
0049     for (uint64_t i : cnt) {
0050       if (cnt.count(i) == n) {
0051         return {i};
0052       }
0053     }
0054   }
0055 
0056   return {};
0057 }
0058 
0059 exact::exact() {}
0060 
0061 std::string exact::get_name() const {
0062   char buffer[512];
0063   snprintf(buffer, 512, "Exact");
0064   return std::string(buffer);
0065 }
0066 
0067 std::optional<uint64_t> exact::operator()(
0068     const std::vector<std::vector<uint64_t>>& p) const {
0069   std::multiset<uint64_t> cnt;
0070 
0071   /*
0072    * Record all the particle identifiers in a multiset in order to count
0073    * them.
0074    */
0075   for (const std::vector<uint64_t>& i : p) {
0076     for (uint64_t j : i) {
0077       cnt.insert(j);
0078     }
0079   }
0080 
0081   /*
0082    * Find a particle which matches every single spacepoint.
0083    */
0084   for (uint64_t i : cnt) {
0085     if (cnt.count(i) == p.size()) {
0086       return {i};
0087     }
0088   }
0089 
0090   return {};
0091 }
0092 }  // namespace traccc