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 
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,
58  const detinfo::DetectorPropertiesData& detProp,
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
dbsPoint(double X=0.0, double Y=0.0, double dX=0.0, double dY=0.0)
Definition: DBScanAlg.h:38
Reconstruction base classes.
std::vector< uint32_t > fBadWireSum
Definition: DBScanAlg.h:99
struct vector vector
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:72
Cluster finding and building.
void Expand(double DX, double DY)
Definition: DBScanAlg.h:42
double dy
Definition: DBScanAlg.h:37
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:76
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:73
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
BoundedItem::BoundingBox BoundingBox
Definition: RStarTree.h:92
General LArSoft Utilities.
Definition of data types for geometry description.
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:97
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.
list x
Definition: train.py:276
double y
Definition: DBScanAlg.h:36
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:98
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:75
std::vector< bool > fnoise
Definition: DBScanAlg.h:95
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:92