Skip to content

Commit b133cb7

Browse files
committed
Move functions to creators
1 parent 8bdb5fb commit b133cb7

File tree

7 files changed

+483
-266
lines changed

7 files changed

+483
-266
lines changed

PWGHF/Core/CorrelatedBkgs.h

Lines changed: 312 additions & 232 deletions
Large diffs are not rendered by default.

PWGHF/DataModel/CandidateReconstructionTables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //!
748748
DECLARE_SOA_TABLE(HfCand2ProngMcGen, "AOD", "HFCAND2PMCGEN", //!
749749
hf_cand_2prong::FlagMcMatchGen,
750750
hf_cand_2prong::OriginMcGen,
751-
hf_cand_2prong::FlagMcDecayChanRec,
751+
hf_cand_2prong::FlagMcDecayChanGen,
752752
hf_cand::IdxBhadMotherPart);
753753

754754
// cascade decay candidate table

PWGHF/TableProducer/candidateCreator2Prong.cxx

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,79 @@ struct HfCandidateCreator2ProngExpressions {
772772

773773
if (matchCorrBkgs) {
774774
LOG(info) << "--------------------------------------------";
775-
LOG(info) << "Matching correlated bkgs of " << Pdg::kD0;
775+
LOG(info) << "Matching correlated bkgs";
776+
indexRec = -1; // Index of the matched reconstructed candidate
777+
std::vector<int> arrResoDaughIndex = {};
778+
// const std::unordered_map<int, std::vector<int>>* finalStates = nullptr;
779+
// switch (pdgMother) {
780+
// case Pdg::kD0:
781+
// finalStates = reinterpret_cast<const std::unordered_map<int, std::vector<int>>*>(&finalStates2Prongs);
782+
// break;
783+
// default:
784+
// finalStates = reinterpret_cast<const std::unordered_map<int, std::vector<int>>*>(&finalStates3Prongs);
785+
// break;
786+
// }
787+
788+
int depth = 2;
789+
for (const auto& [chn, finalState] : finalStates2Prongs) {
790+
std::array<int, 2> finalStateParts2Prong = std::array{finalState[0], finalState[1]};
791+
if (finalState.size() == 3) { // Partly Reco 2-prong decays
792+
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
793+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
794+
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
795+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks);
796+
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
797+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, false, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial);
798+
} else {
799+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, false, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth);
800+
}
801+
802+
if (indexRec != -1) {
803+
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
804+
std::array<int, 3> finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]};
805+
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) {
806+
indexRec = -1; // Reset indexRec if the generated decay
807+
}
808+
}
809+
} else if (finalState.size() == 2) { // Fully Reco 2-prong decays
810+
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
811+
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
812+
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
813+
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks);
814+
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
815+
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial);
816+
} else {
817+
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth);
818+
}
819+
} else {
820+
LOG(info) << "Final state size not supported: " << finalStateParts2Prong.size();
821+
continue; // Skip unsupported final states
822+
}
823+
if (indexRec > -1) {
824+
// std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl;
825+
flag = sign * (chn + 10); // Only D0 decay channels are considered here
826+
827+
// Flag the resonant decay channel
828+
int resoMaxDepth = 1;
829+
int NDaughtersResonant = 2;
830+
RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth);
831+
std::vector<int> arrPDGDaugh = {};
832+
if (arrResoDaughIndex.size() == NDaughtersResonant) {
833+
for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) {
834+
auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]);
835+
arrPDGDaugh.push_back(std::abs(daughI.pdgCode()));
836+
}
837+
flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh);
838+
// LOG(info) << "[matchFinalStateCorrBkgs] Matched D0 final state: " << chn << ", flag: " << static_cast<int>(flag) << ", &sign: " << static_cast<int>(sign);
839+
// LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast<int>(flag) << " sign: " << static_cast<int>(sign) << " for channel: " << static_cast<int>(channel);
840+
}
841+
break; // Exit loop if a match is found
842+
}
843+
}
844+
LOG(info) << "D0 matching ended with flag " << static_cast<int>(flag) << " and indexRec " << static_cast<int>(indexRec) << ", &sign " << static_cast<int>(sign) << ", channel " << static_cast<int>(channel);
845+
846+
// LOG(info) << "--------------------------------------------";
847+
// LOG(info) << "Matching correlated bkgs of " << Pdg::kD0;
776848
// if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
777849
// indexRec = matchFinalStateCorrBkgs<true, true>(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial);
778850
// } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
@@ -832,8 +904,10 @@ struct HfCandidateCreator2ProngExpressions {
832904
}
833905
if (origin == RecoDecay::OriginType::NonPrompt) {
834906
auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]);
907+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
835908
rowMcMatchRec(flag, origin, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial);
836909
} else {
910+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
837911
rowMcMatchRec(flag, origin, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial);
838912
}
839913
}

