Skip to content

Commit b9f268d

Browse files
authored
Don't forget unattenuated energy and restore discarded sim variables in SimCalorimeterHitProcessor (#2198)
### Briefly, what does this PR introduce? This PR does addresses two issues in SimCalorimeterHitProcessor: 1. The unattenuated energy is necessary to benchmark e.g. clustering algorithm performance, or to train AI algorithms. While it was originally foreseen to be available through 2-step simulated hit processor, but was then not added once we combined both steps for performance reasons. 2. Some variables in the SimCalorimeterHit were silently removed in #2076 as they were deemed "not needed". However, this was not documented, and leaves the actual SimCalorimeterHits that we use for our digi/reco in a partially filled state with some information irretrievably lost. I addressed the issues as follows 1. Keep track of the unattenuated energy and store it with the contribution members of the SimCalorimeterHit so it can still be accessed. It means that SimCalorimeterHit.energy/sum(contribution.energies) equals the effective attenuation. 2. Restored the discarded PID/position.xyz/... fields ### What kind of change does this PR introduce? - [X] Bug fix (issue #__) - [X] New feature (issue #__) - [ ] Documentation update - [ ] Other: __ ### Please check if this PR fulfills the following: - [ ] Tests for the changes have been added - [ ] Documentation has been added / updated - [ ] Changes have been communicated to collaborators ### Does this PR introduce breaking changes? What changes might users need to make to their code? ### Does this PR change default behavior?
1 parent be68024 commit b9f268d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/algorithms/calorimetry/SimCalorimeterHitProcessor.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,22 @@ edm4hep::MCParticle lookup_primary(const edm4hep::CaloHitContribution& contrib)
8787
class HitContributionAccumulator {
8888
private:
8989
float m_energy{0};
90+
float m_att_energy{0};
9091
float m_avg_time{0};
9192
float m_min_time{std::numeric_limits<float>::max()};
9293
edm4hep::Vector3f m_avg_position{0, 0, 0};
9394

9495
public:
95-
void add(const float energy, const float time, const edm4hep::Vector3f& pos) {
96+
void add(const float energy, const float attFactor, const float time,
97+
const edm4hep::Vector3f& pos) {
9698
m_energy += energy;
99+
m_att_energy += energy * attFactor;
97100
m_avg_time += energy * time;
98101
m_avg_position = m_avg_position + energy * pos;
99102
m_min_time = (time < m_min_time) ? time : m_min_time;
100103
}
101104
float getEnergy() const { return m_energy; }
105+
float getAttEnergy() const { return m_att_energy; }
102106
float getAvgTime() const { return m_energy > 0 ? m_avg_time / m_energy : 0; }
103107
float getMinTime() const { return m_min_time; }
104108
edm4hep::Vector3f getAvgPosition() const {
@@ -200,7 +204,7 @@ void SimCalorimeterHitProcessor::process(const SimCalorimeterHitProcessor::Input
200204
const double totalTime = contrib.getTime() + propagationTime + m_cfg.fixedTimeDelay;
201205
const int newhit_timeID = std::floor(totalTime / m_cfg.timeWindow);
202206
auto& hit_accum = hit_map[{primary, newhit_cellID, newhit_timeID}][newcontrib_cellID];
203-
hit_accum.add(contrib.getEnergy() * attFactor, totalTime, ih.getPosition());
207+
hit_accum.add(contrib.getEnergy(), attFactor, totalTime, ih.getPosition());
204208
}
205209
}
206210

@@ -213,18 +217,21 @@ void SimCalorimeterHitProcessor::process(const SimCalorimeterHitProcessor::Input
213217
const auto& [particle, cellID, timeID] = hit_idx;
214218
HitContributionAccumulator new_hit;
215219
for (const auto& [contrib_idx, contrib] : contribs) {
216-
// Aggregate contributions to for the global hit
217-
new_hit.add(contrib.getEnergy(), contrib.getMinTime(), contrib.getAvgPosition());
220+
// Aggregate contributions to for the global hit; use effective "attenuation"
221+
new_hit.add(contrib.getEnergy(), contrib.getAttEnergy() / contrib.getEnergy(),
222+
contrib.getMinTime(), contrib.getAvgPosition());
218223
// Now store the contribution itself
219224
auto out_hit_contrib = out_hit_contribs->create();
225+
out_hit_contrib.setPDG(particle.getPDG());
226+
out_hit_contrib.setEnergy(contrib.getEnergy()); // UNattenuated energy
220227
out_hit_contrib.setTime(contrib.getMinTime());
221-
out_hit_contrib.setStepPosition(edm4hep::Vector3f{0, 0, contrib.getAvgPosition().z});
228+
out_hit_contrib.setStepPosition(contrib.getAvgPosition());
222229
out_hit_contrib.setParticle(particle);
223230
out_hit.addToContributions(out_hit_contrib);
224231
}
225232
out_hit.setCellID(cellID);
226-
out_hit.setEnergy(new_hit.getEnergy());
227-
out_hit.setPosition(edm4hep::Vector3f{0, 0, new_hit.getAvgPosition().z});
233+
out_hit.setEnergy(new_hit.getAttEnergy()); // sum of attenuated energies
234+
out_hit.setPosition(new_hit.getAvgPosition());
228235
}
229236
}
230237

0 commit comments

Comments
 (0)