WireSelector.h
Go to the documentation of this file.
1 // WireSelector.h
2 //
3 // David Adams
4 // March 2018
5 //
6 // Class to select wires and return measured coordinate and
7 // readout channel for each selected wire.
8 //
9 // The planes are selected automatically when the this object is constructed
10 // and after calls to any of the plane selection methods. Call fillData()
11 // to construct the vector of wires.
12 //
13 // To fetch all the wires for a channel with selelector sel:
14 // auto rng = sel.dataMap().equal_range(icha);
15 // for ( auto ient=rng.first; ient!=rng.secon; ++ient) {
16 // const WireSelector::WireInfo& win = *(ient->second);
17 
18 #ifndef WireSelector_H
19 #define WireSelector_H
20 
22 #include <vector>
23 #include <map>
24 
25 namespace geo {
26 class GeometryCore;
27 }
28 
29 class WireSelector {
30 
31 public:
32 
33  using Index = unsigned int;
34  using IndexVector = std::vector<Index>;
36  using View = geo::View_t;
38  using PlaneIDVector = std::vector<PlaneID>;
39 
40  // Class that describes a wire and its associated drift volume.
41  // The coordinate system is a rotation (no translation or inversion) of the
42  // global coordinate system such that
43  // x is the coordinate in the drift direction, i.e. perpendicular to the plane
44  // y is the global coordinate along the wire
45  // z is the global coordinate the wire number measures, i.e. perpendicular to the wire in the wire plane.
46  struct WireInfo {
47  float x;
48  float y;
49  float z;
50  float driftMax; // < 0 if TPC volume has x < x_wire
51  float length;
52  float pitch;
53  Index channel; // Channel that reads out this wire.
54  WireInfo() : y(0.0), z(0.0), length(0.0), pitch(0.0), channel(0) {}
55  WireInfo(float a_x, float a_y, float a_z,
56  float a_driftMax, float a_length, float a_pitch,
57  Index a_channel)
58  : x(a_x), y(a_y), z(a_z), driftMax(a_driftMax), length(a_length), pitch(a_pitch), channel(a_channel) { }
59  float x1() const { return driftMax > 0.0 ? x : x + driftMax; }
60  float x2() const { return driftMax < 0.0 ? x : x + driftMax; }
61  float y1() const { return y - 0.5*length; }
62  float y2() const { return y + 0.5*length; }
63  float z1() const { return z - 0.5*pitch; }
64  float z2() const { return z + 0.5*pitch; }
65  float driftSign() const { return driftMax > 0.0 ? 1.0 : -1.0; }
66  };
67 
68  // Class that describes the full set of wires for this selection.
69  // It includes the x and z coordinates of all wires and the corresponding
70  // x coordinate on the cathode plane.
71  // It also has the (x,y,z) limits.
72  class WireSummary {
73  public:
74  float xmin =0.0;
75  float ymin =0.0;
76  float zmin =0.0;
77  float xmax =0.0;
78  float ymax =0.0;
79  float zmax =0.0;
80  std::vector<float> xWire;
81  std::vector<float> xCathode;
82  std::vector<float> zWire;
83  Index size() const { return xWire.size(); }
84  void clear() {
85  xmin =0.0;
86  ymin =0.0;
87  zmin =0.0;
88  xmax =0.0;
89  ymax =0.0;
90  zmax =0.0;
91  xWire.clear();
92  xCathode.clear();
93  zWire.clear();
94  }
95  };
96 
97  using WireInfoVector = std::vector<WireInfo>;
98  using WireInfoMap = std::multimap<Index, const WireInfo*>;
99 
100  // Ctor from a cryostat.
101  explicit WireSelector(Index icry =0);
102 
103  // Const methods.
104 
105  // Return the geometry.
106  const GeometryCore* geometry() const { return m_pgeo; }
107 
108  // Return the selected cryostats.
109  const IndexVector& cryostats() const { return m_icrys; }
110 
111  // View if a view selection was made.
112  View view() const { return m_view; }
113 
114  // Wire angle if a wire angle selection was made.
115  double wireAngle() const { return m_wireAngle; }
116  double wireAngleTolerance() const { return m_wireAngleTolerance; }
117 
118  // TPC drift range.
119  double driftMin() const { return m_driftMin; }
120  double driftMax() const { return m_driftMax; }
121 
122  // Return the selected wire planes. Use geo::kUnknown to select all.
123  const PlaneIDVector& planeIDs() const { return m_pids; }
124 
125  // Return the wire data.
126  bool haveData() const { return m_haveData; };
127  const WireInfoVector& data() const { return m_data; }
128  const WireInfoMap& dataMap() const { return m_datamap; }
129  const WireSummary& wireSummary() const { return m_wireSummary; }
130 
131  // Non-const methods.
132 
133  // Fetch the geometry (if needed).
134  const GeometryCore* geometry();
135 
136  // Specify the list of cryostats.
137  // If this is not called, only crystat 0 is used.
138  void selectCryostats(const IndexVector& a_icrys);
139 
140  // Select planes with the specified geometry view (geo::kU, geo::kV, geo::kZ, ...).
141  // Use geo::kUnknown to select all planes.
142  // Vector of selected planes is updated.
143  void selectView(View view);
144 
145  // Select planes within tol of a specified wire angle.
146  // Selects all if tol > pi.
147  // Vector of selected planes is updated.
148  void selectWireAngle(double wireAngle, double tol =0.001);
149 
150  // Select planes in TPCs with max drift distance in the range [dmin, dmax).
151  // Vector of selected planes is updated.
152  void selectDrift(double dmin, double dmax =1.e20);
153 
154  // Add a selected TPC set or sets.
155  void selectTpcSet(Index itps);
156  void selectTpcSets(const IndexVector& itpss);
157 
158  // Select planes using the current criteria.
159  // This is called automatically by ctors and plane selectors.
160  void selectPlanes();
161 
162  // Returns the wire data after building it if it is not already present.
163  const WireInfoVector& fillData();
164 
165  // Returns the channel-mapped wire data after building it if it is not already present.
166  const WireInfoMap& fillDataMap();
167 
168  // Returns the wire summary data after building if needed.
169  const WireSummary& fillWireSummary();
170 
171  // Clear the wire data.
172  void clearData();
173 
174 private:
175 
176  const GeometryCore* m_pgeo =nullptr;
179  double m_wireAngle =999.;
180  double m_wireAngleTolerance =999.;
181  double m_driftMin = 0.0;
182  double m_driftMax = 1.e20;
185  bool m_haveData =false;
189 
190 };
191 
192 #endif
double wireAngleTolerance() const
Definition: WireSelector.h:116
double driftMax() const
Definition: WireSelector.h:120
const WireInfoMap & dataMap() const
Definition: WireSelector.h:128
float z2() const
Definition: WireSelector.h:64
double wireAngle() const
Definition: WireSelector.h:115
float x1() const
Definition: WireSelector.h:59
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:136
auto const tol
Definition: SurfXYZTest.cc:16
float z1() const
Definition: WireSelector.h:63
std::vector< float > xWire
Definition: WireSelector.h:80
const PlaneIDVector & planeIDs() const
Definition: WireSelector.h:123
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
const WireInfoVector & data() const
Definition: WireSelector.h:127
IndexVector m_tpcSets
Definition: WireSelector.h:184
WireInfoMap m_datamap
Definition: WireSelector.h:187
const GeometryCore * geometry() const
Definition: WireSelector.h:106
std::vector< Index > IndexVector
Definition: WireSelector.h:34
IndexVector m_icrys
Definition: WireSelector.h:177
float x2() const
Definition: WireSelector.h:60
float y1() const
Definition: WireSelector.h:61
PlaneIDVector m_pids
Definition: WireSelector.h:183
const WireSummary & wireSummary() const
Definition: WireSelector.h:129
std::vector< WireInfo > WireInfoVector
Definition: WireSelector.h:97
std::enable_if_t<(I==std::tuple_size_v< Tuple >)> fillData(Tuple &, int const ncols[[maybe_unused]], int const currentcol[[maybe_unused]], char **)
Definition: get_result.h:14
std::vector< float > zWire
Definition: WireSelector.h:82
std::vector< PlaneID > PlaneIDVector
Definition: WireSelector.h:38
Description of geometry of one entire detector.
Definition of data types for geometry description.
double driftMin() const
Definition: WireSelector.h:119
geo::View_t View
Definition: WireSelector.h:36
float driftSign() const
Definition: WireSelector.h:65
std::vector< float > xCathode
Definition: WireSelector.h:81
std::multimap< Index, const WireInfo * > WireInfoMap
Definition: WireSelector.h:98
View view() const
Definition: WireSelector.h:112
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
WireInfo(float a_x, float a_y, float a_z, float a_driftMax, float a_length, float a_pitch, Index a_channel)
Definition: WireSelector.h:55
LArSoft geometry interface.
Definition: ChannelGeo.h:16
const IndexVector & cryostats() const
Definition: WireSelector.h:109
bool haveData() const
Definition: WireSelector.h:126
unsigned int Index
Definition: WireSelector.h:33
float y2() const
Definition: WireSelector.h:62
WireInfoVector m_data
Definition: WireSelector.h:186
WireSummary m_wireSummary
Definition: WireSelector.h:188