Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:46

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