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

#include "DBScanAlg.h"

Public Member Functions

 DBScanAlg (fhicl::ParameterSet const &pset)
 
void InitScan (const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &allhits, std::set< uint32_t > badChannels, const std::vector< geo::WireID > &wireids=std::vector< geo::WireID >())
 
double getSimilarity (const std::vector< double > v1, const std::vector< double > v2)
 
std::vector< unsigned int > findNeighbors (unsigned int pid, double threshold, double threshold2)
 
void computeSimilarity ()
 
void run_cluster ()
 
double getSimilarity2 (const std::vector< double > v1, const std::vector< double > v2)
 
void computeSimilarity2 ()
 
double getWidthFactor (const std::vector< double > v1, const std::vector< double > v2)
 
void computeWidthFactor ()
 

Public Attributes

std::vector< std::vector< unsigned int > > fclusters
 collection of something More...
 
std::vector< std::vector< double > > fps
 the collection of points we are working on More...
 
std::vector< unsigned int > fpointId_to_clusterId
 mapping point_id -> clusterId More...
 
std::vector< std::vector< double > > fsim
 
std::vector< std::vector< double > > fsim2
 
std::vector< std::vector< double > > fsim3
 
double fMaxWidth
 
RTree fRTree
 
std::vector< dbsPointfRect
 

Private Member Functions

void run_dbscan_cluster ()
 
void run_FN_cluster ()
 
void run_FN_naive_cluster ()
 
bool ExpandCluster (unsigned int point, unsigned int clusterID)
 
std::set< unsigned int > RegionQuery (unsigned int point)
 
std::vector< unsigned int > RegionQuery_vector (unsigned int point)
 

Private Attributes

double fEps
 
double fEps2
 
unsigned int fMinPts
 
unsigned int fClusterMethod
 Which clustering method to use. More...
 
unsigned int fDistanceMetric
 Which distance metric to use. More...
 
std::vector< bool > fnoise
 
std::vector< bool > fvisited
 
std::vector< double > fWirePitch
 the pitch of the wires in each plane More...
 
std::set< uint32_t > fBadChannels
 set of bad channels in this detector More...
 
std::vector< uint32_t > fBadWireSum
 

Detailed Description

Definition at line 51 of file DBScanAlg.h.

Constructor & Destructor Documentation

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

Definition at line 245 of file DBScanAlg.cxx.

References fhicl::ParameterSet::get().

246 {
247  fEps = p.get<double>("eps");
248  fEps2 = p.get<double>("epstwo");
249  fMinPts = p.get<int>("minPts");
250  fClusterMethod = p.get<int>("Method");
251  fDistanceMetric = p.get<int>("Metric");
252 }
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:90
unsigned int fMinPts
Definition: DBScanAlg.h:88
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:91

Member Function Documentation

void cluster::DBScanAlg::computeSimilarity ( )

Definition at line 469 of file DBScanAlg.cxx.

References util::size().

