Skip to content

Commit 7a1e4e4

Browse files
committed
ITS: TrackExtension fix dangling reference on vector reallocation
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 91c7686 commit 7a1e4e4

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -855,36 +855,40 @@ bool TrackerTraits::trackFollowing(TrackITSExt* track, int rof, bool outward, co
855855
auto propInstance = o2::base::Propagator::Instance();
856856
const int step = -1 + outward * 2;
857857
const int end = outward ? mTrkParams[iteration].NLayers - 1 : 0;
858-
std::vector<TrackITSExt> hypotheses(1, *track);
859-
for (auto& hypo : hypotheses) {
860-
int iLayer = outward ? track->getLastClusterLayer() : track->getFirstClusterLayer();
858+
std::vector<TrackITSExt> hypotheses(1, *track); // possibly avoid reallocation
859+
for (size_t iHypo{0}; iHypo < hypotheses.size(); ++iHypo) {
860+
auto hypo{hypotheses[iHypo]};
861+
int iLayer = static_cast<int>(outward ? hypo.getLastClusterLayer() : hypo.getFirstClusterLayer());
862+
// per layer we add new hypotheses
861863
while (iLayer != end) {
862-
iLayer += step;
864+
iLayer += step; // step through all layers until we reach the end, this allows for skipping on empty layers
863865
const float r = mTrkParams[iteration].LayerRadii[iLayer];
866+
// get an estimate of the trackinf-frame x for the next step
864867
float x{-999};
865868
if (!hypo.getXatLabR(r, x, mTimeFrame->getBz(), o2::track::DirAuto) || x <= 0.f) {
866869
continue;
867870
}
868-
871+
// estimate hypo's trk parameters at that x
869872
auto& hypoParam{outward ? hypo.getParamOut() : hypo.getParamIn()};
870873
if (!propInstance->propagateToX(hypoParam, x, mTimeFrame->getBz(), PropagatorF::MAX_SIN_PHI,
871874
PropagatorF::MAX_STEP, mTrkParams[iteration].CorrType)) {
872875
continue;
873876
}
874877

875-
if (mTrkParams[iteration].CorrType == PropagatorF::MatCorrType::USEMatCorrNONE) {
876-
float radl = 9.36f; // Radiation length of Si [cm]
877-
float rho = 2.33f; // Density of Si [g/cm^3]
878+
if (mTrkParams[iteration].CorrType == PropagatorF::MatCorrType::USEMatCorrNONE) { // account for material affects if propagator does not
879+
constexpr float radl = 9.36f; // Radiation length of Si [cm]
880+
constexpr float rho = 2.33f; // Density of Si [g/cm^3]
878881
if (!hypoParam.correctForMaterial(mTrkParams[iteration].LayerxX0[iLayer], mTrkParams[iteration].LayerxX0[iLayer] * radl * rho, true)) {
879882
continue;
880883
}
881884
}
885+
886+
// calculate the search window on this layer
882887
const float phi{hypoParam.getPhi()};
883888
const float ePhi{o2::gpu::CAMath::Sqrt(hypoParam.getSigmaSnp2() / hypoParam.getCsp2())};
884889
const float z{hypoParam.getZ()};
885890
const float eZ{o2::gpu::CAMath::Sqrt(hypoParam.getSigmaZ2())};
886891
const int4 selectedBinsRect{getBinsRect(iLayer, phi, mTrkParams[iteration].NSigmaCut * ePhi, z, mTrkParams[iteration].NSigmaCut * eZ)};
887-
888892
if (selectedBinsRect.x == 0 && selectedBinsRect.y == 0 && selectedBinsRect.z == 0 && selectedBinsRect.w == 0) {
889893
continue;
890894
}
@@ -900,9 +904,9 @@ bool TrackerTraits::trackFollowing(TrackITSExt* track, int rof, bool outward, co
900904
continue;
901905
}
902906

903-
TrackITSExt currentHypo{hypo}, newHypo{hypo};
904-
bool first{true};
905-
for (int iPhiCount{0}; iPhiCount < phiBinsNum; iPhiCount++) {
907+
// check all clusters in search windows for possible new hypotheses
908+
#pragma omp parallel for num_threads(mNThreads) shared(hypotheses)
909+
for (int iPhiCount = 0; iPhiCount < phiBinsNum; iPhiCount++) {
906910
int iPhiBin = (selectedBinsRect.y + iPhiCount) % mTrkParams[iteration].PhiBins;
907911
const int firstBinIndex{mTimeFrame->mIndexTableUtils.getBinIndex(selectedBinsRect.x, iPhiBin)};
908912
const int maxBinIndex{firstBinIndex + selectedBinsRect.z - selectedBinsRect.x + 1};
@@ -921,7 +925,7 @@ bool TrackerTraits::trackFollowing(TrackITSExt* track, int rof, bool outward, co
921925

922926
const TrackingFrameInfo& trackingHit = mTimeFrame->getTrackingFrameInfoOnLayer(iLayer).at(nextCluster.clusterId);
923927

924-
TrackITSExt& tbupdated = first ? hypo : newHypo;
928+
auto tbupdated{hypo};
925929
auto& tbuParams = outward ? tbupdated.getParamOut() : tbupdated.getParamIn();
926930
if (!tbuParams.rotate(trackingHit.alphaTrackingFrame)) {
927931
continue;
@@ -942,12 +946,10 @@ bool TrackerTraits::trackFollowing(TrackITSExt* track, int rof, bool outward, co
942946
}
943947
tbupdated.setChi2(tbupdated.getChi2() + predChi2); /// This is wrong for outward propagation as the chi2 refers to inward parameters
944948
tbupdated.setExternalClusterIndex(iLayer, nextCluster.clusterId, true);
945-
946-
if (!first) {
949+
#pragma omp critical
950+
{
947951
hypotheses.emplace_back(tbupdated);
948-
newHypo = currentHypo;
949952
}
950-
first = false;
951953
}
952954
}
953955
}

0 commit comments

Comments
 (0)