WireSummary.cxx
Go to the documentation of this file.
3 
4 #include <iterator>
5 #include <map>
6 
7 using namespace WireCell;
8 using namespace std;
9 
10 
11 // Return a Ray going from the center point of wires[0] to a point on
12 // wire[1] and perpendicular to both.
13 static Ray pitch2(const IWire::vector& wires)
14 {
15  // Use two consecutive wires from the center to determine the pitch.
16  int ind = wires.size()/2;
17  IWire::pointer one = wires[ind];
18  IWire::pointer two = wires[ind+1];
19  const Ray p = ray_pitch(one->ray(), two->ray());
20 
21  // Move the pitch to the first wire
22  IWire::pointer zero = wires[0];
23  const Vector center0 = zero->center();
24  return Ray(center0, center0 + ray_vector(p));
25 }
26 
33  double pitch_mag;
34 
35  WirePlaneCache(WirePlaneId wpid, const IWire::vector& all_wires)
36  : wpid(wpid) // maybe one day support more then one face/apa
37  {
38  copy_if(all_wires.begin(), all_wires.end(),
39  back_inserter(wires), select_uvw_wires[wpid.index()]);
40  pitch_ray = pitch2(wires);
41  pitch_vector = ray_vector(pitch_ray); // cache
42  pitch_unit = pitch_vector.norm(); // the
43  pitch_mag = pitch_vector.magnitude(); // things!
44  }
45 
47  if (index < 0 || index >= (int)wires.size()) {
48  return 0;
49  }
50  return wires[index];
51  }
52 
53  double pitch_distance(const Point& point) {
54  return ray_dist(pitch_ray, point);
55  }
56 
57 
58 };
59 
63  WirePlaneCache *plane_cache[3];
64 
65  std::map<int,IWireSegmentSet> chan2wire;
66 
68  : wires(wires)
69  {
70  for (auto wire : wires) {
71  bb(wire->ray());
72  chan2wire[wire->channel()].insert(wire);
73  }
74 
75  plane_cache[0] = new WirePlaneCache(WirePlaneId(kUlayer), wires);
76  plane_cache[1] = new WirePlaneCache(WirePlaneId(kVlayer), wires);
77  plane_cache[2] = new WirePlaneCache(WirePlaneId(kWlayer), wires);
78  }
79 
81  for (int ind=0; ind<3; ++ind) {
82  delete plane_cache[ind];
83  }
84  }
85 
87  return plane(wpid.index());
88  }
90  if (index<0 ||index>2) return 0;
91  return plane_cache[index];
92  }
93 
94  IWire::vector by_chan(int chan) {
95  IWireSegmentSet& got = chan2wire[chan];
96  return IWire::vector(got.begin(), got.end());
97  }
98 
99 };
100 
102 
104 {
105  if (!m_cache) {
106  static BoundingBox bbdummy;
107  return bbdummy;
108  }
109  return m_cache->bb;
110 }
111 
113 {
114  if (!m_cache) {
115  return 0;
116  }
117  WirePlaneCache* wpc = m_cache->plane(wpid);
118  if (!wpc) {
119  return 0;
120  }
121 
122  double dist = wpc->pitch_distance(point);
123  return wpc->wire_by_index(dist/wpc->pitch_mag);
124 }
125 
127 {
128  if (!m_cache) {
129  return IWirePair();
130  }
131  WirePlaneCache* wpc = m_cache->plane(wpid);
132  if (!wpc) {
133  return IWirePair();
134  }
135 
136  IWire::pointer wire = closest(point, wpid);
137  if (!wire) return IWirePair();
138 
139  int index = wire->index();
140 
141  Vector topoint = point - wire->ray().first;
142  double dot = wpc->pitch_unit.dot(topoint);
143  int other_index = index - 1;
144  if (dot > 0) {
145  other_index = index + 1;
146  }
147 
148  IWire::pointer other_wire = wpc->wire_by_index(other_index);
149 
150  if (index < other_index) {
151  return IWirePair(IWire::pointer(wire), IWire::pointer(other_wire));
152  }
153  return IWirePair(IWire::pointer(other_wire), IWire::pointer(wire));
154 }
155 
156 double WireSummary::pitch_distance(const Point& point, WirePlaneId wpid) const
157 {
158  if (!m_cache) {
159  return 0;
160  }
161  WirePlaneCache* wpc = m_cache->plane(wpid);
162  if (!wpc) {
163  return 0;
164  }
165  return wpc->pitch_distance(point);
166 }
167 
169 {
170  static Vector dummy;
171  if (!m_cache) {
172  return dummy;
173  }
174  WirePlaneCache* wpc = m_cache->plane(wpid);
175  if (!wpc) {
176  return dummy;
177  }
178  return wpc->pitch_unit;
179 }
180 
182 {
183  if (!m_cache) {
184  return IWire::vector();
185  }
186  return m_cache->by_chan(channel);
187 }
188 
190  : m_cache(0)
191 {
192  m_cache = new WireSummaryCache(wires);
193 }
195 {
196 }
197 
198 
199 
200 
201 
WirePlaneCache(WirePlaneId wpid, const IWire::vector &all_wires)
Definition: WireSummary.cxx:35
virtual const Vector & pitch_direction(WirePlaneId wpid) const
Return a unit vector along the direction of the pitch.
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
virtual IWire::pointer closest(const Point &point, WirePlaneId wpid) const
std::shared_ptr< const IWire > pointer
Definition: IData.h:19
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
std::set< IWire::pointer, IWireCompareSegment > IWireSegmentSet
Definition: IWire.h:89
IWire::vector wires
Definition: WireSummary.cxx:29
static IWire::vector dummy_vector
STL namespace.
WirePlaneCache * plane(int index)
Definition: WireSummary.cxx:89
std::vector< pointer > vector
Definition: IData.h:21
virtual IWirePair bounding_wires(const Point &point, WirePlaneId wpid) const
WireSummary(const IWire::vector &wires)
static Ray pitch2(const IWire::vector &wires)
Definition: WireSummary.cxx:13
virtual IWire::vector by_channel(int channel) const
Return all wires, in order of segment number, attached to the channel.
double ray_dist(const Ray &ray, const Point &point)
Definition: Point.cxx:95
wire_selector select_uvw_wires[3]
std::pair< IWire::pointer, IWire::pointer > IWirePair
Some common collections.
Definition: IWire.h:55
double pitch_distance(const Point &point)
Definition: WireSummary.cxx:53
Vector pitch_vector
Definition: WireSummary.cxx:31
WireSummaryCache * m_cache
Definition: WireSummary.h:42
virtual const BoundingBox & box() const
Return the bounding box of the wire planes.
WirePlaneId wpid
Definition: WireSummary.cxx:28
WirePlaneCache * plane(WirePlaneId wpid)
Definition: WireSummary.cxx:86
Definition: Main.h:22
p
Definition: test.py:223
std::vector< float > Vector
Ray ray_pitch(const Ray &ray1, const Ray &ray2)
Definition: Point.cxx:76
IWire::pointer wire_by_index(int index)
Definition: WireSummary.cxx:46
virtual double pitch_distance(const Point &point, WirePlaneId wpid) const
cet::LibraryManager dummy("noplugin")
Vector ray_vector(const Ray &ray)
Definition: Point.cxx:67
std::map< int, IWireSegmentSet > chan2wire
Definition: WireSummary.cxx:65
int index() const
Layer as index number (0,1 or 2). -1 if unknown.
Definition: WirePlaneId.cxx:34
WireSummaryCache(const IWire::vector &wires)
Definition: WireSummary.cxx:67