All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
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 52 of file DBScanAlg.h.

Constructor & Destructor Documentation

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

Definition at line 261 of file DBScanAlg.cxx.

262 {
263  fEps = p.get<double>("eps");
264  fEps2 = p.get<double>("epstwo");
265  fMinPts = p.get<int>("minPts");
266  fClusterMethod = p.get<int>("Method");
267  fDistanceMetric = p.get<int>("Metric");
268 }
pdgs p
Definition: selectors.fcl:22
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:91
unsigned int fMinPts
Definition: DBScanAlg.h:89
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:92

Member Function Documentation

void cluster::DBScanAlg::computeSimilarity ( )

Definition at line 487 of file DBScanAlg.cxx.

488 {
489  int size = fps.size();
490  fsim.resize(size, std::vector<double>(size));
491  for (int i = 0; i < size; i++) {
492  for (int j = i + 1; j < size; j++) {
493  fsim[j][i] = fsim[i][j] = getSimilarity(fps[i], fps[j]);
494  }
495  }
496 }
double getSimilarity(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:365
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:74
void cluster::DBScanAlg::computeSimilarity2 ( )

Definition at line 500 of file DBScanAlg.cxx.

501 {
502  int size = fps.size();
503  fsim2.resize(size, std::vector<double>(size));
504  for (int i = 0; i < size; i++) {
505  for (int j = i + 1; j < size; j++) {
506  fsim2[j][i] = fsim2[i][j] = getSimilarity2(fps[i], fps[j]);
507  }
508  }
509 }
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
double getSimilarity2(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:402
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:75
void cluster::DBScanAlg::computeWidthFactor ( )

Definition at line 513 of file DBScanAlg.cxx.

514 {
515  int size = fps.size();
516  fsim3.resize(size, std::vector<double>(size));
517 
518  for (int i = 0; i < size; i++) {
519  for (int j = i + 1; j < size; j++) {
520  fsim3[j][i] = fsim3[i][j] = getWidthFactor(fps[i], fps[j]);
521  }
522  }
523 }
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:76
double getWidthFactor(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:441
bool cluster::DBScanAlg::ExpandCluster ( unsigned int  point,
unsigned int  clusterID 
)
private

Definition at line 631 of file DBScanAlg.cxx.

632 {
633  /* GetSetOfPoints for point*/
634  std::set<unsigned int> seeds = RegionQuery(point);
635 
636  // not enough support -> mark as noise
637  if (seeds.size() < fMinPts) {
639  return false;
640  }
641  else {
642  // Add to the currecnt cluster
643  fpointId_to_clusterId[point] = clusterID;
644  for (std::set<unsigned int>::iterator itr = seeds.begin(); itr != seeds.end(); itr++) {
645  fpointId_to_clusterId[*itr] = clusterID;
646  }
647  seeds.erase(point);
648  while (!seeds.empty()) {
649  unsigned int currentP = *(seeds.begin());
650  std::set<unsigned int> result = RegionQuery(currentP);
651 
652  if (result.size() >= fMinPts) {
653  for (std::set<unsigned int>::iterator itr = result.begin(); itr != result.end(); itr++) {
654  unsigned int resultP = *itr;
655  // not already assigned to a cluster
656  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER ||
658  if (fpointId_to_clusterId[resultP] == kNO_CLUSTER) { seeds.insert(resultP); }
659  fpointId_to_clusterId[resultP] = clusterID;
660  } // unclassified or noise
661  } // for
662  } // enough support
663  seeds.erase(currentP);
664  } // while
665  return true;
666  }
667 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:254
std::set< unsigned int > RegionQuery(unsigned int point)
Definition: DBScanAlg.cxx:593
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:255
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
unsigned int fMinPts
Definition: DBScanAlg.h:89
std::vector< unsigned int > cluster::DBScanAlg::findNeighbors ( unsigned int  pid,
double  threshold,
double  threshold2 
)

Definition at line 470 of file DBScanAlg.cxx.

471 {
472  std::vector<unsigned int> ne;
473 
474  for (int unsigned j = 0; j < fsim.size(); j++) {
475  if ((pid != j) &&
476  (((fsim[pid][j]) / (threshold * threshold)) +
477  ((fsim2[pid][j]) / (threshold2 * threshold2 * (fsim3[pid][j])))) < 1) { //ellipse
478  ne.push_back(j);
479  }
480  } // end loop over fsim
481 
482  return ne;
483 }
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:76
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:74
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:75
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 365 of file DBScanAlg.cxx.

366 {
367 
368  //for Euclidean distance comment everything out except this-->>>
369  // return std::sqrt((v2[1]-v1[1])*(v2[1]-v1[1])+(v2[0]-v1[0])*(v2[0]-v1[0]));
370  //------------------------------------------------------------------------
371  // return std::abs( v2[0]-v1[0]); //for rectangle
372  //----------------------------------------------------------------------
373  //Manhattan distance:
374  //return std::abs(v1[0]-v2[0])+std::abs(v1[1]-v2[1]);
375 
376  /// \todo this code assumes that all planes have the same wire pitch
377  double wire_dist = fWirePitch[0];
378 
379  unsigned int wire1 =
380  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
381  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
382  int wirestobridge = 0;
383 
384  if (wire1 > wire2) {
385  unsigned int wire = wire1;
386  wire1 = wire2;
387  wire2 = wire;
388  }
389 
390  for (unsigned int i = wire1; i < wire2; i++) {
391  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
392  }
393 
394  double cmtobridge = wirestobridge * wire_dist;
395  //---------------------------------------------------------------------
396  return ((std::abs(v2[0] - v1[0]) - cmtobridge) *
397  (std::abs(v2[0] - v1[0]) - cmtobridge)); //for ellipse
398 }
T abs(T value)
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:98
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 402 of file DBScanAlg.cxx.

403 {
404 
405  //-------------------------------------------
406  //return std::abs( v2[1]-v1[1]);//for rectangle
407  //------------------------------------------
408 
409  /// \todo this code assumes all planes have the same wire pitch
410  double wire_dist = fWirePitch[0];
411 
412  unsigned int wire1 =
413  (unsigned int)(v1[0] / wire_dist + 0.5); //to make sure to get desired integer
414  unsigned int wire2 = (unsigned int)(v2[0] / wire_dist + 0.5);
415  int wirestobridge = 0;
416 
417  if (wire1 > wire2) {
418  unsigned int wire = wire1;
419  wire1 = wire2;
420  wire2 = wire;
421  }
422 
423  for (unsigned int i = wire1; i < wire2; i++) {
424  if (fBadChannels.find(i) != fBadChannels.end()) wirestobridge++;
425  }
426 
427  double cmtobridge = wirestobridge * wire_dist;
428 
429  if (std::abs(v2[0] - v1[0]) > 1e-10) {
430  cmtobridge *= std::abs((v2[1] - v1[1]) / (v2[0] - v1[0]));
431  }
432  else
433  cmtobridge = 0;
434 
435  return ((std::abs(v2[1] - v1[1]) - cmtobridge) *
436  (std::abs(v2[1] - v1[1]) - cmtobridge)); //for ellipse
437 }
T abs(T value)
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
do i e
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:98
double cluster::DBScanAlg::getWidthFactor ( const std::vector< double >  v1,
const std::vector< double >  v2 
)

Definition at line 441 of file DBScanAlg.cxx.

442 {
443 
444  //double k=0.13; //this number was determined by looking at flat muon hits' widths.
445  //The average width of these hits in cm is 0.505, so 4*2*(w1^2)=2.04
446  //where w1=w2=0.505, e^2.044= 7.69. In order not to change the distance
447  //in time direction of the ellipse we want to make it equal to 1 for
448  //these hits. Thus the k factor is k=1/7.69=0.13//for coeff=4
449 
450  //..................................................
451  double k = 0.1; //for 4.5 coeff
452  double WFactor = (exp(4.6 * ((v1[2] * v1[2]) + (v2[2] * v2[2])))) * k;
453  //........................................................
454  // Let's try something different:
455  if (WFactor > 1) {
456  if (WFactor < 6.25)
457  return WFactor; //remember that we are increasing the distance in
458  //eps2 as std::sqrt of this number (i.e std::sqrt(6.25))
459  else
460  return 6.25;
461  }
462  else
463  return 1.0;
464 }
pdgs k
Definition: selectors.fcl:22
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 272 of file DBScanAlg.cxx.

277 {
278  if (wireids.size() && wireids.size() != allhits.size()) {
279  throw cet::exception("DBScanAlg") << "allhits size = " << allhits.size()
280  << " wireids size = " << wireids.size() << " do not match\n";
281  }
282  // clear all the data member vectors for the new set of hits
283  fps.clear();
284  fpointId_to_clusterId.clear();
285  fnoise.clear();
286  fvisited.clear();
287  fsim.clear();
288  fsim2.clear();
289  fsim3.clear();
290  fclusters.clear();
291  fWirePitch.clear();
292 
293  fBadChannels = badChannels;
294  fBadWireSum.clear();
295 
296  // Clear the RTree
297  fRTree.Remove(RTree::AcceptAny(), RTree::RemoveLeaf());
298  // and the bounds list
299  fRect.clear();
300 
301  //------------------------------------------------------------------
302  // Determine spacing between wires (different for each detector)
303  ///get 2 first wires and find their spacing (wire_dist)
304 
305  art::ServiceHandle<geo::Geometry const> geom;
306 
307  for (size_t p = 0; p < geom->Nplanes(); ++p)
308  fWirePitch.push_back(geom->WirePitch(p));
309 
310  // Collect the bad wire list into a useful form
311  if (fClusterMethod) { // Using the R*-tree
312  fBadWireSum.resize(geom->Nchannels());
313  unsigned int count = 0;
314  for (unsigned int i = 0; i < fBadWireSum.size(); ++i) {
315  count += fBadChannels.count(i);
316  fBadWireSum[i] = count;
317  }
318  }
319 
320  // Collect the hits in a useful form,
321  // and take note of the maximum time width
322  fMaxWidth = 0.0;
323  for (unsigned int j = 0; j < allhits.size(); ++j) {
324  int dims = 3; //our point is defined by 3 elements:wire#,center of the hit, and the hit width
325  std::vector<double> p(dims);
326 
327  double tickToDist = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
328  tickToDist *= 1.e-3 * sampling_rate(clockData); // 1e-3 is conversion of 1/us to 1/ns
329  if (!wireids.size())
330  p[0] = (allhits[j]->WireID().Wire) * fWirePitch[allhits[j]->WireID().Plane];
331  else
332  p[0] = (wireids[j].Wire) * fWirePitch[allhits[j]->WireID().Plane];
333  p[1] = allhits[j]->PeakTime() * tickToDist;
334  p[2] = 2. * allhits[j]->RMS() * tickToDist; //width of a hit in cm
335 
336  // check on the maximum width condition
337  if (p[2] > fMaxWidth) fMaxWidth = p[2];
338 
339  fps.push_back(p);
340 
341  if (fClusterMethod) { // Using the R*-tree
342  // Convert these same values into dbsPoints to feed into the R*-tree
343  dbsPoint pp(p[0], p[1], 0.0, p[2] / 2.0); // note dividing by two
344  fRTree.Insert(j, pp.bounds());
345  // Keep a parallel list already made up. We could use fps instead, but...
346  fRect.push_back(pp);
347  }
348  }
349 
350  fpointId_to_clusterId.resize(fps.size(), kNO_CLUSTER); // Not zero as before!
351  fnoise.resize(fps.size(), false);
352  fvisited.resize(fps.size(), false);
353 
354  if (fClusterMethod) { // Using the R*-tree
355  Visitor visitor = fRTree.Query(RTree::AcceptAny(), Visitor());
356  mf::LogInfo("DBscan") << "InitScan: hits RTree loaded with " << visitor.count << " items.";
357  }
358  mf::LogInfo("DBscan") << "InitScan: hits vector size is " << fps.size();
359 
360  return;
361 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:254
unsigned int count
Definition: DBScanAlg.cxx:54
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:99
pdgs p
Definition: selectors.fcl:22
double Temperature() const
In kelvin.
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
double Efield(unsigned int planegap=0) const
kV/cm
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:76
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:80
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:74
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:91
std::vector< bool > fvisited
Definition: DBScanAlg.h:96
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:71
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:98
std::size_t count(Cont const &cont)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:75
std::vector< bool > fnoise
Definition: DBScanAlg.h:95
std::set< unsigned int > cluster::DBScanAlg::RegionQuery ( unsigned int  point)
private

Definition at line 593 of file DBScanAlg.cxx.

594 {
595  dbsPoint region(fRect[point]);
596  Visitor visitor = fRTree.Query(AcceptFindNeighbors(region.bounds(),
597  fEps,
598  fEps2,
599  fMaxWidth,
600  fWirePitch[0], //\todo
601  fBadWireSum), // assumes
602  Visitor()); // equal
603  // pitch
604  return visitor.sResult;
605 }
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:99
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:80
std::set< unsigned int > sResult
Definition: DBScanAlg.cxx:56
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
std::vector< unsigned int > cluster::DBScanAlg::RegionQuery_vector ( unsigned int  point)
private

Definition at line 609 of file DBScanAlg.cxx.

610 {
611  dbsPoint region(fRect[point]);
612  Visitor visitor = fRTree.Query(AcceptFindNeighbors(region.bounds(),
613  fEps,
614  fEps2,
615  fMaxWidth,
616  fWirePitch[0], //\todo
617  fBadWireSum), // assumes
618  Visitor()); // equal
619  // pitch
620  std::vector<unsigned int>& v = visitor.vResult;
621  // find neighbors insures that the called point is not in the
622  // returned and this is intended as a drop-in replacement, so insure
623  // this condition
624  v.erase(std::remove(v.begin(), v.end(), point), v.end());
625  return v;
626 }
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:99
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:80
std::vector< unsigned int > vResult
Definition: DBScanAlg.cxx:55
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
void cluster::DBScanAlg::run_cluster ( )

Definition at line 530 of file DBScanAlg.cxx.

531 {
532  switch (fClusterMethod) {
533  case 2: return run_dbscan_cluster();
534  case 1: return run_FN_cluster();
535  default:
536  computeSimilarity(); // watch out for this, they are *slow*
537  computeSimilarity2(); // "
538  computeWidthFactor(); // "
539  return run_FN_naive_cluster();
540  }
541 }
void computeSimilarity()
Definition: DBScanAlg.cxx:487
void computeWidthFactor()
Definition: DBScanAlg.cxx:513
void run_dbscan_cluster()
Definition: DBScanAlg.cxx:549
void run_FN_naive_cluster()
Definition: DBScanAlg.cxx:754
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:91
void computeSimilarity2()
Definition: DBScanAlg.cxx:500
void cluster::DBScanAlg::run_dbscan_cluster ( )
private

Definition at line 549 of file DBScanAlg.cxx.

550 {
551  unsigned int cid = 0;
552  // foreach pid
553  for (size_t pid = 0; pid < fps.size(); pid++) {
554  // not already visited
555  if (fpointId_to_clusterId[pid] == kNO_CLUSTER) {
556  if (ExpandCluster(pid, cid)) { cid++; }
557  } // if (!visited
558  } // for
559  // END DBSCAN
560 
561  // Construct clusters, count noise, etc..
562  int noise = 0;
563  fclusters.resize(cid);
564  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
566  // This shouldn't happen...all points should be clasified by now!
567  mf::LogWarning("DBscan") << "Unclassified point!";
568  }
569  else if (fpointId_to_clusterId[y] == kNOISE_CLUSTER) {
570  ++noise;
571  }
572  else {
573  unsigned int c = fpointId_to_clusterId[y];
574  if (c >= cid) {
575  mf::LogWarning("DBscan") << "Point in cluster " << c << " when only " << cid
576  << " clusters wer found [0-" << cid - 1 << "]";
577  }
578  fclusters[c].push_back(y);
579  }
580  }
581  mf::LogInfo("DBscan") << "DWM (R*-tree): Found " << cid << " clusters...";
582  for (unsigned int c = 0; c < cid; ++c) {
583  mf::LogVerbatim("DBscan") << "\t"
584  << "Cluster " << c << ":\t" << fclusters[c].size();
585  }
586  mf::LogVerbatim("DBscan") << "\t"
587  << "...and " << noise << " noise points.";
588 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:254
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:255
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
process_name opflash particleana ie ie y
bool ExpandCluster(unsigned int point, unsigned int clusterID)
Definition: DBScanAlg.cxx:631
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:71
void cluster::DBScanAlg::run_FN_cluster ( )
private

Definition at line 676 of file DBScanAlg.cxx.

677 {
678 
679  unsigned int cid = 0;
680  // foreach pid
681  for (size_t pid = 0; pid < fps.size(); pid++) {
682  // not already visited
683  if (!fvisited[pid]) {
684 
685  fvisited[pid] = true;
686  // get the neighbors
687  std::vector<unsigned int> ne = RegionQuery_vector(pid);
688 
689  // not enough support -> mark as noise
690  if (ne.size() < fMinPts) { fnoise[pid] = true; }
691  else {
692  // Add p to current cluster
693 
694  std::vector<unsigned int> c; // a new cluster
695 
696  c.push_back(pid); // assign pid to cluster
697  fpointId_to_clusterId[pid] = cid;
698  // go to neighbors
699  for (size_t i = 0; i < ne.size(); ++i) {
700  unsigned int nPid = ne[i];
701 
702  // not already visited
703  if (!fvisited[nPid]) {
704  fvisited[nPid] = true;
705  // go to neighbors
706  std::vector<unsigned int> ne1 = RegionQuery_vector(nPid);
707  // enough support
708  if (ne1.size() >= fMinPts) {
709 
710  // join
711 
712  for (size_t i = 0; i < ne1.size(); ++i) {
713  // join neighbord
714  ne.push_back(ne1[i]);
715  }
716  }
717  }
718 
719  // not already assigned to a cluster
720  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
721  c.push_back(nPid);
722  fpointId_to_clusterId[nPid] = cid;
723  }
724  }
725 
726  fclusters.push_back(c);
727 
728  cid++;
729  }
730  } // if (!visited
731  } // for
732 
733  int noise = 0;
734  // no_hits=fnoise.size();
735 
736  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
737  if (fpointId_to_clusterId[y] == kNO_CLUSTER) noise++;
738  }
739  mf::LogInfo("DBscan") << "FindNeighbors (R*-tree): Found " << cid << " clusters...";
740  for (unsigned int c = 0; c < cid; ++c) {
741  mf::LogVerbatim("DBscan") << "\t"
742  << "Cluster " << c << ":\t" << fclusters[c].size();
743  }
744  mf::LogVerbatim("DBscan") << "\t"
745  << "...and " << noise << " noise points.";
746 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:254
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
process_name opflash particleana ie ie y
std::vector< bool > fvisited
Definition: DBScanAlg.h:96
std::vector< unsigned int > RegionQuery_vector(unsigned int point)
Definition: DBScanAlg.cxx:609
unsigned int fMinPts
Definition: DBScanAlg.h:89
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:71
std::vector< bool > fnoise
Definition: DBScanAlg.h:95
void cluster::DBScanAlg::run_FN_naive_cluster ( )
private

Definition at line 754 of file DBScanAlg.cxx.

755 {
756 
757  unsigned int cid = 0;
758  // foreach pid
759  for (size_t pid = 0; pid < fps.size(); ++pid) {
760  // not already visited
761  if (!fvisited[pid]) {
762 
763  fvisited[pid] = true;
764  // get the neighbors
765  std::vector<unsigned int> ne = findNeighbors(pid, fEps, fEps2);
766 
767  // not enough support -> mark as noise
768  if (ne.size() < fMinPts) { fnoise[pid] = true; }
769  else {
770  // Add p to current cluster
771 
772  std::vector<unsigned int> c; // a new cluster
773 
774  c.push_back(pid); // assign pid to cluster
775  fpointId_to_clusterId[pid] = cid;
776  // go to neighbors
777  for (size_t i = 0; i < ne.size(); ++i) {
778  unsigned int nPid = ne[i];
779 
780  // not already visited
781  if (!fvisited[nPid]) {
782  fvisited[nPid] = true;
783  // go to neighbors
784  std::vector<unsigned int> ne1 = findNeighbors(nPid, fEps, fEps2);
785  // enough support
786  if (ne1.size() >= fMinPts) {
787 
788  // join
789 
790  for (unsigned int i = 0; i < ne1.size(); i++) {
791  // join neighbord
792  ne.push_back(ne1[i]);
793  }
794  }
795  }
796 
797  // not already assigned to a cluster
798  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER) {
799  c.push_back(nPid);
800  fpointId_to_clusterId[nPid] = cid;
801  }
802  }
803 
804  fclusters.push_back(c);
805 
806  cid++;
807  }
808  } // if (!visited
809  } // for
810 
811  int noise = 0;
812 
813  for (size_t y = 0; y < fpointId_to_clusterId.size(); ++y) {
814  if (fpointId_to_clusterId[y] == kNO_CLUSTER) ++noise;
815  }
816  mf::LogInfo("DBscan") << "FindNeighbors (naive): Found " << cid << " clusters...";
817  for (unsigned int c = 0; c < cid; ++c) {
818  mf::LogVerbatim("DBscan") << "\t"
819  << "Cluster " << c << ":\t" << fclusters[c].size() << " points";
820  }
821  mf::LogVerbatim("DBscan") << "\t"
822  << "...and " << noise << " noise points.";
823 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:254
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
process_name opflash particleana ie ie y
std::vector< bool > fvisited
Definition: DBScanAlg.h:96
std::vector< unsigned int > findNeighbors(unsigned int pid, double threshold, double threshold2)
Definition: DBScanAlg.cxx:470
unsigned int fMinPts
Definition: DBScanAlg.h:89
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:71
std::vector< bool > fnoise
Definition: DBScanAlg.h:95

Member Data Documentation

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

set of bad channels in this detector

Definition at line 98 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 99 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fClusterMethod
private

Which clustering method to use.

Definition at line 91 of file DBScanAlg.h.

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

collection of something

Definition at line 71 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fDistanceMetric
private

Which distance metric to use.

Definition at line 92 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps
private

Definition at line 86 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps2
private

Definition at line 87 of file DBScanAlg.h.

double cluster::DBScanAlg::fMaxWidth

Definition at line 77 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fMinPts
private

Definition at line 89 of file DBScanAlg.h.

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

Definition at line 95 of file DBScanAlg.h.

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

mapping point_id -> clusterId

Definition at line 73 of file DBScanAlg.h.

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

the collection of points we are working on

Definition at line 72 of file DBScanAlg.h.

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

Definition at line 80 of file DBScanAlg.h.

RTree cluster::DBScanAlg::fRTree

Definition at line 79 of file DBScanAlg.h.

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

Definition at line 74 of file DBScanAlg.h.

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

Definition at line 75 of file DBScanAlg.h.

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

Definition at line 76 of file DBScanAlg.h.

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

Definition at line 96 of file DBScanAlg.h.

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

the pitch of the wires in each plane

Definition at line 97 of file DBScanAlg.h.


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