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

#include <NaiveStriper.h>

Inheritance diagram for WireCell::Img::NaiveStriper:
WireCell::ISliceStriper WireCell::IConfigurable WireCell::IFunctionNode< ISlice, IStripeSet > WireCell::IComponent< IConfigurable > WireCell::IFunctionNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

virtual ~NaiveStriper ()
 
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 &in, output_pointer &out)
 The calling signature: More...
 
- Public Member Functions inherited from WireCell::ISliceStriper
virtual ~ISliceStriper ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::IFunctionNode< ISlice, IStripeSet >
virtual ~IFunctionNode ()
 
virtual bool operator() (const boost::any &anyin, boost::any &anyout)
 The calling signature: More...
 
virtual std::vector< std::stringinput_types ()
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::IFunctionNodeBase
virtual ~IFunctionNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual int concurrency ()
 By default assume all subclasses are stateless. 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 Attributes

size_t m_gap
 

Additional Inherited Members

- Public Types inherited from WireCell::ISliceStriper
typedef std::shared_ptr< ISliceStriperpointer
 
- Public Types inherited from WireCell::IFunctionNode< ISlice, IStripeSet >
typedef ISlice input_type
 
typedef IStripeSet output_type
 
typedef std::shared_ptr< const ISliceinput_pointer
 
typedef std::shared_ptr< const IStripeSetoutput_pointer
 
typedef IFunctionNode< ISlice, IStripeSetsignature_type
 
- Public Types inherited from WireCell::IFunctionNodeBase
typedef std::shared_ptr< IFunctionNodeBasepointer
 
- 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 16 of file NaiveStriper.h.

Constructor & Destructor Documentation

Img::NaiveStriper::~NaiveStriper ( )
virtual

Definition at line 17 of file NaiveStriper.cxx.

18 {
19 }

Member Function Documentation

void Img::NaiveStriper::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 33 of file NaiveStriper.cxx.

34 {
35  m_gap = get(cfg, "gap", 1);
36 }
cfg
Definition: dbjson.py:29
WireCell::Configuration Img::NaiveStriper::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 21 of file NaiveStriper.cxx.

22 {
24 
25  // The number of intersticial wires which must exist without
26  // activity to consider two wires to be non-adjacent.
27  cfg["gap"] = 1;
28 
29  return cfg;
30 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Img::NaiveStriper::operator() ( const input_pointer in,
output_pointer out 
)
virtual

The calling signature:

Implements WireCell::IFunctionNode< ISlice, IStripeSet >.

Definition at line 39 of file NaiveStriper.cxx.

40 {
41  out = nullptr;
42  if (!slice) {
43  return true; // eos
44  }
45 
46  // The graph connects channels to attached wires and wires to
47  // their adjacent neighbor in the plane and along the positive
48  // pitch direction.
49 
50  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> graph_t;
51  typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t;
52  graph_t graph;
53 
54  // Boost graph uses simple numbers as the "node object". We could
55  // attach vertex properties to nodes to hold either the IWire or
56  // the IChannel+charge values or we can keep or own lookup tables.
57  // The former is probably faster but for now, we these lookups out
58  // in the open.
59  std::unordered_map<IWire::pointer, IChannel::pointer> wire_to_chan;
60  std::unordered_map<IChannel::pointer, vertex_t> chan_to_node;
61  std::unordered_map<vertex_t, ISlice::pair_t> node_to_chanval;
62  std::unordered_map<int, IWireIndexSet> hit_wires;
63 
64  // Fill channel nodes in graph and group wires by plane
65  for (const auto& cv : slice->activity()) {
66  auto ichan = cv.first;
67  auto node = boost::add_vertex(graph);
68  chan_to_node[ichan] = node;
69  node_to_chanval[node] = cv;
70  for (auto iwire : ichan->wires()) {
71  const auto pid = iwire->planeid();
72  hit_wires[pid.ident()].insert(iwire);
73  wire_to_chan[iwire] = ichan;
74  }
75  }
76 
77  // Loop over ordered wires per plane and make edges.
78  for (const auto& phw : hit_wires) {
79  int last_ind = -1;
80  vertex_t last_wire = 0;
81  for (auto iwire : phw.second) {
82  auto ichan = wire_to_chan[iwire];
83  vertex_t chan_node = chan_to_node[ichan];
84  vertex_t wire_node = boost::add_vertex(graph);
85  const int this_index = iwire->index();
86 
87  // no matter what, chan->node.
88  boost::add_edge(chan_node, wire_node, graph);
89 
90  const size_t dind = this_index - last_ind;
91  if (last_ind >= 0 and dind <= m_gap) {
92  boost::add_edge(last_wire, wire_node, graph);
93  }
94  last_ind = this_index;
95  last_wire = wire_node;
96  }
97  }
98 
99  // Here's the heavy lifing. Stripes are understood to be formed as
100  // the channels found by looking for the "connected subgraphs".
101  // Like the graph itself, this neesds some looksup to translate
102  // between Boost Graph's subgraph index and a corresponding stripe.
103  std::unordered_map<vertex_t, int> subclusters;
104  std::unordered_map<int, Img::Data::Stripe*> cluster_to_stripe;
105  boost::connected_components(graph, boost::make_assoc_property_map(subclusters));
106 
107  // Collect channels of like cluster number into stripes
108  for (auto& p : subclusters) {
109  auto ncvit = node_to_chanval.find(p.first);
110  if (ncvit == node_to_chanval.end()) {
111  continue;
112  }
113  auto& cv = ncvit->second;
114  auto stripe = cluster_to_stripe[p.second];
115  if (!stripe) {
116  cluster_to_stripe[p.second] = stripe = new Img::Data::Stripe(p.first);
117  }
118  stripe->append(cv.first, cv.second);
119  }
120 
121  auto sliceset = new Img::Data::StripeSet(slice->ident());
122  for (auto ss : cluster_to_stripe) {
123  sliceset->push_back(IStripe::pointer(ss.second));
124  }
125 
126  out = IStripeSet::pointer(sliceset);
127  return true;
128 }
std::shared_ptr< const IStripe > pointer
Definition: IData.h:19
def graph(desc, maker=maker)
Definition: apa.py:294
p
Definition: test.py:223

Member Data Documentation

size_t WireCell::Img::NaiveStriper::m_gap
private

Definition at line 26 of file NaiveStriper.h.


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