Skip to content

Commit 8a51c07

Browse files
authored
[Common] Allow stopping before reaching partonic level in RecoDecay::getMother (#17816)
1 parent 41b3ae1 commit 8a51c07

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

Common/Core/RecoDecay.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,16 @@ struct RecoDecay {
569569
/// \param acceptAntiParticles switch to accept the antiparticle of the expected mother
570570
/// \param sign antiparticle indicator of the found mother w.r.t. pdgMother; 1 if particle, -1 if antiparticle, 0 if mother not found
571571
/// \param depthMax maximum decay tree level to check; Mothers up to this level will be considered. If -1, all levels are considered.
572+
/// \param searchUpToQuark switch to stop searching for mothers when a quark or boson is found
572573
/// \return index of the mother particle if found, -1 otherwise
573574
template <bool acceptFlavourOscillation = false, typename T>
574575
static int getMother(const T& particlesMC,
575576
const typename T::iterator& particle,
576577
int pdgMother,
577578
bool acceptAntiParticles = false,
578579
int8_t* sign = nullptr,
579-
int8_t depthMax = -1)
580+
int8_t depthMax = -1,
581+
const bool searchUpToQuark = true)
580582
{
581583
int8_t sgn = 0; // 1 if the expected mother is particle, -1 if antiparticle (w.r.t. pdgMother)
582584
int indexMother = -1; // index of the final matched mother, if found
@@ -597,13 +599,18 @@ struct RecoDecay {
597599
for (auto iPart : arrayIds[-stage]) { // check all the particles that were the mothers at the previous stage, o2-linter: disable=const-ref-in-for-loop (int elements)
598600
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
599601
if (particleMother.has_mothers()) {
600-
for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle
601-
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
602+
// If searchUpToQuark is false we only take the first mother (since decay products only have one mother)
603+
auto lastMotherIdxToCheck = searchUpToQuark ? particleMother.mothersIds().back() : particleMother.mothersIds().front();
604+
for (auto iMother = particleMother.mothersIds().front(); iMother <= lastMotherIdxToCheck; ++iMother) { // loop over the mother particles of the analysed particle
605+
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
602606
continue;
603607
}
604608
auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset());
605609
// Check mother's PDG code.
606610
auto pdgParticleIMother = mother.pdgCode(); // PDG code of the mother
611+
if (!searchUpToQuark && (std::abs(pdgParticleIMother) <= PdgQuarkMax || (std::abs(pdgParticleIMother) >= PdgBosonMin && std::abs(pdgParticleIMother) <= PdgBosonMax))) {
612+
continue;
613+
}
607614
// printf("getMother: ");
608615
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
609616
// printf(" ");
@@ -729,6 +736,7 @@ struct RecoDecay {
729736
/// \param nPiToMu number of pion prongs decayed to a muon
730737
/// \param nKaToPi number of kaon prongs decayed to a pion
731738
/// \param nInteractionsWithMaterial number of daughter particles that interacted with material
739+
/// \param searchUpToQuark switch to search for the decay up to the quark level
732740
/// \return index of the mother particle if the mother and daughters are correct, -1 otherwise
733741
template <bool acceptFlavourOscillation = false, bool checkProcess = false, bool acceptIncompleteReco = false, bool acceptTrackDecay = false, bool acceptTrackIntWithMaterial = false, std::size_t N, typename T, typename U>
734742
static int getMatchedMCRec(const T& particlesMC,
@@ -740,7 +748,8 @@ struct RecoDecay {
740748
int depthMax = 1,
741749
int8_t* nPiToMu = nullptr,
742750
int8_t* nKaToPi = nullptr,
743-
int8_t* nInteractionsWithMaterial = nullptr)
751+
int8_t* nInteractionsWithMaterial = nullptr,
752+
bool searchUpToQuark = true)
744753
{
745754
// Printf("MC Rec: Expected mother PDG: %d", pdgMother);
746755
int8_t coefFlavourOscillation = 1; // 1 if no B0(s) flavour oscillation occured, -1 else
@@ -815,7 +824,7 @@ struct RecoDecay {
815824
if (iProng == 0) {
816825
// Get the mother index and its sign.
817826
// PDG code of the first daughter's mother determines whether the expected mother is a particle or antiparticle.
818-
indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax);
827+
indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax, searchUpToQuark);
819828
// Check whether mother was found.
820829
if (indexMother <= -1) {
821830
// Printf("MC Rec: Rejected: bad mother index or PDG");

0 commit comments

Comments
 (0)