Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
reco3d::TripletFinder Class Reference

#include <TripletFinder.h>

Public Member Functions

 TripletFinder (const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &xhits, const std::vector< art::Ptr< recob::Hit >> &uhits, const std::vector< art::Ptr< recob::Hit >> &vhits, const std::vector< raw::ChannelID_t > &xbad, const std::vector< raw::ChannelID_t > &ubad, const std::vector< raw::ChannelID_t > &vbad, double distThresh, double distThreshDrift, double xhitOffset)
 
std::vector< HitTripletTriplets ()
 
std::vector< HitTripletTripletsTwoView ()
 Only search for XU intersections. More...
 

Protected Member Functions

void FillHitMap (const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits, std::map< geo::TPCID, std::vector< HitOrChan >> &out)
 Helper for constructor. More...
 
void FillBadMap (const std::vector< raw::ChannelID_t > &bads, std::map< geo::TPCID, std::vector< raw::ChannelID_t >> &out)
 Helper for constructor. More...
 
bool CloseDrift (double xa, double xb) const
 
bool CloseSpace (geo::WireIDIntersection ra, geo::WireIDIntersection rb) const
 
std::vector< ChannelDoubletDoubletsXU (geo::TPCID tpc)
 
std::vector< ChannelDoubletDoubletsXV (geo::TPCID tpc)
 
std::vector< ChannelDoubletDoubletHelper (geo::TPCID tpc, const std::vector< HitOrChan > &ahits, const std::vector< HitOrChan > &bhits, const std::vector< raw::ChannelID_t > &bbads) const
 

Protected Attributes

const geo::GeometryCoregeom
 
double fDistThresh
 
double fDistThreshDrift
 
double fXHitOffset
 
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
 
std::map< geo::TPCID, std::vector< HitOrChan > > fU_by_tpc
 
std::map< geo::TPCID, std::vector< HitOrChan > > fV_by_tpc
 
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
 
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fUbad_by_tpc
 
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fVbad_by_tpc
 

Detailed Description

Definition at line 51 of file TripletFinder.h.

Constructor & Destructor Documentation

reco3d::TripletFinder::TripletFinder ( const detinfo::DetectorPropertiesData detProp,
const std::vector< art::Ptr< recob::Hit >> &  xhits,
const std::vector< art::Ptr< recob::Hit >> &  uhits,
const std::vector< art::Ptr< recob::Hit >> &  vhits,
const std::vector< raw::ChannelID_t > &  xbad,
const std::vector< raw::ChannelID_t > &  ubad,
const std::vector< raw::ChannelID_t > &  vbad,
double  distThresh,
double  distThreshDrift,
double  xhitOffset 
)

Definition at line 13 of file TripletFinder.cxx.

24  , fDistThresh(distThresh)
25  , fDistThreshDrift(distThreshDrift)
26  , fXHitOffset(xhitOffset)
27  {
28  FillHitMap(detProp, xhits, fX_by_tpc);
29  FillHitMap(detProp, uhits, fU_by_tpc);
30  FillHitMap(detProp, vhits, fV_by_tpc);
31 
32  FillBadMap(xbad, fXbad_by_tpc);
33  FillBadMap(ubad, fUbad_by_tpc);
34  FillBadMap(vbad, fVbad_by_tpc);
35  }
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:94
virtual const provider_type * provider() const override
std::map< geo::TPCID, std::vector< HitOrChan > > fV_by_tpc
Definition: TripletFinder.h:96
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
Definition: TripletFinder.h:99
std::map< geo::TPCID, std::vector< HitOrChan > > fU_by_tpc
Definition: TripletFinder.h:95
const geo::GeometryCore * geom
Definition: TripletFinder.h:69
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fUbad_by_tpc
void FillBadMap(const std::vector< raw::ChannelID_t > &bads, std::map< geo::TPCID, std::vector< raw::ChannelID_t >> &out)
Helper for constructor.
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fVbad_by_tpc
void FillHitMap(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits, std::map< geo::TPCID, std::vector< HitOrChan >> &out)
Helper for constructor.

Member Function Documentation

bool reco3d::TripletFinder::CloseDrift ( double  xa,
double  xb 
) const
protected

Definition at line 122 of file TripletFinder.cxx.