470 {
471  int size = fps.size();
472  fsim.resize(size, std::vector<double>(size));
473  for (int i = 0; i < size; i++) {
474  for (int j = i + 1; j < size; j++) {
475  fsim[j][i] = fsim[i][j] = getSimilarity(fps[i], fps[j]);
476  }
477  }
478 }
double getSimilarity(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:347
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:73
void cluster::DBScanAlg::computeSimilarity2 ( )

Definition at line 481 of file DBScanAlg.cxx.

References util::size().

482 {
483  int size = fps.size();
484  fsim2.resize(size, std::vector<double>(size));
485  for (int i = 0; i < size; i++) {
486  for (int j = i + 1; j < size; j++) {
487  fsim2[j][i] = fsim2[i][j] = getSimilarity2(fps[i], fps[j]);
488  }
489  }
490 }
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
double getSimilarity2(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:383
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:74
void cluster::DBScanAlg::computeWidthFactor ( )

Definition at line 493 of file DBScanAlg.cxx.

References util::size().

494 {
495  int size = fps.size();
496  fsim3.resize(size, std::vector<double>(size));
497 
498  for (int i = 0; i < size; i++) {
499  for (int j = i + 1; j < size; j++) {
500  fsim3[j][i] = fsim3[i][j] = getWidthFactor(fps[i], fps[j]);
501  }
502  }
503 }
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:75
double getWidthFactor(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:422
bool cluster::DBScanAlg::ExpandCluster ( unsigned int  point,
unsigned int  clusterID 
)
private

Definition at line 606 of file DBScanAlg.cxx.

References cluster::kNO_CLUSTER, cluster::kNOISE_CLUSTER, and tca::seeds.

607 {
608  /* GetSetOfPoints for point*/
609  std::set<unsigned int> seeds = RegionQuery(point);
610 
611  // not enough support -> mark as noise
612  if (seeds.size() < fMinPts) {
614  return false;
615  }
616  else {
617  // Add to the currecnt cluster
618  fpointId_to_clusterId[point] = clusterID;
619  for (std::set<unsigned int>::iterator itr = seeds.begin(); itr != seeds.end(); itr++) {
620  fpointId_to_clusterId[*itr] = clusterID;
621  }
622  seeds.erase(point);
623  while (!seeds.empty()) {
624  unsigned int currentP = *(seeds.begin());
625  std::set<unsigned int> result = RegionQuery(currentP);
626 
627  if (result.size() >= fMinPts) {
628  for (std::set<unsigned int>::iterator itr = result.begin(); itr != result.end(); itr++) {
629  unsigned int resultP = *itr;
630  // not already assigned to a cluster
631  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER ||
633  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER) { seeds.insert(resultP); }
634  fpointId_to_clusterId[resultP] = clusterID;
635  } // unclassified or noise
636  } // for
637  } // enough support
638  seeds.erase(currentP);
639  } // while
640  return true;
641  }
642 }
intermediate_table::iterator iterator
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:238
std::set< unsigned int > RegionQuery(unsigned int point)
Definition: DBScanAlg.cxx:570
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:239
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
unsigned int fMinPts
Definition: DBScanAlg.h:88
std::vector< unsigned int > cluster::DBScanAlg::findNeighbors ( unsigned int  pid,
double  threshold,
double  threshold2 
)

Definition at line 451 of file DBScanAlg.cxx.

454 {
455  std::vector<unsigned int> ne;
456 
457  for (int unsigned j = 0; j < fsim.size(); j++) {
458  if ((pid != j) &&
459  (((fsim[pid][j]) / (threshold * threshold)) +
460  ((fsim2[pid][j]) / (threshold2 * threshold2 * (fsim3[pid][j])))) < 1) { //ellipse
461  ne.push_back(j);
462  }
463  } // end loop over fsim
464 
465  return ne;
466 }
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:75
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:73
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:74
double cluster::DBScanAlg::getSimilarity ( const std::vector< double >  v1,
const std::vector< double >  v2 
)
Todo:
this code assumes that all planes have the same wire pitch

Definition at line 347 of file DBScanAlg.cxx.

References util::abs().

348 {
349 
350  //for Euclidean distance comment everything out except this-->>>
351  // return std::sqrt((v2[1]-v1[1])*(v2[1]-v1[1])+(v2[0]-v1[0])*(v2[0]-v1[0]));
352  //------------------------------------------------------------------------
353  // return std::abs( v2[0]-v1[0]); //for rectangle
354  //----------------------------------------------------------------------
355  //Manhattan distance:
356  //return std::abs(v1[0]-v2[0])+std::abs(v1[1]-v2[1]);
357 
359  double wire_dist = fWirePitch[0];
360 
361  unsigned int wire1 =
362  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
363  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
364  int wirestobridge = 0;
365 
366  if (wire1 > wire2) {
367  unsigned int wire = wire1;
368  wire1 = wire2;
369  wire2 = wire;
370  }
371 
372  for (unsigned int i = wire1; i < wire2; i++) {
373  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
374  }
375 
376  double cmtobridge = wirestobridge * wire_dist;
377  //---------------------------------------------------------------------
378  return ((std::abs(v2[0] - v1[0]) - cmtobridge) *
379  (std::abs(v2[0] - v1[0]) - cmtobridge)); //for ellipse
380 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:97
double cluster::DBScanAlg::getSimilarity2 ( const std::vector< double >  v1,
const std::vector< double >  v2 
)
Todo:
this code assumes all planes have the same wire pitch

Definition at line 383 of file DBScanAlg.cxx.

References util::abs(), and e.

385 {
386 
387  //-------------------------------------------
388  //return std::abs( v2[1]-v1[1]);//for rectangle
389  //------------------------------------------
390 
392  double wire_dist = fWirePitch[0];
393 
394  unsigned int wire1 =
395  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
396  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
397  int wirestobridge = 0;
398 
399  if (wire1 > wire2) {
400  unsigned int wire = wire1;
401  wire1 = wire2;
402  wire2 = wire;
403  }
404 
405  for (unsigned int i = wire1; i < wire2; i++) {
406  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
407  }
408 
409  double cmtobridge = wirestobridge * wire_dist;
410 
411  if (std::abs(v2[0] - v1[0]) > 1e-10) {
412  cmtobridge *= std::abs((v2[1] - v1[1]) / (v2[0] - v1[0]));
413  }
414  else
415  cmtobridge = 0;
416 
417  return ((std::abs(v2[1] - v1[1]) - cmtobridge) *
418  (std::abs(v2[1] - v1[1]) - cmtobridge)); //for ellipse
419 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:97
Float_t e
Definition: plot.C:35
double cluster::DBScanAlg::getWidthFactor ( const std::vector< double >  v1,
const std::vector< double >  v2 
)

Definition at line 422 of file DBScanAlg.cxx.

424 {
425 
426  //double k=0.13; //this number was determined by looking at flat muon hits' widths.
427  //The average width of these hits in cm is 0.505, so 4*2*(w1^2)=2.04
428  //where w1=w2=0.505, e^2.044= 7.69. In order not to change the distance
429  //in time direction of the ellipse we want to make it equal to 1 for
430  //these hits. Thus the k factor is k=1/7.69=0.13//for coeff=4
431 
432  //..................................................
433  double k = 0.1; //for 4.5 coeff
434  double WFactor = (exp(4.6 * ((v1[2] * v1[2]) + (v2[2] * v2[2])))) * k;
435  //........................................................
436  // Let's try something different:
437  if (WFactor > 1) {
438  if (WFactor < 6.25)
439  return WFactor; //remember that we are increasing the distance in
440  //eps2 as std::sqrt of this number (i.e std::sqrt(6.25))
441  else
442  return 6.25;
443  }
444  else
445  return 1.0;
446 }
void cluster::DBScanAlg::InitScan ( const detinfo::DetectorClocksData clockData,
const detinfo::DetectorPropertiesData detProp,
const std::vector< art::Ptr< recob::Hit >> &  allhits,
std::set< uint32_t >  badChannels,
const std::vector< geo::WireID > &  wireids = std::vector<geo::WireID>() 
)

get 2 first wires and find their spacing (wire_dist)

Definition at line 255 of file DBScanAlg.cxx.

References dbsPoint::bounds(), Visitor::count, detinfo::DetectorPropertiesData::DriftVelocity(), detinfo::DetectorPropertiesData::Efield(), geo::GeometryCore::Iterate(), cluster::kNO_CLUSTER, geo::GeometryCore::Nchannels(), detinfo::sampling_rate(), and detinfo::DetectorPropertiesData::Temperature().

Referenced by cluster::DBcluster::produce().

260 {
261  if (wireids.size() && wireids.size() != allhits.size()) {
262  throw cet::exception("DBScanAlg") << "allhits size = " << allhits.size()
263  << " wireids size = " << wireids.size() << " do not match\n";
264  }
265  // clear all the data member vectors for the new set of hits
266  fps.clear();
267  fpointId_to_clusterId.clear();
268  fnoise.clear();
269  fvisited.clear();
270  fsim.clear();
271  fsim2.clear();
272  fsim3.clear();
273  fclusters.clear();
274  fWirePitch.clear();
275 
276  fBadChannels = badChannels;
277  fBadWireSum.clear();
278 
279  // Clear the RTree
280  fRTree.Remove(RTree::AcceptAny(), RTree::RemoveLeaf());
281  // and the bounds list
282  fRect.clear();
283 
284  //------------------------------------------------------------------
285  // Determine spacing between wires (different for each detector)
287 
289  constexpr geo::TPCID tpcid{0, 0};
290  for (auto const& plane : geom->Iterate<geo::PlaneGeo>(tpcid))
291  fWirePitch.push_back(plane.WirePitch());
292 
293  // Collect the bad wire list into a useful form
294  if (fClusterMethod) { // Using the R*-tree
295  fBadWireSum.resize(geom->Nchannels());
296  unsigned int count = 0;
297  for (unsigned int i = 0; i < fBadWireSum.size(); ++i) {
298  count += fBadChannels.count(i);
299  fBadWireSum[i] = count;
300  }
301  }
302 
303  // Collect the hits in a useful form,
304  // and take note of the maximum time width
305  fMaxWidth = 0.0;
306  for (unsigned int j = 0; j < allhits.size(); ++j) {
307  int dims = 3; //our point is defined by 3 elements:wire#,center of the hit, and the hit width
308  std::vector<double> p(dims);
309 
310  double tickToDist = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
311  tickToDist *= 1.e-3 * sampling_rate(clockData); // 1e-3 is conversion of 1/us to 1/ns
312  if (!wireids.size())
313  p[0] = (allhits[j]->WireID().Wire) * fWirePitch[allhits[j]->WireID().Plane];
314  else
315  p[0] = (wireids[j].Wire) * fWirePitch[allhits[j]->WireID().Plane];
316  p[1] = allhits[j]->PeakTime() * tickToDist;
317  p[2] = 2. * allhits[j]->RMS() * tickToDist; //width of a hit in cm
318 
319  // check on the maximum width condition
320  if (p[2] > fMaxWidth) fMaxWidth = p[2];
321 
322  fps.push_back(p);
323 
324  if (fClusterMethod) { // Using the R*-tree
325  // Convert these same values into dbsPoints to feed into the R*-tree
326  dbsPoint pp(p[0], p[1], 0.0, p[2] / 2.0); // note dividing by two
327  fRTree.Insert(j, pp.bounds());
328  // Keep a parallel list already made up. We could use fps instead, but...
329  fRect.push_back(pp);
330  }
331  }
332 
333  fpointId_to_clusterId.resize(fps.size(), kNO_CLUSTER); // Not zero as before!
334  fnoise.resize(fps.size(), false);
335  fvisited.resize(fps.size(), false);
336 
337  if (fClusterMethod) { // Using the R*-tree
338  Visitor visitor = fRTree.Query(RTree::AcceptAny(), Visitor());
339  mf::LogInfo("DBscan") << "InitScan: hits RTree loaded with " << visitor.count << " items.";
340  }
341  mf::LogInfo("DBscan") << "InitScan: hits vector size is " << fps.size();
342 
343  return;
344 }
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
Definition: GeometryCore.h:541
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:238
unsigned int count
Definition: DBScanAlg.cxx:53
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:98
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
double Temperature() const
In kelvin.
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
double Efield(unsigned int planegap=0) const
kV/cm
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:75
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:79
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:73
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:90
std::vector< bool > fvisited
Definition: DBScanAlg.h:95
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:78
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:70
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:97
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:74
std::vector< bool > fnoise
Definition: DBScanAlg.h:94
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::set< unsigned int > cluster::DBScanAlg::RegionQuery ( unsigned int  point)
private

Definition at line 570 of file DBScanAlg.cxx.

References dbsPoint::bounds(), and Visitor::sResult.

571 {
572  dbsPoint region(fRect[point]);
573  Visitor visitor = fRTree.Query(AcceptFindNeighbors(region.bounds(),
574  fEps,
575  fEps2,
576  fMaxWidth,
577  fWirePitch[0], //\todo
578  fBadWireSum), // assumes
579  Visitor()); // equal
580  // pitch
581  return visitor.sResult;
582 }
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:98
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:79
std::set< unsigned int > sResult
Definition: DBScanAlg.cxx:55
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
std::vector< unsigned int > cluster::DBScanAlg::RegionQuery_vector ( unsigned int  point)
private

Definition at line 585 of file DBScanAlg.cxx.

References dbsPoint::bounds(), and Visitor::vResult.

586 {
587  dbsPoint region(fRect[point]);
588  Visitor visitor = fRTree.Query(AcceptFindNeighbors(region.bounds(),
589  fEps,
590  fEps2,
591  fMaxWidth,
592  fWirePitch[0], //\todo
593  fBadWireSum), // assumes
594  Visitor()); // equal
595  // pitch
596  std::vector<unsigned int>& v = visitor.vResult;
597  // find neighbors insures that the called point is not in the
598  // returned and this is intended as a drop-in replacement, so insure
599  // this condition
600  v.erase(std::remove(v.begin(), v.end(), point), v.end());
601  return v;
602 }
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:98
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:79
std::vector< unsigned int > vResult
Definition: DBScanAlg.cxx:54
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
void cluster::DBScanAlg::run_cluster ( )

Definition at line 509 of file DBScanAlg.cxx.

Referenced by cluster::DBcluster::produce().

510 {
511  switch (fClusterMethod) {
512  case 2: return run_dbscan_cluster();
513  case 1: return run_FN_cluster();
514  default:
515  computeSimilarity(); // watch out for this, they are *slow*
516  computeSimilarity2(); // "
517  computeWidthFactor(); // "
518  return run_FN_naive_cluster();
519  }
520 }
void computeSimilarity()
Definition: DBScanAlg.cxx:469
void computeWidthFactor()
Definition: DBScanAlg.cxx:493
void run_dbscan_cluster()
Definition: DBScanAlg.cxx:527
void run_FN_naive_cluster()
Definition: DBScanAlg.cxx:727
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:90
void computeSimilarity2()
Definition: DBScanAlg.cxx:481
void cluster::DBScanAlg::run_dbscan_cluster ( )
private

Definition at line 527 of file DBScanAlg.cxx.

References cluster::kNO_CLUSTER, cluster::kNOISE_CLUSTER, noise(), and dbsPoint::y.

528 {
529  unsigned int cid = 0;
530  // foreach pid
531  for (size_t pid = 0; pid < fps.size(); pid++) {
532  // not already visited
534  if (ExpandCluster(pid, cid)) { cid++; }
535  } // if (!visited
536  } // for
537  // END DBSCAN
538 
539  // Construct clusters, count noise, etc..
540  int noise = 0;
541  fclusters.resize(cid);
542  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
544  // This shouldn't happen...all points should be clasified by now!
545  mf::LogWarning("DBscan") << "Unclassified point!";
546  }
547  else if (fpointId_to_clusterId[y] == kNOISE_CLUSTER) {
548  ++noise;
549  }
550  else {
551  unsigned int c = fpointId_to_clusterId[y];
552  if (c >= cid) {
553  mf::LogWarning("DBscan") << "Point in cluster " << c << " when only " << cid
554  << " clusters wer found [0-" << cid - 1 << "]";
555  }
556  fclusters[c].push_back(y);
557  }
558  }
559  mf::LogInfo("DBscan") << "DWM (R*-tree): Found " << cid << " clusters...";
560  for (unsigned int c = 0; c < cid; ++c) {
561  mf::LogVerbatim("DBscan") << "\t"
562  << "Cluster " << c << ":\t" << fclusters[c].size();
563  }
564  mf::LogVerbatim("DBscan") << "\t"
565  << "...and " << noise << " noise points.";
566 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:238
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t y
Definition: compare.C:6
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
unsigned int noise()
Definition: chem4.cc:261
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:239
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
bool ExpandCluster(unsigned int point, unsigned int clusterID)
Definition: DBScanAlg.cxx:606
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:70
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void cluster::DBScanAlg::run_FN_cluster ( )
private

Definition at line 650 of file DBScanAlg.cxx.

References cluster::kNO_CLUSTER, noise(), and dbsPoint::y.

651 {
652 
653  unsigned int cid = 0;
654  // foreach pid
655  for (size_t pid = 0; pid < fps.size(); pid++) {
656  // not already visited
657  if (!fvisited[pid]) {
658 
659  fvisited[pid] = true;
660  // get the neighbors
661  std::vector<unsigned int> ne = RegionQuery_vector(pid);
662 
663  // not enough support -> mark as noise
664  if (ne.size() < fMinPts) { fnoise[pid] = true; }
665  else {
666  // Add p to current cluster
667 
668  std::vector<unsigned int> c; // a new cluster
669 
670  c.push_back(pid); // assign pid to cluster
671  fpointId_to_clusterId[pid] = cid;
672  // go to neighbors
673  for (size_t i = 0; i < ne.size(); ++i) {
674  unsigned int nPid = ne[i];
675 
676  // not already visited
677  if (!fvisited[nPid]) {
678  fvisited[nPid] = true;
679  // go to neighbors
680  std::vector<unsigned int> ne1 = RegionQuery_vector(nPid);
681  // enough support
682  if (ne1.size() >= fMinPts) {
683 
684  // join
685 
686  for (size_t i = 0; i < ne1.size(); ++i) {
687  // join neighbord
688  ne.push_back(ne1[i]);
689  }
690  }
691  }
692 
693  // not already assigned to a cluster
694  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
695  c.push_back(nPid);
696  fpointId_to_clusterId[nPid] = cid;
697  }
698  }
699 
700  fclusters.push_back(c);
701 
702  cid++;
703  }
704  } // if (!visited
705  } // for
706 
707  int noise = 0;
708  // no_hits=fnoise.size();
709 
710  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
711  if (fpointId_to_clusterId[y] == kNO_CLUSTER) noise++;
712  }
713  mf::LogInfo("DBscan") << "FindNeighbors (R*-tree): Found " << cid << " clusters...";
714  for (unsigned int c = 0; c < cid; ++c) {
715  mf::LogVerbatim("DBscan") << "\t"
716  << "Cluster " << c << ":\t" << fclusters[c].size();
717  }
718  mf::LogVerbatim("DBscan") << "\t"
719  << "...and " << noise << " noise points.";
720 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:238
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t y
Definition: compare.C:6
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
unsigned int noise()
Definition: chem4.cc:261
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
std::vector< bool > fvisited
Definition: DBScanAlg.h:95
std::vector< unsigned int > RegionQuery_vector(unsigned int point)
Definition: DBScanAlg.cxx:585
unsigned int fMinPts
Definition: DBScanAlg.h:88
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:70
std::vector< bool > fnoise
Definition: DBScanAlg.h:94
void cluster::DBScanAlg::run_FN_naive_cluster ( )
private

