Skip to content

Commit eeab638

Browse files
authored
PWGHF, RecoDecay: Fix search of mothers to work also at partonic level (#939)
1 parent 1acfd89 commit eeab638

19 files changed

Lines changed: 75 additions & 62 deletions

Common/Core/RecoDecay.h

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -562,62 +562,75 @@ class RecoDecay
562562
}
563563

564564
/// Finds the mother of an MC particle by looking for the expected PDG code in the mother chain.
565+
/// \param particlesMC table with MC particles
565566
/// \param particle MC particle
566567
/// \param PDGMother expected mother PDG code
567568
/// \param acceptAntiParticles switch to accept the antiparticle of the expected mother
568569
/// \param sign antiparticle indicator of the found mother w.r.t. PDGMother; 1 if particle, -1 if antiparticle, 0 if mother not found
569570
/// \param depthMax maximum decay tree level to check; Mothers up to this level will be considered. If -1, all levels are considered.
570571
/// \return index of the mother particle if found, -1 otherwise
571572
template <typename T>
572-
static int getMother(const T& particle,
573+
static int getMother(const T& particlesMC,
574+
const typename T::iterator& particle,
573575
int PDGMother,
574576
bool acceptAntiParticles = false,
575577
int8_t* sign = nullptr,
576578
int8_t depthMax = -1)
577579
{
578-
int8_t sgn = 0; // 1 if the expected mother is particle, -1 if antiparticle (w.r.t. PDGMother)
579-
int indexMother = -1; // index of the final matched mother, if found
580-
auto particleMother = particle; // Initialise loop over mothers.
581-
int stage = 0; // mother tree level (just for debugging)
580+
int8_t sgn = 0; // 1 if the expected mother is particle, -1 if antiparticle (w.r.t. PDGMother)
581+
int indexMother = -1; // index of the final matched mother, if found
582+
int stage = 0; // mother tree level (just for debugging)
583+
bool motherFound = false; // true when the desired mother particle is found in the kine tree
582584
if (sign) {
583585
*sign = sgn;
584586
}
585-
std::vector<int> listId;
586-
listId.push_back(particleMother.globalIndex());
587-
while (particleMother.has_mothers()) {
588-
if (depthMax > -1 && -stage >= depthMax) { // Maximum depth has been reached.
589-
return -1;
590-
}
591-
if (particleMother.mothersIds()[0] == -1) { // Additional check for converted Run 2 MC
592-
return -1;
593-
}
594-
particleMother = particleMother.template mothers_first_as<typename std::decay_t<T>::parent_t>(); // get mother 0
595-
auto indexMotherTmp = particleMother.globalIndex();
596-
// Check mother's PDG code.
597-
auto PDGParticleIMother = particleMother.pdgCode(); // PDG code of the mother
598-
// printf("getMother: ");
599-
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
600-
// printf(" ");
601-
// printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, PDGParticleIMother, indexMotherTmp);
602-
if (std::find(listId.begin(), listId.end(), indexMotherTmp) != listId.end()) {
603-
LOGF(fatal, "Circular mothership at particle index %d", indexMotherTmp);
604-
return -1;
605-
}
606-
listId.push_back(indexMotherTmp);
607-
if (PDGParticleIMother == PDGMother) { // exact PDG match
608-
sgn = 1;
609-
indexMother = indexMotherTmp;
610-
break;
611-
} else if (acceptAntiParticles && PDGParticleIMother == -PDGMother) { // antiparticle PDG match
612-
sgn = -1;
613-
indexMother = indexMotherTmp;
614-
break;
587+
588+
// vector of vectors with mother indices; each line corresponds to a "stage"
589+
std::vector<std::vector<long int>> arrayIds{};
590+
std::vector<long int> initVec{particle.globalIndex()};
591+
arrayIds.push_back(initVec); // the first vector contains the index of the original particle
592+
593+
while (!motherFound && arrayIds[-stage].size() > 0 && (depthMax < 0 || -stage < depthMax)) {
594+
// vector of mother indices for the current stage
595+
std::vector<long int> arrayIdsStage{};
596+
for (auto& iPart : arrayIds[-stage]) { // check all the particles that were the mothers at the previous stage
597+
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
598+
if (particleMother.has_mothers()) {
599+
for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle
600+
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
601+
continue;
602+
}
603+
auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset());
604+
// Check mother's PDG code.
605+
auto PDGParticleIMother = mother.pdgCode(); // PDG code of the mother
606+
// printf("getMother: ");
607+
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
608+
// printf(" ");
609+
// printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, PDGParticleIMother, iMother);
610+
if (PDGParticleIMother == PDGMother) { // exact PDG match
611+
sgn = 1;
612+
indexMother = iMother;
613+
motherFound = true;
614+
break;
615+
} else if (acceptAntiParticles && PDGParticleIMother == -PDGMother) { // antiparticle PDG match
616+
sgn = -1;
617+
indexMother = iMother;
618+
motherFound = true;
619+
break;
620+
}
621+
// add mother index in the vector for the current stage
622+
arrayIdsStage.push_back(iMother);
623+
}
624+
}
615625
}
626+
// add vector of mother indices for the current stage
627+
arrayIds.push_back(arrayIdsStage);
616628
stage--;
617629
}
618630
if (sign) {
619631
*sign = sgn;
620632
}
633+
621634
return indexMother;
622635
}
623636

@@ -723,7 +736,7 @@ class RecoDecay
723736
if (iProng == 0) {
724737
// Get the mother index and its sign.
725738
// PDG code of the first daughter's mother determines whether the expected mother is a particle or antiparticle.
726-
indexMother = getMother(particleI, PDGMother, acceptAntiParticles, &sgn, depthMax);
739+
indexMother = getMother(particlesMC, particleI, PDGMother, acceptAntiParticles, &sgn, depthMax);
727740
// Check whether mother was found.
728741
if (indexMother <= -1) {
729742
//Printf("MC Rec: Rejected: bad mother index or PDG");

EventFiltering/PWGHF/HFFilter.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ struct HfFilter { // Main struct for HF triggers
979979
auto indexRec = RecoDecay::getMatchedMCRec(particlesMC, std::array{trackPos, trackNeg}, pdg::Code::kD0, array{+kPiPlus, -kKPlus}, true, &sign);
980980
if (indexRec > -1) {
981981
auto particle = particlesMC.rawIteratorAt(indexRec);
982-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
982+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
983983
if (origin == OriginType::NonPrompt) {
984984
flag = kNonPrompt;
985985
} else {
@@ -1038,7 +1038,7 @@ struct HfFilter { // Main struct for HF triggers
10381038

10391039
if (indexRec > -1) {
10401040
auto particle = particlesMC.rawIteratorAt(indexRec);
1041-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
1041+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
10421042
if (origin == OriginType::NonPrompt) {
10431043
flag = kNonPrompt;
10441044
} else {

PWGHF/TableProducer/HFCandidateCreator2Prong.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct HFCandidateCreator2ProngExpressions {
210210
// Check whether the particle is non-prompt (from a b quark).
211211
if (flag != 0) {
212212
auto particle = particlesMC.rawIteratorAt(indexRec);
213-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
213+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
214214
}
215215

216216
rowMCMatchRec(flag, origin);
@@ -246,7 +246,7 @@ struct HFCandidateCreator2ProngExpressions {
246246

247247
// Check whether the particle is non-prompt (from a b quark).
248248
if (flag != 0) {
249-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
249+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
250250
}
251251

252252
rowMCMatchGen(flag, origin);

PWGHF/TableProducer/HFCandidateCreator3Prong.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct HFCandidateCreator3ProngExpressions {
251251
// Check whether the particle is non-prompt (from a b quark).
252252
if (flag != 0) {
253253
auto particle = particlesMC.rawIteratorAt(indexRec);
254-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
254+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
255255
}
256256

257257
rowMCMatchRec(flag, origin, swapping, channel);
@@ -305,7 +305,7 @@ struct HFCandidateCreator3ProngExpressions {
305305

306306
// Check whether the particle is non-prompt (from a b quark).
307307
if (flag != 0) {
308-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
308+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
309309
}
310310

311311
rowMCMatchGen(flag, origin, channel);

PWGHF/TableProducer/HFCandidateCreatorChic.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ struct HFCandidateCreatorChicMC {
231231
if (indexRec > -1) {
232232
hMassJpsiToMuMuMatched->Fill(InvMassJpsiToMuMu(candidate.index0()));
233233

234-
int indexMother = RecoDecay::getMother(particlesMC.rawIteratorAt(indexRec), pdg::Code::kChic1);
235-
int indexMotherGamma = RecoDecay::getMother(particlesMC.rawIteratorAt(candidate.index1().mcparticleId()), pdg::Code::kChic1);
234+
int indexMother = RecoDecay::getMother(particlesMC, particlesMC.rawIteratorAt(indexRec), pdg::Code::kChic1);
235+
int indexMotherGamma = RecoDecay::getMother(particlesMC, particlesMC.rawIteratorAt(candidate.index1().mcparticleId()), pdg::Code::kChic1);
236236
if (indexMother > -1 && indexMotherGamma == indexMother && candidate.index1().mcparticle().pdgCode() == kGamma) {
237237
auto particleMother = particlesMC.rawIteratorAt(indexMother);
238238
hEphotonMatched->Fill(candidate.index1().e());
@@ -249,7 +249,7 @@ struct HFCandidateCreatorChicMC {
249249
}
250250
if (flag != 0) {
251251
auto particle = particlesMC.rawIteratorAt(indexRec);
252-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? NonPrompt : Prompt);
252+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? NonPrompt : Prompt);
253253
}
254254
rowMCMatchRec(flag, origin, channel);
255255
}

PWGHF/TableProducer/HFCandidateCreatorX.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ struct HFCandidateCreatorXMC {
305305
// Check whether the particle is non-prompt (from a b quark).
306306
if (flag != 0) {
307307
auto particle = particlesMC.rawIteratorAt(indexRec);
308-
origin = (RecoDecay::getMother(particle, 5, true) > -1 ? NonPrompt : Prompt);
308+
origin = (RecoDecay::getMother(particlesMC, particle, 5, true) > -1 ? NonPrompt : Prompt);
309309
}
310310

311311
rowMCMatchRec(flag, origin, channel);
@@ -338,7 +338,7 @@ struct HFCandidateCreatorXMC {
338338

339339
// Check whether the particle is non-prompt (from a b quark).
340340
if (flag != 0) {
341-
origin = (RecoDecay::getMother(particle, 5, true) > -1 ? NonPrompt : Prompt);
341+
origin = (RecoDecay::getMother(particlesMC, particle, 5, true) > -1 ? NonPrompt : Prompt);
342342
}
343343

344344
rowMCMatchGen(flag, origin, channel);

PWGHF/Tasks/HFMCValidation.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct ValidationGenLevel {
157157
std::size_t arrayPDGsize = arrPDGFinal[iD].size() - std::count(arrPDGFinal[iD].begin(), arrPDGFinal[iD].end(), 0);
158158
int origin = -1;
159159
if (listDaughters.size() == arrayPDGsize) {
160-
origin = (RecoDecay::getMother(particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
160+
origin = (RecoDecay::getMother(particlesMC, particle, kBottom, true) > -1 ? OriginType::NonPrompt : OriginType::Prompt);
161161
if (origin == OriginType::Prompt) {
162162
counterPrompt[iD]++;
163163
} else if (origin == OriginType::NonPrompt) {
@@ -293,7 +293,7 @@ struct ValidationRecLevel {
293293
if (whichHad >= 0 && whichOrigin >= 0) {
294294
int indexParticle = 0;
295295
if (cand2Prong.index0_as<aod::BigTracksMC>().has_mcParticle()) {
296-
indexParticle = RecoDecay::getMother(cand2Prong.index0_as<aod::BigTracksMC>().mcParticle(), PDGArrayParticle[whichHad], true);
296+
indexParticle = RecoDecay::getMother(particlesMC, cand2Prong.index0_as<aod::BigTracksMC>().mcParticle(), PDGArrayParticle[whichHad], true);
297297
}
298298
auto mother = particlesMC.rawIteratorAt(indexParticle);
299299
histDeltaPt[whichHad]->Fill(cand2Prong.pt() - mother.pt());
@@ -358,7 +358,7 @@ struct ValidationRecLevel {
358358
if (whichHad >= 0) {
359359
int indexParticle = 0;
360360
if (cand3Prong.index0_as<aod::BigTracksMC>().has_mcParticle()) {
361-
indexParticle = RecoDecay::getMother(cand3Prong.index0_as<aod::BigTracksMC>().mcParticle(), PDGArrayParticle[whichHad], true);
361+
indexParticle = RecoDecay::getMother(particlesMC, cand3Prong.index0_as<aod::BigTracksMC>().mcParticle(), PDGArrayParticle[whichHad], true);
362362
}
363363
auto mother = particlesMC.rawIteratorAt(indexParticle);
364364
histDeltaPt[whichHad]->Fill(cand3Prong.pt() - mother.pt());

PWGHF/Tasks/taskBPlus.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct HfTaskBplusMc {
182182
}
183183
if (std::abs(candidate.flagMCMatchRec()) == 1 << hf_cand_bplus::DecayType::BPlusToD0Pi) {
184184

185-
auto indexMother = RecoDecay::getMother(candidate.index1_as<aod::BigTracksMC>().mcParticle_as<soa::Join<aod::McParticles, aod::HfCandBPMCGen>>(), pdg::Code::kBPlus, true);
185+
auto indexMother = RecoDecay::getMother(particlesMC, candidate.index1_as<aod::BigTracksMC>().mcParticle_as<soa::Join<aod::McParticles, aod::HfCandBPMCGen>>(), pdg::Code::kBPlus, true);
186186
auto particleMother = particlesMC.rawIteratorAt(indexMother);
187187
registry.fill(HIST("hPtGenSig"), particleMother.pt());
188188
registry.fill(HIST("hPtRecSig"), candidate.pt());

PWGHF/Tasks/taskChic.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct TaskChicMC {
165165
}
166166
if (candidate.flagMCMatchRec() == 1 << decayMode) {
167167
//FIXME the access to the MC particle gen not yet functional
168-
//int indexMother = RecoDecay::getMother(particlesMC.rawIteratorAt(candidate.index1().mcParticle_as<aod::McParticles_000>().globalIndex()), 20443);
168+
//int indexMother = RecoDecay::getMother(particlesMC, particlesMC.rawIteratorAt(candidate.index1().mcParticle_as<aod::McParticles_000>().globalIndex()), 20443);
169169
//auto particleMother = particlesMC.rawIteratorAt(indexMother);
170170
//registry.fill(HIST("hPtGenSig"), particleMother.pt());
171171
registry.fill(HIST("hPtRecSig"), candidate.pt());

PWGHF/Tasks/taskD0.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct TaskD0 {
182182
}
183183
if (std::abs(candidate.flagMCMatchRec()) == 1 << DecayType::D0ToPiK) {
184184
// Get the corresponding MC particle.
185-
auto indexMother = RecoDecay::getMother(candidate.index0_as<aod::BigTracksMC>().mcParticle_as<soa::Join<aod::McParticles, aod::HfCandProng2MCGen>>(), pdg::Code::kD0, true);
185+
auto indexMother = RecoDecay::getMother(particlesMC, candidate.index0_as<aod::BigTracksMC>().mcParticle_as<soa::Join<aod::McParticles, aod::HfCandProng2MCGen>>(), pdg::Code::kD0, true);
186186
auto particleMother = particlesMC.rawIteratorAt(indexMother);
187187
registry.fill(HIST("hPtGenSig"), particleMother.pt()); // gen. level pT
188188
auto ptRec = candidate.pt();

0 commit comments

Comments
 (0)