RaySolving.h
Go to the documentation of this file.
1 /** Solving attempts to invert the matrix equation m = G*b where m is
2  * a vector of measurements on channels, b is a vector of blobs and G
3  * is a matrix that relates the two.
4  */
5 #ifndef WIRECELL_RAYSOLVING_H
6 #define WIRECELL_RAYSOLVING_H
7 
8 #include <boost/graph/graph_traits.hpp>
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/graph/connected_components.hpp>
11 
12 #include <Eigen/Dense>
13 
14 #include <vector>
15 #include <unordered_map>
16 
17 namespace WireCell {
18 
19  namespace RayGrid {
20 
21  class Grouping {
22  public:
23  Grouping() = default;
24  virtual ~Grouping() = default;
25 
26  typedef size_t ident_t;
27  struct node_t {
28  char ntype; // 'm', 'w', or 's'
29  ident_t ident; // an ident for a 'm' or an 's'
30  float value;
31  float weight;
32  };
33  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, node_t> graph_t;
34  typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t;
35 
36  // Add an 'm' or 's' type node.
37  virtual void add(char ntype, ident_t chid, std::vector<ident_t> wids,
38  float value, float weight=1.0);
39 
40  typedef std::vector<node_t> cluster_t;
41  typedef std::unordered_map<int, cluster_t> clusterset_t;
42 
43  // Return nodes in connected subgraphs
44  clusterset_t clusters();
45 
46  graph_t& graph() { return m_graph; }
47 
48  private:
49  graph_t m_graph;
50  std::unordered_map<ident_t, vertex_t> m_wid2vtx;
51 
52  // helper
53  vertex_t wire_node(ident_t wid);
54 
55  };
56 
57 
58 
59  class Solving {
60  public:
61  Solving() = default;
62  ~Solving() = default;
63 
64  typedef size_t ident_t;
65  struct node_t {
66  char ntype; // 'm' or 's'
67  ident_t ident; // an ident number for a 'm' or an 's'
68  float value;
69  float weight;
70  };
71  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, node_t> graph_t;
72  typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t;
73 
74  //
75  void add(const Grouping::clusterset_t& cset);
76 
77  // Solve for "S", return map from original source ident to solved value.
78  typedef std::unordered_map<ident_t, float> solution_t;
79  solution_t solve();
80 
81  graph_t& graph() { return m_graph; }
82 
83  private:
84 
85  graph_t m_graph;
86  std::unordered_map<ident_t, vertex_t> m_sid2vtx;
87 
88  vertex_t measurement_node(float value, float weight);
89  vertex_t source_node(ident_t sid, float value, float weight);
90 
91  void solve_one(solution_t& answer,
92  const std::vector<vertex_t>& sources,
93  const std::vector<vertex_t>& measures);
94 
95  };
96 
97 
98  } // RayGrid
99 
100 
101 } // WireCell
102 
103 
104 
105 #endif /* WIRECELL_RAYSOLVING_H */
std::unordered_map< ident_t, vertex_t > m_wid2vtx
Definition: RaySolving.h:50
vector_t solve(matrix_t response, vector_t measured, const Params &params=Params(), vector_t source=Eigen::VectorXd(), vector_t weights=Eigen::VectorXd())
Definition: Ress.cxx:7
std::unordered_map< ident_t, vertex_t > m_sid2vtx
Definition: RaySolving.h:86
std::unordered_map< int, cluster_t > clusterset_t
Definition: RaySolving.h:41
boost::graph_traits< graph_t >::vertex_descriptor vertex_t
Definition: RaySolving.h:72
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, node_t > graph_t
Definition: RaySolving.h:33
vertex_t wire_node(ident_t wid)
Definition: RaySolving.cxx:6
boost::graph_traits< graph_t >::vertex_descriptor vertex_t
Definition: RaySolving.h:34
virtual void add(char ntype, ident_t chid, std::vector< ident_t > wids, float value, float weight=1.0)
Definition: RaySolving.cxx:21
Definition: Main.h:22
std::unordered_map< ident_t, float > solution_t
Definition: RaySolving.h:78
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, node_t > graph_t
Definition: RaySolving.h:71
std::vector< node_t > cluster_t
Definition: RaySolving.h:40
tbb::flow::source_node< boost::any > source_node
virtual ~Grouping()=default