Public Member Functions | Private Member Functions | Private Attributes | List of all members
lar_cluster3d::DBScanAlg Class Reference

DBScanAlg class definiton. More...

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

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...
 
- Public Member Functions inherited from lar_cluster3d::IClusterAlg
virtual ~IClusterAlg () noexcept=default
 Virtual Destructor. 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
 

Additional Inherited Members

- Public Types inherited from lar_cluster3d::IClusterAlg
enum  TimeValues {
  BUILDTHREEDHITS = 0, BUILDHITTOHITMAP = 1, RUNDBSCAN = 2, BUILDCLUSTERINFO = 3,
  PATHFINDING = 4, NUMTIMEVALUES
}
 enumerate the possible values for time checking if monitoring timing More...
 

Detailed Description

DBScanAlg class definiton.

Definition at line 34 of file DBScanAlg_tool.cc.

Constructor & Destructor Documentation

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

Constructor.

Parameters
pset

Definition at line 95 of file DBScanAlg_tool.cc.

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

Destructor.

Definition at line 102 of file DBScanAlg_tool.cc.

103 {
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.

137 {
138  /**
139  * @brief Driver for processing input 2D hits, transforming to 3D hits and building lists
140  * of associated 3D hits (candidate 3D clusters)
141  */
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  {
160  // Check if the hit has already been visited
161  if (hit.getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED) continue;
162 
163  // Mark as visited
165 
166  // Find the neighborhood for this hit
167  kdTree::CandPairList candPairList;
168  float bestDistance(std::numeric_limits<float>::max());
169 
170  m_kdTree.FindNearestNeighbors(&hit, topNode, candPairList, bestDistance);
171 
172  if (candPairList.size() < m_minPairPts)
173  {
175  }
176  else
177  {
178  // "Create" a new cluster and get a reference to it
179  clusterParametersList.push_back(reco::ClusterParameters());
180 
181  reco::ClusterParameters& curCluster = clusterParametersList.back();
182 
184  curCluster.addHit3D(&hit);
185 
186  // expand the cluster
187  expandCluster(topNode, candPairList, curCluster, m_minPairPts);
188  }
189  }
190 
191  if (m_enableMonitoring)
192  {
193  theClockDBScan.stop();
194 
195  m_timeVector[RUNDBSCAN] = theClockDBScan.accumulated_real_time();
196  }
197 
198  // Initial clustering is done, now trim the list and get output parameters
199  cet::cpu_timer theClockBuildClusters;
200 
201  // Start clocks if requested
202  if (m_enableMonitoring) theClockBuildClusters.start();
203 
204  m_clusterBuilder->BuildClusterInfo(clusterParametersList);
205 
206  if (m_enableMonitoring)
207  {
208  theClockBuildClusters.stop();
209 
210  m_timeVector[BUILDCLUSTERINFO] = theClockBuildClusters.accumulated_real_time();
211  }
212 
213  mf::LogDebug("Cluster3D") << ">>>>> DBScan done, found " << clusterParametersList.size() << " clusters" << std::endl;
214 
215  return;
216 }
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:67
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:170
Labelled "noise" by a clustering algorithm.
Definition: Cluster3D.h:108
static int max(int a, int b)
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:79
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
double accumulated_real_time() const
Definition: cpu_timer.cc:66
float getTimeToExecute() const
Definition: kdTree.h:95
"visited" by a clustering algorithm
Definition: Cluster3D.h:107
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:112
void start()
Definition: cpu_timer.cc:83
attached to a cluster
Definition: Cluster3D.h:109
QTextStream & endl(QTextStream &s)
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:457
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 218 of file DBScanAlg_tool.cc.

220 {
221  /**
222  * @brief Driver for processing input 2D hits, transforming to 3D hits and building lists
223  * of associated 3D hits (candidate 3D clusters)
224  */
225  cet::cpu_timer theClockDBScan;
226 
227  m_timeVector.resize(NUMTIMEVALUES, 0.);
228 
229  // DBScan is driven of its "epsilon neighborhood". Computing adjacency within DBScan can be time
230  // consuming so the idea is the prebuild the adjaceny map and then run DBScan.
231  // We'll employ a kdTree to implement this scheme
232  kdTree::KdTreeNodeList kdTreeNodeContainer;
233  kdTree::KdTreeNode topNode = m_kdTree.BuildKdTree(hitPairList, kdTreeNodeContainer);
234 
236 
237  if (m_enableMonitoring) theClockDBScan.start();
238 
239  // Ok, here we go!
240  // The idea is to loop through all of the input 3D hits and do the clustering
241  for(const auto& hit : hitPairList)
242  {
243  // Check if the hit has already been visited
244  if (hit->getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED) continue;
245 
246  // Mark as visited
248 
249  // Find the neighborhood for this hit
250  kdTree::CandPairList candPairList;
251  float bestDistance(std::numeric_limits<float>::max());
252 
253  m_kdTree.FindNearestNeighbors(hit, topNode, candPairList, bestDistance);
254 
255  if (candPairList.size() < m_minPairPts)
256  {
257  hit->setStatusBit(reco::ClusterHit3D::CLUSTERNOISE);
258  }
259  else
260  {
261  // "Create" a new cluster and get a reference to it
262  clusterParametersList.push_back(reco::ClusterParameters());
263 
264  reco::ClusterParameters& curCluster = clusterParametersList.back();
265 
267  curCluster.addHit3D(hit);
268 
269  // expand the cluster
270  expandCluster(topNode, candPairList, curCluster, m_minPairPts);
271  }
272  }
273 
274  if (m_enableMonitoring)
275  {
276  theClockDBScan.stop();
277 
278  m_timeVector[RUNDBSCAN] = theClockDBScan.accumulated_real_time();
279  }
280 
281  // Initial clustering is done, now trim the list and get output parameters
282  cet::cpu_timer theClockBuildClusters;
283 
284  // Start clocks if requested
285  if (m_enableMonitoring) theClockBuildClusters.start();
286 
287  m_clusterBuilder->BuildClusterInfo(clusterParametersList);
288 
289  if (m_enableMonitoring)
290  {
291  theClockBuildClusters.stop();
292 
293  m_timeVector[BUILDCLUSTERINFO] = theClockBuildClusters.accumulated_real_time();
294  }
295 
296  mf::LogDebug("Cluster3D") << ">>>>> DBScan done, found " << clusterParametersList.size() << " clusters" << std::endl;
297 
298  return;
299 }
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:67
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:170
Labelled "noise" by a clustering algorithm.
Definition: Cluster3D.h:108
static int max(int a, int b)
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:79
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
double accumulated_real_time() const
Definition: cpu_timer.cc:66
float getTimeToExecute() const
Definition: kdTree.h:95
"visited" by a clustering algorithm
Definition: Cluster3D.h:107
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:112
void start()
Definition: cpu_timer.cc:83
attached to a cluster
Definition: Cluster3D.h:109
QTextStream & endl(QTextStream &s)
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:457
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.

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>(pset.get<fhicl::ParameterSet>("ClusterParamsBuilder"));
114 
115  // Recover the parameter set for the kdTree
116  fhicl::ParameterSet kdTreeParams(pset.get<fhicl::ParameterSet>("kdTree"));
117 
118  // Now work out the maximum wire pitch
120 
121  // Returns the wire pitch per plane assuming they will be the same for all TPCs
122  std::vector<float> wirePitchVec(3,0.);
123 
124  wirePitchVec[0] = geometry->WirePitch(0);
125  wirePitchVec[1] = geometry->WirePitch(1);
126  wirePitchVec[2] = geometry->WirePitch(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.
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
std::unique_ptr< lar_cluster3d::IClusterParametersBuilder > m_clusterBuilder
Common cluster builder tool.
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 301 of file DBScanAlg_tool.cc.

305 {
306  // This is the main inside loop for the DBScan based clustering algorithm
307 
308  // Loop over added hits until list has been exhausted
309  while(!candPairList.empty())
310  {
311  // Dereference the point so we can see in the debugger...
312  const reco::ClusterHit3D* neighborHit = candPairList.front().second;
313 
314  // Process if we've not been here before
315  if (!(neighborHit->getStatusBits() & reco::ClusterHit3D::CLUSTERVISITED))
316  {
317  // set as visited
319 
320  // get the neighborhood around this point
321  kdTree::CandPairList neighborCandPairList;
322  float bestDistance(std::numeric_limits<float>::max());
323 
324  m_kdTree.FindNearestNeighbors(neighborHit, topNode, neighborCandPairList, bestDistance);
325 
326  // If the epsilon neighborhood of this point is large enough then add its points to our list
327  if (neighborCandPairList.size() >= minPts)
328  {
329  std::copy(neighborCandPairList.begin(),neighborCandPairList.end(),std::back_inserter(candPairList));
330  }
331  }
332 
333  // If the point is not yet in a cluster then we now add
334  if (!(neighborHit->getStatusBits() & reco::ClusterHit3D::CLUSTERATTACHED))
335  {
337  cluster.addHit3D(neighborHit);
338  }
339 
340  candPairList.pop_front();
341  }
342 
343  return;
344 }
size_t FindNearestNeighbors(const reco::ClusterHit3D *, const KdTreeNode &, CandPairList &, float &) const
Definition: kdTree.cxx:170
unsigned int getStatusBits() const
Definition: Cluster3D.h:157
static int max(int a, int b)
std::list< CandPair > CandPairList
Definition: kdTree.h:79
T copy(T const &v)
"visited" by a clustering algorithm
Definition: Cluster3D.h:107
attached to a cluster
Definition: Cluster3D.h:109
void addHit3D(const reco::ClusterHit3D *hit3D)
Definition: Cluster3D.h:457
void setStatusBit(unsigned bits) const
Definition: Cluster3D.h:180
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 72 of file DBScanAlg_tool.cc.

Member Data Documentation

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

Common cluster builder tool.

Definition at line 91 of file DBScanAlg_tool.cc.

bool lar_cluster3d::DBScanAlg::m_enableMonitoring
private

Data members to follow.

Definition at line 87 of file DBScanAlg_tool.cc.

kdTree lar_cluster3d::DBScanAlg::m_kdTree
private

Definition at line 92 of file DBScanAlg_tool.cc.

size_t lar_cluster3d::DBScanAlg::m_minPairPts
private

Definition at line 88 of file DBScanAlg_tool.cc.

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

Definition at line 89 of file DBScanAlg_tool.cc.


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