WireGenerator.cxx
Go to the documentation of this file.
4 
5 #include <cmath>
6 #include <iostream> // debugging
7 #include <vector>
8 
11 
12 using namespace WireCell;
13 using namespace std;
14 
15 
16 
17 namespace WireCell {
18 class GenWire : public IWire {
20  int m_index;
22 
23 public:
24  GenWire(WirePlaneId wpid, int index, const Ray& ray)
25  : m_wpid(wpid), m_index(index), m_ray(ray)
26  {
27  }
28  virtual ~GenWire()
29  {
30  }
31 
32  int ident() const {
33  int iplane = m_wpid.index();
34  ++iplane;
35  return iplane*100000 + m_index;
36  }
37 
38  WirePlaneId planeid() const { return m_wpid; }
39 
40  int index() const { return m_index; }
41 
42  int channel() const { return ident(); }
43 
44  WireCell::Ray ray() const { return m_ray; }
45 
46  /// fixme: supply
47  int segment() const {return 0;}
48  int face() const {return 0;}
49  int apa() const {return 0;}
50 
51  void set_index(int ind) { m_index = ind; }
52  void set_planeid(WirePlaneId wpid) { m_wpid = wpid; }
53 
54 };
55 }
56 
57 static GenWire* make_wire(int index, const Point& point,
58  const Point& proto, const Ray& bounds)
59 {
60  const Point pt1 = point;
61  const Point pt2 = pt1 + proto;
62  const Ray wireray(pt1, pt2);
63 
64  Ray hits;
65  int hitmask = box_intersection(bounds, wireray, hits);
66  if (3 != hitmask) {
67  return 0;
68  }
69  // ray should point generally towards +Y
70  if (hits.first.y() > hits.second.y()) {
71  hits = Ray(hits.second, hits.first);
72  }
73  return new GenWire(WirePlaneId(kUnknownLayer), index, hits);
74 }
75 
76 struct SortByIndex {
77  inline bool operator()(const GenWire* lhs, const GenWire* rhs) {
78  return lhs->index() < rhs->index();
79  }
80 };
81 
82 
83 static void make_one_plane(IWire::vector& returned_wires,
84  WirePlaneId wpid, const Ray& bounds, const Ray& step)
85 {
86  const Vector xaxis(1,0,0);
87  const Point starting_point = step.first;
88  const Vector pitch = step.second - starting_point;
89  const Vector proto = pitch.cross(xaxis).norm();
90 
91  std::vector<GenWire*> these_wires;
92 
93  int pos_index = 0;
94  Point offset = starting_point;
95  while (true) { // go in positive pitch direction
96  GenWire* wire = make_wire(pos_index, offset, proto, bounds);
97  if (! wire) { break; }
98  these_wires.push_back(wire);
99  offset = wire->center() + pitch;
100  pos_index += 1;
101  }
102 
103  int neg_index = -1; // now go in negative pitch direction
104  const Vector neg_pitch = -1.0 * pitch;
105  offset = these_wires[0]->center() + neg_pitch; // start one below first upward going one
106  while (true) { // go in negative pitch direction
107  GenWire* wire = make_wire(neg_index, offset, proto, bounds);
108  if (! wire) { break; }
109  these_wires.push_back(wire);
110  offset = wire->center() + neg_pitch;
111  neg_index -= 1;
112  }
113 
114  // order by index
115  std::sort(these_wires.begin(), these_wires.end(), SortByIndex());
116 
117  // load in to store and fix up index and plane
118  for (size_t ind=0; ind<these_wires.size(); ++ind) {
119  GenWire* pwire = these_wires[ind];
120  pwire->set_index(ind);
121  pwire->set_planeid(wpid);
122  returned_wires.push_back(IWire::pointer(pwire));
123  }
124 
125  //std::cerr << "Made "<<store.size()<<" wires for plane " << plane << std::endl;
126  //std::cerr << "step = " << step << std::endl;
127  //std::cerr << "bounds = " << bounds << std::endl;
128 }
129 
130 
131 
132 
133 bool WireGenerator::operator()(const input_pointer& wp, output_pointer& wires)
134 {
135  if (!wp) {
136  wires = nullptr;
137  return true;
138  }
139  IWire::vector* pwires = new IWire::vector;
140  make_one_plane(*pwires, WirePlaneId(kUlayer), wp->bounds(), wp->pitchU());
141  make_one_plane(*pwires, WirePlaneId(kVlayer), wp->bounds(), wp->pitchV());
142  make_one_plane(*pwires, WirePlaneId(kWlayer), wp->bounds(), wp->pitchW());
143  wires = output_pointer (pwires);
144  return true;
145 }
146 
147 
148 WireGenerator::WireGenerator()
149 {
150 }
151 
152 WireGenerator::~WireGenerator()
153 {
154 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
void set_index(int ind)
bool operator()(const GenWire *lhs, const GenWire *rhs)
int apa() const
int segment() const
fixme: supply
struct vector vector
STL namespace.
GenWire(WirePlaneId wpid, int index, const Ray &ray)
std::vector< pointer > vector
Definition: IData.h:21
WireCell::Ray ray() const
Return the ray representing the wire segment.
WirePlaneId planeid() const
The ID of the plane this wire is in.
int face() const
std::shared_ptr< const IWireParameters > input_pointer
Definition: IFunctionNode.h:39
WIRECELL_FACTORY(WireGenerator, WireCell::WireGenerator, WireCell::IWireGenerator) using namespace WireCell
int index() const
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
int ident() const
General LArSoft Utilities.
Interface to information about a physical wire segment.
Definition: IWire.h:18
WirePlaneId m_wpid
std::shared_ptr< const IWire::vector > output_pointer
Definition: IFunctionNode.h:40
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
Definition: Main.h:22
std::vector< float > Vector
int channel() const
static GenWire * make_wire(int index, const Point &point, const Point &proto, const Ray &bounds)
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124
void set_planeid(WirePlaneId wpid)
int box_intersection(const Ray &bounds, const Ray &ray, Ray &hits)
int index() const
Layer as index number (0,1 or 2). -1 if unknown.
Definition: WirePlaneId.cxx:34
static void make_one_plane(IWire::vector &returned_wires, WirePlaneId wpid, const Ray &bounds, const Ray &step)