Back to home page

EIC code displayed by LXR

 
 

    


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

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/em/interactor/SeltzerBergerInteractor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/StackAllocator.hh"
0011 #include "corecel/math/ArrayUtils.hh"
0012 #include "celeritas/Constants.hh"
0013 #include "celeritas/Quantities.hh"
0014 #include "celeritas/Types.hh"
0015 #include "celeritas/em/data/SeltzerBergerData.hh"
0016 #include "celeritas/em/distribution/TsaiUrbanDistribution.hh"
0017 #include "celeritas/mat/ElementView.hh"
0018 #include "celeritas/mat/MaterialView.hh"
0019 #include "celeritas/phys/CutoffView.hh"
0020 #include "celeritas/phys/Interaction.hh"
0021 #include "celeritas/phys/ParticleTrackView.hh"
0022 #include "celeritas/phys/Secondary.hh"
0023 
0024 #include "detail/BremFinalStateHelper.hh"
0025 #include "detail/PhysicsConstants.hh"
0026 #include "detail/SBEnergySampler.hh"
0027 
0028 namespace celeritas
0029 {
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Seltzer-Berger model for electron and positron bremsstrahlung processes.
0033  *
0034  * Given an incoming electron or positron of sufficient energy (as per
0035  * CutOffView), this class provides the energy loss of these particles due to
0036  * radiation of photons in the field of a nucleus. This model improves accuracy
0037  * using cross sections based on interpolation of published tables from Seltzer
0038  * and Berger given in \cite{sb-brems-1985} and \cite{sb-brems-1986}.
0039  * The cross
0040  * sections are obtained from SBEnergyDistribution and are appropriately scaled
0041  * in the case of positrons via SBPositronXsCorrector.
0042  *
0043  * \note This interactor performs an analogous sampling as in Geant4's
0044  * G4SeltzerBergerModel, documented in 10.2.1 of the Geant Physics Reference
0045  * (release 10.6). The implementation is based on Geant4 10.4.3.
0046  */
0047 class SeltzerBergerInteractor
0048 {
0049   public:
0050     //!@{
0051     //! \name Type aliases
0052     using Energy = units::MevEnergy;
0053     using Momentum = units::MevMomentum;
0054     //!@}
0055 
0056   public:
0057     //! Construct sampler from device/shared and state data
0058     inline CELER_FUNCTION
0059     SeltzerBergerInteractor(SeltzerBergerRef const& shared,
0060                             ParticleTrackView const& particle,
0061                             Real3 const& inc_direction,
0062                             CutoffView const& cutoffs,
0063                             StackAllocator<Secondary>& allocate,
0064                             MaterialView const& material,
0065                             ElementComponentId const& elcomp_id);
0066 
0067     // Sample an interaction with the given RNG
0068     template<class Engine>
0069     inline CELER_FUNCTION Interaction operator()(Engine& rng);
0070 
0071   private:
0072     //// DATA ////
0073     // Device (host CPU or GPU device) references
0074     SeltzerBergerRef const& shared_;
0075     // Incident particle energy
0076     Energy const inc_energy_;
0077     // Incident particle direction
0078     Momentum const inc_momentum_;
0079     // Incident particle direction
0080     Real3 const& inc_direction_;
0081     // Production cutoff for gammas
0082     Energy const gamma_cutoff_;
0083     // Allocate space for a secondary particle
0084     StackAllocator<Secondary>& allocate_;
0085     // Element in which interaction occurs
0086     ElementComponentId const elcomp_id_;
0087 
0088     //// HELPER CLASSES ////
0089     // A helper to sample the bremsstrahlung photon energy
0090     detail::SBEnergySampler sample_photon_energy_;
0091     // Secondary angular distribution
0092     TsaiUrbanDistribution sample_costheta_;
0093 };
0094 
0095 //---------------------------------------------------------------------------//
0096 // INLINE DEFINITIONS
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Construct with shared/device and state data.
0100  *
0101  * The incident particle must be within the model's valid energy range. this
0102  * must be handled in code *before* the interactor is constructed.
0103  */
0104 CELER_FUNCTION SeltzerBergerInteractor::SeltzerBergerInteractor(
0105     SeltzerBergerRef const& shared,
0106     ParticleTrackView const& particle,
0107     Real3 const& inc_direction,
0108     CutoffView const& cutoffs,
0109     StackAllocator<Secondary>& allocate,
0110     MaterialView const& material,
0111     ElementComponentId const& elcomp_id)
0112     : shared_(shared)
0113     , inc_energy_(particle.energy())
0114     , inc_momentum_(particle.momentum())
0115     , inc_direction_(inc_direction)
0116     , gamma_cutoff_(cutoffs.energy(shared.ids.gamma))
0117     , allocate_(allocate)
0118     , elcomp_id_(elcomp_id)
0119     , sample_photon_energy_(shared.differential_xs,
0120                             particle,
0121                             gamma_cutoff_,
0122                             material,
0123                             elcomp_id,
0124                             particle.particle_id() == shared_.ids.electron)
0125     , sample_costheta_(inc_energy_, particle.mass())
0126 {
0127     CELER_EXPECT(particle.particle_id() == shared_.ids.electron
0128                  || particle.particle_id() == shared_.ids.positron);
0129     CELER_EXPECT(gamma_cutoff_ > zero_quantity());
0130     CELER_EXPECT(inc_energy_ < shared_.high_energy_limit);
0131 }
0132 
0133 //---------------------------------------------------------------------------//
0134 /*!
0135  * Bremsstrahlung using the Seltzer-Berger model.
0136  *
0137  * See section 10.2.1 of the Geant physics reference 10.6.
0138  */
0139 template<class Engine>
0140 CELER_FUNCTION Interaction SeltzerBergerInteractor::operator()(Engine& rng)
0141 {
0142     if (inc_energy_ <= gamma_cutoff_)
0143     {
0144         /*!
0145          * \todo Remove and replace with an assertion once material-dependent
0146          * model bounds are supported
0147          */
0148         return Interaction::from_unchanged();
0149     }
0150 
0151     // Allocate space for the brems photon
0152     Secondary* secondaries = allocate_(1);
0153     if (secondaries == nullptr)
0154     {
0155         // Failed to allocate space for the secondary
0156         return Interaction::from_failure();
0157     }
0158 
0159     // Update kinematics of the final state and return this interaction
0160     return detail::BremFinalStateHelper{inc_energy_,
0161                                         inc_direction_,
0162                                         inc_momentum_,
0163                                         shared_.ids.gamma,
0164                                         sample_photon_energy_(rng),
0165                                         sample_costheta_(rng),
0166                                         secondaries}(rng);
0167 }
0168 
0169 //---------------------------------------------------------------------------//
0170 }  // namespace celeritas