Pimpos.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Pimpos.h"
2 
3 using namespace WireCell;
4 
5 Pimpos::Pimpos(int nwires, double minwirepitch, double maxwirepitch,
6  const Vector& wire,
7  const Vector& pitch,
8  const Point& origin,
9  int nbins) // default=10
10  : m_nimpbins_per_wire(nbins)
11  , m_origin(origin)
12  , m_axis{Vector(0,0,0), wire.norm(), pitch.norm()}
13 {
14  // drift = X = wire (x) pitch = Y cross Z
15  m_axis[0] = m_axis[1].cross(m_axis[2]);
16 
17  // total number of impact bins:
18  const int nimpstot = nwires*nbins;
19 
20  // total pitch span from first to last wire
21  const double regionsize = (maxwirepitch-minwirepitch)/(nwires-1);
22 
23  // expand by 1/2 pitch on either end to get total sensitive span in pitch direction
24  const double pmin = minwirepitch - 0.5*regionsize;
25  const double pmax = maxwirepitch + 0.5*regionsize;
26 
27  // Wire binning. Wires are at bin center.
28  m_regionbins.set(nwires, pmin, pmax);
29 
30  // Impact binning. Impact *positions* are bin-edges.
31  m_impactbins.set(nimpstot, pmin, pmax);
32 }
33 
34 std::pair<int, int> Pimpos::closest(double pitch) const
35 {
36  const int iwire = m_regionbins.bin(pitch);
37  const double wire_pitch = m_regionbins.center(iwire);
38  const double remainder = pitch - wire_pitch;
39  const int irelimp = int(round(remainder/m_impactbins.binsize()));
40  return std::make_pair(iwire, irelimp);
41 }
42 
43 int Pimpos::wire_impact(int wireind) const
44 {
45  return (0.5 + wireind)*m_nimpbins_per_wire;
46 }
47 
48 std::pair<int,int> Pimpos::wire_impacts(int wireind) const
49 {
50  const int wi = wire_impact(wireind);
51  return std::make_pair(wi - m_nimpbins_per_wire/2,
52  wi + m_nimpbins_per_wire/2);
53 }
54 
55 
56 int Pimpos::reflect(int wireind, int impind) const
57 {
58  const int wireimpind = wire_impact(wireind);
59  const int delta = impind - wireimpind;
60  return wireimpind - delta;
61 }
62 
63 
64 
65 
66 Vector Pimpos::relative(const Point& pt) const
67 {
68  return pt - m_origin;
69 }
70 
71 double Pimpos::distance(const Point& pt, int axis) const
72 {
73  return m_axis[axis].dot(relative(pt));
74 }
75 
76 Point Pimpos::transform(const Point& pt) const
77 {
78  const Vector v = relative(pt);
79  Point ret;
80  for (int axis=0; axis<3; ++axis) {
81  ret[axis] = m_axis[axis].dot(v);
82  }
83  return ret;
84 }
85 
86 
87 // Local Variables:
88 // mode: c++
89 // c-basic-offset: 4
90 // End:
Vector m_axis[3]
Definition: Pimpos.h:141
Point m_origin
Definition: Pimpos.h:140
const int nwires
std::pair< int, int > closest(double pitch) const
Definition: Pimpos.cxx:34
Point transform(const Point &pt) const
Definition: Pimpos.cxx:76
double center(int ind) const
Definition: Binning.h:86
double distance(const Point &pt, int axis=2) const
Definition: Pimpos.cxx:71
int reflect(int wireind, int impind) const
Definition: Pimpos.cxx:56
Binning m_impactbins
Definition: Pimpos.h:142
double binsize() const
Definition: Binning.h:73
int m_nimpbins_per_wire
Definition: Pimpos.h:139
void set(int nbins, double minval, double maxval)
Definition: Binning.h:34
int bin(double val) const
Definition: Binning.h:80
Pimpos(int nwires, double minwirepitch, double maxwirepitch, const Vector &wire=Vector(0, 1, 0), const Vector &pitch=Vector(0, 0, 1), const Point &origin=Point(0, 0, 0), int nimpact_bins_per_wire_region=10)
Definition: Pimpos.cxx:5
D3Vector norm() const
Return a normalized vector in the direction of this vector.
Definition: D3Vector.h:91
Point Vector
An alias for Point.
Definition: Point.h:18
Definition: Main.h:22
int wire_impact(int wireind) const
Return the impact position index coincident with the wire index.
Definition: Pimpos.cxx:43
Binning m_regionbins
Definition: Pimpos.h:142
T dot(const D3Vector &rhs) const
Return the dot product of this vector and the other.
Definition: D3Vector.h:80
std::pair< int, int > wire_impacts(int wireind) const
Definition: Pimpos.cxx:48
D3Vector cross(const D3Vector &rhs) const
Return the cross product of this vector and the other.
Definition: D3Vector.h:100
Vector relative(const Point &pt) const
Return the vector from the origin to the given point.
Definition: Pimpos.cxx:66
const double wire_pitch
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
const Vector & axis(int i) const
Definition: Pimpos.h:89