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