Back to home page

EIC code displayed by LXR

 
 

    


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