Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:44

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