Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-04 09:23:09

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 "Acts/Definitions/Common.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "ActsFatras/EventData/Barcode.hpp"
0015 
0016 #include <cstdint>
0017 
0018 namespace ActsFatras {
0019 
0020 /// A simulation hit on a surface.
0021 ///
0022 /// This is the undigitized, truth hit, i.e. just a recording of the particle
0023 /// state at the surface intersection. Since Fatras is surface-based, the hit
0024 /// position is always constrained to a surface. Depending on the simulated
0025 /// interactions the momentum state before and after might differ and is
0026 /// thus stored as two separate four-vectors.
0027 class Hit {
0028  public:
0029   /// Construct default hit with (mostly) invalid information.
0030   Hit() = default;
0031   /// Construct from four-position and four-momenta.
0032   ///
0033   /// @param geometryId      Geometry identifier of the surface
0034   /// @param particleId Particle identifier of the particle that created the hit
0035   /// @param pos4       Particle space-time four-vector on the surface
0036   /// @param before4    Particle four-momentum before the interaction
0037   /// @param after4     Particle four-momentum after the interaction
0038   /// @param index_     Hit index along the particle trajectory
0039   ///
0040   /// All quantities are given in the global coordinate system. It is the
0041   /// users responsibility to ensure that the position correspond to a
0042   /// position on the given surface.
0043   Hit(Acts::GeometryIdentifier geometryId, Barcode particleId,
0044       const Acts::Vector4& pos4, const Acts::Vector4& before4,
0045       const Acts::Vector4& after4, std::int32_t index_ = -1)
0046       : m_geometryId(geometryId),
0047         m_particleId(particleId),
0048         m_index(index_),
0049         m_pos4(pos4),
0050         m_before4(before4),
0051         m_after4(after4) {}
0052   /// Copy constructor
0053   Hit(const Hit&) = default;
0054   /// Move constructor
0055   Hit(Hit&&) = default;
0056   /// Copy assignment operator
0057   /// @return Reference to this hit after copying
0058   Hit& operator=(const Hit&) = default;
0059   /// Move assignment operator
0060   /// @return Reference to this hit after moving
0061   Hit& operator=(Hit&&) = default;
0062 
0063   /// Geometry identifier of the hit surface.
0064   /// @return GeometryIdentifier of the surface where the hit occurred
0065   constexpr Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
0066   /// Particle identifier of the particle that generated the hit.
0067   /// @return Barcode identifier of the particle that created this hit
0068   constexpr Barcode particleId() const { return m_particleId; }
0069   /// Hit index along the particle trajectory.
0070   ///
0071   /// @retval negative if the hit index is undefined.
0072   constexpr std::int32_t index() const { return m_index; }
0073 
0074   /// Space-time position four-vector.
0075   /// @return Reference to four-vector containing position and time coordinates
0076   const Acts::Vector4& fourPosition() const { return m_pos4; }
0077   /// Three-position, i.e. spatial coordinates without the time.
0078   /// @return Three-dimensional position vector (x,y,z)
0079   auto position() const { return m_pos4.segment<3>(Acts::ePos0); }
0080   /// Time coordinate.
0081   /// @return Time of the hit occurrence
0082   double time() const { return m_pos4[Acts::eTime]; }
0083 
0084   /// Particle four-momentum before the hit.
0085   /// @return Reference to four-momentum vector before interaction
0086   const Acts::Vector4& momentum4Before() const { return m_before4; }
0087   /// Particle four-momentum after the hit.
0088   /// @return Reference to four-momentum vector after interaction
0089   const Acts::Vector4& momentum4After() const { return m_after4; }
0090   /// Normalized particle direction vector before the hit.
0091   /// @return Normalized three-dimensional direction vector before interaction
0092   Acts::Vector3 directionBefore() const {
0093     return m_before4.segment<3>(Acts::eMom0).normalized();
0094   }
0095   /// Normalized particle direction vector the hit.
0096   /// @return Normalized three-dimensional direction vector after interaction
0097   Acts::Vector3 directionAfter() const {
0098     return m_after4.segment<3>(Acts::eMom0).normalized();
0099   }
0100   /// Average normalized particle direction vector through the surface.
0101   /// @return Average normalized direction vector of particle momentum before and after
0102   Acts::Vector3 direction() const {
0103     auto dir0 = m_before4.segment<3>(Acts::eMom0).normalized();
0104     auto dir1 = m_after4.segment<3>(Acts::eMom0).normalized();
0105     return ((dir0 + dir1) / 2.).segment<3>(Acts::eMom0).normalized();
0106   }
0107   /// Energy deposited by the hit.
0108   ///
0109   /// @retval positive if the particle lost energy when it passed the surface
0110   /// @retval negative if magic was involved
0111   double depositedEnergy() const {
0112     return m_before4[Acts::eEnergy] - m_after4[Acts::eEnergy];
0113   }
0114 
0115  private:
0116   /// Identifier of the surface.
0117   Acts::GeometryIdentifier m_geometryId;
0118   /// Identifier of the generating particle.
0119   Barcode m_particleId;
0120   /// Index of the hit along the particle trajectory.
0121   std::int32_t m_index = -1;
0122   /// Global space-time position four-vector.
0123   Acts::Vector4 m_pos4 = Acts::Vector4::Zero();
0124   /// Global particle energy-momentum four-vector before the hit.
0125   Acts::Vector4 m_before4 = Acts::Vector4::Zero();
0126   /// Global particle energy-momentum four-vector after the hit.
0127   Acts::Vector4 m_after4 = Acts::Vector4::Zero();
0128 };
0129 
0130 }  // namespace ActsFatras