123  {
124  return fabs(xa - xb) < fDistThreshDrift;
125  }
bool reco3d::TripletFinder::CloseSpace ( geo::WireIDIntersection  ra,
geo::WireIDIntersection  rb 
) const
protected

Definition at line 129 of file TripletFinder.cxx.

130  {
131  const TVector3 pa(ra.y, ra.z, 0);
132  const TVector3 pb(rb.y, rb.z, 0);
133 
134  return (pa - pb).Mag() < fDistThresh;
135  }
double z
z position of intersection
Definition: geo_types.h:805
double y
y position of intersection
Definition: geo_types.h:804
static constexpr double pb
Definition: Units.h:82
std::vector< ChannelDoublet > reco3d::TripletFinder::DoubletHelper ( geo::TPCID  tpc,
const std::vector< HitOrChan > &  ahits,
const std::vector< HitOrChan > &  bhits,
const std::vector< raw::ChannelID_t > &  bbads 
) const
protected

Definition at line 302 of file TripletFinder.cxx.

306  {
307  std::vector<ChannelDoublet> ret;
308 
309  IntersectionCache isect(tpc);
310 
311  auto b_begin = bhits.begin();
312 
313  for (const HitOrChan& a : ahits) {
314  // Bad channels are easy because there's no timing constraint
315  for (raw::ChannelID_t b : bbads) {
317  if (isect(a.chan, b, pt)) { ret.emplace_back(a, b, pt); }
318  }
319 
320  while (b_begin != bhits.end() && b_begin->xpos < a.xpos && !CloseDrift(b_begin->xpos, a.xpos))
321  ++b_begin;
322 
323  for (auto bit = b_begin; bit != bhits.end(); ++bit) {
324  const HitOrChan& b = *bit;
325 
326  if (b.xpos > a.xpos && !CloseDrift(b.xpos, a.xpos)) break;
327 
329  if (!isect(a.chan, b.chan, pt)) continue;
330 
331  ret.emplace_back(a, b, pt);
332  } // end for b
333  } // end for a
334 
335  return ret;
336  }
const double a
bool CloseDrift(double xa, double xb) const
static bool * b
Definition: config.cpp:1043
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< ChannelDoublet > reco3d::TripletFinder::DoubletsXU ( geo::TPCID  tpc)
protected

Definition at line 272 of file TripletFinder.cxx.

273  {
274  std::vector<ChannelDoublet> ret =
275  DoubletHelper(tpc, fX_by_tpc[tpc], fU_by_tpc[tpc], fUbad_by_tpc[tpc]);
276 
277  // Find X(bad)+U(good) doublets, have to flip them for the final result
278  for (auto it : DoubletHelper(tpc, fU_by_tpc[tpc], {}, fXbad_by_tpc[tpc])) {
279  ret.push_back({it.b, it.a, it.pt});
280  }
281 
282  return ret;
283  }
std::vector< ChannelDoublet > DoubletHelper(geo::TPCID tpc, const std::vector< HitOrChan > &ahits, const std::vector< HitOrChan > &bhits, const std::vector< raw::ChannelID_t > &bbads) const
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:94
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
Definition: TripletFinder.h:99
std::map< geo::TPCID, std::vector< HitOrChan > > fU_by_tpc
Definition: TripletFinder.h:95
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fUbad_by_tpc
std::vector< ChannelDoublet > reco3d::TripletFinder::DoubletsXV ( geo::TPCID  tpc)
protected

Definition at line 287 of file TripletFinder.cxx.

288  {
289  std::vector<ChannelDoublet> ret =
290  DoubletHelper(tpc, fX_by_tpc[tpc], fV_by_tpc[tpc], fVbad_by_tpc[tpc]);
291 
292  // Find X(bad)+V(good) doublets, have to flip them for the final result
293  for (auto it : DoubletHelper(tpc, fV_by_tpc[tpc], {}, fXbad_by_tpc[tpc])) {
294  ret.push_back({it.b, it.a, it.pt});
295  }
296 
297  return ret;
298  }
std::vector< ChannelDoublet > DoubletHelper(geo::TPCID tpc, const std::vector< HitOrChan > &ahits, const std::vector< HitOrChan > &bhits, const std::vector< raw::ChannelID_t > &bbads) const
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:94
std::map< geo::TPCID, std::vector< HitOrChan > > fV_by_tpc
Definition: TripletFinder.h:96
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
Definition: TripletFinder.h:99
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fVbad_by_tpc
void reco3d::TripletFinder::FillBadMap ( const std::vector< raw::ChannelID_t > &  bads,
std::map< geo::TPCID, std::vector< raw::ChannelID_t >> &  out 
)
protected

Helper for constructor.

Definition at line 62 of file TripletFinder.cxx.

64  {
65  for (raw::ChannelID_t chan : bads) {
66  for (geo::TPCID tpc : geom->ROPtoTPCs(geom->ChannelToROP(chan))) {
67  out[tpc].push_back(chan);
68  }
69  }
70  }
std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const
Returns a list of ID of TPCs the specified ROP spans.
const geo::GeometryCore * geom
Definition: TripletFinder.h:69
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
readout::ROPID ChannelToROP(raw::ChannelID_t channel) const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void reco3d::TripletFinder::FillHitMap ( const detinfo::DetectorPropertiesData clockData,
const std::vector< art::Ptr< recob::Hit >> &  hits,
std::map< geo::TPCID, std::vector< HitOrChan >> &  out 
)
protected

Helper for constructor.

Definition at line 39 of file TripletFinder.cxx.

42  {
43  for (const art::Ptr<recob::Hit>& hit : hits) {
44  for (geo::TPCID tpc : geom->ROPtoTPCs(geom->ChannelToROP(hit->Channel()))) {
45  double xpos = 0;
46  for (geo::WireID wire : geom->ChannelToWire(hit->Channel())) {
47  if (geo::TPCID(wire) == tpc) {
48  xpos = detProp.ConvertTicksToX(hit->PeakTime(), wire);
49  if (geom->SignalType(wire) == geo::kCollection) xpos += fXHitOffset;
50  }
51  }
52 
53  out[tpc].emplace_back(hit.get(), xpos);
54  }
55  }
56  for (auto& it : out)
57  std::sort(it.second.begin(), it.second.end(), [](auto a, auto b) { return a.xpos < b.xpos; });
58  }
std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const
Returns a list of ID of TPCs the specified ROP spans.
TH3F * xpos
Definition: doAna.cpp:29
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
const geo::GeometryCore * geom
Definition: TripletFinder.h:69
const double a
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
Detector simulation of raw signals on wires.
readout::ROPID ChannelToROP(raw::ChannelID_t channel) const
static bool * b
Definition: config.cpp:1043
Signal from collection planes.
Definition: geo_types.h:146
std::vector< HitTriplet > reco3d::TripletFinder::Triplets ( )

Definition at line 155 of file TripletFinder.cxx.

156  {
157  std::vector<HitTriplet> ret;
158 
159  for (const auto& it : fX_by_tpc) {
160  const geo::TPCID& tpc = it.first;
161 
162  std::vector<ChannelDoublet> xus = DoubletsXU(tpc);
163  std::vector<ChannelDoublet> xvs = DoubletsXV(tpc);
164 
165  // Cache to prevent repeating the same questions
166  IntersectionCache isectUV(tpc);
167 
168  // For the efficient looping below to work we need to sort the doublet
169  // lists so the X hits occur in the same order.
170  std::sort(xus.begin(), xus.end(), LessThanXHit);
171  std::sort(xvs.begin(), xvs.end(), LessThanXHit);
172 
173  auto xvit_begin = xvs.begin();
174 
175  int nxuv = 0;
176  for (const ChannelDoublet& xu : xus) {
177  const HitOrChan& x = xu.a;
178  const HitOrChan& u = xu.b;
179 
180  // Catch up until we're looking at the same X hit in XV
181  while (xvit_begin != xvs.end() && LessThanXHit(*xvit_begin, xu))
182  ++xvit_begin;
183 
184  // Loop through all those matching hits
185  for (auto xvit = xvit_begin; xvit != xvs.end() && SameXHit(*xvit, xu); ++xvit) {
186  const HitOrChan& v = xvit->b;
187 
188  // Only allow one bad channel per triplet
189  if (!x.hit && !u.hit) continue;
190  if (!x.hit && !v.hit) continue;
191  if (!u.hit && !v.hit) continue;
192 
193  if (u.hit && v.hit && !CloseDrift(u.xpos, v.xpos)) continue;
194 
196  if (!isectUV(u.chan, v.chan, ptUV)) continue;
197 
198  if (!CloseSpace(xu.pt, xvit->pt) || !CloseSpace(xu.pt, ptUV) ||
199  !CloseSpace(xvit->pt, ptUV))
200  continue;
201 
202  double xavg = 0;
203  int nx = 0;
204  if (x.hit) {
205  xavg += x.xpos;
206  ++nx;
207  }
208  if (u.hit) {
209  xavg += u.xpos;
210  ++nx;
211  }
212  if (v.hit) {
213  xavg += v.xpos;
214  ++nx;
215  }
216  xavg /= nx;
217 
218  const XYZ pt{
219  xavg, (xu.pt.y + xvit->pt.y + ptUV.y) / 3, (xu.pt.z + xvit->pt.z + ptUV.z) / 3};
220 
221  ret.emplace_back(HitTriplet{x.hit, u.hit, v.hit, pt});
222  ++nxuv;
223  } // end for xv
224  } // end for xu
225 
226  std::cout << tpc << " " << xus.size() << " XUs and " << xvs.size() << " XVs -> " << nxuv
227  << " XUVs" << std::endl;
228 
229  } // end for tpc
230 
231  std::cout << ret.size() << " XUVs total" << std::endl;
232 
233  return ret;
234  }
bool CloseSpace(geo::WireIDIntersection ra, geo::WireIDIntersection rb) const
double z
z position of intersection
Definition: geo_types.h:805
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:94
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
bool SameXHit(const ChannelDoublet &a, const ChannelDoublet &b)
std::vector< ChannelDoublet > DoubletsXV(geo::TPCID tpc)
std::vector< ChannelDoublet > DoubletsXU(geo::TPCID tpc)
double y
y position of intersection
Definition: geo_types.h:804
bool CloseDrift(double xa, double xb) const
bool LessThanXHit(const ChannelDoublet &a, const ChannelDoublet &b)
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)
std::vector< HitTriplet > reco3d::TripletFinder::TripletsTwoView ( )

Only search for XU intersections.

Definition at line 238 of file TripletFinder.cxx.

239  {
240  std::vector<HitTriplet> ret;
241 
242  for (const auto& it : fX_by_tpc) {
243  const geo::TPCID& tpc = it.first;
244 
245  std::vector<ChannelDoublet> xus = DoubletsXU(tpc);
246 
247  for (const ChannelDoublet& xu : xus) {
248  const HitOrChan& x = xu.a;
249  const HitOrChan& u = xu.b;
250 
251  double xavg = x.xpos;
252  int nx = 1;
253  if (u.hit) {
254  xavg += u.xpos;
255  ++nx;
256  }
257  xavg /= nx;
258 
259  const XYZ pt{xavg, xu.pt.y, xu.pt.z};
260 
261  ret.emplace_back(HitTriplet{x.hit, u.hit, 0, pt});
262  } // end for xu
263  } // end for tpc
264 
265  std::cout << ret.size() << " XUs total" << std::endl;
266 
267  return ret;
268  }
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:94
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
std::vector< ChannelDoublet > DoubletsXU(geo::TPCID tpc)
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)

Member Data Documentation

double reco3d::TripletFinder::fDistThresh
protected

Definition at line 90 of file TripletFinder.h.

double reco3d::TripletFinder::fDistThreshDrift
protected

Definition at line 91 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<HitOrChan> > reco3d::TripletFinder::fU_by_tpc
protected

Definition at line 95 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<raw::ChannelID_t> > reco3d::TripletFinder::fUbad_by_tpc
protected

Definition at line 100 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<HitOrChan> > reco3d::TripletFinder::fV_by_tpc
protected

Definition at line 96 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<raw::ChannelID_t> > reco3d::TripletFinder::fVbad_by_tpc
protected

Definition at line 101 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<HitOrChan> > reco3d::TripletFinder::fX_by_tpc
protected

Definition at line 94 of file TripletFinder.h.

std::map<geo::TPCID, std::vector<raw::ChannelID_t> > reco3d::TripletFinder::fXbad_by_tpc
protected

Definition at line 99 of file TripletFinder.h.

double reco3d::TripletFinder::fXHitOffset
protected

Definition at line 92 of file TripletFinder.h.

const geo::GeometryCore* reco3d::TripletFinder::geom
protected

Definition at line 69 of file TripletFinder.h.


The documentation for this class was generated from the following files: