All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBScanAlg.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////
2 // \fileDBScanAlg.h
3 // kinga.partyka@yale.edu
4 ////////////////////////////////////////////////////////////////////
5 #ifndef DBSCANALG_H
6 #define DBSCANALG_H
7 
8 #include <set>
9 #include <stdint.h>
10 #include <vector>
11 
12 #include "canvas/Persistency/Common/Ptr.h"
14 #include "RStarTree/RStarTree.h"
15 namespace detinfo {
16  class DetectorClocksData;
17  class DetectorPropertiesData;
18 }
19 
20 namespace fhicl {
21  class ParameterSet;
22 }
23 
24 namespace recob {
25  class Hit;
26 }
27 
28 // RStarTree related infrastructure
29 //
30 // Our core objects have a physical extent (i.e. there are not
31 // points), but a R*-tree should be able to deal with that.
32 using RTree = RStarTree<uint32_t, 2, 32, 64>; // payload is just an index
34 
35 struct dbsPoint {
36  double x, y;
37  double dx, dy;
38  dbsPoint(double X = 0.0, double Y = 0.0, double dX = 0.0, double dY = 0.0)
39  : x(X), y(Y), dx(dX), dy(dY){};
40  BoundingBox bounds() const;
41  void
42  Expand(double DX, double DY)
43  {
44  dx += DX;
45  dy += DY;
46  };
47 };
48 
49 namespace cluster {
50 
51  //---------------------------------------------------------------
52  class DBScanAlg {
53  public:
54  explicit DBScanAlg(fhicl::ParameterSet const& pset);
55 
56  void InitScan(
57  const detinfo::DetectorClocksData& clockData,
59  const std::vector<art::Ptr<recob::Hit>>& allhits,
60  std::set<uint32_t> badChannels,
61  const std::vector<geo::WireID>& wireids = std::vector<geo::WireID>()); //wireids is optional
62  double getSimilarity(const std::vector<double> v1, const std::vector<double> v2);
63  std::vector<unsigned int> findNeighbors(unsigned int pid, double threshold, double threshold2);
64  void computeSimilarity();
65  void run_cluster();
66  double getSimilarity2(const std::vector<double> v1, const std::vector<double> v2);
67  void computeSimilarity2();
68  double getWidthFactor(const std::vector<double> v1, const std::vector<double> v2);
69  void computeWidthFactor();
70 
71  std::vector<std::vector<unsigned int>> fclusters; ///< collection of something
72  std::vector<std::vector<double>> fps; ///< the collection of points we are working on
73  std::vector<unsigned int> fpointId_to_clusterId; ///< mapping point_id -> clusterId
74  std::vector<std::vector<double>> fsim; ///<
75  std::vector<std::vector<double>> fsim2; ///<
76  std::vector<std::vector<double>> fsim3; ///<
77  double fMaxWidth;
78 
80  std::vector<dbsPoint> fRect;
81 
82  private:
83  // eps radius
84  // Two points are neighbors if the distance
85  // between them does not exceed threshold value.
86  double fEps;
87  double fEps2;
88  //minimum number of points
89  unsigned int fMinPts;
90  // Which clustering to run
91  unsigned int fClusterMethod; ///< Which clustering method to use
92  unsigned int fDistanceMetric; ///< Which distance metric to use
93 
94  // noise vector
95  std::vector<bool> fnoise;
96  std::vector<bool> fvisited;
97  std::vector<double> fWirePitch; ///< the pitch of the wires in each plane
98  std::set<uint32_t> fBadChannels; ///< set of bad channels in this detector
99  std::vector<uint32_t> fBadWireSum; ///< running total of bad channels. Used for fast intervening
100  ///< dead wire counting ala
101  ///< fBadChannelSum[m]-fBadChannelSum[n].
102 
103  // Three differnt version of the clustering code
104  void run_dbscan_cluster();
105  void run_FN_cluster();
106  void run_FN_naive_cluster();
107 
108  // Helper routined for run_dbscan_cluster() names and
109  // responsibilities taken directly from the paper
110  bool ExpandCluster(unsigned int point /* to be added */,
111  unsigned int clusterID /* which is being expanded */);
112  std::set<unsigned int> RegionQuery(unsigned int point);
113  // Helper for the accelerated run_FN_cluster()
114  std::vector<unsigned int> RegionQuery_vector(unsigned int point);
115 
116  }; // class DBScanAlg
117 } // namespace
118 
119 #endif // ifndef DBSCANALG_H
RStarTree< uint32_t, 2, 32, 64 > RTree
Definition: DBScanAlg.h:32
double getSimilarity(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:365
dbsPoint(double X=0.0, double Y=0.0, double dX=0.0, double dY=0.0)
Definition: DBScanAlg.h:38
void computeSimilarity()
Definition: DBScanAlg.cxx:487
void computeWidthFactor()
Definition: DBScanAlg.cxx:513
process_name cluster
Definition: cheaterreco.fcl:51
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:99
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
void run_dbscan_cluster()
Definition: DBScanAlg.cxx:549
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
std::set< unsigned int > RegionQuery(unsigned int point)
Definition: DBScanAlg.cxx:593
void Expand(double DX, double DY)
Definition: DBScanAlg.h:42
double dy
Definition: DBScanAlg.h:37
void run_FN_naive_cluster()
Definition: DBScanAlg.cxx:754
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:76
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -&gt; clusterId
Definition: DBScanAlg.h:73
std::vector< dbsPoint > fRect
Definition: DBScanAlg.h:80
std::vector< std::vector< double > > fsim
Definition: DBScanAlg.h:74
double dx
Definition: DBScanAlg.h:37
unsigned int fClusterMethod
Which clustering method to use.
Definition: DBScanAlg.h:91
RTree::BoundingBox BoundingBox
Definition: DBScanAlg.h:33
BoundingBox bounds() const
Definition: DBScanAlg.cxx:37
std::vector< bool > fvisited
Definition: DBScanAlg.h:96
DBScanAlg(fhicl::ParameterSet const &pset)
Definition: DBScanAlg.cxx:261
Definition of data types for geometry description.
double getWidthFactor(const std::vector< double > v1, const std::vector< double > v2)
Definition: DBScanAlg.cxx:441
void computeSimilarity2()
Definition: DBScanAlg.cxx:500
std::vector< unsigned int > findNeighbors(unsigned int pid, double threshold, double threshold2)
Definition: DBScanAlg.cxx:470
std::vector< unsigned int > RegionQuery_vector(unsigned int point)
Definition: DBScanAlg.cxx:609
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 >())
Definition: DBScanAlg.cxx:272
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
bool ExpandCluster(unsigned int point, unsigned int clusterID)
Definition: DBScanAlg.cxx:631
unsigned int fMinPts
Definition: DBScanAlg.h:89
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:71
Contains all timing reference information for the detector.
double x
Definition: DBScanAlg.h:36
double y
Definition: DBScanAlg.h:36
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:98
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
auto const detProp
std::vector< bool > fnoise
Definition: DBScanAlg.h:95
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:92