LArSoft  v10_04_05
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 246 of file DBScanAlg.cxx.

References fhicl::ParameterSet::get().

247 {
248  fEps = p.get<double>("eps");
249  fEps2 = p.get<double>("epstwo");
250  fMinPts = p.get<int>("minPts");
251  fClusterMethod = p.get<int>("Method");
252  fDistanceMetric = p.get<int>("Metric");
253 }
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 472 of file DBScanAlg.cxx.

References util::size().

473 {
474  int size = fps.size();
475  fsim.resize(size, std::vector<double>(size));
476  for (int i = 0; i < size; i++) {
477  for (int j = i + 1; j < size; j++) {
478  fsim[j][i] = fsim[i][j] = getSimilarity(fps[i], fps[j]);
479  }
480  }
481 }
double getSimilarity(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:350
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 484 of file DBScanAlg.cxx.

References util::size().

485 {
486  int size = fps.size();
487  fsim2.resize(size, std::vector<double>(size));
488  for (int i = 0; i < size; i++) {
489  for (int j = i + 1; j < size; j++) {
490  fsim2[j][i] = fsim2[i][j] = getSimilarity2(fps[i], fps[j]);
491  }
492  }
493 }
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:386
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:74
void cluster::DBScanAlg::computeWidthFactor ( )

Definition at line 496 of file DBScanAlg.cxx.

References util::size().

497 {
498  int size = fps.size();
499  fsim3.resize(size, std::vector<double>(size));
500 
501  for (int i = 0; i < size; i++) {
502  for (int j = i + 1; j < size; j++) {
503  fsim3[j][i] = fsim3[i][j] = getWidthFactor(fps[i], fps[j]);
504  }
505  }
506 }
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:425
bool cluster::DBScanAlg::ExpandCluster ( unsigned int  point,
unsigned int  clusterID 
)
private

Definition at line 609 of file DBScanAlg.cxx.

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

610 {
611  /* GetSetOfPoints for point*/
612  std::set<unsigned int> seeds = RegionQuery(point);
613 
614  // not enough support -> mark as noise
615  if (seeds.size() < fMinPts) {
617  return false;
618  }
619  else {
620  // Add to the currecnt cluster
621  fpointId_to_clusterId[point] = clusterID;
622  for (std::set<unsigned int>::iterator itr = seeds.begin(); itr != seeds.end(); itr++) {
623  fpointId_to_clusterId[*itr] = clusterID;
624  }
625  seeds.erase(point);
626  while (!seeds.empty()) {
627  unsigned int currentP = *(seeds.begin());
628  std::set<unsigned int> result = RegionQuery(currentP);
629 
630  if (result.size() >= fMinPts) {
631  for (std::set<unsigned int>::iterator itr = result.begin(); itr != result.end(); itr++) {
632  unsigned int resultP = *itr;
633  // not already assigned to a cluster
634  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER ||
636  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER) { seeds.insert(resultP); }
637  fpointId_to_clusterId[resultP] = clusterID;
638  } // unclassified or noise
639  } // for
640  } // enough support
641  seeds.erase(currentP);
642  } // while
643  return true;
644  }
645 }
intermediate_table::iterator iterator
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:239
std::set< unsigned int > RegionQuery(unsigned int point)
Definition: DBScanAlg.cxx:573
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:240
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 454 of file DBScanAlg.cxx.

457 {
458  std::vector<unsigned int> ne;
459 
460  for (int unsigned j = 0; j < fsim.size(); j++) {
461  if ((pid != j) &&
462  (((fsim[pid][j]) / (threshold * threshold)) +
463  ((fsim2[pid][j]) / (threshold2 * threshold2 * (fsim3[pid][j])))) < 1) { //ellipse
464  ne.push_back(j);
465  }
466  } // end loop over fsim
467 
468  return ne;
469 }
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 350 of file DBScanAlg.cxx.

References util::abs().

351 {
352 
353  //for Euclidean distance comment everything out except this-->>>
354  // return std::sqrt((v2[1]-v1[1])*(v2[1]-v1[1])+(v2[0]-v1[0])*(v2[0]-v1[0]));
355  //------------------------------------------------------------------------
356  // return std::abs( v2[0]-v1[0]); //for rectangle
357  //----------------------------------------------------------------------
358  //Manhattan distance:
359  //return std::abs(v1[0]-v2[0])+std::abs(v1[1]-v2[1]);
360 
362  double wire_dist = fWirePitch[0];
363 
364  unsigned int wire1 =
365  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
366  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
367  int wirestobridge = 0;
368 
369  if (wire1 > wire2) {
370  unsigned int wire = wire1;
371  wire1 = wire2;
372  wire2 = wire;
373  }
374 
375  for (unsigned int i = wire1; i < wire2; i++) {
376  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
377  }
378 
379  double cmtobridge = wirestobridge * wire_dist;
380  //---------------------------------------------------------------------
381  return ((std::abs(v2[0] - v1[0]) - cmtobridge) *
382  (std::abs(v2[0] - v1[0]) - cmtobridge)); //for ellipse
383 }
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 386 of file DBScanAlg.cxx.

