8#include <tracking/datcon/findlets/FastInterceptFinder2DFPGA.h>
9#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
10#include <vxd/dataobjects/VxdID.h>
11#include <framework/core/ModuleParamList.h>
12#include <framework/core/ModuleParamList.templateDetails.h>
15using namespace TrackFindingCDC;
77 B2ASSERT(
"The maximum number of currentRecursion in u must not be larger than 14, but it is " <<
m_param_maxRecursionLevel,
114 std::vector<std::pair<double, double>>& tracks)
133 tracks.emplace_back(trackCand);
146 uint xmin, uint xmax, uint ymin, uint ymax, uint currentRecursion)
148 std::vector<std::pair<VxdID, std::pair<long, long>>> containedHits;
153 const uint centerx = xmin + (uint)((xmax - xmin) / 2);
154 const uint centery = ymin + (uint)((ymax - ymin) / 2);
155 const uint xIndexCache[3] = {xmin, centerx, xmax};
156 const uint yIndexCache[3] = {ymin, centery, ymax};
158 for (
int i = 0; i < 2 ; ++i) {
159 const uint left = xIndexCache[i];
160 const uint right = xIndexCache[i + 1];
161 const uint localIndexX = left;
163 if (left == right)
continue;
165 const double& localLeft =
m_HSXLUT[left];
166 const double& localRight =
m_HSXLUT[right];
177 for (
int j = 0; j < 2; ++j) {
179 const uint lowerIndex = yIndexCache[j];
180 const uint upperIndex = yIndexCache[j + 1];
182 const uint localIndexY = lowerIndex;
183 const long& localUpperCoordinate =
m_HSYLUT[lowerIndex];
184 const long& localLowerCoordinate =
m_HSYLUT[upperIndex];
186 if (lowerIndex == upperIndex)
continue;
188 std::vector<bool> layerHits(7);
189 containedHits.clear();
190 for (
auto& hit : hits) {
191 const VxdID& sensor = hit.first;
193 const long& m = hit.second.first;
194 const long& a = hit.second.second;
196 long yLeft = m * cosLeft + a * sinLeft;
197 long yRight = m * cosRight + a * sinRight;
198 long yCenter = m * cosCenter + a * sinCenter;
199 long derivativeyLeft = m * -sinLeft + a * cosLeft;
200 long derivativeyRight = m * -sinRight + a * cosRight;
201 long derivativeyCenter = m * -sinCenter + a * cosCenter;
205 if (derivativeyLeft < 0 and derivativeyRight < 0 and derivativeyCenter < 0)
continue;
208 if ((yLeft <= localUpperCoordinate and yRight >= localLowerCoordinate) or
209 (yCenter <= localUpperCoordinate and yLeft >= localLowerCoordinate and yRight >= localLowerCoordinate) or
210 (yCenter >= localLowerCoordinate and yLeft <= localUpperCoordinate and yRight <= localUpperCoordinate)) {
211 layerHits[sensor.getLayerNumber()] =
true;
212 containedHits.emplace_back(hit);
222 " to " << localRight <<
", " << localUpperCoordinate <<
" fc rgb \"" <<
223 m_const_rectColor[currentRecursion % 8] <<
"\" fs solid 0.5 behind" << std::endl;
235 " to " << localRight <<
", " << localUpperCoordinate <<
" fc rgb \"" <<
236 m_const_rectColor[currentRecursion % 8] <<
"\" fs solid 0.5 behind" << std::endl;
267 auto sortSectors = [](
const std::pair<uint, uint> a,
const std::pair<uint, uint> b) {
268 return ((
int)b.second - (int)a.second) * 16384 < (int)b.first - (
int)a.first;
292 double trackPhi = CoGX + M_PI_2;
293 if (trackPhi < -M_PI) trackPhi += 2 * M_PI;
294 if (trackPhi > M_PI) trackPhi -= 2 * M_PI;
298 double trackRadius = 1. / CoGY * 1e+13;
306 " CoGX: " << CoGX <<
" CoGY: " << CoGY);
320 for (uint currentIndexY = lastIndexY; currentIndexY >= lastIndexY - 1; currentIndexY--) {
323 for (uint currentIndexX = lastIndexX; currentIndexX <= lastIndexX + 1; currentIndexX++) {
328 if (lastIndexX == currentIndexX && lastIndexY == currentIndexY)
continue;
350 std::ofstream hsoutstream;
353 hsoutstream <<
"set pointsize 1.5\nset style line 42 lc rgb '#0060ad' pt 7 # circle" << std::endl;
355 hsoutstream <<
"set style line 80 lt rgb \"#808080\"" << std::endl;
356 hsoutstream <<
"set style line 81 lt 0" << std::endl;
357 hsoutstream <<
"set style line 81 lt rgb \"#808080\"" << std::endl << std::endl;
359 hsoutstream <<
"set style line 1 lt rgb \"#A00000\" lw 1 pt 1" << std::endl;
360 hsoutstream <<
"set style line 2 lt rgb \"#00A000\" lw 1 pt 6" << std::endl;
361 hsoutstream <<
"set style line 3 lt rgb \"#000000\" lw 1 pt 6" << std::endl;
363 hsoutstream <<
"set style line 3 lt rgb 'black' lw 1 pt 6" << std::endl;
364 hsoutstream <<
"set style line 4 lt rgb 'blue' lw 1 pt 6" << std::endl;
365 hsoutstream <<
"set style line 5 lt rgb 'green' lw 1 pt 6" << std::endl;
366 hsoutstream <<
"set style line 6 lt rgb 'red' lw 1 pt 6" << std::endl;
368 hsoutstream <<
"# Description position\nset key top right" << std::endl << std::endl;
369 hsoutstream <<
"# Grid and border style\nset grid back linestyle 81\nset border 3 back linestyle 80" << std::endl << std::endl;
371 hsoutstream <<
"# No mirrors\nset xtics nomirror\nset ytics nomirror" << std::endl << std::endl;
372 hsoutstream <<
"# Encoding\nset encoding utf8" << std::endl << std::endl;
373 hsoutstream <<
"set xlabel \"x\"\nset ylabel \"y\"" << std::endl << std::endl;
375 hsoutstream <<
"set xrange [-pi-0.5:pi+0.5]" << std::endl << std::endl;
380 for (
auto& hit : hits) {
381 const VxdID&
id = hit.first;
382 int layer =
id.getLayerNumber();
386 const long xc = 1000 * hit.second.first;
387 const long yc = 1000 * hit.second.second;
390 hsoutstream <<
"plot " << xc <<
" * -sin(x) + " << yc <<
" * cos(x) > 0 ? " << xc <<
" * cos(x) + " << yc <<
391 " * sin(x) : 1/0 notitle linestyle " << layer <<
" # " <<
id << std::endl;
392 if (count < hits.size() - 1) hsoutstream <<
"re";
396 hsoutstream << std::endl;
398 hsoutstream <<
"pause -1" << std::endl;
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
void gnuplotoutput(const std::vector< std::pair< VxdID, std::pair< long, long > > > &hits)
gnuplot output for debugging
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 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 assigned to a g...
void initialize() override
Create the store arrays.
std::array< long, 16385 > m_HSYLUT
y values of the Hough Space sector boarders
double m_unitX
HS unit size in x.
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.
double m_unitY
HS unit size in y.
uint m_clusterCount
count the clusters
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.
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::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...
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
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.
void initialize() override
Receive and dispatch signal before the start of the event processing.
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Forward prefixed parameters of this findlet to the module parameter list.
Class to uniquely identify a any structure of the PXD and SVD.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double atan(double a)
atan for double
long convertFloatToInt(double value, int power)
Convert float or double to long int for more similarity to the FPGA implementation.
Abstract base class for different kinds of events.