Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //---------------------------------*-CUDA-*----------------------------------//
0002 // Copyright 2020-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/ParticleParams.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <string>
0012 #include <unordered_map>
0013 #include <utility>
0014 #include <vector>
0015 
0016 #include "corecel/Assert.hh"
0017 #include "corecel/data/CollectionMirror.hh"
0018 #include "corecel/data/ParamsDataInterface.hh"
0019 #include "celeritas/Quantities.hh"
0020 #include "celeritas/Types.hh"
0021 
0022 #include "PDGNumber.hh"
0023 #include "ParticleData.hh"
0024 #include "ParticleView.hh"
0025 
0026 namespace celeritas
0027 {
0028 struct ImportData;
0029 
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Data management for Standard Model particle classifications.
0033  *
0034  * This class represents "per-problem" shared data about standard
0035  * model particles being used.
0036  *
0037  * The ParticleParams is constructed on the host with a vector that
0038  * combines metadata (used for debugging output and interfacing with physics
0039  * setup) and data (used for on-device transport). Each entry in the
0040  * construction is assigned a unique \c ParticleId used for runtime access.
0041  *
0042  * The PDG Monte Carlo number is a unique "standard model" identifier for a
0043  * particle. See "Monte Carlo Particle Numbering Scheme" in the "Review of
0044  * Particle Physics":
0045  * https://pdg.lbl.gov/2020/reviews/rpp2020-rev-monte-carlo-numbering.pdf
0046  * It should be used to identify particle types during construction time.
0047  */
0048 class ParticleParams final : public ParamsDataInterface<ParticleParamsData>
0049 {
0050   public:
0051     //! Define a particle's input data
0052     struct ParticleInput
0053     {
0054         std::string name;  //!< Particle name
0055         PDGNumber pdg_code;  //!< See "Review of Particle Physics"
0056         units::MevMass mass;  //!< Rest mass [MeV / c^2]
0057         units::ElementaryCharge charge;  //!< Charge in units of [e]
0058         real_type decay_constant;  //!< Decay constant [1/s]
0059     };
0060 
0061     //! Input data to construct this class
0062     using Input = std::vector<ParticleInput>;
0063 
0064   public:
0065     // Construct with imported data
0066     static std::shared_ptr<ParticleParams> from_import(ImportData const& data);
0067 
0068     // Construct with a vector of particle definitions
0069     explicit ParticleParams(Input const& defs);
0070 
0071     //// HOST ACCESSORS ////
0072 
0073     //! Number of particle definitions
0074     ParticleId::size_type size() const { return md_.size(); }
0075 
0076     // Get particle name
0077     inline std::string const& id_to_label(ParticleId id) const;
0078 
0079     // Get PDG code
0080     inline PDGNumber id_to_pdg(ParticleId id) const;
0081 
0082     // Find the ID from a name
0083     inline ParticleId find(std::string const& name) const;
0084 
0085     // Find the ID from a PDG code
0086     inline ParticleId find(PDGNumber pdg_code) const;
0087 
0088     // Access particle properties on host
0089     ParticleView get(ParticleId id) const;
0090 
0091     //! Access material properties on the host
0092     HostRef const& host_ref() const final { return data_.host_ref(); }
0093 
0094     //! Access material properties on the device
0095     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0096 
0097   private:
0098     // Saved copy of metadata
0099     std::vector<std::pair<std::string, PDGNumber>> md_;
0100 
0101     // Map particle names to registered IDs
0102     std::unordered_map<std::string, ParticleId> name_to_id_;
0103 
0104     // Map particle codes to registered IDs
0105     std::unordered_map<PDGNumber, ParticleId> pdg_to_id_;
0106 
0107     // Host/device storage and reference
0108     CollectionMirror<ParticleParamsData> data_;
0109 };
0110 
0111 //---------------------------------------------------------------------------//
0112 // INLINE DEFINITIONS
0113 //---------------------------------------------------------------------------//
0114 /*!
0115  * Get particle name.
0116  */
0117 std::string const& ParticleParams::id_to_label(ParticleId id) const
0118 {
0119     CELER_EXPECT(id < this->size());
0120     return md_[id.get()].first;
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 /*!
0125  * Get PDG code for a particle ID.
0126  */
0127 PDGNumber ParticleParams::id_to_pdg(ParticleId id) const
0128 {
0129     CELER_EXPECT(id < this->size());
0130     return md_[id.get()].second;
0131 }
0132 
0133 //---------------------------------------------------------------------------//
0134 /*!
0135  * Find the ID from a name.
0136  */
0137 ParticleId ParticleParams::find(std::string const& name) const
0138 {
0139     auto iter = name_to_id_.find(name);
0140     if (iter == name_to_id_.end())
0141     {
0142         return ParticleId{};
0143     }
0144     return iter->second;
0145 }
0146 
0147 //---------------------------------------------------------------------------//
0148 /*!
0149  * Find the ID from a PDG code.
0150  */
0151 ParticleId ParticleParams::find(PDGNumber pdg_code) const
0152 {
0153     auto iter = pdg_to_id_.find(pdg_code);
0154     if (iter == pdg_to_id_.end())
0155     {
0156         return ParticleId{};
0157     }
0158     return iter->second;
0159 }
0160 
0161 //---------------------------------------------------------------------------//
0162 }  // namespace celeritas