LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
cluster::DBScanAlg Class Reference

#include "DBScanAlg.h"

Public Member Functions

 DBScanAlg (fhicl::ParameterSet const &pset)
 
virtual ~DBScanAlg ()
 
void reconfigure (fhicl::ParameterSet const &p)
 
void InitScan (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 34 of file DBScanAlg.h.

Constructor & Destructor Documentation

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

Definition at line 260 of file DBScanAlg.cxx.

261 {
262  this->reconfigure(pset);
263 }
void reconfigure(fhicl::ParameterSet const &p)
Definition: DBScanAlg.cxx:271
cluster::DBScanAlg::~DBScanAlg ( )
virtual

Definition at line 266 of file DBScanAlg.cxx.

267 {
268 }

Member Function Documentation

void cluster::DBScanAlg::computeSimilarity ( )

Definition at line 489 of file DBScanAlg.cxx.

490 {
491  int size = fps.size();
492  fsim.resize(size, std::vector<double>(size));
493  for ( int i=0; i < size; i++){
494  for ( int j=i+1; j < size; j++){
495  fsim[j] [i] = fsim[i][ j] = getSimilarity(fps[i], fps[j]);
496  }
497  }
498 }
double getSimilarity(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:372
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:61
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:63
void cluster::DBScanAlg::computeSimilarity2 ( )

Definition at line 501 of file DBScanAlg.cxx.

502 {
503  int size = fps.size();
504  fsim2.resize(size, std::vector<double>(size));
505  for ( int i=0; i < size; i++){
506  for ( int j=i+1; j < size; j++){
507  fsim2[j] [i] = fsim2[i][ j] = getSimilarity2(fps[i], fps[j]);
508  }
509  }
510 }
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:61
double getSimilarity2(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:407
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:64
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::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:61
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:65
double getWidthFactor(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:444
bool cluster::DBScanAlg::ExpandCluster ( unsigned int  point,
unsigned int  clusterID 
)
private

Definition at line 632 of file DBScanAlg.cxx.

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

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

Definition at line 472 of file DBScanAlg.cxx.

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

372  {
373 
374 
375  //for Euclidean distance comment everything out except this-->>>
376  // return std::sqrt((v2[1]-v1[1])*(v2[1]-v1[1])+(v2[0]-v1[0])*(v2[0]-v1[0]));
377  //------------------------------------------------------------------------
378  // return std::abs( v2[0]-v1[0]); //for rectangle
379  //----------------------------------------------------------------------
380  //Manhattan distance:
381  //return std::abs(v1[0]-v2[0])+std::abs(v1[1]-v2[1]);
382 
384  double wire_dist = fWirePitch[0];
385 
386  unsigned int wire1=(unsigned int)(v1[0]/wire_dist+0.5); //to make sure to get desired integer
387  unsigned int wire2=(unsigned int)(v2[0]/wire_dist+0.5);
388  int wirestobridge=0;
389 
390  if (wire1>wire2) {
391  unsigned int wire = wire1;
392  wire1 = wire2;
393  wire2 = wire;
394  }
395 
396  for(unsigned int i=wire1;i<wire2;i++){
397  if(fBadChannels.find(i) != fBadChannels.end())
398  wirestobridge++;
399  }
400 
401  double cmtobridge=wirestobridge*wire_dist;
402  //---------------------------------------------------------------------
403  return (( std::abs(v2[0]-v1[0])-cmtobridge)*( std::abs(v2[0]-v1[0])-cmtobridge)); //for ellipse
404 }
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:87
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:88
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 407 of file DBScanAlg.cxx.

References e.

407  {
408 
409  //-------------------------------------------
410  //return std::abs( v2[1]-v1[1]);//for rectangle
411  //------------------------------------------
412 
414  double wire_dist = fWirePitch[0];
415 
416  unsigned int wire1=(unsigned int)(v1[0]/wire_dist+0.5); //to make sure to get desired integer
417  unsigned int wire2=(unsigned int)(v2[0]/wire_dist+0.5);
418  int wirestobridge=0;
419 
420  if (wire1>wire2) {
421  unsigned int wire = wire1;
422  wire1 = wire2;
423  wire2 = wire;
424  }
425 
426  for(unsigned int i=wire1;i<wire2;i++){
427  if(fBadChannels.find(i) != fBadChannels.end())
428  wirestobridge++;
429  }
430 
431  double cmtobridge=wirestobridge*wire_dist;
432 
433  if (std::abs(v2[0]-v1[0])>1e-10){
434  cmtobridge *= std::abs((v2[1]-v1[1])/(v2[0]-v1[0]));
435  }
436  else cmtobridge = 0;
437 
438  return (( std::abs(v2[1]-v1[1])-cmtobridge)*( std::abs(v2[1]-v1[1])-cmtobridge));//for ellipse
439 
440 
441 }
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:87
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:88
Float_t e
Definition: plot.C:34
double cluster::DBScanAlg::getWidthFactor ( const std::vector< double >  v1,
const std::vector< double >  v2 
)

Definition at line 444 of file DBScanAlg.cxx.

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

References dbsPoint::bounds(), Visitor::count, detinfo::DetectorProperties::DriftVelocity(), detinfo::DetectorProperties::Efield(), cluster::kNO_CLUSTER, detinfo::DetectorProperties::SamplingRate(), and detinfo::DetectorProperties::Temperature().

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

284 {
285  if (wireids.size()&&wireids.size()!=allhits.size()){
286  throw cet::exception("DBScanAlg") << "allhits size = "<<allhits.size()<<" wireids size = "<<wireids.size()<<" do not match\n";
287  }
288  // clear all the data member vectors for the new set of hits
289  fps.clear();
290  fpointId_to_clusterId.clear();
291  fnoise.clear();
292  fvisited.clear();
293  fsim.clear();
294  fsim2.clear();
295  fsim3.clear();
296  fclusters.clear();
297  fWirePitch.clear();
298 
299  fBadChannels = badChannels;
300  fBadWireSum.clear();
301 
302  // Clear the RTree
304  // and the bounds list
305  fRect.clear();
306 
307  //------------------------------------------------------------------
308  // Determine spacing between wires (different for each detector)
310 
311  const detinfo::DetectorProperties* detp = lar::providerFrom<detinfo::DetectorPropertiesService>();
313 
314  for(size_t p = 0; p < geom->Nplanes(); ++p)
315  fWirePitch.push_back(geom->WirePitch(p));
316 
317 
318  // Collect the bad wire list into a useful form
319  if (fClusterMethod) { // Using the R*-tree
320  fBadWireSum.resize(geom->Nchannels());
321  unsigned int count=0;
322  for (unsigned int i=0; i<fBadWireSum.size(); ++i) {
323  count += fBadChannels.count(i);
324  fBadWireSum[i] = count;
325  }
326  }
327 
328  // Collect the hits in a useful form,
329  // and take note of the maximum time width
330  fMaxWidth=0.0;
331  for (unsigned int j = 0; j < allhits.size(); ++j){
332  int dims = 3;//our point is defined by 3 elements:wire#,center of the hit, and the hit width
333  std::vector<double> p(dims);
334 
335  double tickToDist = detp->DriftVelocity(detp->Efield(),detp->Temperature());
336  tickToDist *= 1.e-3 * detp->SamplingRate(); // 1e-3 is conversion of 1/us to 1/ns
337  if (!wireids.size()) p[0] = (allhits[j]->WireID().Wire)*fWirePitch[allhits[j]->WireID().Plane];
338  else p[0] = (wireids[j].Wire)*fWirePitch[allhits[j]->WireID().Plane];
339  p[1] = allhits[j]->PeakTime()*tickToDist;
340  p[2] = 2.*allhits[j]->RMS()*tickToDist; //width of a hit in cm
341 
342  // check on the maximum width condition
343  if ( p[2] > fMaxWidth ) fMaxWidth = p[2];
344 
345  fps.push_back(p);
346 
347  if (fClusterMethod) { // Using the R*-tree
348  // Convert these same values into dbsPoints to feed into the R*-tree
349  dbsPoint pp(p[0], p[1], 0.0, p[2]/2.0); // note dividing by two
350  fRTree.Insert(j, pp.bounds());
351  // Keep a parallel list already made up. We could use fps instead, but...
352  fRect.push_back(pp);
353  }
354  }
355 
356  fpointId_to_clusterId.resize(fps.size(), kNO_CLUSTER); // Not zero as before!
357  fnoise.resize(fps.size(), false);
358  fvisited.resize(fps.size(), false);
359 
360  if (fClusterMethod) { // Using the R*-tree
361  Visitor visitor =
363  mf::LogInfo("DBscan") << "InitScan: hits RTree loaded with "
364  << visitor.count << " items.";
365  }
366  mf::LogInfo("DBscan") << "InitScan: hits vector size is " << fps.size();
367 
368  return;
369 }
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:253
void Remove(const Acceptor &accept, LeafRemover leafRemover)
Removes item(s) from the tree.
Definition: RStarTree.h:245
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:89
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual double SamplingRate() const =0
Returns the period of the TPC readout electronics clock.
void Insert(LeafType leaf, const BoundingBox &bound)
Definition: RStarTree.h:123
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:61
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:65
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:62
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:63
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:81
virtual double Temperature() const =0
std::vector< bool > fvisited
Definition: DBScanAlg.h:86
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:69
Definition: main.cpp:51
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:87
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:60
virtual double DriftVelocity(double efield=0., double temperature=0.) const =0
int count
Definition: main.cpp:52
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:88
virtual double Efield(unsigned int planegap=0) const =0
Returns the nominal electric field in the specified volume.
Visitor Query(const Acceptor &accept, Visitor visitor)
Touches each node using the visitor pattern.
Definition: RStarTree.h:215
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:64
std::vector< bool > fnoise
Definition: DBScanAlg.h:85
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void cluster::DBScanAlg::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 271 of file DBScanAlg.cxx.

References fhicl::ParameterSet::get().

Referenced by cluster::fuzzyClusterAlg::reconfigure(), and cluster::DBcluster::reconfigure().

272 {
273  fEps = p.get< double >("eps" );
274  fEps2 = p.get< double >("epstwo");
275  fMinPts = p.get< int >("minPts");
276  fClusterMethod = p.get< int >("Method");
277  fDistanceMetric = p.get< int >("Metric");
278 }
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:81
unsigned int fMinPts
Definition: DBScanAlg.h:79
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:82
std::set< unsigned int > cluster::DBScanAlg::RegionQuery ( unsigned int  point)
private

Definition at line 595 of file DBScanAlg.cxx.

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

595  {
596  dbsPoint region(fRect[point]);
597  Visitor visitor =
598 // fRTree.Query(RTree::AcceptOverlapping(region.bounds()),Visitor());
599 // fRTree.Query(AcceptEllipse(region.bounds(),fEps,fEps2),Visitor());
600  fRTree.Query(AcceptFindNeighbors(region.bounds(),
601  fEps,fEps2,
602  fMaxWidth,fWirePitch[0],//\todo
603  fBadWireSum), //assumes
604  Visitor()); //equal
605  //pitch
606  return visitor.sResult;
607 }
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:89
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:69
Definition: main.cpp:51
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:87
Visitor Query(const Acceptor &accept, Visitor visitor)
Touches each node using the visitor pattern.
Definition: RStarTree.h:215
std::set< unsigned int > sResult
Definition: DBScanAlg.cxx:70
std::vector< unsigned int > cluster::DBScanAlg::RegionQuery_vector ( unsigned int  point)
private

Definition at line 610 of file DBScanAlg.cxx.

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

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

Definition at line 530 of file DBScanAlg.cxx.

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

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

Definition at line 549 of file DBScanAlg.cxx.

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

549  {
550  unsigned int cid = 0;
551  // foreach pid
552  for (size_t pid = 0; pid < fps.size(); pid++){
553  // not already visited
555  if ( ExpandCluster(pid,cid) ) {
556  cid++;
557  }
558  } // if (!visited
559  } // for
560  // END DBSCAN
561 
562  // Construct clusters, count noise, etc..
563  int noise = 0;
564  fclusters.resize(cid);
565  for(size_t y = 0; y < fpointId_to_clusterId.size(); ++y){
567  // This shouldn't happen...all points should be clasified by now!
568  mf::LogWarning("DBscan") << "Unclassified point!";
569  }
571  ++noise;
572  }
573  else {
574  unsigned int c = fpointId_to_clusterId[y];
575  if (c >= cid) {
576  mf::LogWarning("DBscan") << "Point in cluster " << c
577  << " when only " << cid
578  << " clusters wer found [0-" << cid-1
579  << "]";
580  }
581  fclusters[c].push_back(y);
582  }
583  }
584  mf::LogInfo("DBscan") << "DWM (R*-tree): Found "
585  << cid << " clusters...";
586  for (unsigned int c = 0; c < cid; ++c){
587  mf::LogVerbatim("DBscan") << "\t" << "Cluster " << c << ":\t"
588  << fclusters[c].size();
589  }
590  mf::LogVerbatim("DBscan") << "\t" << "...and " << noise << " noise points.";
591 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:253
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:61
unsigned int noise()
Definition: chem4.cc:265
const unsigned int kNOISE_CLUSTER
Definition: DBScanAlg.cxx:254
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:62
bool ExpandCluster(unsigned int point, unsigned int clusterID)
Definition: DBScanAlg.cxx:632
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:60
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void cluster::DBScanAlg::run_FN_cluster ( )
private

Definition at line 681 of file DBScanAlg.cxx.

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

682 {
683 
684  unsigned int cid = 0;
685  // foreach pid
686  for (size_t pid = 0; pid < fps.size(); pid++){
687  // not already visited
688  if (!fvisited[pid]){
689 
690  fvisited[pid] = true;
691  // get the neighbors
692  //std::vector<unsigned int> ne = findNeighbors(pid, fEps,fEps2);
693  std::vector<unsigned int> ne = RegionQuery_vector(pid);
694 
695  // not enough support -> mark as noise
696  if (ne.size() < fMinPts){
697  fnoise[pid] = true;
698  }
699  else{
700  // Add p to current cluster
701 
702  std::vector<unsigned int> c; // a new cluster
703 
704  c.push_back(pid); // assign pid to cluster
705  fpointId_to_clusterId[pid]=cid;
706  // go to neighbors
707  for (size_t i = 0; i < ne.size(); ++i){
708  unsigned int nPid = ne[i];
709 
710  // not already visited
711  if (!fvisited[nPid]){
712  fvisited[nPid] = true;
713  // go to neighbors
714  //std::vector<unsigned int> ne1 = findNeighbors(nPid, fEps, fEps2);
715  std::vector<unsigned int> ne1 = RegionQuery_vector(nPid);
716  // enough support
717  if (ne1.size() >= fMinPts){
718 
719  // join
720 
721  for(size_t i = 0; i < ne1.size(); ++i){
722  // join neighbord
723  ne.push_back(ne1[i]);
724  }
725  }
726  }
727 
728  // not already assigned to a cluster
729  //if (!fpointId_to_clusterId[nPid]){
730  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER ){
731  c.push_back(nPid);
732  fpointId_to_clusterId[nPid]=cid;
733  }
734  }
735 
736  fclusters.push_back(c);
737 
738 
739  cid++;
740  }
741  } // if (!visited
742  } // for
743 
744 
745  int noise=0;
746  //no_hits=fnoise.size();
747 
748  for(size_t y = 0;y < fpointId_to_clusterId.size(); ++y){
749  //if (fpointId_to_clusterId[y]==0) noise++;
750  if (fpointId_to_clusterId[y]==kNO_CLUSTER) noise++;
751  }
752  mf::LogInfo("DBscan") << "FindNeighbors (R*-tree): Found "
753  << cid << " clusters...";
754  for (unsigned int c = 0; c < cid; ++c){
755  mf::LogVerbatim("DBscan") << "\t" << "Cluster " << c << ":\t"
756  << fclusters[c].size();
757  }
758  mf::LogVerbatim("DBscan") << "\t" << "...and " << noise << " noise points.";
759 
760 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:253
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:61
unsigned int noise()
Definition: chem4.cc:265
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:62
std::vector< bool > fvisited
Definition: DBScanAlg.h:86
std::vector< unsigned int > RegionQuery_vector(unsigned int point)
Definition: DBScanAlg.cxx:610
unsigned int fMinPts
Definition: DBScanAlg.h:79
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:60
std::vector< bool > fnoise
Definition: DBScanAlg.h:85
void cluster::DBScanAlg::run_FN_naive_cluster ( )
private

Definition at line 767 of file DBScanAlg.cxx.

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

768 {
769 
770  unsigned int cid = 0;
771  // foreach pid
772  for (size_t pid = 0; pid < fps.size(); ++pid){
773  // not already visited
774  if (!fvisited[pid]){
775 
776  fvisited[pid] = true;
777  // get the neighbors
778  std::vector<unsigned int> ne = findNeighbors(pid, fEps,fEps2);
779 
780  // not enough support -> mark as noise
781  if (ne.size() < fMinPts){
782  fnoise[pid] = true;
783  }
784  else{
785  // Add p to current cluster
786 
787  std::vector<unsigned int> c; // a new cluster
788 
789  c.push_back(pid); // assign pid to cluster
790  fpointId_to_clusterId[pid] = cid;
791  // go to neighbors
792  for (size_t i = 0; i < ne.size(); ++i){
793  unsigned int nPid = ne[i];
794 
795  // not already visited
796  if (!fvisited[nPid]){
797  fvisited[nPid] = true;
798  // go to neighbors
799  std::vector<unsigned int> ne1 = findNeighbors(nPid, fEps, fEps2);
800  // enough support
801  if (ne1.size() >= fMinPts){
802 
803  // join
804 
805  for(unsigned int i=0;i<ne1.size();i++){
806  // join neighbord
807  ne.push_back(ne1[i]);
808  }
809  }
810  }
811 
812  // not already assigned to a cluster
813  //if (!fpointId_to_clusterId[nPid]){
814  if (fpointId_to_clusterId[nPid] == kNO_CLUSTER){
815  c.push_back(nPid);
816  fpointId_to_clusterId[nPid]=cid;
817  }
818  }
819 
820  fclusters.push_back(c);
821 
822 
823  cid++;
824  }
825  } // if (!visited
826  } // for
827 
828 
829  int noise = 0;
830  //no_hits=fnoise.size();
831 
832  for(size_t y = 0; y < fpointId_to_clusterId.size(); ++y){
833  //if (fpointId_to_clusterId[y]==0) noise++;
835  }
836  mf::LogInfo("DBscan") << "FindNeighbors (naive): Found " << cid
837  << " clusters...";
838  for (unsigned int c = 0; c < cid; ++c){
839  mf::LogVerbatim("DBscan") << "\t" << "Cluster " << c << ":\t"
840  << fclusters[c].size() << " points";
841  }
842  mf::LogVerbatim("DBscan") << "\t" << "...and " << noise << " noise points.";
843 
844 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const unsigned int kNO_CLUSTER
Definition: DBScanAlg.cxx:253
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:61
unsigned int noise()
Definition: chem4.cc:265
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:62
std::vector< bool > fvisited
Definition: DBScanAlg.h:86
std::vector< unsigned int > findNeighbors(unsigned int pid, double threshold, double threshold2)
Definition: DBScanAlg.cxx:472
unsigned int fMinPts
Definition: DBScanAlg.h:79
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:60
std::vector< bool > fnoise
Definition: DBScanAlg.h:85

Member Data Documentation

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

set of bad channels in this detector

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

unsigned int cluster::DBScanAlg::fClusterMethod
private

Which clustering method to use.

Definition at line 81 of file DBScanAlg.h.

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

collection of something

Definition at line 60 of file DBScanAlg.h.

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

unsigned int cluster::DBScanAlg::fDistanceMetric
private

Which distance metric to use.

Definition at line 82 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps
private

Definition at line 76 of file DBScanAlg.h.

double cluster::DBScanAlg::fEps2
private

Definition at line 77 of file DBScanAlg.h.

double cluster::DBScanAlg::fMaxWidth

Definition at line 66 of file DBScanAlg.h.

unsigned int cluster::DBScanAlg::fMinPts
private

Definition at line 79 of file DBScanAlg.h.

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

Definition at line 85 of file DBScanAlg.h.

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

mapping point_id -> clusterId

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

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

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

Definition at line 69 of file DBScanAlg.h.

RTree cluster::DBScanAlg::fRTree

Definition at line 68 of file DBScanAlg.h.

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

Definition at line 63 of file DBScanAlg.h.

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

Definition at line 64 of file DBScanAlg.h.

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

Definition at line 65 of file DBScanAlg.h.

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

Definition at line 86 of file DBScanAlg.h.

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

the pitch of the wires in each plane

Definition at line 87 of file DBScanAlg.h.


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