References util::abs(), and e.

388 {
389 
390  //-------------------------------------------
391  //return std::abs( v2[1]-v1[1]);//for rectangle
392  //------------------------------------------
393 
395  double wire_dist = fWirePitch[0];
396 
397  unsigned int wire1 =
398  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
399  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
400  int wirestobridge = 0;
401 
402  if (wire1 > wire2) {
403  unsigned int wire = wire1;
404  wire1 = wire2;
405  wire2 = wire;
406  }
407 
408  for (unsigned int i = wire1; i < wire2; i++) {
409  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
410  }
411 
412  double cmtobridge = wirestobridge * wire_dist;
413 
414  if (std::abs(v2[0] - v1[0]) > 1e-10) {
415  cmtobridge *= std::abs((v2[1] - v1[1]) / (v2[0] - v1[0]));
416  }
417  else
418  cmtobridge = 0;
419 
420  return ((std::abs(v2[1] - v1[1]) - cmtobridge) *
421  (std::abs(v2[1] - v1[1]) - cmtobridge)); //for ellipse
422 }
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 425 of file DBScanAlg.cxx.

427 {
428 
429  //double k=0.13; //this number was determined by looking at flat muon hits' widths.
430  //The average width of these hits in cm is 0.505, so 4*2*(w1^2)=2.04
431  //where w1=w2=0.505, e^2.044= 7.69. In order not to change the distance
432  //in time direction of the ellipse we want to make it equal to 1 for
433  //these hits. Thus the k factor is k=1/7.69=0.13//for coeff=4
434 
435  //..................................................
436  double k = 0.1; //for 4.5 coeff
437  double WFactor = (exp(4.6 * ((v1[2] * v1[2]) + (v2[2] * v2[2])))) * k;
438  //........................................................
439  // Let's try something different:
440  if (WFactor > 1) {
441  if (WFactor < 6.25)
442  return WFactor; //remember that we are increasing the distance in
443  //eps2 as std::sqrt of this number (i.e std::sqrt(6.25))
444  else
445  return 6.25;
446  }
447  else
448  return 1.0;
449 }
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>() 
)

Definition at line 256 of file DBScanAlg.cxx.

References dbsPoint::bounds(), Visitor::count, detinfo::DetectorPropertiesData::DriftVelocity(), detinfo::DetectorPropertiesData::Efield(), Get, cluster::kNO_CLUSTER, detinfo::sampling_rate(), and detinfo::DetectorPropertiesData::Temperature().

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

