12#include <boost/container/flat_map.hpp>
13#include <boost/container/flat_set.hpp>
19#include "Acts/EventData/SourceLink.hpp"
20#include "Acts/Geometry/GeometryIdentifier.hpp"
21#include "Acts/Surfaces/Surface.hpp"
22#include "Tracking/Sim/GroupBy.h"
23#include "Tracking/Sim/Range.h"
25namespace ActsExamples {
31 constexpr Acts::GeometryIdentifier operator()(
32 Acts::GeometryIdentifier geometryId)
const {
36 constexpr Acts::GeometryIdentifier operator()(
37 Acts::GeometryIdentifier::Value encoded)
const {
38 return Acts::GeometryIdentifier(encoded);
42 constexpr Acts::GeometryIdentifier operator()(
43 const std::pair<Acts::GeometryIdentifier, T>& mapItem)
const {
48 inline auto operator()(
const T& thing)
const
49 ->
decltype(thing.geometryId(), Acts::GeometryIdentifier()) {
50 return thing.geometryId();
54 inline auto operator()(std::reference_wrapper<T> thing)
const
55 ->
decltype(thing.get().geometryId(), Acts::GeometryIdentifier()) {
56 return thing.get().geometryId();
62 using is_transparent = void;
64 template <
typename Left,
typename Right>
65 constexpr bool operator()(Left&& lhs, Right&& rhs)
const {
83using GeometryIdMultiset =
84 boost::container::flat_multiset<T, detail::CompareGeometryId>;
100using GeometryIdMultimap =
101 GeometryIdMultiset<std::pair<Acts::GeometryIdentifier, T>>;
106 const GeometryIdMultiset<T>& container,
107 Acts::GeometryIdentifier::Value volume) {
108 auto cmp = Acts::GeometryIdentifier().setVolume(volume);
109 auto beg = std::lower_bound(container.begin(), container.end(), cmp,
112 cmp = Acts::GeometryIdentifier().setVolume(volume + 1u);
118 return makeRange(beg, end);
123inline auto selectVolume(
const GeometryIdMultiset<T>& container,
124 Acts::GeometryIdentifier
id) {
125 return selectVolume(container,
id.volume());
130inline Range<typename GeometryIdMultiset<T>::const_iterator> selectLayer(
131 const GeometryIdMultiset<T>& container,
132 Acts::GeometryIdentifier::Value volume,
133 Acts::GeometryIdentifier::Value layer) {
134 auto cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer);
135 auto beg = std::lower_bound(container.begin(), container.end(), cmp,
136 detail::CompareGeometryId{});
138 cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer + 1u);
143 std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
144 return makeRange(beg, end);
149inline auto selectLayer(
const GeometryIdMultiset<T>& container,
150 Acts::GeometryIdentifier
id) {
151 return selectLayer(container,
id.volume(),
id.layer());
156inline Range<typename GeometryIdMultiset<T>::const_iterator> selectModule(
157 const GeometryIdMultiset<T>& container, Acts::GeometryIdentifier geoId) {
159 return makeRange(container.equal_range(geoId));
164inline auto selectModule(
const GeometryIdMultiset<T>& container,
165 Acts::GeometryIdentifier::Value volume,
166 Acts::GeometryIdentifier::Value layer,
167 Acts::GeometryIdentifier::Value module) {
170 Acts::GeometryIdentifier().setVolume(volume).setLayer(layer).setSensitive(
191inline Range<typename GeometryIdMultiset<T>::const_iterator>
192selectLowestNonZeroGeometryObject(
const GeometryIdMultiset<T>& container,
193 Acts::GeometryIdentifier geoId) {
194 assert((geoId.boundary() == 0u) and
"Boundary component must be zero");
195 assert((geoId.approach() == 0u) and
"Approach component must be zero");
197 if (geoId.sensitive() != 0u) {
198 return selectModule(container, geoId);
199 }
else if (geoId.layer() != 0u) {
200 return selectLayer(container, geoId);
201 }
else if (geoId.volume() != 0u) {
202 return selectVolume(container, geoId);
204 return makeRange(container.begin(), container.end());
210inline GroupBy<typename GeometryIdMultiset<T>::const_iterator,
211 detail::GeometryIdGetter>
212groupByModule(
const GeometryIdMultiset<T>& container) {
213 return makeGroupBy(container, detail::GeometryIdGetter());
222 using Container = GeometryIdMultiset<T>;
223 using Key = Acts::GeometryIdentifier;
224 using Value =
typename GeometryIdMultiset<T>::value_type;
225 using Iterator =
typename GeometryIdMultiset<T>::const_iterator;
228 const Container* container =
nullptr;
A wrapper around a pair of iterators to simplify range-based loops.
The accessor for the GeometryIdMultiset container.