GridTiling.cxx
Go to the documentation of this file.
2 
6 
9 
10 using namespace WireCell;
11 using namespace WireCell::RayGrid;
12 
13 
15  : m_blobs_seen(0)
16  , m_threshold(0.0)
17  , l(Log::logger("img"))
18 {
19 }
20 
21 Img::GridTiling::~GridTiling()
22 {
23 
24 }
25 
27 {
28  m_anode = Factory::find_tn<IAnodePlane>(cfg["anode"].asString());
29  m_face = m_anode->face(cfg["face"].asInt());
30  m_threshold = get(cfg, "threshold", m_threshold);
31 }
32 
33 WireCell::Configuration Img::GridTiling::default_configuration() const
34 {
36  cfg["anode"] = ""; // user must set
37  cfg["face"] = 0; // the face number to focus on
38  // activity must be bigger than this much to consider.
39  cfg["threshold"] = m_threshold;
40  return cfg;
41 }
42 
43 
44 
45 bool Img::GridTiling::operator()(const input_pointer& slice, output_pointer& out)
46 {
47  out = nullptr;
48  if (!slice) {
49  m_blobs_seen = 0;
50  SPDLOG_LOGGER_TRACE(l, "GridTiling: EOS");
51  return true; // eos
52  }
53 
54  const int sbs_ident = slice->ident();
55  SimpleBlobSet* sbs = new SimpleBlobSet(sbs_ident, slice);
56  out = IBlobSet::pointer(sbs);
57 
58  const int nbounds_layers = 2;
59  const int nlayers = m_face->nplanes() + nbounds_layers;
60  std::vector< std::vector<Activity::value_t> > measures(nlayers);
61  measures[0].push_back(1); // assume first two layers in RayGrid::Coordinates
62  measures[1].push_back(1); // are for horiz/vert bounds
63 
64  const auto anodeid = m_anode->ident();
65  const auto faceid = m_face->ident();
66  auto chvs = slice->activity();
67  if (chvs.empty()) {
68  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} no activity",
69  anodeid, faceid, slice->ident());
70  return true;
71  }
72 
73  const int nactivities = slice->activity().size();
74  int total_activity=0;
75  if (nactivities < m_face->nplanes()) {
76  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} too few activities given",
77  anodeid, faceid, slice->ident());
78  return true;
79  }
80 
81  for (const auto& chv : slice->activity()) {
82  for (const auto& wire : chv.first->wires()) {
83  auto wpid = wire->planeid();
84  if (wpid.face() != faceid) {
85  //l->trace("anode:{} face:{} slice:{} chan:{} wip:{} q:{} skip {}", anodeid, faceid, slice->ident(), chv.first->ident(), wire->index(), chv.second, wpid);
86  continue;
87  }
88  //l->trace("anode:{} face:{} slice:{} chan:{} wip:{} q:{} keep {}", anodeid, faceid, slice->ident(), chv.first->ident(), wire->index(), chv.second, wpid);
89  const int pit_ind = wire->index();
90  const int layer = nbounds_layers + wire->planeid().index();
91  auto& m = measures[layer];
92  if (pit_ind < 0) {
93  continue;
94  }
95  if ((int)m.size() <= pit_ind) {
96  m.resize(pit_ind+1, 0.0);
97  }
98  m[pit_ind] += 1.0;
99  ++total_activity;
100  }
101  }
102 
103  if (!total_activity) {
104  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} no activity",
105  anodeid, faceid, slice->ident());
106  return true;
107  }
108  size_t nactive_layers = 0;
109  for (size_t ind = 0; ind<measures.size(); ++ind) {
110  const auto& blah = measures[ind];
111  if (blah.empty()) {
112  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} empty active layer ind={} out of {}",
113  anodeid, faceid, slice->ident(), ind, measures.size());
114  continue;
115  }
116  ++nactive_layers;
117  }
118  if (nactive_layers != measures.size()) {
119  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} missing active layers {} != {}, {} activities",
120  anodeid, faceid, slice->ident(), nactive_layers, measures.size(), nactivities);
121  return true;
122  }
123 
124  activities_t activities;
125  for (int layer = 0; layer<nlayers; ++layer) {
126  auto& m = measures[layer];
127  Activity activity(layer, {m.begin(), m.end()}, 0, m_threshold);
128  SPDLOG_LOGGER_TRACE(l, "L{} A:{}", layer, activity.as_string());
129  activities.push_back(activity);
130  }
131 
132  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} making blobs",
133  anodeid, faceid, slice->ident());
134  auto blobs = make_blobs(m_face->raygrid(), activities);
135 
136  const float blob_value = 0.0; // tiling doesn't consider particular charge
137  for (const auto& blob : blobs) {
138  SimpleBlob* sb = new SimpleBlob(m_blobs_seen++, blob_value, 0.0, blob, slice, m_face);
139  sbs->m_blobs.push_back(IBlob::pointer(sb));
140  }
141  SPDLOG_LOGGER_TRACE(l,"GridTiling: anode:{} face:{} slice:{} found {} blobs",
142  anodeid, faceid, slice->ident(), sbs->m_blobs.size());
143 
144  return true;
145 }
146 
IBlob::vector m_blobs
Definition: SimpleBlob.h:61
static const double m
Definition: Units.h:79
std::shared_ptr< const IBlob > pointer
Definition: IData.h:19
WIRECELL_FACTORY(GridTiling, WireCell::Img::GridTiling, WireCell::ITiling, WireCell::IConfigurable) using namespace WireCell
cfg
Definition: dbjson.py:29
static QStrList * l
Definition: config.cpp:1044
def blobs(cm, hist)
Definition: plots.py:79
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
std::shared_ptr< const ISlice > input_pointer
Definition: IFunctionNode.h:39
def configure(cfg)
Definition: cuda.py:34
std::shared_ptr< const IBlobSet > output_pointer
Definition: IFunctionNode.h:40
logptr_t logger(std::string name)
Definition: Logging.cxx:71
Definition: Main.h:22
#define SPDLOG_LOGGER_TRACE(logger,...)
Definition: spdlog.h:319
Json::Value Configuration
Definition: Configuration.h:50
blobs_t make_blobs(const Coordinates &coords, const activities_t &activities)
Definition: RayTiling.cxx:371
std::vector< Activity > activities_t
Definition: RayTiling.h:105
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124