Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-18 10:26:29

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/RelativisticBremInteractor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/data/Collection.hh"
0012 #include "corecel/data/StackAllocator.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/ArrayUtils.hh"
0015 #include "celeritas/Quantities.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/em/data/RelativisticBremData.hh"
0018 #include "celeritas/em/distribution/TsaiUrbanDistribution.hh"
0019 #include "celeritas/mat/ElementView.hh"
0020 #include "celeritas/mat/MaterialView.hh"
0021 #include "celeritas/phys/CutoffView.hh"
0022 #include "celeritas/phys/Interaction.hh"
0023 #include "celeritas/phys/ParticleTrackView.hh"
0024 #include "celeritas/phys/Secondary.hh"
0025 
0026 #include "detail/BremFinalStateHelper.hh"
0027 #include "detail/PhysicsConstants.hh"
0028 #include "detail/RBEnergySampler.hh"
0029 
0030 namespace celeritas
0031 {
0032 //---------------------------------------------------------------------------//
0033 /*!
0034  * Perform a high-energy Bremsstrahlung interaction.
0035  *
0036  * This is a relativistic Bremsstrahlung model for high-energy (> 1 GeV)
0037  * electrons and positrons.
0038  *
0039  * \note This performs the same sampling routine as in Geant4's
0040  * G4eBremsstrahlungRelModel class, as documented in section 10.2.2 of the
0041  * Geant4 Physics Reference (release 10.7).
0042  */
0043 class RelativisticBremInteractor
0044 {
0045   public:
0046     //!@{
0047     //! \name Type aliases
0048     using Energy = units::MevEnergy;
0049     using Momentum = units::MevMomentum;
0050     using ElementData = RelBremElementData;
0051     using ItemIdT = celeritas::ItemId<unsigned int>;
0052     //!@}
0053 
0054   public:
0055     // Construct with shared and state data
0056     inline CELER_FUNCTION RelativisticBremInteractor(
0057         NativeCRef<RelativisticBremData> const& shared,
0058         ParticleTrackView const& particle,
0059         Real3 const& direction,
0060         CutoffView const& cutoffs,
0061         StackAllocator<Secondary>& allocate,
0062         MaterialView const& material,
0063         ElementComponentId const& elcomp_id);
0064 
0065     // Sample an interaction with the given RNG
0066     template<class Engine>
0067     inline CELER_FUNCTION Interaction operator()(Engine& rng);
0068 
0069   private:
0070     //// DATA ////
0071 
0072     // Shared constant physics properties
0073     NativeCRef<RelativisticBremData> const& shared_;
0074     // Incident particle energy
0075     Energy const inc_energy_;
0076     // Incident particle momentum
0077     Momentum const inc_momentum_;
0078     // Incident direction
0079     Real3 const& inc_direction_;
0080     // Allocate space for a secondary particle
0081     StackAllocator<Secondary>& allocate_;
0082 
0083     //// HELPER CLASSES ////
0084 
0085     // A helper to sample the photon energy from the relativistic model
0086     detail::RBEnergySampler sample_photon_energy_;
0087     // Secondary angular distribution
0088     TsaiUrbanDistribution sample_costheta_;
0089 };
0090 
0091 //---------------------------------------------------------------------------//
0092 // INLINE DEFINITIONS
0093 //---------------------------------------------------------------------------//
0094 /*!
0095  * Construct with shared and state data.
0096  */
0097 CELER_FUNCTION RelativisticBremInteractor::RelativisticBremInteractor(
0098     NativeCRef<RelativisticBremData> const& shared,
0099     ParticleTrackView const& particle,
0100     Real3 const& direction,
0101     CutoffView const& cutoffs,
0102     StackAllocator<Secondary>& allocate,
0103     MaterialView const& material,
0104     ElementComponentId const& elcomp_id)
0105     : shared_(shared)
0106     , inc_energy_(particle.energy())
0107     , inc_momentum_(particle.momentum())
0108     , inc_direction_(direction)
0109     , allocate_(allocate)
0110     , sample_photon_energy_(shared, particle, cutoffs, material, elcomp_id)
0111     , sample_costheta_(inc_energy_, particle.mass())
0112 {
0113     CELER_EXPECT(particle.particle_id() == shared_.ids.electron
0114                  || particle.particle_id() == shared_.ids.positron);
0115 
0116     // Valid energy region of the relativistic e-/e+ Bremsstrahlung model
0117     CELER_EXPECT(inc_energy_ >= shared_.low_energy_limit);
0118 }
0119 
0120 //---------------------------------------------------------------------------//
0121 /*!
0122  * Sample the production of photons and update final states.
0123  */
0124 template<class Engine>
0125 CELER_FUNCTION Interaction RelativisticBremInteractor::operator()(Engine& rng)
0126 {
0127     // Allocate space for the brems photon
0128     Secondary* secondaries = allocate_(1);
0129     if (secondaries == nullptr)
0130     {
0131         // Failed to allocate space for the secondary
0132         return Interaction::from_failure();
0133     }
0134 
0135     // Update kinematics of the final state and return this interaction
0136     return detail::BremFinalStateHelper{inc_energy_,
0137                                         inc_direction_,
0138                                         inc_momentum_,
0139                                         shared_.ids.gamma,
0140                                         sample_photon_energy_(rng),
0141                                         sample_costheta_(rng),
0142                                         secondaries}(rng);
0143 }
0144 
0145 //---------------------------------------------------------------------------//
0146 }  // namespace celeritas