Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/phys/ParticleParams.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 struct ImportParticle;
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Data management for Standard Model particle classifications.
0034  *
0035  * This class represents "per-problem" shared data about standard
0036  * model particles being used.
0037  *
0038  * The ParticleParams is constructed on the host with a vector that
0039  * combines metadata (used for debugging output and interfacing with physics
0040  * setup) and data (used for on-device transport). Each entry in the
0041  * construction is assigned a unique \c ParticleId used for runtime access. See
0042  * \c celeritas::PDGNumber for details on the PDG code used during
0043  * construction.
0044  */
0045 class ParticleParams final : public ParamsDataInterface<ParticleParamsData>
0046 {
0047   public:
0048     //! Define a particle's input data
0049     struct ParticleInput
0050     {
0051         std::string name;  //!< Particle name
0052         PDGNumber pdg_code;  //!< See "Review of Particle Physics"
0053         units::MevMass mass;  //!< Rest mass [MeV / c^2]
0054         units::ElementaryCharge charge;  //!< Charge in units of [e]
0055         real_type decay_constant{};  //!< Decay constant [1/time]
0056 
0057         // Conversion function
0058         static ParticleInput from_import(ImportParticle const&);
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  * \todo Multiple particles can share a "generic" PDG code so this should be a
0152  * multimap.
0153  */
0154 ParticleId ParticleParams::find(PDGNumber pdg_code) const
0155 {
0156     auto iter = pdg_to_id_.find(pdg_code);
0157     if (iter == pdg_to_id_.end())
0158     {
0159         return ParticleId{};
0160     }
0161     return iter->second;
0162 }
0163 
0164 //---------------------------------------------------------------------------//
0165 }  // namespace celeritas