File indexing completed on 2025-01-18 09:55:41
0001
0002
0003
0004 #pragma once
0005
0006 #include <algorithms/service.h>
0007 #include <map>
0008 #include <memory>
0009 #include <string>
0010
0011 namespace algorithms {
0012
0013 class ParticleSvc : public Service<ParticleSvc> {
0014 public:
0015 struct ParticleData {
0016 int pdgCode;
0017 int charge;
0018 double mass;
0019 std::string name;
0020 };
0021 using Particle = ParticleData;
0022 using ParticleMap = std::map<int, Particle>;
0023
0024 private:
0025 static const std::shared_ptr<ParticleMap> kParticleMap;
0026
0027 public:
0028 virtual void init(std::shared_ptr<ParticleMap> map = kParticleMap) {
0029 if (map != nullptr) {
0030 m_particleMap = map;
0031 }
0032 }
0033
0034 virtual std::shared_ptr<ParticleMap> particleMap() const {
0035 return m_particleMap;
0036 };
0037
0038 virtual Particle& particle(int pdg) const {
0039 if (m_particleMap->count(pdg) == 0) {
0040 return m_particleMap->at(0);
0041 }
0042 return m_particleMap->at(pdg);
0043 };
0044
0045 protected:
0046 std::shared_ptr<ParticleMap> m_particleMap{nullptr};
0047
0048 ALGORITHMS_DEFINE_SERVICE(ParticleSvc)
0049 };
0050
0051 }