File indexing completed on 2025-02-22 10:31:29
0001
0002
0003
0004
0005
0006
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
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 class ParticleParams final : public ParamsDataInterface<ParticleParamsData>
0049 {
0050 public:
0051
0052 struct ParticleInput
0053 {
0054 std::string name;
0055 PDGNumber pdg_code;
0056 units::MevMass mass;
0057 units::ElementaryCharge charge;
0058 real_type decay_constant;
0059 };
0060
0061
0062 using Input = std::vector<ParticleInput>;
0063
0064 public:
0065
0066 static std::shared_ptr<ParticleParams> from_import(ImportData const& data);
0067
0068
0069 explicit ParticleParams(Input const& defs);
0070
0071
0072
0073
0074 ParticleId::size_type size() const { return md_.size(); }
0075
0076
0077 inline std::string const& id_to_label(ParticleId id) const;
0078
0079
0080 inline PDGNumber id_to_pdg(ParticleId id) const;
0081
0082
0083 inline ParticleId find(std::string const& name) const;
0084
0085
0086 inline ParticleId find(PDGNumber pdg_code) const;
0087
0088
0089 ParticleView get(ParticleId id) const;
0090
0091
0092 HostRef const& host_ref() const final { return data_.host_ref(); }
0093
0094
0095 DeviceRef const& device_ref() const final { return data_.device_ref(); }
0096
0097 private:
0098
0099 std::vector<std::pair<std::string, PDGNumber>> md_;
0100
0101
0102 std::unordered_map<std::string, ParticleId> name_to_id_;
0103
0104
0105 std::unordered_map<PDGNumber, ParticleId> pdg_to_id_;
0106
0107
0108 CollectionMirror<ParticleParamsData> data_;
0109 };
0110
0111
0112
0113
0114
0115
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
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
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
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 }