LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DBScanAlg.h
Go to the documentation of this file.
1 // \fileDBScanAlg.h
3 // kinga.partyka@yale.edu
5 #ifndef DBSCANALG_H
6 #define DBSCANALG_H
7 
8 #include <set>
9 #include <stdint.h>
10 #include <vector>
11 
12 #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 Expand(double DX, double DY)
42  {
43  dx += DX;
44  dy += DY;
45  };
46 };
47 
48 namespace cluster {
49 
50  //---------------------------------------------------------------
51  class DBScanAlg {
52  public:
53  explicit DBScanAlg(fhicl::ParameterSet const& pset);
54 
55  void InitScan(
56  const detinfo::DetectorClocksData& clockData,
57  const detinfo::DetectorPropertiesData& detProp,
58  const std::vector<art::Ptr<recob::Hit>>& allhits,
59  std::set<uint32_t> badChannels,
60  const std::vector<geo::WireID>& wireids = std::vector<geo::WireID>()); //wireids is optional
61  double getSimilarity(const std::vector<double> v1, const std::vector<double> v2);
62  std::vector<unsigned int> findNeighbors(unsigned int pid, double threshold, double threshold2);
63  void computeSimilarity();
64  void run_cluster();
65  double getSimilarity2(const std::vector<double> v1, const std::vector<double> v2);
66  void computeSimilarity2();
67  double getWidthFactor(const std::vector<double> v1, const std::vector<double> v2);
68  void computeWidthFactor();
69 
70  std::vector<std::vector<unsigned int>> fclusters;
71  std::vector<std::vector<double>> fps;
72  std::vector<unsigned int> fpointId_to_clusterId;
73  std::vector<std::vector<double>> fsim;
74  std::vector<std::vector<double>> fsim2;
75  std::vector<std::vector<double>> fsim3;
76  double fMaxWidth;
77 
79  std::vector<dbsPoint> fRect;
80 
81  private:
82  // eps radius
83  // Two points are neighbors if the distance
84  // between them does not exceed threshold value.
85  double fEps;
86  double fEps2;
87  //minimum number of points
88  unsigned int fMinPts;
89  // Which clustering to run
90  unsigned int fClusterMethod;
91  unsigned int fDistanceMetric;
92 
93  // noise vector
94  std::vector<bool> fnoise;
95  std::vector<bool> fvisited;
96  std::vector<double> fWirePitch;
97  std::set<uint32_t> fBadChannels;
98  std::vector<uint32_t> fBadWireSum;
99 
102  // Three differnt version of the clustering code
103  void run_dbscan_cluster();
104  void run_FN_cluster();
105  void run_FN_naive_cluster();
106 
107  // Helper routined for run_dbscan_cluster() names and
108  // responsibilities taken directly from the paper
109  bool ExpandCluster(unsigned int point /* to be added */,
110  unsigned int clusterID /* which is being expanded */);
111  std::set<unsigned int> RegionQuery(unsigned int point);
112  // Helper for the accelerated run_FN_cluster()
113  std::vector<unsigned int> RegionQuery_vector(unsigned int point);
114 
115  }; // class DBScanAlg
116 } // namespace
117 
118 #endif // ifndef DBSCANALG_H
Float_t x
Definition: compare.C:6
RStarTree< uint32_t, 2, 32, 64 > RTree
Definition: DBScanAlg.h:32
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:98
Float_t Y
Definition: plot.C:37
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:71
Cluster finding and building.
void Expand(double DX, double DY)
Definition: DBScanAlg.h:41
double dy
Definition: DBScanAlg.h:37
std::vector< std::vector< double > > fsim3
Definition: DBScanAlg.h:75
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:72
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
RTree::BoundingBox BoundingBox
Definition: DBScanAlg.h:33
parameter set interface
std::vector< bool > fvisited
Definition: DBScanAlg.h:95
General LArSoft Utilities.
Definition of data types for geometry description.
std::vector< double > fWirePitch
the pitch of the wires in each plane
Definition: DBScanAlg.h:96
unsigned int fMinPts
Definition: DBScanAlg.h:88
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:70
Contains all timing reference information for the detector.
double y
Definition: DBScanAlg.h:36
std::set< uint32_t > fBadChannels
set of bad channels in this detector
Definition: DBScanAlg.h:97
Float_t X
Definition: plot.C:37
std::vector< std::vector< double > > fsim2
Definition: DBScanAlg.h:74
std::vector< bool > fnoise
Definition: DBScanAlg.h:94
unsigned int fDistanceMetric
Which distance metric to use.
Definition: DBScanAlg.h:91