Belle II Software  release-06-02-00
FastInterceptFinder2DFPGA.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
11 #include <tracking/datcon/utilities/DATCONHelpers.h>
12 
13 #include <string>
14 #include <vector>
15 #include <iostream>
16 #include <fstream>
17 #include <algorithm>
18 #include <cmath>
19 
20 namespace Belle2 {
25  class ModuleParamList;
26  class VxdID;
27 
33  TrackFindingCDC::Findlet<const std::pair<VxdID, std::pair<long, long>>, std::pair<double, double>> {
36 
37  public:
40 
42  void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override;
43 
45  void initialize() override;
46 
48  void apply(const std::vector<std::pair<VxdID, std::pair<long, long>>>& hits,
49  std::vector<std::pair<double, double>>& tracks) override;
50 
51  private:
52 
55  inline unsigned short layerFilter(std::vector<bool> layer)
56  {
57  uint layercount = std::count(layer.begin(), layer.end(), true);
58  return (layercount >= 3 ? layercount : 0);
59  }
60 
69  void fastInterceptFinder2d(const std::vector<std::pair<VxdID, std::pair<long, long>>>& hits,
70  uint xmin, uint xmax, uint ymin, uint ymax, uint currentRecursion);
71 
74  void FindHoughSpaceCluster();
75 
79  void DepthFirstSearch(uint lastIndexX, uint lastIndexY);
80 
82  void gnuplotoutput(const std::vector<std::pair<VxdID, std::pair<long, long>>>& hits);
83 
84  // Parameters
86  bool m_param_isUFinder = true;
87 
90 
93 
96 
99 
101  double m_param_minimumX = -3.168;
103  double m_param_maximumX = 3.168;
104 
106  double m_unitX = 0;
108  double m_unitY = 0;
109 
118 
121  std::array<long, 16385> m_HSSinValuesLUT = {0};
123  std::array<long, 16385> m_HSCosValuesLUT = {0};
125  std::array<long, 16384> m_HSCenterSinValuesLUT = {0};
127  std::array<long, 16384> m_HSCenterCosValuesLUT = {0};
129  std::array<long, 16385> m_HSYLUT = {0};
131  std::array<long, 16384> m_HSYCenterLUT = {0};
133  std::array<double, 16385> m_HSXLUT = {0};
135  std::array<double, 16384> m_HSXCenterLUT = {0};
136 
138  std::vector<int> m_SectorArray;
143  std::vector<std::pair<uint, uint>> m_activeSectorArray;
144 
146  uint m_clusterCount = 0;
148  uint m_clusterSize = 0;
149 
153  std::string m_param_gnuplotHSOutputFileName = "HSFPGA.plt";
155  std::string m_param_gnuplotHSRectOutputFileName = "HSFPGARect.plt";
157  std::string m_param_gnuplotHSCoGOutputFileName = "HSFPGACoG.plt";
159  std::ofstream m_rectoutstream;
161  std::ofstream m_cogoutstream;
163  const std::string m_const_rectColor[8] = {"blue", "cyan", "green", "yellow", "orange", "violet", "skyblue", "pink"};
165  uint m_rectcounter = 1;
166 
168  std::pair<int, int> m_clusterInitialPosition = std::make_pair(0, 0);
170  std::pair<int, int> m_clusterCoG = std::make_pair(0, 0);
171 
173  std::vector<std::pair<double, double>> m_trackCandidates;
174 
175  };
177 }
Findlet for finging intersections of sinosoidal curves in the 2D Hough space by iteratively calling f...
void gnuplotoutput(const std::vector< std::pair< VxdID, std::pair< long, long >>> &hits)
gnuplot output for debugging
std::vector< int > m_SectorArray
vector containing only the 1D representation of active cells to speed up processing
uint m_param_MinimumHSClusterSize
minimum cluster size of sectors belonging to intercepts in the Hough Space
const std::string m_const_rectColor[8]
color definition for the sector debug output
void FindHoughSpaceCluster()
Find Hough Space clusters.
double m_param_maximumX
maximum x value of the Hough Space, defaults to the value for u-side
uint m_clusterSize
size of the current cluster
void initialize() override
Create the store arrays.
std::array< long, 16385 > m_HSYLUT
y values of the Hough Space sector boarders
std::array< double, 16385 > m_HSXLUT
x values of the Hough Space sector boarders
std::vector< std::pair< double, double > > m_trackCandidates
vector containing track candidates, consisting of the found intersection values in the Hough Space
std::string m_param_gnuplotHSRectOutputFileName
gnuplot HS sector output filename
uint m_param_nVerticalSectors
number of sectors of the Hough Space on the vertical axis
bool m_param_isUFinder
Is this the intercept finder for the u-side hits (r-phi) or v-side (r-z)?
long m_param_verticalHoughSpaceSize
vertical size of the Hough Space, defaults to the value for u-side
std::array< long, 16385 > m_HSCosValuesLUT
cosine values of the Hough Space sector boarder coordinates
void DepthFirstSearch(uint lastIndexX, uint lastIndexY)
Perform depth first search recursive algorithm to find clusters in the Hough Space.
std::array< long, 16385 > m_HSSinValuesLUT
Look-Up-Tables for values as cache to speed up calculation sine values of the Hough Space sector boar...
std::array< long, 16384 > m_HSCenterCosValuesLUT
cosine values of the Hough Space sector center coordinates
uint m_param_maxRecursionLevel
maximum number of recursive calls of fastInterceptFinder2d
std::ofstream m_rectoutstream
HS sector debug file.
std::ofstream m_cogoutstream
HS CoG debug file.
std::pair< int, int > m_clusterCoG
center of gravity containing describing the current best track parameters in the Hough Space
double m_param_minimumX
minimum x value of the Hough Space, defaults to the value for u-side
uint m_param_nAngleSectors
number of sectors of the Hough Space on the horizontal axis
std::string m_param_gnuplotHSOutputFileName
gnuplot HS output filename
std::vector< std::pair< uint, uint > > m_activeSectorArray
vector containing information for each cell whether it contained enough hits after m_maxRecursionLeve...
void apply(const std::vector< std::pair< VxdID, std::pair< long, long >>> &hits, std::vector< std::pair< double, double >> &tracks) override
Load in the prepared hits and create tracks for extrapolation to PXD.
std::array< long, 16384 > m_HSYCenterLUT
y values of the Hough Space sector centers
uint m_param_MaximumHSClusterSizeX
maximum cluster size in x of sectors belonging to intercepts in the Hough Space
std::string m_param_gnuplotHSCoGOutputFileName
gnuplot HS sector output filename
void fastInterceptFinder2d(const std::vector< std::pair< VxdID, std::pair< long, long >>> &hits, uint xmin, uint xmax, uint ymin, uint ymax, uint currentRecursion)
find intercepts in the 2D Hough Space by recursively calling itself until no hits are assinged to a g...
uint m_param_MaximumHSClusterSize
maximum cluster size of sectors belonging to intercepts in the Hough Space
bool m_param_writeGnuplotOutput
use gnuplot output?
unsigned short layerFilter(std::vector< bool > layer)
Layer filter, checks if at least hits from 3 layers are in a set of hits.
FastInterceptFinder2DFPGA()
Find intercepts in the 2D Hough space.
uint m_rectcounter
count HS debug rectangles
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
std::array< double, 16384 > m_HSXCenterLUT
x values of the Hough Space sector centers
std::pair< int, int > m_clusterInitialPosition
start cell of the recursive cluster finding in the Hough Space
uint m_param_MaximumHSClusterSizeY
maximum cluster size in y of sectors belonging to intercepts in the Hough Space
std::array< long, 16384 > m_HSCenterSinValuesLUT
sine values of the Hough Space sector center coordinates
The Module parameter list class.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
long convertFloatToInt(double value, int power)
Convert float or double to long int for more similarity to the FPGA implementation.
Definition: DATCONHelpers.h:21
Abstract base class for different kinds of events.