12 #include <type_traits>
16 template <
typename external_spacepo
int_t,
typename platform_t>
21 throw std::runtime_error(
22 "SeedFinderConfig not in ACTS internal units in SeedFinder");
25 throw std::runtime_error(
"Value of deltaRMaxTopSP was not initialised");
28 throw std::runtime_error(
"Value of deltaRMinTopSP was not initialised");
31 throw std::runtime_error(
"Value of deltaRMaxBottomSP was not initialised");
34 throw std::runtime_error(
"Value of deltaRMinBottomSP was not initialised");
38 template <
typename external_spacepo
int_t,
typename platform_t>
39 template <
template <
typename...>
typename container_t,
typename sp_range_t>
44 const sp_range_t& bottomSPsIdx,
const std::size_t middleSPsIdx,
45 const sp_range_t& topSPsIdx,
48 throw std::runtime_error(
49 "SeedFinderOptions not in ACTS internal units in SeedFinder");
53 const std::size_t max_num_seeds_per_spm =
54 m_config.seedFilter->getSeedFilterConfig().maxSeedsPerSpMConf;
55 const std::size_t max_num_quality_seeds_per_spm =
56 m_config.seedFilter->getSeedFilterConfig().maxQualitySeedsPerSpMConf;
59 max_num_quality_seeds_per_spm);
62 if (bottomSPsIdx.size() == 0 or topSPsIdx.size() == 0) {
67 const auto& middleSPs = grid.
at(middleSPsIdx);
76 for (
const std::size_t
idx : bottomSPsIdx) {
78 grid,
idx, middleSPs.front()->radius() - m_config.deltaRMaxBottomSP);
81 for (
const std::size_t
idx : topSPsIdx) {
83 grid,
idx, middleSPs.front()->radius() + m_config.deltaRMinTopSP);
86 for (
const auto& spM : middleSPs) {
87 float rM = spM->radius();
90 if (m_config.useVariableMiddleSPRange) {
91 if (rM < rMiddleSPRange.
min()) {
94 if (rM > rMiddleSPRange.
max()) {
98 }
else if (not m_config.rRangeMiddleSP.empty()) {
100 auto pVal = std::lower_bound(m_config.zBinEdges.begin(),
101 m_config.zBinEdges.end(), spM->z());
104 zBin == 0 ? zBin : --zBin;
105 if (rM < m_config.rRangeMiddleSP[zBin][0]) {
108 if (rM > m_config.rRangeMiddleSP[zBin][1]) {
113 if (rM < m_config.rMinMiddle) {
116 if (rM > m_config.rMaxMiddle) {
125 if (zM < m_config.zOutermostLayers.first or
126 zM > m_config.zOutermostLayers.second) {
130 const float uIP = -1. / rM;
131 const float cosPhiM = -spM->x() * uIP;
132 const float sinPhiM = -spM->y() * uIP;
133 const float uIP2 = uIP * uIP;
136 getCompatibleDoublets<Acts::SpacePointCandidateType::eTop>(
139 m_config.deltaRMaxTopSP, uIP, uIP2, cosPhiM, sinPhiM);
148 if (m_config.seedConfirmation) {
151 (zM > m_config.centralSeedConfirmationRange.zMaxSeedConf ||
152 zM < m_config.centralSeedConfirmationRange.zMinSeedConf)
153 ? m_config.forwardSeedConfirmationRange
154 : m_config.centralSeedConfirmationRange;
169 getCompatibleDoublets<Acts::SpacePointCandidateType::eBottom>(
172 m_config.deltaRMaxBottomSP, uIP, uIP2, cosPhiM, sinPhiM);
180 if (m_config.useDetailedDoubleMeasurementInfo) {
181 filterCandidates<Acts::DetectorMeasurementInfo::eDetailed>(
184 filterCandidates<Acts::DetectorMeasurementInfo::eDefault>(
188 m_config.seedFilter->filterSeeds_1SpFixed(
195 template <
typename external_spacepo
int_t,
typename platform_t>
196 template <Acts::SpacePo
intCand
idateType cand
idateType,
typename out_range_t>
205 std::vector<LinCircle>& linCircleVec, out_range_t& outVec,
206 const float deltaRMinSP,
const float deltaRMaxSP,
const float uIP,
207 const float uIP2,
const float cosPhiM,
const float sinPhiM)
const {
209 if constexpr (candidateType == Acts::SpacePointCandidateType::eBottom) {
214 linCircleVec.clear();
218 for (
const auto& otherSPCol : otherSPsNeighbours) {
219 nsp += grid.
at(otherSPCol.index).size();
222 linCircleVec.reserve(nsp);
225 const float rM = mediumSP.
radius();
226 const float xM = mediumSP.
x();
227 const float yM = mediumSP.
y();
228 const float zM = mediumSP.
z();
229 const float varianceRM = mediumSP.
varianceR();
230 const float varianceZM = mediumSP.
varianceZ();
233 if (m_config.interactionPointCut) {
235 vIPAbs = impactMax * uIP2;
241 for (
auto& otherSPCol : otherSPsNeighbours) {
242 const auto& otherSPs = grid.
at(otherSPCol.index);
243 if (otherSPs.size() == 0) {
249 auto min_itr = otherSPCol.itr;
253 for (; min_itr != otherSPs.end(); ++min_itr) {
254 const auto& otherSP = *min_itr;
255 if constexpr (candidateType == Acts::SpacePointCandidateType::eBottom) {
257 if ((rM - otherSP->radius()) <= deltaRMaxSP) {
262 if ((otherSP->radius() - rM) >= deltaRMinSP) {
270 otherSPCol.itr = min_itr;
272 for (; min_itr != otherSPs.end(); ++min_itr) {
273 const auto& otherSP = *min_itr;
275 if constexpr (candidateType == Acts::SpacePointCandidateType::eBottom) {
276 deltaR = (rM - otherSP->radius());
279 if (deltaR < deltaRMinSP) {
283 deltaR = (otherSP->radius() - rM);
286 if (deltaR > deltaRMaxSP) {
291 if constexpr (candidateType == Acts::SpacePointCandidateType::eBottom) {
292 deltaZ = (zM - otherSP->z());
294 deltaZ = (otherSP->z() - zM);
301 const float zOriginTimesDeltaR = (zM * deltaR - rM * deltaZ);
303 if (zOriginTimesDeltaR < m_config.collisionRegionMin * deltaR or
304 zOriginTimesDeltaR > m_config.collisionRegionMax * deltaR) {
312 if (not m_config.interactionPointCut) {
316 if (deltaZ > m_config.cotThetaMax * deltaR or
317 deltaZ < -m_config.cotThetaMax * deltaR) {
321 if (deltaZ > m_config.deltaZMax or deltaZ < -m_config.deltaZMax) {
326 const float deltaX = otherSP->x() - xM;
327 const float deltaY = otherSP->y() - yM;
329 const float xNewFrame = deltaX * cosPhiM + deltaY * sinPhiM;
330 const float yNewFrame = deltaY * cosPhiM - deltaX * sinPhiM;
332 const float deltaR2 = (deltaX * deltaX + deltaY * deltaY);
333 const float iDeltaR2 = 1. / deltaR2;
335 const float uT = xNewFrame * iDeltaR2;
336 const float vT = yNewFrame * iDeltaR2;
338 const float iDeltaR = std::sqrt(iDeltaR2);
339 const float cotTheta = deltaZ * iDeltaR;
342 ((varianceZM + otherSP->varianceZ()) +
343 (cotTheta * cotTheta) * (varianceRM + otherSP->varianceR())) *
347 linCircleVec.emplace_back(cotTheta, iDeltaR, Er, uT, vT, xNewFrame,
349 spacePointData.
setDeltaR(otherSP->index(),
350 std::sqrt(deltaR2 + (deltaZ * deltaZ)));
351 outVec.push_back(otherSP.get());
356 const float deltaX = otherSP->x() - xM;
357 const float deltaY = otherSP->y() - yM;
359 const float xNewFrame = deltaX * cosPhiM + deltaY * sinPhiM;
360 const float yNewFrame = deltaY * cosPhiM - deltaX * sinPhiM;
362 const float deltaR2 = (deltaX * deltaX + deltaY * deltaY);
363 const float iDeltaR2 = 1. / deltaR2;
365 const float uT = xNewFrame * iDeltaR2;
366 const float vT = yNewFrame * iDeltaR2;
370 if (std::abs(rM * yNewFrame) <= impactMax * xNewFrame) {
374 if (deltaZ > m_config.cotThetaMax * deltaR or
375 deltaZ < -m_config.cotThetaMax * deltaR) {
379 const float iDeltaR = std::sqrt(iDeltaR2);
380 const float cotTheta = deltaZ * iDeltaR;
383 ((varianceZM + otherSP->varianceZ()) +
384 (cotTheta * cotTheta) * (varianceRM + otherSP->varianceR())) *
388 linCircleVec.emplace_back(cotTheta, iDeltaR, Er, uT, vT, xNewFrame,
390 spacePointData.
setDeltaR(otherSP->index(),
391 std::sqrt(deltaR2 + (deltaZ * deltaZ)));
392 outVec.emplace_back(otherSP.get());
398 const float vIP = (yNewFrame > 0.) ? -vIPAbs : vIPAbs;
403 const float aCoef = (vT - vIP) / (uT - uIP);
404 const float bCoef = vIP - aCoef * uIP;
415 if (deltaZ > m_config.cotThetaMax * deltaR or
416 deltaZ < -m_config.cotThetaMax * deltaR) {
420 const float iDeltaR = std::sqrt(iDeltaR2);
421 const float cotTheta = deltaZ * iDeltaR;
424 ((varianceZM + otherSP->varianceZ()) +
425 (cotTheta * cotTheta) * (varianceRM + otherSP->varianceR())) *
429 linCircleVec.emplace_back(cotTheta, iDeltaR, Er, uT, vT, xNewFrame,
431 spacePointData.
setDeltaR(otherSP->index(),
432 std::sqrt(deltaR2 + (deltaZ * deltaZ)));
433 outVec.emplace_back(otherSP.get());
438 template <
typename external_spacepo
int_t,
typename platform_t>
439 template <Acts::DetectorMeasurementInfo detailedMeasurement>
446 float cosPhiM = spM.
x() / rM;
447 float sinPhiM = spM.
y() / rM;
455 for (std::size_t
i(0);
i < sorted_bottoms.size(); ++
i) {
456 sorted_bottoms[
i] =
i;
459 std::vector<std::size_t> sorted_tops(state.
linCircleTop.size());
460 for (std::size_t
i(0);
i < sorted_tops.size(); ++
i) {
464 if constexpr (detailedMeasurement ==
465 Acts::DetectorMeasurementInfo::eDefault) {
466 std::sort(sorted_bottoms.begin(), sorted_bottoms.end(),
467 [&
state](
const std::size_t
a,
const std::size_t
b) ->
bool {
472 std::sort(sorted_tops.begin(), sorted_tops.end(),
473 [&
state](
const std::size_t
a,
const std::size_t
b) ->
bool {
489 for (
const std::size_t
b : sorted_bottoms) {
491 if (t0 == numTopSP) {
496 float cotThetaB = lb.cotTheta;
500 float iDeltaRB = lb.iDeltaR;
503 float iSinTheta2 = (1. + cotThetaB * cotThetaB);
516 float sinTheta = 1 / std::sqrt(iSinTheta2);
517 float cosTheta = cotThetaB * sinTheta;
526 float rotationTermsUVtoXY[2] = {0, 0};
527 if constexpr (detailedMeasurement ==
528 Acts::DetectorMeasurementInfo::eDetailed) {
529 rotationTermsUVtoXY[0] = cosPhiM * sinTheta;
530 rotationTermsUVtoXY[1] = sinPhiM * sinTheta;
536 size_t minCompatibleTopSPs = 2;
537 if (!m_config.seedConfirmation or
539 minCompatibleTopSPs = 1;
542 minCompatibleTopSPs++;
545 for (
size_t index_t = t0; index_t < numTopSP; index_t++) {
546 const std::size_t
t = sorted_tops[index_t];
550 float cotThetaT = lt.cotTheta;
561 float iDeltaRB2 = 0.;
562 float iDeltaRT2 = 0.;
564 if constexpr (detailedMeasurement ==
565 Acts::DetectorMeasurementInfo::eDetailed) {
567 float dU = lt.U - Ub;
573 float A0 = (lt.V - Vb) / dU;
575 float zPositionMiddle = cosTheta * std::sqrt(1 + A0 * A0);
579 double positionMiddle[3] = {
580 rotationTermsUVtoXY[0] - rotationTermsUVtoXY[1] * A0,
581 rotationTermsUVtoXY[0] * A0 + rotationTermsUVtoXY[1],
590 float B0 = 2. * (Vb - A0 * Ub);
591 float Cb = 1. - B0 * lb.y;
592 float Sb = A0 + B0 * lb.x;
593 double positionBottom[3] = {
594 rotationTermsUVtoXY[0] * Cb - rotationTermsUVtoXY[1] * Sb,
595 rotationTermsUVtoXY[0] * Sb + rotationTermsUVtoXY[1] * Cb,
606 float Ct = 1. - B0 * lt.y;
607 float St = A0 + B0 * lt.x;
608 double positionTop[3] = {
609 rotationTermsUVtoXY[0] * Ct - rotationTermsUVtoXY[1] * St,
610 rotationTermsUVtoXY[0] * St + rotationTermsUVtoXY[1] * Ct,
621 xB = rBTransf[0] - rMTransf[0];
622 yB = rBTransf[1] - rMTransf[1];
623 float zB = rBTransf[2] - rMTransf[2];
624 xT = rTTransf[0] - rMTransf[0];
625 yT = rTTransf[1] - rMTransf[1];
626 float zT = rTTransf[2] - rMTransf[2];
628 iDeltaRB2 = 1. / (xB * xB + yB * yB);
629 iDeltaRT2 = 1. / (xT * xT + yT * yT);
631 cotThetaB = -zB * std::sqrt(iDeltaRB2);
632 cotThetaT = zT * std::sqrt(iDeltaRT2);
636 float cotThetaAvg2 = cotThetaB * cotThetaT;
637 if constexpr (detailedMeasurement ==
638 Acts::DetectorMeasurementInfo::eDetailed) {
640 float averageCotTheta = 0.5 * (cotThetaB + cotThetaT);
641 cotThetaAvg2 = averageCotTheta * averageCotTheta;
642 }
else if (cotThetaAvg2 <= 0) {
650 2 * (cotThetaAvg2 * varianceRM + varianceZM) * iDeltaRB * lt.iDeltaR;
652 float deltaCotTheta = cotThetaB - cotThetaT;
653 float deltaCotTheta2 = deltaCotTheta * deltaCotTheta;
665 if (deltaCotTheta2 > (error2 + scatteringInRegion2)) {
667 if constexpr (detailedMeasurement ==
668 Acts::DetectorMeasurementInfo::eDetailed) {
673 if (cotThetaB - cotThetaT < 0) {
680 if constexpr (detailedMeasurement ==
681 Acts::DetectorMeasurementInfo::eDetailed) {
682 rMxy = std::sqrt(rMTransf[0] * rMTransf[0] + rMTransf[1] * rMTransf[1]);
683 double irMxy = 1 / rMxy;
684 float Ax = rMTransf[0] * irMxy;
685 float Ay = rMTransf[1] * irMxy;
687 ub = (xB * Ax + yB * Ay) * iDeltaRB2;
688 vb = (yB * Ax - xB * Ay) * iDeltaRB2;
689 ut = (xT * Ax + yT * Ay) * iDeltaRT2;
690 vt = (yT * Ax - xT * Ay) * iDeltaRT2;
699 if constexpr (detailedMeasurement ==
700 Acts::DetectorMeasurementInfo::eDetailed) {
718 A = (lt.V - Vb) / dU;
733 float iHelixDiameter2 = B2 / S2;
736 float p2scatterSigma = iHelixDiameter2 * sigmaSquaredPtDependent;
737 if (!std::isinf(m_config.maxPtScattering)) {
743 2. * m_config.maxPtScattering) {
744 float pTscatterSigma =
745 (m_config.highland / m_config.maxPtScattering) *
746 m_config.sigmaScattering;
747 p2scatterSigma = pTscatterSigma * pTscatterSigma * iSinTheta2;
752 if (deltaCotTheta2 > (error2 + p2scatterSigma)) {
753 if constexpr (detailedMeasurement ==
754 Acts::DetectorMeasurementInfo::eDetailed) {
757 if (cotThetaB - cotThetaT < 0) {
767 if constexpr (detailedMeasurement ==
768 Acts::DetectorMeasurementInfo::eDetailed) {
769 Im = std::abs((A - B * rMxy) * rMxy);
771 Im = std::abs((A - B * rM) * rM);
774 if (Im > m_config.impactMax) {
781 state.
curvatures.push_back(B / std::sqrt(S2));
786 if (state.
topSpVec.size() < minCompatibleTopSPs) {
790 seedFilterState.
zOrigin = spM.
z() - rM * lb.cotTheta;
792 m_config.seedFilter->filterSeeds_2SpFixed(
799 template <
typename external_spacepo
int_t,
typename platform_t>
800 template <
typename sp_range_t>
801 std::vector<Seed<external_spacepoint_t>>
805 const sp_range_t& bottomSPs,
const std::size_t middleSPs,
806 const sp_range_t& topSPs)
const {
809 std::vector<Seed<external_spacepoint_t>> ret;
811 createSeedsForGroup(options, state, grid, std::back_inserter(ret), bottomSPs,
812 middleSPs, topSPs, rMiddleSPRange);