DBScanAlg_DUNE35t.h
Go to the documentation of this file.
1 /**
2  * @file DBScanAlg_DUNE35t.h
3  *
4  * @brief This algorithm will create and then cluster 3D hits using DBScan
5  *
6  * @author usher@slac.stanford.edu
7  *
8  */
9 #ifndef DBScanAlg_DUNE35t_h
10 #define DBScanAlg_DUNE35t_h
11 
12 // Framework Includes
13 #include "fhiclcpp/ParameterSet.h"
14 
15 // LArSoft includes
19 #include "lardata/RecoObjects/Cluster3D.h"
20 
21 // std includes
22 #include <vector>
23 #include <list>
24 #include <set>
25 #include <map>
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
28 namespace lar_cluster3d
29 {
30 /**
31  * @brief a utility class for keeping track of the state of a hit for DBScan
32  */
34 {
35 public:
36  DBScanParams() : m_visited(false), m_noise(false), m_inCluster(false), m_count(0) {}
37 
38  void setVisited() {m_visited = true;}
39  void setNoise() {m_noise = true;}
40  void setInCluster() {m_inCluster = true;}
41  void setCount(int count) {m_count = count;}
42 
43  void clearVisited() const {m_visited = false;}
44  void incrementCount(size_t count = 1) const {m_count += count;}
45 
46  bool visited() const {return m_visited;}
47  bool isNoise() const {return m_noise;}
48  bool inCluster() const {return m_inCluster;}
49  size_t getCount() const {return m_count;}
50 
51 private:
52  mutable bool m_visited;
53  bool m_noise;
55  mutable size_t m_count;
56 };
57 
58 /**
59  * @brief What follows are several highly useful typedefs which we
60  * want to expose to the outside world
61  */
62 
63 typedef std::vector<reco::ClusterHit2D*> HitVector;
64 typedef std::vector<const reco::ClusterHit2D*> HitVectorConst;
65 typedef std::map<int, HitVector > HitClusterMap;
66 typedef std::map<geo::View_t, HitVector> ViewToHitVectorMap;
67 
68 // forward declaration to define an ordering function for our hit set
70 {
71  bool operator() (const reco::ClusterHit2D*, const reco::ClusterHit2D*) const;
72 };
73 
74 typedef std::vector<reco::ClusterHit2D> Hit2DVector;
75 typedef std::set<const reco::ClusterHit2D*, Hit2DSetCompare> Hit2DSet;
76 typedef std::map<unsigned int, Hit2DSet > WireToHitSetMap;
77 typedef std::map<geo::View_t, WireToHitSetMap > ViewToWireToHitSetMap;
78 typedef std::map<geo::View_t, HitVector > HitVectorMap;
79 
80 typedef std::vector<std::unique_ptr<reco::ClusterHit3D> > HitPairVector;
81 typedef std::list<std::unique_ptr<reco::ClusterHit3D> > HitPairList;
82 
83 /**
84  * @brief DBScanAlg_DUNE35t class definiton
85  */
87 {
88 public:
89  /**
90  * @brief Constructor
91  *
92  * @param pset
93  */
95 
96  /**
97  * @brief Destructor
98  */
99  virtual ~DBScanAlg_DUNE35t();
100 
101  void reconfigure(fhicl::ParameterSet const &pset);
102 
103  /**
104  * @brief Given a set of recob hits, run DBscan to form 3D clusters
105  */
106  void ClusterHitsDBScan(ViewToHitVectorMap& viewToHitVectorMap,
107  ViewToWireToHitSetMap& viewToWiretoHitSetMap,
108  HitPairList& hitPairList,
109  reco::HitPairClusterMap& hitPairClusterMap);
110 
111  /**
112  * @brief enumerate the possible values for time checking if monitoring timing
113  */
114  enum TimeValues {BUILDTHREEDHITS = 0,
115  BUILDHITTOHITMAP = 1,
116  RUNDBSCAN = 2,
117  NUMTIMEVALUES
118  };
119 
120  /**
121  * @brief If monitoring, recover the time to execute a particular function
122  */
123  double getTimeToExecute(TimeValues index) const {return m_timeVector.at(index);}
124 
125 private:
126 
127  /**
128  * @brief Given the ClusterHit2D objects, build the HitPairMap
129  */
130  size_t BuildHitPairMap(ViewToHitVectorMap& viewToHitVectorMap, ViewToWireToHitSetMap& viewToWiretoHitSetMap, HitPairList& hitPairList) const;
131 
132  /**
133  * @brief Make a HitPair object by checking two hits
134  */
135  reco::ClusterHit3D makeHitPair(const reco::ClusterHit2D* hit1,
136  const reco::ClusterHit2D* hit2,
137  double hitWidthSclFctr = 1.,
138  size_t hitPairCntr = 0) const;
139 
140  /**
141  * @brief Make a HitPair object by checking two hits
142  */
143  reco::ClusterHit3D makeHitTriplet(const reco::ClusterHit3D& pair,
144  const reco::ClusterHit2D* hit2) const;
145 
146  /**
147  * @brief A utility routine for finding a 2D hit closest in time to the given pair
148  */
149  const reco::ClusterHit2D* FindBestMatchingHit(const Hit2DSet& hit2DSet, const reco::ClusterHit3D& pair, double pairDeltaTimeLimits) const;
150 
151  /**
152  * @brief A utility routine for returning the number of 2D hits from the list in a given range
153  */
154  int FindNumberInRange(const Hit2DSet& hit2DSet, const reco::ClusterHit3D& pair, double range) const;
155 
156  /**
157  * @brief The bigger question: are two pairs of hits consistent?
158  */
159  bool consistentPairs(const reco::ClusterHit3D* pair1, const reco::ClusterHit3D* pair2) const;
160 
161  typedef std::list<const reco::ClusterHit3D*> EpsPairNeighborhoodList;
162  typedef std::pair<DBScanParams, EpsPairNeighborhoodList > EpsPairNeighborhoodPair;
163  typedef std::map<const reco::ClusterHit3D*, EpsPairNeighborhoodPair > EpsPairNeighborhoodMap;
164  typedef std::pair<const reco::ClusterHit3D*, EpsPairNeighborhoodPair > EpsPairNeighborhoodMapPair;
165  typedef std::vector<EpsPairNeighborhoodMapPair > EpsPairNeighborhoodMapVec;
166 
167  /**
168  * @brief the main routine for DBScan
169  */
170  void expandCluster(EpsPairNeighborhoodMapVec& nMap,
173  size_t minPts) const;
174 
175  /**
176  * @brief Given an input HitPairList, build out the map of nearest neighbors
177  */
178  size_t BuildNeighborhoodMap(HitPairList& hitPairList,
179  EpsPairNeighborhoodMapVec& epsPairNeighborhoodMapVec )const;
180 
181 
182  /**
183  * @brief Jacket the calls to finding the nearest wire in order to intercept the exceptions if out of range
184  */
185  geo::WireID NearestWireID(const double* position, const geo::View_t& view) const;
186  geo::WireID NearestWireID_mod(const double* position, const geo::PlaneID & thePlaneID ) const;
187 
188 
189  /**
190  * @brief Data members to follow
191  */
192 
193  size_t m_minPairPts;
196  double m_EpsMaxDist;
197 
199  int m_hits; ///<
200  std::vector<float> m_timeVector; ///<
201 
202  geo::Geometry* m_geometry; // pointer to the Geometry service
203 
204 
205  // const detinfo::DetectorProperties* m_detector; // Pointer to the detector properties
206 };
207 
208 } // namespace lar_cluster3d
209 #endif
std::vector< reco::ClusterHit2D > Hit2DVector
intermediate_table::iterator iterator
std::map< int, HitPairListPtr > HitPairClusterMap
Definition: Cluster3D.h:338
std::map< int, HitVector > HitClusterMap
std::vector< EpsPairNeighborhoodMapPair > EpsPairNeighborhoodMapVec
std::map< const reco::ClusterHit3D *, EpsPairNeighborhoodPair > EpsPairNeighborhoodMap
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
What follows are several highly useful typedefs which we want to expose to the outside world...
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
std::map< geo::View_t, WireToHitSetMap > ViewToWireToHitSetMap
DBScanAlg_DUNE35t class definiton.
Cluster finding and building.
TimeValues
enumerate the possible values for time checking if monitoring timing
std::pair< DBScanParams, EpsPairNeighborhoodList > EpsPairNeighborhoodPair
art framework interface to geometry description
a utility class for keeping track of the state of a hit for DBScan
std::map< geo::View_t, HitVector > HitVectorMap
void incrementCount(size_t count=1) const
virtual void reconfigure(fhicl::ParameterSet const &pset)
std::map< geo::View_t, HitVector > ViewToHitVectorMap
double getTimeToExecute(TimeValues index) const
If monitoring, recover the time to execute a particular function.
std::list< std::unique_ptr< reco::ClusterHit3D > > HitPairList
std::vector< std::unique_ptr< reco::ClusterHit3D > > HitPairVector
std::list< const reco::ClusterHit3D * > HitPairListPtr
Definition: Cluster3D.h:335
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
size_t m_minPairPts
Data members to follow.
std::set< const reco::ClusterHit2D *, Hit2DSetCompare > Hit2DSet
std::vector< reco::ClusterHit2D * > HitVector
What follows are several highly useful typedefs which we want to expose to the outside world...
Declaration of signal hit object.
std::pair< const reco::ClusterHit3D *, EpsPairNeighborhoodPair > EpsPairNeighborhoodMapPair
std::vector< const reco::ClusterHit2D * > HitVectorConst
std::list< const reco::ClusterHit3D * > EpsPairNeighborhoodList
std::map< unsigned int, Hit2DSet > WireToHitSetMap