Back to home page

EIC code displayed by LXR

 
 

    


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

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