LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_cluster3d::DBScanAlg Class Reference

DBScanAlg class definiton. More...

Inheritance diagram for lar_cluster3d::DBScanAlg:
lar_cluster3d::IClusterAlg

Public Types

enum  TimeValues {
  BUILDTHREEDHITS = 0, BUILDHITTOHITMAP = 1, RUNDBSCAN = 2, BUILDCLUSTERINFO = 3,
  PATHFINDING = 4, NUMTIMEVALUES
}
 enumerate the possible values for time checking if monitoring timing More...
 

Public Member Functions

 DBScanAlg (fhicl::ParameterSet const &pset)
 Constructor. More...
 
 ~DBScanAlg ()
 Destructor. More...
 
void configure (const fhicl::ParameterSet &) override
 Interface for configuring the particular algorithm tool. More...
 
void Cluster3DHits (reco::HitPairList &hitPairList, reco::ClusterParametersList &clusterParametersList) const override
 Given a set of recob hits, run DBscan to form 3D clusters. More...
 
void Cluster3DHits (reco::HitPairListPtr &hitPairList, reco::ClusterParametersList &clusterParametersList) const override
 Given a set of recob hits, run DBscan to form 3D clusters. More...
 
float getTimeToExecute (IClusterAlg::TimeValues index) const override
 If monitoring, recover the time to execute a particular function. More...
 

Private Member Functions

void expandCluster (const kdTree::KdTreeNode &, kdTree::CandPairList &, reco::ClusterParameters &, size_t) const
 the main routine for DBScan More...
 

Private Attributes

bool m_enableMonitoring
 Data members to follow. More...
 
size_t m_minPairPts
 
std::vector< float > m_timeVector
 
std::unique_ptr< lar_cluster3d::IClusterParametersBuilderm_clusterBuilder
 Common cluster builder tool. More...
 
kdTree m_kdTree
 

Detailed Description

DBScanAlg class definiton.

Definition at line 34 of file DBScanAlg_tool.cc.

Member Enumeration Documentation

enumerate the possible values for time checking if monitoring timing

Enumerator
BUILDTHREEDHITS 
BUILDHITTOHITMAP 
RUNDBSCAN 
BUILDCLUSTERINFO 
PATHFINDING 
NUMTIMEVALUES 

Definition at line 61 of file IClusterAlg.h.

Constructor & Destructor Documentation

lar_cluster3d::DBScanAlg::DBScanAlg ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Parameters
pset

Definition at line 97 of file DBScanAlg_tool.cc.

References configure().

98  {
99  this->configure(pset);
100  }
void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
lar_cluster3d::DBScanAlg::~DBScanAlg ( )

Destructor.

Definition at line 104 of file DBScanAlg_tool.cc.

104 {}

Member Function Documentation

void lar_cluster3d::DBScanAlg::Cluster3DHits ( reco::HitPairList hitPairList,
reco::ClusterParametersList clusterParametersList 
) const
overridevirtual

Given a set of recob hits, run DBscan to form 3D clusters.

Parameters
hitPairListThe input list of 3D hits to run clustering on
clusterParametersListA list of cluster objects (parameters from associated hits)

Driver for processing input 2D hits, transforming to 3D hits and building lists of associated 3D hits (candidate 3D clusters)

Implements lar_cluster3d::IClusterAlg.

Definition at line 135 of file DBScanAlg_tool.cc.

References reco::ClusterParameters::addHit3D(), lar_cluster3d::IClusterAlg::BUILDCLUSTERINFO, lar_cluster3d::IClusterAlg::BUILDHITTOHITMAP, lar_cluster3d::kdTree::BuildKdTree(), reco::ClusterHit3D::CLUSTERATTACHED, reco::ClusterHit3D::CLUSTERNOISE, reco::ClusterHit3D::CLUSTERVISITED, expandCluster(), lar_cluster3d::kdTree::FindNearestNeighbors(), lar_cluster3d::kdTree::getTimeToExecute(), m_clusterBuilder, m_enableMonitoring, m_kdTree, m_minPairPts, m_timeVector, lar_cluster3d::IClusterAlg::NUMTIMEVALUES, and lar_cluster3d::IClusterAlg::RUNDBSCAN.

