Back to home page

EIC code displayed by LXR

 
 

    


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

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/CutoffView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "CutoffData.hh"
0010 #include "Secondary.hh"
0011 
0012 namespace celeritas
0013 {
0014 //---------------------------------------------------------------------------//
0015 /*!
0016  * Access invariant material- and particle-dependent cutoff values.
0017  *
0018  * \c CutoffParamsData is defined in \c CutoffData.hh and constructed by
0019  * \c CutoffParams .
0020  *
0021  * \code
0022  * CutoffParams cutoffs(input);
0023  * CutoffView cutoff_view(cutoffs.host_ref(), material_id);
0024  * cutoff_view.energy(particle_id);
0025  * cutoff_view.range(particle_id);
0026  * \endcode
0027  */
0028 class CutoffView
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using CutoffId = OpaqueId<ParticleCutoff>;
0034     using CutoffData = NativeCRef<CutoffParamsData>;
0035     using Energy = units::MevEnergy;
0036     //!@}
0037 
0038   public:
0039     // Construct for the given particle and material ids
0040     inline CELER_FUNCTION
0041     CutoffView(CutoffData const& params, PhysMatId material);
0042 
0043     // Return energy cutoff value
0044     inline CELER_FUNCTION Energy energy(ParticleId particle) const;
0045 
0046     // Return range cutoff value
0047     inline CELER_FUNCTION real_type range(ParticleId particle) const;
0048 
0049     // Whether to kill secondaries below the production cut post-interaction
0050     inline CELER_FUNCTION bool apply_post_interaction() const;
0051 
0052     // Whether the post-interaction cutoff should be applied to the secondary
0053     inline CELER_FUNCTION bool apply(Secondary const&) const;
0054 
0055   private:
0056     CutoffData const& params_;
0057     PhysMatId material_;
0058 
0059     //// HELPER FUNCTIONS ////
0060 
0061     // Get the cutoff for the given particle and material
0062     CELER_FORCEINLINE_FUNCTION ParticleCutoff get(ParticleId particle) const;
0063 };
0064 
0065 //---------------------------------------------------------------------------//
0066 // INLINE DEFINITIONS
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Construct view from host/device for the given material id.
0070  */
0071 CELER_FUNCTION
0072 CutoffView::CutoffView(CutoffData const& params, PhysMatId material)
0073     : params_(params), material_(material)
0074 {
0075     CELER_EXPECT(params_);
0076     CELER_EXPECT(material_ < params_.num_materials);
0077 }
0078 
0079 //---------------------------------------------------------------------------//
0080 /*!
0081  * Return energy cutoff value.
0082  */
0083 CELER_FUNCTION auto CutoffView::energy(ParticleId particle) const -> Energy
0084 {
0085     return this->get(particle).energy;
0086 }
0087 
0088 //---------------------------------------------------------------------------//
0089 /*!
0090  * Return range cutoff value.
0091  */
0092 CELER_FUNCTION real_type CutoffView::range(ParticleId particle) const
0093 {
0094     return this->get(particle).range;
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Whether to kill secondaries below the production cut post-interaction.
0100  */
0101 CELER_FUNCTION bool CutoffView::apply_post_interaction() const
0102 {
0103     return params_.apply_post_interaction;
0104 }
0105 
0106 //---------------------------------------------------------------------------//
0107 /*!
0108  * Whether the post-interaction cutoff should be applied to the secondary.
0109  *
0110  * This will be true if the \c apply_post_interaction option is enabled and the
0111  * seccondary is an electron, positron, or gamma with energy below the
0112  * production cut.
0113  */
0114 CELER_FUNCTION bool CutoffView::apply(Secondary const& secondary) const
0115 {
0116     return (secondary.particle_id == params_.ids.gamma
0117             || secondary.particle_id == params_.ids.electron
0118             || secondary.particle_id == params_.ids.positron)
0119            && secondary.energy < this->energy(secondary.particle_id);
0120 }
0121 
0122 //---------------------------------------------------------------------------//
0123 /*!
0124  * Get the cutoff for the given particle and material.
0125  */
0126 CELER_FUNCTION ParticleCutoff CutoffView::get(ParticleId particle) const
0127 {
0128     CELER_EXPECT(particle < params_.id_to_index.size());
0129     CELER_EXPECT(params_.id_to_index[particle] < params_.num_particles);
0130     CutoffId id{params_.num_materials * params_.id_to_index[particle]
0131                 + material_.get()};
0132     CELER_ENSURE(id < params_.cutoffs.size());
0133     return params_.cutoffs[id];
0134 }
0135 
0136 //---------------------------------------------------------------------------//
0137 }  // namespace celeritas