Skip to content

Commit 84e756f

Browse files
committed
Move functions to creators
1 parent 96d4af0 commit 84e756f

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
@@ -749,7 +749,7 @@ DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //!
749749
DECLARE_SOA_TABLE(HfCand2ProngMcGen, "AOD", "HFCAND2PMCGEN", //!
750750
hf_cand_2prong::FlagMcMatchGen,
751751
hf_cand_2prong::OriginMcGen,
752-
hf_cand_2prong::FlagMcDecayChanRec,
752+
hf_cand_2prong::FlagMcDecayChanGen,
753753
hf_cand::IdxBhadMotherPart);
754754

755755
// cascade decay candidate table

PWGHF/TableProducer/candidateCreator2Prong.cxx

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

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

PWGHF/TableProducer/candidateCreator3Prong.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ struct HfCandidateCreator3ProngExpressions {
961961
// break;
962962
// }
963963

964-
for (const auto& pdg : mothersPdgCodes) {
964+
for (const auto& pdg : mothersPdgCodes) {
965965
int depth = 2;
966966
if (pdg == Pdg::kDStar) {
967967
depth = 3; // D0 resonant decays are active
@@ -970,9 +970,7 @@ struct HfCandidateCreator3ProngExpressions {
970970
std::array<int, 3> finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]};
971971
if (finalState.size() == 4) { // Partly Reco 3-prong decays
972972
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
973-
// indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
974-
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial);
975-
973+
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
976974
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
977975
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, false>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks);
978976
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
@@ -983,7 +981,7 @@ struct HfCandidateCreator3ProngExpressions {
983981

984982
if (indexRec != -1) {
985983
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
986-
std::array<int, 4> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]};
984+
std::array<int, 4> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]};
987985
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) {
988986
indexRec = -1; // Reset indexRec if the generated decay
989987
}
@@ -1048,15 +1046,14 @@ struct HfCandidateCreator3ProngExpressions {
10481046
arrPDGDaugh.push_back(std::abs(daughI.pdgCode()));
10491047
}
10501048
flagResonantDecay(pdg, &channel, arrPDGDaugh);
1051-
LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdg << ", flag: " << flag << ", &sign: " << sign;
1052-
LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << flag << " sign: " << sign << " for channel: " << channel;
1053-
break;
1049+
// LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast<int>(pdg) << ", flag: " << static_cast<int>(flag) << ", &sign: " << static_cast<int>(sign);
1050+
// LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast<int>(flag) << " sign: " << static_cast<int>(sign) << " for channel: " << static_cast<int>(channel);
10541051
}
10551052
break; // Exit loop if a match is found
10561053
}
10571054
}
10581055
}
1059-
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);
1056+
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);
10601057
} else {
10611058
// D± → π± K∓ π±
10621059
LOG(info) << "--------------------------------------------";
@@ -1178,16 +1175,16 @@ struct HfCandidateCreator3ProngExpressions {
11781175
}
11791176
if (origin == RecoDecay::OriginType::NonPrompt) {
11801177
auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]);
1181-
LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel;
1178+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
11821179
rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial);
11831180
} else {
1184-
LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel;
1181+
LOG(info) << "[MCREC] Filling with flag: " << static_cast<int>(flag) << ", origin: " << static_cast<int>(origin) << ", channel: " << static_cast<int>(channel);
11851182
rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial);
11861183
}
11871184
}
11881185

1189-
LOG(info) << "Filling MC match gen for 3 prong candidates";
1190-
LOG(info) << "Number of MC collisions: " << mcCollisions.size();
1186+
// LOG(info) << "Filling MC match gen for 3 prong candidates";
1187+
// LOG(info) << "Number of MC collisions: " << mcCollisions.size();
11911188
for (const auto& mcCollision : mcCollisions) {
11921189

11931190
// 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
@@ -211,7 +211,7 @@ struct HfCandidateSelectorD0 {
211211
if (candidate.decayLengthXY() > cuts->get(pTBin, "max decay length XY")) {
212212
return false;
213213
}
214-
214+
LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << hfHelper.invMassD0ToPiK(candidate) << " GeV/c^2";
215215
return true;
216216
}
217217

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

485485
void processWithDCAFitterN(aod::HfCand2ProngWPid const& candidates, TracksSel const& tracks)
486486
{
487+
LOG(info) << "Processing candidates selection with DCAFitterN";
488+
LOG(info) << "Number of candidates: " << candidates.size();
487489
processSel<aod::hf_cand::VertexerType::DCAFitter>(candidates, tracks);
488490
}
489491
PROCESS_SWITCH(HfCandidateSelectorD0, processWithDCAFitterN, "process candidates selection with DCAFitterN", true);
490-
492+
491493
void processWithKFParticle(soa::Join<aod::HfCand2ProngWPid, aod::HfCand2ProngKF> const& candidates, TracksSel const& tracks)
492494
{
495+
LOG(info) << "Processing candidates selection with KFParticle";
496+
LOG(info) << "Number of candidates: " << candidates.size();
493497
processSel<aod::hf_cand::VertexerType::KfParticle>(candidates, tracks);
494498
}
495499
PROCESS_SWITCH(HfCandidateSelectorD0, processWithKFParticle, "process candidates selection with KFParticle", false);

0 commit comments

Comments
 (0)