WireBoundedDepos.cxx
Go to the documentation of this file.
3 #include "WireCellUtil/Units.h"
4 #include "WireCellUtil/String.h"
5 
10 
11 #include <boost/range.hpp>
12 
13 #include <sstream>
14 #include <iostream>
15 
18 
19 using namespace std;
20 using namespace WireCell;
21 
22 WireCell::Configuration Gen::WireBoundedDepos::default_configuration() const
23 {
25  cfg["anode"] = "";
26 
27  // A the list of wire regions
28  // [{
29  // plane: <plane-number>,
30  // min: <min-wire-number>,
31  // max: <max-wire-number,
32  // },...]
33  cfg["wires"] = Json::arrayValue;
34 
35  cfg["mode"] = "accept";
36 
37  return cfg;
38 }
39 
41 {
42  // we just want the pimpos but best to keep a handle on the anode
43  // since it's shared_ptr memory.
44  m_anode = Factory::find_tn<IAnodePlane>(cfg["anode"].asString());
45 
46  for (auto face : m_anode->faces()) {
47  if (face->planes().empty()) {
48  std::cerr << "Gen::WireBoundedDepos: not given multi-plane AnodeFace for face "
49  << face->ident() << "\n";
50  continue;
51  }
52  for (auto plane : face->planes()) {
53  const size_t iplane = plane->ident();
54  if (m_pimpos.size() <= iplane) {
55  m_pimpos.resize(iplane+1);
56  }
57  m_pimpos[iplane] = plane->pimpos();
58  }
59  break; // fixme:
60  }
61  m_accept = cfg["mode"].asString() == "accept";
62 
63  auto jregions = cfg["regions"];
64  for (auto jregion : jregions) {
65  wire_region_t wr;
66  for (auto jtrio : jregion) {
67  wr.push_back(wire_bounds_t(jtrio["plane"].asInt(),
68  jtrio["min"].asInt(),
69  jtrio["max"].asInt()));
70  }
71  m_regions.push_back(wr);
72  }
73 
74  std::cerr << "WireBoundedDepos: " << cfg ["mode"]
75  << " with " << m_regions.size() << " wires in "
76  << m_pimpos.size() << " planes\n";
77 }
78 
80 {
81  if (!depo) { // EOS protocol
82  outq.push_back(nullptr);
83  return true;
84  }
85 
86  // lazily calculate nearest wire
87  const size_t nplanes = m_pimpos.size();
88  std::vector<bool> already(nplanes, false);
89  std::vector<int> closest_wire(nplanes, -1);
90 
91  for (const auto& region : m_regions) {
92 
93  bool inregion = true;
94  for (const auto& trio : region) {
95 
96  const int iplane = get<0>(trio);
97  const int imin = get<1>(trio);
98  const int imax = get<2>(trio);
99 
100  if (!already[iplane]) { // lazy
101  const double pitch = m_pimpos[iplane]->distance(depo->pos(), 2);
102  closest_wire[iplane] = m_pimpos[iplane]->region_binning().bin(pitch);
103  already[iplane] = true;
104  }
105  const int iwire = closest_wire[iplane];
106 
107  if (iwire < imin or iwire > imax) {
108  inregion = false;
109  break;
110  }
111  }
112 
113 
114  if (inregion) {
115  if (m_accept) {
116  outq.push_back(depo);
117  }
118  // accept or reject, we landed this depo in a configured
119  // region.
120  return true;
121  }
122  }
123  if (!m_accept) { // depo missed all rejections.
124  outq.push_back(depo);
125  }
126  return true;
127 }
128 
130  : m_accept(true)
131 {
132 }
134 {
135 }
std::vector< wire_bounds_t > wire_region_t
virtual bool operator()(const input_pointer &depo, output_queue &outq)
The calling signature:
STL namespace.
cfg
Definition: dbjson.py:29
std::deque< output_pointer > output_queue
def configure(cfg)
Definition: cuda.py:34
std::vector< const Pimpos * > m_pimpos
WIRECELL_FACTORY(WireBoundedDepos, WireCell::Gen::WireBoundedDepos, WireCell::IDrifter, WireCell::IConfigurable) using namespace std
std::vector< wire_region_t > m_regions
Definition: Main.h:22
Json::Value Configuration
Definition: Configuration.h:50
std::shared_ptr< const IDepo > input_pointer
std::tuple< int, int, int > wire_bounds_t