HerdSoftware  0.4.0
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 
19 // Event Analysis headers
20 #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 #include <variant>
30 
31 namespace Herd {
32 // clang-format off
63 // clang-format on
64 
65 using HFClusters = std::vector<std::vector<HFCluster>>;
66 using ClusterColl = std::variant<FitClustersColl, ScdClustersColl>;
67 using GeoParamsColl = std::variant<FitGeoParamsColl, ScdGeoParamsColl>;
68 
69 class HoughFinder2DAlgo : public EA::Algorithm {
70 public:
75  HoughFinder2DAlgo(const std::string &name);
76 
81  bool Initialize() override;
82 
87  bool Process() override;
88 
93  bool Finalize() override;
94 
101  int VotingIndex(float R, float Theta);
102 
107  std::pair<float, float> RTheta(int votingIndex);
108 
114  void FindTracks(RefFrame::View view, const HFClusters &clusters);
115 
116 private:
117  std::string m_collName = "tracks2DColl_hough";
118  bool m_publishAlias = true;
119 
120  bool m_useSCD = true;
121  bool m_useFIT = true;
122 
123  unsigned int m_nThetaDiv;
124  unsigned int m_nRDiv;
125  float m_RMax;
126  unsigned int m_nVotes;
127 
131 
132  // TH2D *_debugHist;
133  // TCanvas *_debugCanv;
134  void ImportHits(const ClusterColl &clColl, const GeoParamsColl &geoParamsColl, HFCluster::DetectorType detType);
135 
136  // Pretty self explanatory...
137  inline void ClearVotingSpace() { m_votingSpace.clear(); };
138 
139  // Fill voting space with clusters. Pass the normal axis to the view to
140  // determine which coordinates will be used.
141  void FillVotingSpace(RefFrame::View view, const HFClusters &clusters);
142 
143  // Remove a cluster votes from the voting space. Avoids a cluster partecipating
144  // in more than one track.
145  // void RemoveFromVotingSpace(HoughTrackStub trStub);
146  void RemoveFromVotingSpace(const Cluster &cluster);
147 
148  // Find out the voting space cell with highest number of votes
149  int FindCandidateTrack();
150 
151  // Aggregate all compatible votes around maximum
152  std::vector<HoughTrackStub> AccumulateVotes(int votingIndex);
153 
154  // Search around vote for compatible stubs
155  void SearchVotes(int votingIndex, std::vector<int> &vIndexes);
156 
157  // Find back a cluster given the seed ID
158  std::pair<bool, HFCluster> FindClusterFromSeedIndex(const HFClusters &clColl, unsigned int clID);
159 
160  // Get average direction from list of votes
161  std::pair<float, float> RThetaAverage(const std::vector<HoughTrackStub> &votes);
162 
163  // Build a track from a set of votes and eventually add it to the collection
164  Track2D BuildTrackFromVotes(std::vector<HoughTrackStub> &votes, const HFClusters &clColl);
165 
166  // Separate internal representation of clusters into separate detector collections, depending on a list
167  // of votes
168  std::tuple<ScdClustersColl, FitClustersColl> FillClusterCollections(const std::vector<HoughTrackStub> &votes,
169  const HFClusters &clColl);
170 
171  // int index -> list of track stubs that voted for that index
172  std::unordered_map<int, std::vector<HoughTrackStub>> m_votingSpace;
173 
174  EA::observer_ptr<ScdGeoParamsColl> m_scdGeoParamsColl;
175  EA::observer_ptr<FitGeoParamsColl> m_fitGeoParamsColl;
177  EA::StorePtr m_globStore; // Pointer to the global data store
178  EA::StorePtr m_evStore; // Pointer to the event data store
179 };
180 } // namespace Herd
181 #endif
HFCluster.h
Herd::HoughFinder2DAlgo::m_nVotes
unsigned int m_nVotes
Definition: HoughFinder2DAlgo.h:126
Herd::HoughFinder2DAlgo::VotingIndex
int VotingIndex(float R, float Theta)
Computes voting space index for a given pair of R-Theta.
Definition: HoughFinder2DAlgo.cpp:101
Herd::HoughFinder2DAlgo::m_nRDiv
unsigned int m_nRDiv
Definition: HoughFinder2DAlgo.h:124
Herd::HoughFinder2DAlgo::HoughFinder2DAlgo
HoughFinder2DAlgo(const std::string &name)
Constructor.
Definition: HoughFinder2DAlgo.cpp:28
Herd::HFClusters
std::vector< std::vector< HFCluster > > HFClusters
Definition: HoughFinder2DAlgo.h:65
Herd::HoughFinder2DAlgo::FindCandidateTrack
int FindCandidateTrack()
Definition: HoughFinder2DAlgo.cpp:122
Track2DColl.h
Herd::HoughFinder2DAlgo::m_fitGeoParamsColl
EA::observer_ptr< FitGeoParamsColl > m_fitGeoParamsColl
Definition: HoughFinder2DAlgo.h:175
Herd::HoughFinder2DAlgo::m_useFIT
bool m_useFIT
Definition: HoughFinder2DAlgo.h:121
Herd::HoughFinder2DAlgo::RemoveFromVotingSpace
void RemoveFromVotingSpace(const Cluster &cluster)
Definition: HoughFinder2DAlgo.cpp:201
Herd::HoughFinder2DAlgo::RTheta
std::pair< float, float > RTheta(int votingIndex)
Returns R and Theta values given a voting space index.
Definition: HoughFinder2DAlgo.cpp:115
Herd::HoughFinder2DAlgo::Initialize
bool Initialize() override
Initialization of the algorithm.
Definition: HoughFinder2DAlgo.cpp:212
Herd::Cluster
Tracker cluster object for transient data model.
Definition: Cluster.h:30
Herd::ClusterColl
std::variant< FitClustersColl, ScdClustersColl > ClusterColl
Definition: HoughFinder2DAlgo.h:66
Herd::HoughFinder2DAlgo::m_scdGeoParamsColl
EA::observer_ptr< ScdGeoParamsColl > m_scdGeoParamsColl
Definition: HoughFinder2DAlgo.h:174
Herd::HoughFinder2DAlgo::m_RMax
float m_RMax
Definition: HoughFinder2DAlgo.h:125
Herd::HoughFinder2DAlgo::FillClusterCollections
std::tuple< ScdClustersColl, FitClustersColl > FillClusterCollections(const std::vector< HoughTrackStub > &votes, const HFClusters &clColl)
Definition: HoughFinder2DAlgo.cpp:307
Herd::HoughFinder2DAlgo::ClearVotingSpace
void ClearVotingSpace()
Definition: HoughFinder2DAlgo.h:137
Herd
CssGeoParams.h CssGeoParams class declaration.
Definition: CaloPDCalibrationAlgo.h:22
Herd::GeoParamsColl
std::variant< FitGeoParamsColl, ScdGeoParamsColl > GeoParamsColl
Definition: HoughFinder2DAlgo.h:67
Herd::RefFrame::View
View
Aliases for the three 2D projection planes.
Definition: RefFrame.h:91
Herd::HoughFinder2DAlgo::RThetaAverage
std::pair< float, float > RThetaAverage(const std::vector< HoughTrackStub > &votes)
Definition: HoughFinder2DAlgo.cpp:280
Herd::HoughFinder2DAlgo::BuildTrackFromVotes
Track2D BuildTrackFromVotes(std::vector< HoughTrackStub > &votes, const HFClusters &clColl)
Definition: HoughFinder2DAlgo.cpp:376
HoughTrackStub.h
Herd::HoughFinder2DAlgo::AccumulateVotes
std::vector< HoughTrackStub > AccumulateVotes(int votingIndex)
Definition: HoughFinder2DAlgo.cpp:144
ViewArray.h
Herd::HoughFinder2DAlgo::m_clXY
HFClusters m_clXY
Definition: HoughFinder2DAlgo.h:130
ScdClusters.h
Herd::HoughFinder2DAlgo::FindClusterFromSeedIndex
std::pair< bool, HFCluster > FindClusterFromSeedIndex(const HFClusters &clColl, unsigned int clID)
Definition: HoughFinder2DAlgo.cpp:492
ScdGeoParamsColl.h
Herd::HoughFinder2DAlgo::Finalize
bool Finalize() override
Post processing part.
Definition: HoughFinder2DAlgo.cpp:275
Herd::HoughFinder2DAlgo::m_votingSpace
std::unordered_map< int, std::vector< HoughTrackStub > > m_votingSpace
Definition: HoughFinder2DAlgo.h:172
Herd::HoughFinder2DAlgo::m_nThetaDiv
unsigned int m_nThetaDiv
Definition: HoughFinder2DAlgo.h:123
Herd::HoughFinder2DAlgo::m_useSCD
bool m_useSCD
Definition: HoughFinder2DAlgo.h:120
Herd::HoughFinder2DAlgo::m_globStore
EA::StorePtr m_globStore
Definition: HoughFinder2DAlgo.h:177
Herd::ViewArray< std::vector< Track2D > >
Herd::HoughFinder2DAlgo
Finds tracks from a collection of 2D hits.
Definition: HoughFinder2DAlgo.h:69
Herd::HoughFinder2DAlgo::FillVotingSpace
void FillVotingSpace(RefFrame::View view, const HFClusters &clusters)
Definition: HoughFinder2DAlgo.cpp:508
Herd::HoughFinder2DAlgo::m_trackColl
Track2DColl m_trackColl
Definition: HoughFinder2DAlgo.h:176
Herd::HoughFinder2DAlgo::Process
bool Process() override
Process a single event.
Definition: HoughFinder2DAlgo.cpp:233
Herd::HoughFinder2DAlgo::SearchVotes
void SearchVotes(int votingIndex, std::vector< int > &vIndexes)
Definition: HoughFinder2DAlgo.cpp:163
Herd::Track2D
Class describing a track.
Definition: Track2D.h:32
Herd::HFCluster::DetectorType
DetectorType
Definition: HFCluster.h:23
Herd::HoughFinder2DAlgo::m_publishAlias
bool m_publishAlias
Definition: HoughFinder2DAlgo.h:118
Herd::HoughFinder2DAlgo::m_collName
std::string m_collName
Definition: HoughFinder2DAlgo.h:117
Herd::HoughFinder2DAlgo::m_clYZ
HFClusters m_clYZ
Definition: HoughFinder2DAlgo.h:129
Herd::HoughFinder2DAlgo::ImportHits
void ImportHits(const ClusterColl &clColl, const GeoParamsColl &geoParamsColl, HFCluster::DetectorType detType)
Definition: HoughFinder2DAlgo.cpp:46
Herd::HoughFinder2DAlgo::m_evStore
EA::StorePtr m_evStore
Definition: HoughFinder2DAlgo.h:178
Herd::HoughFinder2DAlgo::m_clXZ
HFClusters m_clXZ
Definition: HoughFinder2DAlgo.h:128
Track.h
Herd::HoughFinder2DAlgo::FindTracks
void FindTracks(RefFrame::View view, const HFClusters &clusters)
Takes a collection of clusters on a given view and finds all the tracks.
Definition: HoughFinder2DAlgo.cpp:545