RayGrid.h
Go to the documentation of this file.
1 /** A ray grid is defined by pair-wise layers of parallel, ordered pairs of rays.
2  *
3  * This file includes the implemenation for a ray grid as well as
4  * classes and functions that operate with it.
5  *
6  * See section in the WCT manual for details.
7  */
8 
9 #ifndef WIRECELL_RAYGRID
10 #define WIRECELL_RAYGRID
11 
12 #include "WireCellUtil/Point.h"
14 
15 #include <boost/multi_array.hpp>
16 
17 #include <vector>
18 #include <map>
19 
20 
21 namespace WireCell {
22 
23  namespace RayGrid {
24 
25  // A ray grid layer associates the set of parallel rays
26  // generated from the seeding pair. All layers in a ray grid
27  // are considered co-planar.
28  typedef int layer_index_t;
29 
30  // Within one layer any ray may be identified by its index in
31  // a uniform linear grid. Grid index 0 is the first ray of
32  // the defining pair, grid index 1 is the second.
33  typedef int grid_index_t;
34 
35  // A ray is located in the ray grid through its layer and its
36  // grid indices.
37  struct coordinate_t {
38  layer_index_t layer;
39  grid_index_t grid;
40  };
41 
42  // Identify a pair of layers.
43  typedef std::pair<layer_index_t, layer_index_t> layer_pair_t;
44 
45  // Identify a triple of layers.
46  typedef std::tuple<layer_index_t, layer_index_t, layer_index_t> layer_triple_t;
47 
48  // A tensor type used to connect two ray coordinates and their
49  // crossing point location in a third layer.
50  typedef boost::multi_array<double, 3> tensor_t;
51 
52  // A 1D array of Vectors.
53  typedef std::vector<Vector> vector_array1d_t;
54  // A 2D array'ish of Vectors.
56 
57  // A half open range between two grid indices.
58  typedef std::pair<grid_index_t, grid_index_t> grid_range_t;
59 
60  // A crossing is identified by the addresses of two rays.
61  typedef std::pair<coordinate_t,coordinate_t> crossing_t;
62  typedef std::vector<crossing_t> crossings_t;
63 
64 
65  // was class RayGrid
66  class Coordinates {
67  public:
68 
69  // Create a ray grid by specifying the axis of projection.
70  Coordinates(const ray_pair_vector_t& rays,
71  int normal_axis=0, double normal_location = 0.0);
72 
73  // Return the crossing point of the index=0 rays for two layers.
74  Vector zero_crossing(layer_index_t one, layer_index_t two) const;
75 
76  // Return the crossing point of two rays.
77  Vector ray_crossing(const coordinate_t& one, const coordinate_t& two) const;
78 
79  // Return the pitch location measured in an other layer give of the crossing point of two rays
80  double pitch_location(const coordinate_t& one, const coordinate_t& two, layer_index_t other) const;
81 
82  int pitch_index(double pitch, layer_index_t layer) const {
83  return std::floor(pitch/m_pitch_mag[layer]);
84  }
85 
86  int nlayers() const { return m_nlayers; }
87  const std::vector<double>& pitch_mags() const { return m_pitch_mag; }
88  const vector_array1d_t& pitch_dirs() const { return m_pitch_dir; }
89  const vector_array1d_t& centers() const { return m_center; }
90 
91  const vector_array2d_t& ray_jumps() const { return m_ray_jump; }
92 
93  const tensor_t a() const { return m_a; }
94  const tensor_t b() const { return m_b; }
95 
96  private:
97 
98  int m_nlayers;
99 
100  // Pitch magnitude for each layer
101  std::vector<double> m_pitch_mag;
102 
103  // The unit vector in the pitch direction for each layer
104  vector_array1d_t m_pitch_dir;
105 
106  // A point (center point) on ray 0 of each layer
107  vector_array1d_t m_center;
108 
109  // Zero-rays crossing points indexed by layer index pairs.
110  // Symmetric array, diagonal is invalid.
111  vector_array2d_t m_zero_crossing;
112 
113  // Element (l,m) holds a relative vector which jumps along ray
114  // direction of layer l between crossing points of neighboring
115  // rays of layer m. Not symmectric, and diagonal is invalid.
116  vector_array2d_t m_ray_jump;
117 
118  // Coefficients for fast pitch location calculation. These
119  // are scalar values indexed by three different layer
120  // indicies.
121  tensor_t m_a, m_b;
122 
123  };
124 
125  inline
126  std::ostream& operator<<(std::ostream& os, const WireCell::RayGrid::coordinate_t& ra)
127  {
128  os << "<rayaddr {L" << ra.layer << ",G" << ra.grid <<"}>";
129  return os;
130  }
131 
132  } // RayGrid namespace
133 } // WireCell namespace
134 
135 
136 #endif
vector_array2d_t m_ray_jump
Definition: RayGrid.h:116
const vector_array2d_t & ray_jumps() const
Definition: RayGrid.h:91
ObjectArray2d< Vector > vector_array2d_t
Definition: RayGrid.h:55
vector_array2d_t m_zero_crossing
Definition: RayGrid.h:111
vector_array1d_t m_pitch_dir
Definition: RayGrid.h:104
std::vector< double > m_pitch_mag
Definition: RayGrid.h:101
const vector_array1d_t & pitch_dirs() const
Definition: RayGrid.h:88
std::ostream & operator<<(std::ostream &os, const WireCell::RayGrid::coordinate_t &ra)
Definition: RayGrid.h:126
const tensor_t a() const
Definition: RayGrid.h:93
int pitch_index(double pitch, layer_index_t layer) const
Definition: RayGrid.h:82
std::pair< grid_index_t, grid_index_t > grid_range_t
Definition: RayGrid.h:58
const tensor_t b() const
Definition: RayGrid.h:94
const vector_array1d_t & centers() const
Definition: RayGrid.h:89
const std::vector< double > & pitch_mags() const
Definition: RayGrid.h:87
vector_array1d_t m_center
Definition: RayGrid.h:107
std::tuple< layer_index_t, layer_index_t, layer_index_t > layer_triple_t
Definition: RayGrid.h:46
std::vector< crossing_t > crossings_t
Definition: RayGrid.h:62
std::vector< ray_pair_t > ray_pair_vector_t
Definition: Point.h:27
Definition: Main.h:22
std::pair< coordinate_t, coordinate_t > crossing_t
Definition: RayGrid.h:61
std::pair< layer_index_t, layer_index_t > layer_pair_t
Definition: RayGrid.h:43
boost::multi_array< double, 3 > tensor_t
Definition: RayGrid.h:50
std::vector< Vector > vector_array1d_t
Definition: RayGrid.h:53