Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:26

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/phys/ParticleView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "ParticleData.hh"
0010 
0011 namespace celeritas
0012 {
0013 //---------------------------------------------------------------------------//
0014 /*!
0015  * Access invariant particle data.
0016  *
0017  * A \c ParticleView can be used to access properties of a single particle
0018  * type, e.g. electron or photon.
0019  */
0020 class ParticleView
0021 {
0022   public:
0023     //!@{
0024     //! \name Type aliases
0025     using ParticleParamsRef = NativeCRef<ParticleParamsData>;
0026     //!@}
0027 
0028   public:
0029     // Construct from "static" particle definitions
0030     inline CELER_FUNCTION ParticleView(ParticleParamsRef const&, ParticleId);
0031 
0032     // Unique particle type identifier
0033     CELER_FORCEINLINE_FUNCTION ParticleId particle_id() const;
0034 
0035     // Rest mass [MeV / c^2]
0036     CELER_FORCEINLINE_FUNCTION units::MevMass mass() const;
0037 
0038     // Charge [elemental charge e+]
0039     CELER_FORCEINLINE_FUNCTION units::ElementaryCharge charge() const;
0040 
0041     // Decay constant [1/s]
0042     CELER_FORCEINLINE_FUNCTION real_type decay_constant() const;
0043 
0044     // Whether it is an antiparticle
0045     CELER_FORCEINLINE_FUNCTION bool is_antiparticle() const;
0046 
0047   private:
0048     ParticleParamsRef const& params_;
0049     ParticleId const particle_;
0050 };
0051 
0052 //---------------------------------------------------------------------------//
0053 // INLINE DEFINITIONS
0054 //---------------------------------------------------------------------------//
0055 /*!
0056  * Construct from "static" particle definitions.
0057  */
0058 CELER_FUNCTION
0059 ParticleView::ParticleView(ParticleParamsRef const& params, ParticleId id)
0060     : params_(params), particle_(id)
0061 {
0062     CELER_EXPECT(particle_ < params_.size());
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Unique particle type identifier.
0068  */
0069 CELER_FUNCTION ParticleId ParticleView::particle_id() const
0070 {
0071     return particle_;
0072 }
0073 
0074 //---------------------------------------------------------------------------//
0075 /*!
0076  * Rest mass [MeV / c^2].
0077  */
0078 CELER_FUNCTION units::MevMass ParticleView::mass() const
0079 {
0080     return params_.mass[particle_];
0081 }
0082 
0083 //---------------------------------------------------------------------------//
0084 /*!
0085  * Elementary charge.
0086  */
0087 CELER_FUNCTION units::ElementaryCharge ParticleView::charge() const
0088 {
0089     return params_.charge[particle_];
0090 }
0091 
0092 //---------------------------------------------------------------------------//
0093 /*!
0094  * Decay constant.
0095  */
0096 CELER_FUNCTION real_type ParticleView::decay_constant() const
0097 {
0098     return params_.decay_constant[particle_];
0099 }
0100 
0101 //---------------------------------------------------------------------------//
0102 /*!
0103  * Whether it is an antiparticle.
0104  */
0105 CELER_FUNCTION bool ParticleView::is_antiparticle() const
0106 {
0107     return params_.matter[particle_] == MatterType::antiparticle;
0108 }
0109 
0110 //---------------------------------------------------------------------------//
0111 }  // namespace celeritas