WireSelector.cxx
Go to the documentation of this file.
1 // WireSelector.cxx
2 
3 #include "WireSelector.h"
6 #include <string>
7 #include <iostream>
8 
9 using std::string;
10 using std::cout;
11 using std::endl;
12 
13 //**********************************************************************
14 
16  selectCryostats({icry});
17 }
18 
19 //**********************************************************************
20 
22  if ( m_pgeo == nullptr ) {
24  m_pgeo = hgeo.get();
25  }
26  return m_pgeo;
27 }
28 
29 //**********************************************************************
30 
32  m_icrys = a_icrys;
33  selectPlanes();
34 }
35 
36 //**********************************************************************
37 
39  m_view = a_view;
40  selectPlanes();
41 }
42 
43 //**********************************************************************
44 
45 void WireSelector::selectWireAngle(double angle, double tol) {
46  m_wireAngle = angle;
48  selectPlanes();
49 }
50 
51 //**********************************************************************
52 
53 void WireSelector::selectDrift(double dmin, double dmax) {
54  m_driftMin = dmin;
55  m_driftMax = dmax;
56  selectPlanes();
57 }
58 
59 //**********************************************************************
60 
62  m_tpcSets.clear();
63  m_tpcSets.push_back(itps);
64  selectPlanes();
65 }
66 //**********************************************************************
67 
69  m_tpcSets = itpss;
70  selectPlanes();
71 }
72 
73 //**********************************************************************
74 
76  const double pi = acos(-1.0);
77  const double piOver2 = 0.5*pi;
78  m_pids.clear();
79  clearData();
80  for ( Index icry : cryostats() ) {
81  geo::CryostatID cid(icry);
82  for ( geo::TPCID tid : geometry()->IterateTPCIDs(cid) ) {
83  // Check TPC set.
84  if ( m_tpcSets.size() ) {
85  Index itps = geometry()->TPCtoTPCset(tid).TPCset;
86  if ( find(m_tpcSets.begin(), m_tpcSets.end(), itps) == m_tpcSets.end() ) continue;
87  }
88  // Check drift.
89  if ( driftMin() > 0.0 || driftMax() < 1.e20 ) {
90  const geo::TPCGeo& gtpc = geometry()->TPC(tid);
91  //double driftSize = gtpc.ActiveWidth();
92  double driftSize = gtpc.DriftDistance(); // good for the last anode plane
93  if ( driftSize < driftMin() ) continue;
94  if ( driftSize >= driftMax() ) continue;
95  }
96  for ( geo::PlaneID pid : geometry()->IteratePlaneIDs(tid) ) {
97  const geo::PlaneGeo& gpla = geometry()->Plane(pid);
98  // Check view.
99  if ( view() != geo::kUnknown && gpla.View() != view() ) continue;
100  // Check wire angle.
101  if ( wireAngleTolerance() < pi ) {
102  double planeWireAngle = gpla.ThetaZ() - piOver2;
103  double dang = planeWireAngle - wireAngle();
104  while ( dang < -piOver2 ) dang += pi;
105  while ( dang > piOver2 ) dang -= pi;
106  if ( fabs(dang) >= wireAngleTolerance() ) continue;
107  }
108  // Keep this plane.
109  m_pids.push_back(pid);
110  }
111  }
112  }
113 }
114 
115 //**********************************************************************
116 
118  const string myname = "WireSelector::fillData: ";
119  const double piOver2 = 0.5*acos(-1.0);
120  if ( haveData() ) return m_data;
121  for ( geo::PlaneID pid : planeIDs() ) {
122  const geo::PlaneGeo& gpla = geometry()->Plane(pid);
123  const geo::TPCGeo& gtpc = geometry()->TPC(pid);
124  const geo::PlaneGeo& gplaLast = gtpc.LastPlane(); // Plane furthest from TPC center.
125  double xLastPlane = gplaLast.MiddleWire().GetCenter<TVector3>().x();
126  double xThisPlane = gpla.MiddleWire().GetCenter<TVector3>().x();
127  double driftOffset = fabs(xThisPlane - xLastPlane);
128  for ( Index iwir=0; iwir<gpla.Nwires(); ++iwir ) {
129  geo::WireID wid(pid, iwir);
130  const geo::WireGeo* pgwir = gpla.WirePtr(wid);
131  double wireAngle = gpla.ThetaZ() - piOver2;
132  TVector3 xyzWire = pgwir->GetCenter<TVector3>();
133  xyzWire.RotateX(wireAngle);
134  double driftSign = gpla.GetNormalDirection().x();
135  if ( fabs(fabs(driftSign) - 1.0) > 0.001 ) {
136  cout << myname << "ERROR: Plane normal is not along x." << endl;
137  continue;
138  }
139  double driftDist = gtpc.DriftDistance() - driftOffset;
140  m_data.emplace_back(xyzWire.x(), xyzWire.y(), xyzWire.z(),
141  driftSign*driftDist,
142  pgwir->Length(),
143  gpla.WirePitch(),
144  geometry()->PlaneWireToChannel(wid));
145  }
146  }
147  m_haveData = true;
148  return m_data;
149 }
150 
151 //**********************************************************************
152 
154  if ( haveData() && m_datamap.size() == m_data.size() ) return m_datamap;
155  for ( const WireInfo& dat : fillData() ) {
156  m_datamap.emplace(dat.channel, &dat);
157  }
158  return m_datamap;
159 }
160 
161 //**********************************************************************
162 
164  if ( haveData() && m_wireSummary.size() == m_data.size() ) return m_wireSummary;
166  Index nwir = data().size();
167  ws.xmin = 1000.0;
168  ws.ymin = 1000.0;
169  ws.zmin = 1000.0;
170  ws.xmax = -1000.0;
171  ws.ymax = -1000.0;
172  ws.zmax = -1000.0;
173  ws.xWire.resize(nwir);
174  ws.xCathode.resize(nwir);
175  ws.zWire.resize(nwir);
176  for ( Index iwir=0; iwir<nwir; ++iwir ) {
177  const WireInfo& dat = data()[iwir];
178  if ( dat.x1() < ws.xmin ) ws.xmin = dat.x1();
179  if ( dat.y1() < ws.ymin ) ws.ymin = dat.y1();
180  if ( dat.z1() < ws.zmin ) ws.zmin = dat.z1();
181  if ( dat.x2() > ws.xmax ) ws.xmax = dat.x2();
182  if ( dat.y2() > ws.ymax ) ws.ymax = dat.y2();
183  if ( dat.z2() > ws.zmax ) ws.zmax = dat.z2();
184  ws.xWire[iwir] = dat.x;
185  ws.xCathode[iwir] = dat.x + dat.driftMax;
186  ws.zWire[iwir] = dat.z;
187  }
188  return ws;
189 }
190 
191 //**********************************************************************
192 
194  m_data.clear();
195  m_datamap.clear();
197  m_haveData = false;
198 }
199 
200 //**********************************************************************
geo::WirePtr WirePtr(unsigned int iwire) const
Returns the wire number iwire from this plane.
Definition: PlaneGeo.h:324
double wireAngleTolerance() const
Definition: WireSelector.h:116
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:65
double driftMax() const
Definition: WireSelector.h:120
float z2() const
Definition: WireSelector.h:64
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
double wireAngle() const
Definition: WireSelector.h:115
float x1() const
Definition: WireSelector.h:59
T * get() const
Definition: ServiceHandle.h:63
std::string string
Definition: nybbler.cc:12
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
double Length() const
Returns the wire length in centimeters.
Definition: WireGeo.h:236
const PlaneIDVector & planeIDs() const
Definition: WireSelector.h:123
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
Geometry information for a single TPC.
Definition: TPCGeo.h:38
const WireInfoVector & data() const
Definition: WireSelector.h:127
IndexVector m_tpcSets
Definition: WireSelector.h:184
WireInfoMap m_datamap
Definition: WireSelector.h:187
Vector GetNormalDirection() const
Returns the direction normal to the plane.
Definition: PlaneGeo.h:442
const GeometryCore * geometry() const
Definition: WireSelector.h:106
readout::TPCsetID TPCtoTPCset(geo::TPCID const &tpcid) const
Returns the ID of the TPC set tpcid belongs to.
art framework interface to geometry description
std::vector< Index > IndexVector
Definition: WireSelector.h:34
IndexVector m_icrys
Definition: WireSelector.h:177
double ThetaZ() const
Angle of the wires from positive z axis; .
Definition: PlaneGeo.cxx:726
void selectView(View view)
float x2() const
Definition: WireSelector.h:60
void selectWireAngle(double wireAngle, double tol=0.001)
float y1() const
Definition: WireSelector.h:61
PlaneIDVector m_pids
Definition: WireSelector.h:183
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:184
void selectTpcSets(const IndexVector &itpss)
const WireGeo & MiddleWire() const
Return the middle wire in the plane.
Definition: PlaneGeo.h:347
std::vector< WireInfo > WireInfoVector
Definition: WireSelector.h:97
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
void selectDrift(double dmin, double dmax=1.e20)
std::vector< float > zWire
Definition: WireSelector.h:82
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
Description of geometry of one entire detector.
void selectPlanes()
const GeometryCore * m_pgeo
Definition: WireSelector.h:176
double m_driftMin
Definition: WireSelector.h:181
double driftMin() const
Definition: WireSelector.h:119
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
Definition: readout_types.h:90
geo::View_t View
Definition: WireSelector.h:36
void selectTpcSet(Index itps)
const WireSummary & fillWireSummary()
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
double m_wireAngleTolerance
Definition: WireSelector.h:180
double DriftDistance() const
Definition: TPCGeo.h:155
const WireInfoVector & fillData()
std::vector< float > xCathode
Definition: WireSelector.h:81
std::multimap< Index, const WireInfo * > WireInfoMap
Definition: WireSelector.h:98
geo::PlaneGeo const & LastPlane() const
Returns the last wire plane (the farther from TPC center).
Definition: TPCGeo.h:248
unsigned int Nwires() const
Number of wires in this plane.
Definition: PlaneGeo.h:269
View view() const
Definition: WireSelector.h:112
double m_wireAngle
Definition: WireSelector.h:179
WireSelector(Index icry=0)
list x
Definition: train.py:276
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
float pi
Definition: units.py:11
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73
const WireInfoMap & fillDataMap()
const IndexVector & cryostats() const
Definition: WireSelector.h:109
bool haveData() const
Definition: WireSelector.h:126
unsigned int Index
Definition: WireSelector.h:33
double m_driftMax
Definition: WireSelector.h:182
float y2() const
Definition: WireSelector.h:62
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Definition: PlaneGeo.h:411
QTextStream & endl(QTextStream &s)
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
WireInfoVector m_data
Definition: WireSelector.h:186
void selectCryostats(const IndexVector &a_icrys)
WireSummary m_wireSummary
Definition: WireSelector.h:188