File indexing completed on 2026-05-09 08:40:05
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <unordered_map>
0012 #include <utility>
0013 #include <vector>
0014
0015 #include "corecel/Assert.hh"
0016 #include "corecel/data/CollectionMirror.hh"
0017 #include "corecel/data/ParamsDataInterface.hh"
0018 #include "celeritas/Quantities.hh"
0019 #include "celeritas/Types.hh"
0020
0021 #include "PDGNumber.hh"
0022 #include "ParticleData.hh"
0023 #include "ParticleView.hh"
0024
0025 namespace celeritas
0026 {
0027 struct ImportData;
0028 struct ImportParticle;
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 class ParticleParams final : public ParamsDataInterface<ParticleParamsData>
0045 {
0046 public:
0047
0048 struct ParticleInput
0049 {
0050 std::string name;
0051 PDGNumber pdg_code;
0052 units::MevMass mass;
0053 units::ElementaryCharge charge;
0054 real_type decay_constant{};
0055
0056
0057 static ParticleInput from_import(ImportParticle const&);
0058 };
0059
0060
0061 using Input = std::vector<ParticleInput>;
0062
0063 public:
0064
0065 static std::shared_ptr<ParticleParams> from_import(ImportData const& data);
0066
0067
0068 explicit ParticleParams(Input const& defs);
0069
0070
0071
0072
0073 ParticleId::size_type size() const { return md_.size(); }
0074
0075
0076 inline std::string const& id_to_label(ParticleId id) const;
0077
0078
0079 inline PDGNumber id_to_pdg(ParticleId id) const;
0080
0081
0082 inline ParticleId find(std::string const& name) const;
0083
0084
0085 inline ParticleId find(PDGNumber pdg_code) const;
0086
0087
0088 ParticleView get(ParticleId id) const;
0089
0090
0091 HostRef const& host_ref() const final { return data_.host_ref(); }
0092
0093
0094 DeviceRef const& device_ref() const final { return data_.device_ref(); }
0095
0096 private:
0097
0098 std::vector<std::pair<std::string, PDGNumber>> md_;
0099
0100
0101 std::unordered_map<std::string, ParticleId> name_to_id_;
0102
0103
0104 std::unordered_map<PDGNumber, ParticleId> pdg_to_id_;
0105
0106
0107 CollectionMirror<ParticleParamsData> data_;
0108 };
0109
0110
0111
0112
0113
0114
0115
0116 std::string const& ParticleParams::id_to_label(ParticleId id) const
0117 {
0118 CELER_EXPECT(id < this->size());
0119 return md_[id.get()].first;
0120 }
0121
0122
0123
0124
0125
0126 PDGNumber ParticleParams::id_to_pdg(ParticleId id) const
0127 {
0128 CELER_EXPECT(id < this->size());
0129 return md_[id.get()].second;
0130 }
0131
0132
0133
0134
0135
0136 ParticleId ParticleParams::find(std::string const& name) const
0137 {
0138 auto iter = name_to_id_.find(name);
0139 if (iter == name_to_id_.end())
0140 {
0141 return ParticleId{};
0142 }
0143 return iter->second;
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153 ParticleId ParticleParams::find(PDGNumber pdg_code) const
0154 {
0155 auto iter = pdg_to_id_.find(pdg_code);
0156 if (iter == pdg_to_id_.end())
0157 {
0158 return ParticleId{};
0159 }
0160 return iter->second;
0161 }
0162
0163
0164 }