@@ -73,20 +73,29 @@ namespace {
7373// Lookup primary MCParticle
7474// we stop looking if we find the parent has status 1 but with only 2 daughters
7575// 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
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+ //
7784// @TODO this should be a shared utiliy function in the edm4xxx
7885// libraries
7986edm4hep::MCParticle lookup_primary (const edm4hep::CaloHitContribution& contrib) {
8087 const auto contributor = contrib.getParticle ();
8188
8289 edm4hep::MCParticle primary = contributor;
90+ size_t steps_taken = 0 ; // The number of steps taken looking for the primary
8391 while (primary.parents_size () > 0 ) {
8492 auto parent = primary.getParents (0 );
8593 if (primary.getGeneratorStatus () != 0 ||
86- (parent.getGeneratorStatus () != 0 && parent.daughters_size () == 2 )) {
94+ (parent.getGeneratorStatus () != 0 && parent.daughters_size () == 2 && steps_taken == 0 )) {
8795 break ;
8896 }
8997 primary = parent;
98+ steps_taken += 1 ;
9099 }
91100 return primary;
92101}
0 commit comments