Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-02 09:19:52

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   /// Set the primary vertex identifier.
0047   [[deprecated("Use withVertexPrimary() instead")]]
0048   constexpr SimVertexBarcode setVertexPrimary(PrimaryVertexId id) {
0049     m_id = m_id.withVertexPrimary(id);
0050     return *this;
0051   }
0052   /// Set the secondary vertex identifier.
0053   [[deprecated("Use withVertexSecondary() instead")]]
0054   constexpr SimVertexBarcode setVertexSecondary(SecondaryVertexId id) {
0055     m_id = m_id.withVertexSecondary(id);
0056     return *this;
0057   }
0058   /// Set the particle identifier.
0059   [[deprecated("Use withGeneration() instead")]]
0060   constexpr SimVertexBarcode setGeneration(GenerationId id) {
0061     m_id = m_id.withGeneration(id);
0062     return *this;
0063   }
0064 
0065   /// Create a new barcode with a different primary vertex identifier.
0066   [[nodiscard]]
0067   constexpr SimVertexBarcode withVertexPrimary(PrimaryVertexId id) const {
0068     return SimVertexBarcode(m_id.withVertexPrimary(id));
0069   }
0070   /// Create a new barcode with a different secondary vertex identifier.
0071   [[nodiscard]]
0072   constexpr SimVertexBarcode withVertexSecondary(SecondaryVertexId id) const {
0073     return SimVertexBarcode(m_id.withVertexSecondary(id));
0074   }
0075   /// Create a new barcode with a different generation identifier.
0076   [[nodiscard]]
0077   constexpr SimVertexBarcode withGeneration(GenerationId id) const {
0078     return SimVertexBarcode(m_id.withGeneration(id));
0079   }
0080 
0081   std::size_t hash() const { return m_id.hash(); }
0082 
0083  private:
0084   /// The vertex ID
0085   /// Note that only primary, secondary and generation should be set
0086   SimBarcode m_id;
0087 
0088   friend constexpr bool operator<(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0089     return lhs.m_id < rhs.m_id;
0090   }
0091 
0092   friend constexpr bool operator==(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0093     return lhs.m_id == rhs.m_id;
0094   }
0095 
0096   friend inline std::ostream& operator<<(std::ostream& os,
0097                                          SimVertexBarcode idx) {
0098     return os << idx.m_id;
0099   }
0100 };
0101 
0102 /// A simulated vertex e.g. from a physics process.
0103 struct SimVertex {
0104   /// The vertex ID
0105   SimVertexBarcode id = SimVertexBarcode(SimBarcode::Invalid());
0106   /// The vertex four-position
0107   Acts::Vector4 position4 = Acts::Vector4::Zero();
0108   /// The vertex process type
0109   ActsFatras::ProcessType process = ActsFatras::ProcessType::eUndefined;
0110   /// The incoming particles into the vertex
0111   SimBarcodeContainer incoming;
0112   /// The outgoing particles from the vertex
0113   SimBarcodeContainer outgoing;
0114 
0115   /// Construct the vertex from a position and optional process type.
0116   ///
0117   /// @param position4_ the vertex four-position
0118   /// @param process_ the process type that generated this vertex
0119   ///
0120   /// Associated particles are left empty by default and must be filled by the
0121   /// user after construction.
0122   SimVertex(
0123       SimVertexBarcode id_, const Acts::Vector4& position4_,
0124       ActsFatras::ProcessType process_ = ActsFatras::ProcessType::eUndefined)
0125       : id(id_), position4(position4_), process(process_) {}
0126   // explicitly default rule-of-five.
0127   SimVertex() = default;
0128   SimVertex(const SimVertex&) = default;
0129   SimVertex(SimVertex&&) = default;
0130   SimVertex& operator=(const SimVertex&) = default;
0131   SimVertex& operator=(SimVertex&&) = default;
0132 
0133   constexpr SimVertexBarcode vertexId() const { return id; }
0134   /// The vertex three-position.
0135   auto position() const { return position4.head<3>(); }
0136   /// The vertex time.
0137   double time() const { return position4[3]; }
0138 };
0139 
0140 namespace detail {
0141 struct CompareVertexId {
0142   using is_transparent = void;
0143   constexpr bool operator()(const SimVertex& lhs, const SimVertex& rhs) const {
0144     return lhs.vertexId() < rhs.vertexId();
0145   }
0146   constexpr bool operator()(SimVertexBarcode lhs, const SimVertex& rhs) const {
0147     return lhs < rhs.vertexId();
0148   }
0149   constexpr bool operator()(const SimVertex& lhs, SimVertexBarcode rhs) const {
0150     return lhs.vertexId() < rhs;
0151   }
0152 };
0153 }  // namespace detail
0154 
0155 /// Store vertices ordered by vertex identifier.
0156 using SimVertexContainer =
0157     ::boost::container::flat_set<SimVertex, detail::CompareVertexId>;
0158 
0159 }  // namespace ActsExamples
0160 
0161 // specialize std::hash so Barcode can be used e.g. in an unordered_map
0162 namespace std {
0163 template <>
0164 struct hash<ActsExamples::SimVertexBarcode> {
0165   auto operator()(ActsExamples::SimVertexBarcode barcode) const noexcept {
0166     return barcode.hash();
0167   }
0168 };
0169 }  // namespace std