Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EDM4hepReader sets number of hits on particles #4056

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Examples/Io/EDM4hep/src/EDM4hepReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) {
// container
std::unordered_map<int, std::size_t> edm4hepParticleMap;

std::size_t nGeneratorParticles = 0;

std::size_t nPrimaryVertices = 0;
// Walk the particle tree
for (const auto& [vtxPos, particles] : primaryVertices) {
Expand All @@ -215,6 +217,11 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) {
.withParticleId(SimBarcode{}
.setParticle(nParticles)
.setVertexPrimary(nPrimaryVertices));

if (!inParticle.isCreatedInSimulation()) {
nGeneratorParticles += 1;
}

ACTS_VERBOSE("+ add particle " << particle);
ACTS_VERBOSE(" - at " << particle.position().transpose());
ACTS_VERBOSE(" - createdInSim: " << inParticle.isCreatedInSimulation());
Expand Down Expand Up @@ -243,9 +250,10 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) {
ACTS_DEBUG("Found " << unorderedParticlesInitial.size() << " particles");

std::vector<SimParticle> particlesGeneratorUnordered;
particlesGeneratorUnordered.reserve(mcParticleCollection.size());
particlesGeneratorUnordered.reserve(nGeneratorParticles);
std::vector<SimParticle> particlesSimulatedUnordered;
particlesSimulatedUnordered.reserve(mcParticleCollection.size());
particlesSimulatedUnordered.reserve(mcParticleCollection.size() -
nGeneratorParticles);

for (const auto& inParticle : mcParticleCollection) {
auto particleIt = edm4hepParticleMap.find(inParticle.getObjectID().index);
Expand Down Expand Up @@ -370,6 +378,17 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) {
return surface->geometryId();
});

// Increase hit count in generated and simulated particles
if (auto itSim = particlesSimulated.find(simHit.particleId());
itSim != particlesSimulated.end()) {
itSim->final().setNumberOfHits(itSim->final().numberOfHits() + 1);
} else if (auto itGen = particlesGenerator.find(simHit.particleId());
itGen != particlesGenerator.end()) {
itGen->final().setNumberOfHits(itGen->final().numberOfHits() + 1);
} else {
ACTS_ERROR("SimHit has source particle that we did not see before");
}
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved

simHitsUnordered.push_back(std::move(simHit));
}
}
Expand Down
Loading