Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 "Acts/EventData/SourceLink.hpp"
0012 #include "Acts/Geometry/TrackingGeometry.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "ActsExamples/EventData/GeometryContainers.hpp"
0015 #include "ActsExamples/EventData/Index.hpp"
0016 
0017 #include <cassert>
0018 
0019 namespace ActsExamples {
0020 
0021 /// A source link that stores just an index.
0022 ///
0023 /// This is intentionally kept as barebones as possible. The source link
0024 /// is just a reference and will be copied, moved around, etc. often.
0025 /// Keeping it small and separate from the actual, potentially large,
0026 /// measurement data should result in better overall performance.
0027 /// Using an index instead of e.g. a pointer, means source link and
0028 /// measurement are decoupled and the measurement representation can be
0029 /// easily changed without having to also change the source link.
0030 class IndexSourceLink final {
0031  public:
0032   /// Construct from geometry identifier and index.
0033   constexpr IndexSourceLink(Acts::GeometryIdentifier gid, Index idx)
0034       : m_geometryId(gid), m_index(idx) {}
0035 
0036   // Construct an invalid source link. Must be default constructible to
0037   /// satisfy SourceLinkConcept.
0038   IndexSourceLink() = default;
0039   IndexSourceLink(const IndexSourceLink&) = default;
0040   IndexSourceLink(IndexSourceLink&&) = default;
0041   IndexSourceLink& operator=(const IndexSourceLink&) = default;
0042   IndexSourceLink& operator=(IndexSourceLink&&) = default;
0043 
0044   /// Access the index.
0045   constexpr Index index() const { return m_index; }
0046 
0047   Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
0048 
0049   struct SurfaceAccessor {
0050     const Acts::TrackingGeometry& trackingGeometry;
0051 
0052     const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
0053       const auto& indexSourceLink = sourceLink.get<IndexSourceLink>();
0054       return trackingGeometry.findSurface(indexSourceLink.geometryId());
0055     }
0056   };
0057 
0058  private:
0059   Acts::GeometryIdentifier m_geometryId;
0060   Index m_index = 0;
0061 
0062   friend bool operator==(const IndexSourceLink& lhs,
0063                          const IndexSourceLink& rhs) {
0064     return (lhs.geometryId() == rhs.geometryId()) &&
0065            (lhs.m_index == rhs.m_index);
0066   }
0067   friend bool operator!=(const IndexSourceLink& lhs,
0068                          const IndexSourceLink& rhs) {
0069     return !(lhs == rhs);
0070   }
0071 };
0072 
0073 /// Container of index source links.
0074 ///
0075 /// Since the source links provide a `.geometryId()` accessor, they can be
0076 /// stored in an ordered geometry container.
0077 using IndexSourceLinkContainer = GeometryIdMultiset<IndexSourceLink>;
0078 /// Accessor for the above source link container
0079 ///
0080 /// It wraps up a few lookup methods to be used in the Combinatorial Kalman
0081 /// Filter
0082 struct IndexSourceLinkAccessor : GeometryIdMultisetAccessor<IndexSourceLink> {
0083   using BaseIterator = GeometryIdMultisetAccessor<IndexSourceLink>::Iterator;
0084 
0085   using Iterator = Acts::SourceLinkAdapterIterator<BaseIterator>;
0086 
0087   // get the range of elements with requested geoId
0088   std::pair<Iterator, Iterator> range(const Acts::Surface& surface) const {
0089     assert(container != nullptr);
0090     auto [begin, end] = container->equal_range(surface.geometryId());
0091     return {Iterator{begin}, Iterator{end}};
0092   }
0093 };
0094 }  // namespace ActsExamples