Public Member Functions | Private Member Functions | Private Attributes | List of all members
WireCell::Img::BlobClustering Class Reference

#include <BlobClustering.h>

Inheritance diagram for WireCell::Img::BlobClustering:
WireCell::IClustering WireCell::IConfigurable WireCell::IQueuedoutNode< IBlobSet, ICluster > WireCell::IComponent< IConfigurable > WireCell::IQueuedoutNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 BlobClustering ()
 
virtual ~BlobClustering ()
 
virtual void configure (const WireCell::Configuration &cfg)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
virtual bool operator() (const input_pointer &blobset, output_queue &clusters)
 The calling signature: More...
 
- Public Member Functions inherited from WireCell::IClustering
virtual ~IClustering ()
 
virtual std::string signature ()
 
- Public Member Functions inherited from WireCell::IQueuedoutNode< IBlobSet, ICluster >
virtual ~IQueuedoutNode ()
 
virtual bool operator() (const boost::any &anyin, queuedany &outanyq)
 The calling signature: More...
 
virtual std::vector< std::stringinput_types ()
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::IQueuedoutNodeBase
virtual ~IQueuedoutNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual int concurrency ()
 By default assume all subclasses maintain state. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual void reset ()
 
- Public Member Functions inherited from WireCell::IComponent< INode >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Member Functions

void add_slice (const ISlice::pointer &islice)
 
void add_blobs (const input_pointer &newbs)
 
void flush (output_queue &clusters)
 
bool graph_bs (const input_pointer &newbs)
 
bool judge_gap (const input_pointer &newbs)
 
void intern (const input_pointer &newbs)
 

Private Attributes

double m_spans
 
IBlobSet::pointer m_last_bs
 
cluster_indexed_graph_t m_grind
 
Log::logptr_t l
 

Additional Inherited Members

- Public Types inherited from WireCell::IClustering
typedef std::shared_ptr< IClusteringpointer
 
- Public Types inherited from WireCell::IQueuedoutNode< IBlobSet, ICluster >
typedef std::shared_ptr< IQueuedoutNodeBasepointer
 
typedef IBlobSet input_type
 
typedef ICluster output_type
 
typedef std::shared_ptr< const IBlobSetinput_pointer
 
typedef std::shared_ptr< const IClusteroutput_pointer
 
typedef std::deque< output_pointeroutput_queue
 
- Public Types inherited from WireCell::IQueuedoutNodeBase
typedef std::shared_ptr< IQueuedoutNodeBasepointer
 
typedef std::deque< boost::any > queuedany
 
- Public Types inherited from WireCell::INode
enum  NodeCategory {
  unknown, sourceNode, sinkNode, functionNode,
  queuedoutNode, joinNode, splitNode, faninNode,
  fanoutNode, multioutNode, hydraNode
}
 
- Public Types inherited from WireCell::IComponent< INode >
typedef std::shared_ptr< INodepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 40 of file BlobClustering.h.

Constructor & Destructor Documentation

Img::BlobClustering::BlobClustering ( )

Definition at line 14 of file BlobClustering.cxx.

15  : m_spans(1.0)
16  , m_last_bs(nullptr)
17  , l(Log::logger("img"))
18 {
19 }
logptr_t logger(std::string name)
Definition: Logging.cxx:71
Img::BlobClustering::~BlobClustering ( )
virtual

Definition at line 20 of file BlobClustering.cxx.

21 {
22 }

Member Function Documentation

void Img::BlobClustering::add_blobs ( const input_pointer newbs)
private

Definition at line 86 of file BlobClustering.cxx.

87 {
88  for (const auto& iblob : newbs->blobs()) {
89  auto islice = iblob->slice();
90  add_slice(islice);
91  m_grind.edge(islice, iblob);
92 
93  auto iface = iblob->face();
94  auto wire_planes = iface->planes();
95 
96  const auto& shape = iblob->shape();
97  for (const auto& strip : shape.strips()) {
98  // FIXME: need a way to encode this convention!
99  // For now, it requires collusion. Don't impeach me.
100  const int num_nonplane_layers = 2;
101  int iplane = strip.layer - num_nonplane_layers;
102  if (iplane < 0) {
103  continue;
104  }
105  const auto& wires = wire_planes[iplane]->wires();
106  for (int wip=strip.bounds.first; wip < strip.bounds.second and wip < int(wires.size()); ++wip) {
107  auto iwire = wires[wip];
108  m_grind.edge(iblob, iwire);
109  }
110  }
111  }
112 }
void add_slice(const ISlice::pointer &islice)
cluster_indexed_graph_t m_grind
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
Definition: IndexedGraph.h:93
void Img::BlobClustering::add_slice ( const ISlice::pointer islice)
private

Definition at line 69 of file BlobClustering.cxx.

70 {
71  if (m_grind.has(islice)) {
72  return;
73  }
74 
75  for (const auto& ichv : islice->activity()) {
76  const IChannel::pointer ich = ichv.first;
77  if (m_grind.has(ich)) {
78  continue;
79  }
80  for (const auto& iwire : ich->wires()) {
81  m_grind.edge(ich, iwire);
82  }
83  }
84 }
std::shared_ptr< const IChannel > pointer
Definition: IData.h:19
cluster_indexed_graph_t m_grind
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
Definition: IndexedGraph.h:93
bool has(vertex_t vobj) const
Definition: IndexedGraph.h:84
void Img::BlobClustering::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 24 of file BlobClustering.cxx.

25 {
26  m_spans = get(cfg, "spans", m_spans);
27 }
cfg
Definition: dbjson.py:29
WireCell::Configuration Img::BlobClustering::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 29 of file BlobClustering.cxx.

