RayTiling.h
Go to the documentation of this file.
1 /** Define a tiling of overlapping sets rays.
2 
3  This is part of Ray Grid.
4 
5  See the WCT manual for details.
6  */
7 
8 #ifndef WIRECELL_RAYTILING
9 #define WIRECELL_RAYTILING
10 
11 #include <map>
12 #include <vector>
13 #include <string>
14 
15 #include "WireCellUtil/RayGrid.h"
16 
17 namespace WireCell {
18 
19  namespace RayGrid {
20 
21  struct Strip {
22 
23  // The index of the layer this strip is in.
25 
26  // The pitch indices bounding the strip in its layer pitch direction.
28 
30  return std::make_pair(coordinate_t{layer, bounds.first},
31  coordinate_t{layer, bounds.second});
32  }
33 
34  bool in(grid_index_t pitch_index) const {
35  return (bounds.first <= pitch_index) and (pitch_index < bounds.second);
36  }
37  bool on(grid_index_t pitch_index) const {
38  return (bounds.first <= pitch_index) and (pitch_index <= bounds.second);
39  }
40 
41  };
42  typedef std::vector<Strip> strips_t;
43 
44  // Activity represents an absolutly positioned span of pitch
45  // indices which may contain some measure of some kind of
46  // activity (ie, an ADC sum measured in the channels fed by
47  // wires represented by the rays). The activity may be
48  // indexed by pitch index. Each index n is considered to
49  // contain the activity from its pitch up to but not including
50  // the pitch of the n+1 bin.
51  class Activity {
52  public:
53  typedef double value_t;
54  typedef std::vector<value_t> vector_t;
56  typedef std::pair<iterator_t,iterator_t> range_t;
57  typedef std::vector<range_t> ranges_t;
58 
59  // Create empty activity
61 
62  // Create an activity from a range of some vector starting
63  // at given offset in the enumeration of pitch indices.
64  Activity(layer_index_t layer, const range_t& span,
65  int offset=0, double threshold=0.0);
66 
67  // Create an activity starting at offset and with each
68  // subsequent span elements set to value.
69  Activity(layer_index_t layer, size_t span, double value,
70  int offset=0, double threshold=0.0);
71 
72  // Produce a subspan activity between pitch indices [pi1, pi2)
73  Activity subspan(int pi_begin, int pi_end) const;
74 
75  layer_index_t layer() const { return m_layer; }
76 
77  iterator_t begin() const;
78  iterator_t end() const;
79 
80  bool empty() const;
81 
82  // lil helpers
83 
84  int pitch_index(const iterator_t& it) const;
85 
86  // Make a strip from a sub span of the current activity.
87  Strip make_strip(const range_t& subspan) const;
88 
89  // Return strips bounding contiguous positive activity
90  // subspans.
91  strips_t make_strips() const;
92 
93  // Return all subspans with activities
94  ranges_t active_ranges() const;
95 
96  int offset() const { return m_offset; }
97  std::string as_string() const;
98 
99  private:
100  vector_t m_span;
102  int m_offset;
103  double m_threshold;
104  };
105  typedef std::vector<Activity> activities_t;
106 
107  class Blob {
108  public:
109  void add(const Coordinates& coords, const Strip& strip);
110 
111  const strips_t& strips() const { return m_strips; }
112  strips_t& strips() { return m_strips; }
113 
114  // Blob corners are pair-wise ray crossing points which
115  // are contained by all strips.
116  const crossings_t& corners() const;
117 
118  bool valid() const {
119  size_t nstrips = m_strips.size();
120  if (nstrips == 0) { return false; } // empty
121  if (nstrips == 1) { return true; } // no corners expected
122  return corners().size() > 0;
123  }
124 
125  std::string as_string() const;
126 
127  private:
128  strips_t m_strips;
130  };
131 
132 
133  // A collection of blobs.
134  typedef std::vector<Blob> blobs_t;
135 
136  class Tiling {
137  public:
138 
139  Tiling(const Coordinates& coords);
140 
141  // Return a new activity which is shrunk to fall into the shadow of the blob.
142  Activity projection(const Blob& blob, const Activity& activity);
143 
144  // Tile activity from initial layer into blobs.
145  blobs_t operator()(const Activity& activity);
146 
147  // Refine existing blobs with the activity in a new layer.
148  blobs_t operator()(const blobs_t& prior,
149  const Activity& activity);
150 
151  private:
153  };
154 
155 
156  /// free functions
157 
158  // Remove any invalid blobs, return number removed.
159  size_t drop_invalid(blobs_t& blobs);
160 
161  // Visit each blob and prune away any portions of strips which
162  // are outside the corners. These vestigle strip portions can
163  // result when another layer provides a corner inside the
164  // strip in question.
165  void prune(const Coordinates& coords, blobs_t& blobs);
166 
167  // One stop shopping to generate blobs from activity
168  blobs_t make_blobs(const Coordinates& coords, const activities_t& activities);
169 
170 
171  inline
172  std::ostream& operator<<(std::ostream& os, const WireCell::RayGrid::Strip& s)
173  {
174  os << "<strip L" << s.layer << " pind:[" << s.bounds.first << "," << s.bounds.second << "]>";
175  return os;
176  }
177 
178  inline
179  std::ostream& operator<<(std::ostream& os, const WireCell::RayGrid::Activity& a)
180  {
181  int b = a.pitch_index(a.begin()), e = a.pitch_index(a.end());
182  auto strips = a.make_strips();
183  os << "<activity L" << a.layer() << " " << strips.size() << " strips over pind:[" << b << "," << e << "]>";
184  return os;
185  }
186 
187  inline
188  std::ostream& operator<<(std::ostream& os, const WireCell::RayGrid::Blob& b)
189  {
190  os << "<blob " << b.strips().size() << " strips, " << b.corners().size() << " corners>";
191  return os;
192  }
193 
194  inline
195  std::ostream& operator<<(std::ostream& os, const WireCell::RayGrid::crossing_t& c)
196  {
197  os << "<corner [{L" << c.first.layer << ",G" << c.first.grid << "},"
198  << "{L" << c.second.layer << ",G" << c.second.grid << "}]>";
199  return os;
200  }
201 
202  }
203 } // WireCell namespace
204 
205 #endif
206 
layer_index_t layer
Definition: RayTiling.h:24
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< decltype(adaptor(std::forward< IterB >(b))), decltype(adaptor(std::forward< IterE >(e))) >
std::string string
Definition: nybbler.cc:12
bool in(grid_index_t pitch_index) const
Definition: RayTiling.h:34
iterator_t begin() const
Definition: RayTiling.cxx:50
Coord add(Coord c1, Coord c2)
Definition: restypedef.cpp:23
strips_t make_strips() const
Definition: RayTiling.cxx:92
crossings_t m_corners
Definition: RayTiling.h:129
intermediate_table::const_iterator const_iterator
void prune(const Coordinates &coords, blobs_t &blobs)
Definition: RayTiling.cxx:334
std::vector< Strip > strips_t
Definition: RayTiling.h:42
std::vector< range_t > ranges_t
Definition: RayTiling.h:57
def blobs(cm, hist)
Definition: plots.py:79
bool valid() const
Definition: RayTiling.h:118
strips_t & strips()
Definition: RayTiling.h:112
vector_t::const_iterator iterator_t
Definition: RayTiling.h:55
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:72
size_t drop_invalid(blobs_t &blobs)
free functions
Definition: RayTiling.cxx:325
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
std::ostream & operator<<(std::ostream &os, const WireCell::RayGrid::coordinate_t &ra)
Definition: RayGrid.h:126
const double e
std::pair< grid_index_t, grid_index_t > grid_range_t
Definition: RayGrid.h:58
int pitch_index(const iterator_t &it) const
Definition: RayTiling.cxx:65
grid_range_t bounds
Definition: RayTiling.h:27
layer_index_t layer() const
Definition: RayTiling.h:75
const strips_t & strips() const
Definition: RayTiling.h:111
std::vector< value_t > vector_t
Definition: RayTiling.h:54
const Coordinates & m_coords
Definition: RayTiling.h:152
std::vector< crossing_t > crossings_t
Definition: RayGrid.h:62
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Definition: Main.h:22
std::vector< Blob > blobs_t
Definition: RayTiling.h:134
bool on(grid_index_t pitch_index) const
Definition: RayTiling.h:37
std::pair< coordinate_t, coordinate_t > crossing_t
Definition: RayGrid.h:61
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static bool * b
Definition: config.cpp:1043
blobproj_t projection(const blobvec_t &blobs, layer_index_t layer)
blobs_t make_blobs(const Coordinates &coords, const activities_t &activities)
Definition: RayTiling.cxx:371
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:67
const crossings_t & corners() const
Definition: RayTiling.cxx:202
std::vector< Activity > activities_t
Definition: RayTiling.h:105
std::pair< iterator_t, iterator_t > range_t
Definition: RayTiling.h:56
crossing_t addresses() const
Definition: RayTiling.h:29
static QCString * s
Definition: config.cpp:1042
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:92
iterator_t end() const
Definition: RayTiling.cxx:55