HerdSoftware  0.1.1
HoughFinder2DAlgo.hpp
Go to the documentation of this file.
1 /*
2  * HoughFinder2DAlgo.hpp
3  *
4  * Created on: 20 Nov 2018
5  * Author: Valerio Formato
6  */
7 
9 
10 namespace Herd {
11 
12 template <RefFrame::View T> void HoughFinder2DAlgo::FillVotingSpace(const HFClusters &clusters) {
13  const std::string routineName("HoughFinder2DAlgo::FillVotingSpace");
14 
16  RefFrame::Axis dir1 = axes.Dir1;
17  RefFrame::Axis dir2 = axes.Dir2;
18 
19  float r = 0, theta = 0;
20  for (size_t iLayer = 0; iLayer < clusters.size() - 1; iLayer++) {
21  for (auto _cl1 : clusters[iLayer]) {
22  for (size_t jLayer = iLayer + 1; jLayer < clusters.size(); jLayer++) {
23  for (auto _cl2 : clusters[jLayer]) {
24 
25  HoughTrackStub trStub(_cl1, _cl2, dir1, dir2);
26  theta = trStub.Theta();
27  r = trStub.R();
28 
29  // { // DEBUG
30  // int iTheta = floor(theta / M_PI * _nThetaDiv + 0.5);
31  // int iR = floor((r / _RMax + 1) * _nRDiv / 2 + 0.5);
32  // int iBin = _debugHist->GetBin(iTheta + 1, iR + 1);
33  // _debugHist->SetBinContent(iBin, _debugHist->GetBinContent(iBin) + 1);
34  // }
35 
36  int vspIndex = GetVotingIndex(r, theta);
37 
38  _votingSpace[vspIndex].emplace_back(trStub);
39  }
40  }
41  }
42  }
43 
44  // { //DEBUG
45  // _debugCanv->cd();
46  // _debugHist->Draw("colz");
47  // _debugCanv->Print("testHist.pdf");
48  // }
49 }
50 
51 template <RefFrame::View T> void HoughFinder2DAlgo::FindTracks(const HFClusters &clusters) {
52  const std::string routineName("HoughFinder2DAlgo::FindTracks");
53  COUT(DEBUG) << "Start!" << ENDL;
54 
55  _trackColl.clear();
56  int nClusters = 0;
57  for (auto layerClusters : clusters) {
58  nClusters += layerClusters.size();
59  }
60  if (nClusters < 1)
61  return;
62 
63  // _debugHist->Reset();
64 
65  // Clear up the voting space
67 
68  // Fill the voting space according to the event clusters
69  FillVotingSpace<T>(clusters);
70  // return;
71  auto vIndex = FindCandidateTrack();
72  if (vIndex < 0)
73  return;
74 
75  // Group up clustered votes
76  auto votes = AccumulateVotes(vIndex);
77 
78  // If the track candidate has enough votes...
79  while (votes.size() >= _nVotes) {
80  // Build it, clean up spurious hits, and remove the track clusters from the voting space
81  BuildTrackFromVotes(votes, clusters);
82  // break;
83  // move to the next candidate
84  vIndex = FindCandidateTrack();
85  if (vIndex < 0)
86  break;
87 
88  // rinse and repeat
89  votes = AccumulateVotes(vIndex);
90  }
91 }
92 
93 } // namespace Herd
std::vector< Track2D > _trackColl
Definition: HoughFinder2DAlgo.h:170
CssGeoParams.h CssGeoParams class declaration.
Definition: CaloPDCalibrationAlgo.h:24
std::unordered_map< int, std::vector< HoughTrackStub > > _votingSpace
Definition: HoughFinder2DAlgo.h:165
#define DEBUG
Definition: CaloAcceptanceCut.cpp:11
int FindCandidateTrack()
Definition: HoughFinder2DAlgo.cpp:154
Definition: HoughTrackStub.h:16
float R() const
Definition: HoughTrackStub.h:23
std::vector< std::vector< HFCluster > > HFClusters
Definition: HoughFinder2DAlgo.h:61
void ClearVotingSpace()
Definition: HoughFinder2DAlgo.h:130
Base struct to get the two axes of a given view.
Definition: RefFrame.h:140
Axis
Aliases for the axes. RefFrame.h common/RefFrame.h.
Definition: RefFrame.h:31
void FindTracks(const HFClusters &clusters)
Takes a collection of clusters on a given view and finds all the tracks.
Definition: HoughFinder2DAlgo.hpp:51
void BuildTrackFromVotes(std::vector< HoughTrackStub > &votes, const HFClusters &clusters)
Definition: HoughFinder2DAlgo.cpp:423
float Theta() const
Definition: HoughTrackStub.h:22
void FillVotingSpace(const HFClusters &clusters)
Definition: HoughFinder2DAlgo.hpp:12
int GetVotingIndex(float R, float Theta)
Computes voting space index for a given pair of R-Theta.
Definition: HoughFinder2DAlgo.cpp:133
unsigned int _nVotes
Definition: HoughFinder2DAlgo.h:113
std::vector< HoughTrackStub > AccumulateVotes(int votingIndex)
Definition: HoughFinder2DAlgo.cpp:175