Definition at line 727 of file DBScanAlg.cxx.

References cluster::kNO_CLUSTER, noise(), and dbsPoint::y.

728 {
729 
730  unsigned int cid = 0;
731  // foreach pid
732  for (size_t pid = 0; pid < fps.size(); ++pid) {
733  // not already visited
734  if (!fvisited[pid]) {
735 
736  fvisited[pid] = true;
737  // get the neighbors
738  std::vector<unsigned int> ne = findNeighbors(pid, fEps, fEps2);
739 
740  // not enough support -> mark as noise
741  if (ne.size() < fMinPts) { fnoise[pid] = true; }
742  else {
743  // Add p to current cluster
744 
745  std::vector<unsigned int> c; // a new cluster
746 
747  c.push_back(pid); // assign pid to cluster
748  fpointId_to_clusterId[pid] = cid;
749  // go to neighbors
750  for (size_t i = 0; i < ne.size(); ++i) {
751  unsigned int nPid = ne[i];
752 
753  // not already visited
754  if (!fvisited[nPid]) {
755  fvisited[nPid] = true;
756  // go to neighbors
757  std::vector<unsigned int> ne1 = findNeighbors(nPid, fEps, fEps2);
758  // enough support
759  if (ne1.size() >= fMinPts) {
760 
761  // join
762 
763  for (unsigned int i = 0; i < ne1.size(); i++) {
764  // join neighbord
765  ne.push_back(ne1[i]);
766  }
767  }
768  }
769 
770  // not already assigned to a cluster
771  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
772  c.push_back(nPid);
773  fpointId_to_clusterId[nPid] = cid;
774  }
775  }
776 
777  fclusters.push_back(c);
778 
779  cid++;
780  }
781  } // if (!visited
782  } // for
783 
784  int noise = 0;
785 
786  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
788  }
789  mf::LogInfo("DBscan") << "FindNeighbors (naive): Found " << cid << " clusters...";
790  for (unsigned int c = 0; c < cid; ++c) {
791  mf::LogVerbatim("DBscan") << "\t"
792  << "Cluster " << c << ":\t" << fclusters[c].size() << " points";
793  }
794  mf::LogVerbatim("DBscan") << "\t"
795  << "...and " << noise << " noise points.";
796 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:238
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t y
Definition: compare.C:6
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
unsigned int noise()
Definition: chem4.cc:261
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
std::vector< bool > fvisited
Definition: DBScanAlg.h:95
std::vector< unsigned int > findNeighbors(unsigned int pid, double threshold, double threshold2)
Definition: DBScanAlg.cxx:451
unsigned int fMinPts
Definition: DBScanAlg.h:88
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:70
std::vector< bool > fnoise
Definition: DBScanAlg.h:94

