LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
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, int maxTriplets=0)
 
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
 
const geo::WireReadoutGeomwireReadoutGeom
 
double fDistThresh
 
double fDistThreshDrift
 
double fXHitOffset
 
int fMaxTriplets
 
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 49 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,
int  maxTriplets = 0 
)

Definition at line 12 of file TripletFinder.cxx.

References fDistThresh, fDistThreshDrift, FillBadMap(), FillHitMap(), fMaxTriplets, fU_by_tpc, fUbad_by_tpc, fV_by_tpc, fVbad_by_tpc, fX_by_tpc, fXbad_by_tpc, fXHitOffset, and Get.

24  , fDistThresh(distThresh)
25  , fDistThreshDrift(distThreshDrift)
26  , fXHitOffset(xhitOffset)
27  , fMaxTriplets(maxTriplets)
28  {
29  FillHitMap(detProp, xhits, fX_by_tpc);
30  FillHitMap(detProp, uhits, fU_by_tpc);
31  FillHitMap(detProp, vhits, fV_by_tpc);
32 
33  FillBadMap(xbad, fXbad_by_tpc);
34  FillBadMap(ubad, fUbad_by_tpc);
35  FillBadMap(vbad, fVbad_by_tpc);
36  }
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:95
const geo::WireReadoutGeom * wireReadoutGeom
Definition: TripletFinder.h:69
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
std::map< geo::TPCID, std::vector< HitOrChan > > fV_by_tpc
Definition: TripletFinder.h:97
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
std::map< geo::TPCID, std::vector< HitOrChan > > fU_by_tpc
Definition: TripletFinder.h:96
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 114 of file TripletFinder.cxx.

References fDistThreshDrift.

Referenced by DoubletHelper(), and Triplets().

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

Definition at line 120 of file TripletFinder.cxx.

References fDistThresh, geo::WireIDIntersection::y, and geo::WireIDIntersection::z.

Referenced by Triplets().

121  {
122  const TVector3 pa(ra.y, ra.z, 0);
123  const TVector3 pb(rb.y, rb.z, 0);
124 
125  return (pa - pb).Mag() < fDistThresh;
126  }
double z
z position of intersection
Definition: geo_types.h:584
double y
y position of intersection
Definition: geo_types.h:583
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 289 of file TripletFinder.cxx.

References reco3d::HitOrChan::chan, CloseDrift(), pt, wireReadoutGeom, and reco3d::HitOrChan::xpos.

Referenced by DoubletsXU(), and DoubletsXV().

294  {
295  std::vector<ChannelDoublet> ret;
296 
297  IntersectionCache isect(wireReadoutGeom, tpc);
298 
299  auto b_begin = bhits.begin();
300 
301  for (const HitOrChan& a : ahits) {
302  // Bad channels are easy because there's no timing constraint
303  for (raw::ChannelID_t b : bbads) {
304  if (auto pt = isect(a.chan, b)) { ret.emplace_back(a, b, *pt); }
305  }
306 
307  while (b_begin != bhits.end() && b_begin->xpos < a.xpos && !CloseDrift(b_begin->xpos, a.xpos))
308  ++b_begin;
309 
310  for (auto bit = b_begin; bit != bhits.end(); ++bit) {
311  const HitOrChan& b = *bit;
312 
313  if (b.xpos > a.xpos && !CloseDrift(b.xpos, a.xpos)) break;
314 
315  auto pt = isect(a.chan, b.chan);
316  if (!pt) continue;
317 
318  ret.emplace_back(a, b, *pt);
319  } // end for b
320  } // end for a
321 
322  return ret;
323  }
const geo::WireReadoutGeom * wireReadoutGeom
Definition: TripletFinder.h:69
TMarker * pt
Definition: egs.C:25
bool CloseDrift(double xa, double xb) const
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 261 of file TripletFinder.cxx.

References DoubletHelper(), fU_by_tpc, fUbad_by_tpc, fX_by_tpc, and fXbad_by_tpc.

Referenced by Triplets(), and TripletsTwoView().

262  {
263  std::vector<ChannelDoublet> ret =
264  DoubletHelper(tpc, fX_by_tpc[tpc], fU_by_tpc[tpc], fUbad_by_tpc[tpc]);
265 
266  // Find X(bad)+U(good) doublets, have to flip them for the final result
267  for (auto it : DoubletHelper(tpc, fU_by_tpc[tpc], {}, fXbad_by_tpc[tpc])) {
268  ret.push_back({it.b, it.a, it.pt});
269  }
270 
271  return ret;
272  }
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:95
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
std::map< geo::TPCID, std::vector< HitOrChan > > fU_by_tpc
Definition: TripletFinder.h:96
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 275 of file TripletFinder.cxx.

References DoubletHelper(), fV_by_tpc, fVbad_by_tpc, fX_by_tpc, and fXbad_by_tpc.

Referenced by Triplets().

