Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Core/src/Seeding2/detail/CandidatesForMiddleSp2.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 #include "Acts/Seeding2/detail/CandidatesForMiddleSp2.hpp"
0010 
0011 #include <algorithm>
0012 
0013 namespace Acts {
0014 
0015 CandidatesForMiddleSp2::CandidatesForMiddleSp2()
0016     : CandidatesForMiddleSp2(kNoSize, kNoSize) {}
0017 
0018 CandidatesForMiddleSp2::CandidatesForMiddleSp2(Size nLow, Size nHigh)
0019     : m_maxSizeLow(nLow), m_maxSizeHigh(nHigh) {
0020   // Reserve enough memory for all collections
0021   m_storage.reserve((nLow != kNoSize ? nLow : 0) +
0022                     (nHigh != kNoSize ? nHigh : 0));
0023 }
0024 
0025 void CandidatesForMiddleSp2::clear() {
0026   m_storage.clear();
0027   m_indicesLow.clear();
0028   m_indicesHigh.clear();
0029 }
0030 
0031 bool CandidatesForMiddleSp2::push(SpacePointIndex2 spB, SpacePointIndex2 spM,
0032                                   SpacePointIndex2 spT, float weight,
0033                                   float zOrigin, bool isQuality) {
0034   // Decide in which collection this candidate may be added to according to the
0035   // isQuality boolean
0036   if (isQuality) {
0037     return push(m_indicesHigh, m_maxSizeHigh, spB, spM, spT, weight, zOrigin,
0038                 isQuality);
0039   }
0040   return push(m_indicesLow, m_maxSizeLow, spB, spM, spT, weight, zOrigin,
0041               isQuality);
0042 }
0043 
0044 bool CandidatesForMiddleSp2::push(Container& container, Size nMax,
0045                                   SpacePointIndex2 spB, SpacePointIndex2 spM,
0046                                   SpacePointIndex2 spT, float weight,
0047                                   float zOrigin, bool isQuality) {
0048   if (nMax == 0) {
0049     return false;
0050   }
0051 
0052   if (container.size() < nMax) {
0053     // If there is still space, add anything
0054     m_storage.emplace_back(spB, spM, spT, weight, zOrigin, isQuality);
0055     container.emplace_back(weight, m_storage.size() - 1);
0056     std::ranges::push_heap(container, comparator);
0057     return true;
0058   }
0059 
0060   // If no space, replace one if quality is enough
0061   // Compare to element with lowest weight
0062   const auto [smallestWeight, smallestIndex] = container.front();
0063   if (weight <= smallestWeight) {
0064     return false;
0065   }
0066 
0067   // Remove element with lower weight and add this one
0068   m_storage[smallestIndex] =
0069       TripletCandidate2(spB, spM, spT, weight, zOrigin, isQuality);
0070   std::ranges::pop_heap(container, comparator);
0071   container.back() = {weight, smallestIndex};
0072   std::ranges::push_heap(container, comparator);
0073 
0074   return true;
0075 }
0076 
0077 void CandidatesForMiddleSp2::toSortedCandidates(
0078     std::vector<TripletCandidate2>& output) {
0079   output.clear();
0080   output.reserve(size());
0081 
0082   std::ranges::sort_heap(m_indicesHigh, comparator);
0083   std::ranges::sort_heap(m_indicesLow, comparator);
0084 
0085   for (const auto& [weight, index] : m_indicesHigh) {
0086     output.emplace_back(m_storage[index]);
0087   }
0088   for (const auto& [weight, index] : m_indicesLow) {
0089     output.emplace_back(m_storage[index]);
0090   }
0091 
0092   clear();
0093 }
0094 
0095 }  // namespace Acts