![]() |
|
|||
File indexing completed on 2025-06-30 07:51:51
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 #include <vector> 0012 0013 namespace Acts { 0014 0015 /// @brief A description of a triplet candidate. 0016 /// @tparam external_space_point_t The external spacepoint type. 0017 template <typename external_space_point_t> 0018 struct TripletCandidate { 0019 /// @brief Default Constructor 0020 TripletCandidate() = default; 0021 0022 /// @brief constructor 0023 /// @param b The bottom space point 0024 /// @param m The middle space point 0025 /// @param t The top space point 0026 /// @param w The quality of the candidate 0027 /// @param z The z coordinate of the origin 0028 /// @param q Whether the candidate is high or low quality 0029 TripletCandidate(external_space_point_t& b, external_space_point_t& m, 0030 external_space_point_t& t, float w, float z, bool q) 0031 : bottom(&b), middle(&m), top(&t), weight(w), zOrigin(z), isQuality(q) {} 0032 0033 external_space_point_t* bottom{nullptr}; 0034 external_space_point_t* middle{nullptr}; 0035 external_space_point_t* top{nullptr}; 0036 float weight{0.}; 0037 float zOrigin{0.}; 0038 bool isQuality{false}; 0039 }; 0040 0041 /// @class CandidatesForMiddleSp 0042 /// The CandidatesForMiddleSp collects the triplet candidates given a 0043 /// fixed middle spacepoint. It internally stores the triplet candidates 0044 /// keeping only those with the higher quality. 0045 /// 0046 /// @tparam external_space_point_t The external spacepoint type. 0047 0048 template <typename external_space_point_t> 0049 concept SatisfyCandidateConcept = requires(external_space_point_t spacePoint) { 0050 { spacePoint.x() } -> std::convertible_to<float>; 0051 { spacePoint.y() } -> std::convertible_to<float>; 0052 { spacePoint.z() } -> std::convertible_to<float>; 0053 }; 0054 0055 template <SatisfyCandidateConcept external_space_point_t> 0056 class CandidatesForMiddleSp { 0057 public: 0058 using value_type = TripletCandidate<external_space_point_t>; 0059 0060 /// @brief Setting maximum number of candidates to keep 0061 /// @param nLow Maximum number of candidates in the low-quality collection 0062 /// @param nHigh Maximum number of candidates in the high-quality collection 0063 void setMaxElements(std::size_t nLow, std::size_t nHigh); 0064 0065 /// @brief Retrieve the triplet candidates, the resulting vector is already sorted, 0066 /// elements with higher quality first 0067 /// @returns Vector of triplet candidates 0068 std::vector<value_type> storage(); 0069 0070 /// @brief Adding a new triplet candidate to the collection, should it satisfy the 0071 /// selection criteria 0072 /// @param spB Bottom space point 0073 /// @param spM Medium space point 0074 /// @param spT Top space point 0075 /// @param weight The quality of the triplet candidate 0076 /// @param zOrigin The z-coordinate of the origin 0077 /// @param isQuality Whether the triplet candidate is high or low quality 0078 /// @returns whether the triplet candidate has been added or not to the collection 0079 bool push(external_space_point_t& spB, external_space_point_t& spM, 0080 external_space_point_t& spT, float weight, float zOrigin, 0081 bool isQuality); 0082 0083 /// @brief Clear the internal storage 0084 void clear(); 0085 0086 /// @brief A function for sorting the triplet candidates from higher to lower quality 0087 /// @param i1 First triplet candidate 0088 /// @param i2 Second triplet candidate 0089 /// @returns The comparison result 0090 static bool descendingByQuality(const value_type& i1, const value_type& i2); 0091 0092 /// @brief A function for sorting the triplet candidates from lower to higher quality 0093 /// @param i1 First triplet candidate 0094 /// @param i2 Second triplet candidate 0095 /// @returns The comparison result 0096 static bool ascendingByQuality(const value_type& i1, const value_type& i2); 0097 0098 /// @brief Retrieve the number of Low quality candidates 0099 /// @returns The number of Low quality candidates 0100 std::size_t nLowQualityCandidates() const; 0101 0102 /// @brief Retrieve the number of High quality candidates 0103 /// @returns The number of High quality candidates 0104 std::size_t nHighQualityCandidates() const; 0105 0106 private: 0107 /// @brief dding a new triplet candidate to the collection, should it satisfy the 0108 /// selection criteria 0109 /// @param indices The collection into which the candidate should be stored 0110 /// @param n The current number of stored elements in the container 0111 /// @param nMax The maximum number of elements that can be stored in the container 0112 /// @param spB The bottom space point 0113 /// @param spM The middle space point 0114 /// @param spT The top space point 0115 /// @param weight The quality of the triplet candidate 0116 /// @param zOrigin The z-coordinate of the origin 0117 /// @param isQuality Whether the triplet candidate is high or low quality 0118 /// @returns whether the triplet candidate has been added or not to the collection 0119 bool push(std::vector<std::size_t>& indices, std::size_t& n, 0120 const std::size_t nMax, external_space_point_t& spB, 0121 external_space_point_t& spM, external_space_point_t& spT, 0122 float weight, float zOrigin, bool isQuality); 0123 0124 /// @brief Check if an element exists in the collection. The element to be checked 0125 /// is supposed to be in the n position of the collection. 0126 /// @param n Index of the requested element 0127 /// @param maxSize Number of elements currently stored in the collection 0128 /// @returns Whether the element exists 0129 bool exists(const std::size_t n, const std::size_t maxSize) const; 0130 0131 /// @brief Pop an element from a collection. The removal of the element from the collection 0132 /// does not imply its destruction. In fact, the number of stored elements is 0133 /// simply diminished by 1. The popped element is technically still available 0134 /// at the end of the collection. 0135 /// @param indices The collection 0136 /// @param currentSize The current number of element stored in the collection. The function will 0137 /// diminish this value by 1 0138 void pop(std::vector<std::size_t>& indices, std::size_t& currentSize); 0139 0140 /// @brief Return the weight for a candidate 0141 /// @param indices The collection in which the element is stored 0142 /// @param n Index of the element in the collection 0143 /// @returns The weight of the candidate 0144 float weight(const std::vector<std::size_t>& indices, std::size_t n) const; 0145 0146 /// @brief Move an element up in the min heap tree. The function checks whether the element's 0147 /// weight is lower of its parent's weight. If so, it swaps them. Reiterate 0148 /// the process until the element is in the correct position on the tree 0149 /// @param indices The collection 0150 /// @param n The index of the element to place in the correct position 0151 void bubbleup(std::vector<std::size_t>& indices, std::size_t n); 0152 0153 /// @brief Move an element down in the min heap tree. The function checks whether the elements's 0154 /// weight is lower of its child's weights. If so, it swaps the element with 0155 /// the child with the lowest weight. Reiterate the process until the element 0156 /// is in the correct position on the tree 0157 /// @param indices The collection 0158 /// @param n The index of the element to place in the correct position 0159 /// @param actualSize The current number of elements stored in the collection 0160 void bubbledw(std::vector<std::size_t>& indices, std::size_t n, 0161 std::size_t actualSize); 0162 0163 /// @brief Adding a new triplet candidate to the collection. The function is called after the candidate has satisfied 0164 /// all the selection criteria 0165 /// @param indices The collection 0166 /// @param n Current number of stored elements in the collection 0167 /// @param nMax The maximum number of elements that can be stored in the collection 0168 /// @param element The element that must be added to the collection 0169 void addToCollection(std::vector<std::size_t>& indices, std::size_t& n, 0170 const std::size_t nMax, value_type&& element); 0171 0172 private: 0173 // sizes 0174 // m_maxSize* is the maximum size of the indices collections. These values 0175 // are set by the user once 0176 std::size_t m_maxSizeHigh{0}; 0177 std::size_t m_maxSizeLow{0}; 0178 // m_n_* is the current size of the indices collections [0, m_maxSize*). 0179 // These values are set internally by the class 0180 std::size_t m_nHigh{0}; 0181 std::size_t m_nLow{0}; 0182 0183 // storage contains the collection of the candidates 0184 std::vector<value_type> m_storage{}; 0185 0186 // The following vectors store indexes to elements in the storage 0187 // They are sorted as a min heap tree, in which 0188 // Each node is lower than its children 0189 // Thus, it is guaranteed that the lower elements is at the front 0190 // Sorting criteria is the seed quality 0191 // 0192 // This is in effect faster sorted container - implementation with std::set 0193 // and std::priority_queue were tried and were found to be slower. 0194 0195 // list of indexes of candidates with high quality in the storage 0196 std::vector<std::size_t> m_indicesHigh{}; 0197 // list of indexes of candidates with low quality in the storage 0198 std::vector<std::size_t> m_indicesLow{}; 0199 }; 0200 0201 } // namespace Acts 0202 0203 #include "Acts/Seeding/CandidatesForMiddleSp.ipp"
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |