HerdSoftware  0.1.1
HoughFinder2DAlgo.h
Go to the documentation of this file.
1 /*
2  * HoughFinder2DAlgo.h
3  *
4  * Created on: 20 Nov 2018
5  * Author: Valerio Formato
6  */
7 
8 #ifndef HoughFinder2DAlgo_H_
9 #define HoughFinder2DAlgo_H_
10 
11 // HERD headers
18 #include "dataobjects/Track2D.h"
19 
20 // Event Analysis headers
21 #include "algorithm/Algorithm.h"
22 
23 // headers for debug only
24 // #include "TCanvas.h"
25 // #include "TH2D.h"
26 
27 // c++ headers
28 #include <tuple>
29 
30 using namespace EA;
31 
32 namespace Herd {
61 using HFClusters = std::vector<std::vector<HFCluster>>;
62 
63 class HoughFinder2DAlgo : public Algorithm {
64 public:
69  HoughFinder2DAlgo(const std::string &name);
70 
75  bool Initialize();
76 
81  bool Process();
82 
87  bool Finalize();
88 
95  int GetVotingIndex(float R, float Theta);
96 
101  std::pair<float, float> GetRTheta(int votingIndex);
102 
107  template <RefFrame::View T> void FindTracks(const HFClusters &clusters);
108 
109 private:
110  unsigned int _nThetaDiv;
111  unsigned int _nRDiv;
112  float _RMax;
113  unsigned int _nVotes;
114 
118 
119  // TH2D *_debugHist;
120  // TCanvas *_debugCanv;
121 
122  // handle both stk and scd hits and import them
123  void ImportSiliconDetectorHits(const SiliconDetectorClustersColl &clColl,
124  const SiliconDetectorGeoParamsColl &geoParamsColl, HFCluster::DetectorType detType);
125 
126  // handle fit hits and import them
127  void ImportFitHits(const FitClustersColl &clColl, const FitGeoParamsColl &geoParamsColl);
128 
129  // Pretty self explanatory...
130  inline void ClearVotingSpace() { _votingSpace.clear(); };
131 
132  // Fill voting space with clusters. Pass the normal axis to the view to
133  // determine which coordinates will be used.
134  template <RefFrame::View T> void FillVotingSpace(const HFClusters &clusters);
135 
136  // Remove a cluster votes from the voting space. Avoids a cluster partecipating
137  // in more than one track.
138  // void RemoveFromVotingSpace(HoughTrackStub trStub);
139  void RemoveFromVotingSpace(const Cluster &cluster);
140 
141  // Find out the voting space cell with highest number of votes
142  int FindCandidateTrack();
143 
144  // Aggregate all compatible votes around maximum
145  std::vector<HoughTrackStub> AccumulateVotes(int votingIndex);
146 
147  // Search around vote for compatible stubs
148  void SearchVotes(int votingIndex, std::vector<int> &vIndexes);
149 
150  // Find back a cluster given the seed ID
151  std::pair<bool, HFCluster> FindClusterFromSeedIndex(const HFClusters &clColl, unsigned int clID);
152 
153  // Get average direction from list of votes
154  std::pair<float, float> GetAvRTheta(const std::vector<HoughTrackStub> &votes);
155 
156  // Build a track from a set of votes and eventually add it to the collection
157  void BuildTrackFromVotes(std::vector<HoughTrackStub> &votes, const HFClusters &clusters);
158 
159  // Separate internal representation of clusters into separate detector collections, depending on a list
160  // of votes
161  std::tuple<StkClustersColl, ScdClustersColl, FitClustersColl>
162  FillClusterCollections(const std::vector<HoughTrackStub> &votes, const HFClusters &clColl);
163 
164  // int index -> list of track stubs that voted for that index
165  std::unordered_map<int, std::vector<HoughTrackStub>> _votingSpace;
166 
167  EA::observer_ptr<StkGeoParamsColl> _stkGeoParamsColl;
168  EA::observer_ptr<ScdGeoParamsColl> _scdGeoParamsColl;
169  EA::observer_ptr<FitGeoParamsColl> _fitGeoParamsColl;
170  std::vector<Track2D> _trackColl;
171  StorePtr _globStore; // Pointer to the global data store
172  StorePtr _evStore; // Pointer to the event data store
173 };
174 } // namespace Herd
175 #endif
std::vector< Track2D > _trackColl
Definition: HoughFinder2DAlgo.h:170
CssGeoParams.h CssGeoParams class declaration.
Definition: CaloPDCalibrationAlgo.h:24
DetectorType
Definition: HFCluster.h:23
std::unordered_map< int, std::vector< HoughTrackStub > > _votingSpace
Definition: HoughFinder2DAlgo.h:165
Finds tracks from a collection of 2D hits.
Definition: HoughFinder2DAlgo.h:63
Tracker cluster object for transient data model.
Definition: Cluster.h:30
std::vector< std::vector< HFCluster > > HFClusters
Definition: HoughFinder2DAlgo.h:61
void ClearVotingSpace()
Definition: HoughFinder2DAlgo.h:130
HFClusters _clXY
Definition: HoughFinder2DAlgo.h:117
EA::observer_ptr< ScdGeoParamsColl > _scdGeoParamsColl
Definition: HoughFinder2DAlgo.h:168
EA::observer_ptr< FitGeoParamsColl > _fitGeoParamsColl
Definition: HoughFinder2DAlgo.h:169
float _RMax
Definition: HoughFinder2DAlgo.h:112
EA::observer_ptr< StkGeoParamsColl > _stkGeoParamsColl
Definition: HoughFinder2DAlgo.h:167
HFClusters _clYZ
Definition: HoughFinder2DAlgo.h:116
HFClusters _clXZ
Definition: HoughFinder2DAlgo.h:115
unsigned int _nRDiv
Definition: HoughFinder2DAlgo.h:111
Collection of containers for the clusters of all the FIT detectors.
Definition: FitClustersColl.h:23
unsigned int _nThetaDiv
Definition: HoughFinder2DAlgo.h:110
unsigned int _nVotes
Definition: HoughFinder2DAlgo.h:113
StorePtr _globStore
Definition: HoughFinder2DAlgo.h:171
StorePtr _evStore
Definition: HoughFinder2DAlgo.h:172