137  {
142  cet::cpu_timer theClockDBScan;
143 
144  m_timeVector.resize(NUMTIMEVALUES, 0.);
145 
146  // DBScan is driven of its "epsilon neighborhood". Computing adjacency within DBScan can be time
147  // consuming so the idea is the prebuild the adjaceny map and then run DBScan.
148  // We'll employ a kdTree to implement this scheme
149  kdTree::KdTreeNodeList kdTreeNodeContainer;
150  kdTree::KdTreeNode topNode = m_kdTree.BuildKdTree(hitPairList, kdTreeNodeContainer);
151 
153 
154  if (m_enableMonitoring) theClockDBScan.start();
155 
156  // Ok, here we go!
157  // The idea is to loop through all of the input 3D hits and do the clustering
158  for (const auto& hit : hitPairList) {
159  // Check if the hit has already been visited
160  if (hit.getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED) continue;
161 
162  // Mark as visited
164 
165  // Find the neighborhood for this hit
166  kdTree::CandPairList candPairList;
167  float bestDistance(std::numeric_limits<float>::max());
168 
169  m_kdTree.FindNearestNeighbors(&hit, topNode, candPairList, bestDistance);
170 
171  if (candPairList.size() < m_minPairPts) {
173  }
174  else {
175  // "Create" a new cluster and get a reference to it
176  clusterParametersList.push_back(reco::ClusterParameters());
177 
178  reco::ClusterParameters& curCluster = clusterParametersList.back();
179 
181  curCluster.addHit3D(&hit);
182 
183  // expand the cluster
184  expandCluster(topNode, candPairList, curCluster, m_minPairPts);
185  }
186  }
187 
188  if (m_enableMonitoring) {
189  theClockDBScan.stop();
190 
191  m_timeVector[RUNDBSCAN] = theClockDBScan.accumulated_real_time();
192  }
193 
194  // Initial clustering is done, now trim the list and get output parameters
195  cet::cpu_timer theClockBuildClusters;
196 
197  // Start clocks if requested
198  if (m_enableMonitoring) theClockBuildClusters.start();
199 
200  m_clusterBuilder->BuildClusterInfo(clusterParametersList);
201 
202  if (m_enableMonitoring) {
203  theClockBuildClusters.stop();
204 
205  m_timeVector[BUILDCLUSTERINFO] = theClockBuildClusters.accumulated_real_time();
206  }
207 
208  mf::LogDebug("Cluster3D") << ">>>>> DBScan done, found " << clusterParametersList.size()
209  << " clusters" << std::endl;
210 
211  return;
212  }
void expandCluster(const kdTree::KdTreeNode &, kdTree::CandPairList &, reco::ClusterParameters &, size_t) const
the main routine for DBScan
bool m_enableMonitoring
Data members to follow.
std::list< KdTreeNode > KdTreeNodeList
Definition: kdTree.h:69
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:183
Labelled "noise" by a clustering algorithm.
Definition: Cluster3D.h:105
std::unique_ptr< lar_cluster3d::IClusterParametersBuilder > m_clusterBuilder
Common cluster builder tool.
Detector simulation of raw signals on wires.
std::list< CandPair > CandPairList
Definition: kdTree.h:84
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
float getTimeToExecute() const
Definition: kdTree.h:104
"visited" by a clustering algorithm
Definition: Cluster3D.h:104
std::vector< float > m_timeVector
KdTreeNode & BuildKdTree(Hit3DVec::iterator, Hit3DVec::iterator, KdTreeNodeList &, int depth=0) const
Given an input set of ClusterHit3D objects, build a kd tree structure.
Definition: kdTree.cxx:109
attached to a cluster
Definition: Cluster3D.h:106
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:445
void lar_cluster3d::DBScanAlg::Cluster3DHits ( reco::HitPairListPtr hitPairList,
reco::ClusterParametersList clusterParametersList 
) const
overridevirtual