261 {
262  if (wireids.size() && wireids.size() != allhits.size()) {
263  throw cet::exception("DBScanAlg") << "allhits size = " << allhits.size()
264  << " wireids size = " << wireids.size() << " do not match\n";
265  }
266  // clear all the data member vectors for the new set of hits
267  fps.clear();
268  fpointId_to_clusterId.clear();
269  fnoise.clear();
270  fvisited.clear();
271  fsim.clear();
272  fsim2.clear();
273  fsim3.clear();
274  fclusters.clear();
275  fWirePitch.clear();
276 
277  fBadChannels = badChannels;
278  fBadWireSum.clear();
279 
280  // Clear the RTree
281  fRTree.Remove(RTree::AcceptAny(), RTree::RemoveLeaf());
282  // and the bounds list
283  fRect.clear();
284 
285  //------------------------------------------------------------------
286  // Determine spacing between wires (different for each detector)
287  // get 2 first wires and find their spacing (wire_dist)
288 
289  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
291  constexpr geo::TPCID tpcid{0, 0};
292  for (auto const& plane : wireReadoutGeom.Iterate<geo::PlaneGeo>(tpcid))
293  fWirePitch.push_back(plane.WirePitch());
294 
295  // Collect the bad wire list into a useful form
296  if (fClusterMethod) { // Using the R*-tree
297  auto const nchannels = wireReadoutGeom.Nchannels();
298  fBadWireSum.resize(nchannels);
299  unsigned int count = 0;
300  for (unsigned int i = 0; i < fBadWireSum.size(); ++i) {
301  count += fBadChannels.count(i);
302  fBadWireSum[i] = count;
303  }
304  }
305 
306  // Collect the hits in a useful form,
307  // and take note of the maximum time width
308  fMaxWidth = 0.0;
309  for (unsigned int j = 0; j < allhits.size(); ++j) {
310  int dims = 3; //our point is defined by 3 elements:wire#,center of the hit, and the hit width
311  std::vector<double> p(dims);
312 
313  double tickToDist = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
314  tickToDist *= 1.e-3 * sampling_rate(clockData); // 1e-3 is conversion of 1/us to 1/ns
315  if (!wireids.size())
316  p[0] = (allhits[j]->WireID().Wire) * fWirePitch[allhits[j]->WireID().Plane];
317  else
318  p[0] = (wireids[j].Wire) * fWirePitch[allhits[j]->WireID().Plane];
319  p[1] = allhits[j]->PeakTime() * tickToDist;
320  p[2] = 2. * allhits[j]->RMS() * tickToDist; //width of a hit in cm
321 
322  // check on the maximum width condition
323  if (p[2] > fMaxWidth) fMaxWidth = p[2];
324 
325  fps.push_back(p);
326 
327  if (fClusterMethod) { // Using the R*-tree
328  // Convert these same values into dbsPoints to feed into the R*-tree
329  dbsPoint pp(p[0], p[1], 0.0, p[2] / 2.0); // note dividing by two
330  fRTree.Insert(j, pp.bounds());
331  // Keep a parallel list already made up. We could use fps instead, but...
332  fRect.push_back(pp);
333  }
334  }
335 
336  fpointId_to_clusterId.resize(fps.size(), kNO_CLUSTER); // Not zero as before!
337  fnoise.resize(fps.size(), false);
338  fvisited.resize(fps.size(), false);
339 
340  if (fClusterMethod) { // Using the R*-tree
341  Visitor visitor = fRTree.Query(RTree::AcceptAny(), Visitor());
342  mf::LogInfo("DBscan") << "InitScan: hits RTree loaded with " << visitor.count << " items.";
343  }
344  mf::LogInfo("DBscan") << "InitScan: hits vector size is " << fps.size();
345 
346  return;
347 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:239
unsigned int count
Definition: DBScanAlg.cxx:54
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:98
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
double Temperature() const
In kelvin.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
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:67
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
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 573 of file DBScanAlg.cxx.

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

574 {
575  dbsPoint region(fRect[point]);
576  Visitor visitor = fRTree.Query(AcceptFindNeighbors(region.bounds(),
577  fEps,
578  fEps2,
579  fMaxWidth,
580  fWirePitch[0], //\todo
581  fBadWireSum), // assumes
582  Visitor()); // equal
583  // pitch
584  return visitor.sResult;
585 }
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:56
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 588 of file DBScanAlg.cxx.

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

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

Definition at line 512 of file DBScanAlg.cxx.

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

513 {
514  switch (fClusterMethod) {
515  case 2: return run_dbscan_cluster();
516  case 1: return run_FN_cluster();
517  default:
518  computeSimilarity(); // watch out for this, they are *slow*
519  computeSimilarity2(); // "
520  computeWidthFactor(); // "
521  return run_FN_naive_cluster();
522  }
523 }
void computeSimilarity()
Definition: DBScanAlg.cxx:472
void computeWidthFactor()
Definition: DBScanAlg.cxx:496
void run_dbscan_cluster()
Definition: DBScanAlg.cxx:530
void run_FN_naive_cluster()
Definition: DBScanAlg.cxx:730
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:90
void computeSimilarity2()
Definition: DBScanAlg.cxx:484
void cluster::DBScanAlg::run_dbscan_cluster ( )
private

Definition at line 530 of file DBScanAlg.cxx.

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

531 {
532  unsigned int cid = 0;
533  // foreach pid
534  for (size_t pid = 0; pid < fps.size(); pid++) {
535  // not already visited
537  if (ExpandCluster(pid, cid)) { cid++; }
538  } // if (!visited
539  } // for
540  // END DBSCAN
541 
542  // Construct clusters, count noise, etc..
543  int noise = 0;
544  fclusters.resize(cid);
545  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
547  // This shouldn't happen...all points should be clasified by now!
548  mf::LogWarning("DBscan") << "Unclassified point!";
549  }
550  else if (fpointId_to_clusterId[y] == kNOISE_CLUSTER) {
551  ++noise;
552  }
553  else {
554  unsigned int c = fpointId_to_clusterId[y];
555  if (c >= cid) {
556  mf::LogWarning("DBscan") << "Point in cluster " << c << " when only " << cid
557  << " clusters wer found [0-" << cid - 1 << "]";
558  }
559  fclusters[c].push_back(y);
560  }
561  }
562  mf::LogInfo("DBscan") << "DWM (R*-tree): Found " << cid << " clusters...";
563  for (unsigned int c = 0; c < cid; ++c) {
564  mf::LogVerbatim("DBscan") << "\t"
565  << "Cluster " << c << ":\t" << fclusters[c].size();
566  }
567  mf::LogVerbatim("DBscan") << "\t"
568  << "...and " << noise << " noise points.";
569 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:239
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:240
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:609
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 653 of file DBScanAlg.cxx.

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

