Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:11:01

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/phys/CutoffParams.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <map>
0010 #include <memory>
0011 #include <vector>
0012 
0013 #include "corecel/Assert.hh"
0014 #include "corecel/data/CollectionMirror.hh"
0015 #include "corecel/data/ParamsDataInterface.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/mat/MaterialParams.hh"
0019 
0020 #include "CutoffData.hh"
0021 #include "CutoffView.hh"
0022 #include "PDGNumber.hh"
0023 
0024 namespace celeritas
0025 {
0026 class ParticleParams;
0027 struct ImportData;
0028 
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * Management particle and material cutoffs.
0032  *
0033  * Geant4 provides accessors to its production cuts from its
0034  * \c G4MaterialCutsCouple class, which couples cutoff and material data.
0035  * During import, for simplicity, G4's production cuts are stored alongside
0036  * the material information, in \c ImportPhysMaterial . Since this is a direct
0037  * import, the cutoff map in \c ImportPhysMaterial stores only the cuts
0038  * available in Geant4, i.e. only values for gammas, electrons, positrons, and
0039  * protons.
0040  *
0041  * In Celeritas, particle cutoff is stored contiguously in a single vector
0042  * of size num_particles * num_materials, which stores all particle cutoffs
0043  * for all materials. During import, any particle that is not in Geant4's
0044  * list receives a zero cutoff value. This opens the possibility to expand
0045  * cutoffs in the future, when data is not imported anymore.
0046  *
0047  * The \c Input structure provides a failsafe mechanism to construct the
0048  * host/device data.
0049  *
0050  * Some processes (e.g. photoelectric effect, decay) can produce secondaries
0051  * below the production threshold, while others (e.g. bremsstrahlung,
0052  * ionization) use the production cut as their instrinsic limit. By default all
0053  * of these secondaries are transported, even if their energy is below the
0054  * threshold. If the \c apply_post_interaction option is enabled, any secondary
0055  * photon, electron, or positron with energy below the cutoff will be killed
0056  * (the flag will be ignored for other particle types).
0057  */
0058 class CutoffParams final : public ParamsDataInterface<CutoffParamsData>
0059 {
0060   public:
0061     //!@{
0062     //! \name Type aliases
0063     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0064     using SPConstMaterials = std::shared_ptr<MaterialParams const>;
0065     using MaterialCutoffs = std::vector<ParticleCutoff>;
0066     //!@}
0067 
0068     //! Input data to construct this class
0069     struct Input
0070     {
0071         SPConstParticles particles;
0072         SPConstMaterials materials;
0073         std::map<PDGNumber, MaterialCutoffs> cutoffs;
0074         bool apply_post_interaction{false};
0075     };
0076 
0077   public:
0078     // Construct with imported data
0079     static std::shared_ptr<CutoffParams>
0080     from_import(ImportData const& data,
0081                 SPConstParticles particle_params,
0082                 SPConstMaterials material_params);
0083 
0084     // Construct with cutoff input data
0085     explicit CutoffParams(Input const& input);
0086 
0087     // Access cutoffs on host
0088     inline CutoffView get(PhysMatId material) const;
0089 
0090     //! Access cutoff data on the host
0091     HostRef const& host_ref() const final { return data_.host_ref(); }
0092 
0093     //! Access cutoff data on the device
0094     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0095 
0096   private:
0097     // Host/device storage and reference
0098     CollectionMirror<CutoffParamsData> data_;
0099     using HostValue = HostVal<CutoffParamsData>;
0100 
0101     //// HELPER FUNCTIONS ////
0102 
0103     // PDG numbers of particles with prodution cuts
0104     static std::vector<PDGNumber> const& pdg_numbers();
0105 };
0106 
0107 //---------------------------------------------------------------------------//
0108 // INLINE DEFINITIONS
0109 //---------------------------------------------------------------------------//
0110 /*!
0111  * Access cutoffs on host.
0112  */
0113 CutoffView CutoffParams::get(PhysMatId material) const
0114 {
0115     CELER_EXPECT(material < this->host_ref().num_materials);
0116     return CutoffView(this->host_ref(), material);
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 }  // namespace celeritas