Skip to content

Commit

Permalink
move
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Sep 19, 2024
1 parent c334ce4 commit eb0c85b
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 327 deletions.
8 changes: 3 additions & 5 deletions Core/include/Acts/Utilities/BinnedArrayXD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ class BinnedArrayXD : public BinnedArray<T> {
for (auto& o2 : m_objectGrid) {
for (auto& o1 : o2) {
for (auto& o0 : o1) {
if (o0) {
/// fill the unique m_arrayObjects
if (!rangeContainsValue(m_arrayObjects, o0)) {
m_arrayObjects.push_back(o0);
}
/// fill the unique m_arrayObjects
if (o0 && !rangeContainsValue(m_arrayObjects, o0)) {
m_arrayObjects.push_back(o0);
}
}
}
Expand Down
44 changes: 27 additions & 17 deletions Core/src/Detector/IndexedRootVolumeFinderBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2023-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -23,28 +23,38 @@ void fillGridIndices2D(
rootVolumes,
const std::array<std::vector<Acts::ActsScalar>, 2u>& boundaries,
const std::array<Acts::BinningValue, 2u>& casts) {
if (casts != std::array<Acts::BinningValue, 2u>{Acts::BinningValue::binZ,
Acts::BinningValue::binR}) {
return;
}

// Brute force loop over all bins & all volumes
for (const auto [ic0, c0] : Acts::enumerate(boundaries[0u])) {
if (ic0 > 0) {
Acts::ActsScalar v0 = 0.5 * (c0 + boundaries[0u][ic0 - 1]);
for (const auto [ic1, c1] : Acts::enumerate(boundaries[1u])) {
if (ic1 > 0) {
Acts::ActsScalar v1 = 0.5 * (c1 + boundaries[1u][ic1 - 1]);
if (casts ==
std::array<Acts::BinningValue, 2u>{Acts::BinningValue::binZ,
Acts::BinningValue::binR}) {
Acts::Vector3 zrPosition{v1, 0., v0};
for (const auto [iv, v] : Acts::enumerate(rootVolumes)) {
if (v->inside(gctx, zrPosition)) {
typename Grid2D::point_t p{v0, v1};
grid.atPosition(p) = iv;
}
}
}
if (ic0 == 0) {
continue;
}

const Acts::ActsScalar v0 = 0.5 * (c0 + boundaries[0u][ic0 - 1]);

for (const auto [ic1, c1] : Acts::enumerate(boundaries[1u])) {
if (ic1 == 0) {
continue;
}

const Acts::ActsScalar v1 = 0.5 * (c1 + boundaries[1u][ic1 - 1]);
const Acts::Vector3 zrPosition{v1, 0., v0};

for (const auto [iv, v] : Acts::enumerate(rootVolumes)) {
if (!v->inside(gctx, zrPosition)) {
continue;
}
typename Grid2D::point_t p{v0, v1};
grid.atPosition(p) = iv;
}
}
}

return;
}
} // namespace

Expand Down
68 changes: 37 additions & 31 deletions Core/src/Geometry/GridPortalLinkMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,43 +513,49 @@ void GridPortalLink::fillMergedGrid(const GridPortalLink& a,
for (std::size_t i = 1; i <= nBinsB; ++i) {
merged.atLocalBins({nBinsA + i}) = b.atLocalBins({i});
}
} else {
if (a.direction() == direction) {
std::size_t nBinsA = locBinsA.at(0);
std::size_t nBinsB = locBinsB.at(0);
std::size_t nBinsCommon = locBinsB.at(1);

for (std::size_t i = 1; i <= nBinsA; ++i) {
for (std::size_t j = 1; j <= nBinsCommon; ++j) {
merged.atLocalBins({i, j}) = a.atLocalBins({i, j});
}
}

for (std::size_t i = 1; i <= nBinsB; ++i) {
for (std::size_t j = 1; j <= nBinsCommon; ++j) {
std::size_t ti = i + nBinsA;
merged.atLocalBins({ti, j}) = b.atLocalBins({i, j});
}
}
} else {
std::size_t nBinsA = locBinsA.at(1);
std::size_t nBinsB = locBinsB.at(1);
std::size_t nBinsCommon = locBinsB.at(0);

for (std::size_t i = 1; i <= nBinsCommon; ++i) {
for (std::size_t j = 1; j <= nBinsA; ++j) {
merged.atLocalBins({i, j}) = a.atLocalBins({i, j});
}
return;
}

if (a.direction() == direction) {
std::size_t nBinsA = locBinsA.at(0);
std::size_t nBinsB = locBinsB.at(0);
std::size_t nBinsCommon = locBinsB.at(1);

for (std::size_t i = 1; i <= nBinsA; ++i) {
for (std::size_t j = 1; j <= nBinsCommon; ++j) {
merged.atLocalBins({i, j}) = a.atLocalBins({i, j});
}
}

for (std::size_t i = 1; i <= nBinsCommon; ++i) {
for (std::size_t j = 1; j <= nBinsB; ++j) {
std::size_t tj = j + nBinsA;
merged.atLocalBins({i, tj}) = b.atLocalBins({i, j});
}
for (std::size_t i = 1; i <= nBinsB; ++i) {
for (std::size_t j = 1; j <= nBinsCommon; ++j) {
std::size_t ti = i + nBinsA;
merged.atLocalBins({ti, j}) = b.atLocalBins({i, j});
}
}

return;
}

std::size_t nBinsA = locBinsA.at(1);
std::size_t nBinsB = locBinsB.at(1);
std::size_t nBinsCommon = locBinsB.at(0);

for (std::size_t i = 1; i <= nBinsCommon; ++i) {
for (std::size_t j = 1; j <= nBinsA; ++j) {
merged.atLocalBins({i, j}) = a.atLocalBins({i, j});
}
}

for (std::size_t i = 1; i <= nBinsCommon; ++i) {
for (std::size_t j = 1; j <= nBinsB; ++j) {
std::size_t tj = j + nBinsA;
merged.atLocalBins({i, tj}) = b.atLocalBins({i, j});
}
}

return;
}

std::unique_ptr<PortalLinkBase> GridPortalLink::merge(const GridPortalLink& a,
Expand Down
52 changes: 26 additions & 26 deletions Core/src/Material/VolumeMaterialMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,34 +197,34 @@ void Acts::VolumeMaterialMapper::collectMaterialSurfaces(
if (tVolume.confinedLayers() != nullptr) {
for (auto& cLayer : tVolume.confinedLayers()->arrayObjects()) {
// Take only layers that are not navigation layers
if (cLayer->layerType() != navigation) {
// Check the representing surface
if (cLayer->surfaceRepresentation().surfaceMaterial() != nullptr) {
mState.surfaceMaterial[cLayer->surfaceRepresentation().geometryId()] =
cLayer->surfaceRepresentation().surfaceMaterialSharedPtr();
}
// Get the approach surfaces if present
if (cLayer->approachDescriptor() != nullptr) {
for (auto& aSurface :
cLayer->approachDescriptor()->containedSurfaces()) {
if (aSurface != nullptr) {
if (aSurface->surfaceMaterial() != nullptr) {
mState.surfaceMaterial[aSurface->geometryId()] =
aSurface->surfaceMaterialSharedPtr();
}
}
if (cLayer->layerType() == navigation) {
continue;
}

// Check the representing surface
if (cLayer->surfaceRepresentation().surfaceMaterial() != nullptr) {
mState.surfaceMaterial[cLayer->surfaceRepresentation().geometryId()] =
cLayer->surfaceRepresentation().surfaceMaterialSharedPtr();
}

// Get the approach surfaces if present
if (cLayer->approachDescriptor() != nullptr) {
for (auto& aSurface :
cLayer->approachDescriptor()->containedSurfaces()) {
if (aSurface != nullptr && aSurface->surfaceMaterial() != nullptr) {
mState.surfaceMaterial[aSurface->geometryId()] =
aSurface->surfaceMaterialSharedPtr();
}
}
// Get the sensitive surface is present
if (cLayer->surfaceArray() != nullptr) {
// Sensitive surface loop
for (auto& sSurface : cLayer->surfaceArray()->surfaces()) {
if (sSurface != nullptr) {
if (sSurface->surfaceMaterial() != nullptr) {
mState.surfaceMaterial[sSurface->geometryId()] =
sSurface->surfaceMaterialSharedPtr();
}
}
}

// Get the sensitive surface is present
if (cLayer->surfaceArray() != nullptr) {
// Sensitive surface loop
for (auto& sSurface : cLayer->surfaceArray()->surfaces()) {
if (sSurface != nullptr && sSurface->surfaceMaterial() != nullptr) {
mState.surfaceMaterial[sSurface->geometryId()] =
sSurface->surfaceMaterialSharedPtr();
}
}
}
Expand Down
121 changes: 69 additions & 52 deletions Examples/Algorithms/TrackFinding/src/HoughTransformSeeder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,34 @@ ActsExamples::ProcessCode ActsExamples::HoughTransformSeeder::execute(
for (unsigned y = 0; y < m_cfg.houghHistSize_y; y++) {
for (unsigned x = 0; x < m_cfg.houghHistSize_x; x++) {
if (passThreshold(m_houghHist, x, y)) {
/* now we need to unpack the hits; there should be multiple track
candidates if we have multiple hits in a given layer So the first
thing is to unpack the indices (which is what we need) by layer */

std::vector<std::vector<std::vector<Index>>> hitIndicesAll(
m_cfg.nLayers); // [layer,vector<Index]
std::vector<std::size_t> nHitsPerLayer(m_cfg.nLayers);
for (auto measurementIndex : m_houghHist.atLocalBins({y, x}).second) {
HoughMeasurementStruct* meas =
houghMeasurementStructs[measurementIndex].get();
hitIndicesAll[meas->layer].push_back(meas->indices);
nHitsPerLayer[meas->layer]++;
}
std::vector<std::vector<int>> combs = getComboIndices(nHitsPerLayer);

for (auto [icomb, hit_indices] :
Acts::enumerate(combs)) { // loop over all the combination

ProtoTrack protoTrack;
for (unsigned layer = 0; layer < m_cfg.nLayers; layer++) {
if (hit_indices[layer] >= 0) {
for (auto index : hitIndicesAll[layer][hit_indices[layer]]) {
protoTrack.push_back(index);
}
continue;
}
// now we need to unpack the hits; there should be multiple track
// candidates if we have multiple hits in a given layer So the first
// thing is to unpack the indices (which is what we need) by layer

std::vector<std::vector<std::vector<Index>>> hitIndicesAll(
m_cfg.nLayers); // [layer,vector<Index]
std::vector<std::size_t> nHitsPerLayer(m_cfg.nLayers);
for (auto measurementIndex : m_houghHist.atLocalBins({y, x}).second) {
HoughMeasurementStruct* meas =
houghMeasurementStructs[measurementIndex].get();
hitIndicesAll[meas->layer].push_back(meas->indices);
nHitsPerLayer[meas->layer]++;
}
std::vector<std::vector<int>> combs = getComboIndices(nHitsPerLayer);

// loop over all the combination
for (auto [icomb, hit_indices] : Acts::enumerate(combs)) {
ProtoTrack protoTrack;
for (std::size_t layer = 0; layer < m_cfg.nLayers; layer++) {
if (hit_indices[layer] >= 0) {
for (auto index : hitIndicesAll[layer][hit_indices[layer]]) {
protoTrack.push_back(index);
}
}
protoTracks.push_back(protoTrack);
}
protoTracks.push_back(protoTrack);
}
}
}
Expand Down Expand Up @@ -281,43 +281,60 @@ ActsExamples::HoughHist ActsExamples::HoughTransformSeeder::createHoughHist(
bool ActsExamples::HoughTransformSeeder::passThreshold(
HoughHist const& houghHist, unsigned x, unsigned y) const {
// Pass window threshold
unsigned width = m_cfg.threshold.size() / 2;
const unsigned width = m_cfg.threshold.size() / 2;

if (x < width || m_cfg.houghHistSize_x - x < width) {
return false;
}

for (unsigned i = 0; i < m_cfg.threshold.size(); i++) {
if (houghHist.atLocalBins({y, x - width + i}).first < m_cfg.threshold[i]) {
return false;
}
}

// Pass local-maximum check, if used
if (m_cfg.localMaxWindowSize != 0) {
for (int j = -m_cfg.localMaxWindowSize; j <= m_cfg.localMaxWindowSize;
j++) {
for (int i = -m_cfg.localMaxWindowSize; i <= m_cfg.localMaxWindowSize;
i++) {
if (i == 0 && j == 0) {
continue;
}
if (y + j < m_cfg.houghHistSize_y && x + i < m_cfg.houghHistSize_x) {
if (houghHist.atLocalBins({y + j, x + i}).first >
houghHist.atLocalBins({y, x}).first) {
return false;
}
if (houghHist.atLocalBins({y + j, x + i}).first ==
houghHist.atLocalBins({y, x}).first) {
if (houghHist.atLocalBins({y + j, x + i}).second.size() >
houghHist.atLocalBins({y, x}).second.size()) {
return false;
}
if (houghHist.atLocalBins({y + j, x + i}).second.size() ==
houghHist.atLocalBins({y, x}).second.size() &&
j <= 0 && i <= 0) {
return false; // favor bottom-left (low phi, low neg q/pt)
}
}
}
if (m_cfg.localMaxWindowSize == 0) {
return true;
}

for (int j = -m_cfg.localMaxWindowSize; j <= m_cfg.localMaxWindowSize; j++) {
if (y + j >= m_cfg.houghHistSize_y) {
continue;
}

for (int i = -m_cfg.localMaxWindowSize; i <= m_cfg.localMaxWindowSize;
i++) {
if (i == 0 && j == 0) {
continue;
}

if (x + i >= m_cfg.houghHistSize_x) {
continue;
}

if (houghHist.atLocalBins({y + j, x + i}).first <
houghHist.atLocalBins({y, x}).first) {
continue;
}

if (houghHist.atLocalBins({y + j, x + i}).first >
houghHist.atLocalBins({y, x}).first) {
return false;
}

if (houghHist.atLocalBins({y + j, x + i}).second.size() <
houghHist.atLocalBins({y, x}).second.size()) {
continue;
}

if (houghHist.atLocalBins({y + j, x + i}).second.size() >
houghHist.atLocalBins({y, x}).second.size()) {
return false;
}

if (j <= 0 && i <= 0) {
return false; // favor bottom-left (low phi, low neg q/pt)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,11 @@ ActsExamples::ProcessCode ActsExamples::TruthSeedingAlgorithm::execute(
double mtDeltaR = std::abs(spacePointsOnTrack[it]->r() -
spacePointsOnTrack[im]->r());
if (bmDeltaR >= m_cfg.deltaRMin && bmDeltaR <= m_cfg.deltaRMax &&
mtDeltaR >= m_cfg.deltaRMin && mtDeltaR <= m_cfg.deltaRMax) {
if ((bmDeltaR + mtDeltaR) > maxDeltaR) {
maxDeltaR = bmDeltaR + mtDeltaR;
bestSPIndices = {ib, im, it};
seedFound = true;
}
mtDeltaR >= m_cfg.deltaRMin && mtDeltaR <= m_cfg.deltaRMax &&
(bmDeltaR + mtDeltaR) > maxDeltaR) {
maxDeltaR = bmDeltaR + mtDeltaR;
bestSPIndices = {ib, im, it};
seedFound = true;
}
}
}
Expand Down
Loading

0 comments on commit eb0c85b

Please sign in to comment.