PWGHF/TableProducer/candidateCreator3Prong.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ struct HfCandidateCreator3ProngExpressions {
958958
// break;
959959
// }
960960

961-
for (const auto& pdg : mothersPdgCodes) {
961+
for (const auto& pdg : mothersPdgCodes) {
962962
int depth = 2;
963963
if (pdg == Pdg::kDStar) {
964964
depth = 3; // D0 resonant decays are active
@@ -967,9 +967,7 @@ struct HfCandidateCreator3ProngExpressions {
967967
std::array<int, 3> finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]};
968968
if (finalState.size() == 4) { // Partly Reco 3-prong decays
969969
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
970-
// indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
971-
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial);
972-
970+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
973971
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
974972
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, false>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks);
975973
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
@@ -980,7 +978,7 @@ struct HfCandidateCreator3ProngExpressions {
980978

981979
if (indexRec != -1) {
982980
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
983-
std::array<int, 4> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]};
981+
std::array<int, 4> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]};
984982
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) {
985983
indexRec = -1; // Reset indexRec if the generated decay
986984
}
@@ -1045,15 +1043,14 @@ struct HfCandidateCreator3ProngExpressions {
10451043
arrPDGDaugh.push_back(std::abs(daughI.pdgCode()));
10461044
}
10471045
flagResonantDecay(pdg, &channel, arrPDGDaugh);
1048-
LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdg << ", flag: " << flag << ", &sign: " << sign;
1049-
LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << flag << " sign: " << sign << " for channel: " << channel;
1050-
break;
1046+
// LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast<int>(pdg) << ", flag: " << static_cast<int>(flag) << ", &sign: " << static_cast<int>(sign);
1047+
// LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast<int>(flag) << " sign: " << static_cast<int>(sign) << " for channel: " << static_cast<int>(channel);
10511048
}
10521049
break; // Exit loop if a match is found
10531050
}
10541051
}
10551052
}
1056-
LOG(info) << "D+ matching ended with flag " << static_cast<int>(flag) << " and indexRec " << static_cast<int>(indexRec) << ", &sign " << static_cast<int>(sign) << ", channel " << static_cast<int>(channel);
1053+
LOG(info) << "Corr Bkg matching ended with flag " << static_cast<int>(flag) << " and indexRec " << static_cast<int>(indexRec) << ", &sign " << static_cast<int>(sign) << ", channel " << static_cast<int>(channel);
10571054
} else {
10581055
// D± → π± K∓ π±
10591056
if (flag == 0) {
@@ -1193,16 +1190,16 @@ struct HfCandidateCreator3ProngExpressions {
11931190
}
11941191
if (origin == RecoDecay::OriginType::NonPrompt) {
11951192
auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]);
1196-
LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel;
1193+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
11971194
rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial);
11981195
} else {
1199-
LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel;
1196+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
12001197
rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial);
12011198
}
12021199
}
12031200

1204-
LOG(info) << "Filling MC match gen for 3 prong candidates";
1205-
LOG(info) << "Number of MC collisions: " << mcCollisions.size();
1201+
// LOG(info) << "Filling MC match gen for 3 prong candidates";
1202+
// LOG(info) << "Number of MC collisions: " << mcCollisions.size();
12061203
for (const auto& mcCollision : mcCollisions) {
12071204

12081205
// Slice the particles table to get the particles for the current MC collision

PWGHF/TableProducer/candidateSelectorD0.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct HfCandidateSelectorD0 {
210210
if (candidate.decayLengthXY() > cuts->get(pTBin, "max decay length XY")) {
211211
return false;
212212
}
213-
213+
LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << hfHelper.invMassD0ToPiK(candidate) << " GeV/c^2";
214214
return true;
215215
}
216216

@@ -288,7 +288,7 @@ struct HfCandidateSelectorD0 {
288288
}
289289
}
290290
}
291-
291+
LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << (trackPion.sign() > 0 ? massD0 : massD0bar) << " GeV/c^2";
292292
return true;
293293
}
294294
template <int reconstructionType, typename CandType>
@@ -483,12 +483,16 @@ struct HfCandidateSelectorD0 {
483483

484484
void processWithDCAFitterN(aod::HfCand2ProngWPid const& candidates, TracksSel const& tracks)
485485
{
486+
LOG(info) << "Processing candidates selection with DCAFitterN";
487+
LOG(info) << "Number of candidates: " << candidates.size();
486488
processSel<aod::hf_cand::VertexerType::DCAFitter>(candidates, tracks);
487489
}
488490
PROCESS_SWITCH(HfCandidateSelectorD0, processWithDCAFitterN, "process candidates selection with DCAFitterN", true);
489-
491+
490492
void processWithKFParticle(soa::Join<aod::HfCand2ProngWPid, aod::HfCand2ProngKF> const& candidates, TracksSel const& tracks)
491493
{
494+
LOG(info) << "Processing candidates selection with KFParticle";
495+
LOG(info) << "Number of candidates: " << candidates.size();
492496
processSel<aod::hf_cand::VertexerType::KfParticle>(candidates, tracks);
493497
}
494498
PROCESS_SWITCH(HfCandidateSelectorD0, processWithKFParticle, "process candidates selection with KFParticle", false);

0 commit comments

Comments
 (0)