Given a set of recob hits, run DBscan to form 3D clusters.

Parameters
hitPairListThe input list of 3D hits to run clustering on
clusterParametersListA list of cluster objects (parameters from associated hits)

Driver for processing input 2D hits, transforming to 3D hits and building lists of associated 3D hits (candidate 3D clusters)

Implements lar_cluster3d::IClusterAlg.

Definition at line 214 of file DBScanAlg_tool.cc.

References reco::ClusterParameters::addHit3D(), lar_cluster3d::IClusterAlg::BUILDCLUSTERINFO, lar_cluster3d::IClusterAlg::BUILDHITTOHITMAP, lar_cluster3d::kdTree::BuildKdTree(), reco::ClusterHit3D::CLUSTERATTACHED, reco::ClusterHit3D::CLUSTERNOISE, reco::ClusterHit3D::CLUSTERVISITED, expandCluster(), lar_cluster3d::kdTree::FindNearestNeighbors(), lar_cluster3d::kdTree::getTimeToExecute(), m_clusterBuilder, m_enableMonitoring, m_kdTree, m_minPairPts, m_timeVector, lar_cluster3d::IClusterAlg::NUMTIMEVALUES, and lar_cluster3d::IClusterAlg::RUNDBSCAN.

216  {
221  cet::cpu_timer theClockDBScan;
222 
223  m_timeVector.resize(NUMTIMEVALUES, 0.);
224 
225  // DBScan is driven of its "epsilon neighborhood". Computing adjacency within DBScan can be time
226  // consuming so the idea is the prebuild the adjaceny map and then run DBScan.
227  // We'll employ a kdTree to implement this scheme
228  kdTree::KdTreeNodeList kdTreeNodeContainer;
229  kdTree::KdTreeNode topNode = m_kdTree.BuildKdTree(hitPairList, kdTreeNodeContainer);
230 
232 
233  if (m_enableMonitoring) theClockDBScan.start();
234 
235  // Ok, here we go!
236  // The idea is to loop through all of the input 3D hits and do the clustering
237  for (const auto& hit : hitPairList) {
238  // Check if the hit has already been visited
239  if (hit->getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED) continue;
240 
241  // Mark as visited
243 
244  // Find the neighborhood for this hit
245  kdTree::CandPairList candPairList;
246  float bestDistance(std::numeric_limits<float>::max());
247 
248  m_kdTree.FindNearestNeighbors(hit, topNode, candPairList, bestDistance);
249 
250  if (candPairList.size() < m_minPairPts) {
251  hit->setStatusBit(reco::ClusterHit3D::CLUSTERNOISE);
252  }
253  else {
254  // "Create" a new cluster and get a reference to it
255  clusterParametersList.push_back(reco::ClusterParameters());
256 
257  reco::ClusterParameters& curCluster = clusterParametersList.back();
258 
260  curCluster.addHit3D(hit);
261 
262  // expand the cluster
263  expandCluster(topNode, candPairList, curCluster, m_minPairPts);
264  }
265  }
266 
267  if (m_enableMonitoring) {
268  theClockDBScan.stop();
269 
270  m_timeVector[RUNDBSCAN] = theClockDBScan.accumulated_real_time();
271  }
272 
273  // Initial clustering is done, now trim the list and get output parameters
274  cet::cpu_timer theClockBuildClusters;
275 
276  // Start clocks if requested
277  if (m_enableMonitoring) theClockBuildClusters.start();
278 
279  m_clusterBuilder->BuildClusterInfo(clusterParametersList);
280 
281  if (m_enableMonitoring) {
282  theClockBuildClusters.stop();
283 
284  m_timeVector[BUILDCLUSTERINFO] = theClockBuildClusters.accumulated_real_time();
285  }
286 
287  mf::LogDebug("Cluster3D") << ">>>>> DBScan done, found " << clusterParametersList.size()
288  << " clusters" << std::endl;
289 
290  return;
291  }
void expandCluster(const kdTree::KdTreeNode &, kdTree::CandPairList &, reco::ClusterParameters &, size_t) const
the main routine for DBScan
bool m_enableMonitoring
Data members to follow.
std::list< KdTreeNode > KdTreeNodeList
Definition: kdTree.h:69
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:183
Labelled "noise" by a clustering algorithm.
Definition: Cluster3D.h:105
std::unique_ptr< lar_cluster3d::IClusterParametersBuilder > m_clusterBuilder
Common cluster builder tool.
Detector simulation of raw signals on wires.
std::list< CandPair > CandPairList
Definition: kdTree.h:84
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
float getTimeToExecute() const
Definition: kdTree.h:104
"visited" by a clustering algorithm
Definition: Cluster3D.h:104
std::vector< float > m_timeVector
KdTreeNode & BuildKdTree(Hit3DVec::iterator, Hit3DVec::iterator, KdTreeNodeList &, int depth=0) const
Given an input set of ClusterHit3D objects, build a kd tree structure.
Definition: kdTree.cxx:109
attached to a cluster
Definition: Cluster3D.h:106
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:445
void lar_cluster3d::DBScanAlg::configure ( const fhicl::ParameterSet )
overridevirtual

