Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-14 08:50:33

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/MollerBhabhaInteractor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cmath>
0010 
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/StackAllocator.hh"
0014 #include "corecel/math/Algorithms.hh"
0015 #include "corecel/math/ArrayUtils.hh"
0016 #include "celeritas/Constants.hh"
0017 #include "celeritas/Quantities.hh"
0018 #include "celeritas/em/data/MollerBhabhaData.hh"
0019 #include "celeritas/em/distribution/BhabhaEnergyDistribution.hh"
0020 #include "celeritas/em/distribution/MollerEnergyDistribution.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/IoniFinalStateHelper.hh"
0027 
0028 namespace celeritas
0029 {
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Perform Moller (e-e-) and Bhabha (e+e-) scattering.
0033  *
0034  * This interaction, part of the ionization process, is when an incident
0035  * electron or positron ejects an electron from the surrounding matter.
0036  *
0037  * \note This performs the same sampling routine as in Geant4's
0038  * G4MollerBhabhaModel class, as documented in section 10.1.4 of the Geant4
0039  * Physics Reference (release 10.6).
0040  */
0041 class MollerBhabhaInteractor
0042 {
0043   public:
0044     //!@{
0045     //! \name Type aliases
0046     using Mass = units::MevMass;
0047     using Energy = units::MevEnergy;
0048     using Momentum = units::MevMomentum;
0049     //!@}
0050 
0051   public:
0052     //! Construct with shared and state data
0053     inline CELER_FUNCTION
0054     MollerBhabhaInteractor(MollerBhabhaData const& shared,
0055                            ParticleTrackView const& particle,
0056                            CutoffView const& cutoffs,
0057                            Real3 const& inc_direction,
0058                            StackAllocator<Secondary>& allocate);
0059 
0060     // Sample an interaction with the given RNG
0061     template<class Engine>
0062     inline CELER_FUNCTION Interaction operator()(Engine& rng);
0063 
0064   private:
0065     // Shared constant physics properties
0066     MollerBhabhaData const& shared_;
0067     // Incident energy [MeV]
0068     Energy inc_energy_;
0069     // Incident momentum [MeV]
0070     Momentum inc_momentum_;
0071     // Incident direction
0072     Real3 const& inc_direction_;
0073     // Secondary electron cutoff for current material
0074     Energy electron_cutoff_;
0075     // Allocate space for the secondary particle
0076     StackAllocator<Secondary>& allocate_;
0077     // Incident particle flag for selecting Moller or Bhabha scattering
0078     bool const inc_particle_is_electron_;
0079 };
0080 
0081 //---------------------------------------------------------------------------//
0082 // INLINE DEFINITIONS
0083 //---------------------------------------------------------------------------//
0084 /*!
0085  * Construct with shared and state data.
0086  *
0087  * The incident particle must be within the model's valid energy range. this
0088  * must be handled in code *before* the interactor is constructed.
0089  */
0090 CELER_FUNCTION MollerBhabhaInteractor::MollerBhabhaInteractor(
0091     MollerBhabhaData const& shared,
0092     ParticleTrackView const& particle,
0093     CutoffView const& cutoffs,
0094     Real3 const& inc_direction,
0095     StackAllocator<Secondary>& allocate)
0096     : shared_(shared)
0097     , inc_energy_(particle.energy())
0098     , inc_momentum_(particle.momentum())
0099     , inc_direction_(inc_direction)
0100     , electron_cutoff_(cutoffs.energy(shared_.ids.electron))
0101     , allocate_(allocate)
0102     , inc_particle_is_electron_(particle.particle_id() == shared_.ids.electron)
0103 {
0104     CELER_EXPECT(particle.particle_id() == shared_.ids.electron
0105                  || particle.particle_id() == shared_.ids.positron);
0106 }
0107 
0108 //---------------------------------------------------------------------------//
0109 /*!
0110  * Sample e-e- or e+e- scattering using Moller or Bhabha models, depending on
0111  * the incident particle.
0112  *
0113  * See section 10.1.4 of the Geant4 physics reference manual (release 10.6).
0114  */
0115 template<class Engine>
0116 CELER_FUNCTION Interaction MollerBhabhaInteractor::operator()(Engine& rng)
0117 {
0118     if (inc_energy_ <= (inc_particle_is_electron_ ? 2 : 1) * electron_cutoff_)
0119     {
0120         /*!
0121          * \todo Remove and replace with an assertion once material-dependent
0122          * model bounds are supported
0123          */
0124         return Interaction::from_unchanged();
0125     }
0126 
0127     // Allocate memory for the produced electron
0128     Secondary* electron_secondary = allocate_(1);
0129 
0130     if (electron_secondary == nullptr)
0131     {
0132         // Fail to allocate space for a secondary
0133         return Interaction::from_failure();
0134     }
0135 
0136     // Sample secondary electron energy
0137     Energy secondary_energy = inc_energy_ * [this, &rng] {
0138         if (inc_particle_is_electron_)
0139         {
0140             return MollerEnergyDistribution(
0141                 shared_.electron_mass, electron_cutoff_, inc_energy_)(rng);
0142         }
0143         return BhabhaEnergyDistribution(
0144             shared_.electron_mass, electron_cutoff_, inc_energy_)(rng);
0145     }();
0146     CELER_ASSERT(secondary_energy >= electron_cutoff_);
0147 
0148     // Sample the delta ray energy to construct the final sampler
0149     detail::IoniFinalStateHelper sample_interaction(inc_energy_,
0150                                                     inc_direction_,
0151                                                     inc_momentum_,
0152                                                     shared_.electron_mass,
0153                                                     secondary_energy,
0154                                                     shared_.electron_mass,
0155                                                     shared_.ids.electron,
0156                                                     electron_secondary);
0157 
0158     // Update kinematics of the final state and return this interaction
0159     return sample_interaction(rng);
0160 }
0161 
0162 //---------------------------------------------------------------------------//
0163 }  // namespace celeritas