ComPWA
Common Partial-Wave-Analysis Framework
SubSystem.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 
9 
10 #ifndef COMPWA_PHYSICS_SUBSYSTEM_HPP_
11 #define COMPWA_PHYSICS_SUBSYSTEM_HPP_
12 
13 #include <functional>
14 #include <vector>
15 
16 #include <boost/property_tree/ptree.hpp>
17 
18 namespace ComPWA {
19 
20 typedef std::vector<unsigned int> IndexList;
21 
22 namespace Physics {
23 
31 class SubSystem {
32 public:
33  SubSystem(const std::vector<std::vector<unsigned int>> &FinalStates,
34  const std::vector<unsigned int> &Recoil,
35  const std::vector<unsigned int> &ParentRecoil);
36 
37  virtual ~SubSystem() = default;
38 
39  bool operator==(const SubSystem &b) const;
40 
41  friend std::ostream &operator<<(std::ostream &stream, const SubSystem &s);
42  virtual const std::vector<std::vector<unsigned int>> &getFinalStates() const;
43  virtual const std::vector<unsigned int> &getRecoilState() const;
44  virtual const std::vector<unsigned int> &getParentRecoilState() const;
45 
46 private:
47  std::vector<std::vector<unsigned int>> DecayProductFinalStates;
48  std::vector<unsigned int> RecoilFinalState;
49  std::vector<unsigned int> ParentRecoilFinalState;
50 };
51 
54 inline std::vector<unsigned int> stringToVectInt(std::string str) {
55  std::vector<unsigned int> result;
56  std::istringstream iStr(str);
57  std::vector<std::string> stringFrag{std::istream_iterator<std::string>{iStr},
58  std::istream_iterator<std::string>{}};
59  for (auto i : stringFrag) {
60  result.push_back(std::stoul(i));
61  }
62  return result;
63 }
64 
65 } // namespace Physics
66 } // namespace ComPWA
67 
68 namespace std {
69 
70 // this function was copied from boost
71 template <typename T> std::size_t combineHash(size_t hash, const T &v) {
72  hash ^= std::hash<T>()(v) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
73  return hash;
74 }
75 template <> struct hash<ComPWA::IndexList> {
76  std::size_t operator()(const ComPWA::IndexList &key) const {
77  std::size_t seed = key.size();
78  for (unsigned int i : key) {
79  seed = combineHash(seed, i);
80  }
81  return seed;
82  }
83 };
84 
85 template <> struct hash<ComPWA::Physics::SubSystem> {
86  std::size_t operator()(const ComPWA::Physics::SubSystem &key) const {
87  std::size_t seed = key.getFinalStates().size();
88  for (auto const &x : key.getFinalStates()) {
89  seed = combineHash(seed, x);
90  }
91  seed = combineHash(seed, key.getRecoilState());
92  seed = combineHash(seed, key.getParentRecoilState());
93 
94  return seed;
95  }
96 };
97 
98 } // namespace std
99 
100 #endif
virtual ~SubSystem()=default
std::size_t combineHash(size_t hash, const T &v)
Definition: SubSystem.hpp:71
virtual const std::vector< unsigned int > & getParentRecoilState() const
Definition: SubSystem.cpp:56
std::vector< unsigned int > stringToVectInt(std::string str)
Helper funtions to transfor a string of space-separated numbers to a vector<unsigned int>...
Definition: SubSystem.hpp:54
virtual const std::vector< unsigned int > & getRecoilState() const
Definition: SubSystem.cpp:52
friend std::ostream & operator<<(std::ostream &stream, const SubSystem &s)
Definition: SubSystem.cpp:23
std::vector< unsigned int > IndexList
Definition: SubSystem.hpp:20
virtual const std::vector< std::vector< unsigned int > > & getFinalStates() const
Definition: SubSystem.cpp:48
SubSystem(const std::vector< std::vector< unsigned int >> &FinalStates, const std::vector< unsigned int > &Recoil, const std::vector< unsigned int > &ParentRecoil)
Definition: SubSystem.cpp:10
bool operator==(const SubSystem &b) const
Definition: SubSystem.cpp:38
std::vector< std::vector< unsigned int > > DecayProductFinalStates
Definition: SubSystem.hpp:47
std::vector< unsigned int > RecoilFinalState
Definition: SubSystem.hpp:48
std::vector< unsigned int > ParentRecoilFinalState
Definition: SubSystem.hpp:49
Definition of a two-body decay node within a sequential decay tree.
Definition: SubSystem.hpp:31