30 {
32  // A number multiplied to the span of the current slice when
33  // determining it a gap exists between the next slice. Default is
34  // 1.0. Eg, if set to 2.0 then a single missing slice won't be
35  // grounds for considering a gap in the cluster. A number less
36  // than 1.0 will cause each "cluster" to consist of only one blob.
37  cfg["spans"] = m_spans;
38  return cfg;
39 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
void Img::BlobClustering::flush ( output_queue clusters)
private

Definition at line 41 of file BlobClustering.cxx.

42 {
43  clusters.push_back(std::make_shared<SimpleCluster>(m_grind.graph()));
44  m_grind.clear();
45  m_last_bs = nullptr;
46 }
const graph_t & graph() const
Definition: IndexedGraph.h:141
cluster_indexed_graph_t m_grind
bool Img::BlobClustering::graph_bs ( const input_pointer newbs)
private

Definition at line 114 of file BlobClustering.cxx.

115 {
116  add_blobs(newbs);
117 
118  if (!m_last_bs) {
119  // need to wait for next one to do anything.
120  // note, caller interns.
121  return false;
122  }
123  if (judge_gap(newbs)) {
124  // nothing to do, but pass on that we hit a gap
125  return true;
126  }
127 
128  // handle each face separately faces
129  IBlob::vector iblobs1 = newbs->blobs();
130  IBlob::vector iblobs2 = m_last_bs->blobs();
131 
132  RayGrid::blobs_t blobs1 = newbs->shapes();
133  RayGrid::blobs_t blobs2 = m_last_bs->shapes();
134 
135  const auto beg1 = blobs1.begin();
136  const auto beg2 = blobs2.begin();
137 
138  auto assoc = [&](RayGrid::blobref_t& a, RayGrid::blobref_t& b) {
139  int an = a - beg1;
140  int bn = b - beg2;
141  m_grind.edge(iblobs1[an], iblobs2[bn]);
142  };
143  RayGrid::associate(blobs1, blobs2, assoc);
144 
145 
146 
147  return false;
148 }
std::vector< pointer > vector
Definition: IData.h:21
void add_blobs(const input_pointer &newbs)
void associate(const blobs_t &one, const blobs_t &two, associator_t func)
cluster_indexed_graph_t m_grind
blobs_t::const_iterator blobref_t
Definition: RayClustering.h:13
bool judge_gap(const input_pointer &newbs)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
std::vector< Blob > blobs_t
Definition: RayTiling.h:134
static bool * b
Definition: config.cpp:1043
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
Definition: IndexedGraph.h:93
void Img::BlobClustering::intern ( const input_pointer newbs)
private

Definition at line 48 of file BlobClustering.cxx.

49 {
50  m_last_bs = newbs;
51 }
bool Img::BlobClustering::judge_gap ( const input_pointer newbs)
private

Definition at line 53 of file BlobClustering.cxx.

54 {
55  const double epsilon = 1*units::ns;
56 
57  if (m_spans <= epsilon) {
58  return false; // never break on gap.
59  }
60 
61  auto nslice = newbs->slice();
62  auto oslice = m_last_bs->slice();
63 
64  const double dt = nslice->start() - oslice->start();
65  return std::abs(dt - m_spans*oslice->span()) > epsilon;
66 }
T abs(T value)
static const double ns
Definition: Units.h:102
bool Img::BlobClustering::operator() ( const input_pointer in,
output_queue outq 
)
virtual

The calling signature:

Implements WireCell::IQueuedoutNode< IBlobSet, ICluster >.

Definition at line 150 of file BlobClustering.cxx.

151 {
152  if (!blobset) { // eos
153  l->debug("BlobClustering: EOS");
154  flush(clusters);
155  clusters.push_back(nullptr); // forward eos
156  return true;
157  }
158 
159  SPDLOG_LOGGER_TRACE(l,"BlobClustering: got {} blobs", blobset->blobs().size());
160 
161  bool gap = graph_bs(blobset);
162  if (gap) {
163  flush(clusters);
164  l->debug("BlobClustering: sending {} clusters", clusters.size());
165  // note: flush fast to keep memory usage in this component
166  // down and because in an MT job, downstream components might
167  // benefit to start consuming clusters ASAP. We do NOT want
168  // to intern() the new blob set BEFORE a flush if there is a
169  // gap because newbs is needed for next time and fush clears
170  // the cache.
171  }
172 
173  intern(blobset);
174 
175  SPDLOG_LOGGER_TRACE(l,"BlobClustering: holding {}", boost::num_vertices(m_grind.graph()));
176 
177  return true;
178 }
const graph_t & graph() const
Definition: IndexedGraph.h:141
cluster_indexed_graph_t m_grind
void intern(const input_pointer &newbs)
bool graph_bs(const input_pointer &newbs)
#define SPDLOG_LOGGER_TRACE(logger,...)
Definition: spdlog.h:319
void flush(output_queue &clusters)

Member Data Documentation

Log::logptr_t WireCell::Img::BlobClustering::l
private

Definition at line 77 of file BlobClustering.h.

cluster_indexed_graph_t WireCell::Img::BlobClustering::m_grind
private

Definition at line 59 of file BlobClustering.h.

IBlobSet::pointer WireCell::Img::BlobClustering::m_last_bs
private

Definition at line 57 of file BlobClustering.h.

double WireCell::Img::BlobClustering::m_spans
private

Definition at line 54 of file BlobClustering.h.


The documentation for this class was generated from the following files: