13 template <
int mainGr
idSize,
int trkGr
idSize>
17 if (mainGrid == MainGridVector::Zero()) {
18 return VertexingError::EmptyInput;
22 if (!
m_cfg.useHighestSumZPosition) {
24 mainGrid.maxCoeff(&zbin);
28 zbin = getHighestSumZPosition(mainGrid);
32 return (zbin - mainGridSize / 2.0
f + 0.5
f) *
m_cfg.binSize;
35 template <
int mainGr
idSize,
int trkGr
idSize>
40 auto maxZRes = getMaxZPosition(mainGrid);
41 if (not maxZRes.ok()) {
42 return maxZRes.error();
44 float maxZ = *maxZRes;
47 auto widthRes = estimateSeedWidth(mainGrid, maxZ);
48 if (not widthRes.ok()) {
49 return widthRes.error();
51 float width = *widthRes;
52 std::pair<float, float> returnPair{
maxZ, width};
56 template <
int mainGr
idSize,
int trkGr
idSize>
58 mainGridSize, trkGridSize>::TrackGridVector>
66 int dOffset =
static_cast<int>(std::floor(d0 /
m_cfg.binSize - 0.5) + 1);
69 if (std::abs(dOffset) > (trkGridSize - 1) / 2.) {
72 return {-1, TrackGridVector::Zero()};
76 int zBin = int(z0 /
m_cfg.binSize + mainGridSize / 2.);
78 if (zBin < 0 || zBin >= mainGridSize) {
79 return {-1, TrackGridVector::Zero()};
82 float binCtrZ = (zBin + 0.5f) *
m_cfg.binSize -
m_cfg.zMinMax;
86 float distCtrZ = z0 - binCtrZ;
91 addTrackGridToMainGrid(zBin, trackGrid, mainGrid);
93 return {zBin, trackGrid};
96 template <
int mainGr
idSize,
int trkGr
idSize>
100 modifyMainGridWithTrackGrid(zBin, trkGrid, mainGrid, +1);
103 template <
int mainGr
idSize,
int trkGr
idSize>
107 modifyMainGridWithTrackGrid(zBin, trkGrid, mainGrid, -1);
110 template <
int mainGr
idSize,
int trkGr
idSize>
114 int modifyModeSign)
const {
115 int width = (trkGridSize - 1) / 2;
117 int leftOL = zBin -
width;
119 int rightOL = zBin + width - mainGridSize + 1;
121 int totalTrkSize = trkGridSize + leftOL;
122 mainGrid.segment(0, totalTrkSize) +=
123 modifyModeSign * trkGrid.segment(-leftOL, totalTrkSize);
127 int totalTrkSize = trkGridSize - rightOL;
128 mainGrid.segment(mainGridSize - totalTrkSize, totalTrkSize) +=
129 modifyModeSign * trkGrid.segment(0, totalTrkSize);
133 mainGrid.segment(zBin - width, trkGridSize) += modifyModeSign * trkGrid;
136 template <
int mainGr
idSize,
int trkGr
idSize>
138 trkGridSize>::TrackGridVector
142 float floorHalfTrkGridSize =
static_cast<float>(trkGridSize) / 2 - 0.5
f;
145 for (
int j = 0;
j < trkGridSize;
j++) {
146 float z = (
j - floorHalfTrkGridSize) *
m_cfg.binSize;
147 trackGrid(
j) = normal2D(-d0, z - distCtrZ, cov);
152 template <
int mainGr
idSize,
int trkGr
idSize>
156 if (mainGrid == MainGridVector::Zero()) {
157 return VertexingError::EmptyInput;
160 int zBin = int(maxZ /
m_cfg.binSize + mainGridSize / 2.);
162 const float maxValue = mainGrid(zBin);
163 float gridValue = mainGrid(zBin);
167 while (gridValue > maxValue / 2) {
169 gridValue = mainGrid(rhmBin);
173 float deltaZ1 =
m_cfg.binSize * (maxValue / 2 - mainGrid(rhmBin - 1)) /
174 (mainGrid(rhmBin) - mainGrid(rhmBin - 1));
178 gridValue = mainGrid(zBin);
179 while (gridValue > maxValue / 2) {
181 gridValue = mainGrid(lhmBin);
185 float deltaZ2 =
m_cfg.binSize * (mainGrid(lhmBin + 1) - maxValue / 2) /
186 (mainGrid(lhmBin + 1) - mainGrid(lhmBin));
190 rhmBin *
m_cfg.binSize - deltaZ1 - lhmBin *
m_cfg.binSize - deltaZ2;
193 float width = fwhm / 2.355f;
195 return std::isnormal(width) ? width : 0.0f;
198 template <
int mainGr
idSize,
int trkGr
idSize>
201 float det = cov.determinant();
202 float coef = 1 / std::sqrt(det);
205 (
cov(1, 1) * d * d - (
cov(0, 1) +
cov(1, 0)) * d * z +
cov(0, 0) * z *
z);
209 template <
int mainGr
idSize,
int trkGr
idSize>
217 mainGrid.maxCoeff(&zbin);
218 int zFirstMax = zbin;
219 double firstDensity = mainGrid(zFirstMax);
220 double firstSum = getDensitySum(mainGrid, zFirstMax);
223 mainGrid[zFirstMax] = 0;
224 mainGrid.maxCoeff(&zbin);
225 int zSecondMax = zbin;
226 double secondDensity = mainGrid(zSecondMax);
227 double secondSum = 0;
228 if (firstDensity - secondDensity <
229 firstDensity *
m_cfg.maxRelativeDensityDev) {
230 secondSum = getDensitySum(mainGrid, zSecondMax);
234 mainGrid[zSecondMax] = 0;
235 mainGrid.maxCoeff(&zbin);
236 int zThirdMax = zbin;
237 double thirdDensity = mainGrid(zThirdMax);
239 if (firstDensity - thirdDensity <
240 firstDensity *
m_cfg.maxRelativeDensityDev) {
241 thirdSum = getDensitySum(mainGrid, zThirdMax);
245 mainGrid[zFirstMax] = firstDensity;
246 mainGrid[zSecondMax] = secondDensity;
249 if (secondSum > firstSum && secondSum > thirdSum) {
252 if (thirdSum > secondSum && thirdSum > firstSum) {
258 template <
int mainGr
idSize,
int trkGr
idSize>
261 double sum = mainGrid(pos);
265 sum += mainGrid(pos - 1);
267 if (pos + 1 <= mainGrid.size() - 1) {
268 sum += mainGrid(pos + 1);