|
27 | 27 | #include <vector> |
28 | 28 |
|
29 | 29 | #include "algorithms/calorimetry/SimCalorimeterHitProcessorConfig.h" |
| 30 | +#include "MCTools.h" |
30 | 31 |
|
31 | 32 | using namespace dd4hep; |
32 | 33 |
|
@@ -70,35 +71,6 @@ template <> struct hash<std::tuple<edm4hep::MCParticle, uint64_t, int>> { |
70 | 71 |
|
71 | 72 | // unnamed namespace for internal utility |
72 | 73 | namespace { |
73 | | -// Lookup primary MCParticle |
74 | | -// we stop looking if we find the parent has status 1 but with only 2 daughters |
75 | | -// so we don't merge radiative photons with the primary electron as this prevents us |
76 | | -// from properly linking the clusters back to the event geometry. Note that we also |
77 | | -// enforce for this case that no steps back towards the primary were taken to avoid |
78 | | -// storing the first pair of calorimetric showers that start inside the tracking volume. |
79 | | -// Hence, this algorithm will return: |
80 | | -// - Contribution came from primary: primary |
81 | | -// - Contribution came from immediate daughter of primary and has no childern -> daughter |
82 | | -// - All other cases (i.e. early showers, multi-radiation): primary |
83 | | -// |
84 | | -// @TODO this should be a shared utiliy function in the edm4xxx |
85 | | -// libraries |
86 | | -edm4hep::MCParticle lookup_primary(const edm4hep::CaloHitContribution& contrib) { |
87 | | - const auto contributor = contrib.getParticle(); |
88 | | - |
89 | | - edm4hep::MCParticle primary = contributor; |
90 | | - size_t steps_taken = 0; // The number of steps taken looking for the primary |
91 | | - while (primary.parents_size() > 0) { |
92 | | - auto parent = primary.getParents(0); |
93 | | - if (primary.getGeneratorStatus() != 0 || |
94 | | - (parent.getGeneratorStatus() != 0 && parent.daughters_size() == 2 && steps_taken == 0)) { |
95 | | - break; |
96 | | - } |
97 | | - primary = parent; |
98 | | - steps_taken += 1; |
99 | | - } |
100 | | - return primary; |
101 | | -} |
102 | 74 | class HitContributionAccumulator { |
103 | 75 | private: |
104 | 76 | float m_energy{0}; |
@@ -206,7 +178,7 @@ void SimCalorimeterHitProcessor::process(const SimCalorimeterHitProcessor::Input |
206 | 178 | m_attenuationReferencePosition ? get_attenuation(ih.getPosition().z) : 1.; |
207 | 179 | // Use primary particle (traced back through parents) to group contributions |
208 | 180 | for (const auto& contrib : ih.getContributions()) { |
209 | | - edm4hep::MCParticle primary = lookup_primary(contrib); |
| 181 | + edm4hep::MCParticle primary = MCTools::lookup_primary(contrib); |
210 | 182 | const double propagationTime = |
211 | 183 | m_attenuationReferencePosition |
212 | 184 | ? std::abs(m_attenuationReferencePosition.value() - ih.getPosition().z) * |
|
0 commit comments