Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2021-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/em/interactor/CombinedBremInteractor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/StackAllocator.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/ArrayUtils.hh"
0015 #include "celeritas/Constants.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/em/data/CombinedBremData.hh"
0019 #include "celeritas/em/distribution/TsaiUrbanDistribution.hh"
0020 #include "celeritas/mat/ElementView.hh"
0021 #include "celeritas/mat/MaterialView.hh"
0022 #include "celeritas/phys/CutoffView.hh"
0023 #include "celeritas/phys/Interaction.hh"
0024 #include "celeritas/phys/ParticleTrackView.hh"
0025 #include "celeritas/phys/Secondary.hh"
0026 
0027 #include "detail/BremFinalStateHelper.hh"
0028 #include "detail/PhysicsConstants.hh"
0029 #include "detail/RBEnergySampler.hh"
0030 #include "detail/SBEnergySampler.hh"
0031 
0032 namespace celeritas
0033 {
0034 //---------------------------------------------------------------------------//
0035 /*!
0036  * Apply either Seltzer-Berger or Relativistic depending on energy.
0037  *
0038  * This is a combined bremsstrahlung interactor consisted of the Seltzer-Berger
0039  * interactor at the low energy (< 1 GeV) and the relativistic bremsstrahlung
0040  * interactor at the high energy for the e-/e+ bremsstrahlung process.
0041  *
0042  * \todo: see if there's any occupancy/performance difference by defining the
0043  * samplers *inside* the conditional on "is_relativistic".
0044  */
0045 class CombinedBremInteractor
0046 {
0047     //!@{
0048     //! \name Type aliases
0049     using Energy = units::MevEnergy;
0050     using Momentum = units::MevMomentum;
0051     using ElementData = RelBremElementData;
0052     using ItemIdT = celeritas::ItemId<unsigned int>;
0053     //!@}
0054 
0055   public:
0056     // Construct with shared and state data
0057     inline CELER_FUNCTION
0058     CombinedBremInteractor(CombinedBremRef const& shared,
0059                            ParticleTrackView const& particle,
0060                            Real3 const& direction,
0061                            CutoffView const& cutoffs,
0062                            StackAllocator<Secondary>& allocate,
0063                            MaterialView const& material,
0064                            ElementComponentId const& elcomp_id);
0065 
0066     // Sample an interaction with the given RNG
0067     template<class Engine>
0068     inline CELER_FUNCTION Interaction operator()(Engine& rng);
0069 
0070   private:
0071     //// DATA ////
0072 
0073     // SB and relativistic data
0074     CombinedBremRef const& shared_;
0075     // Incident particle
0076     ParticleTrackView const& particle_;
0077     // Incident particle direction
0078     Real3 const& inc_direction_;
0079     // Energy cutoffs
0080     CutoffView const& cutoffs_;
0081     // Production cutoff for gammas
0082     Energy const gamma_cutoff_;
0083     // Allocate space for a secondary particle
0084     StackAllocator<Secondary>& allocate_;
0085     // Material properties
0086     MaterialView const& material_;
0087     // Element in which interaction occurs
0088     ElementComponentId const elcomp_id_;
0089     // Secondary angular distribution
0090     TsaiUrbanDistribution sample_costheta_;
0091 };
0092 
0093 //---------------------------------------------------------------------------//
0094 // INLINE DEFINITIONS
0095 //---------------------------------------------------------------------------//
0096 /*!
0097  * Construct with shared and state data.
0098  */
0099 CELER_FUNCTION
0100 CombinedBremInteractor::CombinedBremInteractor(
0101     CombinedBremRef const& shared,
0102     ParticleTrackView const& particle,
0103     Real3 const& direction,
0104     CutoffView const& cutoffs,
0105     StackAllocator<Secondary>& allocate,
0106     MaterialView const& material,
0107     ElementComponentId const& elcomp_id)
0108     : shared_(shared)
0109     , particle_(particle)
0110     , inc_direction_(direction)
0111     , cutoffs_(cutoffs)
0112     , gamma_cutoff_(cutoffs.energy(shared.rb_data.ids.gamma))
0113     , allocate_(allocate)
0114     , material_(material)
0115     , elcomp_id_(elcomp_id)
0116     , sample_costheta_(particle.energy(), particle.mass())
0117 {
0118     CELER_EXPECT(particle.particle_id() == shared.rb_data.ids.electron
0119                  || particle.particle_id() == shared.rb_data.ids.positron);
0120     CELER_EXPECT(gamma_cutoff_ > zero_quantity());
0121     CELER_EXPECT(particle_.energy() > gamma_cutoff_);
0122 }
0123 
0124 //---------------------------------------------------------------------------//
0125 /*!
0126  * Sample the production of bremsstrahlung photons using a combined model.
0127  */
0128 template<class Engine>
0129 CELER_FUNCTION Interaction CombinedBremInteractor::operator()(Engine& rng)
0130 {
0131     // Allocate space for the brems photon
0132     Secondary* secondaries = allocate_(1);
0133     if (secondaries == nullptr)
0134     {
0135         // Failed to allocate space for the secondary
0136         return Interaction::from_failure();
0137     }
0138 
0139     // Sample the bremsstrahlung photon energy
0140     Energy gamma_energy;
0141     if (particle_.energy() >= detail::seltzer_berger_upper_limit())
0142     {
0143         detail::RBEnergySampler sample_energy{
0144             shared_.rb_data, particle_, cutoffs_, material_, elcomp_id_};
0145         gamma_energy = sample_energy(rng);
0146     }
0147     else
0148     {
0149         detail::SBEnergySampler sample_energy{
0150             shared_.sb_differential_xs,
0151             particle_,
0152             gamma_cutoff_,
0153             material_,
0154             elcomp_id_,
0155             particle_.particle_id() == shared_.rb_data.ids.electron};
0156         gamma_energy = sample_energy(rng);
0157     }
0158 
0159     // Update kinematics of the final state and return this interaction
0160     return detail::BremFinalStateHelper(particle_.energy(),
0161                                         inc_direction_,
0162                                         particle_.momentum(),
0163                                         shared_.rb_data.ids.gamma,
0164                                         gamma_energy,
0165                                         sample_costheta_(rng),
0166                                         secondaries)(rng);
0167 }
0168 
0169 //---------------------------------------------------------------------------//
0170 }  // namespace celeritas