Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:34

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