Interface for configuring the particular algorithm tool.

Parameters
ParameterSetThe input set of parameters for configuration

Implements lar_cluster3d::IClusterAlg.

Definition at line 108 of file DBScanAlg_tool.cc.

References fhicl::ParameterSet::get(), m_clusterBuilder, m_enableMonitoring, m_kdTree, m_minPairPts, fhicl::ParameterSet::put_or_replace(), and geo::GeometryCore::WirePitch().

Referenced by DBScanAlg().

109  {
110  m_enableMonitoring = pset.get<bool>("EnableMonitoring", true);
111  m_minPairPts = pset.get<size_t>("MinPairPts", 2);
112 
113  m_clusterBuilder = art::make_tool<lar_cluster3d::IClusterParametersBuilder>(
114  pset.get<fhicl::ParameterSet>("ClusterParamsBuilder"));
115 
116  // Recover the parameter set for the kdTree
117  fhicl::ParameterSet kdTreeParams(pset.get<fhicl::ParameterSet>("kdTree"));
118 
119  // Now work out the maximum wire pitch
121 
122  // Returns the wire pitch per plane assuming they will be the same for all TPCs
123  constexpr geo::TPCID tpcid{0, 0};
124  std::vector<double> const wirePitchVec{geometry->WirePitch(geo::PlaneID{tpcid, 0}),
125  geometry->WirePitch(geo::PlaneID{tpcid, 1}),
126  geometry->WirePitch(geo::PlaneID{tpcid, 2})};
127 
128  float maxBestDist = 1.99 * *std::max_element(wirePitchVec.begin(), wirePitchVec.end());
129 
130  kdTreeParams.put_or_replace<float>("RefLeafBestDist", maxBestDist);
131 
132  m_kdTree = kdTree(kdTreeParams);
133  }
bool m_enableMonitoring
Data members to follow.
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
std::unique_ptr< lar_cluster3d::IClusterParametersBuilder > m_clusterBuilder
Common cluster builder tool.
Length_t WirePitch(PlaneID const &planeid=plane_zero) const
Returns the distance between two consecutive wires.
void lar_cluster3d::DBScanAlg::expandCluster ( const kdTree::KdTreeNode topNode,
kdTree::CandPairList candPairList,
reco::ClusterParameters cluster,
size_t  minPts 
) const
private

