Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:32:31

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