Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:27

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/optical/ParticleTrackView.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/math/ArraySoftUnit.hh"
0011 #include "geocel/Types.hh"
0012 #include "celeritas/Quantities.hh"
0013 
0014 #include "ParticleData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace optical
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Properties of a single particle track.
0023  */
0024 class ParticleTrackView
0025 {
0026   public:
0027     //!@{
0028     //! \name Type aliases
0029     using Energy = units::MevEnergy;
0030     //!@}
0031 
0032     //! Data for initializing a particle track
0033     struct Initializer
0034     {
0035         Energy energy;
0036         Real3 polarization{0, 0, 0};
0037     };
0038 
0039   public:
0040     inline CELER_FUNCTION
0041     ParticleTrackView(NativeRef<ParticleStateData> const&, TrackSlotId);
0042 
0043     // Initialize the particle
0044     inline CELER_FUNCTION ParticleTrackView& operator=(Initializer const&);
0045 
0046     // Access the kinetic energy [MeV]
0047     CELER_FORCEINLINE_FUNCTION Energy energy() const;
0048 
0049     // Access the polarization
0050     CELER_FORCEINLINE_FUNCTION Real3 const& polarization() const;
0051 
0052     // Change the particle's energy [MeV]
0053     inline CELER_FUNCTION void energy(Energy);
0054 
0055     // Change the particle's polarization
0056     inline CELER_FUNCTION void polarization(Real3 const&);
0057 
0058   private:
0059     NativeRef<ParticleStateData> const& states_;
0060     TrackSlotId track_slot_;
0061 };
0062 
0063 //---------------------------------------------------------------------------//
0064 // INLINE DEFINITIONS
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Construct from dynamic particle properties.
0068  */
0069 CELER_FUNCTION
0070 ParticleTrackView::ParticleTrackView(NativeRef<ParticleStateData> const& states,
0071                                      TrackSlotId tid)
0072     : states_(states), track_slot_(tid)
0073 {
0074     CELER_EXPECT(track_slot_ < states_.size());
0075 }
0076 
0077 //---------------------------------------------------------------------------//
0078 /*!
0079  * Initialize the particle.
0080  */
0081 CELER_FUNCTION ParticleTrackView&
0082 ParticleTrackView::operator=(Initializer const& init)
0083 {
0084     CELER_EXPECT(init.energy >= zero_quantity());
0085     states_.energy[track_slot_] = value_as<Energy>(init.energy);
0086     states_.polarization[track_slot_] = init.polarization;
0087     return *this;
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 /*!
0092  * Access the kinetic energy [MeV].
0093  */
0094 CELER_FUNCTION auto ParticleTrackView::energy() const -> Energy
0095 {
0096     return Energy{states_.energy[track_slot_]};
0097 }
0098 
0099 //---------------------------------------------------------------------------//
0100 /*!
0101  * Access the polarization.
0102  */
0103 CELER_FUNCTION Real3 const& ParticleTrackView::polarization() const
0104 {
0105     return states_.polarization[track_slot_];
0106 }
0107 
0108 //---------------------------------------------------------------------------//
0109 /*!
0110  * Change the particle's kinetic energy.
0111  */
0112 CELER_FUNCTION
0113 void ParticleTrackView::energy(Energy energy)
0114 {
0115     CELER_EXPECT(energy >= zero_quantity());
0116     states_.energy[track_slot_] = value_as<Energy>(energy);
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 /*!
0121  * Change the particle's polarization.
0122  */
0123 CELER_FUNCTION
0124 void ParticleTrackView::polarization(Real3 const& polarization)
0125 {
0126     CELER_EXPECT(is_soft_unit_vector(polarization));
0127     states_.polarization[track_slot_] = polarization;
0128 }
0129 
0130 //---------------------------------------------------------------------------//
0131 }  // namespace optical
0132 }  // namespace celeritas