the main routine for DBScan

Definition at line 293 of file DBScanAlg_tool.cc.

References reco::ClusterParameters::addHit3D(), reco::ClusterHit3D::CLUSTERATTACHED, reco::ClusterHit3D::CLUSTERVISITED, DEFINE_ART_CLASS_TOOL, lar_cluster3d::kdTree::FindNearestNeighbors(), reco::ClusterHit3D::getStatusBits(), m_kdTree, and reco::ClusterHit3D::setStatusBit().

Referenced by Cluster3DHits(), and getTimeToExecute().

297  {
298  // This is the main inside loop for the DBScan based clustering algorithm
299 
300  // Loop over added hits until list has been exhausted
301  while (!candPairList.empty()) {
302  // Dereference the point so we can see in the debugger...
303  const reco::ClusterHit3D* neighborHit = candPairList.front().second;
304 
305  // Process if we've not been here before
306  if (!(neighborHit->getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED)) {
307  // set as visited
309 
310  // get the neighborhood around this point
311  kdTree::CandPairList neighborCandPairList;
312  float bestDistance(std::numeric_limits<float>::max());
313 
314  m_kdTree.FindNearestNeighbors(neighborHit, topNode, neighborCandPairList, bestDistance);
315 
316  // If the epsilon neighborhood of this point is large enough then add its points to our list
317  if (neighborCandPairList.size() >= minPts) {
318  std::copy(neighborCandPairList.begin(),
319  neighborCandPairList.end(),
320  std::back_inserter(candPairList));
321  }
322  }
323 
324  // If the point is not yet in a cluster then we now add
325  if (!(neighborHit->getStatusBits() & reco::ClusterHit3D::CLUSTERATTACHED)) {
327  cluster.addHit3D(neighborHit);
328  }
329 
330  candPairList.pop_front();
331  }
332 
333  return;
334  }
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:183
unsigned int getStatusBits() const
Definition: Cluster3D.h:154
std::list< CandPair > CandPairList
Definition: kdTree.h:84
"visited" by a clustering algorithm
Definition: Cluster3D.h:104
attached to a cluster
Definition: Cluster3D.h:106
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:445
void setStatusBit(unsigned bits) const
Definition: Cluster3D.h:177
float lar_cluster3d::DBScanAlg::getTimeToExecute ( IClusterAlg::TimeValues  index) const
inlineoverridevirtual

If monitoring, recover the time to execute a particular function.

Implements lar_cluster3d::IClusterAlg.

Definition at line 71 of file DBScanAlg_tool.cc.

References expandCluster(), and m_timeVector.

72  {
73  return m_timeVector[index];
74  }
std::vector< float > m_timeVector

Member Data Documentation

std::unique_ptr<lar_cluster3d::IClusterParametersBuilder> lar_cluster3d::DBScanAlg::m_clusterBuilder
private

Common cluster builder tool.

Definition at line 93 of file DBScanAlg_tool.cc.

Referenced by Cluster3DHits(), and configure().

bool lar_cluster3d::DBScanAlg::m_enableMonitoring
private

Data members to follow.

Definition at line 88 of file DBScanAlg_tool.cc.

Referenced by Cluster3DHits(), and configure().

kdTree lar_cluster3d::DBScanAlg::m_kdTree
private

Definition at line 94 of file DBScanAlg_tool.cc.

Referenced by Cluster3DHits(), configure(), and expandCluster().

size_t lar_cluster3d::DBScanAlg::m_minPairPts
private

Definition at line 89 of file DBScanAlg_tool.cc.

Referenced by Cluster3DHits(), and configure().

std::vector<float> lar_cluster3d::DBScanAlg::m_timeVector
mutableprivate

Definition at line 90 of file DBScanAlg_tool.cc.

Referenced by Cluster3DHits(), and getTimeToExecute().


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