Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:45

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/ProcessType.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::ProcessType process = ActsFatras::ProcessType::eUndefined;
0091   /// The incoming particles into the vertex
0092   SimBarcodeContainer incoming;
0093   /// The outgoing particles from the vertex
0094   SimBarcodeContainer outgoing;
0095 
0096   /// Construct the vertex from a position and optional process type.
0097   ///
0098   /// @param position4_ the vertex four-position
0099   /// @param process_ the process type that generated this vertex
0100   ///
0101   /// Associated particles are left empty by default and must be filled by the
0102   /// user after construction.
0103   SimVertex(
0104       SimVertexBarcode id_, const Acts::Vector4& position4_,
0105       ActsFatras::ProcessType process_ = ActsFatras::ProcessType::eUndefined)
0106       : id(id_), position4(position4_), process(process_) {}
0107   // explicitly default rule-of-five.
0108   SimVertex() = default;
0109   SimVertex(const SimVertex&) = default;
0110   SimVertex(SimVertex&&) = default;
0111   SimVertex& operator=(const SimVertex&) = default;
0112   SimVertex& operator=(SimVertex&&) = default;
0113 
0114   constexpr SimVertexBarcode vertexId() const { return id; }
0115   /// The vertex three-position.
0116   auto position() const { return position4.head<3>(); }
0117   /// The vertex time.
0118   double time() const { return position4[3]; }
0119 };
0120 
0121 namespace detail {
0122 struct CompareVertexId {
0123   using is_transparent = void;
0124   constexpr bool operator()(const SimVertex& lhs, const SimVertex& rhs) const {
0125     return lhs.vertexId() < rhs.vertexId();
0126   }
0127   constexpr bool operator()(SimVertexBarcode lhs, const SimVertex& rhs) const {
0128     return lhs < rhs.vertexId();
0129   }
0130   constexpr bool operator()(const SimVertex& lhs, SimVertexBarcode rhs) const {
0131     return lhs.vertexId() < rhs;
0132   }
0133 };
0134 }  // namespace detail
0135 
0136 /// Store vertices ordered by vertex identifier.
0137 using SimVertexContainer =
0138     ::boost::container::flat_set<SimVertex, detail::CompareVertexId>;
0139 
0140 }  // namespace ActsExamples
0141 
0142 // specialize std::hash so Barcode can be used e.g. in an unordered_map
0143 namespace std {
0144 template <>
0145 struct hash<ActsExamples::SimVertexBarcode> {
0146   auto operator()(ActsExamples::SimVertexBarcode barcode) const noexcept {
0147     return barcode.hash();
0148   }
0149 };
0150 }  // namespace std