654 {
655 
656  unsigned int cid = 0;
657  // foreach pid
658  for (size_t pid = 0; pid < fps.size(); pid++) {
659  // not already visited
660  if (!fvisited[pid]) {
661 
662  fvisited[pid] = true;
663  // get the neighbors
664  std::vector<unsigned int> ne = RegionQuery_vector(pid);
665 
666  // not enough support -> mark as noise
667  if (ne.size() < fMinPts) { fnoise[pid] = true; }
668  else {
669  // Add p to current cluster
670 
671  std::vector<unsigned int> c; // a new cluster
672 
673  c.push_back(pid); // assign pid to cluster
674  fpointId_to_clusterId[pid] = cid;
675  // go to neighbors
676  for (size_t i = 0; i < ne.size(); ++i) {
677  unsigned int nPid = ne[i];
678 
679  // not already visited
680  if (!fvisited[nPid]) {
681  fvisited[nPid] = true;
682  // go to neighbors
683  std::vector<unsigned int> ne1 = RegionQuery_vector(nPid);
684  // enough support
685  if (ne1.size() >= fMinPts) {
686 
687  // join
688 
689  for (size_t i = 0; i < ne1.size(); ++i) {
690  // join neighbord
691  ne.push_back(ne1[i]);
692  }
693  }
694  }
695 
696  // not already assigned to a cluster
697  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
698  c.push_back(nPid);
699  fpointId_to_clusterId[nPid] = cid;
700  }
701  }
702 
703  fclusters.push_back(c);
704 
705  cid++;
706  }
707  } // if (!visited
708  } // for
709 
710  int noise = 0;
711  // no_hits=fnoise.size();
712 
713  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
714  if (fpointId_to_clusterId[y] == kNO_CLUSTER) noise++;
715  }
716  mf::LogInfo("DBscan") << "FindNeighbors (R*-tree): Found " << cid << " clusters...";
717  for (unsigned int c = 0; c < cid; ++c) {
718  mf::LogVerbatim("DBscan") << "\t"
719  << "Cluster " << c << ":\t" << fclusters[c].size();
720  }
721  mf::LogVerbatim("DBscan") << "\t"
722  << "...and " << noise << " noise points.";
723 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:239
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:588
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 730 of file DBScanAlg.cxx.

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

731 {
732 
733  unsigned int cid = 0;
734  // foreach pid
735  for (size_t pid = 0; pid < fps.size(); ++pid) {
736  // not already visited
737  if (!fvisited[pid]) {
738 
739  fvisited[pid] = true;
740  // get the neighbors
741  std::vector<unsigned int> ne = findNeighbors(pid, fEps, fEps2);
742 
743  // not enough support -> mark as noise
744  if (ne.size() < fMinPts) { fnoise[pid] = true; }
745  else {
746  // Add p to current cluster
747 
748  std::vector<unsigned int> c; // a new cluster
749 
750  c.push_back(pid); // assign pid to cluster
751  fpointId_to_clusterId[pid] = cid;
752  // go to neighbors
753  for (size_t i = 0; i < ne.size(); ++i) {
754  unsigned int nPid = ne[i];
755 
756  // not already visited
757  if (!fvisited[nPid]) {
758  fvisited[nPid] = true;
759  // go to neighbors
760  std::vector<unsigned int> ne1 = findNeighbors(nPid, fEps, fEps2);
761  // enough support
762  if (ne1.size() >= fMinPts) {
763 
764  // join
765 
766  for (unsigned int i = 0; i < ne1.size(); i++) {
767  // join neighbord
768  ne.push_back(ne1[i]);
769  }
770  }
771  }
772 
773  // not already assigned to a cluster
774  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
775  c.push_back(nPid);
776  fpointId_to_clusterId[nPid] = cid;
777  }
778  }
779 
780  fclusters.push_back(c);
781 
782  cid++;
783  }
784  } // if (!visited
785  } // for
786 
787  int noise = 0;
788 
789  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
791  }
792  mf::LogInfo("DBscan") << "FindNeighbors (naive): Found " << cid << " clusters...";
793  for (unsigned int c = 0; c < cid; ++c) {
794  mf::LogVerbatim("DBscan") << "\t"
795  << "Cluster " << c << ":\t" << fclusters[c].size() << " points";
796  }
797  mf::LogVerbatim("DBscan") << "\t"
798  << "...and " << noise << " noise points.";
799 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:239
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:454
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: