ComPWA
Common Partial-Wave-Analysis Framework
Properties.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #ifndef COMPWA_PROPERTIES_HPP_
6 #define COMPWA_PROPERTIES_HPP_
7 
8 #include "Core/Exceptions.hpp"
9 #include "Core/FitParameter.hpp"
10 
11 #include "boost/property_tree/ptree.hpp"
12 
13 #include <map>
14 #include <set>
15 #include <vector>
16 
17 namespace ComPWA {
18 
22 typedef int pid;
23 
28 public:
29  ParticleProperties(boost::property_tree::ptree pt);
30 
31  std::string getName() const { return Name; }
32 
33  pid getId() const { return Id; }
34 
36 
37  template <typename T> T getQuantumNumber(std::string type) const;
38 
39  boost::property_tree::ptree getDecayInfo() const { return DecayInfo; }
40 
41  std::string getDecayType() const {
42  return DecayInfo.get<std::string>("<xmlattr>.Type");
43  }
44 
45  friend bool operator<(const ParticleProperties &l,
46  const ParticleProperties &r) {
47  return l.Id < r.Id;
48  }
49 
50 private:
51  std::string Name;
52  pid Id;
54  std::map<std::string, int> IntQuantumNumbers;
55  std::map<std::string, double> RealQuantumNumbers;
56 
59  boost::property_tree::ptree DecayInfo;
60 };
61 
62 template <>
63 inline int ParticleProperties::getQuantumNumber(std::string type) const {
64  auto it = IntQuantumNumbers.find(type);
65  if (it == IntQuantumNumbers.end())
66  throw std::runtime_error("ParticleProperties::getQuantumNumber<int>() | "
67  "Quantum Number '" +
68  type + "' not found!");
69 
70  return it->second;
71 }
72 
73 template <>
74 inline double ParticleProperties::getQuantumNumber(std::string type) const {
75  auto it = RealQuantumNumbers.find(type);
76  if (it == RealQuantumNumbers.end())
77  throw std::runtime_error("ParticleProperties::getQuantumNumber<double>() | "
78  "Quantum Number '" +
79  type + "' not found!");
80 
81  return it->second;
82 }
83 
84 using ParticleList = std::set<ParticleProperties>;
85 
86 inline std::ostream &operator<<(std::ostream &os, const ParticleList &p) {
87  for (auto i : p)
88  os << i.getName() << " [ " << i.getId()
89  << " ]: mass = " << i.getMass().Value << std::endl;
90  return os;
91 }
92 
93 inline const ParticleProperties &findParticle(const ParticleList &list,
94  pid Pid) {
95  auto found = std::find_if(list.begin(), list.end(),
96  [&Pid](auto const &x) { return x.getId() == Pid; });
97  if (list.end() == found) {
98  throw std::runtime_error("Could not find particle with id " +
99  std::to_string(Pid) + " in list");
100  }
101  return *found;
102 }
103 
104 inline const ParticleProperties &findParticle(const ParticleList &list,
105  std::string refname) {
106  auto found =
107  std::find_if(list.begin(), list.end(), [&refname](auto const &x) {
108  return x.getName() == refname;
109  });
110  if (list.end() == found) {
111  throw std::runtime_error("Could not find particle with name " + refname +
112  " in list");
113  }
114  return *found;
115 }
116 
118 void insertParticles(ParticleList &list, const boost::property_tree::ptree &pt);
119 
121 void insertParticles(ParticleList &list, std::stringstream &Stream);
122 
124 void insertParticles(ParticleList &list, std::string FileName);
125 
128 ParticleList readParticles(std::stringstream &Stream);
129 
131 ParticleList readParticles(std::string FileName);
132 
134 ParticleList readParticles(boost::property_tree::ptree &pt);
135 
136 } // namespace ComPWA
137 
138 #endif
std::string getDecayType() const
Definition: Properties.hpp:41
ParticleProperties(boost::property_tree::ptree pt)
Definition: Properties.cpp:14
T getQuantumNumber(std::string type) const
ComPWA::FitParameter< double > Mass
Definition: Properties.hpp:53
ComPWA::FitParameter< double > getMass() const
Definition: Properties.hpp:35
std::ostream & operator<<(std::ostream &os, const Event &ev)
Definition: Event.cpp:11
ComPWA exceptions.
ParticleList readParticles(std::stringstream &Stream)
Read list of particles from a stringstream For some reason the boost xml parser needs a non-const ref...
Definition: Properties.cpp:151
const ParticleProperties & findParticle(const ParticleList &list, pid Pid)
Definition: Properties.hpp:93
std::set< ParticleProperties > ParticleList
Definition: Properties.hpp:84
friend bool operator<(const ParticleProperties &l, const ParticleProperties &r)
Definition: Properties.hpp:45
boost::property_tree::ptree getDecayInfo() const
Definition: Properties.hpp:39
void insertParticles(ParticleList &list, const boost::property_tree::ptree &pt)
Read list of particles from a boost::property_tree.
Definition: Properties.cpp:95
std::string getName() const
Definition: Properties.hpp:31
int pid
Particle ID.
Definition: Properties.hpp:22
std::map< std::string, double > RealQuantumNumbers
Definition: Properties.hpp:55
boost::property_tree::ptree DecayInfo
Store decay info in property_tree.
Definition: Properties.hpp:59
std::map< std::string, int > IntQuantumNumbers
Definition: Properties.hpp:54