Back to home page

EIC code displayed by LXR

 
 

    


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

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 Value = SimBarcode::Value;
0022 
0023   constexpr SimVertexBarcode() = default;
0024   explicit constexpr SimVertexBarcode(Value encoded)
0025       : m_id(SimBarcode(encoded)) {}
0026   explicit constexpr SimVertexBarcode(SimBarcode vertexId)
0027       : m_id(vertexId.setParticle(0).setSubParticle(0)) {
0028     if (vertexId != vertexId.vertexId()) {
0029       throw std::invalid_argument("SimVertexBarcode: invalid vertexId");
0030     }
0031   }
0032 
0033   /// Get the encoded value of all index levels.
0034   constexpr Value value() const { return m_id.value(); }
0035 
0036   /// Return the barcode.
0037   constexpr SimBarcode barcode() const { return m_id; }
0038 
0039   /// Return the primary vertex identifier.
0040   constexpr Value vertexPrimary() const { return m_id.vertexPrimary(); }
0041   /// Return the secondary vertex identifier.
0042   constexpr Value vertexSecondary() const { return m_id.vertexSecondary(); }
0043   /// Return the generation identifier.
0044   constexpr Value generation() const { return m_id.generation(); }
0045 
0046   /// Set the primary vertex identifier.
0047   constexpr SimVertexBarcode& setVertexPrimary(Value id) {
0048     return m_id.setVertexPrimary(id), *this;
0049   }
0050   /// Set the secondary vertex identifier.
0051   constexpr SimVertexBarcode& setVertexSecondary(Value id) {
0052     return m_id.setVertexSecondary(id), *this;
0053   }
0054   /// Set the particle identifier.
0055   constexpr SimVertexBarcode& setGeneration(Value id) {
0056     return m_id.setGeneration(id), *this;
0057   }
0058 
0059  private:
0060   /// The vertex ID
0061   /// Note that only primary, secondary and generation should be set
0062   SimBarcode m_id = 0;
0063 
0064   friend constexpr bool operator<(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0065     return lhs.m_id < rhs.m_id;
0066   }
0067 
0068   friend constexpr bool operator==(SimVertexBarcode lhs, SimVertexBarcode rhs) {
0069     return lhs.m_id == rhs.m_id;
0070   }
0071 
0072   friend inline std::ostream& operator<<(std::ostream& os,
0073                                          SimVertexBarcode idx) {
0074     return os << idx.m_id;
0075   }
0076 };
0077 
0078 /// A simulated vertex e.g. from a physics process.
0079 struct SimVertex {
0080   /// The vertex ID
0081   SimVertexBarcode id;
0082   /// The vertex four-position
0083   Acts::Vector4 position4 = Acts::Vector4::Zero();
0084   /// The vertex process type
0085   ActsFatras::ProcessType process = ActsFatras::ProcessType::eUndefined;
0086   /// The incoming particles into the vertex
0087   SimBarcodeContainer incoming;
0088   /// The outgoing particles from the vertex
0089   SimBarcodeContainer outgoing;
0090 
0091   /// Construct the vertex from a position and optional process type.
0092   ///
0093   /// @param position4_ the vertex four-position
0094   /// @param process_ the process type that generated this vertex
0095   ///
0096   /// Associated particles are left empty by default and must be filled by the
0097   /// user after construction.
0098   SimVertex(
0099       SimVertexBarcode id_, const Acts::Vector4& position4_,
0100       ActsFatras::ProcessType process_ = ActsFatras::ProcessType::eUndefined)
0101       : id(id_), position4(position4_), process(process_) {}
0102   // explicitly default rule-of-five.
0103   SimVertex() = default;
0104   SimVertex(const SimVertex&) = default;
0105   SimVertex(SimVertex&&) = default;
0106   SimVertex& operator=(const SimVertex&) = default;
0107   SimVertex& operator=(SimVertex&&) = default;
0108 
0109   constexpr SimVertexBarcode vertexId() const { return id; }
0110   /// The vertex three-position.
0111   auto position() const { return position4.head<3>(); }
0112   /// The vertex time.
0113   double time() const { return position4[3]; }
0114 };
0115 
0116 namespace detail {
0117 struct CompareVertexId {
0118   using is_transparent = void;
0119   constexpr bool operator()(const SimVertex& lhs, const SimVertex& rhs) const {
0120     return lhs.vertexId() < rhs.vertexId();
0121   }
0122   constexpr bool operator()(SimVertexBarcode lhs, const SimVertex& rhs) const {
0123     return lhs < rhs.vertexId();
0124   }
0125   constexpr bool operator()(const SimVertex& lhs, SimVertexBarcode rhs) const {
0126     return lhs.vertexId() < rhs;
0127   }
0128 };
0129 }  // namespace detail
0130 
0131 /// Store vertices ordered by vertex identifier.
0132 using SimVertexContainer =
0133     ::boost::container::flat_set<SimVertex, detail::CompareVertexId>;
0134 
0135 }  // namespace ActsExamples