276  {
277  std::vector<ChannelDoublet> ret =
278  DoubletHelper(tpc, fX_by_tpc[tpc], fV_by_tpc[tpc], fVbad_by_tpc[tpc]);
279 
280  // Find X(bad)+V(good) doublets, have to flip them for the final result
281  for (auto it : DoubletHelper(tpc, fV_by_tpc[tpc], {}, fXbad_by_tpc[tpc])) {
282  ret.push_back({it.b, it.a, it.pt});
283  }
284 
285  return ret;
286  }
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:95
std::map< geo::TPCID, std::vector< HitOrChan > > fV_by_tpc
Definition: TripletFinder.h:97
std::map< geo::TPCID, std::vector< raw::ChannelID_t > > fXbad_by_tpc
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.

References geo::WireReadoutGeom::ChannelToROP(), geo::WireReadoutGeom::ROPtoTPCs(), and wireReadoutGeom.

Referenced by TripletFinder().

64  {
65  for (raw::ChannelID_t chan : bads) {
67  out[tpc].push_back(chan);
68  }
69  }
70  }
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const =0
Returns the ID of the ROP the channel belongs to.
const geo::WireReadoutGeom * wireReadoutGeom
Definition: TripletFinder.h:69
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
virtual std::vector< TPCID > ROPtoTPCs(readout::ROPID const &ropid) const =0
Returns a list of ID of TPCs the specified ROP spans.
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.

References geo::WireReadoutGeom::ChannelToROP(), geo::WireReadoutGeom::ChannelToWire(), detinfo::DetectorPropertiesData::ConvertTicksToX(), fXHitOffset, hits(), geo::kCollection, geo::WireReadoutGeom::ROPtoTPCs(), geo::WireReadoutGeom::SignalType(), and wireReadoutGeom.

Referenced by TripletFinder().

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

Definition at line 143 of file TripletFinder.cxx.

References reco3d::HitOrChan::chan, CloseDrift(), CloseSpace(), DoubletsXU(), DoubletsXV(), geo::TPCID::first(), fMaxTriplets, fX_by_tpc, reco3d::HitOrChan::hit, reco3d::LessThanXHit(), pt, reco3d::SameXHit(), wireReadoutGeom, x, and reco3d::HitOrChan::xpos.

Referenced by reco3d::SpacePointSolver::produce().

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

Only search for XU intersections.

Definition at line 228 of file TripletFinder.cxx.

References DoubletsXU(), geo::TPCID::first(), fX_by_tpc, reco3d::HitOrChan::hit, pt, x, and reco3d::HitOrChan::xpos.

229  {
230  std::vector<HitTriplet> ret;
231 
232  for (const auto& it : fX_by_tpc) {
233  const geo::TPCID& tpc = it.first;
234 
235  std::vector<ChannelDoublet> xus = DoubletsXU(tpc);
236 
237  for (const ChannelDoublet& xu : xus) {
238  const HitOrChan& x = xu.a;
239  const HitOrChan& u = xu.b;
240 
241  double xavg = x.xpos;
242  int nx = 1;
243  if (u.hit) {
244  xavg += u.xpos;
245  ++nx;
246  }
247  xavg /= nx;
248 
249  const XYZ pt{xavg, xu.pt.y, xu.pt.z};
250 
251  ret.emplace_back(HitTriplet{x.hit, u.hit, 0, pt});
252  } // end for xu
253  } // end for tpc
254 
255  std::cout << ret.size() << " XUs total" << std::endl;
256 
257  return ret;
258  }
Float_t x
Definition: compare.C:6
std::map< geo::TPCID, std::vector< HitOrChan > > fX_by_tpc
Definition: TripletFinder.h:95
TMarker * pt
Definition: egs.C:25
static constexpr auto first()
Definition: geo_types.h:328
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
std::vector< ChannelDoublet > DoubletsXU(geo::TPCID tpc)

Member Data Documentation

double reco3d::TripletFinder::fDistThresh
protected

Definition at line 90 of file TripletFinder.h.

Referenced by CloseSpace(), and TripletFinder().

double reco3d::TripletFinder::fDistThreshDrift
protected

Definition at line 91 of file TripletFinder.h.

Referenced by CloseDrift(), and TripletFinder().

int reco3d::TripletFinder::fMaxTriplets
protected

Definition at line 93 of file TripletFinder.h.

Referenced by TripletFinder(), and Triplets().

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

Definition at line 96 of file TripletFinder.h.

Referenced by DoubletsXU(), and TripletFinder().

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

Definition at line 101 of file TripletFinder.h.

Referenced by DoubletsXU(), and TripletFinder().

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

Definition at line 97 of file TripletFinder.h.

Referenced by DoubletsXV(), and TripletFinder().

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

Definition at line 102 of file TripletFinder.h.

Referenced by DoubletsXV(), and TripletFinder().

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

Definition at line 95 of file TripletFinder.h.

Referenced by DoubletsXU(), DoubletsXV(), TripletFinder(), Triplets(), and TripletsTwoView().

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

Definition at line 100 of file TripletFinder.h.

Referenced by DoubletsXU(), DoubletsXV(), and TripletFinder().

double reco3d::TripletFinder::fXHitOffset
protected

Definition at line 92 of file TripletFinder.h.

Referenced by FillHitMap(), and TripletFinder().

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

Definition at line 68 of file TripletFinder.h.

const geo::WireReadoutGeom* reco3d::TripletFinder::wireReadoutGeom
protected

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