Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:48

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/ParticleData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/Collection.hh"
0011 #include "corecel/data/CollectionBuilder.hh"
0012 #include "corecel/sys/ThreadId.hh"
0013 #include "celeritas/Quantities.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 // PARAMS
0020 //---------------------------------------------------------------------------//
0021 
0022 enum class MatterType : char
0023 {
0024     particle,
0025     antiparticle
0026 };
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Access particle definitions on the device.
0031  *
0032  * Fundamental (static) properties of a particle type. Physical state of a
0033  * particle (kinetic energy, ...) is part of a ParticleState. This view is
0034  * created from \c ParticleParams. The size of the \c defs data member is the
0035  * number of particle types (accessed by \c ParticleId).
0036  *
0037  * \sa ParticleParams (owns the pointed-to data)
0038  * \sa ParticleTrackView (uses the pointed-to data in a kernel)
0039  */
0040 template<Ownership W, MemSpace M>
0041 struct ParticleParamsData
0042 {
0043     //// TYPES ////
0044 
0045     template<class T>
0046     using Items = Collection<T, W, M, ParticleId>;
0047 
0048     //// DATA ////
0049 
0050     Items<units::MevMass> mass;  //!< Rest mass [MeV / c^2]
0051     Items<units::ElementaryCharge> charge;  //!< Charge in units of [e]
0052     Items<real_type> decay_constant;  //!< Decay constant [1/s]
0053     Items<MatterType> matter;  //!< Antiparticle flag (negative PDG number)
0054 
0055     //// METHODS ////
0056 
0057     //! Whether the data is assigned
0058     explicit CELER_FUNCTION operator bool() const
0059     {
0060         return !mass.empty() && !charge.empty() && !decay_constant.empty()
0061                && !matter.empty();
0062     }
0063 
0064     //! Number of particles
0065     CELER_FUNCTION ParticleId::size_type size() const
0066     {
0067         return decay_constant.size();
0068     }
0069 
0070     //! Assign from another set of data
0071     template<Ownership W2, MemSpace M2>
0072     ParticleParamsData& operator=(ParticleParamsData<W2, M2> const& other)
0073     {
0074         CELER_EXPECT(other);
0075         mass = other.mass;
0076         charge = other.charge;
0077         decay_constant = other.decay_constant;
0078         matter = other.matter;
0079         return *this;
0080     }
0081 };
0082 
0083 //---------------------------------------------------------------------------//
0084 // STATE
0085 //---------------------------------------------------------------------------//
0086 /*!
0087  * Physical (dynamic) state of a particle track.
0088  *
0089  * The "physical state" is just about what differentiates this particle from
0090  * another (type, energy, polarization, ...) in the lab's inertial reference
0091  * frame. It does not include information about the particle's direction or
0092  * position, nor about path lengths or collisions.
0093  *
0094  * The energy is with respect to the lab frame. The particle state is
0095  * immutable: collisions and other interactions should return changes to the
0096  * particle state.
0097  */
0098 
0099 struct ParticleTrackInitializer
0100 {
0101     ParticleId particle_id;  //!< Type of particle (electron, gamma, ...)
0102     units::MevEnergy energy;  //!< Kinetic energy [MeV]
0103 
0104     //! True if assigned and valid
0105     explicit CELER_FUNCTION operator bool() const
0106     {
0107         return particle_id && energy > zero_quantity();
0108     }
0109 };
0110 
0111 //---------------------------------------------------------------------------//
0112 /*!
0113  * Data storage/access for particle properties.
0114  *
0115  * \sa ParticleTrackView (uses the pointed-to data in a kernel)
0116  */
0117 template<Ownership W, MemSpace M>
0118 struct ParticleStateData
0119 {
0120     //// TYPES ////
0121 
0122     template<class T>
0123     using Items = celeritas::StateCollection<T, W, M>;
0124 
0125     //// DATA ////
0126 
0127     Items<ParticleId> particle_id;  //!< Type of particle (electron, gamma,
0128                                     //!< ...)
0129     Items<real_type> particle_energy;  //!< Kinetic energy [MeV]
0130 
0131     //// METHODS ////
0132 
0133     //! Whether the interface is assigned
0134     explicit CELER_FUNCTION operator bool() const
0135     {
0136         return !particle_id.empty() && !particle_energy.empty();
0137     }
0138 
0139     //! State size
0140     CELER_FUNCTION TrackSlotId::size_type size() const
0141     {
0142         return particle_id.size();
0143     }
0144 
0145     //! Assign from another set of data
0146     template<Ownership W2, MemSpace M2>
0147     ParticleStateData& operator=(ParticleStateData<W2, M2>& other)
0148     {
0149         CELER_EXPECT(other);
0150         particle_id = other.particle_id;
0151         particle_energy = other.particle_energy;
0152         return *this;
0153     }
0154 };
0155 
0156 //---------------------------------------------------------------------------//
0157 /*!
0158  * Resize particle states in host code.
0159  */
0160 template<MemSpace M>
0161 inline void resize(ParticleStateData<Ownership::value, M>* data,
0162                    HostCRef<ParticleParamsData> const&,
0163                    size_type size)
0164 {
0165     CELER_EXPECT(size > 0);
0166     resize(&data->particle_id, size);
0167     resize(&data->particle_energy, size);
0168 }
0169 
0170 //---------------------------------------------------------------------------//
0171 }  // namespace celeritas