Skip to content

Commit

Permalink
loops
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Sep 19, 2024
1 parent 7f62258 commit 658bcb8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Core/src/Detector/detail/CuboidalDetectorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Acts::Experimental::detail::CuboidalDetectorHelper::xyzBoundaries(
}

for (auto [im, map] : enumerate(valueMaps)) {
for (auto [key, value] : map) {
for (auto [key, _] : map) {
boundaries[im].push_back(key);
}
std::ranges::sort(boundaries[im]);
Expand Down
6 changes: 3 additions & 3 deletions Core/src/Material/BinnedSurfaceMaterialAccumulater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void Acts::BinnedSurfaceMaterialAccumulater::accumulate(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
tmapBin.first->trackAverage(trackBins, true);
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
key->trackAverage(trackBins, true);
}

// Empty bin correction
Expand Down
20 changes: 10 additions & 10 deletions Core/src/Material/SurfaceMaterialMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,19 @@ void Acts::SurfaceMaterialMapper::mapInteraction(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
if (m_cfg.computeVariance) {
// This only makes sense for the binned material
auto binnedMaterial = dynamic_cast<const BinnedSurfaceMaterial*>(
touchedMaterialBin[tmapBin.first].get());
touchedMaterialBin[key].get());
if (binnedMaterial != nullptr) {
tmapBin.first->trackVariance(
key->trackVariance(
trackBins,
binnedMaterial->fullMaterial()[trackBins[0][1]][trackBins[0][0]]);
}
}
tmapBin.first->trackAverage(trackBins);
key->trackAverage(trackBins);
}

// After mapping this track, average the untouched but intersected bins
Expand Down Expand Up @@ -498,21 +498,21 @@ void Acts::SurfaceMaterialMapper::mapSurfaceInteraction(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
if (m_cfg.computeVariance) {
// This only makes sense for the binned material
auto binnedMaterial = dynamic_cast<const BinnedSurfaceMaterial*>(
touchedMaterialBin[tmapBin.first].get());
touchedMaterialBin[key].get());
if (binnedMaterial != nullptr) {
tmapBin.first->trackVariance(
key->trackVariance(
trackBins,
binnedMaterial->fullMaterial()[trackBins[0][1]][trackBins[0][0]],
true);
}
}
// No need to do an extra pass for untouched surfaces they would have been
// added to the material interaction in the initial mapping
tmapBin.first->trackAverage(trackBins, true);
key->trackAverage(trackBins, true);
}
}
16 changes: 8 additions & 8 deletions Core/src/TrackFinding/AmbiguityTrackClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ Acts::detail::clusterDuplicateTracks(
std::unordered_map<std::size_t, std::size_t> hitToTrack;

// Loop over all the tracks
for (auto track = trackMap.rbegin(); track != trackMap.rend(); ++track) {
std::vector<std::size_t> hits = track->second.second;
for (const auto& [_, trackValue] : trackMap) {
std::vector<std::size_t> hits = trackValue.second;
auto matchedTrack = hitToTrack.end();
// Loop over all the hits in the track
for (auto hit = hits.begin(); hit != hits.end(); hit++) {
for (const auto& hit : hits) {
// Check if the hit is already associated to a track
matchedTrack = hitToTrack.find(*hit);
matchedTrack = hitToTrack.find(hit);
if (matchedTrack != hitToTrack.end()) {
// Add the track to the cluster associated to the matched track
cluster.at(matchedTrack->second).push_back(track->second.first);
cluster.at(matchedTrack->second).push_back(trackValue.first);
break;
}
}
// None of the hits have been matched to a track create a new cluster
if (matchedTrack == hitToTrack.end()) {
cluster.emplace(track->second.first,
std::vector<std::size_t>(1, track->second.first));
cluster.emplace(trackValue.first,
std::vector<std::size_t>(1, trackValue.first));
for (const auto& hit : hits) {
// Add the hits of the new cluster to the hitToTrack
hitToTrack.emplace(hit, track->second.first);
hitToTrack.emplace(hit, trackValue.first);
}
}
}
Expand Down
48 changes: 18 additions & 30 deletions Core/src/TrackFinding/GbtsConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
// TODO: update to C++17 style
#include "Acts/TrackFinding/GbtsConnector.hpp"

#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <ranges>
#include <set>
#include <unordered_map>

Expand Down Expand Up @@ -57,15 +59,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
continue;
}

std::map<int, std::vector<GbtsConnection *>>::iterator it =
m_connMap.find(stage);

if (it == m_connMap.end()) {
std::vector<GbtsConnection *> v(1, pC);
m_connMap.insert(std::make_pair(stage, v));
} else {
(*it).second.push_back(pC);
}
auto &connections = m_connMap[stage];
connections.push_back(pC);
}

// re-arrange the connection stages
Expand All @@ -74,9 +69,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

std::map<int, std::vector<const GbtsConnection *>> newConnMap;

for (const auto &conn : m_connMap) {
std::copy(conn.second.begin(), conn.second.end(),
std::back_inserter(lConns));
for (const auto &[_, value] : m_connMap) {
std::ranges::copy(value, std::back_inserter(lConns));
}

int stageCounter = 0;
Expand Down Expand Up @@ -111,19 +105,19 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

std::set<unsigned int> zeroLayers;

for (const auto &layerCounts : mCounter) {
if (layerCounts.second.second != 0) {
for (const auto &[key, value] : mCounter) {
if (value.second != 0) {
continue;
}

zeroLayers.insert(layerCounts.first);
zeroLayers.insert(key);
}

// remove connections which use zeroLayer as destination

std::vector<const GbtsConnection *> theStage;

std::list<const GbtsConnection *>::iterator cIt = lConns.begin();
auto cIt = lConns.begin();

while (cIt != lConns.end()) {
if (zeroLayers.find((*cIt)->m_dst) !=
Expand All @@ -145,10 +139,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
// the doublet making is done using "outside-in" approach hence the reverse
// iterations

for (std::map<int, std::vector<const GbtsConnection *>>::reverse_iterator it =
newConnMap.rbegin();
it != newConnMap.rend(); ++it, currentStage++) {
const std::vector<const GbtsConnection *> &vConn = (*it).second;
for (const auto &[_, vConn] : std::ranges::reverse_view(newConnMap)) {
currentStage++;

// loop over links, extract all connections for the stage, group sources by
// L1 (dst) index
Expand All @@ -158,8 +150,7 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
for (const auto *conn : vConn) {
unsigned int dst = conn->m_dst;

std::map<unsigned int, std::vector<const GbtsConnection *>>::iterator
l1MapIt = l1ConnMap.find(dst);
auto l1MapIt = l1ConnMap.find(dst);
if (l1MapIt != l1ConnMap.end()) {
(*l1MapIt).second.push_back(conn);
} else {
Expand All @@ -172,8 +163,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

lgv.reserve(l1ConnMap.size());

for (const auto &l1Group : l1ConnMap) {
lgv.push_back(LayerGroup(l1Group.first, l1Group.second));
for (const auto &[key, value] : l1ConnMap) {
lgv.push_back(LayerGroup(key, value));
}

m_layerGroups.insert(std::make_pair(currentStage, lgv));
Expand All @@ -184,12 +175,9 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

GbtsConnector::~GbtsConnector() {
m_layerGroups.clear();
for (std::map<int, std::vector<GbtsConnection *>>::iterator it =
m_connMap.begin();
it != m_connMap.end(); ++it) {
for (std::vector<GbtsConnection *>::iterator cIt = (*it).second.begin();
cIt != (*it).second.end(); ++cIt) {
delete (*cIt);
for (auto &[_, connections] : m_connMap) {
for (auto *conn : connections) {
delete conn;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Core/src/Vertexing/AdaptiveMultiVertexFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ Result<void> AdaptiveMultiVertexFinder::deleteLastVertex(
return removeResult.error();
}

for (auto& entry : fitterState.tracksAtVerticesMap) {
for (auto& [key, value] : fitterState.tracksAtVerticesMap) {
// Delete all linearized tracks for current (bad) vertex
if (entry.first.second == &vtx) {
entry.second.isLinearized = false;
if (key.second == &vtx) {
value.isLinearized = false;
}
}

Expand Down
15 changes: 9 additions & 6 deletions Examples/Framework/src/Validation/TrackClassification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ void ActsExamples::identifyContributingParticles(

for (auto hitIndex : protoTrack) {
// register all particles that generated this hit
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
}
sortHitCount(particleHitCounts);
Expand All @@ -80,8 +81,9 @@ void ActsExamples::identifyContributingParticles(
IndexSourceLink sl =
state.getUncalibratedSourceLink().template get<IndexSourceLink>();
auto hitIndex = sl.index();
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
return true;
});
Expand All @@ -103,8 +105,9 @@ void ActsExamples::identifyContributingParticles(
IndexSourceLink sl =
state.getUncalibratedSourceLink().template get<IndexSourceLink>();
auto hitIndex = sl.index();
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
}
sortHitCount(particleHitCounts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ std::pair<std::vector<float>, std::vector<std::uint32_t>> buildMap(
}

/// @brief This method builds decomposed cumulative probability distributions
/// out of a vector of proability distributions
/// out of a vector of probability distributions
///
/// @param [in] histos Vector of probability distributions
///
Expand Down Expand Up @@ -410,35 +410,35 @@ ActsExamples::RootNuclearInteractionParametersWriter::finalize() {
gDirectory->WriteObject(&mapNIprob.second, "NuclearInteractionBinContents");
ACTS_DEBUG("Nuclear interaction probability parametrised");

ACTS_DEBUG("Starting calulcation of probability of interaction type");
// Write the interaction type proability
ACTS_DEBUG("Starting calculation of probability of interaction type");
// Write the interaction type probability
const auto softProbability =
Parametrisation::softProbability(m_eventFractionCollection);

gDirectory->WriteObject(&softProbability, "SoftInteraction");
ACTS_DEBUG("Calulcation of probability of interaction type finished");
ACTS_DEBUG("Calculation of probability of interaction type finished");

// Write the PDG id production distribution
ACTS_DEBUG(
"Starting calulcation of transition probabilities between PDG IDs");
"Starting calculation of transition probabilities between PDG IDs");
const auto pdgIdMap =
Parametrisation::cumulativePDGprobability(m_eventFractionCollection);
std::vector<int> branchingPdgIds;
std::vector<int> targetPdgIds;
std::vector<float> targetPdgProbability;
for (const auto& targetPdgIdMap : pdgIdMap) {
for (const auto& producedPdgIdMap : targetPdgIdMap.second) {
branchingPdgIds.push_back(targetPdgIdMap.first);
targetPdgIds.push_back(producedPdgIdMap.first);
targetPdgProbability.push_back(producedPdgIdMap.second);
for (const auto& [targetKey, targetValue] : pdgIdMap) {
for (const auto& [producedKey, producedValue] : targetValue) {
branchingPdgIds.push_back(targetKey);
targetPdgIds.push_back(producedKey);
targetPdgProbability.push_back(producedValue);
}
}

gDirectory->WriteObject(&branchingPdgIds, "BranchingPdgIds");
gDirectory->WriteObject(&targetPdgIds, "TargetPdgIds");
gDirectory->WriteObject(&targetPdgProbability, "TargetPdgProbability");
ACTS_DEBUG(
"Calulcation of transition probabilities between PDG IDs finished");
"Calculation of transition probabilities between PDG IDs finished");

// Write the multiplicity and kinematics distribution
ACTS_DEBUG("Starting parametrisation of multiplicity probabilities");
Expand Down
8 changes: 4 additions & 4 deletions Plugins/Json/src/MaterialMapJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson(
VolumeMaterialMap volumeMap = maps.second;
std::vector<std::pair<GeometryIdentifier, const IVolumeMaterial*>>
mapVolumeInit;
for (auto it = volumeMap.begin(); it != volumeMap.end(); it++) {
mapVolumeInit.push_back({it->first, it->second.get()});
for (const auto& [key, value] : volumeMap) {
mapVolumeInit.push_back({key, value.get()});
}
GeometryHierarchyMap<const IVolumeMaterial*> hierarchyVolumeMap(
mapVolumeInit);
Expand All @@ -263,8 +263,8 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson(
SurfaceMaterialMap surfaceMap = maps.first;
std::vector<std::pair<GeometryIdentifier, const ISurfaceMaterial*>>
mapSurfaceInit;
for (auto it = surfaceMap.begin(); it != surfaceMap.end(); it++) {
mapSurfaceInit.push_back({it->first, it->second.get()});
for (const auto& [key, value] : surfaceMap) {
mapSurfaceInit.push_back({key, value.get()});
}
GeometryHierarchyMap<const ISurfaceMaterial*> hierarchySurfaceMap(
mapSurfaceInit);
Expand Down

0 comments on commit 658bcb8

Please sign in to comment.