Member Data Documentation

std::set<uint32_t> cluster::DBScanAlg::fBadChannels
private

set of bad channels in this detector

Definition at line 97 of file DBScanAlg.h.

std::vector<uint32_t> cluster::DBScanAlg::fBadWireSum
private

running total of bad channels. Used for fast intervening dead wire counting ala fBadChannelSum[m]-fBadChannelSum[n].

Definition at line 98 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fClusterMethod
private

Which clustering method to use.

Definition at line 90 of file DBScanAlg.h.

std::vector<std::vector<unsigned int> > cluster::DBScanAlg::fclusters

collection of something

Definition at line 70 of file DBScanAlg.h.

Referenced by cluster::DBcluster::produce().

unsigned int cluster::DBScanAlg::fDistanceMetric
private

Which distance metric to use.

Definition at line 91 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps
private

Definition at line 85 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps2
private

Definition at line 86 of file DBScanAlg.h.

double cluster::DBScanAlg::fMaxWidth

Definition at line 76 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fMinPts
private

Definition at line 88 of file DBScanAlg.h.

std::vector<bool> cluster::DBScanAlg::fnoise
private

Definition at line 94 of file DBScanAlg.h.

std::vector<unsigned int> cluster::DBScanAlg::fpointId_to_clusterId

mapping point_id -> clusterId

Definition at line 72 of file DBScanAlg.h.

Referenced by cluster::DBcluster::produce().

std::vector<std::vector<double> > cluster::DBScanAlg::fps

the collection of points we are working on

Definition at line 71 of file DBScanAlg.h.

Referenced by cluster::DBcluster::produce().

std::vector<dbsPoint> cluster::DBScanAlg::fRect

Definition at line 79 of file DBScanAlg.h.

RTree cluster::DBScanAlg::fRTree

Definition at line 78 of file DBScanAlg.h.

std::vector<std::vector<double> > cluster::DBScanAlg::fsim

Definition at line 73 of file DBScanAlg.h.

std::vector<std::vector<double> > cluster::DBScanAlg::fsim2

Definition at line 74 of file DBScanAlg.h.

std::vector<std::vector<double> > cluster::DBScanAlg::fsim3

Definition at line 75 of file DBScanAlg.h.

std::vector<bool> cluster::DBScanAlg::fvisited
private

Definition at line 95 of file DBScanAlg.h.

std::vector<double> cluster::DBScanAlg::fWirePitch
private

the pitch of the wires in each plane

Definition at line 96 of file DBScanAlg.h.


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