Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CandidatesForMiddleSp.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CandidatesForMiddleSp.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <algorithm>
12 #include <limits>
13 #include <memory>
14 #include <tuple>
15 #include <vector>
16 
17 namespace Acts {
20 template <typename external_space_point_t>
23  TripletCandidate() = default;
24 
26  ~TripletCandidate() = default;
27 
35  TripletCandidate(external_space_point_t& b, external_space_point_t& m,
36  external_space_point_t& t, float w, float z, bool q)
37  : bottom(&b), middle(&m), top(&t), weight(w), zOrigin(z), isQuality(q) {}
38 
40  TripletCandidate(const TripletCandidate&) = default;
41  TripletCandidate& operator=(const TripletCandidate&) = default;
42 
46 
47  external_space_point_t* bottom{nullptr};
48  external_space_point_t* middle{nullptr};
49  external_space_point_t* top{nullptr};
50  float weight{0.};
51  float zOrigin{0.};
52  bool isQuality{false};
53 };
54 
61 
62 template <typename external_space_point_t>
64  public:
66 
68  CandidatesForMiddleSp() = default;
70  ~CandidatesForMiddleSp() = default;
71 
75  void setMaxElements(std::size_t n_low, std::size_t n_high);
76 
80  std::vector<value_type> storage();
81 
91  bool push(external_space_point_t& SpB, external_space_point_t& SpM,
92  external_space_point_t& SpT, float weight, float zOrigin,
93  bool isQuality);
94 
96  void clear();
97 
102  static bool descendingByQuality(const value_type& i1, const value_type& i2);
103 
108  static bool ascendingByQuality(const value_type& i1, const value_type& i2);
109 
110  private:
123  bool push(std::vector<std::size_t>& indices, std::size_t& n,
124  const std::size_t n_max, external_space_point_t& SpB,
125  external_space_point_t& SpM, external_space_point_t& SpT,
126  float weight, float zOrigin, bool isQuality);
127 
133  bool exists(const std::size_t n, const std::size_t max_size) const;
134 
142  void pop(std::vector<std::size_t>& indices, std::size_t& current_size);
143 
148  float weight(const std::vector<std::size_t>& indices, std::size_t n) const;
149 
155  void bubbleup(std::vector<std::size_t>& indices, std::size_t n);
156 
164  void bubbledw(std::vector<std::size_t>& indices, std::size_t n,
165  std::size_t actual_size);
166 
173  void addToCollection(std::vector<std::size_t>& indices, std::size_t& n,
174  const std::size_t n_max, value_type&& element);
175 
176  private:
177  // sizes
178  // m_max_size_* is the maximum size of the indices collections. These values
179  // are set by the user once
180  std::size_t m_max_size_high{0};
181  std::size_t m_max_size_low{0};
182  // m_n_* is the current size of the indices collections [0, m_max_size_*).
183  // These values are set internally by the class
184  std::size_t m_n_high{0};
185  std::size_t m_n_low{0};
186 
187  // storage contains the collection of the candidates
188  std::vector<value_type> m_storage{};
189 
190  // The following vectors store indexes to elements in the storage
191  // They are sorted as a min heap tree, in which
192  // Each node is lower than its children
193  // Thus, it is guaranteed that the lower elements is at the front
194  // Sorting criteria is the seed quality
195  //
196  // This is in effect faster sorted container - implementation with std::set
197  // and std::priority_queue were tried and were found to be slower.
198 
199  // list of indexes of candidates with high quality in the storage
200  std::vector<std::size_t> m_indices_high{};
201  // list of indexes of candidates with low quality in the storage
202  std::vector<std::size_t> m_indices_low{};
203 };
204 
205 } // namespace Acts
206