Skip to content

Commit 7e1ea1e

Browse files
andiwandnjacazio
authored andcommitted
fix: Merge cells to unique set before clustering in Examples (acts-project#4759)
As discovered in acts-project#4745 and acts-project#4736, cells are not merged correctly right now. This PR fixes the merging by using a `std::map` intermediately and adding up the activations.
1 parent e75108a commit 7e1ea1e

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

Examples/Algorithms/Digitization/include/ActsExamples/Digitization/ModuleClusters.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include "Acts/Clusterization/Clusterization.hpp"
12-
#include "Acts/Definitions/Algebra.hpp"
1312
#include "Acts/Definitions/TrackParametrization.hpp"
1413
#include "Acts/Utilities/BinUtility.hpp"
1514
#include "ActsExamples/Digitization/MeasurementCreation.hpp"

Examples/Algorithms/Digitization/src/ModuleClusters.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
#include "Acts/Clusterization/Clusterization.hpp"
1212
#include "Acts/Utilities/Helpers.hpp"
1313
#include "ActsExamples/Digitization/MeasurementCreation.hpp"
14-
#include "ActsFatras/Digitization/Channelizer.hpp"
1514

1615
#include <array>
1716
#include <cmath>
18-
#include <cstdint>
1917
#include <cstdlib>
2018
#include <limits>
21-
#include <memory>
19+
#include <map>
2220
#include <stdexcept>
23-
#include <type_traits>
2421

2522
namespace ActsExamples {
2623

@@ -88,11 +85,26 @@ void clusterAddCell(std::vector<ModuleValue>& cl, const ModuleValue& ce) {
8885
}
8986

9087
std::vector<ModuleValue> ModuleClusters::createCellCollection() {
91-
std::vector<ModuleValue> cells;
92-
for (ModuleValue& mval : m_moduleValues) {
93-
if (std::holds_alternative<Cluster::Cell>(mval.value)) {
94-
cells.push_back(mval);
88+
std::map<ActsFatras::Segmentizer::Bin2D, ModuleValue> uniqueCells;
89+
for (const ModuleValue& mval : m_moduleValues) {
90+
if (!std::holds_alternative<Cluster::Cell>(mval.value)) {
91+
continue;
9592
}
93+
const auto& cell = std::get<ActsExamples::Cluster::Cell>(mval.value).bin;
94+
95+
if (const auto it = uniqueCells.find(cell); it != uniqueCells.end()) {
96+
// Cell already exists, so merge the hit sources
97+
std::get<Cluster::Cell>(it->second.value).activation +=
98+
std::get<Cluster::Cell>(mval.value).activation;
99+
} else {
100+
// New cell
101+
uniqueCells[cell] = mval;
102+
}
103+
}
104+
std::vector<ModuleValue> cells;
105+
cells.reserve(uniqueCells.size());
106+
for (const auto& [_, mval] : uniqueCells) {
107+
cells.push_back(mval);
96108
}
97109
return cells;
98110
}

Fatras/include/ActsFatras/Digitization/Segmentizer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ struct Segmentizer {
6868
/// The bin of this segment
6969
Bin2D bin = {0, 0};
7070
/// The segment start, end points
71-
Segment2D path2D;
71+
Segment2D path2D = {Acts::Vector2::Zero(), Acts::Vector2::Zero()};
7272
/// The (clipped) value (uncorrected: path length)
73-
double activation = 0.;
73+
double activation = 0;
7474

7575
/// Constructor with arguments
7676
///

0 commit comments

Comments
 (0)