Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-12 07:34:57

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/Definitions/Algebra.hpp"
0012 #include "ActsExamples/EventData/SimParticle.hpp"
0013 #include "ActsFatras/EventData/GenerationProcess.hpp"
0014 
0015 #include <boost/container/flat_set.hpp>
0016 
0017 namespace ActsExamples {
0018 
0019 class SimVertexBarcode {
0020  public:
0021   using PrimaryVertexId = SimBarcode::PrimaryVertexId;
0022   using SecondaryVertexId = SimBarcode::SecondaryVertexId;
0023   using ParticleId = SimBarcode::ParticleId;
0024   using GenerationId = SimBarcode::GenerationId;
0025   using SubParticleId = SimBarcode::SubParticleId;
0026 
0027   explicit constexpr SimVertexBarcode(SimBarcode barcode)
0028       : m_id(barcode.vertexId()) {}
0029 
0030   constexpr SimVertexBarcode() = default;
0031 
0032   /// Return the barcode.
0033   constexpr SimBarcode barcode() const { return m_id; }
0034 
0035   /// Return the primary vertex identifier.
0036   constexpr PrimaryVertexId vertexPrimary() const {
0037     return m_id.vertexPrimary();
0038   }
0039   /// Return the secondary vertex identifier.
0040   constexpr SecondaryVertexId vertexSecondary() const {
0041     return m_id.vertexSecondary();
0042   }
0043   /// Return the generation identifier.
0044   constexpr GenerationId generation() const { return m_id.generation(); }
0045 
0046   /// Create a new barcode with a different primary vertex identifier.
0047   [[nodiscard]]
0048   constexpr SimVertexBarcode withVertexPrimary(PrimaryVertexId id) const {
0049     return SimVertexBarcode(m_id.withVertexPrimary(id));
0050   }
0051   /// Create a new barcode with a different secondary vertex identifier.
0052   [[nodiscard]]
0053   constexpr SimVertexBarcode withVertexSecondary(SecondaryVertexId id) const {
0054     return SimVertexBarcode(m_id.withVertexSecondary(id));
0055   }
0056   /// Create a new barcode with a different generation identifier.
0057   [[nodiscard]]
0058   constexpr SimVertexBarcode withGeneration(GenerationId id) const {
0059     return SimVertexBarcode(m_id.withGeneration(id));
0060   }
0061 
0062   std::size_t hash() const { return m_id.hash(); }
0063 
0064  private:
0065   /// The vertex ID
0066   /// Note that only primary, secondary and generation should be set
0067   SimBarcode m_id;
0068 
0069   friend constexpr bool operator<(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0070     return lhs.m_id < rhs.m_id;
0071   }
0072 
0073   friend constexpr bool operator==(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0074     return lhs.m_id == rhs.m_id;
0075   }
0076 
0077   friend inline std::ostream& operator<<(std::ostream& os,
0078                                          SimVertexBarcode idx) {
0079     return os << idx.m_id;
0080   }
0081 };
0082 
0083 /// A simulated vertex e.g. from a physics process.
0084 struct SimVertex {
0085   /// The vertex ID
0086   SimVertexBarcode id = SimVertexBarcode(SimBarcode::Invalid());
0087   /// The vertex four-position
0088   Acts::Vector4 position4 = Acts::Vector4::Zero();
0089   /// The vertex process type
0090   ActsFatras::GenerationProcess process =
0091       ActsFatras::GenerationProcess::eUndefined;
0092   /// The incoming particles into the vertex
0093   SimBarcodeContainer incoming;
0094   /// The outgoing particles from the vertex
0095   SimBarcodeContainer outgoing;
0096 
0097   /// Construct the vertex from a position and optional process type.
0098   ///
0099   /// @param position4_ the vertex four-position
0100   /// @param process_ the process type that generated this vertex
0101   ///
0102   /// Associated particles are left empty by default and must be filled by the
0103   /// user after construction.
0104   SimVertex(SimVertexBarcode id_, const Acts::Vector4& position4_,
0105             ActsFatras::GenerationProcess process_ =
0106                 ActsFatras::GenerationProcess::eUndefined)
0107       : id(id_), position4(position4_), process(process_) {}
0108   // explicitly default rule-of-five.
0109   SimVertex() = default;
0110   SimVertex(const SimVertex&) = default;
0111   SimVertex(SimVertex&&) = default;
0112   SimVertex& operator=(const SimVertex&) = default;
0113   SimVertex& operator=(SimVertex&&) = default;
0114 
0115   constexpr SimVertexBarcode vertexId() const { return id; }
0116   /// The vertex three-position.
0117   auto position() const { return position4.head<3>(); }
0118   /// The vertex time.
0119   double time() const { return position4[3]; }
0120 };
0121 
0122 namespace detail {
0123 struct CompareVertexId {
0124   using is_transparent = void;
0125   constexpr bool operator()(const SimVertex& lhs, const SimVertex& rhs) const {
0126     return lhs.vertexId() < rhs.vertexId();
0127   }
0128   constexpr bool operator()(SimVertexBarcode lhs, const SimVertex& rhs) const {
0129     return lhs < rhs.vertexId();
0130   }
0131   constexpr bool operator()(const SimVertex& lhs, SimVertexBarcode rhs) const {
0132     return lhs.vertexId() < rhs;
0133   }
0134 };
0135 }  // namespace detail
0136 
0137 /// Store vertices ordered by vertex identifier.
0138 using SimVertexContainer =
0139     ::boost::container::flat_set<SimVertex, detail::CompareVertexId>;
0140 
0141 }  // namespace ActsExamples
0142 
0143 // specialize std::hash so Barcode can be used e.g. in an unordered_map
0144 namespace std {
0145 template <>
0146 struct hash<ActsExamples::SimVertexBarcode> {
0147   auto operator()(ActsExamples::SimVertexBarcode barcode) const noexcept {
0148     return barcode.hash();
0149   }
0150 };
0151 }  // namespace std