diff --git a/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx b/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx index 143bf64e50b..a114191cc9f 100644 --- a/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx +++ b/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx @@ -67,6 +67,7 @@ #include #include +#include #include #include #include @@ -496,6 +497,44 @@ struct HfProducerCharmHadronsTrackFemtoDream { -999., -999., -999.); } + // Strong-decay kaons may be physical primaries, so inspect phi ancestry first. + template + static bool hasPhiAncestor(T const& particles, typename T::iterator const& particle) + { + std::vector pending; + std::vector visited{particle.globalIndex()}; + if (particle.has_mothers()) { + for (const auto id : particle.mothersIds()) { + pending.push_back(id); + } + } + while (!pending.empty()) { + const auto id = pending.back(); + pending.pop_back(); + if (id < static_cast(particles.offset()) || + id - static_cast(particles.offset()) >= static_cast(particles.size()) || + std::find(visited.begin(), visited.end(), id) != visited.end()) { + continue; + } + visited.push_back(id); + const auto mother = particles.rawIteratorAt(id - particles.offset()); + const int absPdg = std::abs(mother.pdgCode()); + if (absPdg == 333) { + return true; + } + // Stop at the partonic boundary of the hadron decay chain. + if (absPdg <= 100 || RecoDecay::isDiquark(absPdg)) { + continue; + } + if (mother.has_mothers()) { + for (const auto parentId : mother.mothersIds()) { + pending.push_back(parentId); + } + } + } + return false; + } + /// Classify true kaons from the correct collision for the DCA templates. template static int getKaonOrigin(T const& particles, typename T::iterator const& particle) @@ -509,6 +548,10 @@ struct HfProducerCharmHadronsTrackFemtoDream { if (RecoDecay::getParticleOrigin(particles, particle) != RecoDecay::OriginType::None) { return kSecondaryFromHF; } + // Keep HF -> phi -> K in HF + if (hasPhiAncestor(particles, particle)) { + return kSecondaryFromPhi; + } if (particle.isPhysicalPrimary()) { return kPrimary; }