Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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/detail/IoniFinalStateHelper.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "celeritas/Quantities.hh"
0011 #include "celeritas/phys/InteractionUtils.hh"
0012 #include "celeritas/phys/Secondary.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Update final state of incident particle and delta ray for ionization.
0021  */
0022 class IoniFinalStateHelper
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using Energy = units::MevEnergy;
0028     using Mass = units::MevMass;
0029     using Momentum = units::MevMomentum;
0030     //!@}
0031 
0032   public:
0033     // Construct from data
0034     inline CELER_FUNCTION IoniFinalStateHelper(Energy inc_energy,
0035                                                Real3 const& inc_direction,
0036                                                Momentum inc_momentum,
0037                                                Mass inc_mass,
0038                                                Energy electron_energy,
0039                                                Mass electron_mass,
0040                                                ParticleId electron_id,
0041                                                Secondary* secondary);
0042 
0043     // Update the final state of the incident particle and secondary electron
0044     template<class Engine>
0045     inline CELER_FUNCTION Interaction operator()(Engine& rng);
0046 
0047   private:
0048     // Incident particle energy [MeV]
0049     real_type inc_energy_;
0050     // Incident particle direction
0051     Real3 const& inc_direction_;
0052     // Incident particle momentum [MeV / c]
0053     real_type inc_momentum_;
0054     // Incident particle mass
0055     real_type inc_mass_;
0056     // Secondary electron energy [MeV]
0057     real_type electron_energy_;
0058     // Electron mass
0059     real_type electron_mass_;
0060     // Secondary electron ID
0061     ParticleId electron_id_;
0062     // Allocated secondary electron
0063     Secondary* secondary_;
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 // INLINE DEFINITIONS
0068 //---------------------------------------------------------------------------//
0069 /*!
0070  * Construct from incident particle and exiting gamma data.
0071  */
0072 CELER_FUNCTION
0073 IoniFinalStateHelper::IoniFinalStateHelper(Energy inc_energy,
0074                                            Real3 const& inc_direction,
0075                                            Momentum inc_momentum,
0076                                            Mass inc_mass,
0077                                            Energy electron_energy,
0078                                            Mass electron_mass,
0079                                            ParticleId electron_id,
0080                                            Secondary* secondary)
0081     : inc_energy_(value_as<Energy>(inc_energy))
0082     , inc_direction_(inc_direction)
0083     , inc_momentum_(value_as<Momentum>(inc_momentum))
0084     , inc_mass_(value_as<Mass>(inc_mass))
0085     , electron_energy_(value_as<Energy>(electron_energy))
0086     , electron_mass_(value_as<Mass>(electron_mass))
0087     , electron_id_(electron_id)
0088     , secondary_{secondary}
0089 {
0090     CELER_EXPECT(secondary_);
0091 }
0092 
0093 //---------------------------------------------------------------------------//
0094 /*!
0095  * Update the final state of the incident particle and secondary electron.
0096  */
0097 template<class Engine>
0098 CELER_FUNCTION Interaction IoniFinalStateHelper::operator()(Engine& rng)
0099 {
0100     // Calculate the polar angle of the exiting electron
0101     real_type momentum = std::sqrt(electron_energy_
0102                                    * (electron_energy_ + 2 * electron_mass_));
0103     real_type costheta = electron_energy_
0104                          * (inc_energy_ + inc_mass_ + electron_mass_)
0105                          / (momentum * inc_momentum_);
0106     CELER_ASSERT(costheta <= 1);
0107 
0108     // Sample and save outgoing secondary data
0109     secondary_->energy = Energy{electron_energy_};
0110     secondary_->direction
0111         = ExitingDirectionSampler{costheta, inc_direction_}(rng);
0112     secondary_->particle_id = electron_id_;
0113 
0114     // Construct interaction for change to parent (incoming) particle
0115     Interaction result;
0116     result.energy = Energy{inc_energy_ - electron_energy_};
0117     result.direction = calc_exiting_direction(
0118         {inc_momentum_, inc_direction_}, {momentum, secondary_->direction});
0119     result.secondaries = {secondary_, 1};
0120 
0121     return result;
0122 }
0123 
0124 //---------------------------------------------------------------------------//
0125 }  // namespace detail
0126 }  // namespace celeritas