From d03ed6e45cd2f761102665b19351fe0408023160 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 23 May 2025 10:07:48 +0200 Subject: [PATCH 01/47] Header for correlated bkgs --- PWGHF/Core/CorrelatedBkgs.h | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 PWGHF/Core/CorrelatedBkgs.h diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h new file mode 100644 index 00000000000..989adcdaae6 --- /dev/null +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -0,0 +1,74 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file CorrelatedBkgTagger.h +/// \brief Definitions of channels for correlated bkgs +/// \author Marcello Di Costanzo , Polytechnic of Turin and INFN + +#ifndef PWGHF_CORE_CORRELATEDBKGTAGGER_H_ +#define PWGHF_CORE_CORRELATEDBKGTAGGER_H_ + +namespace o2::hf_corrbkg +{ + + // D± → K± K∓ π± + enum DecayChannelResoDplus { + PhiPi = 0, + K0starK, + // K01430K, + // RhoPi, + // f2_1270Pi + }; + + // Ds± → K± K∓ π± + enum DecayChannelResoDs { + PhiPi = DecayChannelResoDplus::PhiPi, + K0starK, + // PhiRho, + // f2_1270Pi, + // K0starPi, + // RhoK, + // EtaPi + }; + + // enum DecayChannelResoD0 { + // PhiPi = DecayChannelResoDs::PhiPi, + // K0starPi, + // RhoK, + // K0starPi0, + // K0starPi, + // RhoPi, + // }; + + // enum DecayChannelResoLc { + // K0starP = DecayChannelResoD0::PhiPi, + // DeltaK, + // Lambda1520K, + // PhiP, + // }; + + // enum DecayChannelResoXic { + // K0starP = DecayChannelResoLc::K0starP, + // PhiP, + // }; + + // Function to associate vectors with enum values + std::vector getFinalDaughters(DecayType finalState) { + switch(finalState) { + case DecayChannelCorrBkg::DstarToPiKPiBkg: + return std::array{+kPiPlus, +kPiPlus, -kKPlus}; + default: + return std::array{}; + } + } +} // namespace o2::hf_corrbkg + +#endif // PWGHF_CORE_CORRELATEDBKGTAGGER_H_ From 8c93137f4c3073e0bd6bc822dce795ceb5aba9da Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sat, 24 May 2025 04:44:21 +0200 Subject: [PATCH 02/47] [WIP] D+ matching --- Common/Core/RecoDecay.h | 4 + Common/TableProducer/centralityTable.cxx | 3 + PWGHF/Core/CorrelatedBkgs.h | 205 +++++++++++++++++- .../TableProducer/candidateCreator3Prong.cxx | 39 ++-- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 14 ++ 5 files changed, 233 insertions(+), 32 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 7716a8d64a0..1d5d399b65b 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -803,6 +803,8 @@ struct RecoDecay { // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!acceptIncompleteReco && !checkProcess) { if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast(N)) { + // LOG(info) << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 + // << " (expected " << N << " final)"; // Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, N); return -1; } @@ -815,7 +817,9 @@ struct RecoDecay { // } // printf("\n"); // Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs). + // Printf("MC Rec: Number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != N) { + // LOG(info) << "MC Rec: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")"; // Printf("MC Rec: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return -1; } diff --git a/Common/TableProducer/centralityTable.cxx b/Common/TableProducer/centralityTable.cxx index 48f1598afc5..d222a7d14ee 100644 --- a/Common/TableProducer/centralityTable.cxx +++ b/Common/TableProducer/centralityTable.cxx @@ -240,6 +240,7 @@ struct CentralityTable { mRunNumber = 0; listCalib.setObject(new TList); if (!produceHistograms.value) { + LOG(info) << "Debug histograms are disabled. No histograms will be produced."; return; } @@ -259,6 +260,7 @@ struct CentralityTable { histos.addClone("FT0C/", "sel8FT0C/"); histos.addClone("FT0A/", "sel8FT0A/"); + LOG(info) << "Debug histograms are enabled. Histograms will be produced."; histos.print(); } @@ -569,6 +571,7 @@ struct CentralityTable { mftInfo.mCalibrationStored = false; if (callst != nullptr) { if (produceHistograms) { + LOG(info) << "Adding calibration list to the list of calibration lists"; listCalib->Add(callst->Clone(Form("%i", bc.runNumber()))); } LOGF(info, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 989adcdaae6..95e5d8761f0 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -13,16 +13,31 @@ /// \brief Definitions of channels for correlated bkgs /// \author Marcello Di Costanzo , Polytechnic of Turin and INFN +#include +#include +#include + #ifndef PWGHF_CORE_CORRELATEDBKGTAGGER_H_ #define PWGHF_CORE_CORRELATEDBKGTAGGER_H_ +using namespace o2::constants::physics; + namespace o2::hf_corrbkg { + enum FinalStatesDMesons { + KKPi = 0, + KPiPi, + KPiPiPi0, + PiPiPi, + PiPiPiPi0, + NFinalStatesDMesons + }; + // D± → K± K∓ π± enum DecayChannelResoDplus { - PhiPi = 0, - K0starK, + PhiPiDplus = 0, + K0starKDplus, // K01430K, // RhoPi, // f2_1270Pi @@ -30,8 +45,8 @@ namespace o2::hf_corrbkg // Ds± → K± K∓ π± enum DecayChannelResoDs { - PhiPi = DecayChannelResoDplus::PhiPi, - K0starK, + PhiPiDs = 0, + K0starKDs, // PhiRho, // f2_1270Pi, // K0starPi, @@ -60,15 +75,183 @@ namespace o2::hf_corrbkg // PhiP, // }; - // Function to associate vectors with enum values - std::vector getFinalDaughters(DecayType finalState) { - switch(finalState) { - case DecayChannelCorrBkg::DstarToPiKPiBkg: - return std::array{+kPiPlus, +kPiPlus, -kKPlus}; - default: - return std::array{}; + + // using FinalStateVariant = std::variant< + // std::array, + // std::array + // >; + + // std::unordered_map finalStates = + // { + // {FinalStatesDMesons::KKPi, std::array{+kKPlus, +kKPlus, +kPiPlus}}, + // {FinalStatesDMesons::KPiPiPi0, std::array{+kKPlus, +kKPlus, +kPiPlus, +kPi0}} + // }; + + std::unordered_map, bool>> finalStates = + { + {FinalStatesDMesons::KKPi, {std::array{-kKPlus, +kKPlus, +kPiPlus}, false}}, + {FinalStatesDMesons::KPiPi, {std::array{+kPiPlus, -kKPlus, +kPiPlus}, false}}, + {FinalStatesDMesons::KPiPiPi0, {std::array{+kPiPlus, -kKPlus, +kPiPlus}, true}}, + {FinalStatesDMesons::PiPiPi, {std::array{+kPiMinus, +kPiPlus, +kPiPlus}, false}}, + {FinalStatesDMesons::PiPiPiPi0, {std::array{+kPiMinus, +kPiPlus, +kPiPlus}, true}}, + }; + + + template + int matchFinalStateDMeson(aod::McParticles const& mcParticles, auto arrayDaughters, int pdg, int8_t* flag, int8_t* sign, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { + int indexRec = -1; + LOG(info) << "matchFinalStateDMeson: " << pdg; + for (const std::pair, bool>>& finalState : finalStates) { + if (finalState.second.second) { // 4 prong decay, partly reconstructed + LOG(info) << "[4prong] Taking channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << " " << finalState.second.first[3] << ", has 4 daughters: " << finalState.second.second; + LOG(info) << "[4prong] Trying 4-prong decay ... "; + LOG(info) << "[4prong] Matching channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2]; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, &sign, depth); + } + } else { + LOG(info) << "[3prong] Trying 3-prong decay ... "; + LOG(info) << "[3prong] Taking channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << ", has 4 daughters: " << finalState.second.second; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, &sign, depth); + } + } + if (indexRec > -1) { + LOG(info) << "Found channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << ", has 4 prongs: " << finalState.second.second; + *flag = (*sign) * (1 << finalState.first); + break; + } } + return indexRec; } + + + + + + // Function to associate vectors with enum values + // std::vector getFinalDaughters(DecayType finalState) { + // switch(finalState) { + // case DecayChannelCorrBkg::DstarToPiKPiBkg: + // return std::array{+kPiPlus, +kPiPlus, -kKPlus}; + // default: + // return std::array{}; + // } + // } + + // std::vector getFinalStateDMeson(int index) { + // switch (index) { + // case KKPi: + // return std::vector{+kKPlus, -kKPlus, +kPiPlus}; + // case KPiPi: + // return std::vector{+kKPlus, +kPiPlus, +kPiPlus}; + // case KPiPiPi0: + // return std::vector{+kKPlus, +kPiPlus, +kPiPlus, +kPi0}; + // case PiPiPi: + // return std::vector{+kPiPlus, +kPiPlus, +kPiPlus}; + // case PiPiPiPi0: + // return std::vector{+kPiPlus, +kPiPlus, +kPiPlus, +kPi0}; + // default: + // throw std::out_of_range("Invalid index for final state D meson"); + // } + // } + + + // template + // std::array getFinalStateDMeson(int index) { + // if constexpr (N == 3) { + // switch (index) { + // case FinalStatesDMesons::KKPi: + // return std::array{+kKPlus, -kKPlus, +kPiPlus}; + // case FinalStatesDMesons::KPiPi: + // return std::array{+kKPlus, +kPiPlus, +kPiPlus}; + // case FinalStatesDMesons::PiPiPi: + // return std::array{+kPiPlus, +kPiPlus, +kPiPlus}; + // default: + // throw std::out_of_range("Invalid index for final state D meson"); + // } + // } else if constexpr (N == 4) { + // switch (index) { + // case FinalStatesDMesons::KPiPiPi0: + // return std::array{+kKPlus, +kPiPlus, +kPiPlus, +kPi0}; + // case FinalStatesDMesons::PiPiPiPi0: + // return std::array{+kPiPlus, +kPiPlus, +kPiPlus, +kPi0}; + // default: + // throw std::out_of_range("Invalid index for final state D meson"); + // } + // } else { + // throw std::invalid_argument("Invalid size for final state D meson"); + // } + // } + + // int getFinalStateParts(int index) { + // switch (index) { + // case FinalStatesDMesons::KKPi: + // return 3; + // case FinalStatesDMesons::KPiPi: + // return 3; + // case FinalStatesDMesons::KPiPiPi0: + // return 4; + // case FinalStatesDMesons::PiPiPi: + // return 3; + // case FinalStatesDMesons::PiPiPiPi0: + // return 4; + // default: + // throw std::out_of_range("Invalid index for final state D meson"); + // } + // } + + // template + // int matchFinalStateDMeson(int iChannel, aod::McParticles const& mcParticles, auto arrayDaughters, int pdg, int8_t* sign, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { + // int indexRec = -1; + // int nFinalStateParts = getFinalStateParts(iChannel); + // if (nFinalStateParts == 3) { + // auto finalState = getFinalStateDMeson<3>(iChannel); + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, &sign, depth); + // } + // if (indexRec > -1) { + // LOG(info) << "Matched final state: " << iChannel; + // return indexRec; + // } + // } else if (nFinalStateParts == 4) { + // auto finalState = getFinalStateDMeson<4>(iChannel); + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, &sign, depth); + // } + // if (indexRec > -1) { + // LOG(info) << "Matched final state: " << iChannel; + // return indexRec; + // } + // } else { + // throw std::invalid_argument("Invalid size for final state D meson"); + // } + // } + } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_CORRELATEDBKGTAGGER_H_ diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 145e84513db..6508a0bc987 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -47,6 +47,7 @@ #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/Core/DecayChannels.h" +#include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/Utils/utilsBfieldCCDB.h" #include "PWGHF/Utils/utilsEvSelHf.h" @@ -61,6 +62,7 @@ using namespace o2::aod::hf_cand_3prong; using namespace o2::hf_decay::hf_cand_3prong; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; +using namespace o2::hf_corrbkg; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; @@ -941,7 +943,10 @@ struct HfCandidateCreator3ProngExpressions { } } + // D± → π± K∓ π± + LOG(info) << "--------------------------------------------"; + LOG(info) << "D+ -> Pi K Pi"; if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); @@ -956,6 +961,17 @@ struct HfCandidateCreator3ProngExpressions { flag = sign * DecayChannelMain::DplusToPiKPi; } } + LOG(info) << "D+ matching ended"; + + // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + // } else { + // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + // } // Ds± → K± K∓ π± and D± → K± K∓ π± if (flag == 0) { @@ -1028,27 +1044,6 @@ struct HfCandidateCreator3ProngExpressions { if (indexRec > -1) { flag = sign * DecayChannelMain::LcToPKPi; - // Flagging the different Λc± → p± K∓ π± decay channels - if (arrayDaughters[0].has_mcParticle()) { - swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); - } - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrDaughIndex[iProng]); - arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); - } - if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) { - channel = 1; - } else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) { - channel = 2; - } else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) { - channel = 3; - } - } - } - } - // Ξc± → p± K∓ π± if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -1070,6 +1065,7 @@ struct HfCandidateCreator3ProngExpressions { // Check whether the particle is non-prompt (from a b quark). if (flag != 0) { + LOG(info) << "Setting origin"; auto particle = mcParticles.rawIteratorAt(indexRec); origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } @@ -1079,6 +1075,7 @@ struct HfCandidateCreator3ProngExpressions { } else { rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } + LOG(info) << "--------------------------------------------"; } for (const auto& mcCollision : mcCollisions) { diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 3d23c0b30ca..d3d72904595 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -23,6 +23,7 @@ #include "Framework/runDataProcessing.h" #include "PWGHF/Core/HfHelper.h" +#include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/DataModel/CandidateSelectionTables.h" @@ -31,6 +32,7 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::hf_centrality; +using namespace o2::hf_corrbkg; namespace o2::aod { @@ -273,6 +275,7 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK); Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi); + Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -607,6 +610,17 @@ struct HfTreeCreatorDplusToPiKPi { } PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); + + void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, + aod::McCollisions const& mccollisions, + SelectedCandidatesMcWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + fillMcTables(collisions, mccollisions, reconstructedCandCorrBkgsMl, particles, tracks); + } + + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcCorrBkgsSgnWCentMl, "Process MC correlated bkgs with cent and ML info", false); }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) From 004acaaa90cf546287e33f9dfc1c085ff52d9c86 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 27 May 2025 19:05:24 +0200 Subject: [PATCH 03/47] [WIP] Match correlated bkgs --- Common/Core/RecoDecay.h | 88 +-- PWGHF/Core/CorrelatedBkgs.h | 549 +++++++++++------- .../DataModel/CandidateReconstructionTables.h | 3 + .../TableProducer/candidateCreator2Prong.cxx | 90 ++- .../TableProducer/candidateCreator3Prong.cxx | 229 ++++---- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 3 +- PWGHF/Utils/utilsMcGen.h | 126 ++-- 7 files changed, 650 insertions(+), 438 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 1d5d399b65b..da710398a78 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,6 +25,7 @@ #include // std::apply #include // std::move #include // std::vector +#include // std::ostream // ROOT includes #include // for VMC Particle Production Process @@ -566,8 +567,10 @@ struct RecoDecay { while (!motherFound && arrayIds[-stage].size() > 0 && (depthMax < 0 || -stage < depthMax)) { // vector of mother indices for the current stage std::vector arrayIdsStage{}; + // std::cout << "[getMother] number of mothers at stage " << stage << ": " << arrayIds[-stage].size() << std::endl; 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) auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset()); + // std::cout << "[getMother] particleMother.pdgCode(): " << particleMother.pdgCode() << std::endl; if (particleMother.has_mothers()) { for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again @@ -576,10 +579,9 @@ struct RecoDecay { auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset()); // Check mother's PDG code. auto pdgParticleIMother = mother.pdgCode(); // PDG code of the mother - // printf("getMother: "); - // for (int i = stage; i < 0; i++) // Indent to make the tree look nice. - // printf(" "); - // printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, pdgParticleIMother, iMother); + for (int i = stage; i < 0; i++) // Indent to make the tree look nice. + std::cout << " "; + // std::cout << "[getMother] Stage: " << stage << " Mother PDG: " << pdgParticleIMother << ", Index: " << iMother << std::endl; if (pdgParticleIMother == pdgMother) { // exact PDG match sgn = 1; indexMother = iMother; @@ -640,6 +642,7 @@ struct RecoDecay { } bool isFinal = false; // Flag to indicate the end of recursion + std::cout << "[getDaughters] Stage: " << static_cast(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast(depthMax) << std::endl; if (depthMax > -1 && stage >= depthMax) { // Maximum depth has been reached (or exceeded). isFinal = true; } @@ -647,6 +650,7 @@ struct RecoDecay { if (!isFinal && !particle.has_daughters()) { // If the original particle has no daughters, we do nothing and exit. if (stage == 0) { + // std::cout << "[getDaughters] No daughters of the original particle " << particle.globalIndex() << std::endl; // Printf("getDaughters: No daughters of %d", index); return; } @@ -658,8 +662,10 @@ struct RecoDecay { if (!isFinal && stage > 0) { // If the particle has daughters but is considered to be final, we label it as final. for (auto pdgI : arrPdgFinal) { // o2-linter: disable=const-ref-in-for-loop (int elements) + // std::cout << "[getDaughters] Checking PDG code: " << pdgI << " with " << pdgParticle << std::endl; if (pdgParticle == std::abs(pdgI)) { // Accept antiparticles. isFinal = true; + // std::cout << "[getDaughters] Particle " << particle.globalIndex() << " is final with PDG code " << pdgParticle << std::endl; break; } } @@ -667,15 +673,18 @@ struct RecoDecay { // If the particle is labelled as final, we add this particle in the list of final daughters and exit. if (isFinal) { // printf("getDaughters: "); - // for (int i = 0; i < stage; i++) // Indent to make the tree look nice. - // printf(" "); + for (int i = 0; i < stage; i++) // Indent to make the tree look nice. + std::cout << " "; + // printf(" "); // printf("Stage %d: Adding %d (PDG %d) as final daughter.\n", stage, index, pdgParticle); + // std::cout << "[getDaughters] Adding particle " << particle.globalIndex() << " as final daughter with PDG code " << pdgParticle << std::endl; list->push_back(particle.globalIndex()); return; } // If we are here, we have to follow the daughter tree. // printf("getDaughters: "); - // for (int i = 0; i < stage; i++) // Indent to make the tree look nice. + for (int i = 0; i < stage; i++) // Indent to make the tree look nice. + std::cout << " "; // printf(" "); // printf("Stage %d: %d (PDG %d) -> %d-%d\n", stage, index, pdgParticle, indexDaughterFirst, indexDaughterLast); // Call itself to get daughters of daughters recursively. @@ -702,11 +711,11 @@ struct RecoDecay { /// \param nKaToPi number of kaon prongs decayed to a pion /// \param nInteractionsWithMaterial number of daughter particles that interacted with material /// \return index of the mother particle if the mother and daughters are correct, -1 otherwise - template + template static int getMatchedMCRec(const T& particlesMC, - const std::array& arrDaughters, + const std::array& arrDaughters, int pdgMother, - std::array arrPdgDaughters, + std::array arrPdgDaughters, bool acceptAntiParticles = false, int8_t* sign = nullptr, int depthMax = 1, @@ -722,13 +731,13 @@ struct RecoDecay { int8_t nInteractionsWithMaterialLocal = 0; // number of interactions with material int indexMother = -1; // index of the mother particle std::vector arrAllDaughtersIndex; // vector of indices of all daughters of the mother of the first provided daughter - std::array arrDaughtersIndex; // array of indices of provided daughters + std::array arrDaughtersIndex; // array of indices of provided daughters if (sign) { *sign = sgn; } if constexpr (acceptFlavourOscillation) { // Loop over decay candidate prongs to spot possible oscillation decay product - for (std::size_t iProng = 0; iProng < N; ++iProng) { + for (std::size_t iProng = 0; iProng < NDaug; ++iProng) { if (!arrDaughters[iProng].has_mcParticle()) { return -1; } @@ -740,7 +749,7 @@ struct RecoDecay { } } // Loop over decay candidate prongs - for (std::size_t iProng = 0; iProng < N; ++iProng) { + for (std::size_t iProng = 0; iProng < NDaug; ++iProng) { if (!arrDaughters[iProng].has_mcParticle()) { return -1; } @@ -790,37 +799,43 @@ struct RecoDecay { indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax); // Check whether mother was found. if (indexMother <= -1) { - // Printf("MC Rec: Rejected: bad mother index or PDG"); + std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl; return -1; } - // Printf("MC Rec: Good mother: %d", indexMother); + std::cout << "MC Rec: Good mother: " << indexMother << std::endl; auto particleMother = particlesMC.rawIteratorAt(indexMother - particlesMC.offset()); // Check the daughter indices. if (!particleMother.has_daughters()) { - // Printf("MC Rec: Rejected: bad daughter index range: %d-%d", particleMother.daughtersIds().front(), particleMother.daughtersIds().back()); + std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl; return -1; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!acceptIncompleteReco && !checkProcess) { - if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast(N)) { - // LOG(info) << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 - // << " (expected " << N << " final)"; - // Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, N); + if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast(NDaug)) { + std::cout << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 + << " (expected " << NDaug << " final)" << std::endl; + // Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, NDaug); return -1; } } // Get the list of actual final daughters. getDaughters(particleMother, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - // printf("MC Rec: Mother %d has %d final daughters:", indexMother, arrAllDaughtersIndex.size()); - // for (auto i : arrAllDaughtersIndex) { - // printf(" %d", i); - // } - // printf("\n"); + std::cout << "MC Rec: Mother " << indexMother << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl; + for (auto i : arrAllDaughtersIndex) { + std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; + } + std::cout << " " << std::endl; // Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs). - // Printf("MC Rec: Number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); - if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != N) { - // LOG(info) << "MC Rec: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")"; - // Printf("MC Rec: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); + if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != NDaug) { + std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")" << std::endl; + // LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")"; + // Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug); + return -1; + } + if (forceIncompleteReco && arrAllDaughtersIndex.size() == NDaug) { + std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << "vs Number of daughters " << NDaug << ", expected incomplete reco" << std::endl; + // LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")"; + // Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug); return -1; } } @@ -828,6 +843,7 @@ struct RecoDecay { // (Check that the daughter is not a stepdaughter, i.e. particle pointing to the mother while not being its daughter.) bool isDaughterFound = false; // Is the index of this prong among the remaining expected indices of daughters? for (std::size_t iD = 0; iD < arrAllDaughtersIndex.size(); ++iD) { + // std::cout << "MC Rec: Checking daughter " << iProng << " index: " << arrDaughtersIndex[iProng] << " against expected index: " << arrAllDaughtersIndex[iD] << std::endl; if (arrDaughtersIndex[iProng] == arrAllDaughtersIndex[iD]) { arrAllDaughtersIndex[iD] = -1; // Remove this index from the array of expected daughters. (Rejects twin daughters, i.e. particle considered twice as a daughter.) isDaughterFound = true; @@ -835,14 +851,14 @@ struct RecoDecay { } } if (!isDaughterFound) { - // Printf("MC Rec: Rejected: bad daughter index: %d not in the list of final daughters", arrDaughtersIndex[iProng]); + std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl; return -1; } // Check daughter's PDG code. auto pdgParticleI = particleI.pdgCode(); // PDG code of the ith daughter - // Printf("MC Rec: Daughter %d PDG: %d", iProng, pdgParticleI); + // std::cout << "MC Rec: Daughter " << iProng << " PDG: " << pdgParticleI << std::endl; bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? - for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { + for (std::size_t iProngCp = 0; iProngCp < NDaug; ++iProngCp) { if (pdgParticleI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) { arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones. isPdgFound = true; @@ -850,11 +866,11 @@ struct RecoDecay { } } if (!isPdgFound) { - // Printf("MC Rec: Rejected: bad daughter PDG: %d", pdgParticleI); + std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl; return -1; } } - // Printf("MC Rec: Accepted: m: %d", indexMother); + std::cout << "MC Rec: Accepted: m: " << indexMother << std::endl; if (sign) { *sign = sgn; } @@ -949,14 +965,14 @@ struct RecoDecay { } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); + // printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { // printf(" %d", i); // } // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { - // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); + // Printf("MC Gen: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } if constexpr (acceptFlavourOscillation) { diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 95e5d8761f0..43271fce5dd 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -9,249 +9,382 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file CorrelatedBkgTagger.h +/// \file CorrelatedBkgs.h /// \brief Definitions of channels for correlated bkgs /// \author Marcello Di Costanzo , Polytechnic of Turin and INFN +/// \author Stefano Politanò , CERN #include #include #include -#ifndef PWGHF_CORE_CORRELATEDBKGTAGGER_H_ -#define PWGHF_CORE_CORRELATEDBKGTAGGER_H_ +#include "/home/mdicosta/alice/O2Physics/Common/Core/RecoDecay.h" + +#ifndef PWGHF_CORE_CORRELATEDBKGS_H_ +#define PWGHF_CORE_CORRELATEDBKGS_H_ using namespace o2::constants::physics; namespace o2::hf_corrbkg { - enum FinalStatesDMesons { - KKPi = 0, + enum FinalStates2Prongs { + PiK = 1, + KPi, + KPiPi0, + PiPi, + PiPiPi0, + }; + + std::unordered_map > finalStates2Prongs = + { + {FinalStates2Prongs::PiK, std::vector{+kPiPlus, -kKPlus}}, + {FinalStates2Prongs::KPi, std::vector{-kKPlus, +kPiPlus}}, + {FinalStates2Prongs::KPiPi0, std::vector{-kKPlus, +kPiPlus, +kPi0}}, + {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, + {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + }; + + enum FinalStates3Prongs { + KKPi = 1, + KKPiPi0, KPiPi, KPiPiPi0, PiPiPi, PiPiPiPi0, - NFinalStatesDMesons + ProtonPiPi, + ProtonKPi, + NFinalStates }; - // D± → K± K∓ π± - enum DecayChannelResoDplus { - PhiPiDplus = 0, - K0starKDplus, - // K01430K, - // RhoPi, - // f2_1270Pi + std::unordered_map > finalStates3Prongs = + { + {FinalStates3Prongs::KKPi, std::vector{-kKPlus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KKPiPi0, std::vector{-kKPlus, +kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KPiPi, std::vector{+kPiPlus, -kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KPiPiPi0, std::vector{+kPiPlus, -kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonPiPi, std::vector{kProton, -kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKPi, std::vector{kProton, -kKPlus, +kPiPlus}} }; - // Ds± → K± K∓ π± - enum DecayChannelResoDs { - PhiPiDs = 0, - K0starKDs, - // PhiRho, - // f2_1270Pi, - // K0starPi, - // RhoK, - // EtaPi - }; + // Dstar → K± K∓ π± + namespace D0 { + enum DecayChannelResoD0 { + RhoK = 1, + K0starPi0, + K0starPiPlus, + RhoPi, + }; - // enum DecayChannelResoD0 { - // PhiPi = DecayChannelResoDs::PhiPi, - // K0starPi, - // RhoK, - // K0starPi0, - // K0starPi, - // RhoPi, - // }; + std::unordered_map > resoStatesD0 = + { + {DecayChannelResoD0::RhoK, std::array{213, -kKPlus}}, + {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoD0::K0starPiPlus, std::array{-323, kKPlus}}, + {DecayChannelResoD0::RhoPi, std::array{213, -kPiPlus}}, + }; + } - // enum DecayChannelResoLc { - // K0starP = DecayChannelResoD0::PhiPi, - // DeltaK, - // Lambda1520K, - // PhiP, - // }; + // D± → K± K∓ π± + namespace DPlus { + enum DecayChannelResoDplus { + K0starK = 1, + K_1430K, + PhiPi, + RhoPi, + f2_1270Pi, + }; - // enum DecayChannelResoXic { - // K0starP = DecayChannelResoLc::K0starP, - // PhiP, - // }; + std::unordered_map > resoStatesDPlus = + { + {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDplus::K_1430K, std::array{-10321, -kKPlus}}, + {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDplus::RhoPi, std::array{+213, +kPiPlus}}, + {DecayChannelResoDplus::f2_1270Pi, std::array{225, +kPiPlus}}, + }; + } + + // Ds± → K± K∓ π± + namespace DS { + enum DecayChannelResoDs { + PhiPi = 1, + K0starK, + PhiRho, + f2_1270Pi, + K0starPi, + RhoK, + EtaPi, + }; + + std::unordered_map > resoStatesDs = + { + {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDs::K0starK, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDs::PhiRho, std::array{-kPhi, -113}}, + {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResoDs::K0starPi, std::array{-kK0Star892, -kPiPlus}}, + {DecayChannelResoDs::RhoK, std::array{-113, -kKPlus}}, + {DecayChannelResoDs::EtaPi, std::array{-221, -kPiPlus}}, + }; + } + // Dstar → K± K∓ π± + namespace DStar { + enum DecayChannelResoDStarD0 { + RhoK = 1, + K0starPi0, + K0starPiPlus, + RhoPi, + }; - // using FinalStateVariant = std::variant< - // std::array, - // std::array - // >; + std::unordered_map > resoStatesDStarD0 = + { + {DecayChannelResoDStarD0::RhoK, std::array{213, -kKPlus}}, + {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDStarD0::K0starPiPlus, std::array{-323, kKPlus}}, + {DecayChannelResoDStarD0::RhoPi, std::array{213, -kPiPlus}}, + }; + } - // std::unordered_map finalStates = - // { - // {FinalStatesDMesons::KKPi, std::array{+kKPlus, +kKPlus, +kPiPlus}}, - // {FinalStatesDMesons::KPiPiPi0, std::array{+kKPlus, +kKPlus, +kPiPlus, +kPi0}} - // }; + // Lc → p K∓ π± + namespace LambdaC { + enum DecayChannelResoLambdaC { + K0starP = 1, + DeltaK, + Lambda1520Pi, + ProtonPhi, + }; - std::unordered_map, bool>> finalStates = - { - {FinalStatesDMesons::KKPi, {std::array{-kKPlus, +kKPlus, +kPiPlus}, false}}, - {FinalStatesDMesons::KPiPi, {std::array{+kPiPlus, -kKPlus, +kPiPlus}, false}}, - {FinalStatesDMesons::KPiPiPi0, {std::array{+kPiPlus, -kKPlus, +kPiPlus}, true}}, - {FinalStatesDMesons::PiPiPi, {std::array{+kPiMinus, +kPiPlus, +kPiPlus}, false}}, - {FinalStatesDMesons::PiPiPiPi0, {std::array{+kPiMinus, +kPiPlus, +kPiPlus}, true}}, - }; + std::unordered_map > resoStatesLambdaC = + { + {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, -kProton}}, + {DecayChannelResoLambdaC::DeltaK, std::array{+2224, -kKPlus}}, + {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, -kPiPlus}}, + {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, -kPhi}}, + }; + } + + // Xic → p K∓ π± + namespace XiC { + enum DecayChannelResoXiC { + K0starP = 1, + ProtonPhi, + SigmaPiPi, + }; + + std::unordered_map > resoStatesXiC = + { + {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, -kProton}}, + {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, -kPhi}}, + {DecayChannelResoXiC::SigmaPiPi, std::array{+kProton, -kPhi}}, + }; + } + bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { + std::cout << "###"; + for (int iArrDaugh : arrDaughIndex) { + bool findDaug = false; + for (int i = 0; i < 2; ++i) { + std::cout << "Checking daughter PDG: " << iArrDaugh << " against resonant PDG: " << arrPDGResonant[i] << std::endl; + if (std::abs(iArrDaugh) == arrPDGResonant[i]) { + findDaug = true; + } + } + if (!findDaug) { + std::cout << "###"; + return false; // If any daughter does not match, return false + } + } + std::cout << "###"; + return true; + } - template - int matchFinalStateDMeson(aod::McParticles const& mcParticles, auto arrayDaughters, int pdg, int8_t* flag, int8_t* sign, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - int indexRec = -1; - LOG(info) << "matchFinalStateDMeson: " << pdg; - for (const std::pair, bool>>& finalState : finalStates) { - if (finalState.second.second) { // 4 prong decay, partly reconstructed - LOG(info) << "[4prong] Taking channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << " " << finalState.second.first[3] << ", has 4 daughters: " << finalState.second.second; - LOG(info) << "[4prong] Trying 4-prong decay ... "; - LOG(info) << "[4prong] Matching channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2]; - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, &sign, depth); - } - } else { - LOG(info) << "[3prong] Trying 3-prong decay ... "; - LOG(info) << "[3prong] Taking channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << ", has 4 daughters: " << finalState.second.second; - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState.second.first, true, &sign, depth); - } + /// Check if the decay is resonant + /// \tparam arrDaughIndex index of the particle daughters at resonance level + /// \tparam arrPDGResonant PDG code of the resonant decay + /// \return true if the decay is resonant + void flagResonantDecay(int motherPdg, int8_t* channel, std::vector arrDaughIndex) { + switch (motherPdg) { + case Pdg::kD0: + for (const auto& [flag, pdgCodes] : D0::resoStatesD0) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; } - if (indexRec > -1) { - LOG(info) << "Found channel with final state: " << finalState.second.first[0] << " " << finalState.second.first[1] << " " << finalState.second.first[2] << ", has 4 prongs: " << finalState.second.second; - *flag = (*sign) * (1 << finalState.first); - break; + } + break; + case Pdg::kDPlus: + for (const auto& [flag, pdgCodes] : DPlus::resoStatesDPlus) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; } - } - return indexRec; + } + break; + case Pdg::kDS: + for (const auto& [flag, pdgCodes] : DS::resoStatesDs) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; + } + } + break; + case Pdg::kDStar: + for (const auto& [flag, pdgCodes] : DStar::resoStatesDStarD0) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; + } + } + break; + case Pdg::kLambdaCPlus: + for (const auto& [flag, pdgCodes] : LambdaC::resoStatesLambdaC) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; + } + } + break; + case Pdg::kXiCPlus: + for (const auto& [flag, pdgCodes] : XiC::resoStatesXiC) { + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = (1 << flag); + break; + } + } + break; + } } + template + int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { + std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; + std::vector arrResoDaughIndex = {}; + int indexRec = -1; // Index of the matched reconstructed candidate + // for (std::size_t iProng = 0; iProng < 3; ++iProng) { + // if (!arrayDaughters[iProng].has_mcParticle()) { + // return -1; + // } + // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle + // auto motherI = particleI.template mothers_first_as(); + // auto pdgI = particleI.pdgCode(); + // auto pdgMotherI = motherI.pdgCode(); + // auto pdgMotherII = -1; + // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgMotherI; + // } + LOG(info) << "Matching daughters ... "; + int matchedMotherId = 0; + + // auto finalStates = finalStates3Prongs; + // if (std::abs(pdgMother) == Pdg::kD0) { + // finalStates = finalStates2Prongs; + // } - - - - // Function to associate vectors with enum values - // std::vector getFinalDaughters(DecayType finalState) { - // switch(finalState) { - // case DecayChannelCorrBkg::DstarToPiKPiBkg: - // return std::array{+kPiPlus, +kPiPlus, -kKPlus}; - // default: - // return std::array{}; - // } - // } - - // std::vector getFinalStateDMeson(int index) { - // switch (index) { - // case KKPi: - // return std::vector{+kKPlus, -kKPlus, +kPiPlus}; - // case KPiPi: - // return std::vector{+kKPlus, +kPiPlus, +kPiPlus}; - // case KPiPiPi0: - // return std::vector{+kKPlus, +kPiPlus, +kPiPlus, +kPi0}; - // case PiPiPi: - // return std::vector{+kPiPlus, +kPiPlus, +kPiPlus}; - // case PiPiPiPi0: - // return std::vector{+kPiPlus, +kPiPlus, +kPiPlus, +kPi0}; - // default: - // throw std::out_of_range("Invalid index for final state D meson"); - // } - // } - - - // template - // std::array getFinalStateDMeson(int index) { - // if constexpr (N == 3) { - // switch (index) { - // case FinalStatesDMesons::KKPi: - // return std::array{+kKPlus, -kKPlus, +kPiPlus}; - // case FinalStatesDMesons::KPiPi: - // return std::array{+kKPlus, +kPiPlus, +kPiPlus}; - // case FinalStatesDMesons::PiPiPi: - // return std::array{+kPiPlus, +kPiPlus, +kPiPlus}; - // default: - // throw std::out_of_range("Invalid index for final state D meson"); - // } - // } else if constexpr (N == 4) { - // switch (index) { - // case FinalStatesDMesons::KPiPiPi0: - // return std::array{+kKPlus, +kPiPlus, +kPiPlus, +kPi0}; - // case FinalStatesDMesons::PiPiPiPi0: - // return std::array{+kPiPlus, +kPiPlus, +kPiPlus, +kPi0}; - // default: - // throw std::out_of_range("Invalid index for final state D meson"); - // } - // } else { - // throw std::invalid_argument("Invalid size for final state D meson"); - // } - // } - - // int getFinalStateParts(int index) { - // switch (index) { - // case FinalStatesDMesons::KKPi: - // return 3; - // case FinalStatesDMesons::KPiPi: - // return 3; - // case FinalStatesDMesons::KPiPiPi0: - // return 4; - // case FinalStatesDMesons::PiPiPi: - // return 3; - // case FinalStatesDMesons::PiPiPiPi0: - // return 4; - // default: - // throw std::out_of_range("Invalid index for final state D meson"); - // } - // } - - // template - // int matchFinalStateDMeson(int iChannel, aod::McParticles const& mcParticles, auto arrayDaughters, int pdg, int8_t* sign, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - // int indexRec = -1; - // int nFinalStateParts = getFinalStateParts(iChannel); - // if (nFinalStateParts == 3) { - // auto finalState = getFinalStateDMeson<3>(iChannel); - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, &sign, depth); - // } - // if (indexRec > -1) { - // LOG(info) << "Matched final state: " << iChannel; - // return indexRec; - // } - // } else if (nFinalStateParts == 4) { - // auto finalState = getFinalStateDMeson<4>(iChannel); - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalState, true, &sign, depth); - // } - // if (indexRec > -1) { - // LOG(info) << "Matched final state: " << iChannel; - // return indexRec; - // } - // } else { - // throw std::invalid_argument("Invalid size for final state D meson"); - // } - // } + for (const auto& [chn, finalState] : finalStates3Prongs) { + if (finalState.size() == 4) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + } + } else if (finalState.size() == 3 && std::abs(pdgMother) != Pdg::kD0) { // Fully Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + } + } else if (finalState.size() == 3 && std::abs(pdgMother) == Pdg::kD0) { // Partly Reco 2-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1]}; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); + } + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1]}; + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); + } + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + LOG(info) << "IndexRec: " << indexRec; + if (indexRec > -1) { + std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; + switch (pdgMother) { + case Pdg::kD0: + *flag = (*sign) * chn + 10; + break; + case Pdg::kDPlus: + *flag = (*sign) * chn + 20; + break; + case Pdg::kDS: + *flag = (*sign) * chn + 30; + break; + case Pdg::kDStar: + *flag = (*sign) * chn + 40; + break; + case Pdg::kLambdaCPlus: + *flag = (*sign) * chn + 50; + break; + case Pdg::kXiCPlus: + *flag = (*sign) * chn + 60; + break; + default: + LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; + continue; // Skip unknown mother PDG codes + } + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(pdgMother) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances + } + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + if ( (std::abs(pdgMother) == Pdg::kDStar || std::abs(pdgMother) == Pdg::kXiCPlus) + && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + } + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(pdgMother, channel, arrPDGDaugh); + LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << chn; + break; + } + } + } + return indexRec; + } } // namespace o2::hf_corrbkg -#endif // PWGHF_CORE_CORRELATEDBKGTAGGER_H_ +#endif // PWGHF_CORE_CORRELATEDBKGS_H_ diff --git a/PWGHF/DataModel/CandidateReconstructionTables.h b/PWGHF/DataModel/CandidateReconstructionTables.h index a32a88e1d12..2d0c01224d0 100644 --- a/PWGHF/DataModel/CandidateReconstructionTables.h +++ b/PWGHF/DataModel/CandidateReconstructionTables.h @@ -641,6 +641,8 @@ DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); //! reconstruction l DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); //! generator level DECLARE_SOA_COLUMN(OriginMcRec, originMcRec, int8_t); //! particle origin, reconstruction level DECLARE_SOA_COLUMN(OriginMcGen, originMcGen, int8_t); //! particle origin, generator level +DECLARE_SOA_COLUMN(FlagMcDecayChanRec, flagMcDecayChanRec, int8_t); //! resonant decay channel flag, reconstruction level + // KF related properties DECLARE_SOA_COLUMN(KfGeoMassD0, kfGeoMassD0, float); //! mass of the D0 candidate from the KFParticle geometric fit DECLARE_SOA_COLUMN(KfGeoMassD0bar, kfGeoMassD0bar, float); //! mass of the D0bar candidate from the KFParticle geometric fit @@ -754,6 +756,7 @@ DECLARE_SOA_TABLE(HfCand2ProngKF, "AOD", "HFCAND2PKF", DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //! hf_cand_2prong::FlagMcMatchRec, hf_cand_2prong::OriginMcRec, + hf_cand_2prong::FlagMcDecayChanRec, hf_cand::PtBhadMotherPart, hf_cand::PdgBhadMotherPart, hf_cand::NTracksDecayed, diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index d551922b7d5..35dc57f832f 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -47,6 +47,7 @@ #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/Core/SelectorCuts.h" +#include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/Utils/utilsBfieldCCDB.h" #include "PWGHF/Utils/utilsEvSelHf.h" @@ -61,6 +62,7 @@ using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_2prong; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; +using namespace o2::hf_corrbkg; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::aod::pid_tpc_tof_utils; @@ -691,6 +693,7 @@ struct HfCandidateCreator2ProngExpressions { Configurable rejectBackground{"rejectBackground", true, "Reject particles from background events"}; Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; + Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring @@ -738,6 +741,7 @@ struct HfCandidateCreator2ProngExpressions { int indexRec = -1; int8_t sign = 0; int8_t flag = 0; + int8_t channel = 0; int8_t origin = 0; int8_t nKinkedTracks = 0; int8_t nInteractionsWithMaterial = 0; @@ -747,6 +751,7 @@ struct HfCandidateCreator2ProngExpressions { for (const auto& candidate : *rowCandidateProng2) { flag = 0; origin = 0; + channel = 0; auto arrayDaughters = std::array{candidate.prong0_as(), candidate.prong1_as()}; // Check whether the particle is from background events. If so, reject it. @@ -762,47 +767,64 @@ struct HfCandidateCreator2ProngExpressions { } } if (fromBkg) { - rowMcMatchRec(flag, origin, -1.f, 0, 0, 0); + rowMcMatchRec(flag, origin, channel, -1.f, 0, 0, 0); continue; } } std::vector idxBhadMothers{}; - // D0(bar) → π± K∓ - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign); - } - if (indexRec > -1) { - flag = sign * (1 << DecayType::D0ToPiK); - } - - // J/ψ → e+ e− - if (flag == 0) { - if (matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); + if (matchCorrBkgs) { + LOG(info) << "--------------------------------------------"; + LOG(info) << "Matching correlated bkgs of " << Pdg::kD0; + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true); + indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); } if (indexRec > -1) { - flag = 1 << DecayType::JpsiToEE; + LOG(info) << "Matched!"; } - } - - // J/ψ → μ+ μ− - if (flag == 0) { - if (matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); + } else { + // D0(bar) → π± K∓ + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign); } if (indexRec > -1) { - flag = 1 << DecayType::JpsiToMuMu; + flag = sign * (1 << DecayType::D0ToPiK); + } + + // J/ψ → e+ e− + if (flag == 0) { + if (matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true); + } + if (indexRec > -1) { + flag = 1 << DecayType::JpsiToEE; + } + } + + // J/ψ → μ+ μ− + if (flag == 0) { + if (matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true); + } + if (indexRec > -1) { + flag = 1 << DecayType::JpsiToMuMu; + } } } @@ -813,9 +835,9 @@ struct HfCandidateCreator2ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); - rowMcMatchRec(flag, origin, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); + rowMcMatchRec(flag, origin, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { - rowMcMatchRec(flag, origin, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); + rowMcMatchRec(flag, origin, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } @@ -846,7 +868,11 @@ struct HfCandidateCreator2ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + if (matchCorrBkgs) { + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + } else { + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + } } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 6508a0bc987..25bb9fa66b3 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -591,7 +591,7 @@ struct HfCandidateCreator3Prong { uint8_t bitmapProngsContributorsPV = 0; if (indexCollision == track0.collisionId() && track0.isPVContributor()) { SETBIT(bitmapProngsContributorsPV, 0); - } + } if (indexCollision == track1.collisionId() && track1.isPVContributor()) { SETBIT(bitmapProngsContributorsPV, 1); } @@ -852,6 +852,7 @@ struct HfCandidateCreator3ProngExpressions { Configurable rejectBackground{"rejectBackground", true, "Reject particles from background events"}; Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; + Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; constexpr static std::size_t NDaughtersResonant{2u}; @@ -921,6 +922,7 @@ struct HfCandidateCreator3ProngExpressions { origin = 0; swapping = 0; channel = 0; + indexRec = -1; arrDaughIndex.clear(); std::vector idxBhadMothers{}; auto arrayDaughters = std::array{candidate.prong0_as(), candidate.prong1_as(), candidate.prong2_as()}; @@ -943,122 +945,141 @@ struct HfCandidateCreator3ProngExpressions { } } - - // D± → π± K∓ π± - LOG(info) << "--------------------------------------------"; - LOG(info) << "D+ -> Pi K Pi"; - if (flag == 0) { - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2); - } - if (indexRec > -1) { - flag = sign * DecayChannelMain::DplusToPiKPi; - } - } - LOG(info) << "D+ matching ended"; - - // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - // } else { - // indexRec = matchFinalStateDMeson(mcParticles, arrayDaughters, Pdg::kDPlus, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - // } - - // Ds± → K± K∓ π± and D± → K± K∓ π± - if (flag == 0) { - bool isDplus = false; - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2); + if (matchCorrBkgs) { + LOG(info) << "--------------------------------------------"; + LOG(info) << "Matching correlated bkgs"; + std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + for (const auto& motherPdgCode : mothersPdgCodes) { + int maxDepth = 2; + if (motherPdgCode == Pdg::kDStar) { + maxDepth = 3; // to catch the D0 resonances + } + if (indexRec <= -1) { + LOG(info) << "Matching " << motherPdgCode; + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + } else { + indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + } + } + if (indexRec > -1) { + LOG(info) << "Matched!"; + } } - if (indexRec == -1) { - isDplus = true; + LOG(info) << "D+ matching ended with flag " << static_cast(flag) << " and indexRec " << indexRec << ", sign " << static_cast(sign) << ", channel " << static_cast(channel); + } else { + // D± → π± K∓ π± + LOG(info) << "--------------------------------------------"; + LOG(info) << "D+ -> Pi K Pi"; + if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2); + } + if (indexRec > -1) { + flag = sign * DecayChannelMain::DplusToPiKPi; } } - if (indexRec > -1) { - flag = sign * (isDplus ? DecayChannelMain::DplusToPiKK : DecayChannelMain::DsToPiKK); - if (arrayDaughters[0].has_mcParticle()) { - swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + LOG(info) << "D+ matching ended"; + + // Ds± → K± K∓ π± and D± → K± K∓ π± + if (flag == 0) { + bool isDplus = false; + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2); } - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrDaughIndex[iProng]); - arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); + if (indexRec == -1) { + isDplus = true; + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2); } - if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { - channel = isDplus ? DecayChannelResonant::DplusToPhiPi : DecayChannelResonant::DsToPhiPi; - } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { - channel = isDplus ? DecayChannelResonant::DplusToKstar0K : DecayChannelResonant::DsToKstar0K; + } + if (indexRec > -1) { + flag = sign * (isDplus ? DecayChannelMain::DplusToPiKK : DecayChannelMain::DsToPiKK); + if (arrayDaughters[0].has_mcParticle()) { + swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + } + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrDaughIndex, std::array{0}, 1); + if (arrDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrDaughIndex[iProng]); + arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); + } + if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { + channel = isDplus ? DecayChannelResonant::DplusToPhiPi : DecayChannelResonant::DsToPhiPi; + } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { + channel = isDplus ? DecayChannelResonant::DplusToKstar0K : DecayChannelResonant::DsToKstar0K; + } } } } - } - // D* → D0π → Kππ - if (flag == 0) { - if (matchKinkedDecayTopology) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); - } - if (indexRec > -1) { - flag = sign * DecayChannelMain::DstarToPiKPi; - channel = 1; + // D* → D0π → Kππ + if (flag == 0) { + if (matchKinkedDecayTopology) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); + } + if (indexRec > -1) { + flag = sign * DecayChannelMain::DstarToPiKPi; + channel = 1; + } } - } - // Λc± → p± K∓ π± - if (flag == 0) { - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); - } - if (indexRec > -1) { - flag = sign * DecayChannelMain::LcToPKPi; - - // Ξc± → p± K∓ π± - if (flag == 0) { - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); + // Λc± → p± K∓ π± + if (flag == 0) { + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); + } + if (indexRec > -1) { + flag = sign * DecayChannelMain::LcToPKPi; + } } - if (indexRec > -1) { - flag = sign * DecayChannelMain::XicToPKPi; - if (arrayDaughters[0].has_mcParticle()) { - swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + + // Ξc± → p± K∓ π± + if (flag == 0) { + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); + } + if (indexRec > -1) { + flag = sign * DecayChannelMain::XicToPKPi; + if (arrayDaughters[0].has_mcParticle()) { + swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + } } } } @@ -1105,7 +1126,11 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + if (matchCorrBkgs) { + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + } else { + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + } } } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index d3d72904595..e039b3e394a 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -265,6 +265,7 @@ struct HfTreeCreatorDplusToPiKPi { using SelectedCandidatesMc = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; using SelectedCandidatesMcWithMl = soa::Filtered>; + using SelectedCandidatesMcCorrBkgsWithMl = soa::Filtered>; using TracksWPid = soa::Join; using CollisionsCent = soa::Join; @@ -613,7 +614,7 @@ struct HfTreeCreatorDplusToPiKPi { void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, + SelectedCandidatesMcCorrBkgsWithMl const&, MatchedGenCandidatesMc const& particles, TracksWPid const& tracks) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 73dac888c8e..5ee455ed707 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -31,6 +31,8 @@ #include "PWGHF/Core/DecayChannels.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" +#include "PWGHF/Core/CorrelatedBkgs.h" + namespace hf_mc_gen { @@ -82,7 +84,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } -template +template void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { using namespace o2::constants::physics; @@ -108,76 +110,82 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } - // D± → π± K∓ π± - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi; - } - } + if (matchCorrBkgs) { + LOG(info) << "--------------------------------------------"; + LOG(info) << "Matching correlated bkgs of 3prongs"; + } else { - // Ds± → K± K∓ π± and D± → K± K∓ π± - if (flag == 0) { - bool isDplus = false; - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { - // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± - // TODO: move to different and explicit flags - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK; - } else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { - // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± - // TODO: move to different and explicit flags - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK; - isDplus = true; + // D± → π± K∓ π± + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi; + } } - if (flag != 0) { - RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == NDaughtersResonant) { - for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { - auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); - arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); - } - if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { - channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi; - } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { - channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K; + + // Ds± → K± K∓ π± and D± → K± K∓ π± + if (flag == 0) { + bool isDplus = false; + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { + // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + // TODO: move to different and explicit flags + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK; + } else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { + // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + // TODO: move to different and explicit flags + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK; + isDplus = true; + } + if (flag != 0) { + RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); + if (arrDaughIndex.size() == NDaughtersResonant) { + for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { + auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); + arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); + } + if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { + channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi; + } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { + channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K; + } } } } - } - // D*± → D0(bar) π± - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi; + // D*± → D0(bar) π± + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi; + } } - } - // Λc± → p± K∓ π± - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPi; - - // Flagging the different Λc± → p± K∓ π± decay channels - RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == NDaughtersResonant) { - for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { - auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); - arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); - } - if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) { - channel = 1; - } else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) { - channel = 2; - } else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) { - channel = 3; + // Λc± → p± K∓ π± + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPi; + + // Flagging the different Λc± → p± K∓ π± decay channels + RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); + if (arrDaughIndex.size() == NDaughtersResonant) { + for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { + auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); + arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); + } + if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) { + channel = 1; + } else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) { + channel = 2; + } else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) { + channel = 3; + } } } } - } - // Ξc± → p± K∓ π± - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKPi; + // Ξc± → p± K∓ π± + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { + flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKPi; + } } } From ab9677f4465b9c29c525088b782ac0eb68df8fa0 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 28 May 2025 17:53:35 +0200 Subject: [PATCH 04/47] [WIP] Generated matching --- Common/Core/RecoDecay.h | 25 ++- PWGHF/Core/CorrelatedBkgs.h | 191 +++++++++++++----- .../DataModel/CandidateReconstructionTables.h | 2 + .../TableProducer/candidateCreator2Prong.cxx | 2 +- .../TableProducer/candidateCreator3Prong.cxx | 31 ++- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 5 +- PWGHF/Utils/utilsMcGen.h | 74 ++++--- PWGJE/Tasks/CMakeLists.txt | 8 +- PWGLF/Tasks/Resonances/CMakeLists.txt | 8 +- 9 files changed, 245 insertions(+), 101 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index da710398a78..4608a0e063f 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -642,7 +642,7 @@ struct RecoDecay { } bool isFinal = false; // Flag to indicate the end of recursion - std::cout << "[getDaughters] Stage: " << static_cast(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast(depthMax) << std::endl; + // std::cout << "[getDaughters] Stage: " << static_cast(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast(depthMax) << std::endl; if (depthMax > -1 && stage >= depthMax) { // Maximum depth has been reached (or exceeded). isFinal = true; } @@ -799,14 +799,14 @@ struct RecoDecay { indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax); // Check whether mother was found. if (indexMother <= -1) { - std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl; + // std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl; return -1; } std::cout << "MC Rec: Good mother: " << indexMother << std::endl; auto particleMother = particlesMC.rawIteratorAt(indexMother - particlesMC.offset()); // Check the daughter indices. if (!particleMother.has_daughters()) { - std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl; + // std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl; return -1; } // Check that the number of direct daughters is not larger than the number of expected final daughters. @@ -851,7 +851,7 @@ struct RecoDecay { } } if (!isDaughterFound) { - std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl; + // std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl; return -1; } // Check daughter's PDG code. @@ -866,7 +866,7 @@ struct RecoDecay { } } if (!isPdgFound) { - std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl; + // std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl; return -1; } } @@ -939,11 +939,13 @@ struct RecoDecay { // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); + // std::cout << "MC Gen: Candidate PDG: " << pdgCandidate << std::endl; if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match sgn = -1; } else { + // std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl; // Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle)); return false; } @@ -965,13 +967,17 @@ struct RecoDecay { } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); + // printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size()); - // for (auto i : arrAllDaughtersIndex) { - // printf(" %d", i); - // } + // std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl; + for (auto i : arrAllDaughtersIndex) { + // std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; + } + std::cout << " " << std::endl; // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { + // std::cout << "MC Gen: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; // Printf("MC Gen: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } @@ -989,6 +995,7 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter + // std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { @@ -999,6 +1006,7 @@ struct RecoDecay { } } if (!isPdgFound) { + // std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl; // Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI); return false; } @@ -1007,6 +1015,7 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } + std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 43271fce5dd..9fc21deb3be 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -34,15 +34,16 @@ namespace o2::hf_corrbkg KPiPi0, PiPi, PiPiPi0, + NFinalStates2P }; std::unordered_map > finalStates2Prongs = { - {FinalStates2Prongs::PiK, std::vector{+kPiPlus, -kKPlus}}, - {FinalStates2Prongs::KPi, std::vector{-kKPlus, +kPiPlus}}, - {FinalStates2Prongs::KPiPi0, std::vector{-kKPlus, +kPiPlus, +kPi0}}, - {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, - {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + {FinalStates2Prongs::PiK, std::vector{+kPiPlus, -kKPlus}}, + {FinalStates2Prongs::KPi, std::vector{-kKPlus, +kPiPlus}}, + {FinalStates2Prongs::KPiPi0, std::vector{-kKPlus, +kPiPlus, +kPi0}}, + {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, + {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} }; enum FinalStates3Prongs { @@ -54,19 +55,18 @@ namespace o2::hf_corrbkg PiPiPiPi0, ProtonPiPi, ProtonKPi, - NFinalStates + NFinalStates3P }; std::unordered_map > finalStates3Prongs = { - {FinalStates3Prongs::KKPi, std::vector{-kKPlus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KKPiPi0, std::vector{-kKPlus, +kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KPiPi, std::vector{+kPiPlus, -kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KPiPiPi0, std::vector{+kPiPlus, -kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonPiPi, std::vector{kProton, -kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKPi, std::vector{kProton, -kKPlus, +kPiPlus}} + {FinalStates3Prongs::KKPi, std::vector{-kKPlus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KKPiPi0, std::vector{-kKPlus, +kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KPiPi, std::vector{+kPiPlus, -kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KPiPiPi0, std::vector{+kPiPlus, -kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonKPi, std::vector{kProton, -kKPlus, +kPiPlus}} }; // Dstar → K± K∓ π± @@ -80,10 +80,10 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesD0 = { - {DecayChannelResoD0::RhoK, std::array{213, -kKPlus}}, - {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoD0::K0starPiPlus, std::array{-323, kKPlus}}, - {DecayChannelResoD0::RhoPi, std::array{213, -kPiPlus}}, + {DecayChannelResoD0::RhoK, std::array{213, -kKPlus}}, + {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoD0::K0starPiPlus, std::array{-323, +kKPlus}}, + {DecayChannelResoD0::RhoPi, std::array{213, -kPiPlus}}, }; } @@ -99,11 +99,11 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesDPlus = { - {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoDplus::K_1430K, std::array{-10321, -kKPlus}}, - {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResoDplus::RhoPi, std::array{+213, +kPiPlus}}, - {DecayChannelResoDplus::f2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDplus::K_1430K, std::array{-10321, -kKPlus}}, + {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDplus::RhoPi, std::array{+113, +kPiPlus}}, + {DecayChannelResoDplus::f2_1270Pi, std::array{225, +kPiPlus}}, }; } @@ -121,13 +121,13 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesDs = { - {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResoDs::K0starK, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoDs::PhiRho, std::array{-kPhi, -113}}, - {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, - {DecayChannelResoDs::K0starPi, std::array{-kK0Star892, -kPiPlus}}, - {DecayChannelResoDs::RhoK, std::array{-113, -kKPlus}}, - {DecayChannelResoDs::EtaPi, std::array{-221, -kPiPlus}}, + {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDs::K0starK, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDs::PhiRho, std::array{-kPhi, -113}}, + {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResoDs::K0starPi, std::array{-kK0Star892, -kPiPlus}}, + {DecayChannelResoDs::RhoK, std::array{-113, -kKPlus}}, + {DecayChannelResoDs::EtaPi, std::array{-221, -kPiPlus}}, }; } @@ -142,10 +142,10 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesDStarD0 = { - {DecayChannelResoDStarD0::RhoK, std::array{213, -kKPlus}}, - {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, + {DecayChannelResoDStarD0::RhoK, std::array{213, -kKPlus}}, + {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, {DecayChannelResoDStarD0::K0starPiPlus, std::array{-323, kKPlus}}, - {DecayChannelResoDStarD0::RhoPi, std::array{213, -kPiPlus}}, + {DecayChannelResoDStarD0::RhoPi, std::array{213, -kPiPlus}}, }; } @@ -160,10 +160,10 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesLambdaC = { - {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, -kProton}}, - {DecayChannelResoLambdaC::DeltaK, std::array{+2224, -kKPlus}}, - {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, -kPiPlus}}, - {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, -kPhi}}, + {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, -kProton}}, + {DecayChannelResoLambdaC::DeltaK, std::array{+2224, -kKPlus}}, + {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, -kPiPlus}}, + {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, -kPhi}}, }; } @@ -177,28 +177,25 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesXiC = { - {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, -kProton}}, - {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, -kPhi}}, - {DecayChannelResoXiC::SigmaPiPi, std::array{+kProton, -kPhi}}, + {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, -kProton}}, + {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, -kPhi}}, + {DecayChannelResoXiC::SigmaPiPi, std::array{-kSigmaPlus, +kPiPlus}}, }; } bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { - std::cout << "###"; for (int iArrDaugh : arrDaughIndex) { bool findDaug = false; for (int i = 0; i < 2; ++i) { - std::cout << "Checking daughter PDG: " << iArrDaugh << " against resonant PDG: " << arrPDGResonant[i] << std::endl; + // std::cout << "Checking daughter PDG: " << iArrDaugh << " against resonant PDG: " << arrPDGResonant[i] << std::endl; if (std::abs(iArrDaugh) == arrPDGResonant[i]) { findDaug = true; } } if (!findDaug) { - std::cout << "###"; return false; // If any daughter does not match, return false } } - std::cout << "###"; return true; } @@ -210,6 +207,7 @@ namespace o2::hf_corrbkg switch (motherPdg) { case Pdg::kD0: for (const auto& [flag, pdgCodes] : D0::resoStatesD0) { + // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -218,6 +216,7 @@ namespace o2::hf_corrbkg break; case Pdg::kDPlus: for (const auto& [flag, pdgCodes] : DPlus::resoStatesDPlus) { + // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -226,6 +225,7 @@ namespace o2::hf_corrbkg break; case Pdg::kDS: for (const auto& [flag, pdgCodes] : DS::resoStatesDs) { + // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -234,6 +234,7 @@ namespace o2::hf_corrbkg break; case Pdg::kDStar: for (const auto& [flag, pdgCodes] : DStar::resoStatesDStarD0) { + // std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -242,6 +243,7 @@ namespace o2::hf_corrbkg break; case Pdg::kLambdaCPlus: for (const auto& [flag, pdgCodes] : LambdaC::resoStatesLambdaC) { + // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -250,6 +252,7 @@ namespace o2::hf_corrbkg break; case Pdg::kXiCPlus: for (const auto& [flag, pdgCodes] : XiC::resoStatesXiC) { + // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = (1 << flag); break; @@ -276,7 +279,6 @@ namespace o2::hf_corrbkg // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgMotherI; // } LOG(info) << "Matching daughters ... "; - int matchedMotherId = 0; // auto finalStates = finalStates3Prongs; // if (std::abs(pdgMother) == Pdg::kD0) { @@ -377,14 +379,111 @@ namespace o2::hf_corrbkg arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(pdgMother, channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << chn; + LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << channel; break; } + break; // Exit loop if a match is found } } return indexRec; } + template + int matchFinalStateCorrBkgsGen(int pdgParticle, aod::McParticles const& mcParticles, const U& candidate, int8_t* sign, int depth, int8_t* flag, int8_t* channel) { + // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; + std::vector arrResoDaughIndex = {}; + // for (std::size_t iProng = 0; iProng < 3; ++iProng) { + // if (!arrayDaughters[iProng].has_mcParticle()) { + // return -1; + // } + // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle + // auto motherI = particleI.template mothers_first_as(); + // auto pdgI = particleI.pdgCode(); + // auto pdgParticleI = motherI.pdgCode(); + // auto pdgParticleII = -1; + // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgParticleI; + // } + + // auto finalStates = finalStates3Prongs; + // if (std::abs(pdgParticle) == Pdg::kD0) { + // finalStates = finalStates2Prongs; + // } + + bool matched = false; + // LOG(info) << "matched: " << matched; + for (const auto& [chn, finalState] : finalStates3Prongs) { + if (finalState.size() == 4) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1] << " " << finalState[2] << " " << finalState[3]; + // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, sign, depth); + matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + // RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1] << " " << finalState[2]; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1]; + std::array finalStateParts = std::array{finalState[0], finalState[1]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + if (matched) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgParticle << std::endl; + switch (pdgParticle) { + case Pdg::kD0: + *flag = (*sign) * chn + 10; + break; + case Pdg::kDPlus: + *flag = (*sign) * chn + 20; + break; + case Pdg::kDS: + *flag = (*sign) * chn + 30; + break; + case Pdg::kDStar: + *flag = (*sign) * chn + 40; + break; + case Pdg::kLambdaCPlus: + *flag = (*sign) * chn + 50; + break; + case Pdg::kXiCPlus: + *flag = (*sign) * chn + 60; + break; + default: + // LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; + continue; // Skip unknown mother PDG codes + } + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(pdgParticle) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances + } + RecoDecay::getDaughters(candidate, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + if ( (std::abs(pdgParticle) == Pdg::kDStar || std::abs(pdgParticle) == Pdg::kXiCPlus) + && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + } + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(pdgParticle, channel, arrPDGDaugh); + LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + break; + } + break; // Exit loop if a match is found + } + } + return matched; + } + + } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_CORRELATEDBKGS_H_ diff --git a/PWGHF/DataModel/CandidateReconstructionTables.h b/PWGHF/DataModel/CandidateReconstructionTables.h index 2d0c01224d0..3a6f1fd4788 100644 --- a/PWGHF/DataModel/CandidateReconstructionTables.h +++ b/PWGHF/DataModel/CandidateReconstructionTables.h @@ -642,6 +642,7 @@ DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); //! generator level DECLARE_SOA_COLUMN(OriginMcRec, originMcRec, int8_t); //! particle origin, reconstruction level DECLARE_SOA_COLUMN(OriginMcGen, originMcGen, int8_t); //! particle origin, generator level DECLARE_SOA_COLUMN(FlagMcDecayChanRec, flagMcDecayChanRec, int8_t); //! resonant decay channel flag, reconstruction level +DECLARE_SOA_COLUMN(FlagMcDecayChanGen, flagMcDecayChanGen, int8_t); //! resonant decay channel flag, reconstruction level // KF related properties DECLARE_SOA_COLUMN(KfGeoMassD0, kfGeoMassD0, float); //! mass of the D0 candidate from the KFParticle geometric fit @@ -766,6 +767,7 @@ DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //! DECLARE_SOA_TABLE(HfCand2ProngMcGen, "AOD", "HFCAND2PMCGEN", //! hf_cand_2prong::FlagMcMatchGen, hf_cand_2prong::OriginMcGen, + hf_cand_2prong::FlagMcDecayChanRec, hf_cand::IdxBhadMotherPart); // cascade decay candidate table diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 35dc57f832f..5511aedb40f 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -864,7 +864,7 @@ struct HfCandidateCreator2ProngExpressions { if (rejectionMask != 0) { // at least one event selection not satisfied --> reject all particles from this collision for (unsigned int i = 0; i < mcParticlesPerMcColl.size(); ++i) { - rowMcMatchGen(0, 0, -1); + rowMcMatchGen(0, 0, 0, -1); } continue; } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 25bb9fa66b3..d56343bd324 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1099,6 +1099,8 @@ struct HfCandidateCreator3ProngExpressions { LOG(info) << "--------------------------------------------"; } + LOG(info) << "Filling MC match gen for 3 prong candidates"; + LOG(info) << "Number of MC collisions: " << mcCollisions.size(); for (const auto& mcCollision : mcCollisions) { // Slice the particles table to get the particles for the current MC collision @@ -1107,17 +1109,21 @@ struct HfCandidateCreator3ProngExpressions { float centrality{-1.f}; uint16_t rejectionMask{0}; int nSplitColl = 0; - if constexpr (centEstimator == CentralityEstimator::FT0C) { - const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex()); - rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - } else if constexpr (centEstimator == CentralityEstimator::FT0M) { - const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0M, mcCollision.globalIndex()); - nSplitColl = collSlice.size(); - rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - } else if constexpr (centEstimator == CentralityEstimator::None) { - const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - } + // if constexpr (centEstimator == CentralityEstimator::FT0C) { + // LOG(info) << "FT0C centrality estimator"; + // const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex()); + // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + // } else if constexpr (centEstimator == CentralityEstimator::FT0M) { + // LOG(info) << "FT0M centrality estimator"; + // const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0M, mcCollision.globalIndex()); + // nSplitColl = collSlice.size(); + // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + // } else if constexpr (centEstimator == CentralityEstimator::None) { + // LOG(info) << "No centrality estimator"; + // const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + // } + // LOG(info) << "CIAO3"; hfEvSelMc.fillHistograms(mcCollision, rejectionMask, nSplitColl); if (rejectionMask != 0) { // at least one event selection not satisfied --> reject all gen particles from this collision @@ -1126,9 +1132,12 @@ struct HfCandidateCreator3ProngExpressions { } continue; } + // LOG(info) << "CIAO4"; if (matchCorrBkgs) { + // LOG(info) << "Filling MC match gen for correlated bkgs"; hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } else { + // LOG(info) << "Filling MC match gen"; hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index e039b3e394a..88f49d5bac4 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -238,7 +238,8 @@ DECLARE_SOA_TABLE(HfCandDpFullPs, "AOD", "HFCANDDPFULLP", full::Eta, full::Phi, full::Y, - hf_cand_3prong::FlagMcMatchRec, + hf_cand_3prong::FlagMcMatchGen, + hf_cand_3prong::FlagMcDecayChanGen, hf_cand_3prong::OriginMcGen); } // namespace o2::aod @@ -543,6 +544,7 @@ struct HfTreeCreatorDplusToPiKPi { } // Filling particle properties + LOG(info) << "Filling tree generated " << particles.size() << " particles"; rowCandidateFullParticles.reserve(particles.size()); for (const auto& particle : particles) { rowCandidateFullParticles( @@ -552,6 +554,7 @@ struct HfTreeCreatorDplusToPiKPi { particle.phi(), RecoDecay::y(particle.pVector(), o2::constants::physics::MassDPlus), particle.flagMcMatchGen(), + particle.flagMcDecayChanGen(), particle.originMcGen()); } } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 5ee455ed707..021339a2123 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -33,10 +33,12 @@ #include "PWGHF/Core/CorrelatedBkgs.h" +using namespace o2::hf_corrbkg; + namespace hf_mc_gen { -template +template void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { using namespace o2::constants::physics; @@ -45,41 +47,45 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; + int8_t channel = 0; // Not used in 2-prong decays int8_t sign = 0; std::vector idxBhadMothers{}; // Reject particles from background events if (particle.fromBackgroundEvent() && rejectBackground) { - rowMcMatchGen(flag, origin, -1); + rowMcMatchGen(flag, origin, channel, -1); continue; } + if (matchCorrBkgs) { + LOG(info) << "Matching gen correlated bkgs of 2prongs"; + } else { + // D0(bar) → π± K∓ + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) { + flag = sign * (1 << o2::aod::hf_cand_2prong::DecayType::D0ToPiK); + } - // D0(bar) → π± K∓ - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) { - flag = sign * (1 << o2::aod::hf_cand_2prong::DecayType::D0ToPiK); - } - - // J/ψ → e+ e− - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true)) { - flag = 1 << o2::aod::hf_cand_2prong::DecayType::JpsiToEE; + // J/ψ → e+ e− + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true)) { + flag = 1 << o2::aod::hf_cand_2prong::DecayType::JpsiToEE; + } } - } - // J/ψ → μ+ μ− - if (flag == 0) { - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true)) { - flag = 1 << o2::aod::hf_cand_2prong::DecayType::JpsiToMuMu; + // J/ψ → μ+ μ− + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true)) { + flag = 1 << o2::aod::hf_cand_2prong::DecayType::JpsiToMuMu; + } } - } - // Check whether the particle is non-prompt (from a b quark). - if (flag != 0) { - origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); - } - if (origin == RecoDecay::OriginType::NonPrompt) { - rowMcMatchGen(flag, origin, idxBhadMothers[0]); - } else { - rowMcMatchGen(flag, origin, -1); + // Check whether the particle is non-prompt (from a b quark). + if (flag != 0) { + origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); + } + if (origin == RecoDecay::OriginType::NonPrompt) { + rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); + } else { + rowMcMatchGen(flag, origin, channel, -1); + } } } } @@ -112,7 +118,19 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matchCorrBkgs) { LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching correlated bkgs of 3prongs"; + LOG(info) << "Matching gen correlated bkgs of 3prongs"; + std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + for (const auto& motherPdgCode : mothersPdgCodes) { + int maxDepth = 2; + if (motherPdgCode == Pdg::kDStar) { + maxDepth = 3; // to catch the D0 resonances + } + matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); + if (flag != 0) { + LOG(info) << "Matched!"; + break; + } + } } else { // D± → π± K∓ π± @@ -190,12 +208,16 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // Check whether the particle is non-prompt (from a b quark). + LOG(info) << "Flag: " << int(flag); if (flag != 0) { + LOG(info) << "Setting origin gen"; origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { + LOG(info) << "Origin is non-prompt"; rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { + LOG(info) << "Origin is prompt"; rowMcMatchGen(flag, origin, channel, -1); } } diff --git a/PWGJE/Tasks/CMakeLists.txt b/PWGJE/Tasks/CMakeLists.txt index 0e39c04445a..ea243aef9d6 100644 --- a/PWGJE/Tasks/CMakeLists.txt +++ b/PWGJE/Tasks/CMakeLists.txt @@ -68,10 +68,10 @@ if(FastJet_FOUND) SOURCES jetSubstructureD0.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore COMPONENT_NAME Analysis) - o2physics_add_dpl_workflow(jet-substructure-dplus - SOURCES jetSubstructureDplus.cxx - PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore - COMPONENT_NAME Analysis) + # o2physics_add_dpl_workflow(jet-substructure-dplus + # SOURCES jetSubstructureDplus.cxx + # PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore + # COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(jet-substructure-lc SOURCES jetSubstructureLc.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore diff --git a/PWGLF/Tasks/Resonances/CMakeLists.txt b/PWGLF/Tasks/Resonances/CMakeLists.txt index 4ba33fce401..9e00c6e3dbe 100644 --- a/PWGLF/Tasks/Resonances/CMakeLists.txt +++ b/PWGLF/Tasks/Resonances/CMakeLists.txt @@ -174,10 +174,10 @@ o2physics_add_dpl_workflow(highmasslambdasvx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(chk892flow - SOURCES chk892Flow.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) +# o2physics_add_dpl_workflow(chk892flow +# SOURCES chk892Flow.cxx +# PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore +# COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(chk892pp SOURCES chk892pp.cxx From 3d9adfed9311599164694cacaea5d45e33667727 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 29 May 2025 17:50:05 +0200 Subject: [PATCH 05/47] Fix gen matching --- Common/Core/RecoDecay.h | 12 +- PWGHF/Core/CorrelatedBkgs.h | 297 ++++++++++++------ .../TableProducer/candidateCreator3Prong.cxx | 34 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 53 ++-- PWGHF/Utils/utilsMcGen.h | 41 +-- 5 files changed, 271 insertions(+), 166 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 4608a0e063f..90f65759a0a 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -673,8 +673,8 @@ struct RecoDecay { // If the particle is labelled as final, we add this particle in the list of final daughters and exit. if (isFinal) { // printf("getDaughters: "); - for (int i = 0; i < stage; i++) // Indent to make the tree look nice. - std::cout << " "; + // for (int i = 0; i < stage; i++) // Indent to make the tree look nice. + // std::cout << " "; // printf(" "); // printf("Stage %d: Adding %d (PDG %d) as final daughter.\n", stage, index, pdgParticle); // std::cout << "[getDaughters] Adding particle " << particle.globalIndex() << " as final daughter with PDG code " << pdgParticle << std::endl; @@ -824,7 +824,7 @@ struct RecoDecay { for (auto i : arrAllDaughtersIndex) { std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; } - std::cout << " " << std::endl; + // std::cout << " " << std::endl; // Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs). if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != NDaug) { std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")" << std::endl; @@ -970,10 +970,10 @@ struct RecoDecay { // printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size()); // std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl; - for (auto i : arrAllDaughtersIndex) { + // for (auto i : arrAllDaughtersIndex) { // std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; - } - std::cout << " " << std::endl; + // } + // std::cout << " " << std::endl; // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 9fc21deb3be..a49df5f782a 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -209,7 +209,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : D0::resoStatesD0) { // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); break; } } @@ -218,7 +219,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : DPlus::resoStatesDPlus) { // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); break; } } @@ -227,7 +229,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : DS::resoStatesDs) { // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); break; } } @@ -236,7 +239,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : DStar::resoStatesDStarD0) { // std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); break; } } @@ -245,7 +249,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : LambdaC::resoStatesLambdaC) { // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); break; } } @@ -254,7 +259,8 @@ namespace o2::hf_corrbkg for (const auto& [flag, pdgCodes] : XiC::resoStatesXiC) { // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = (1 << flag); + *channel = flag; + LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); break; } } @@ -264,41 +270,42 @@ namespace o2::hf_corrbkg template int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; + // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; std::vector arrResoDaughIndex = {}; int indexRec = -1; // Index of the matched reconstructed candidate - // for (std::size_t iProng = 0; iProng < 3; ++iProng) { - // if (!arrayDaughters[iProng].has_mcParticle()) { - // return -1; - // } - // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle - // auto motherI = particleI.template mothers_first_as(); - // auto pdgI = particleI.pdgCode(); - // auto pdgMotherI = motherI.pdgCode(); - // auto pdgMotherII = -1; - // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgMotherI; - // } - LOG(info) << "Matching daughters ... "; - - // auto finalStates = finalStates3Prongs; - // if (std::abs(pdgMother) == Pdg::kD0) { - // finalStates = finalStates2Prongs; - // } - for (const auto& [chn, finalState] : finalStates3Prongs) { + const std::unordered_map>* finalStates = nullptr; + switch (pdgMother) { + case Pdg::kD0: + finalStates = reinterpret_cast>*>(&finalStates2Prongs); + break; + default: + finalStates = reinterpret_cast>*>(&finalStates3Prongs); + break; + } + + for (const auto& [chn, finalState] : *finalStates) { + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() == 4) { // Partly Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + } + + if (indexRec != -1) { + auto motherParticle = mcParticles.rawIteratorAt(indexRec); + std::array finalStatePartsAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStatePartsAll, false, sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay + } } - } else if (finalState.size() == 3 && std::abs(pdgMother) != Pdg::kD0) { // Fully Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -308,53 +315,30 @@ namespace o2::hf_corrbkg } else { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); } - } else if (finalState.size() == 3 && std::abs(pdgMother) == Pdg::kD0) { // Partly Reco 2-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1]}; - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); - } - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1]}; - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); - } } else { LOG(info) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } - LOG(info) << "IndexRec: " << indexRec; if (indexRec > -1) { - std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; + // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; switch (pdgMother) { case Pdg::kD0: - *flag = (*sign) * chn + 10; + *flag = (*sign) * (chn + 10); break; case Pdg::kDPlus: - *flag = (*sign) * chn + 20; + *flag = (*sign) * (chn + 20); break; case Pdg::kDS: - *flag = (*sign) * chn + 30; + *flag = (*sign) * (chn + 30); break; case Pdg::kDStar: - *flag = (*sign) * chn + 40; + *flag = (*sign) * (chn + 40); break; case Pdg::kLambdaCPlus: - *flag = (*sign) * chn + 50; + *flag = (*sign) * (chn + 50); break; case Pdg::kXiCPlus: - *flag = (*sign) * chn + 60; + *flag = (*sign) * (chn + 60); break; default: LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; @@ -379,7 +363,8 @@ namespace o2::hf_corrbkg arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(pdgMother, channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << channel; + LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); break; } break; // Exit loop if a match is found @@ -390,69 +375,56 @@ namespace o2::hf_corrbkg template int matchFinalStateCorrBkgsGen(int pdgParticle, aod::McParticles const& mcParticles, const U& candidate, int8_t* sign, int depth, int8_t* flag, int8_t* channel) { - // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; std::vector arrResoDaughIndex = {}; - // for (std::size_t iProng = 0; iProng < 3; ++iProng) { - // if (!arrayDaughters[iProng].has_mcParticle()) { - // return -1; - // } - // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle - // auto motherI = particleI.template mothers_first_as(); - // auto pdgI = particleI.pdgCode(); - // auto pdgParticleI = motherI.pdgCode(); - // auto pdgParticleII = -1; - // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgParticleI; - // } - - // auto finalStates = finalStates3Prongs; - // if (std::abs(pdgParticle) == Pdg::kD0) { - // finalStates = finalStates2Prongs; - // } - bool matched = false; - // LOG(info) << "matched: " << matched; - for (const auto& [chn, finalState] : finalStates3Prongs) { + + const std::unordered_map>* finalStates = nullptr; + switch (pdgParticle) { + case Pdg::kD0: + finalStates = reinterpret_cast>*>(&finalStates2Prongs); + break; + default: + finalStates = reinterpret_cast>*>(&finalStates3Prongs); + break; + } + + for (const auto& [chn, finalState] : *finalStates) { if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1] << " " << finalState[2] << " " << finalState[3]; - // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, sign, depth); matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - // RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1] << " " << finalState[2]; std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - // LOG(info) << "Matching final state: " << finalState[0] << " " << finalState[1]; std::array finalStateParts = std::array{finalState[0], finalState[1]}; matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); + LOG(info) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } if (matched) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgParticle << std::endl; switch (pdgParticle) { case Pdg::kD0: - *flag = (*sign) * chn + 10; + *flag = (*sign) * (chn + 10); break; case Pdg::kDPlus: - *flag = (*sign) * chn + 20; + *flag = (*sign) * (chn + 20); break; case Pdg::kDS: - *flag = (*sign) * chn + 30; + *flag = (*sign) * (chn + 30); break; case Pdg::kDStar: - *flag = (*sign) * chn + 40; + *flag = (*sign) * (chn + 40); break; case Pdg::kLambdaCPlus: - *flag = (*sign) * chn + 50; + *flag = (*sign) * (chn + 50); break; case Pdg::kXiCPlus: - *flag = (*sign) * chn + 60; + *flag = (*sign) * (chn + 60); break; default: - // LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; + LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; continue; // Skip unknown mother PDG codes } @@ -468,13 +440,15 @@ namespace o2::hf_corrbkg for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); if ( (std::abs(pdgParticle) == Pdg::kDStar || std::abs(pdgParticle) == Pdg::kXiCPlus) - && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi } + // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(pdgParticle, channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateDMeson] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << pdgParticle << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); break; } break; // Exit loop if a match is found @@ -487,3 +461,130 @@ namespace o2::hf_corrbkg } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_CORRELATEDBKGS_H_ + + + + // template + // int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { + // // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; + // std::vector arrResoDaughIndex = {}; + // int indexRec = -1; // Index of the matched reconstructed candidate + // // for (std::size_t iProng = 0; iProng < 3; ++iProng) { + // // if (!arrayDaughters[iProng].has_mcParticle()) { + // // return -1; + // // } + // // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle + // // auto motherI = particleI.template mothers_first_as(); + // // auto pdgI = particleI.pdgCode(); + // // auto pdgMotherI = motherI.pdgCode(); + // // auto pdgMotherII = -1; + // // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgMotherI; + // // } + + // // auto finalStates = finalStates3Prongs; + // // if (std::abs(pdgMother) == Pdg::kD0) { + // // finalStates = finalStates2Prongs; + // // } + + // for (const auto& [chn, finalState] : finalStates3Prongs) { + // if (finalState.size() == 4) { // Partly Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + // } + // } else if (finalState.size() == 3 && std::abs(pdgMother) != Pdg::kD0) { // Fully Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); + // } + // } else if (finalState.size() == 3 && std::abs(pdgMother) == Pdg::kD0) { // Partly Reco 2-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1]}; + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); + // } + // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1]}; + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); + // } + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // if (indexRec > -1) { + // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; + // switch (pdgMother) { + // case Pdg::kD0: + // *flag = (*sign) * (chn + 10); + // break; + // case Pdg::kDPlus: + // *flag = (*sign) * (chn + 20); + // break; + // case Pdg::kDS: + // *flag = (*sign) * (chn + 30); + // break; + // case Pdg::kDStar: + // *flag = (*sign) * (chn + 40); + // break; + // case Pdg::kLambdaCPlus: + // *flag = (*sign) * (chn + 50); + // break; + // case Pdg::kXiCPlus: + // *flag = (*sign) * (chn + 60); + // break; + // default: + // LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; + // continue; // Skip unknown mother PDG codes + // } + + // // Flag the resonant decay channel + // int resoMaxDepth = 1; + // int NDaughtersResonant = 2; + // if (std::abs(pdgMother) == Pdg::kDStar) { + // resoMaxDepth = 2; // Flag D0 resonances + // } + // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // std::vector arrPDGDaugh = {}; + // if (arrResoDaughIndex.size() == NDaughtersResonant) { + // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ( (std::abs(pdgMother) == Pdg::kDStar || std::abs(pdgMother) == Pdg::kXiCPlus) + // && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // } + // flagResonantDecay(pdgMother, channel, arrPDGDaugh); + // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + // break; + // } + // break; // Exit loop if a match is found + // } + // } + // return indexRec; + // } \ No newline at end of file diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index d56343bd324..f7f8cbed6ec 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -955,7 +955,6 @@ struct HfCandidateCreator3ProngExpressions { maxDepth = 3; // to catch the D0 resonances } if (indexRec <= -1) { - LOG(info) << "Matching " << motherPdgCode; if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -966,9 +965,6 @@ struct HfCandidateCreator3ProngExpressions { indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); } } - if (indexRec > -1) { - LOG(info) << "Matched!"; - } } LOG(info) << "D+ matching ended with flag " << static_cast(flag) << " and indexRec " << indexRec << ", sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { @@ -1092,8 +1088,10 @@ struct HfCandidateCreator3ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); + LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel; rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { + LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel; rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } LOG(info) << "--------------------------------------------"; @@ -1109,20 +1107,20 @@ struct HfCandidateCreator3ProngExpressions { float centrality{-1.f}; uint16_t rejectionMask{0}; int nSplitColl = 0; - // if constexpr (centEstimator == CentralityEstimator::FT0C) { - // LOG(info) << "FT0C centrality estimator"; - // const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex()); - // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - // } else if constexpr (centEstimator == CentralityEstimator::FT0M) { - // LOG(info) << "FT0M centrality estimator"; - // const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0M, mcCollision.globalIndex()); - // nSplitColl = collSlice.size(); - // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - // } else if constexpr (centEstimator == CentralityEstimator::None) { - // LOG(info) << "No centrality estimator"; - // const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - // rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); - // } + if constexpr (centEstimator == CentralityEstimator::FT0C) { + // LOG(info) << "FT0C centrality estimator"; + const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex()); + rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + } else if constexpr (centEstimator == CentralityEstimator::FT0M) { + // LOG(info) << "FT0M centrality estimator"; + const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0M, mcCollision.globalIndex()); + nSplitColl = collSlice.size(); + rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + } else if constexpr (centEstimator == CentralityEstimator::None) { + // LOG(info) << "No centrality estimator"; + const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); + } // LOG(info) << "CIAO3"; hfEvSelMc.fillHistograms(mcCollision, rejectionMask, nSplitColl); if (rejectionMask != 0) { diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 88f49d5bac4..2668b5f7773 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -246,7 +246,7 @@ DECLARE_SOA_TABLE(HfCandDpFullPs, "AOD", "HFCANDDPFULLP", /// Writes the full information in an output TTree struct HfTreeCreatorDplusToPiKPi { Produces rowCandidateFull; - Produces rowCandidateFullEvents; + Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; Produces rowCandidateMl; @@ -527,6 +527,7 @@ struct HfTreeCreatorDplusToPiKPi { fillEvent(collision, 0, 1); } + LOG(info) << "Filling reconstructed " << candidates.size() << " candidates"; // Filling candidate properties if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); @@ -544,9 +545,12 @@ struct HfTreeCreatorDplusToPiKPi { } // Filling particle properties - LOG(info) << "Filling tree generated " << particles.size() << " particles"; rowCandidateFullParticles.reserve(particles.size()); for (const auto& particle : particles) { + // LOG(info) << "Filling particle with pt: " << particle.pt() << ", eta: " << particle.eta() << ", phi: " << particle.phi(); + // LOG(info) << "Flag MC match gen: " << static_cast(particle.flagMcMatchGen()); + // LOG(info) << "Flag MC decay chan gen: " << static_cast(particle.flagMcDecayChanGen()); + // LOG(info) << "Origin MC gen: " << static_cast(particle.originMcGen()); rowCandidateFullParticles( particle.mcCollision().bcId(), particle.pt(), @@ -594,33 +598,34 @@ struct HfTreeCreatorDplusToPiKPi { PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcWCent, "Process MC with cent", false); void processMcSgnWMl(aod::Collisions const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, - MatchedGenCandidatesMc const& particles, - TracksWPid const& tracks) - { - fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); - } + aod::McCollisions const& mccollisions, + SelectedCandidatesMcWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); + } - PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWMl, "Process MC signal with ML info", false); + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWMl, "Process MC signal with ML info", false); void processMcSgnWCentMl(CollisionsCent const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, - MatchedGenCandidatesMc const& particles, - TracksWPid const& tracks) - { - fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); - } - - PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); + aod::McCollisions const& mccollisions, + SelectedCandidatesMcWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); + } + + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcCorrBkgsWithMl const&, - MatchedGenCandidatesMc const& particles, - TracksWPid const& tracks) - { + aod::McCollisions const& mccollisions, + SelectedCandidatesMcCorrBkgsWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " particles"; fillMcTables(collisions, mccollisions, reconstructedCandCorrBkgsMl, particles, tracks); } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 021339a2123..eda5db68ef6 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -49,6 +49,8 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V int8_t origin = 0; int8_t channel = 0; // Not used in 2-prong decays int8_t sign = 0; + bool matched = false; + int maxDepth = 2; // Default depth for matching std::vector idxBhadMothers{}; // Reject particles from background events if (particle.fromBackgroundEvent() && rejectBackground) { @@ -56,7 +58,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matchCorrBkgs) { - LOG(info) << "Matching gen correlated bkgs of 2prongs"; + matched = matchFinalStateCorrBkgsGen(Pdg::kD0, mcParticles, particle, &sign, maxDepth, &flag, &channel); } else { // D0(bar) → π± K∓ if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) { @@ -76,16 +78,16 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V flag = 1 << o2::aod::hf_cand_2prong::DecayType::JpsiToMuMu; } } + } - // Check whether the particle is non-prompt (from a b quark). - if (flag != 0) { - origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); - } - if (origin == RecoDecay::OriginType::NonPrompt) { - rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); - } else { - rowMcMatchGen(flag, origin, channel, -1); - } + // Check whether the particle is non-prompt (from a b quark). + if (flag != 0) { + origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); + } + if (origin == RecoDecay::OriginType::NonPrompt) { + rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); + } else { + rowMcMatchGen(flag, origin, channel, -1); } } } @@ -117,18 +119,17 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matchCorrBkgs) { - LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching gen correlated bkgs of 3prongs"; + // LOG(info) << "--------------------------------------------"; + // LOG(info) << "Matching gen correlated bkgs of 3prongs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; for (const auto& motherPdgCode : mothersPdgCodes) { int maxDepth = 2; + bool matched = false; if (motherPdgCode == Pdg::kDStar) { maxDepth = 3; // to catch the D0 resonances } - matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); - if (flag != 0) { - LOG(info) << "Matched!"; - break; + if (flag == 0) { + matched = matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); } } } else { @@ -208,16 +209,16 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // Check whether the particle is non-prompt (from a b quark). - LOG(info) << "Flag: " << int(flag); + // LOG(info) << "[Gen] Flag: " << static_cast(flag); if (flag != 0) { - LOG(info) << "Setting origin gen"; + // LOG(info) << "[Gen] Setting origin gen"; origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } + // LOG(info) << "[Gen] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); if (origin == RecoDecay::OriginType::NonPrompt) { - LOG(info) << "Origin is non-prompt"; + // LOG(info) << "Origin is non-prompt"; rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { - LOG(info) << "Origin is prompt"; rowMcMatchGen(flag, origin, channel, -1); } } From cb1072eadc926ca8bda3948d1c749b734b47fc54 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 29 May 2025 22:03:26 +0200 Subject: [PATCH 06/47] Moved functions to creator for 3 prong --- Common/Core/RecoDecay.h | 95 +++----- PWGHF/Core/CorrelatedBkgs.h | 225 +++++++++++------- .../TableProducer/candidateCreator2Prong.cxx | 24 +- .../TableProducer/candidateCreator3Prong.cxx | 117 +++++++-- PWGHF/Utils/utilsMcGen.h | 71 +++++- 5 files changed, 353 insertions(+), 179 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 90f65759a0a..6f5e433bb11 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,7 +25,6 @@ #include // std::apply #include // std::move #include // std::vector -#include // std::ostream // ROOT includes #include // for VMC Particle Production Process @@ -567,10 +566,8 @@ struct RecoDecay { while (!motherFound && arrayIds[-stage].size() > 0 && (depthMax < 0 || -stage < depthMax)) { // vector of mother indices for the current stage std::vector arrayIdsStage{}; - // std::cout << "[getMother] number of mothers at stage " << stage << ": " << arrayIds[-stage].size() << std::endl; 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) auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset()); - // std::cout << "[getMother] particleMother.pdgCode(): " << particleMother.pdgCode() << std::endl; if (particleMother.has_mothers()) { for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again @@ -579,9 +576,10 @@ struct RecoDecay { auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset()); // Check mother's PDG code. auto pdgParticleIMother = mother.pdgCode(); // PDG code of the mother - for (int i = stage; i < 0; i++) // Indent to make the tree look nice. - std::cout << " "; - // std::cout << "[getMother] Stage: " << stage << " Mother PDG: " << pdgParticleIMother << ", Index: " << iMother << std::endl; + // printf("getMother: "); + // for (int i = stage; i < 0; i++) // Indent to make the tree look nice. + // printf(" "); + // printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, pdgParticleIMother, iMother); if (pdgParticleIMother == pdgMother) { // exact PDG match sgn = 1; indexMother = iMother; @@ -642,7 +640,6 @@ struct RecoDecay { } bool isFinal = false; // Flag to indicate the end of recursion - // std::cout << "[getDaughters] Stage: " << static_cast(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast(depthMax) << std::endl; if (depthMax > -1 && stage >= depthMax) { // Maximum depth has been reached (or exceeded). isFinal = true; } @@ -650,7 +647,6 @@ struct RecoDecay { if (!isFinal && !particle.has_daughters()) { // If the original particle has no daughters, we do nothing and exit. if (stage == 0) { - // std::cout << "[getDaughters] No daughters of the original particle " << particle.globalIndex() << std::endl; // Printf("getDaughters: No daughters of %d", index); return; } @@ -662,10 +658,8 @@ struct RecoDecay { if (!isFinal && stage > 0) { // If the particle has daughters but is considered to be final, we label it as final. for (auto pdgI : arrPdgFinal) { // o2-linter: disable=const-ref-in-for-loop (int elements) - // std::cout << "[getDaughters] Checking PDG code: " << pdgI << " with " << pdgParticle << std::endl; if (pdgParticle == std::abs(pdgI)) { // Accept antiparticles. isFinal = true; - // std::cout << "[getDaughters] Particle " << particle.globalIndex() << " is final with PDG code " << pdgParticle << std::endl; break; } } @@ -674,17 +668,14 @@ struct RecoDecay { if (isFinal) { // printf("getDaughters: "); // for (int i = 0; i < stage; i++) // Indent to make the tree look nice. - // std::cout << " "; - // printf(" "); + // printf(" "); // printf("Stage %d: Adding %d (PDG %d) as final daughter.\n", stage, index, pdgParticle); - // std::cout << "[getDaughters] Adding particle " << particle.globalIndex() << " as final daughter with PDG code " << pdgParticle << std::endl; list->push_back(particle.globalIndex()); return; } // If we are here, we have to follow the daughter tree. // printf("getDaughters: "); - for (int i = 0; i < stage; i++) // Indent to make the tree look nice. - std::cout << " "; + // for (int i = 0; i < stage; i++) // Indent to make the tree look nice. // printf(" "); // printf("Stage %d: %d (PDG %d) -> %d-%d\n", stage, index, pdgParticle, indexDaughterFirst, indexDaughterLast); // Call itself to get daughters of daughters recursively. @@ -711,11 +702,11 @@ struct RecoDecay { /// \param nKaToPi number of kaon prongs decayed to a pion /// \param nInteractionsWithMaterial number of daughter particles that interacted with material /// \return index of the mother particle if the mother and daughters are correct, -1 otherwise - template + template static int getMatchedMCRec(const T& particlesMC, - const std::array& arrDaughters, + const std::array& arrDaughters, int pdgMother, - std::array arrPdgDaughters, + std::array arrPdgDaughters, bool acceptAntiParticles = false, int8_t* sign = nullptr, int depthMax = 1, @@ -731,13 +722,13 @@ struct RecoDecay { int8_t nInteractionsWithMaterialLocal = 0; // number of interactions with material int indexMother = -1; // index of the mother particle std::vector arrAllDaughtersIndex; // vector of indices of all daughters of the mother of the first provided daughter - std::array arrDaughtersIndex; // array of indices of provided daughters + std::array arrDaughtersIndex; // array of indices of provided daughters if (sign) { *sign = sgn; } if constexpr (acceptFlavourOscillation) { // Loop over decay candidate prongs to spot possible oscillation decay product - for (std::size_t iProng = 0; iProng < NDaug; ++iProng) { + for (std::size_t iProng = 0; iProng < N; ++iProng) { if (!arrDaughters[iProng].has_mcParticle()) { return -1; } @@ -749,7 +740,7 @@ struct RecoDecay { } } // Loop over decay candidate prongs - for (std::size_t iProng = 0; iProng < NDaug; ++iProng) { + for (std::size_t iProng = 0; iProng < N; ++iProng) { if (!arrDaughters[iProng].has_mcParticle()) { return -1; } @@ -799,43 +790,33 @@ struct RecoDecay { indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax); // Check whether mother was found. if (indexMother <= -1) { - // std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl; + // Printf("MC Rec: Rejected: bad mother index or PDG"); return -1; } - std::cout << "MC Rec: Good mother: " << indexMother << std::endl; + // Printf("MC Rec: Good mother: %d", indexMother); auto particleMother = particlesMC.rawIteratorAt(indexMother - particlesMC.offset()); // Check the daughter indices. if (!particleMother.has_daughters()) { - // std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl; + // Printf("MC Rec: Rejected: bad daughter index range: %d-%d", particleMother.daughtersIds().front(), particleMother.daughtersIds().back()); return -1; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!acceptIncompleteReco && !checkProcess) { - if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast(NDaug)) { - std::cout << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 - << " (expected " << NDaug << " final)" << std::endl; - // Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, NDaug); + if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast(N)) { + // Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, N); return -1; } } // Get the list of actual final daughters. getDaughters(particleMother, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - std::cout << "MC Rec: Mother " << indexMother << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl; - for (auto i : arrAllDaughtersIndex) { - std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; - } - // std::cout << " " << std::endl; + // printf("MC Rec: Mother %d has %d final daughters:", indexMother, arrAllDaughtersIndex.size()); + // for (auto i : arrAllDaughtersIndex) { + // printf(" %d", i); + // } + // printf("\n"); // Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs). - if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != NDaug) { - std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")" << std::endl; - // LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")"; - // Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug); - return -1; - } - if (forceIncompleteReco && arrAllDaughtersIndex.size() == NDaug) { - std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << "vs Number of daughters " << NDaug << ", expected incomplete reco" << std::endl; - // LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")"; - // Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug); + if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != N) { + // Printf("MC Rec: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return -1; } } @@ -843,7 +824,6 @@ struct RecoDecay { // (Check that the daughter is not a stepdaughter, i.e. particle pointing to the mother while not being its daughter.) bool isDaughterFound = false; // Is the index of this prong among the remaining expected indices of daughters? for (std::size_t iD = 0; iD < arrAllDaughtersIndex.size(); ++iD) { - // std::cout << "MC Rec: Checking daughter " << iProng << " index: " << arrDaughtersIndex[iProng] << " against expected index: " << arrAllDaughtersIndex[iD] << std::endl; if (arrDaughtersIndex[iProng] == arrAllDaughtersIndex[iD]) { arrAllDaughtersIndex[iD] = -1; // Remove this index from the array of expected daughters. (Rejects twin daughters, i.e. particle considered twice as a daughter.) isDaughterFound = true; @@ -851,14 +831,14 @@ struct RecoDecay { } } if (!isDaughterFound) { - // std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl; + // Printf("MC Rec: Rejected: bad daughter index: %d not in the list of final daughters", arrDaughtersIndex[iProng]); return -1; } // Check daughter's PDG code. auto pdgParticleI = particleI.pdgCode(); // PDG code of the ith daughter - // std::cout << "MC Rec: Daughter " << iProng << " PDG: " << pdgParticleI << std::endl; + // Printf("MC Rec: Daughter %d PDG: %d", iProng, pdgParticleI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? - for (std::size_t iProngCp = 0; iProngCp < NDaug; ++iProngCp) { + for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { if (pdgParticleI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) { arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones. isPdgFound = true; @@ -866,11 +846,11 @@ struct RecoDecay { } } if (!isPdgFound) { - // std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl; + // Printf("MC Rec: Rejected: bad daughter PDG: %d", pdgParticleI); return -1; } } - std::cout << "MC Rec: Accepted: m: " << indexMother << std::endl; + // Printf("MC Rec: Accepted: m: %d", indexMother); if (sign) { *sign = sgn; } @@ -939,13 +919,11 @@ struct RecoDecay { // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); - // std::cout << "MC Gen: Candidate PDG: " << pdgCandidate << std::endl; if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match sgn = -1; } else { - // std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl; // Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle)); return false; } @@ -967,18 +945,14 @@ struct RecoDecay { } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - - // printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size()); - // std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl; + // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { - // std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , "; + // printf(" %d", i); // } - // std::cout << " " << std::endl; // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { - // std::cout << "MC Gen: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; - // Printf("MC Gen: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), N); + // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } if constexpr (acceptFlavourOscillation) { @@ -995,7 +969,6 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter - // std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { @@ -1006,7 +979,6 @@ struct RecoDecay { } } if (!isPdgFound) { - // std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl; // Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI); return false; } @@ -1015,7 +987,6 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } - std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; @@ -1480,4 +1451,4 @@ struct RecoDecayPtEtaPhiBase { using RecoDecayPtEtaPhi = RecoDecayPtEtaPhiBase<>; // alias for instance with default parameters -#endif // COMMON_CORE_RECODECAY_H_ +#endif // COMMON_CORE_RECODECAY_H_ \ No newline at end of file diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index a49df5f782a..056ff2f635b 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -29,8 +29,8 @@ namespace o2::hf_corrbkg { enum FinalStates2Prongs { - PiK = 1, - KPi, + KPi = 1, + KK, KPiPi0, PiPi, PiPiPi0, @@ -39,11 +39,11 @@ namespace o2::hf_corrbkg std::unordered_map > finalStates2Prongs = { - {FinalStates2Prongs::PiK, std::vector{+kPiPlus, -kKPlus}}, - {FinalStates2Prongs::KPi, std::vector{-kKPlus, +kPiPlus}}, - {FinalStates2Prongs::KPiPi0, std::vector{-kKPlus, +kPiPlus, +kPi0}}, - {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, - {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + {FinalStates2Prongs::KPi, std::vector{+kKMinus, +kPiPlus}}, + {FinalStates2Prongs::KK, std::vector{+kKMinus, +kKPlus}}, + {FinalStates2Prongs::KPiPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, + {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, + {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} }; enum FinalStates3Prongs { @@ -60,50 +60,51 @@ namespace o2::hf_corrbkg std::unordered_map > finalStates3Prongs = { - {FinalStates3Prongs::KKPi, std::vector{-kKPlus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KKPiPi0, std::vector{-kKPlus, +kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KPiPi, std::vector{+kPiPlus, -kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KPiPiPi0, std::vector{+kPiPlus, -kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonKPi, std::vector{kProton, -kKPlus, +kPiPlus}} + {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::KPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}} }; // Dstar → K± K∓ π± namespace D0 { enum DecayChannelResoD0 { - RhoK = 1, + RhoPi = 1, + RhoK, K0starPi0, K0starPiPlus, - RhoPi, }; std::unordered_map > resoStatesD0 = { - {DecayChannelResoD0::RhoK, std::array{213, -kKPlus}}, - {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoD0::K0starPiPlus, std::array{-323, +kKPlus}}, - {DecayChannelResoD0::RhoPi, std::array{213, -kPiPlus}}, + {DecayChannelResoD0::RhoPi, std::array{213, +kPiMinus}}, + {DecayChannelResoD0::RhoK, std::array{213, +kKMinus}}, + {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResoD0::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, }; } // D± → K± K∓ π± namespace DPlus { enum DecayChannelResoDplus { - K0starK = 1, + PhiPi = 1, + K0starK, K_1430K, - PhiPi, RhoPi, f2_1270Pi, }; std::unordered_map > resoStatesDPlus = { - {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoDplus::K_1430K, std::array{-10321, -kKPlus}}, {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResoDplus::K_1430K, std::array{-10321, +kKPlus}}, {DecayChannelResoDplus::RhoPi, std::array{+113, +kPiPlus}}, - {DecayChannelResoDplus::f2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResoDplus::f2_1270Pi, std::array{+225, +kPiPlus}}, }; } @@ -111,41 +112,45 @@ namespace o2::hf_corrbkg namespace DS { enum DecayChannelResoDs { PhiPi = 1, - K0starK, PhiRho, - f2_1270Pi, + K0starK, K0starPi, + RhoPi, RhoK, EtaPi, + f2_1270Pi, + f2_1370K, }; std::unordered_map > resoStatesDs = { - {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResoDs::K0starK, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoDs::PhiRho, std::array{-kPhi, -113}}, - {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, - {DecayChannelResoDs::K0starPi, std::array{-kK0Star892, -kPiPlus}}, - {DecayChannelResoDs::RhoK, std::array{-113, -kKPlus}}, - {DecayChannelResoDs::EtaPi, std::array{-221, -kPiPlus}}, + {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResoDs::PhiRho, std::array{+kPhi, +213}}, + {DecayChannelResoDs::K0starK, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResoDs::K0starPi, std::array{+kK0Star892, +kPiPlus}}, + {DecayChannelResoDs::RhoK, std::array{113, +kKPlus}}, + {DecayChannelResoDs::RhoPi, std::array{113, +kPiPlus}}, + {DecayChannelResoDs::EtaPi, std::array{221, +kPiPlus}}, + {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResoDs::f2_1370K, std::array{10221, +kKPlus}}, }; } // Dstar → K± K∓ π± namespace DStar { enum DecayChannelResoDStarD0 { - RhoK = 1, + RhoPi = 1, + RhoK, K0starPi0, K0starPiPlus, - RhoPi, }; std::unordered_map > resoStatesDStarD0 = { - {DecayChannelResoDStarD0::RhoK, std::array{213, -kKPlus}}, - {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, -kKPlus}}, - {DecayChannelResoDStarD0::K0starPiPlus, std::array{-323, kKPlus}}, - {DecayChannelResoDStarD0::RhoPi, std::array{213, -kPiPlus}}, + {DecayChannelResoDStarD0::RhoPi, std::array{213, +kPiMinus}}, + {DecayChannelResoDStarD0::RhoK, std::array{213, +kKMinus}}, + {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResoDStarD0::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, }; } @@ -153,17 +158,17 @@ namespace o2::hf_corrbkg namespace LambdaC { enum DecayChannelResoLambdaC { K0starP = 1, + ProtonPhi, DeltaK, Lambda1520Pi, - ProtonPhi, }; std::unordered_map > resoStatesLambdaC = { - {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, -kProton}}, - {DecayChannelResoLambdaC::DeltaK, std::array{+2224, -kKPlus}}, - {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, -kPiPlus}}, - {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, -kPhi}}, + {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, +kProton}}, + {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, +kPhi}}, + {DecayChannelResoLambdaC::DeltaK, std::array{+2224, +kKMinus}}, + {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, +kPiPlus}}, }; } @@ -177,9 +182,9 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesXiC = { - {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, -kProton}}, - {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, -kPhi}}, - {DecayChannelResoXiC::SigmaPiPi, std::array{-kSigmaPlus, +kPiPlus}}, + {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, +kProton}}, + {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, +kPhi}}, + {DecayChannelResoXiC::SigmaPiPi, std::array{+kSigmaPlus, +kPiPlus}}, }; } @@ -277,47 +282,85 @@ namespace o2::hf_corrbkg const std::unordered_map>* finalStates = nullptr; switch (pdgMother) { case Pdg::kD0: - finalStates = reinterpret_cast>*>(&finalStates2Prongs); - break; + finalStates = reinterpret_cast>*>(&finalStates2Prongs); + break; default: - finalStates = reinterpret_cast>*>(&finalStates3Prongs); - break; + finalStates = reinterpret_cast>*>(&finalStates3Prongs); + break; } - + for (const auto& [chn, finalState] : *finalStates) { - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() == 4) { // Partly Reco 3-prong decays - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); - } - - if (indexRec != -1) { - auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStatePartsAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStatePartsAll, false, sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay + switch (pdgMother) { + // case Pdg::kD0: + // std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; + // if (finalState.size() == 3) { // Partly Reco 2-prong decays + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); + // } + + // if (indexRec != -1) { + // auto motherParticle = mcParticles.rawIteratorAt(indexRec); + // std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts2ProngAll, false, sign, depth)) { + // indexRec = -1; // Reset indexRec if the generated decay + // } + // } + // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); + // } + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // break; + default: + std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; + if (finalState.size() == 4) { // Partly Reco 3-prong decays + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); + } + + if (indexRec != -1) { + auto motherParticle = mcParticles.rawIteratorAt(indexRec); + std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts3ProngAll, false, sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay + } + } + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); + } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); + } + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states } - } - - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); - } - } else { - LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states + break; } if (indexRec > -1) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; @@ -356,8 +399,10 @@ namespace o2::hf_corrbkg if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(pdgMother) == Pdg::kDStar || std::abs(pdgMother) == Pdg::kXiCPlus) - && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + if ( (std::abs(pdgMother) == Pdg::kDStar) || + ( (std::abs(pdgMother) == Pdg::kXiCPlus) && + (std::abs(daughI.pdgCode()) == kPiPlus) && + (arrPDGDaugh.size() >= 2) ) ) { continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi } arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); @@ -439,8 +484,10 @@ namespace o2::hf_corrbkg if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(pdgParticle) == Pdg::kDStar || std::abs(pdgParticle) == Pdg::kXiCPlus) - && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { + if ( (std::abs(pdgParticle) == Pdg::kDStar) || + ( (std::abs(pdgParticle) == Pdg::kXiCPlus) && + (std::abs(daughI.pdgCode()) == kPiPlus) && + (arrPDGDaugh.size() >= 2) ) ) { continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi } // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 5511aedb40f..564e093bdd1 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -776,18 +776,18 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { LOG(info) << "--------------------------------------------"; LOG(info) << "Matching correlated bkgs of " << Pdg::kD0; - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - } else { - indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - } - if (indexRec > -1) { - LOG(info) << "Matched!"; - } + // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + // } else { + // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); + // } + // if (indexRec > -1) { + // LOG(info) << "Matched!"; + // } } else { // D0(bar) → π± K∓ if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index f7f8cbed6ec..22cb5efd522 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -949,24 +949,114 @@ struct HfCandidateCreator3ProngExpressions { LOG(info) << "--------------------------------------------"; LOG(info) << "Matching correlated bkgs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - for (const auto& motherPdgCode : mothersPdgCodes) { - int maxDepth = 2; - if (motherPdgCode == Pdg::kDStar) { - maxDepth = 3; // to catch the D0 resonances + indexRec = -1; // Index of the matched reconstructed candidate + std::vector arrResoDaughIndex = {}; + // const std::unordered_map>* finalStates = nullptr; + // switch (pdgMother) { + // case Pdg::kD0: + // finalStates = reinterpret_cast>*>(&finalStates2Prongs); + // break; + // default: + // finalStates = reinterpret_cast>*>(&finalStates3Prongs); + // break; + // } + + for (const auto& pdg : mothersPdgCodes) { + int depth = 2; + if (pdg == Pdg::kDStar) { + depth = 3; // D0 resonant decays are active } - if (indexRec <= -1) { - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + for (const auto& [chn, finalState] : finalStates3Prongs) { + std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; + if (finalState.size() == 4) { // Partly Reco 3-prong decays + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); + + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + } + + if (indexRec != -1) { + auto motherParticle = mcParticles.rawIteratorAt(indexRec); + std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay + } + } + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + } } else { - indexRec = matchFinalStateCorrBkgs(motherPdgCode, mcParticles, arrayDaughters, &flag, &sign, &channel, maxDepth, &nKinkedTracks, &nInteractionsWithMaterial); + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + if (indexRec > -1) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; + switch (pdg) { + case Pdg::kD0: + flag = sign * (chn + 10); + break; + case Pdg::kDPlus: + flag = sign * (chn + 20); + break; + case Pdg::kDS: + flag = sign * (chn + 30); + break; + case Pdg::kDStar: + flag = sign * (chn + 40); + break; + case Pdg::kLambdaCPlus: + flag = sign * (chn + 50); + break; + case Pdg::kXiCPlus: + flag = sign * (chn + 60); + break; + default: + LOG(info) << "Unknown mother PDG code: " << pdg << ", skipping."; + continue; // Skip unknown mother PDG codes + } + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(pdg) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances + } + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + if ( (std::abs(pdg) == Pdg::kDStar) || + ( (std::abs(pdg) == Pdg::kXiCPlus) && + (std::abs(daughI.pdgCode()) == kPiPlus) && + (arrPDGDaugh.size() >= 2) ) ) { + continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + } + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(pdg, &channel, arrPDGDaugh); + LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdg << ", flag: " << flag << ", &sign: " << sign; + LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << flag << " sign: " << sign << " for channel: " << channel; + break; + } + break; // Exit loop if a match is found } } } - LOG(info) << "D+ matching ended with flag " << static_cast(flag) << " and indexRec " << indexRec << ", sign " << static_cast(sign) << ", channel " << static_cast(channel); + LOG(info) << "D+ matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± LOG(info) << "--------------------------------------------"; @@ -1094,7 +1184,6 @@ struct HfCandidateCreator3ProngExpressions { LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel; rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } - LOG(info) << "--------------------------------------------"; } LOG(info) << "Filling MC match gen for 3 prong candidates"; diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index eda5db68ef6..6aa2bf7ba60 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -128,9 +128,76 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (motherPdgCode == Pdg::kDStar) { maxDepth = 3; // to catch the D0 resonances } - if (flag == 0) { - matched = matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); + + std::vector arrResoDaughIndex = {}; + for (const auto& [chn, finalState] : finalStates3Prongs) { + if (finalState.size() == 4) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + if (matched) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; + switch (motherPdgCode) { + case Pdg::kD0: + flag = sign * (chn + 10); + break; + case Pdg::kDPlus: + flag = sign * (chn + 20); + break; + case Pdg::kDS: + flag = sign * (chn + 30); + break; + case Pdg::kDStar: + flag = sign * (chn + 40); + break; + case Pdg::kLambdaCPlus: + flag = sign * (chn + 50); + break; + case Pdg::kXiCPlus: + flag = sign * (chn + 60); + break; + default: + LOG(info) << "Unknown mother PDG code: " << motherPdgCode << ", skipping."; + continue; // Skip unknown mother PDG codes + } + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(motherPdgCode) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances + } + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + if ( (std::abs(motherPdgCode) == Pdg::kDStar) || + ( (std::abs(motherPdgCode) == Pdg::kXiCPlus) && + (std::abs(daughI.pdgCode()) == kPiPlus) && + (arrPDGDaugh.size() >= 2) ) ) { + continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + } + // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + break; + } + break; // Exit loop if a match is found + } } + // if (flag == 0) { + // matched = matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); + // } } } else { From aef3aa352f1f6dd9040802403608f93a0f9fc9df Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 30 May 2025 14:18:14 +0200 Subject: [PATCH 07/47] Move functions to creators --- PWGHF/Core/CorrelatedBkgs.h | 544 ++++++++++-------- .../DataModel/CandidateReconstructionTables.h | 2 +- .../TableProducer/candidateCreator2Prong.cxx | 76 ++- .../TableProducer/candidateCreator3Prong.cxx | 23 +- PWGHF/TableProducer/candidateSelectorD0.cxx | 10 +- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 33 +- PWGHF/Utils/utilsMcGen.h | 61 +- 7 files changed, 483 insertions(+), 266 deletions(-) diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 056ff2f635b..6e0652c71ee 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -102,7 +102,7 @@ namespace o2::hf_corrbkg { {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResoDplus::K_1430K, std::array{-10321, +kKPlus}}, + {DecayChannelResoDplus::K_1430K, std::array{+10311, +kKPlus}}, {DecayChannelResoDplus::RhoPi, std::array{+113, +kPiPlus}}, {DecayChannelResoDplus::f2_1270Pi, std::array{+225, +kPiPlus}}, }; @@ -128,8 +128,8 @@ namespace o2::hf_corrbkg {DecayChannelResoDs::PhiRho, std::array{+kPhi, +213}}, {DecayChannelResoDs::K0starK, std::array{-kK0Star892, +kKPlus}}, {DecayChannelResoDs::K0starPi, std::array{+kK0Star892, +kPiPlus}}, - {DecayChannelResoDs::RhoK, std::array{113, +kKPlus}}, {DecayChannelResoDs::RhoPi, std::array{113, +kPiPlus}}, + {DecayChannelResoDs::RhoK, std::array{113, +kKPlus}}, {DecayChannelResoDs::EtaPi, std::array{221, +kPiPlus}}, {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, {DecayChannelResoDs::f2_1370K, std::array{10221, +kKPlus}}, @@ -165,7 +165,7 @@ namespace o2::hf_corrbkg std::unordered_map > resoStatesLambdaC = { - {DecayChannelResoLambdaC::K0starP, std::array{-kK0Star892, +kProton}}, + {DecayChannelResoLambdaC::K0starP, std::array{+kK0Star892, +kProton}}, {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, +kPhi}}, {DecayChannelResoLambdaC::DeltaK, std::array{+2224, +kKMinus}}, {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, +kPiPlus}}, @@ -189,18 +189,26 @@ namespace o2::hf_corrbkg } bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { - for (int iArrDaugh : arrDaughIndex) { + std::array arrPDGResonantAbs = {std::abs(arrPDGResonant[0]), std::abs(arrPDGResonant[1])}; + LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; + for (int i = 0; i < 2; i++) { + LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; bool findDaug = false; - for (int i = 0; i < 2; ++i) { - // std::cout << "Checking daughter PDG: " << iArrDaugh << " against resonant PDG: " << arrPDGResonant[i] << std::endl; - if (std::abs(iArrDaugh) == arrPDGResonant[i]) { + for (int j = 0; j < 2; j++) { + LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonantAbs[j]; + if (std::abs(arrDaughIndex[i]) == arrPDGResonantAbs[j]) { + arrPDGResonantAbs[j] = -1; // Mark as found + LOG(info) << "Matched!"; findDaug = true; + break; // If a daughter matches, break the inner loop } } if (!findDaug) { + LOG(info) << "Returning false"; return false; // If any daughter does not match, return false } } + LOG(info) << "Resonant decay found with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; return true; } @@ -212,7 +220,7 @@ namespace o2::hf_corrbkg switch (motherPdg) { case Pdg::kD0: for (const auto& [flag, pdgCodes] : D0::resoStatesD0) { - // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = flag; LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); @@ -271,243 +279,315 @@ namespace o2::hf_corrbkg } break; } + LOG(info) << "Leaving function with channel: " << static_cast(*channel); } - template - int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; - std::vector arrResoDaughIndex = {}; - int indexRec = -1; // Index of the matched reconstructed candidate +} // namespace o2::hf_corrbkg - const std::unordered_map>* finalStates = nullptr; - switch (pdgMother) { - case Pdg::kD0: - finalStates = reinterpret_cast>*>(&finalStates2Prongs); - break; - default: - finalStates = reinterpret_cast>*>(&finalStates3Prongs); - break; - } +#endif // PWGHF_CORE_CORRELATEDBKGS_H_ + + + + + + + + + + + + + + + + + + + + // template + // int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { + // // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; + // std::vector arrResoDaughIndex = {}; + // int indexRec = -1; // Index of the matched reconstructed candidate + + // const std::unordered_map>* finalStates = nullptr; + // switch (pdgMother) { + // case Pdg::kD0: + // finalStates = reinterpret_cast>*>(&finalStates2Prongs); + // break; + // default: + // finalStates = reinterpret_cast>*>(&finalStates3Prongs); + // break; + // } - for (const auto& [chn, finalState] : *finalStates) { - switch (pdgMother) { - // case Pdg::kD0: - // std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; - // if (finalState.size() == 3) { // Partly Reco 2-prong decays - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); - // } + // for (const auto& [chn, finalState] : *finalStates) { + // switch (pdgMother) { + // // case Pdg::kD0: + // // std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; + // // if (finalState.size() == 3) { // Partly Reco 2-prong decays + // // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); + // // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // // } else { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); + // // } - // if (indexRec != -1) { - // auto motherParticle = mcParticles.rawIteratorAt(indexRec); - // std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; - // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts2ProngAll, false, sign, depth)) { - // indexRec = -1; // Reset indexRec if the generated decay - // } - // } - // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); - // } - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // break; - default: - std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() == 4) { // Partly Reco 3-prong decays - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); - } + // // if (indexRec != -1) { + // // auto motherParticle = mcParticles.rawIteratorAt(indexRec); + // // std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + // // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts2ProngAll, false, sign, depth)) { + // // indexRec = -1; // Reset indexRec if the generated decay + // // } + // // } + // // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + // // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); + // // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // // } else { + // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); + // // } + // // } else { + // // LOG(info) << "Final state size not supported: " << finalState.size(); + // // continue; // Skip unsupported final states + // // } + // // break; + // default: + // std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; + // if (finalState.size() == 4) { // Partly Reco 3-prong decays + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); + // } - if (indexRec != -1) { - auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts3ProngAll, false, sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay - } - } - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); - } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); - } - } else { - LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states - } - break; - } - if (indexRec > -1) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; - switch (pdgMother) { - case Pdg::kD0: - *flag = (*sign) * (chn + 10); - break; - case Pdg::kDPlus: - *flag = (*sign) * (chn + 20); - break; - case Pdg::kDS: - *flag = (*sign) * (chn + 30); - break; - case Pdg::kDStar: - *flag = (*sign) * (chn + 40); - break; - case Pdg::kLambdaCPlus: - *flag = (*sign) * (chn + 50); - break; - case Pdg::kXiCPlus: - *flag = (*sign) * (chn + 60); - break; - default: - LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; - continue; // Skip unknown mother PDG codes - } + // if (indexRec != -1) { + // auto motherParticle = mcParticles.rawIteratorAt(indexRec); + // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; + // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts3ProngAll, false, sign, depth)) { + // indexRec = -1; // Reset indexRec if the generated decay + // } + // } + // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); + // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); + // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); + // } + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // break; + // } + // if (indexRec > -1) { + // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; + // switch (pdgMother) { + // case Pdg::kD0: + // *flag = (*sign) * (chn + 10); + // break; + // case Pdg::kDPlus: + // *flag = (*sign) * (chn + 20); + // break; + // case Pdg::kDS: + // *flag = (*sign) * (chn + 30); + // break; + // case Pdg::kDStar: + // *flag = (*sign) * (chn + 40); + // break; + // case Pdg::kLambdaCPlus: + // *flag = (*sign) * (chn + 50); + // break; + // case Pdg::kXiCPlus: + // *flag = (*sign) * (chn + 60); + // break; + // default: + // LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; + // continue; // Skip unknown mother PDG codes + // } - // Flag the resonant decay channel - int resoMaxDepth = 1; - int NDaughtersResonant = 2; - if (std::abs(pdgMother) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances - } - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; - if (arrResoDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(pdgMother) == Pdg::kDStar) || - ( (std::abs(pdgMother) == Pdg::kXiCPlus) && - (std::abs(daughI.pdgCode()) == kPiPlus) && - (arrPDGDaugh.size() >= 2) ) ) { - continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - } - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - } - flagResonantDecay(pdgMother, channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - break; - } - break; // Exit loop if a match is found - } - } - return indexRec; - } - - template - int matchFinalStateCorrBkgsGen(int pdgParticle, aod::McParticles const& mcParticles, const U& candidate, int8_t* sign, int depth, int8_t* flag, int8_t* channel) { - std::vector arrResoDaughIndex = {}; - bool matched = false; + // // Flag the resonant decay channel + // int resoMaxDepth = 1; + // int NDaughtersResonant = 2; + // if (std::abs(pdgMother) == Pdg::kDStar) { + // resoMaxDepth = 2; // Flag D0 resonances + // } + // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // std::vector arrPDGDaugh = {}; + // if (arrResoDaughIndex.size() == NDaughtersResonant) { + // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ( (std::abs(pdgMother) == Pdg::kDStar) || + // ( (std::abs(pdgMother) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // } + // flagResonantDecay(pdgMother, channel, arrPDGDaugh); + // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + // break; + // } + // break; // Exit loop if a match is found + // } + // } + // return indexRec; + // } - const std::unordered_map>* finalStates = nullptr; - switch (pdgParticle) { - case Pdg::kD0: - finalStates = reinterpret_cast>*>(&finalStates2Prongs); - break; - default: - finalStates = reinterpret_cast>*>(&finalStates3Prongs); - break; - } + // template + // int matchFinalStateCorrBkgsGen(int pdgParticle, aod::McParticles const& mcParticles, const U& candidate, int8_t* sign, int depth, int8_t* flag, int8_t* channel) { + // std::vector arrResoDaughIndex = {}; + // bool matched = false; + + // const std::unordered_map>* finalStates = nullptr; + // switch (pdgParticle) { + // case Pdg::kD0: + // finalStates = reinterpret_cast>*>(&finalStates2Prongs); + // break; + // default: + // finalStates = reinterpret_cast>*>(&finalStates3Prongs); + // break; + // } - for (const auto& [chn, finalState] : *finalStates) { - if (finalState.size() == 4) { // Partly Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1]}; - matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - } else { - LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states - } - if (matched) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgParticle << std::endl; - switch (pdgParticle) { - case Pdg::kD0: - *flag = (*sign) * (chn + 10); - break; - case Pdg::kDPlus: - *flag = (*sign) * (chn + 20); - break; - case Pdg::kDS: - *flag = (*sign) * (chn + 30); - break; - case Pdg::kDStar: - *flag = (*sign) * (chn + 40); - break; - case Pdg::kLambdaCPlus: - *flag = (*sign) * (chn + 50); - break; - case Pdg::kXiCPlus: - *flag = (*sign) * (chn + 60); - break; - default: - LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; - continue; // Skip unknown mother PDG codes - } + // for (const auto& [chn, finalState] : *finalStates) { + // if (finalState.size() == 4) { // Partly Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1]}; + // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // if (matched) { + // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgParticle << std::endl; + // switch (pdgParticle) { + // case Pdg::kD0: + // *flag = (*sign) * (chn + 10); + // break; + // case Pdg::kDPlus: + // *flag = (*sign) * (chn + 20); + // break; + // case Pdg::kDS: + // *flag = (*sign) * (chn + 30); + // break; + // case Pdg::kDStar: + // *flag = (*sign) * (chn + 40); + // break; + // case Pdg::kLambdaCPlus: + // *flag = (*sign) * (chn + 50); + // break; + // case Pdg::kXiCPlus: + // *flag = (*sign) * (chn + 60); + // break; + // default: + // LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; + // continue; // Skip unknown mother PDG codes + // } - // Flag the resonant decay channel - int resoMaxDepth = 1; - int NDaughtersResonant = 2; - if (std::abs(pdgParticle) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances - } - RecoDecay::getDaughters(candidate, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; - if (arrResoDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(pdgParticle) == Pdg::kDStar) || - ( (std::abs(pdgParticle) == Pdg::kXiCPlus) && - (std::abs(daughI.pdgCode()) == kPiPlus) && - (arrPDGDaugh.size() >= 2) ) ) { - continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - } - // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - } - flagResonantDecay(pdgParticle, channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << pdgParticle << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - break; - } - break; // Exit loop if a match is found - } - } - return matched; - } + // // Flag the resonant decay channel + // int resoMaxDepth = 1; + // int NDaughtersResonant = 2; + // if (std::abs(pdgParticle) == Pdg::kDStar) { + // resoMaxDepth = 2; // Flag D0 resonances + // } + // RecoDecay::getDaughters(candidate, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // std::vector arrPDGDaugh = {}; + // if (arrResoDaughIndex.size() == NDaughtersResonant) { + // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ( (std::abs(pdgParticle) == Pdg::kDStar) || + // ( (std::abs(pdgParticle) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + // // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // } + // flagResonantDecay(pdgParticle, channel, arrPDGDaugh); + // // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << pdgParticle << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); + // // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); + // break; + // } + // break; // Exit loop if a match is found + // } + // } + // return matched; + // } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -} // namespace o2::hf_corrbkg -#endif // PWGHF_CORE_CORRELATEDBKGS_H_ diff --git a/PWGHF/DataModel/CandidateReconstructionTables.h b/PWGHF/DataModel/CandidateReconstructionTables.h index 3a6f1fd4788..0365c5333d9 100644 --- a/PWGHF/DataModel/CandidateReconstructionTables.h +++ b/PWGHF/DataModel/CandidateReconstructionTables.h @@ -767,7 +767,7 @@ DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //! DECLARE_SOA_TABLE(HfCand2ProngMcGen, "AOD", "HFCAND2PMCGEN", //! hf_cand_2prong::FlagMcMatchGen, hf_cand_2prong::OriginMcGen, - hf_cand_2prong::FlagMcDecayChanRec, + hf_cand_2prong::FlagMcDecayChanGen, hf_cand::IdxBhadMotherPart); // cascade decay candidate table diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 564e093bdd1..b9c45258ad7 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -775,7 +775,79 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching correlated bkgs of " << Pdg::kD0; + LOG(info) << "Matching correlated bkgs"; + indexRec = -1; // Index of the matched reconstructed candidate + std::vector arrResoDaughIndex = {}; + // const std::unordered_map>* finalStates = nullptr; + // switch (pdgMother) { + // case Pdg::kD0: + // finalStates = reinterpret_cast>*>(&finalStates2Prongs); + // break; + // default: + // finalStates = reinterpret_cast>*>(&finalStates3Prongs); + // break; + // } + + int depth = 2; + for (const auto& [chn, finalState] : finalStates2Prongs) { + std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; + if (finalState.size() == 3) { // Partly Reco 2-prong decays + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); + } + + if (indexRec != -1) { + auto motherParticle = mcParticles.rawIteratorAt(indexRec); + std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay + } + } + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); + } + } else { + LOG(info) << "Final state size not supported: " << finalStateParts2Prong.size(); + continue; // Skip unsupported final states + } + if (indexRec > -1) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; + flag = sign * (chn + 10); // Only D0 decay channels are considered here + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); + // LOG(info) << "[matchFinalStateCorrBkgs] Matched D0 final state: " << chn << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + } + break; // Exit loop if a match is found + } + } + LOG(info) << "D0 matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); + + // LOG(info) << "--------------------------------------------"; + // LOG(info) << "Matching correlated bkgs of " << Pdg::kD0; // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -835,8 +907,10 @@ struct HfCandidateCreator2ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); + LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { + LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 22cb5efd522..8d3f1a96aaa 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -961,7 +961,7 @@ struct HfCandidateCreator3ProngExpressions { // break; // } - for (const auto& pdg : mothersPdgCodes) { + for (const auto& pdg : mothersPdgCodes) { int depth = 2; if (pdg == Pdg::kDStar) { depth = 3; // D0 resonant decays are active @@ -970,9 +970,7 @@ struct HfCandidateCreator3ProngExpressions { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() == 4) { // Partly Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); - + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -983,7 +981,7 @@ struct HfCandidateCreator3ProngExpressions { if (indexRec != -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; + std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay } @@ -1048,15 +1046,14 @@ struct HfCandidateCreator3ProngExpressions { arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(pdg, &channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdg << ", flag: " << flag << ", &sign: " << sign; - LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << flag << " sign: " << sign << " for channel: " << channel; - break; + // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } } } - LOG(info) << "D+ matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); + LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± LOG(info) << "--------------------------------------------"; @@ -1178,16 +1175,16 @@ struct HfCandidateCreator3ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); - LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel; + LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { - LOG(info) << "Filling with flag: " << flag << ", origin: " << origin << ", channel: " << channel; + LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } - LOG(info) << "Filling MC match gen for 3 prong candidates"; - LOG(info) << "Number of MC collisions: " << mcCollisions.size(); + // LOG(info) << "Filling MC match gen for 3 prong candidates"; + // LOG(info) << "Number of MC collisions: " << mcCollisions.size(); for (const auto& mcCollision : mcCollisions) { // Slice the particles table to get the particles for the current MC collision diff --git a/PWGHF/TableProducer/candidateSelectorD0.cxx b/PWGHF/TableProducer/candidateSelectorD0.cxx index ae0102b33fe..411adf3fe81 100644 --- a/PWGHF/TableProducer/candidateSelectorD0.cxx +++ b/PWGHF/TableProducer/candidateSelectorD0.cxx @@ -211,7 +211,7 @@ struct HfCandidateSelectorD0 { if (candidate.decayLengthXY() > cuts->get(pTBin, "max decay length XY")) { return false; } - + LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << hfHelper.invMassD0ToPiK(candidate) << " GeV/c^2"; return true; } @@ -289,7 +289,7 @@ struct HfCandidateSelectorD0 { } } } - + LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << (trackPion.sign() > 0 ? massD0 : massD0bar) << " GeV/c^2"; return true; } template @@ -484,12 +484,16 @@ struct HfCandidateSelectorD0 { void processWithDCAFitterN(aod::HfCand2ProngWPid const& candidates, TracksSel const& tracks) { + LOG(info) << "Processing candidates selection with DCAFitterN"; + LOG(info) << "Number of candidates: " << candidates.size(); processSel(candidates, tracks); } PROCESS_SWITCH(HfCandidateSelectorD0, processWithDCAFitterN, "process candidates selection with DCAFitterN", true); - + void processWithKFParticle(soa::Join const& candidates, TracksSel const& tracks) { + LOG(info) << "Processing candidates selection with KFParticle"; + LOG(info) << "Number of candidates: " << candidates.size(); processSel(candidates, tracks); } PROCESS_SWITCH(HfCandidateSelectorD0, processWithKFParticle, "process candidates selection with KFParticle", false); diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 233b1055ea6..435a8bb71e5 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -72,6 +72,8 @@ DECLARE_SOA_COLUMN(Ct, ct, float); DECLARE_SOA_COLUMN(ImpactParameterProduct, impactParameterProduct, float); DECLARE_SOA_COLUMN(CosThetaStar, cosThetaStar, float); DECLARE_SOA_COLUMN(FlagMc, flagMc, int8_t); +DECLARE_SOA_COLUMN(FlagMcDecayChanRec, flagMcDecayChanRec, int8_t); +DECLARE_SOA_COLUMN(FlagMcDecayChanGen, flagMcDecayChanGen, int8_t); DECLARE_SOA_COLUMN(OriginMcRec, originMcRec, int8_t); // is prompt or non-prompt, reco level DECLARE_SOA_COLUMN(OriginMcGen, originMcGen, int8_t); // is prompt or non-prompt, Gen level DECLARE_SOA_INDEX_COLUMN_FULL(Candidate, candidate, int, HfCand2Prong, "_0"); @@ -123,6 +125,7 @@ DECLARE_SOA_TABLE(HfCandD0Lites, "AOD", "HFCANDD0LITE", full::Phi, full::Y, full::FlagMc, + full::FlagMcDecayChanRec, full::OriginMcRec) DECLARE_SOA_TABLE(HfCandD0Fulls, "AOD", "HFCANDD0FULL", @@ -185,6 +188,7 @@ DECLARE_SOA_TABLE(HfCandD0Fulls, "AOD", "HFCANDD0FULL", full::Y, full::E, full::FlagMc, + full::FlagMcDecayChanRec, full::OriginMcRec, full::CandidateId); @@ -204,6 +208,7 @@ DECLARE_SOA_TABLE(HfCandD0FullPs, "AOD", "HFCANDD0FULLP", full::Phi, full::Y, full::FlagMc, + full::FlagMcDecayChanGen, full::OriginMcGen, full::McParticleId); @@ -236,10 +241,12 @@ struct HfTreeCreatorD0ToKPi { using SelectedCandidatesMcKfMl = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; - Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= 1 || aod::hf_sel_candidate_d0::isSelD0bar >= 1; - Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= -1 || aod::hf_sel_candidate_d0::isSelD0bar >= -1; + // Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0; - Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + // Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0; Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); @@ -275,7 +282,7 @@ struct HfTreeCreatorD0ToKPi { template auto fillTable(const T& candidate, int candFlag, double invMass, double topoChi2, - double ct, double y, double e, int8_t flagMc, int8_t origin) + double ct, double y, double e, int8_t flagMc, int8_t flagMcDecay, int8_t origin) { if (fillCandidateLiteTable) { rowCandidateLite( @@ -313,6 +320,7 @@ struct HfTreeCreatorD0ToKPi { candidate.phi(), y, flagMc, + flagMcDecay, origin); } else { double cosThetaStar = candFlag == 0 ? hfHelper.cosThetaStarD0(candidate) : hfHelper.cosThetaStarD0bar(candidate); @@ -376,6 +384,7 @@ struct HfTreeCreatorD0ToKPi { y, e, flagMc, + flagMcDecay, origin, candidate.globalIndex()); } @@ -435,10 +444,10 @@ struct HfTreeCreatorD0ToKPi { massD0bar = hfHelper.invMassD0barToKPi(candidate); } if (candidate.isSelD0()) { - fillTable(candidate, 0, massD0, topolChi2PerNdf, ctD, yD, eD, 0, 0); + fillTable(candidate, 0, massD0, topolChi2PerNdf, ctD, yD, eD, 0, 0, 0); } if (candidate.isSelD0bar()) { - fillTable(candidate, 1, massD0bar, topolChi2PerNdf, ctD, yD, eD, 0, 0); + fillTable(candidate, 1, massD0bar, topolChi2PerNdf, ctD, yD, eD, 0, 0, 0); } } } @@ -502,6 +511,7 @@ struct HfTreeCreatorD0ToKPi { if constexpr (applyMl) { rowCandidateMl.reserve(candidates.size()); } + LOG(info) << "Processing " << candidates.size() << " candidates"; for (const auto& candidate : candidates) { if constexpr (onlyBkg) { if (TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { @@ -533,10 +543,12 @@ struct HfTreeCreatorD0ToKPi { massD0bar = hfHelper.invMassD0barToKPi(candidate); } if (candidate.isSelD0()) { - fillTable(candidate, 0, massD0, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.originMcRec()); + LOG(info) << "Filling D0 candidate with mass: " << massD0 << ", pt: " << candidate.pt() << ", y: " << yD; + fillTable(candidate, 0, massD0, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.flagMcDecayChanRec(), candidate.originMcRec()); } if (candidate.isSelD0bar()) { - fillTable(candidate, 1, massD0bar, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.originMcRec()); + LOG(info) << "Filling D0 candidate with mass: " << massD0 << ", pt: " << candidate.pt() << ", y: " << yD; + fillTable(candidate, 1, massD0bar, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.flagMcDecayChanRec(), candidate.originMcRec()); } } @@ -551,6 +563,7 @@ struct HfTreeCreatorD0ToKPi { particle.phi(), RecoDecay::y(particle.pVector(), o2::constants::physics::MassD0), particle.flagMcMatchGen(), + particle.flagMcDecayChanGen(), particle.originMcGen(), particle.globalIndex()); } @@ -608,6 +621,10 @@ struct HfTreeCreatorD0ToKPi { aod::Tracks const& tracks, aod::BCs const& bcs) { + LOG(info) << "Processing MC with DCAFitterN for all candidates"; + LOG(info) << "Number of candidates: " << candidates.size(); + LOG(info) << "Number of MC particles: " << mcParticles.size(); + LOG(info) << "Number of collisions: " << collisions.size(); processMc(collisions, mcCollisions, candidates, mcParticles, tracks, bcs); } PROCESS_SWITCH(HfTreeCreatorD0ToKPi, processMcWithDCAFitterAll, "Process MC with DCAFitterN", false); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 6aa2bf7ba60..223d3b5c206 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -58,7 +58,53 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matchCorrBkgs) { - matched = matchFinalStateCorrBkgsGen(Pdg::kD0, mcParticles, particle, &sign, maxDepth, &flag, &channel); + int maxDepth = 2; + bool matched = false; + + std::vector arrResoDaughIndex = {}; + for (const auto& [chn, finalState] : finalStates2Prongs) { + if (finalState.size() == 3) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); + } else if (finalState.size() == 2) { // Fully Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1]}; + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + if (matched) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << std::endl; + switch (Pdg::kD0) { + case Pdg::kD0: + flag = sign * (chn + 10); + break; + default: + LOG(info) << "Unknown mother PDG code: " << Pdg::kD0 << ", skipping."; + continue; // Skip unknown mother PDG codes + } + + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + LOG(info) << "[matchFinalStateCorrBkgsGen] Adding daughter PDG: " << daughI.pdgCode(); + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); + LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + } + break; // Exit loop if a match is found + } + } + // matched = matchFinalStateCorrBkgsGen(Pdg::kD0, mcParticles, particle, &sign, maxDepth, &flag, &channel); } else { // D0(bar) → π± K∓ if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) { @@ -85,8 +131,10 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { + LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { + LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } @@ -188,16 +236,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - break; + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } } - // if (flag == 0) { - // matched = matchFinalStateCorrBkgsGen(motherPdgCode, mcParticles, particle, &sign, maxDepth, &flag, &channel); - // } } } else { @@ -281,11 +325,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V // LOG(info) << "[Gen] Setting origin gen"; origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } - // LOG(info) << "[Gen] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); if (origin == RecoDecay::OriginType::NonPrompt) { // LOG(info) << "Origin is non-prompt"; + LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { + LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } From 6c31f044b43aa6b00371a89ce2a108af836160ca Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 30 May 2025 17:27:34 +0200 Subject: [PATCH 08/47] Tested dev for 2prong decays --- PWGHF/Core/CorrelatedBkgs.h | 430 --------------------- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 16 +- PWGHF/Utils/utilsMcGen.h | 30 +- 3 files changed, 27 insertions(+), 449 deletions(-) diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 6e0652c71ee..9c1b35a7316 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -285,433 +285,3 @@ namespace o2::hf_corrbkg } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_CORRELATEDBKGS_H_ - - - - - - - - - - - - - - - - - - - - // template - // int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - // // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; - // std::vector arrResoDaughIndex = {}; - // int indexRec = -1; // Index of the matched reconstructed candidate - - // const std::unordered_map>* finalStates = nullptr; - // switch (pdgMother) { - // case Pdg::kD0: - // finalStates = reinterpret_cast>*>(&finalStates2Prongs); - // break; - // default: - // finalStates = reinterpret_cast>*>(&finalStates3Prongs); - // break; - // } - - // for (const auto& [chn, finalState] : *finalStates) { - // switch (pdgMother) { - // // case Pdg::kD0: - // // std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; - // // if (finalState.size() == 3) { // Partly Reco 2-prong decays - // // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); - // // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // // } else { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); - // // } - - // // if (indexRec != -1) { - // // auto motherParticle = mcParticles.rawIteratorAt(indexRec); - // // std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; - // // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts2ProngAll, false, sign, depth)) { - // // indexRec = -1; // Reset indexRec if the generated decay - // // } - // // } - // // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - // // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nKinkedTracks); - // // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // // } else { - // // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts2Prong, true, sign, depth); - // // } - // // } else { - // // LOG(info) << "Final state size not supported: " << finalState.size(); - // // continue; // Skip unsupported final states - // // } - // // break; - // default: - // std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - // if (finalState.size() == 4) { // Partly Reco 3-prong decays - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); - // } - - // if (indexRec != -1) { - // auto motherParticle = mcParticles.rawIteratorAt(indexRec); - // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[4]}; - // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdgMother, finalStateParts3ProngAll, false, sign, depth)) { - // indexRec = -1; // Reset indexRec if the generated decay - // } - // } - // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts3Prong, true, sign, depth); - // } - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // break; - // } - // if (indexRec > -1) { - // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; - // switch (pdgMother) { - // case Pdg::kD0: - // *flag = (*sign) * (chn + 10); - // break; - // case Pdg::kDPlus: - // *flag = (*sign) * (chn + 20); - // break; - // case Pdg::kDS: - // *flag = (*sign) * (chn + 30); - // break; - // case Pdg::kDStar: - // *flag = (*sign) * (chn + 40); - // break; - // case Pdg::kLambdaCPlus: - // *flag = (*sign) * (chn + 50); - // break; - // case Pdg::kXiCPlus: - // *flag = (*sign) * (chn + 60); - // break; - // default: - // LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; - // continue; // Skip unknown mother PDG codes - // } - - // // Flag the resonant decay channel - // int resoMaxDepth = 1; - // int NDaughtersResonant = 2; - // if (std::abs(pdgMother) == Pdg::kDStar) { - // resoMaxDepth = 2; // Flag D0 resonances - // } - // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // std::vector arrPDGDaugh = {}; - // if (arrResoDaughIndex.size() == NDaughtersResonant) { - // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(pdgMother) == Pdg::kDStar) || - // ( (std::abs(pdgMother) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - // } - // flagResonantDecay(pdgMother, channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - // break; - // } - // break; // Exit loop if a match is found - // } - // } - // return indexRec; - // } - - // template - // int matchFinalStateCorrBkgsGen(int pdgParticle, aod::McParticles const& mcParticles, const U& candidate, int8_t* sign, int depth, int8_t* flag, int8_t* channel) { - // std::vector arrResoDaughIndex = {}; - // bool matched = false; - - // const std::unordered_map>* finalStates = nullptr; - // switch (pdgParticle) { - // case Pdg::kD0: - // finalStates = reinterpret_cast>*>(&finalStates2Prongs); - // break; - // default: - // finalStates = reinterpret_cast>*>(&finalStates3Prongs); - // break; - // } - - // for (const auto& [chn, finalState] : *finalStates) { - // if (finalState.size() == 4) { // Partly Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1]}; - // matched = RecoDecay::isMatchedMCGen(mcParticles, candidate, pdgParticle, finalStateParts, true, sign, depth); - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // if (matched) { - // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgParticle << std::endl; - // switch (pdgParticle) { - // case Pdg::kD0: - // *flag = (*sign) * (chn + 10); - // break; - // case Pdg::kDPlus: - // *flag = (*sign) * (chn + 20); - // break; - // case Pdg::kDS: - // *flag = (*sign) * (chn + 30); - // break; - // case Pdg::kDStar: - // *flag = (*sign) * (chn + 40); - // break; - // case Pdg::kLambdaCPlus: - // *flag = (*sign) * (chn + 50); - // break; - // case Pdg::kXiCPlus: - // *flag = (*sign) * (chn + 60); - // break; - // default: - // LOG(info) << "Unknown mother PDG code: " << pdgParticle << ", skipping."; - // continue; // Skip unknown mother PDG codes - // } - - // // Flag the resonant decay channel - // int resoMaxDepth = 1; - // int NDaughtersResonant = 2; - // if (std::abs(pdgParticle) == Pdg::kDStar) { - // resoMaxDepth = 2; // Flag D0 resonances - // } - // RecoDecay::getDaughters(candidate, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // std::vector arrPDGDaugh = {}; - // if (arrResoDaughIndex.size() == NDaughtersResonant) { - // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(pdgParticle) == Pdg::kDStar) || - // ( (std::abs(pdgParticle) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - // // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - // } - // flagResonantDecay(pdgParticle, channel, arrPDGDaugh); - // // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << pdgParticle << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - // // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - // break; - // } - // break; // Exit loop if a match is found - // } - // } - // return matched; - // } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template - // int matchFinalStateCorrBkgs(int pdgMother, aod::McParticles const& mcParticles, auto arrayDaughters, int8_t* flag, int8_t* sign, int8_t* channel, int depth, int8_t* nKinkedTracks, int8_t* nInteractionsWithMaterial) { - // // std::cout << "Entering flag value: " << static_cast(*flag) << std::endl; - // std::vector arrResoDaughIndex = {}; - // int indexRec = -1; // Index of the matched reconstructed candidate - // // for (std::size_t iProng = 0; iProng < 3; ++iProng) { - // // if (!arrayDaughters[iProng].has_mcParticle()) { - // // return -1; - // // } - // // auto particleI = arrayDaughters[iProng].mcParticle(); // ith daughter particle - // // auto motherI = particleI.template mothers_first_as(); - // // auto pdgI = particleI.pdgCode(); - // // auto pdgMotherI = motherI.pdgCode(); - // // auto pdgMotherII = -1; - // // LOG(info) << "Daughter " << iProng << " PDG: " << pdgI << " motherI: " << pdgMotherI; - // // } - - // // auto finalStates = finalStates3Prongs; - // // if (std::abs(pdgMother) == Pdg::kD0) { - // // finalStates = finalStates2Prongs; - // // } - - // for (const auto& [chn, finalState] : finalStates3Prongs) { - // if (finalState.size() == 4) { // Partly Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); - // } - // } else if (finalState.size() == 3 && std::abs(pdgMother) != Pdg::kD0) { // Fully Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth); - // } - // } else if (finalState.size() == 3 && std::abs(pdgMother) == Pdg::kD0) { // Partly Reco 2-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1]}; - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); - // } - // } else if (finalState.size() == 2) { // Fully Reco 2-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1]}; - // if constexpr (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks, nInteractionsWithMaterial); - // } else if constexpr (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nKinkedTracks); - // } else if constexpr (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign, depth, nullptr, nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdgMother, finalStateParts, true, sign); - // } - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // if (indexRec > -1) { - // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdgMother << std::endl; - // switch (pdgMother) { - // case Pdg::kD0: - // *flag = (*sign) * (chn + 10); - // break; - // case Pdg::kDPlus: - // *flag = (*sign) * (chn + 20); - // break; - // case Pdg::kDS: - // *flag = (*sign) * (chn + 30); - // break; - // case Pdg::kDStar: - // *flag = (*sign) * (chn + 40); - // break; - // case Pdg::kLambdaCPlus: - // *flag = (*sign) * (chn + 50); - // break; - // case Pdg::kXiCPlus: - // *flag = (*sign) * (chn + 60); - // break; - // default: - // LOG(info) << "Unknown mother PDG code: " << pdgMother << ", skipping."; - // continue; // Skip unknown mother PDG codes - // } - - // // Flag the resonant decay channel - // int resoMaxDepth = 1; - // int NDaughtersResonant = 2; - // if (std::abs(pdgMother) == Pdg::kDStar) { - // resoMaxDepth = 2; // Flag D0 resonances - // } - // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // std::vector arrPDGDaugh = {}; - // if (arrResoDaughIndex.size() == NDaughtersResonant) { - // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(pdgMother) == Pdg::kDStar || std::abs(pdgMother) == Pdg::kXiCPlus) - // && std::abs(daughI.pdgCode() == kPiPlus && arrPDGDaugh.size() >= 2)) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - // } - // flagResonantDecay(pdgMother, channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << pdgMother << ", flag: " << static_cast(*flag) << ", sign: " << static_cast(*sign); - // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(*flag) << " sign: " << static_cast(*sign) << " for channel: " << static_cast(*channel); - // break; - // } - // break; // Exit loop if a match is found - // } - // } - // return indexRec; - // } \ No newline at end of file diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 435a8bb71e5..382baf08989 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -514,9 +514,9 @@ struct HfTreeCreatorD0ToKPi { LOG(info) << "Processing " << candidates.size() << " candidates"; for (const auto& candidate : candidates) { if constexpr (onlyBkg) { - if (TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { - continue; - } + // if (TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { + // continue; + // } if (downSampleBkgFactor < 1.) { float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { @@ -525,9 +525,9 @@ struct HfTreeCreatorD0ToKPi { } } if constexpr (onlySig) { - if (!TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { - continue; - } + // if (!TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { + // continue; + // } } double yD = hfHelper.yD0(candidate); double eD = hfHelper.eD0(candidate); @@ -555,7 +555,7 @@ struct HfTreeCreatorD0ToKPi { // Filling particle properties rowCandidateFullParticles.reserve(mcParticles.size()); for (const auto& particle : mcParticles) { - if (TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { + // if (TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { rowCandidateFullParticles( particle.mcCollisionId(), particle.pt(), @@ -566,7 +566,7 @@ struct HfTreeCreatorD0ToKPi { particle.flagMcDecayChanGen(), particle.originMcGen(), particle.globalIndex()); - } + // } } } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 223d3b5c206..5154919e327 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -75,15 +75,8 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matched) { // std::cout << "Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << std::endl; - switch (Pdg::kD0) { - case Pdg::kD0: - flag = sign * (chn + 10); - break; - default: - LOG(info) << "Unknown mother PDG code: " << Pdg::kD0 << ", skipping."; - continue; // Skip unknown mother PDG codes - } - + flag = sign * (chn + 10); + // Flag the resonant decay channel int resoMaxDepth = 1; int NDaughtersResonant = 2; @@ -176,14 +169,29 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (motherPdgCode == Pdg::kDStar) { maxDepth = 3; // to catch the D0 resonances } - + std::vector arrResoDaughIndex = {}; for (const auto& [chn, finalState] : finalStates3Prongs) { if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); + std::vector arrAllDaughtersIndex; // vector of indices of all daughters + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + for (int iDaug = 0; iDaug arrAllDaughtersIndex2; // vector of indices of all daughters + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex2, finalStateParts, maxDepth-1); + for (int iDaug = 0; iDaug finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + std::vector arrAllDaughtersIndex3; // vector of indices of all daughters + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex3, finalStateParts, maxDepth); + for (int iDaug = 0; iDaug Date: Fri, 30 May 2025 17:39:25 +0200 Subject: [PATCH 09/47] revert unwanted changes --- Common/Core/RecoDecay.h | 2 +- Common/TableProducer/centralityTable.cxx | 5 +---- PWGJE/Tasks/CMakeLists.txt | 10 +++++----- PWGLF/Tasks/Resonances/CMakeLists.txt | 10 +++++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 6f5e433bb11..7716a8d64a0 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -1451,4 +1451,4 @@ struct RecoDecayPtEtaPhiBase { using RecoDecayPtEtaPhi = RecoDecayPtEtaPhiBase<>; // alias for instance with default parameters -#endif // COMMON_CORE_RECODECAY_H_ \ No newline at end of file +#endif // COMMON_CORE_RECODECAY_H_ diff --git a/Common/TableProducer/centralityTable.cxx b/Common/TableProducer/centralityTable.cxx index d222a7d14ee..9cdf24583f3 100644 --- a/Common/TableProducer/centralityTable.cxx +++ b/Common/TableProducer/centralityTable.cxx @@ -240,7 +240,6 @@ struct CentralityTable { mRunNumber = 0; listCalib.setObject(new TList); if (!produceHistograms.value) { - LOG(info) << "Debug histograms are disabled. No histograms will be produced."; return; } @@ -260,7 +259,6 @@ struct CentralityTable { histos.addClone("FT0C/", "sel8FT0C/"); histos.addClone("FT0A/", "sel8FT0A/"); - LOG(info) << "Debug histograms are enabled. Histograms will be produced."; histos.print(); } @@ -571,7 +569,6 @@ struct CentralityTable { mftInfo.mCalibrationStored = false; if (callst != nullptr) { if (produceHistograms) { - LOG(info) << "Adding calibration list to the list of calibration lists"; listCalib->Add(callst->Clone(Form("%i", bc.runNumber()))); } LOGF(info, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); @@ -784,4 +781,4 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { metadataInfo.initMetadata(cfgc); return WorkflowSpec{adaptAnalysisTask(cfgc)}; -} +} \ No newline at end of file diff --git a/PWGJE/Tasks/CMakeLists.txt b/PWGJE/Tasks/CMakeLists.txt index ea243aef9d6..aa2f058d26a 100644 --- a/PWGJE/Tasks/CMakeLists.txt +++ b/PWGJE/Tasks/CMakeLists.txt @@ -68,10 +68,10 @@ if(FastJet_FOUND) SOURCES jetSubstructureD0.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore COMPONENT_NAME Analysis) - # o2physics_add_dpl_workflow(jet-substructure-dplus - # SOURCES jetSubstructureDplus.cxx - # PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore - # COMPONENT_NAME Analysis) + o2physics_add_dpl_workflow(jet-substructure-dplus + SOURCES jetSubstructureDplus.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore + COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(jet-substructure-lc SOURCES jetSubstructureLc.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore @@ -269,4 +269,4 @@ if(FastJet_FOUND) SOURCES jetShape.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore COMPONENT_NAME Analysis) -endif() +endif() \ No newline at end of file diff --git a/PWGLF/Tasks/Resonances/CMakeLists.txt b/PWGLF/Tasks/Resonances/CMakeLists.txt index 9e00c6e3dbe..9092e2e3baf 100644 --- a/PWGLF/Tasks/Resonances/CMakeLists.txt +++ b/PWGLF/Tasks/Resonances/CMakeLists.txt @@ -174,10 +174,10 @@ o2physics_add_dpl_workflow(highmasslambdasvx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) -# o2physics_add_dpl_workflow(chk892flow -# SOURCES chk892Flow.cxx -# PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore -# COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(chk892flow + SOURCES chk892Flow.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(chk892pp SOURCES chk892pp.cxx @@ -212,4 +212,4 @@ o2physics_add_dpl_workflow(heptaquark o2physics_add_dpl_workflow(double-resonance-scan SOURCES doubleResonanceScan.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) + COMPONENT_NAME Analysis) \ No newline at end of file From 795f547a3616178acd92fe8dd64c4eec02fa05f7 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 30 May 2025 17:40:44 +0200 Subject: [PATCH 10/47] Remove changes --- Common/TableProducer/centralityTable.cxx | 2 +- PWGJE/Tasks/CMakeLists.txt | 2 +- PWGLF/Tasks/Resonances/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/TableProducer/centralityTable.cxx b/Common/TableProducer/centralityTable.cxx index 9cdf24583f3..48f1598afc5 100644 --- a/Common/TableProducer/centralityTable.cxx +++ b/Common/TableProducer/centralityTable.cxx @@ -781,4 +781,4 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { metadataInfo.initMetadata(cfgc); return WorkflowSpec{adaptAnalysisTask(cfgc)}; -} \ No newline at end of file +} diff --git a/PWGJE/Tasks/CMakeLists.txt b/PWGJE/Tasks/CMakeLists.txt index aa2f058d26a..0e39c04445a 100644 --- a/PWGJE/Tasks/CMakeLists.txt +++ b/PWGJE/Tasks/CMakeLists.txt @@ -269,4 +269,4 @@ if(FastJet_FOUND) SOURCES jetShape.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore COMPONENT_NAME Analysis) -endif() \ No newline at end of file +endif() diff --git a/PWGLF/Tasks/Resonances/CMakeLists.txt b/PWGLF/Tasks/Resonances/CMakeLists.txt index 9092e2e3baf..4ba33fce401 100644 --- a/PWGLF/Tasks/Resonances/CMakeLists.txt +++ b/PWGLF/Tasks/Resonances/CMakeLists.txt @@ -212,4 +212,4 @@ o2physics_add_dpl_workflow(heptaquark o2physics_add_dpl_workflow(double-resonance-scan SOURCES doubleResonanceScan.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) \ No newline at end of file + COMPONENT_NAME Analysis) From 803a34a3f7e86dc55e2e5a3a8e1f601eabb53f2d Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 2 Jun 2025 20:55:32 +0200 Subject: [PATCH 11/47] Fix Dstar matching and add other channels --- Common/Core/RecoDecay.h | 40 +++++++ PWGHF/Core/CorrelatedBkgs.h | 108 +++++++++++++++--- .../TableProducer/candidateCreator3Prong.cxx | 43 +++---- PWGHF/Utils/utilsMcGen.h | 79 +++++++------ 4 files changed, 191 insertions(+), 79 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 7716a8d64a0..7404388a385 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,6 +25,7 @@ #include // std::apply #include // std::move #include // std::vector +#include // ROOT includes #include // for VMC Particle Production Process @@ -918,7 +919,11 @@ struct RecoDecay { } // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); + bool print = false; // Print debug messages only if print is true. // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); + if (std::abs(pdgCandidate) == 413) { + print = true; // Print debug messages for D* candidates. + } if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match @@ -929,22 +934,45 @@ struct RecoDecay { } // Check the PDG codes of the decay products. if (N > 0) { + if (print) { + std::cout << "MC Gen: Checking decay products of " << N << " daughters" << std::endl; + // Printf("MC Gen: Checking decay products of %ld daughters", N); + } // Printf("MC Gen: Checking %d daughters", N); std::vector arrAllDaughtersIndex; // vector of indices of all daughters // Check the daughter indices. if (!candidate.has_daughters()) { + if (print) { + std::cout << "MC Gen: Rejected: bad daughter index range: " << candidate.daughtersIds().front() << "-" << candidate.daughtersIds().back() << std::endl; + // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); + } // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); return false; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!checkProcess) { if (candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 > static_cast(N)) { + if (print) { + std::cout << "MC Gen: Rejected: too many direct daughters: " << candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 + << " (expected " << N << " final)" << std::endl; + // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); + } // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); return false; } } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); + if (print) { + std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final daughters:"; + // Printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); + for (auto i : arrAllDaughtersIndex) { + std::cout << " " << i; + // Printf(" %d", i); + } + std::cout << std::endl; + // Printf("\n"); + } // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { // printf(" %d", i); @@ -952,6 +980,10 @@ struct RecoDecay { // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { + if (print) { + std::cout << "MC Gen: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; + // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); + } // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } @@ -969,6 +1001,10 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter + if (print) { + std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; + // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); + } // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { @@ -987,6 +1023,10 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } + if (print) { + std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; + // Printf("MC Gen: Accepted: m: %ld", candidate.globalIndex()); + } // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h index 9c1b35a7316..1d3cca9d29e 100644 --- a/PWGHF/Core/CorrelatedBkgs.h +++ b/PWGHF/Core/CorrelatedBkgs.h @@ -31,7 +31,7 @@ namespace o2::hf_corrbkg enum FinalStates2Prongs { KPi = 1, KK, - KPiPi0, + KMinusPiPi0, PiPi, PiPiPi0, NFinalStates2P @@ -39,35 +39,45 @@ namespace o2::hf_corrbkg std::unordered_map > finalStates2Prongs = { - {FinalStates2Prongs::KPi, std::vector{+kKMinus, +kPiPlus}}, - {FinalStates2Prongs::KK, std::vector{+kKMinus, +kKPlus}}, - {FinalStates2Prongs::KPiPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, - {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, - {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + {FinalStates2Prongs::KPi, std::vector{+kKMinus, +kPiPlus}}, + {FinalStates2Prongs::KK, std::vector{+kKMinus, +kKPlus}}, + {FinalStates2Prongs::KMinusPiPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, + {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, + {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} }; enum FinalStates3Prongs { KKPi = 1, KKPiPi0, - KPiPi, - KPiPiPi0, + KMinusPiPi, + KMinusPiPiPi0, + KPlusPiPi, + KPlusPiPiPi0, PiPiPi, PiPiPiPi0, - ProtonPiPi, ProtonKPi, + ProtonKPiPi0, + ProtonPiPi, + ProtonKK, + SigmaPiPi, NFinalStates3P }; std::unordered_map > finalStates3Prongs = { - {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::KPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}} + {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KPlusPiPi, std::vector{+kPlus, +kPiPlus, +kPiMinus}}, + {FinalStates3Prongs::KPlusPiPiPi0, std::vector{+kPlus, +kPiPlus, +kPiMinus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}}, + {FinalStates3Prongs::SigmaPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; // Dstar → K± K∓ π± @@ -106,6 +116,15 @@ namespace o2::hf_corrbkg {DecayChannelResoDplus::RhoPi, std::array{+113, +kPiPlus}}, {DecayChannelResoDplus::f2_1270Pi, std::array{+225, +kPiPlus}}, }; + + std::unordered_map > finalStatesDPlus = + { + {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + }; } // Ds± → K± K∓ π± @@ -134,6 +153,15 @@ namespace o2::hf_corrbkg {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, {DecayChannelResoDs::f2_1370K, std::array{10221, +kKPlus}}, }; + + std::unordered_map > finalStatesDs = + { + {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::KPlusPiPi, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + }; } // Dstar → K± K∓ π± @@ -152,6 +180,15 @@ namespace o2::hf_corrbkg {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, +kPi0}}, {DecayChannelResoDStarD0::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, }; + + std::unordered_map > finalStatesDStar = + { + {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + }; } // Lc → p K∓ π± @@ -170,6 +207,14 @@ namespace o2::hf_corrbkg {DecayChannelResoLambdaC::DeltaK, std::array{+2224, +kKMinus}}, {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, +kPiPlus}}, }; + + std::unordered_map > finalStatesLc = + { + {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}} + }; } // Xic → p K∓ π± @@ -186,9 +231,36 @@ namespace o2::hf_corrbkg {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, +kPhi}}, {DecayChannelResoXiC::SigmaPiPi, std::array{+kSigmaPlus, +kPiPlus}}, }; + + std::unordered_map > finalStatesXic = + { + {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}}, + {FinalStates3Prongs::SigmaPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, + }; + } + + std::unordered_map > getParticleFinalStates3Prongs(int pdgMother) { + switch (pdgMother) { + case Pdg::kDPlus: + return DPlus::finalStatesDPlus; + case Pdg::kDS: + return DS::finalStatesDs; + case Pdg::kDStar: + return DStar::finalStatesDStar; + case Pdg::kLambdaCPlus: + return LambdaC::finalStatesLc; + case Pdg::kXiCPlus: + return XiC::finalStatesXic; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; + } } bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { + // LOG(info) << "Entered checkResonantDecay with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " and resonant PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; + // LOG(info) << "arrDaughIndex.size(): " << arrDaughIndex.size() << ", arrPDGResonant.size(): " << arrPDGResonant.size(); std::array arrPDGResonantAbs = {std::abs(arrPDGResonant[0]), std::abs(arrPDGResonant[1])}; LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; for (int i = 0; i < 2; i++) { @@ -250,7 +322,7 @@ namespace o2::hf_corrbkg break; case Pdg::kDStar: for (const auto& [flag, pdgCodes] : DStar::resoStatesDStarD0) { - // std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = flag; LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 8d3f1a96aaa..273a795f65c 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -946,27 +946,19 @@ struct HfCandidateCreator3ProngExpressions { } if (matchCorrBkgs) { - LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching correlated bkgs"; + // LOG(info) << "--------------------------------------------"; + // LOG(info) << "Matching correlated bkgs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; indexRec = -1; // Index of the matched reconstructed candidate std::vector arrResoDaughIndex = {}; - // const std::unordered_map>* finalStates = nullptr; - // switch (pdgMother) { - // case Pdg::kD0: - // finalStates = reinterpret_cast>*>(&finalStates2Prongs); - // break; - // default: - // finalStates = reinterpret_cast>*>(&finalStates3Prongs); - // break; - // } - + for (const auto& pdg : mothersPdgCodes) { int depth = 2; if (pdg == Pdg::kDStar) { depth = 3; // D0 resonant decays are active } - for (const auto& [chn, finalState] : finalStates3Prongs) { + auto finalStates = getParticleFinalStates3Prongs(pdg); + for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() == 4) { // Partly Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -988,13 +980,13 @@ struct HfCandidateCreator3ProngExpressions { } } else if (finalState.size() == 3) { // Fully Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } } else { LOG(info) << "Final state size not supported: " << finalState.size(); @@ -1003,23 +995,20 @@ struct HfCandidateCreator3ProngExpressions { if (indexRec > -1) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; switch (pdg) { - case Pdg::kD0: - flag = sign * (chn + 10); - break; case Pdg::kDPlus: - flag = sign * (chn + 20); + flag = sign * (chn + 30); break; case Pdg::kDS: - flag = sign * (chn + 30); + flag = sign * (chn + 50); break; case Pdg::kDStar: - flag = sign * (chn + 40); + flag = sign * (chn + 70); break; case Pdg::kLambdaCPlus: - flag = sign * (chn + 50); + flag = sign * (chn + 90); break; case Pdg::kXiCPlus: - flag = sign * (chn + 60); + flag = sign * (chn + 110); break; default: LOG(info) << "Unknown mother PDG code: " << pdg << ", skipping."; @@ -1053,7 +1042,7 @@ struct HfCandidateCreator3ProngExpressions { } } } - LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); + // LOG(info) (flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± LOG(info) << "--------------------------------------------"; @@ -1169,7 +1158,7 @@ struct HfCandidateCreator3ProngExpressions { // Check whether the particle is non-prompt (from a b quark). if (flag != 0) { - LOG(info) << "Setting origin"; + // LOG(info) << "Setting origin"; auto particle = mcParticles.rawIteratorAt(indexRec); origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 5154919e327..ed35c4c3406 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -140,6 +140,8 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V constexpr std::size_t NDaughtersResonant{2u}; // Match generated particles. + // LOG(info) << "Matching generated particles for 3-prong decays"; + // LOG(info) << "Number of particles in mcParticlesPerMcColl: " << mcParticlesPerMcColl.size(); for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; @@ -164,6 +166,10 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V // LOG(info) << "Matching gen correlated bkgs of 3prongs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; for (const auto& motherPdgCode : mothersPdgCodes) { + if (std::abs(particle.pdgCode()) != motherPdgCode) { + continue; // Skip if the particle PDG code does not match the mother PDG code + } + auto finalStates = getParticleFinalStates3Prongs(motherPdgCode); int maxDepth = 2; bool matched = false; if (motherPdgCode == Pdg::kDStar) { @@ -171,81 +177,86 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } std::vector arrResoDaughIndex = {}; - for (const auto& [chn, finalState] : finalStates3Prongs) { + std::vector arrAllDaughtersIndex; // vector of indices of all daughters + for (const auto& [chn, finalState] : finalStates) { if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - std::vector arrAllDaughtersIndex; // vector of indices of all daughters RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); - for (int iDaug = 0; iDaug arrAllDaughtersIndex2; // vector of indices of all daughters - RecoDecay::getDaughters(particle, &arrAllDaughtersIndex2, finalStateParts, maxDepth-1); - for (int iDaug = 0; iDaug finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - std::vector arrAllDaughtersIndex3; // vector of indices of all daughters - RecoDecay::getDaughters(particle, &arrAllDaughtersIndex3, finalStateParts, maxDepth); - for (int iDaug = 0; iDaug(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); } else { LOG(info) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } if (matched) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; + std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; switch (motherPdgCode) { - case Pdg::kD0: - flag = sign * (chn + 10); - break; case Pdg::kDPlus: - flag = sign * (chn + 20); + flag = sign * (chn + 30); break; case Pdg::kDS: - flag = sign * (chn + 30); + flag = sign * (chn + 50); break; case Pdg::kDStar: - flag = sign * (chn + 40); + flag = sign * (chn + 70); break; case Pdg::kLambdaCPlus: - flag = sign * (chn + 50); + flag = sign * (chn + 90); break; case Pdg::kXiCPlus: - flag = sign * (chn + 60); + flag = sign * (chn + 110); break; default: LOG(info) << "Unknown mother PDG code: " << motherPdgCode << ", skipping."; continue; // Skip unknown mother PDG codes } - + // Flag the resonant decay channel int resoMaxDepth = 1; int NDaughtersResonant = 2; if (std::abs(motherPdgCode) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances + std::vector arrResoDaughIndexDStar = {}; + RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); + for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { + if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { + auto daughD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + RecoDecay::getDaughters(daughD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + break; + } + std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; + } + } else { + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); } - RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); std::vector arrPDGDaugh = {}; + if (std::abs(motherPdgCode) == Pdg::kDStar) { + LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); + } if (arrResoDaughIndex.size() == NDaughtersResonant) { + if (std::abs(motherPdgCode) == Pdg::kDStar) { + LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; + } for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(motherPdgCode) == Pdg::kDStar) || - ( (std::abs(motherPdgCode) == Pdg::kXiCPlus) && - (std::abs(daughI.pdgCode()) == kPiPlus) && - (arrPDGDaugh.size() >= 2) ) ) { + // if ( (std::abs(motherPdgCode) == Pdg::kDStar) || + if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && + (std::abs(daughI.pdgCode()) == kPiPlus) && + (arrPDGDaugh.size() >= 2) ) { continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi } - // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + if (std::abs(motherPdgCode) == Pdg::kDStar) { + std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + } arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); } flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + if (std::abs(motherPdgCode) == Pdg::kDStar) { + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + } } break; // Exit loop if a match is found } From a43049a61eee77281cfeca4cddd1d5e8465617ee Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 2 Jun 2025 20:57:01 +0200 Subject: [PATCH 12/47] Restore reco decay --- Common/Core/RecoDecay.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 7404388a385..7716a8d64a0 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,7 +25,6 @@ #include // std::apply #include // std::move #include // std::vector -#include // ROOT includes #include // for VMC Particle Production Process @@ -919,11 +918,7 @@ struct RecoDecay { } // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); - bool print = false; // Print debug messages only if print is true. // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); - if (std::abs(pdgCandidate) == 413) { - print = true; // Print debug messages for D* candidates. - } if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match @@ -934,45 +929,22 @@ struct RecoDecay { } // Check the PDG codes of the decay products. if (N > 0) { - if (print) { - std::cout << "MC Gen: Checking decay products of " << N << " daughters" << std::endl; - // Printf("MC Gen: Checking decay products of %ld daughters", N); - } // Printf("MC Gen: Checking %d daughters", N); std::vector arrAllDaughtersIndex; // vector of indices of all daughters // Check the daughter indices. if (!candidate.has_daughters()) { - if (print) { - std::cout << "MC Gen: Rejected: bad daughter index range: " << candidate.daughtersIds().front() << "-" << candidate.daughtersIds().back() << std::endl; - // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); - } // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); return false; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!checkProcess) { if (candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 > static_cast(N)) { - if (print) { - std::cout << "MC Gen: Rejected: too many direct daughters: " << candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 - << " (expected " << N << " final)" << std::endl; - // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); - } // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); return false; } } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - if (print) { - std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final daughters:"; - // Printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); - for (auto i : arrAllDaughtersIndex) { - std::cout << " " << i; - // Printf(" %d", i); - } - std::cout << std::endl; - // Printf("\n"); - } // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { // printf(" %d", i); @@ -980,10 +952,6 @@ struct RecoDecay { // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { - if (print) { - std::cout << "MC Gen: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; - // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); - } // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } @@ -1001,10 +969,6 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter - if (print) { - std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; - // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); - } // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { @@ -1023,10 +987,6 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } - if (print) { - std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; - // Printf("MC Gen: Accepted: m: %ld", candidate.globalIndex()); - } // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; From 0e44745725943c7d3ba0508209f99cfc9261bf3e Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sat, 7 Jun 2025 21:47:27 +0200 Subject: [PATCH 13/47] [WIP] Digest new MC matching --- PWGHF/Core/CorrelatedBkgs.h | 359 ------------------ PWGHF/Core/DecayChannels.h | 235 ++++++++++++ .../TableProducer/candidateCreator2Prong.cxx | 9 +- .../TableProducer/candidateCreator3Prong.cxx | 198 ++++------ PWGHF/TableProducer/trackIndexSkimCreator.cxx | 6 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 15 +- PWGHF/Utils/utilsMcGen.h | 208 +++++----- 7 files changed, 432 insertions(+), 598 deletions(-) delete mode 100644 PWGHF/Core/CorrelatedBkgs.h diff --git a/PWGHF/Core/CorrelatedBkgs.h b/PWGHF/Core/CorrelatedBkgs.h deleted file mode 100644 index 1d3cca9d29e..00000000000 --- a/PWGHF/Core/CorrelatedBkgs.h +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file CorrelatedBkgs.h -/// \brief Definitions of channels for correlated bkgs -/// \author Marcello Di Costanzo , Polytechnic of Turin and INFN -/// \author Stefano Politanò , CERN - -#include -#include -#include - -#include "/home/mdicosta/alice/O2Physics/Common/Core/RecoDecay.h" - -#ifndef PWGHF_CORE_CORRELATEDBKGS_H_ -#define PWGHF_CORE_CORRELATEDBKGS_H_ - -using namespace o2::constants::physics; - -namespace o2::hf_corrbkg -{ - - enum FinalStates2Prongs { - KPi = 1, - KK, - KMinusPiPi0, - PiPi, - PiPiPi0, - NFinalStates2P - }; - - std::unordered_map > finalStates2Prongs = - { - {FinalStates2Prongs::KPi, std::vector{+kKMinus, +kPiPlus}}, - {FinalStates2Prongs::KK, std::vector{+kKMinus, +kKPlus}}, - {FinalStates2Prongs::KMinusPiPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, - {FinalStates2Prongs::PiPi, std::vector{+kPiMinus, +kPiPlus}}, - {FinalStates2Prongs::PiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} - }; - - enum FinalStates3Prongs { - KKPi = 1, - KKPiPi0, - KMinusPiPi, - KMinusPiPiPi0, - KPlusPiPi, - KPlusPiPiPi0, - PiPiPi, - PiPiPiPi0, - ProtonKPi, - ProtonKPiPi0, - ProtonPiPi, - ProtonKK, - SigmaPiPi, - NFinalStates3P - }; - - std::unordered_map > finalStates3Prongs = - { - {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KPlusPiPi, std::vector{+kPlus, +kPiPlus, +kPiMinus}}, - {FinalStates3Prongs::KPlusPiPiPi0, std::vector{+kPlus, +kPiPlus, +kPiMinus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}}, - {FinalStates3Prongs::SigmaPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, - }; - - // Dstar → K± K∓ π± - namespace D0 { - enum DecayChannelResoD0 { - RhoPi = 1, - RhoK, - K0starPi0, - K0starPiPlus, - }; - - std::unordered_map > resoStatesD0 = - { - {DecayChannelResoD0::RhoPi, std::array{213, +kPiMinus}}, - {DecayChannelResoD0::RhoK, std::array{213, +kKMinus}}, - {DecayChannelResoD0::K0starPi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResoD0::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, - }; - } - - // D± → K± K∓ π± - namespace DPlus { - enum DecayChannelResoDplus { - PhiPi = 1, - K0starK, - K_1430K, - RhoPi, - f2_1270Pi, - }; - - std::unordered_map > resoStatesDPlus = - { - {DecayChannelResoDplus::PhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResoDplus::K0starK, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResoDplus::K_1430K, std::array{+10311, +kKPlus}}, - {DecayChannelResoDplus::RhoPi, std::array{+113, +kPiPlus}}, - {DecayChannelResoDplus::f2_1270Pi, std::array{+225, +kPiPlus}}, - }; - - std::unordered_map > finalStatesDPlus = - { - {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - }; - } - - // Ds± → K± K∓ π± - namespace DS { - enum DecayChannelResoDs { - PhiPi = 1, - PhiRho, - K0starK, - K0starPi, - RhoPi, - RhoK, - EtaPi, - f2_1270Pi, - f2_1370K, - }; - - std::unordered_map > resoStatesDs = - { - {DecayChannelResoDs::PhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResoDs::PhiRho, std::array{+kPhi, +213}}, - {DecayChannelResoDs::K0starK, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResoDs::K0starPi, std::array{+kK0Star892, +kPiPlus}}, - {DecayChannelResoDs::RhoPi, std::array{113, +kPiPlus}}, - {DecayChannelResoDs::RhoK, std::array{113, +kKPlus}}, - {DecayChannelResoDs::EtaPi, std::array{221, +kPiPlus}}, - {DecayChannelResoDs::f2_1270Pi, std::array{225, +kPiPlus}}, - {DecayChannelResoDs::f2_1370K, std::array{10221, +kKPlus}}, - }; - - std::unordered_map > finalStatesDs = - { - {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KKPiPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::KPlusPiPi, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - }; - } - - // Dstar → K± K∓ π± - namespace DStar { - enum DecayChannelResoDStarD0 { - RhoPi = 1, - RhoK, - K0starPi0, - K0starPiPlus, - }; - - std::unordered_map > resoStatesDStarD0 = - { - {DecayChannelResoDStarD0::RhoPi, std::array{213, +kPiMinus}}, - {DecayChannelResoDStarD0::RhoK, std::array{213, +kKMinus}}, - {DecayChannelResoDStarD0::K0starPi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResoDStarD0::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, - }; - - std::unordered_map > finalStatesDStar = - { - {FinalStates3Prongs::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {FinalStates3Prongs::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {FinalStates3Prongs::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, - }; - } - - // Lc → p K∓ π± - namespace LambdaC { - enum DecayChannelResoLambdaC { - K0starP = 1, - ProtonPhi, - DeltaK, - Lambda1520Pi, - }; - - std::unordered_map > resoStatesLambdaC = - { - {DecayChannelResoLambdaC::K0starP, std::array{+kK0Star892, +kProton}}, - {DecayChannelResoLambdaC::ProtonPhi, std::array{+kProton, +kPhi}}, - {DecayChannelResoLambdaC::DeltaK, std::array{+2224, +kKMinus}}, - {DecayChannelResoLambdaC::Lambda1520Pi, std::array{+102134, +kPiPlus}}, - }; - - std::unordered_map > finalStatesLc = - { - {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {FinalStates3Prongs::ProtonPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}} - }; - } - - // Xic → p K∓ π± - namespace XiC { - enum DecayChannelResoXiC { - K0starP = 1, - ProtonPhi, - SigmaPiPi, - }; - - std::unordered_map > resoStatesXiC = - { - {DecayChannelResoXiC::K0starP, std::array{-kK0Star892, +kProton}}, - {DecayChannelResoXiC::ProtonPhi, std::array{+kProton, +kPhi}}, - {DecayChannelResoXiC::SigmaPiPi, std::array{+kSigmaPlus, +kPiPlus}}, - }; - - std::unordered_map > finalStatesXic = - { - {FinalStates3Prongs::ProtonKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {FinalStates3Prongs::ProtonKK, std::vector{+kProton, +kKMinus, +kKPlus}}, - {FinalStates3Prongs::SigmaPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, - }; - } - - std::unordered_map > getParticleFinalStates3Prongs(int pdgMother) { - switch (pdgMother) { - case Pdg::kDPlus: - return DPlus::finalStatesDPlus; - case Pdg::kDS: - return DS::finalStatesDs; - case Pdg::kDStar: - return DStar::finalStatesDStar; - case Pdg::kLambdaCPlus: - return LambdaC::finalStatesLc; - case Pdg::kXiCPlus: - return XiC::finalStatesXic; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } - } - - bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { - // LOG(info) << "Entered checkResonantDecay with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " and resonant PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - // LOG(info) << "arrDaughIndex.size(): " << arrDaughIndex.size() << ", arrPDGResonant.size(): " << arrPDGResonant.size(); - std::array arrPDGResonantAbs = {std::abs(arrPDGResonant[0]), std::abs(arrPDGResonant[1])}; - LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - for (int i = 0; i < 2; i++) { - LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; - bool findDaug = false; - for (int j = 0; j < 2; j++) { - LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonantAbs[j]; - if (std::abs(arrDaughIndex[i]) == arrPDGResonantAbs[j]) { - arrPDGResonantAbs[j] = -1; // Mark as found - LOG(info) << "Matched!"; - findDaug = true; - break; // If a daughter matches, break the inner loop - } - } - if (!findDaug) { - LOG(info) << "Returning false"; - return false; // If any daughter does not match, return false - } - } - LOG(info) << "Resonant decay found with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - return true; - } - - /// Check if the decay is resonant - /// \tparam arrDaughIndex index of the particle daughters at resonance level - /// \tparam arrPDGResonant PDG code of the resonant decay - /// \return true if the decay is resonant - void flagResonantDecay(int motherPdg, int8_t* channel, std::vector arrDaughIndex) { - switch (motherPdg) { - case Pdg::kD0: - for (const auto& [flag, pdgCodes] : D0::resoStatesD0) { - std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kDPlus: - for (const auto& [flag, pdgCodes] : DPlus::resoStatesDPlus) { - // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kDS: - for (const auto& [flag, pdgCodes] : DS::resoStatesDs) { - // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kDStar: - for (const auto& [flag, pdgCodes] : DStar::resoStatesDStarD0) { - std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kLambdaCPlus: - for (const auto& [flag, pdgCodes] : LambdaC::resoStatesLambdaC) { - // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kXiCPlus: - for (const auto& [flag, pdgCodes] : XiC::resoStatesXiC) { - // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - } - LOG(info) << "Leaving function with channel: " << static_cast(*channel); - } - -} // namespace o2::hf_corrbkg - -#endif // PWGHF_CORE_CORRELATEDBKGS_H_ diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 44fefb4eeff..4ad7fa9bb59 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -12,6 +12,7 @@ /// \file DecayChannels.h /// \brief Definitions of constants for MC flagging of HF decay channels. /// \author Vít Kučera , Inha University +/// \author Marcello Di Costanzo , Polytechnic University of Turin and INFN /// \note DecayChannelMain enums define unique combinations of the mother and the daughters for main channels. /// \note DecayChannelResonant enums define unique combinations of the mother and the daughters for resonant channels. /// \note Value 0 is reserved to indicate no match. @@ -21,6 +22,11 @@ #define PWGHF_CORE_DECAYCHANNELS_H_ #include +#include +#include +#include + +using namespace o2::constants::physics; namespace o2::hf_decay { @@ -53,6 +59,24 @@ enum DecayChannelResonant : int8_t { // LastChannelResonant }; + +std::unordered_map > finalStates2Prongs = +{ + {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, + {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} +}; + +std::unordered_map > resoStatesD0 = +{ + {DecayChannelResonant::D0ToRhoplusPi, std::array{213, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, std::array{213, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, +}; + } // namespace hf_cand_2prong namespace hf_cand_3prong @@ -112,6 +136,96 @@ enum DecayChannelResonant : int8_t { // LastChannelResonant }; + + +std::unordered_map > resoStatesDPlus = +{ + {DecayChannelResonant::DplusToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, std::array{+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, std::array{+113, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, std::array{+225, +kPiPlus}}, +}; + +std::unordered_map > finalStatesDPlus = +{ + {DecayChannelMain::DplusToPiKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + // {DecayChannelMain::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +}; + +// Ds± → K± K∓ π± +std::unordered_map > resoStatesDs = +{ + {DecayChannelResonant::DsToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, std::array{+kPhi, +213}}, + {DecayChannelResonant::DsToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, std::array{+kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, std::array{113, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, std::array{113, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, std::array{10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, std::array{221, +kPiPlus}}, +}; + +std::unordered_map > finalStatesDs = +{ + {DecayChannelMain::DsToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +}; + +// // Dstar → K± K∓ π± +// std::unordered_map > resoStatesDStarD0 = +// { +// {DecayChannelResonant::RhoPi, std::array{213, +kPiMinus}}, +// {DecayChannelResonant::RhoK, std::array{213, +kKMinus}}, +// {DecayChannelResonant::K0starPi0, std::array{-kK0Star892, +kPi0}}, +// {DecayChannelResonant::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, +// }; + +// std::unordered_map > finalStatesDStar = +// { +// {DecayChannelMain::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, +// {DecayChannelMain::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, +// {DecayChannelMain::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, +// {DecayChannelMain::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, +// {DecayChannelMain::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +// }; + + // Lc → p K∓ π± +std::unordered_map > resoStatesLambdaC = +{ + {DecayChannelResonant::LcToPKstar0, std::array{+kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, std::array{+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, std::array{+102134, +kPiPlus}}, +}; + +std::unordered_map > finalStatesLc = +{ + {DecayChannelMain::LcToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, std::vector{+kProton, +kKMinus, +kKPlus}} +}; + +// Xic → p K∓ π± +std::unordered_map > resoStatesXiC = +{ + {DecayChannelResonant::XicToPKstar0, std::array{-kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, std::array{+kProton, +kPhi}}, +}; + +std::unordered_map > finalStatesXic = +{ + {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, +}; } // namespace hf_cand_3prong namespace hf_cand_dstar @@ -201,4 +315,125 @@ enum DecayChannelToJpsiResonant : int8_t { } // namespace hf_cand_beauty } // namespace o2::hf_decay +// using namespace o2::hf_decay; + +namespace o2::hf_corrbkg +{ + std::unordered_map > getDecayChannel3Prong(int pdgMother) { + switch (pdgMother) { + case Pdg::kDPlus: + return o2::hf_decay::hf_cand_3prong::finalStatesDPlus; + case Pdg::kDS: + return o2::hf_decay::hf_cand_3prong::finalStatesDs; + case Pdg::kDStar: + return o2::hf_decay::hf_cand_3prong::finalStatesDPlus; + case Pdg::kLambdaCPlus: + return o2::hf_decay::hf_cand_3prong::finalStatesLc; + case Pdg::kXiCPlus: + return o2::hf_decay::hf_cand_3prong::finalStatesXic; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; + } + } + + bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { + // LOG(info) << "Entered checkResonantDecay with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " and resonant PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; + // LOG(info) << "arrDaughIndex.size(): " << arrDaughIndex.size() << ", arrPDGResonant.size(): " << arrPDGResonant.size(); + std::array arrPDGResonantAbs = {std::abs(arrPDGResonant[0]), std::abs(arrPDGResonant[1])}; + LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; + for (int i = 0; i < 2; i++) { + LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; + bool findDaug = false; + for (int j = 0; j < 2; j++) { + LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonantAbs[j]; + if (std::abs(arrDaughIndex[i]) == arrPDGResonantAbs[j]) { + arrPDGResonantAbs[j] = -1; // Mark as found + LOG(info) << "Matched!"; + findDaug = true; + break; // If a daughter matches, break the inner loop + } + } + if (!findDaug) { + LOG(info) << "Returning false"; + return false; // If any daughter does not match, return false + } + } + LOG(info) << "Resonant decay found with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; + return true; + } + + /// Check if the decay is resonant + /// \tparam arrDaughIndex index of the particle daughters at resonance level + /// \tparam arrPDGResonant PDG code of the resonant decay + /// \return true if the decay is resonant + void flagResonantDecay(int motherPdg, int8_t* channel, std::vector arrDaughIndex) { + switch (motherPdg) { + case Pdg::kD0: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { + std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); + break; + } + } + break; + case Pdg::kDPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDPlus) { + // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); + break; + } + } + break; + case Pdg::kDS: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDs) { + // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); + break; + } + } + break; + case Pdg::kDStar: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDStarD0) { + // std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + LOG(info) << "Dstar resonant decay not found, checking D0 resonances"; + break; + case Pdg::kLambdaCPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesLambdaC) { + // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); + break; + } + } + break; + case Pdg::kXiCPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesXiC) { + // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); + break; + } + } + break; + } + LOG(info) << "Leaving function with channel: " << static_cast(*channel); + } + +} // namespace o2::hf_corrbkg + #endif // PWGHF_CORE_DECAYCHANNELS_H_ diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index b9c45258ad7..b61a8d35392 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -47,7 +47,7 @@ #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/Core/SelectorCuts.h" -#include "PWGHF/Core/CorrelatedBkgs.h" +#include "PWGHF/Core/DecayChannels.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/Utils/utilsBfieldCCDB.h" #include "PWGHF/Utils/utilsEvSelHf.h" @@ -60,9 +60,10 @@ using namespace o2::analysis; using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_2prong; +using namespace o2::hf_decay::hf_cand_2prong; +using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; -using namespace o2::hf_corrbkg; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::aod::pid_tpc_tof_utils; @@ -804,7 +805,7 @@ struct HfCandidateCreator2ProngExpressions { if (indexRec != -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], sign*finalState[2]}; if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay } @@ -825,7 +826,7 @@ struct HfCandidateCreator2ProngExpressions { } if (indexRec > -1) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; - flag = sign * (chn + 10); // Only D0 decay channels are considered here + flag = sign * chn; // Only D0 decay channels are considered here // Flag the resonant decay channel int resoMaxDepth = 1; diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 273a795f65c..737baae47c4 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -47,7 +47,6 @@ #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/Core/DecayChannels.h" -#include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/Utils/utilsBfieldCCDB.h" #include "PWGHF/Utils/utilsEvSelHf.h" @@ -59,10 +58,10 @@ using namespace o2; using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_3prong; -using namespace o2::hf_decay::hf_cand_3prong; +using namespace o2::hf_decay; +using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; -using namespace o2::hf_corrbkg; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; @@ -947,101 +946,83 @@ struct HfCandidateCreator3ProngExpressions { if (matchCorrBkgs) { // LOG(info) << "--------------------------------------------"; - // LOG(info) << "Matching correlated bkgs"; - std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - indexRec = -1; // Index of the matched reconstructed candidate - std::vector arrResoDaughIndex = {}; - - for (const auto& pdg : mothersPdgCodes) { - int depth = 2; - if (pdg == Pdg::kDStar) { - depth = 3; // D0 resonant decays are active - } - auto finalStates = getParticleFinalStates3Prongs(pdg); - for (const auto& [chn, finalState] : finalStates) { - std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() == 4) { // Partly Reco 3-prong decays - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); - } + LOG(info) << "Matching correlated bkgs"; + // // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + // indexRec = -1; // Index of the matched reconstructed candidate + // std::vector arrResoDaughIndex = {}; + + // for (const auto& pdg : mothersPdgCodes) { + // int depth = 2; + // if (pdg == Pdg::kDStar) { + // depth = 3; // D0 resonant decays are active + // } + // auto finalStates = getDecayChannel3Prong(pdg); + // for (const auto& [chn, finalState] : finalStates) { + // std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; + // if (finalState.size() == 4) { // Partly Reco 3-prong decays + // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + // } - if (indexRec != -1) { - auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay - } - } - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); - } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); - } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); - } - } else { - LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states - } - if (indexRec > -1) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; - switch (pdg) { - case Pdg::kDPlus: - flag = sign * (chn + 30); - break; - case Pdg::kDS: - flag = sign * (chn + 50); - break; - case Pdg::kDStar: - flag = sign * (chn + 70); - break; - case Pdg::kLambdaCPlus: - flag = sign * (chn + 90); - break; - case Pdg::kXiCPlus: - flag = sign * (chn + 110); - break; - default: - LOG(info) << "Unknown mother PDG code: " << pdg << ", skipping."; - continue; // Skip unknown mother PDG codes - } + // if (indexRec != -1) { + // auto motherParticle = mcParticles.rawIteratorAt(indexRec); + // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3]}; + // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + // indexRec = -1; // Reset indexRec if the generated decay + // } + // } + // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + // } else { + // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + // } + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // if (indexRec > -1) { + // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; + // flag = sign * chn; - // Flag the resonant decay channel - int resoMaxDepth = 1; - int NDaughtersResonant = 2; - if (std::abs(pdg) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances - } - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; - if (arrResoDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if ( (std::abs(pdg) == Pdg::kDStar) || - ( (std::abs(pdg) == Pdg::kXiCPlus) && - (std::abs(daughI.pdgCode()) == kPiPlus) && - (arrPDGDaugh.size() >= 2) ) ) { - continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - } - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - } - flagResonantDecay(pdg, &channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); - } - break; // Exit loop if a match is found - } - } - } + // // Flag the resonant decay channel + // int resoMaxDepth = 1; + // int NDaughtersResonant = 2; + // if (std::abs(pdg) == Pdg::kDStar) { + // resoMaxDepth = 2; // Flag D0 resonances + // } + // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // std::vector arrPDGDaugh = {}; + // if (arrResoDaughIndex.size() == NDaughtersResonant) { + // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ( (std::abs(pdg) == Pdg::kDStar) || + // ( (std::abs(pdg) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // } + // flagResonantDecay(pdg, &channel, arrPDGDaugh); + // // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); + // // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + // } + // break; // Exit loop if a match is found + // } + // } + // } // LOG(info) (flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± @@ -1058,7 +1039,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * DecayChannelMain::DplusToPiKPi; + flag = sign * hf_cand_3prong::DecayChannelMain::DplusToPiKPi; } } LOG(info) << "D+ matching ended"; @@ -1088,7 +1069,7 @@ struct HfCandidateCreator3ProngExpressions { } } if (indexRec > -1) { - flag = sign * (isDplus ? DecayChannelMain::DplusToPiKK : DecayChannelMain::DsToPiKK); + flag = sign * (isDplus ? hf_cand_3prong::DecayChannelMain::DplusToPiKK : hf_cand_3prong::DecayChannelMain::DsToPiKK); if (arrayDaughters[0].has_mcParticle()) { swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); } @@ -1099,27 +1080,14 @@ struct HfCandidateCreator3ProngExpressions { arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); } if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { - channel = isDplus ? DecayChannelResonant::DplusToPhiPi : DecayChannelResonant::DsToPhiPi; + channel = isDplus ? hf_cand_3prong::DecayChannelResonant::DplusToPhiPi : hf_cand_3prong::DecayChannelResonant::DsToPhiPi; } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { - channel = isDplus ? DecayChannelResonant::DplusToKstar0K : DecayChannelResonant::DsToKstar0K; + channel = isDplus ? hf_cand_3prong::DecayChannelResonant::DplusToKstar0K : hf_cand_3prong::DecayChannelResonant::DsToKstar0K; } } } } - // D* → D0π → Kππ - if (flag == 0) { - if (matchKinkedDecayTopology) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); - } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); - } - if (indexRec > -1) { - flag = sign * DecayChannelMain::DstarToPiKPi; - channel = 1; - } - } - // Λc± → p± K∓ π± if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -1132,7 +1100,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * DecayChannelMain::LcToPKPi; + flag = sign * hf_cand_3prong::DecayChannelMain::LcToPKPi; } } @@ -1148,7 +1116,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * DecayChannelMain::XicToPKPi; + flag = sign * hf_cand_3prong::DecayChannelMain::XicToPKPi; if (arrayDaughters[0].has_mcParticle()) { swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); } diff --git a/PWGHF/TableProducer/trackIndexSkimCreator.cxx b/PWGHF/TableProducer/trackIndexSkimCreator.cxx index 0f98525ceb1..30039c6bc80 100644 --- a/PWGHF/TableProducer/trackIndexSkimCreator.cxx +++ b/PWGHF/TableProducer/trackIndexSkimCreator.cxx @@ -63,6 +63,8 @@ using namespace o2::aod; using namespace o2::hf_centrality; using namespace o2::framework; using namespace o2::framework::expressions; +using namespace o2::aod::hf_cand_2prong; +using namespace o2::aod::hf_cand_3prong; // enum for candidate type enum CandidateType { @@ -1222,8 +1224,8 @@ struct HfTrackIndexSkimCreator { // int nColls{0}; //can be added to run over limited collisions per file - for tesing purposes - static constexpr int kN2ProngDecays = hf_cand_2prong::DecayType::N2ProngDecays; // number of 2-prong hadron types - static constexpr int kN3ProngDecays = hf_cand_3prong::DecayType::N3ProngDecays; // number of 3-prong hadron types + static constexpr int kN2ProngDecays = o2::aod::hf_cand_2prong::DecayType::N2ProngDecays; // number of 2-prong hadron types + static constexpr int kN3ProngDecays = o2::aod::hf_cand_3prong::DecayType::N3ProngDecays; // number of 3-prong hadron types static constexpr int kNCuts2Prong[kN2ProngDecays] = {hf_cuts_presel_2prong::NCutVars, hf_cuts_presel_2prong::NCutVars, hf_cuts_presel_2prong::NCutVars}; // how many different selections are made on 2-prongs static constexpr int kNCuts3Prong[kN3ProngDecays] = {hf_cuts_presel_3prong::NCutVars, hf_cuts_presel_3prong::NCutVars + 1, hf_cuts_presel_ds::NCutVars, hf_cuts_presel_3prong::NCutVars + 1}; // how many different selections are made on 3-prongs (Lc and Xic have also PID potentially) static constexpr int kNCutsDstar = 3; // how many different selections are made on Dstars diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 2668b5f7773..327c909ed0f 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -23,7 +23,7 @@ #include "Framework/runDataProcessing.h" #include "PWGHF/Core/HfHelper.h" -#include "PWGHF/Core/CorrelatedBkgs.h" +// #include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/DataModel/CandidateSelectionTables.h" @@ -266,7 +266,8 @@ struct HfTreeCreatorDplusToPiKPi { using SelectedCandidatesMc = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; using SelectedCandidatesMcWithMl = soa::Filtered>; - using SelectedCandidatesMcCorrBkgsWithMl = soa::Filtered>; + using MatchedGenCandidatesMcCorrBkgs = soa::Join; + using SelectedCandidatesMcCorrBkgsWithMl = soa::Join; using TracksWPid = soa::Join; using CollisionsCent = soa::Join; @@ -277,7 +278,7 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK); Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi); - Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); void init(InitContext const&) { @@ -514,11 +515,11 @@ struct HfTreeCreatorDplusToPiKPi { PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processDataWCent, "Process data with cent", false); - template + template void fillMcTables(CollType const& collisions, aod::McCollisions const&, - CandType const& candidates, - MatchedGenCandidatesMc const& particles, + CandTypeMcRec const& candidates, + CandTypeMcGen const& particles, TracksWPid const&) { // Filling event properties @@ -622,7 +623,7 @@ struct HfTreeCreatorDplusToPiKPi { void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, aod::McCollisions const& mccollisions, SelectedCandidatesMcCorrBkgsWithMl const&, - MatchedGenCandidatesMc const& particles, + MatchedGenCandidatesMcCorrBkgs const& particles, TracksWPid const& tracks) { LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " particles"; diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index ed35c4c3406..37100daf909 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -31,8 +31,8 @@ #include "PWGHF/Core/DecayChannels.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" -#include "PWGHF/Core/CorrelatedBkgs.h" - +using namespace o2::hf_decay::hf_cand_2prong; +using namespace o2::hf_decay::hf_cand_3prong; using namespace o2::hf_corrbkg; namespace hf_mc_gen @@ -65,6 +65,9 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V for (const auto& [chn, finalState] : finalStates2Prongs) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + if (particle.pdgCode() < 0) { + finalStateParts.back() = -finalState.back(); + } matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); } else if (finalState.size() == 2) { // Fully Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1]}; @@ -75,7 +78,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matched) { // std::cout << "Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << std::endl; - flag = sign * (chn + 10); + flag = sign * chn; // Flag the resonant decay channel int resoMaxDepth = 1; @@ -124,10 +127,10 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { - LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); + // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { - LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); + // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } @@ -162,112 +165,95 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matchCorrBkgs) { - // LOG(info) << "--------------------------------------------"; + LOG(info) << "--------------------------------------------"; // LOG(info) << "Matching gen correlated bkgs of 3prongs"; - std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - for (const auto& motherPdgCode : mothersPdgCodes) { - if (std::abs(particle.pdgCode()) != motherPdgCode) { - continue; // Skip if the particle PDG code does not match the mother PDG code - } - auto finalStates = getParticleFinalStates3Prongs(motherPdgCode); - int maxDepth = 2; - bool matched = false; - if (motherPdgCode == Pdg::kDStar) { - maxDepth = 3; // to catch the D0 resonances - } - - std::vector arrResoDaughIndex = {}; - std::vector arrAllDaughtersIndex; // vector of indices of all daughters - for (const auto& [chn, finalState] : finalStates) { - if (finalState.size() == 4) { // Partly Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); - matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); - matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); - } else { - LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states - } - if (matched) { - std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; - switch (motherPdgCode) { - case Pdg::kDPlus: - flag = sign * (chn + 30); - break; - case Pdg::kDS: - flag = sign * (chn + 50); - break; - case Pdg::kDStar: - flag = sign * (chn + 70); - break; - case Pdg::kLambdaCPlus: - flag = sign * (chn + 90); - break; - case Pdg::kXiCPlus: - flag = sign * (chn + 110); - break; - default: - LOG(info) << "Unknown mother PDG code: " << motherPdgCode << ", skipping."; - continue; // Skip unknown mother PDG codes - } + // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + // for (const auto& motherPdgCode : mothersPdgCodes) { + // if (std::abs(particle.pdgCode()) != motherPdgCode) { + // continue; // Skip if the particle PDG code does not match the mother PDG code + // } + // auto finalStates = getDecayChannel3Prong(motherPdgCode); + // int maxDepth = 2; + // bool matched = false; + // if (motherPdgCode == Pdg::kDStar) { + // maxDepth = 3; // to catch the D0 resonances + // } - // Flag the resonant decay channel - int resoMaxDepth = 1; - int NDaughtersResonant = 2; - if (std::abs(motherPdgCode) == Pdg::kDStar) { - std::vector arrResoDaughIndexDStar = {}; - RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); - for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { - if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { - auto daughD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); - RecoDecay::getDaughters(daughD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - break; - } - std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; - } - } else { - RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - } - std::vector arrPDGDaugh = {}; - if (std::abs(motherPdgCode) == Pdg::kDStar) { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); - } - if (arrResoDaughIndex.size() == NDaughtersResonant) { - if (std::abs(motherPdgCode) == Pdg::kDStar) { - LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; - } - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(motherPdgCode) == Pdg::kDStar) || - if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && - (std::abs(daughI.pdgCode()) == kPiPlus) && - (arrPDGDaugh.size() >= 2) ) { - continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - } - if (std::abs(motherPdgCode) == Pdg::kDStar) { - std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - } - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - } - flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); - if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); - } - } - break; // Exit loop if a match is found - } - } - } + // std::vector arrResoDaughIndex = {}; + // std::vector arrAllDaughtersIndex; // vector of indices of all daughters + // for (const auto& [chn, finalState] : finalStates) { + // if (finalState.size() == 4) { // Partly Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + // if (particle.pdgCode() < 0) { + // finalStateParts.back() = -finalState.back(); + // } + // RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + // matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); + // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + // RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + // matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); + // } else { + // LOG(info) << "Final state size not supported: " << finalState.size(); + // continue; // Skip unsupported final states + // } + // if (matched) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; + // flag = sign * chn; + // // Flag the resonant decay channel + // int resoMaxDepth = 1; + // int NDaughtersResonant = 2; + // if (std::abs(motherPdgCode) == Pdg::kDStar) { + // std::vector arrResoDaughIndexDStar = {}; + // RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); + // for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { + // if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { + // auto daughD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + // RecoDecay::getDaughters(daughD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // break; + // } + // std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; + // } + // } else { + // RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + // } + // std::vector arrPDGDaugh = {}; + // if (std::abs(motherPdgCode) == Pdg::kDStar) { + // LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); + // } + // if (arrResoDaughIndex.size() == NDaughtersResonant) { + // if (std::abs(motherPdgCode) == Pdg::kDStar) { + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; + // } + // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // // if ( (std::abs(motherPdgCode) == Pdg::kDStar) || + // if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + // if (std::abs(motherPdgCode) == Pdg::kDStar) { + // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + // } + // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // } + // flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); + // if (std::abs(motherPdgCode) == Pdg::kDStar) { + // // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + // // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + // } + // } + // break; // Exit loop if a match is found + // } + // } + // } } else { // D± → π± K∓ π± if (flag == 0) { if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi; + flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::DplusToPiKPi); } } @@ -277,24 +263,24 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± // TODO: move to different and explicit flags - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK; + flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::DsToKKPi); } else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± // TODO: move to different and explicit flags - flag = sign * o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK; + flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::DsToKKPi); isDplus = true; } if (flag != 0) { RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == NDaughtersResonant) { + if (arrDaughIndex.size() == 2) { for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); } if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { - channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi; + channel = isDplus ? o2::aod::hf_cand_3prong::DecayChannelDToKKPi::DplusToPhiPi : o2::aod::hf_cand_3prong::DecayChannelDToKKPi::DsToPhiPi; } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { - channel = isDplus ? o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K : o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K; + channel = isDplus ? o2::aod::hf_cand_3prong::DecayChannelDToKKPi::DplusToK0starK : o2::aod::hf_cand_3prong::DecayChannelDToKKPi::DsToK0starK; } } } @@ -346,10 +332,10 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (origin == RecoDecay::OriginType::NonPrompt) { // LOG(info) << "Origin is non-prompt"; - LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); + // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { - LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); + // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } From fa821068d8c977901772b32861e9b06f4764c74f Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sun, 8 Jun 2025 18:45:26 +0200 Subject: [PATCH 14/47] Improve code clarity --- Common/Core/RecoDecay.h | 38 +++ PWGHF/Core/DecayChannels.h | 317 +++++++++++------- .../TableProducer/candidateCreator3Prong.cxx | 199 ++++++----- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 12 +- PWGHF/Utils/utilsMcGen.h | 192 ++++++----- 5 files changed, 472 insertions(+), 286 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index 7716a8d64a0..d1118f6be10 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,6 +25,7 @@ #include // std::apply #include // std::move #include // std::vector +#include // ROOT includes #include // for VMC Particle Production Process @@ -918,12 +919,20 @@ struct RecoDecay { } // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); + bool debugPrint = false; // Set to true to enable debug printing. + if (std::abs(pdgCandidate) == 413) { + // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); + debugPrint = true; // Enable debug printing for D*. + } // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match sgn = -1; } else { + if (debugPrint) { + std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl; + } // Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle)); return false; } @@ -933,18 +942,32 @@ struct RecoDecay { std::vector arrAllDaughtersIndex; // vector of indices of all daughters // Check the daughter indices. if (!candidate.has_daughters()) { + if (debugPrint) { + std::cout << "MC Gen: Rejected: bad daughter index range: " << candidate.daughtersIds().front() << "-" << candidate.daughtersIds().back() << std::endl; + } // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); return false; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!checkProcess) { if (candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 > static_cast(N)) { + if (debugPrint) { + std::cout << "MC Gen: Rejected: too many direct daughters: " << candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 + << " (expected " << N << " final)" << std::endl; + } // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); return false; } } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); + if (debugPrint) { + std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final daughters:"; + for (auto i : arrAllDaughtersIndex) { + std::cout << " " << i; + } + std::cout << std::endl; + } // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { // printf(" %d", i); @@ -952,6 +975,9 @@ struct RecoDecay { // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { + if (debugPrint) { + std::cout << "MC Gen: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; + } // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } @@ -969,9 +995,15 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter + if (debugPrint) { + std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; + } // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { + if (debugPrint) { + std::cout << "MC Gen: Checking against expected PDG: " << coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp] << std::endl; + } if (pdgCandidateDaughterI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) { arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones. isPdgFound = true; @@ -979,6 +1011,9 @@ struct RecoDecay { } } if (!isPdgFound) { + if (debugPrint) { + std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl; + } // Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI); return false; } @@ -987,6 +1022,9 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } + if (debugPrint) { + std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; + } // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 4ad7fa9bb59..f6b18a1fa64 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -84,55 +84,71 @@ namespace hf_cand_3prong /// @brief 3-prong candidates: main channels enum DecayChannelMain : int8_t { // D+ - DplusToPiKPi = 1, // π+ K− π+ - DplusToPiKPiPi0, // π+ K− π+ π0 - DplusToPiPiPi, // π+ π− π+ - DplusToPiKK, // π+ K− K+ + DplusToPiKPi = 1, // 1, π+ K− π+ + DplusToPiKPiPi0, // 2, π+ K− π+ π0 + DplusToPiPiPi, // 3, π+ π− π+ + DplusToPiKK, // 4, π+ K− K+ // Ds+ - DsToPiKK, // π+ K− K+ - DsToPiKKPi0, // π+ K− K+ π0 - DsToPiPiK, // π+ π− K+ - DsToPiPiPi, // π+ π− π+ - DsToPiPiPiPi0, // π+ π− π+ π0 + DsToPiKK, // 5, π+ K− K+ + DsToPiKKPi0, // 6, π+ K− K+ π0 + DsToPiPiK, // 7, π+ π− K+ + DsToPiPiPi, // 8, π+ π− π+ + DsToPiPiPiPi0, // 9, π+ π− π+ π0 // D*+ - DstarToPiKPi, // π+ K− π+ (from [(D0 → π+ K−) π+]) + DstarToPiKPi, // 10, π+ K− π+ (from [(D0 → π+ K−) π+]) + DstarToPiKPiPi0, // 11, π+ K− π+ π0 + DstarToPiKPiPi0Pi0, // 12, π+ K− π+ π0 π0 + DstarToPiKK, // 13, π+ K− K+ + DstarToPiKKPi0, // 14, π+ K− K+ π0 + DstarToPiPiPi, // 15, π+ π− π+ + DstarToPiPiPiPi0, // 16, π+ π− π+ π0 // Λc+ - LcToPKPi, // p K− π+ - LcToPKPiPi0, // p K− π+ π0 - LcToPPiPi, // p π− π+ - LcToPKK, // p K− K+ + LcToPKPi, // 17, p K− π+ + LcToPKPiPi0, // 18, p K− π+ π0 + LcToPPiPi, // 19, p π− π+ + LcToPKK, // 20, p K− K+ // Ξc+ - XicToPKPi, // p K− π+ - XicToPKK, // p K− K+ - XicToSPiPi, // Σ+ π− π+ + XicToPKPi, // 21, p K− π+ + XicToPKK, // 22, p K− K+ + XicToSPiPi, // 23, Σ+ π− π+ // LastChannelMain }; /// @brief 3-prong candidates: resonant channels enum DecayChannelResonant : int8_t { // D+ - DplusToPhiPi = 1, // φ π+ - DplusToKstar0K, // anti-K*0 K+ - DplusToKstar1430_0K, // anti-K*0(1430) K+ - DplusToRho0Pi, // ρ0 π+ - DplusToF2_1270Pi, // f2(1270) π+ + DplusToPhiPi = 1, // 1, φ π+ + DplusToKstar0K, // 2, anti-K*0 K+ + DplusToKstar1430_0K, // 3, anti-K*0(1430) K+ + DplusToRho0Pi, // 4, ρ0 π+ + DplusToF2_1270Pi, // 5, f2(1270) π+ // Ds+ - DsToPhiPi, // φ π+ - DsToPhiRhoplus, // φ ρ+ - DsToKstar0K, // anti-K*0 K+ - DsToKstar0Pi, // anti-K*0 π+ - DsToRho0Pi, // ρ0 π+ - DsToRho0K, // ρ0 K+ - DsToF2_1270Pi, // f2(1270) π+ - DsToF0_1370K, // f0(1370) K+ - DsToEtaPi, // η π+ + DsToPhiPi, // 6, φ π+ + DsToPhiRhoplus, // 7, φ ρ+ + DsToKstar0K, // 8, anti-K*0 K+ + DsToKstar0Pi, // 9, anti-K*0 π+ + DsToRho0Pi, // 10, ρ0 π+ + DsToRho0K, // 11, ρ0 K+ + DsToF2_1270Pi, // 12, f2(1270) π+ + DsToF0_1370K, // 13, f0(1370) K+ + DsToEtaPi, // 14, η π+ + // D*+ + DstarToD0ToRhoplusPi, // 15, ρ+ π− + DstarToD0ToRhoplusK, // 16, ρ+ K− + DstarToD0ToKstar0Pi0, // 17, anti-K*0 π0 + DstarToD0ToKstarPi, // 18, K*− π+ + DstarToDplusToPhiPi, // 19, φ π+ + DstarToDplusToKstar0K, // 20, anti-K*0 K+ + DstarToDplusToKstar1430_0K, // 21, anti-K*0(1430) K+ + DstarToDplusToRho0Pi, // 22, ρ0 π+ + DstarToDplusToF2_1270Pi, // 23, f2(1270) π+ // Λc+ - LcToPKstar0, // p K*0(892) - LcToDeltaplusplusK, // Δ++ K− - LcToL1520Pi, // Λ(1520) π+ + LcToPKstar0, // 24, p K*0(892) + LcToDeltaplusplusK, // 25, Δ++ K− + LcToL1520Pi, // 26, Λ(1520) π+ // Ξc+ - XicToPKstar0, // p anti-K*0(892) - XicToPPhi, // p φ + XicToPKstar0, // 27, p anti-K*0(892) + XicToPPhi, // 28, p φ // LastChannelResonant }; @@ -153,7 +169,6 @@ std::unordered_map > finalStatesDPlus = {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - // {DecayChannelMain::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Ds± → K± K∓ π± @@ -179,25 +194,32 @@ std::unordered_map > finalStatesDs = {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; -// // Dstar → K± K∓ π± -// std::unordered_map > resoStatesDStarD0 = -// { -// {DecayChannelResonant::RhoPi, std::array{213, +kPiMinus}}, -// {DecayChannelResonant::RhoK, std::array{213, +kKMinus}}, -// {DecayChannelResonant::K0starPi0, std::array{-kK0Star892, +kPi0}}, -// {DecayChannelResonant::K0starPiPlus, std::array{-kKPlusStar892, +kPiPlus}}, -// }; +// Dstar → K± K∓ π± +std::unordered_map > resoStatesDstar = +{ + {DecayChannelResonant::DstarToD0ToRhoplusPi, std::array{213, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, std::array{213, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, +}; -// std::unordered_map > finalStatesDStar = -// { -// {DecayChannelMain::KKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, -// {DecayChannelMain::KMinusPiPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, -// {DecayChannelMain::KMinusPiPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, -// {DecayChannelMain::PiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, -// {DecayChannelMain::PiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, -// }; +std::unordered_map > finalStatesDstar = +{ + {DecayChannelMain::DstarToPiKPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +}; - // Lc → p K∓ π± +// Lc → p K∓ π± std::unordered_map > resoStatesLambdaC = { {DecayChannelResonant::LcToPKstar0, std::array{+kK0Star892, +kProton}}, @@ -326,7 +348,7 @@ namespace o2::hf_corrbkg case Pdg::kDS: return o2::hf_decay::hf_cand_3prong::finalStatesDs; case Pdg::kDStar: - return o2::hf_decay::hf_cand_3prong::finalStatesDPlus; + return o2::hf_decay::hf_cand_3prong::finalStatesDstar; case Pdg::kLambdaCPlus: return o2::hf_decay::hf_cand_3prong::finalStatesLc; case Pdg::kXiCPlus: @@ -337,26 +359,44 @@ namespace o2::hf_corrbkg } } - bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { + std::unordered_map > getResoChannels3Prong(int pdgMother) { + switch (pdgMother) { + case Pdg::kDPlus: + return o2::hf_decay::hf_cand_3prong::resoStatesDPlus; + case Pdg::kDS: + return o2::hf_decay::hf_cand_3prong::resoStatesDs; + case Pdg::kDStar: + return o2::hf_decay::hf_cand_3prong::resoStatesDstar; + case Pdg::kLambdaCPlus: + return o2::hf_decay::hf_cand_3prong::resoStatesLambdaC; + case Pdg::kXiCPlus: + return o2::hf_decay::hf_cand_3prong::resoStatesXiC; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; + } + } + + template + bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { // LOG(info) << "Entered checkResonantDecay with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " and resonant PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; // LOG(info) << "arrDaughIndex.size(): " << arrDaughIndex.size() << ", arrPDGResonant.size(): " << arrPDGResonant.size(); - std::array arrPDGResonantAbs = {std::abs(arrPDGResonant[0]), std::abs(arrPDGResonant[1])}; LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - for (int i = 0; i < 2; i++) { + for (int i = 0; i < N; i++) { LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; bool findDaug = false; - for (int j = 0; j < 2; j++) { - LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonantAbs[j]; - if (std::abs(arrDaughIndex[i]) == arrPDGResonantAbs[j]) { - arrPDGResonantAbs[j] = -1; // Mark as found + for (int j = 0; j < N; j++) { + LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonant[j]; + if (std::abs(arrDaughIndex[i]) == std::abs(arrPDGResonant[j])) { + arrPDGResonant[j] = -1; // Mark as found LOG(info) << "Matched!"; findDaug = true; - break; // If a daughter matches, break the inner loop + break; } } if (!findDaug) { LOG(info) << "Returning false"; - return false; // If any daughter does not match, return false + return false; } } LOG(info) << "Resonant decay found with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; @@ -367,72 +407,105 @@ namespace o2::hf_corrbkg /// \tparam arrDaughIndex index of the particle daughters at resonance level /// \tparam arrPDGResonant PDG code of the resonant decay /// \return true if the decay is resonant + template void flagResonantDecay(int motherPdg, int8_t* channel, std::vector arrDaughIndex) { - switch (motherPdg) { - case Pdg::kD0: - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { + if constexpr (is3Prong) { + std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); + for (const auto& [flag, pdgCodes] : resoStates) { + if (abs(motherPdg) == Pdg::kDStar) { std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kDPlus: - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDPlus) { - // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); - break; - } } - break; - case Pdg::kDS: - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDs) { - // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); - break; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + if (abs(motherPdg) == Pdg::kDStar) { + LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); } + break; } - break; - case Pdg::kDStar: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDStarD0) { - // std::cout << "Checking DStar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - LOG(info) << "Dstar resonant decay not found, checking D0 resonances"; - break; - case Pdg::kLambdaCPlus: - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesLambdaC) { - // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); - break; - } - } - break; - case Pdg::kXiCPlus: - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesXiC) { - // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); - break; - } + } + if (abs(motherPdg) == Pdg::kDStar) { + LOG(info) << "Leaving function with channel: " << static_cast(*channel); + } + } else { + if (motherPdg != Pdg::kD0) { + LOG(error) << "Resonant decay flagging is only implemented for D0 resonances in 2-prong decays."; + return; + } + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { + std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; + if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + *channel = flag; + LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); + break; } - break; + } } - LOG(info) << "Leaving function with channel: " << static_cast(*channel); } + + // switch (motherPdg) { + // case Pdg::kD0: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { + // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // break; + // case Pdg::kDPlus: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDPlus) { + // // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // break; + // case Pdg::kDS: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDs) { + // // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // break; + // case Pdg::kDStar: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDstar) { + // std::cout << "Checking Dstar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // LOG(info) << "Dstar resonant decay not found, checking D0 resonances"; + // break; + // case Pdg::kLambdaCPlus: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesLambdaC) { + // // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // break; + // case Pdg::kXiCPlus: + // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesXiC) { + // // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; + // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { + // *channel = flag; + // LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); + // break; + // } + // } + // break; + // } + // } } // namespace o2::hf_corrbkg diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 737baae47c4..6c2e380a6ec 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -944,86 +944,128 @@ struct HfCandidateCreator3ProngExpressions { } } + LOG(info) << "CIAO REC MATCHING"; if (matchCorrBkgs) { + LOG(info) << "CIAO 1"; // LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching correlated bkgs"; - // // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - // indexRec = -1; // Index of the matched reconstructed candidate - // std::vector arrResoDaughIndex = {}; - - // for (const auto& pdg : mothersPdgCodes) { - // int depth = 2; - // if (pdg == Pdg::kDStar) { - // depth = 3; // D0 resonant decays are active - // } - // auto finalStates = getDecayChannel3Prong(pdg); - // for (const auto& [chn, finalState] : finalStates) { - // std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - // if (finalState.size() == 4) { // Partly Reco 3-prong decays - // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); - // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); - // } + // LOG(info) << "Matching correlated bkgs"; + // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + indexRec = -1; // Index of the matched reconstructed candidate + std::vector arrResoDaughIndex = {}; + + LOG(info) << "CIAO 2"; + for (const auto& pdg : mothersPdgCodes) { + int depth = 2; + if (pdg == Pdg::kDStar) { + depth = 3; // D0 resonant decays are active + } + LOG(info) << "CIAO 3"; + auto finalStates = getDecayChannel3Prong(pdg); + LOG(info) << "CIAO 3.0"; + for (const auto& [chn, finalState] : finalStates) { + LOG(info) << "CIAO 3.0.1"; + std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; + if (finalState.size() > 3) { // Partly Reco 3-prong decays + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + } - // if (indexRec != -1) { - // auto motherParticle = mcParticles.rawIteratorAt(indexRec); - // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3]}; - // if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { - // indexRec = -1; // Reset indexRec if the generated decay - // } - // } - // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); - // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); - // } else { - // indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); - // } - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // if (indexRec > -1) { - // // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; - // flag = sign * chn; + LOG(info) << "CIAO 3.0.2"; + if (indexRec != -1) { + auto motherParticle = mcParticles.rawIteratorAt(indexRec); + if (finalState.size() == 4) { // Check if the final state has 4 particles + std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3]}; + if (pdg < 0) { + for (auto& part : finalStateParts3ProngAll) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } + } + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay is not matched + } + LOG(info) << "CIAO 3.0.3"; + } else if (finalState.size() == 5) { // Check if the final state has 3 particles + // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3], sign*finalState[4]}; + LOG(info) << "CIAO 3.0.4"; + std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; + if (pdg < 0) { + for (auto& part : finalStateParts3ProngAll) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } + LOG(info) << "CIAO 3.0.5"; + } + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + indexRec = -1; // Reset indexRec if the generated decay is not matched + LOG(info) << "CIAO 3.0.6"; + } + LOG(info) << "CIAO 3.0.7"; + } + LOG(info) << "CIAO 3.0.8"; + } + LOG(info) << "CIAO 3.0.9"; + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + LOG(info) << "CIAO 3.1"; + if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); + } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); + } + LOG(info) << "CIAO 3.2"; + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + LOG(info) << "CIAO 4"; + if (indexRec > -1) { + // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; + flag = sign * chn; - // // Flag the resonant decay channel - // int resoMaxDepth = 1; - // int NDaughtersResonant = 2; - // if (std::abs(pdg) == Pdg::kDStar) { - // resoMaxDepth = 2; // Flag D0 resonances - // } - // RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // std::vector arrPDGDaugh = {}; - // if (arrResoDaughIndex.size() == NDaughtersResonant) { - // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(pdg) == Pdg::kDStar) || - // ( (std::abs(pdg) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - // } - // flagResonantDecay(pdg, &channel, arrPDGDaugh); - // // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); - // // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); - // } - // break; // Exit loop if a match is found - // } - // } - // } - // LOG(info) (flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(pdg) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances + } + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + std::vector arrPDGDaugh = {}; + if (arrResoDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ( (std::abs(pdg) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(pdg, &channel, arrPDGDaugh); + LOG(info) << "CIAO 5"; + // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + } + break; // Exit loop if a match is found + } + LOG(info) << "CIAO 6"; + } + } + LOG(info) << "CIAO 7"; + LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± LOG(info) << "--------------------------------------------"; @@ -1139,7 +1181,8 @@ struct HfCandidateCreator3ProngExpressions { rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } - + + LOG(info) << "BYE REC MATCHING, HELLO GEN MATCHING"; // LOG(info) << "Filling MC match gen for 3 prong candidates"; // LOG(info) << "Number of MC collisions: " << mcCollisions.size(); for (const auto& mcCollision : mcCollisions) { @@ -1182,6 +1225,8 @@ struct HfCandidateCreator3ProngExpressions { hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } + LOG(info) << "BYE GEN MATCHING"; + } void processMc(aod::TracksWMc const& tracks, diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 327c909ed0f..3f6480b25ba 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -23,7 +23,6 @@ #include "Framework/runDataProcessing.h" #include "PWGHF/Core/HfHelper.h" -// #include "PWGHF/Core/CorrelatedBkgs.h" #include "PWGHF/Core/CentralityEstimation.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/DataModel/CandidateSelectionTables.h" @@ -278,7 +277,7 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK); Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi); - Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); + Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); void init(InitContext const&) { @@ -622,12 +621,13 @@ struct HfTreeCreatorDplusToPiKPi { void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, aod::McCollisions const& mccollisions, - SelectedCandidatesMcCorrBkgsWithMl const&, - MatchedGenCandidatesMcCorrBkgs const& particles, + SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, + MatchedGenCandidatesMcCorrBkgs const& particles, // MatchedGenCandidatesMcCorrBkgs const& particles, TracksWPid const& tracks) { - LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " particles"; - fillMcTables(collisions, mccollisions, reconstructedCandCorrBkgsMl, particles, tracks); + LOG(info) << "processMcCorrBkgsSgnWCentMl with " << reconstructedCandCorrBkgsMl.size() << " reco particles"; + LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " generated particles"; + // fillMcTables(collisions, mccollisions, reconstructedCandCorrBkgsMl, particles, tracks); } PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcCorrBkgsSgnWCentMl, "Process MC correlated bkgs with cent and ML info", false); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 37100daf909..9bb83d68fcc 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -165,89 +165,119 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matchCorrBkgs) { - LOG(info) << "--------------------------------------------"; + // LOG(info) << "--------------------------------------------"; // LOG(info) << "Matching gen correlated bkgs of 3prongs"; - // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - // for (const auto& motherPdgCode : mothersPdgCodes) { - // if (std::abs(particle.pdgCode()) != motherPdgCode) { - // continue; // Skip if the particle PDG code does not match the mother PDG code - // } - // auto finalStates = getDecayChannel3Prong(motherPdgCode); - // int maxDepth = 2; - // bool matched = false; - // if (motherPdgCode == Pdg::kDStar) { - // maxDepth = 3; // to catch the D0 resonances - // } + std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; + for (const auto& motherPdgCode : mothersPdgCodes) { + if (std::abs(particle.pdgCode()) != motherPdgCode) { + continue; // Skip if the particle PDG code does not match the mother PDG code + } + auto finalStates = getDecayChannel3Prong(motherPdgCode); + int maxDepth = 2; + bool matched = false; + if (motherPdgCode == Pdg::kDStar) { + maxDepth = 3; // to catch the D0 resonances + } - // std::vector arrResoDaughIndex = {}; - // std::vector arrAllDaughtersIndex; // vector of indices of all daughters - // for (const auto& [chn, finalState] : finalStates) { - // if (finalState.size() == 4) { // Partly Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - // if (particle.pdgCode() < 0) { - // finalStateParts.back() = -finalState.back(); - // } - // RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); - // matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - // } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - // RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); - // matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); - // } else { - // LOG(info) << "Final state size not supported: " << finalState.size(); - // continue; // Skip unsupported final states - // } - // if (matched) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; - // flag = sign * chn; - // // Flag the resonant decay channel - // int resoMaxDepth = 1; - // int NDaughtersResonant = 2; - // if (std::abs(motherPdgCode) == Pdg::kDStar) { - // std::vector arrResoDaughIndexDStar = {}; - // RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); - // for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { - // if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { - // auto daughD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); - // RecoDecay::getDaughters(daughD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // break; - // } - // std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; - // } - // } else { - // RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - // } - // std::vector arrPDGDaugh = {}; - // if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); - // } - // if (arrResoDaughIndex.size() == NDaughtersResonant) { - // if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; - // } - // for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { - // auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // // if ( (std::abs(motherPdgCode) == Pdg::kDStar) || - // if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - // if (std::abs(motherPdgCode) == Pdg::kDStar) { - // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - // } - // arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); - // } - // flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); - // if (std::abs(motherPdgCode) == Pdg::kDStar) { - // // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - // // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); - // } - // } - // break; // Exit loop if a match is found - // } - // } - // } + std::vector arrResoDaughIndex = {}; + std::vector arrAllDaughtersIndex; // vector of indices of all daughters + for (const auto& [chn, finalState] : finalStates) { + if (finalState.size() == 5) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; + if (particle.pdgCode() < 0) { + for (auto& part : finalStateParts) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } + // finalStateParts[3] = -finalState[3]; + // finalStateParts[4] = -finalState[4]; + } + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); + }else if (finalState.size() == 4) { // Partly Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + if (particle.pdgCode() < 0) { + for (auto& part : finalStateParts) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } + } + // if (particle.pdgCode() < 0) { + // finalStateParts.back() = -finalState.back(); + // } + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); + } else { + LOG(info) << "Final state size not supported: " << finalState.size(); + continue; // Skip unsupported final states + } + if (matched) { + flag = sign * chn; + if (motherPdgCode == Pdg::kDStar) { + std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; + } + // Flag the resonant decay channel + int resoMaxDepth = 1; + int NDaughtersResonant = 2; + if (std::abs(motherPdgCode) == Pdg::kDStar) { + std::vector arrResoDaughIndexDStar = {}; + RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); + for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { + if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { + LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " recognized as D0."; + auto daughDstarD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + RecoDecay::getDaughters(daughDstarD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + break; + } else if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kDPlus) { + LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " is a D+."; + auto daughDstarDplus = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + RecoDecay::getDaughters(daughDstarDplus, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + break; + } else { + LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; + } + + std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; + } + } else { + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + } + std::vector arrPDGDaugh = {}; + if (std::abs(motherPdgCode) == Pdg::kDStar) { + LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); + } + if (arrResoDaughIndex.size() == NDaughtersResonant) { + if (std::abs(motherPdgCode) == Pdg::kDStar) { + LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; + } + for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); + // if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && + // (std::abs(daughI.pdgCode()) == kPiPlus) && + // (arrPDGDaugh.size() >= 2) ) { + // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi + // } + if (std::abs(motherPdgCode) == Pdg::kDStar) { + std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + } + arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + } + flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); + if (std::abs(motherPdgCode) == Pdg::kDStar) { + LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + } + } + break; // Exit loop if a match is found + } + } + } } else { // D± → π± K∓ π± From 7a470ef21470f37a05fd5debc8c0bc6181b25108 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 9 Jun 2025 13:56:06 +0200 Subject: [PATCH 15/47] Remove unused variables --- PWGHF/Core/DecayChannels.h | 111 ++++-------------- .../TableProducer/candidateCreator2Prong.cxx | 44 ++----- .../TableProducer/candidateCreator3Prong.cxx | 75 ++++++------ PWGHF/TableProducer/candidateSelectorD0.cxx | 6 - PWGHF/TableProducer/trackIndexSkimCreator.cxx | 6 +- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 4 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 21 ++-- PWGHF/Utils/utilsMcGen.h | 41 +++---- 8 files changed, 100 insertions(+), 208 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index f6b18a1fa64..4a361434d2d 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -24,7 +24,6 @@ #include #include #include -#include using namespace o2::constants::physics; @@ -64,9 +63,9 @@ std::unordered_map > finalStates2Prongs = { {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, - {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} }; std::unordered_map > resoStatesD0 = @@ -167,7 +166,7 @@ std::unordered_map > finalStatesDPlus = { {DecayChannelMain::DplusToPiKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, }; @@ -188,10 +187,10 @@ std::unordered_map > resoStatesDs = std::unordered_map > finalStatesDs = { {DecayChannelMain::DsToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, {DecayChannelMain::DsToPiPiK, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, {DecayChannelMain::DsToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± @@ -201,22 +200,22 @@ std::unordered_map > resoStatesDstar = {DecayChannelResonant::DstarToD0ToRhoplusK, std::array{213, +kKMinus}}, {DecayChannelResonant::DstarToD0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, {DecayChannelResonant::DstarToD0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, }; std::unordered_map > finalStatesDstar = { {DecayChannelMain::DstarToPiKPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, {DecayChannelMain::DstarToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, {DecayChannelMain::DstarToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± @@ -230,7 +229,7 @@ std::unordered_map > resoStatesLambdaC std::unordered_map > finalStatesLc = { {DecayChannelMain::LcToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, {DecayChannelMain::LcToPPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, {DecayChannelMain::LcToPKK, std::vector{+kProton, +kKMinus, +kKPlus}} }; @@ -244,8 +243,8 @@ std::unordered_map > resoStatesXiC = std::unordered_map > finalStatesXic = { - {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, {DecayChannelMain::XicToSPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; } // namespace hf_cand_3prong @@ -378,9 +377,7 @@ namespace o2::hf_corrbkg } template - bool checkResonantDecay(std::vector arrDaughIndex, std::array arrPDGResonant) { - // LOG(info) << "Entered checkResonantDecay with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " and resonant PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - // LOG(info) << "arrDaughIndex.size(): " << arrDaughIndex.size() << ", arrPDGResonant.size(): " << arrPDGResonant.size(); + bool checkResonantDecay(std::array arrDaughIndex, std::array arrPDGResonant) { LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; for (int i = 0; i < N; i++) { LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; @@ -407,13 +404,13 @@ namespace o2::hf_corrbkg /// \tparam arrDaughIndex index of the particle daughters at resonance level /// \tparam arrPDGResonant PDG code of the resonant decay /// \return true if the decay is resonant - template - void flagResonantDecay(int motherPdg, int8_t* channel, std::vector arrDaughIndex) { + template + void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughIndex) { if constexpr (is3Prong) { std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); for (const auto& [flag, pdgCodes] : resoStates) { if (abs(motherPdg) == Pdg::kDStar) { - std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; + std::cout << "Checking Dstar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; } if (checkResonantDecay(arrDaughIndex, pdgCodes)) { *channel = flag; @@ -441,72 +438,6 @@ namespace o2::hf_corrbkg } } } - - // switch (motherPdg) { - // case Pdg::kD0: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { - // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // break; - // case Pdg::kDPlus: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDPlus) { - // // std::cout << "Checking DPlus resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "D+ resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // break; - // case Pdg::kDS: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDs) { - // // std::cout << "Checking DS resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "Ds resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // break; - // case Pdg::kDStar: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesDstar) { - // std::cout << "Checking Dstar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // LOG(info) << "Dstar resonant decay not found, checking D0 resonances"; - // break; - // case Pdg::kLambdaCPlus: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesLambdaC) { - // // std::cout << "Checking LambdaC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "Lc resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // break; - // case Pdg::kXiCPlus: - // for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::resoStatesXiC) { - // // std::cout << "Checking XiC resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << std::endl; - // if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - // *channel = flag; - // LOG(info) << "Xic resonant decay found with channel: " << static_cast(*channel); - // break; - // } - // } - // break; - // } - // } - } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_DECAYCHANNELS_H_ diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index b61a8d35392..d266a2a03b3 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -746,6 +746,7 @@ struct HfCandidateCreator2ProngExpressions { int8_t origin = 0; int8_t nKinkedTracks = 0; int8_t nInteractionsWithMaterial = 0; + constexpr std::size_t NDaughtersResonant{2u}; // Match reconstructed candidates. // Spawned table can be used directly @@ -778,17 +779,6 @@ struct HfCandidateCreator2ProngExpressions { LOG(info) << "--------------------------------------------"; LOG(info) << "Matching correlated bkgs"; indexRec = -1; // Index of the matched reconstructed candidate - std::vector arrResoDaughIndex = {}; - // const std::unordered_map>* finalStates = nullptr; - // switch (pdgMother) { - // case Pdg::kD0: - // finalStates = reinterpret_cast>*>(&finalStates2Prongs); - // break; - // default: - // finalStates = reinterpret_cast>*>(&finalStates3Prongs); - // break; - // } - int depth = 2; for (const auto& [chn, finalState] : finalStates2Prongs) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; @@ -805,7 +795,14 @@ struct HfCandidateCreator2ProngExpressions { if (indexRec != -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); - std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], sign*finalState[2]}; + std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + if (sign < 0) { + for (auto& part : finalStateParts2ProngAll) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } + } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay } @@ -830,13 +827,13 @@ struct HfCandidateCreator2ProngExpressions { // Flag the resonant decay channel int resoMaxDepth = 1; - int NDaughtersResonant = 2; + std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; + std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); // LOG(info) << "[matchFinalStateCorrBkgs] Matched D0 final state: " << chn << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); @@ -845,22 +842,7 @@ struct HfCandidateCreator2ProngExpressions { break; // Exit loop if a match is found } } - LOG(info) << "D0 matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); - - // LOG(info) << "--------------------------------------------"; - // LOG(info) << "Matching correlated bkgs of " << Pdg::kD0; - // if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - // } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - // } else { - // indexRec = matchFinalStateCorrBkgs(Pdg::kD0, mcParticles, arrayDaughters, &flag, &sign, &channel, 1, &nKinkedTracks, &nInteractionsWithMaterial); - // } - // if (indexRec > -1) { - // LOG(info) << "Matched!"; - // } + // LOG(info) << "D0 matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D0(bar) → π± K∓ if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 6c2e380a6ec..f7817f40206 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -906,13 +906,14 @@ struct HfCandidateCreator3ProngExpressions { int8_t channel = 0; int8_t nKinkedTracks = 0; int8_t nInteractionsWithMaterial = 0; + constexpr std::size_t NDaughtersResonant{2u}; std::vector arrDaughIndex; - std::array arrPDGDaugh; - std::array arrPDGResonant1 = {kProton, 313}; // Λc± → p± K* - std::array arrPDGResonant2 = {2224, kKPlus}; // Λc± → Δ(1232)±± K∓ - std::array arrPDGResonant3 = {102134, kPiPlus}; // Λc± → Λ(1520) π± - std::array arrPDGResonantDPhiPi = {333, kPiPlus}; // Ds± → Phi π± and D± → Phi π± - std::array arrPDGResonantDKstarK = {313, kKPlus}; // Ds± → K*(892)0bar K± and D± → K*(892)0bar K± + std::array arrPDGDaugh; + std::array arrPDGResonant1 = {kProton, 313}; // Λc± → p± K* + std::array arrPDGResonant2 = {2224, kKPlus}; // Λc± → Δ(1232)±± K∓ + std::array arrPDGResonant3 = {102134, kPiPlus}; // Λc± → Λ(1520) π± + std::array arrPDGResonantDPhiPi = {333, kPiPlus}; // Ds± → Phi π± and D± → Phi π± + std::array arrPDGResonantDKstarK = {313, kKPlus}; // Ds± → K*(892)0bar K± and D± → K*(892)0bar K± // Match reconstructed candidates. // Spawned table can be used directly @@ -944,27 +945,25 @@ struct HfCandidateCreator3ProngExpressions { } } - LOG(info) << "CIAO REC MATCHING"; + // LOG(info) << "CIAO REC MATCHING"; if (matchCorrBkgs) { - LOG(info) << "CIAO 1"; + // LOG(info) << "CIAO 1"; // LOG(info) << "--------------------------------------------"; // LOG(info) << "Matching correlated bkgs"; - // std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; indexRec = -1; // Index of the matched reconstructed candidate - std::vector arrResoDaughIndex = {}; - LOG(info) << "CIAO 2"; + // LOG(info) << "CIAO 2"; for (const auto& pdg : mothersPdgCodes) { int depth = 2; if (pdg == Pdg::kDStar) { depth = 3; // D0 resonant decays are active } - LOG(info) << "CIAO 3"; + // LOG(info) << "CIAO 3"; auto finalStates = getDecayChannel3Prong(pdg); - LOG(info) << "CIAO 3.0"; + // LOG(info) << "CIAO 3.0"; for (const auto& [chn, finalState] : finalStates) { - LOG(info) << "CIAO 3.0.1"; + // LOG(info) << "CIAO 3.0.1"; std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() > 3) { // Partly Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -977,13 +976,13 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } - LOG(info) << "CIAO 3.0.2"; + // LOG(info) << "CIAO 3.0.2"; if (indexRec != -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); if (finalState.size() == 4) { // Check if the final state has 4 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3]}; - if (pdg < 0) { + if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // Ensure all parts are positive for matching @@ -993,30 +992,30 @@ struct HfCandidateCreator3ProngExpressions { if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay is not matched } - LOG(info) << "CIAO 3.0.3"; + // LOG(info) << "CIAO 3.0.3"; } else if (finalState.size() == 5) { // Check if the final state has 3 particles // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3], sign*finalState[4]}; - LOG(info) << "CIAO 3.0.4"; + // LOG(info) << "CIAO 3.0.4"; std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; - if (pdg < 0) { + if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // Ensure all parts are positive for matching } } - LOG(info) << "CIAO 3.0.5"; + // LOG(info) << "CIAO 3.0.5"; } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay is not matched - LOG(info) << "CIAO 3.0.6"; + // LOG(info) << "CIAO 3.0.6"; } - LOG(info) << "CIAO 3.0.7"; + // LOG(info) << "CIAO 3.0.7"; } - LOG(info) << "CIAO 3.0.8"; + // LOG(info) << "CIAO 3.0.8"; } - LOG(info) << "CIAO 3.0.9"; + // LOG(info) << "CIAO 3.0.9"; } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - LOG(info) << "CIAO 3.1"; + // LOG(info) << "CIAO 3.1"; if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -1026,50 +1025,43 @@ struct HfCandidateCreator3ProngExpressions { } else { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } - LOG(info) << "CIAO 3.2"; + // LOG(info) << "CIAO 3.2"; } else { LOG(info) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } - LOG(info) << "CIAO 4"; + // LOG(info) << "CIAO 4"; if (indexRec > -1) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; flag = sign * chn; // Flag the resonant decay channel int resoMaxDepth = 1; - int NDaughtersResonant = 2; if (std::abs(pdg) == Pdg::kDStar) { resoMaxDepth = 2; // Flag D0 resonances } + std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; + std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + for (auto iProng = 0u; iProng < NDaughtersResonant; ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ( (std::abs(pdg) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(pdg, &channel, arrPDGDaugh); - LOG(info) << "CIAO 5"; + // LOG(info) << "CIAO 5"; // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } - LOG(info) << "CIAO 6"; + // LOG(info) << "CIAO 6"; } } - LOG(info) << "CIAO 7"; + // LOG(info) << "CIAO 7"; LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± - LOG(info) << "--------------------------------------------"; - LOG(info) << "D+ -> Pi K Pi"; if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2, &nKinkedTracks, &nInteractionsWithMaterial); @@ -1084,7 +1076,6 @@ struct HfCandidateCreator3ProngExpressions { flag = sign * hf_cand_3prong::DecayChannelMain::DplusToPiKPi; } } - LOG(info) << "D+ matching ended"; // Ds± → K± K∓ π± and D± → K± K∓ π± if (flag == 0) { diff --git a/PWGHF/TableProducer/candidateSelectorD0.cxx b/PWGHF/TableProducer/candidateSelectorD0.cxx index 411adf3fe81..38d8cd8fcfd 100644 --- a/PWGHF/TableProducer/candidateSelectorD0.cxx +++ b/PWGHF/TableProducer/candidateSelectorD0.cxx @@ -211,7 +211,6 @@ struct HfCandidateSelectorD0 { if (candidate.decayLengthXY() > cuts->get(pTBin, "max decay length XY")) { return false; } - LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << hfHelper.invMassD0ToPiK(candidate) << " GeV/c^2"; return true; } @@ -289,7 +288,6 @@ struct HfCandidateSelectorD0 { } } } - LOG(info) << "D0 candidate selected with pT: " << candpT << " GeV/c, mass: " << (trackPion.sign() > 0 ? massD0 : massD0bar) << " GeV/c^2"; return true; } template @@ -484,16 +482,12 @@ struct HfCandidateSelectorD0 { void processWithDCAFitterN(aod::HfCand2ProngWPid const& candidates, TracksSel const& tracks) { - LOG(info) << "Processing candidates selection with DCAFitterN"; - LOG(info) << "Number of candidates: " << candidates.size(); processSel(candidates, tracks); } PROCESS_SWITCH(HfCandidateSelectorD0, processWithDCAFitterN, "process candidates selection with DCAFitterN", true); void processWithKFParticle(soa::Join const& candidates, TracksSel const& tracks) { - LOG(info) << "Processing candidates selection with KFParticle"; - LOG(info) << "Number of candidates: " << candidates.size(); processSel(candidates, tracks); } PROCESS_SWITCH(HfCandidateSelectorD0, processWithKFParticle, "process candidates selection with KFParticle", false); diff --git a/PWGHF/TableProducer/trackIndexSkimCreator.cxx b/PWGHF/TableProducer/trackIndexSkimCreator.cxx index 30039c6bc80..0f98525ceb1 100644 --- a/PWGHF/TableProducer/trackIndexSkimCreator.cxx +++ b/PWGHF/TableProducer/trackIndexSkimCreator.cxx @@ -63,8 +63,6 @@ using namespace o2::aod; using namespace o2::hf_centrality; using namespace o2::framework; using namespace o2::framework::expressions; -using namespace o2::aod::hf_cand_2prong; -using namespace o2::aod::hf_cand_3prong; // enum for candidate type enum CandidateType { @@ -1224,8 +1222,8 @@ struct HfTrackIndexSkimCreator { // int nColls{0}; //can be added to run over limited collisions per file - for tesing purposes - static constexpr int kN2ProngDecays = o2::aod::hf_cand_2prong::DecayType::N2ProngDecays; // number of 2-prong hadron types - static constexpr int kN3ProngDecays = o2::aod::hf_cand_3prong::DecayType::N3ProngDecays; // number of 3-prong hadron types + static constexpr int kN2ProngDecays = hf_cand_2prong::DecayType::N2ProngDecays; // number of 2-prong hadron types + static constexpr int kN3ProngDecays = hf_cand_3prong::DecayType::N3ProngDecays; // number of 3-prong hadron types static constexpr int kNCuts2Prong[kN2ProngDecays] = {hf_cuts_presel_2prong::NCutVars, hf_cuts_presel_2prong::NCutVars, hf_cuts_presel_2prong::NCutVars}; // how many different selections are made on 2-prongs static constexpr int kNCuts3Prong[kN3ProngDecays] = {hf_cuts_presel_3prong::NCutVars, hf_cuts_presel_3prong::NCutVars + 1, hf_cuts_presel_ds::NCutVars, hf_cuts_presel_3prong::NCutVars + 1}; // how many different selections are made on 3-prongs (Lc and Xic have also PID potentially) static constexpr int kNCutsDstar = 3; // how many different selections are made on Dstars diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 382baf08989..22eefcbe340 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -231,6 +231,7 @@ struct HfTreeCreatorD0ToKPi { // parameters for production of training samples Configurable downSampleBkgFactor{"downSampleBkgFactor", 1., "Fraction of background candidates to keep for ML trainings"}; Configurable ptMaxForDownSample{"ptMaxForDownSample", 10., "Maximum pt for the application of the downsampling factor"}; + Configurable fillCorrBkgs{"fillCorrBkgs", false, "Flag to fill derived tables with correlated background candidates"}; HfHelper hfHelper; @@ -242,8 +243,7 @@ struct HfTreeCreatorD0ToKPi { using MatchedGenCandidatesMc = soa::Filtered>; Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= -1 || aod::hf_sel_candidate_d0::isSelD0bar >= -1; - // Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0; + Filter filterMcGenMatching = (nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK))) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); // Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0; diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 3f6480b25ba..945b21b71b2 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -254,6 +254,7 @@ struct HfTreeCreatorDplusToPiKPi { Configurable fillCandidateLiteTable{"fillCandidateLiteTable", false, "Switch to fill lite table with candidate properties"}; // parameters for production of training samples Configurable fillOnlySignal{"fillOnlySignal", false, "Flag to fill derived tables with signal for ML trainings"}; + Configurable fillCorrBkgs{"fillCorrBkgs", false, "Flag to fill derived tables with correlated background candidates"}; Configurable fillOnlyBackground{"fillOnlyBackground", false, "Flag to fill derived tables with background for ML trainings"}; Configurable downSampleBkgFactor{"downSampleBkgFactor", 1., "Fraction of background candidates to keep for ML trainings"}; Configurable ptMaxForDownSample{"ptMaxForDownSample", 10., "Maximum pt for the application of the downsampling factor"}; @@ -265,19 +266,19 @@ struct HfTreeCreatorDplusToPiKPi { using SelectedCandidatesMc = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; using SelectedCandidatesMcWithMl = soa::Filtered>; - using MatchedGenCandidatesMcCorrBkgs = soa::Join; - using SelectedCandidatesMcCorrBkgsWithMl = soa::Join; + // using MatchedGenCandidatesMcCorrBkgs = soa::Join; + // using SelectedCandidatesMcCorrBkgsWithMl = soa::Join; using TracksWPid = soa::Join; using CollisionsCent = soa::Join; Filter filterSelectCandidates = aod::hf_sel_candidate_dplus::isSelDplusToPiKPi >= selectionFlagDplus; - Filter filterMcGenMatching = nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); + Filter filterMcGenMatching = (nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) || (fillCorrBkgs && (nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) != 0)); - Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK); + Partition reconstructedCandSig = (nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) || (fillCorrBkgs && (nabs(o2::aod::hf_cand_3prong::flagMcMatchRec) != 0)); Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); - Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi); - Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); + Partition reconstructedCandSigMl = (nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) || (fillCorrBkgs && (nabs(o2::aod::hf_cand_3prong::flagMcMatchRec) != 0)); + // Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); void init(InitContext const&) { @@ -621,13 +622,13 @@ struct HfTreeCreatorDplusToPiKPi { void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, aod::McCollisions const& mccollisions, - SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, - MatchedGenCandidatesMcCorrBkgs const& particles, // MatchedGenCandidatesMcCorrBkgs const& particles, + SelectedCandidatesMcWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, + MatchedGenCandidatesMc const& particles, // MatchedGenCandidatesMcCorrBkgs const& particles, TracksWPid const& tracks) { - LOG(info) << "processMcCorrBkgsSgnWCentMl with " << reconstructedCandCorrBkgsMl.size() << " reco particles"; + LOG(info) << "processMcCorrBkgsSgnWCentMl with " << reconstructedCandSigMl.size() << " reco particles"; LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " generated particles"; - // fillMcTables(collisions, mccollisions, reconstructedCandCorrBkgsMl, particles, tracks); + fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); } PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcCorrBkgsSgnWCentMl, "Process MC correlated bkgs with cent and ML info", false); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 9bb83d68fcc..662284f3414 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -42,15 +42,15 @@ template void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { using namespace o2::constants::physics; + constexpr std::size_t NDaughtersResonant{2u}; // Match generated particles. + int maxDepth = 2; // Default depth for matching for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; int8_t channel = 0; // Not used in 2-prong decays int8_t sign = 0; - bool matched = false; - int maxDepth = 2; // Default depth for matching std::vector idxBhadMothers{}; // Reject particles from background events if (particle.fromBackgroundEvent() && rejectBackground) { @@ -58,15 +58,17 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matchCorrBkgs) { - int maxDepth = 2; bool matched = false; - std::vector arrResoDaughIndex = {}; for (const auto& [chn, finalState] : finalStates2Prongs) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { - finalStateParts.back() = -finalState.back(); + for (auto& part : finalStateParts) { + if (part == kPi0) { + part = -part; // Ensure all parts are positive for matching + } + } } matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); } else if (finalState.size() == 2) { // Fully Reco 3-prong decays @@ -82,20 +84,19 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V // Flag the resonant decay channel int resoMaxDepth = 1; - int NDaughtersResonant = 2; - + std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - std::vector arrPDGDaugh = {}; + std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - LOG(info) << "[matchFinalStateCorrBkgsGen] Adding daughter PDG: " << daughI.pdgCode(); - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Adding daughter PDG: " << daughI.pdgCode(); + arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } @@ -179,7 +180,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V maxDepth = 3; // to catch the D0 resonances } - std::vector arrResoDaughIndex = {}; std::vector arrAllDaughtersIndex; // vector of indices of all daughters for (const auto& [chn, finalState] : finalStates) { if (finalState.size() == 5) { // Partly Reco 3-prong decays @@ -195,7 +195,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - }else if (finalState.size() == 4) { // Partly Reco 3-prong decays + } else if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (particle.pdgCode() < 0) { for (auto& part : finalStateParts) { @@ -224,7 +224,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // Flag the resonant decay channel int resoMaxDepth = 1; - int NDaughtersResonant = 2; + std::vector arrResoDaughIndex = {}; if (std::abs(motherPdgCode) == Pdg::kDStar) { std::vector arrResoDaughIndexDStar = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); @@ -248,7 +248,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } else { RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); } - std::vector arrPDGDaugh = {}; + std::array arrPDGDaugh = {}; if (std::abs(motherPdgCode) == Pdg::kDStar) { LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); } @@ -256,17 +256,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (std::abs(motherPdgCode) == Pdg::kDStar) { LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; } - for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { + for (auto iProng = 0u; iProng < NDaughtersResonant; ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // if ((std::abs(motherPdgCode) == Pdg::kXiCPlus) && - // (std::abs(daughI.pdgCode()) == kPiPlus) && - // (arrPDGDaugh.size() >= 2) ) { - // continue; // Skip the pion from D* decay and the second pion from XiC --> Sigma Pi Pi - // } if (std::abs(motherPdgCode) == Pdg::kDStar) { std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; } - arrPDGDaugh.push_back(std::abs(daughI.pdgCode())); + arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); if (std::abs(motherPdgCode) == Pdg::kDStar) { From b30536c28cb60dbd3e97451581283d56b1f401e9 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 9 Jun 2025 16:10:55 +0200 Subject: [PATCH 16/47] Delete debug prints for 2prong code --- Common/Core/RecoDecay.h | 38 ----- PWGHF/Core/DecayChannels.h | 161 ++++++++++-------- .../TableProducer/candidateCreator2Prong.cxx | 20 +-- .../TableProducer/candidateCreator3Prong.cxx | 52 ++++-- PWGHF/TableProducer/candidateSelectorD0.cxx | 4 +- PWGHF/Utils/utilsMcGen.h | 35 +--- 6 files changed, 153 insertions(+), 157 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index d1118f6be10..7716a8d64a0 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -25,7 +25,6 @@ #include // std::apply #include // std::move #include // std::vector -#include // ROOT includes #include // for VMC Particle Production Process @@ -919,20 +918,12 @@ struct RecoDecay { } // Check the PDG code of the particle. auto pdgCandidate = candidate.pdgCode(); - bool debugPrint = false; // Set to true to enable debug printing. - if (std::abs(pdgCandidate) == 413) { - // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); - debugPrint = true; // Enable debug printing for D*. - } // Printf("MC Gen: Candidate PDG: %d", pdgCandidate); if (pdgCandidate == pdgParticle) { // exact PDG match sgn = 1; } else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match sgn = -1; } else { - if (debugPrint) { - std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl; - } // Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle)); return false; } @@ -942,32 +933,18 @@ struct RecoDecay { std::vector arrAllDaughtersIndex; // vector of indices of all daughters // Check the daughter indices. if (!candidate.has_daughters()) { - if (debugPrint) { - std::cout << "MC Gen: Rejected: bad daughter index range: " << candidate.daughtersIds().front() << "-" << candidate.daughtersIds().back() << std::endl; - } // Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back()); return false; } // Check that the number of direct daughters is not larger than the number of expected final daughters. if constexpr (!checkProcess) { if (candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 > static_cast(N)) { - if (debugPrint) { - std::cout << "MC Gen: Rejected: too many direct daughters: " << candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 - << " (expected " << N << " final)" << std::endl; - } // Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N); return false; } } // Get the list of actual final daughters. getDaughters(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax); - if (debugPrint) { - std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final daughters:"; - for (auto i : arrAllDaughtersIndex) { - std::cout << " " << i; - } - std::cout << std::endl; - } // printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size()); // for (auto i : arrAllDaughtersIndex) { // printf(" %d", i); @@ -975,9 +952,6 @@ struct RecoDecay { // printf("\n"); // Check whether the number of final daughters is equal to the required number. if (arrAllDaughtersIndex.size() != N) { - if (debugPrint) { - std::cout << "MC Gen: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl; - } // Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N); return false; } @@ -995,15 +969,9 @@ struct RecoDecay { for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements) auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter - if (debugPrint) { - std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl; - } // Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI); bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes? for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) { - if (debugPrint) { - std::cout << "MC Gen: Checking against expected PDG: " << coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp] << std::endl; - } if (pdgCandidateDaughterI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) { arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones. isPdgFound = true; @@ -1011,9 +979,6 @@ struct RecoDecay { } } if (!isPdgFound) { - if (debugPrint) { - std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl; - } // Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI); return false; } @@ -1022,9 +987,6 @@ struct RecoDecay { *listIndexDaughters = arrAllDaughtersIndex; } } - if (debugPrint) { - std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl; - } // Printf("MC Gen: Accepted: m: %d", candidate.globalIndex()); if (sign) { *sign = sgn; diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 4a361434d2d..afb0498fe89 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -152,7 +152,6 @@ enum DecayChannelResonant : int8_t { LastChannelResonant }; - std::unordered_map > resoStatesDPlus = { {DecayChannelResonant::DplusToPhiPi, std::array{+kPhi, +kPiPlus}}, @@ -336,108 +335,134 @@ enum DecayChannelToJpsiResonant : int8_t { } // namespace hf_cand_beauty } // namespace o2::hf_decay -// using namespace o2::hf_decay; - namespace o2::hf_corrbkg { - std::unordered_map > getDecayChannel3Prong(int pdgMother) { + using namespace o2::hf_decay; + + /// Returns a map of the possible final states for a specific 3-prong particle specie + /// \param pdgMother PDG code of the mother particle + /// \return a map of final states with their corresponding PDG codes + std::unordered_map > getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { case Pdg::kDPlus: - return o2::hf_decay::hf_cand_3prong::finalStatesDPlus; + return hf_cand_3prong::finalStatesDPlus; case Pdg::kDS: - return o2::hf_decay::hf_cand_3prong::finalStatesDs; + return hf_cand_3prong::finalStatesDs; case Pdg::kDStar: - return o2::hf_decay::hf_cand_3prong::finalStatesDstar; + return hf_cand_3prong::finalStatesDstar; case Pdg::kLambdaCPlus: - return o2::hf_decay::hf_cand_3prong::finalStatesLc; + return hf_cand_3prong::finalStatesLc; case Pdg::kXiCPlus: - return o2::hf_decay::hf_cand_3prong::finalStatesXic; + return hf_cand_3prong::finalStatesXic; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; } } - std::unordered_map > getResoChannels3Prong(int pdgMother) { + /// Returns a map of the resonant decay channels for a specific 3-prong particle specie + /// \param pdgMother PDG code of the mother particle + /// \return a map of resonant decay channels with their corresponding PDG codes + std::unordered_map > getResoChannels3Prong(int pdgMother) { switch (pdgMother) { case Pdg::kDPlus: - return o2::hf_decay::hf_cand_3prong::resoStatesDPlus; + return hf_cand_3prong::resoStatesDPlus; case Pdg::kDS: - return o2::hf_decay::hf_cand_3prong::resoStatesDs; + return hf_cand_3prong::resoStatesDs; case Pdg::kDStar: - return o2::hf_decay::hf_cand_3prong::resoStatesDstar; + return hf_cand_3prong::resoStatesDstar; case Pdg::kLambdaCPlus: - return o2::hf_decay::hf_cand_3prong::resoStatesLambdaC; + return hf_cand_3prong::resoStatesLambdaC; case Pdg::kXiCPlus: - return o2::hf_decay::hf_cand_3prong::resoStatesXiC; + return hf_cand_3prong::resoStatesXiC; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; } } + /// Perform the matching for a single resonant channel + /// \tparam N size of the array of daughter PDG codes + /// \param arrPdgResoChn array of daughter indices + /// \param arrPdgDaugs array of PDG codes for the resonant decay + /// \return true if the resonant channel is matched, false otherwise template - bool checkResonantDecay(std::array arrDaughIndex, std::array arrPDGResonant) { - LOG(info) << "Testing: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - for (int i = 0; i < N; i++) { - LOG(info) << "Checking daughter index: " << arrDaughIndex[i]; - bool findDaug = false; - for (int j = 0; j < N; j++) { - LOG(info) << "Checking daughter PDG: " << arrDaughIndex[i] << " against resonant PDG: " << arrPDGResonant[j]; - if (std::abs(arrDaughIndex[i]) == std::abs(arrPDGResonant[j])) { - arrPDGResonant[j] = -1; // Mark as found - LOG(info) << "Matched!"; - findDaug = true; - break; - } - } - if (!findDaug) { - LOG(info) << "Returning false"; - return false; + bool checkResonantDecay(std::array arrPdgResoChn, std::array arrPdgDaugs) { + // LOG(info) << "Testing: " << arrPdgResoChn[0] << ", " << arrPdgResoChn[1] << " matching PDG codes: " << arrPdgDaugs[0] << ", " << arrPdgDaugs[1]; + for (size_t i = 0; i < N; i++) { + // LOG(info) << "Checking daughter index: " << arrPdgResoChn[i]; + bool findDaug = false; + for (size_t j = 0; j < N; j++) { + // LOG(info) << "Checking daughter PDG: " << arrPdgResoChn[i] << " against resonant PDG: " << arrPdgDaugs[j]; + if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { + arrPdgDaugs[j] = -1; // Mark as found + // LOG(info) << "Matched!"; + findDaug = true; + break; } } - LOG(info) << "Resonant decay found with daughters: " << arrDaughIndex[0] << ", " << arrDaughIndex[1] << " matching PDG codes: " << arrPDGResonant[0] << ", " << arrPDGResonant[1]; - return true; + if (!findDaug) { + // LOG(info) << "Returning false"; + return false; + } } + // LOG(info) << "Resonant decay found with daughters: " << arrPdgResoChn[0] << ", " << arrPdgResoChn[1] << " matching PDG codes: " << arrPdgDaugs[0] << ", " << arrPdgDaugs[1]; + return true; + } - /// Check if the decay is resonant - /// \tparam arrDaughIndex index of the particle daughters at resonance level - /// \tparam arrPDGResonant PDG code of the resonant decay - /// \return true if the decay is resonant - template - void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughIndex) { - if constexpr (is3Prong) { - std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); - for (const auto& [flag, pdgCodes] : resoStates) { - if (abs(motherPdg) == Pdg::kDStar) { - std::cout << "Checking Dstar resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; - } - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - if (abs(motherPdg) == Pdg::kDStar) { - LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); - } - break; - } - } - if (abs(motherPdg) == Pdg::kDStar) { - LOG(info) << "Leaving function with channel: " << static_cast(*channel); - } - } else { - if (motherPdg != Pdg::kD0) { - LOG(error) << "Resonant decay flagging is only implemented for D0 resonances in 2-prong decays."; - return; + /// Flag the resonant decays + /// Function documentation: + /// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay + /// \tparam N size of the array of daughter PDG codes + /// \param motherPdg PDG code of the mother particle + /// \param channel decay channel flag to be set + /// \param arrDaughPdgs array of daughter PDG codes + template + void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) { + if constexpr (is3Prong) { + std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); + if (abs(motherPdg) == Pdg::kDPlus) { + std::cout << "Flagging resonant channel for D+ with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + } + if (abs(motherPdg) == Pdg::kDS) { + std::cout << "Flagging resonant channel for Ds with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + } + if (abs(motherPdg) == Pdg::kDStar) { + std::cout << "Flagging resonant channel for Dstar with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + } + if (abs(motherPdg) == Pdg::kLambdaCPlus) { + std::cout << "Flagging resonant channel for LambdaC with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + } + if (abs(motherPdg) == Pdg::kXiCPlus) { + std::cout << "Flagging resonant channel for XiC with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + } + for (const auto& [flag, pdgCodes] : resoStates) { + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + // if (abs(motherPdg) == Pdg::kDStar) { + // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); + // } + break; } - for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::resoStatesD0) { - std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughIndex[0] << " " << arrDaughIndex[1] << std::endl; - if (checkResonantDecay(arrDaughIndex, pdgCodes)) { - *channel = flag; - LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); - break; - } + } + // if (abs(motherPdg) == Pdg::kDStar) { + // LOG(info) << "Leaving function with channel: " << static_cast(*channel); + // } + } else { + if (motherPdg != Pdg::kD0) { + // LOG(error) << "Resonant decay flagging is only implemented for D0 resonances in 2-prong decays."; + return; + } + for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { + // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + // LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); + break; } } } + } } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_DECAYCHANNELS_H_ diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index d266a2a03b3..daa36fbc5a5 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -776,8 +776,6 @@ struct HfCandidateCreator2ProngExpressions { std::vector idxBhadMothers{}; if (matchCorrBkgs) { - LOG(info) << "--------------------------------------------"; - LOG(info) << "Matching correlated bkgs"; indexRec = -1; // Index of the matched reconstructed candidate int depth = 2; for (const auto& [chn, finalState] : finalStates2Prongs) { @@ -799,12 +797,12 @@ struct HfCandidateCreator2ProngExpressions { if (sign < 0) { for (auto& part : finalStateParts2ProngAll) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay + indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } } else if (finalState.size() == 2) { // Fully Reco 2-prong decays @@ -819,12 +817,11 @@ struct HfCandidateCreator2ProngExpressions { } } else { LOG(info) << "Final state size not supported: " << finalStateParts2Prong.size(); - continue; // Skip unsupported final states + continue; } if (indexRec > -1) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; - flag = sign * chn; // Only D0 decay channels are considered here - + flag = sign * chn; + // Flag the resonant decay channel int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; @@ -836,13 +833,10 @@ struct HfCandidateCreator2ProngExpressions { arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgs] Matched D0 final state: " << chn << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } - break; // Exit loop if a match is found + break; } } - // LOG(info) << "D0 matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D0(bar) → π± K∓ if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -890,10 +884,8 @@ struct HfCandidateCreator2ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); - LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { - LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index f7817f40206..591f6027d90 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -59,13 +59,13 @@ using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_3prong; using namespace o2::hf_decay; -using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::aod::pid_tpc_tof_utils; +using namespace o2::hf_corrbkg; /// Reconstruction of heavy-flavour 3-prong decay candidates struct HfCandidateCreator3Prong { @@ -985,12 +985,12 @@ struct HfCandidateCreator3ProngExpressions { if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay is not matched + indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } // LOG(info) << "CIAO 3.0.3"; } else if (finalState.size() == 5) { // Check if the final state has 3 particles @@ -1000,13 +1000,13 @@ struct HfCandidateCreator3ProngExpressions { if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } // LOG(info) << "CIAO 3.0.5"; } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { - indexRec = -1; // Reset indexRec if the generated decay is not matched + indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched // LOG(info) << "CIAO 3.0.6"; } // LOG(info) << "CIAO 3.0.7"; @@ -1059,7 +1059,7 @@ struct HfCandidateCreator3ProngExpressions { } } // LOG(info) << "CIAO 7"; - LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); + // LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± if (flag == 0) { @@ -1121,6 +1121,19 @@ struct HfCandidateCreator3ProngExpressions { } } + // D* → D0π → Kππ + if (flag == 0) { + if (matchKinkedDecayTopology) { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); + } else { + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); + } + if (indexRec > -1) { + flag = sign * hf_cand_3prong::DecayChannelMain::DstarToPiKPi; + channel = 1; + } + } + // Λc± → p± K∓ π± if (flag == 0) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -1134,6 +1147,25 @@ struct HfCandidateCreator3ProngExpressions { } if (indexRec > -1) { flag = sign * hf_cand_3prong::DecayChannelMain::LcToPKPi; + + // Flagging the different Λc± → p± K∓ π± decay channels + if (arrayDaughters[0].has_mcParticle()) { + swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + } + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrDaughIndex, std::array{0}, 1); + if (arrDaughIndex.size() == NDaughtersResonant) { + for (auto iProng = 0u; iProng < arrDaughIndex.size(); ++iProng) { + auto daughI = mcParticles.rawIteratorAt(arrDaughIndex[iProng]); + arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); + } + if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) { + channel = 1; + } else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) { + channel = 2; + } else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) { + channel = 3; + } + } } } @@ -1165,15 +1197,15 @@ struct HfCandidateCreator3ProngExpressions { } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); - LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); + // LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { - LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); + // LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } - LOG(info) << "BYE REC MATCHING, HELLO GEN MATCHING"; + // LOG(info) << "BYE REC MATCHING, HELLO GEN MATCHING"; // LOG(info) << "Filling MC match gen for 3 prong candidates"; // LOG(info) << "Number of MC collisions: " << mcCollisions.size(); for (const auto& mcCollision : mcCollisions) { @@ -1216,7 +1248,7 @@ struct HfCandidateCreator3ProngExpressions { hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } - LOG(info) << "BYE GEN MATCHING"; + // LOG(info) << "BYE GEN MATCHING"; } diff --git a/PWGHF/TableProducer/candidateSelectorD0.cxx b/PWGHF/TableProducer/candidateSelectorD0.cxx index 38d8cd8fcfd..ae0102b33fe 100644 --- a/PWGHF/TableProducer/candidateSelectorD0.cxx +++ b/PWGHF/TableProducer/candidateSelectorD0.cxx @@ -211,6 +211,7 @@ struct HfCandidateSelectorD0 { if (candidate.decayLengthXY() > cuts->get(pTBin, "max decay length XY")) { return false; } + return true; } @@ -288,6 +289,7 @@ struct HfCandidateSelectorD0 { } } } + return true; } template @@ -485,7 +487,7 @@ struct HfCandidateSelectorD0 { processSel(candidates, tracks); } PROCESS_SWITCH(HfCandidateSelectorD0, processWithDCAFitterN, "process candidates selection with DCAFitterN", true); - + void processWithKFParticle(soa::Join const& candidates, TracksSel const& tracks) { processSel(candidates, tracks); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 662284f3414..1fedabeffea 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -66,7 +66,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (particle.pdgCode() < 0) { for (auto& part : finalStateParts) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } @@ -76,10 +76,9 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); } else { LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states + continue; } if (matched) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << std::endl; flag = sign * chn; // Flag the resonant decay channel @@ -90,18 +89,13 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - // LOG(info) << "[matchFinalStateCorrBkgsGen] Adding daughter PDG: " << daughI.pdgCode(); arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << Pdg::kD0 << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } - break; // Exit loop if a match is found + break; } } - // matched = matchFinalStateCorrBkgsGen(Pdg::kD0, mcParticles, particle, &sign, maxDepth, &flag, &channel); } else { // D0(bar) → π± K∓ if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) { @@ -128,10 +122,8 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { - // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { - // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } @@ -144,8 +136,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V constexpr std::size_t NDaughtersResonant{2u}; // Match generated particles. - // LOG(info) << "Matching generated particles for 3-prong decays"; - // LOG(info) << "Number of particles in mcParticlesPerMcColl: " << mcParticlesPerMcColl.size(); for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; @@ -166,8 +156,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matchCorrBkgs) { - // LOG(info) << "--------------------------------------------"; - // LOG(info) << "Matching gen correlated bkgs of 3prongs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; for (const auto& motherPdgCode : mothersPdgCodes) { if (std::abs(particle.pdgCode()) != motherPdgCode) { @@ -177,21 +165,19 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V int maxDepth = 2; bool matched = false; if (motherPdgCode == Pdg::kDStar) { - maxDepth = 3; // to catch the D0 resonances + maxDepth = 3; // D0 resonant decays are switched on } - std::vector arrAllDaughtersIndex; // vector of indices of all daughters + std::vector arrAllDaughtersIndex; for (const auto& [chn, finalState] : finalStates) { if (finalState.size() == 5) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (particle.pdgCode() < 0) { for (auto& part : finalStateParts) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } - // finalStateParts[3] = -finalState[3]; - // finalStateParts[4] = -finalState[4]; } RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); @@ -200,13 +186,10 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (particle.pdgCode() < 0) { for (auto& part : finalStateParts) { if (part == kPi0) { - part = -part; // Ensure all parts are positive for matching + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } - // if (particle.pdgCode() < 0) { - // finalStateParts.back() = -finalState.back(); - // } RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 3) { // Fully Reco 3-prong decays @@ -215,7 +198,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); } else { LOG(info) << "Final state size not supported: " << finalState.size(); - continue; // Skip unsupported final states + continue; } if (matched) { flag = sign * chn; @@ -228,7 +211,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (std::abs(motherPdgCode) == Pdg::kDStar) { std::vector arrResoDaughIndexDStar = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); - for (int iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { + for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " recognized as D0."; auto daughDstarD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); From 407af312bac0f3e7fa526989e938f370f0b76aa7 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 9 Jun 2025 17:03:38 +0200 Subject: [PATCH 17/47] Correct bitmap matching in D0 tree creator --- .../TableProducer/candidateCreator3Prong.cxx | 9 ---- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 43 +++++++-------- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 52 ++++++------------- 3 files changed, 34 insertions(+), 70 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 591f6027d90..bd223af0c53 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1217,20 +1217,16 @@ struct HfCandidateCreator3ProngExpressions { uint16_t rejectionMask{0}; int nSplitColl = 0; if constexpr (centEstimator == CentralityEstimator::FT0C) { - // LOG(info) << "FT0C centrality estimator"; const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex()); rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); } else if constexpr (centEstimator == CentralityEstimator::FT0M) { - // LOG(info) << "FT0M centrality estimator"; const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0M, mcCollision.globalIndex()); nSplitColl = collSlice.size(); rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); } else if constexpr (centEstimator == CentralityEstimator::None) { - // LOG(info) << "No centrality estimator"; const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex()); rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask(mcCollision, collSlice, centrality); } - // LOG(info) << "CIAO3"; hfEvSelMc.fillHistograms(mcCollision, rejectionMask, nSplitColl); if (rejectionMask != 0) { // at least one event selection not satisfied --> reject all gen particles from this collision @@ -1239,17 +1235,12 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - // LOG(info) << "CIAO4"; if (matchCorrBkgs) { - // LOG(info) << "Filling MC match gen for correlated bkgs"; hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } else { - // LOG(info) << "Filling MC match gen"; hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } - // LOG(info) << "BYE GEN MATCHING"; - } void processMc(aod::TracksWMc const& tracks, diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 22eefcbe340..e278c1a4011 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -242,19 +242,18 @@ struct HfTreeCreatorD0ToKPi { using SelectedCandidatesMcKfMl = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; - Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= -1 || aod::hf_sel_candidate_d0::isSelD0bar >= -1; - Filter filterMcGenMatching = (nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK))) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); + Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= 1 || aod::hf_sel_candidate_d0::isSelD0bar >= 1; + Filter filterMcGenMatching = (nabs(aod::hf_cand_2prong::flagMcMatchGen) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); - // Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0; - Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; + Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; - Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandBkgMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandSigKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandBkgKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; + Partition reconstructedCandSigKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; void init(InitContext const&) { @@ -514,9 +513,9 @@ struct HfTreeCreatorD0ToKPi { LOG(info) << "Processing " << candidates.size() << " candidates"; for (const auto& candidate : candidates) { if constexpr (onlyBkg) { - // if (TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { - // continue; - // } + if ( (std::abs(candidate.flagMcMatchRec() == aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + continue; + } if (downSampleBkgFactor < 1.) { float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { @@ -525,9 +524,9 @@ struct HfTreeCreatorD0ToKPi { } } if constexpr (onlySig) { - // if (!TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { - // continue; - // } + if ( !(std::abs(candidate.flagMcMatchRec()) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + continue; + } } double yD = hfHelper.yD0(candidate); double eD = hfHelper.eD0(candidate); @@ -543,11 +542,9 @@ struct HfTreeCreatorD0ToKPi { massD0bar = hfHelper.invMassD0barToKPi(candidate); } if (candidate.isSelD0()) { - LOG(info) << "Filling D0 candidate with mass: " << massD0 << ", pt: " << candidate.pt() << ", y: " << yD; fillTable(candidate, 0, massD0, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.flagMcDecayChanRec(), candidate.originMcRec()); } if (candidate.isSelD0bar()) { - LOG(info) << "Filling D0 candidate with mass: " << massD0 << ", pt: " << candidate.pt() << ", y: " << yD; fillTable(candidate, 1, massD0bar, topolChi2PerNdf, ctD, yD, eD, candidate.flagMcMatchRec(), candidate.flagMcDecayChanRec(), candidate.originMcRec()); } } @@ -555,7 +552,7 @@ struct HfTreeCreatorD0ToKPi { // Filling particle properties rowCandidateFullParticles.reserve(mcParticles.size()); for (const auto& particle : mcParticles) { - // if (TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK)) { + if ((nabs(aod::hf_cand_2prong::flagMcMatchGen) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0))) { rowCandidateFullParticles( particle.mcCollisionId(), particle.pt(), @@ -566,7 +563,7 @@ struct HfTreeCreatorD0ToKPi { particle.flagMcDecayChanGen(), particle.originMcGen(), particle.globalIndex()); - // } + } } } @@ -621,10 +618,6 @@ struct HfTreeCreatorD0ToKPi { aod::Tracks const& tracks, aod::BCs const& bcs) { - LOG(info) << "Processing MC with DCAFitterN for all candidates"; - LOG(info) << "Number of candidates: " << candidates.size(); - LOG(info) << "Number of MC particles: " << mcParticles.size(); - LOG(info) << "Number of collisions: " << collisions.size(); processMc(collisions, mcCollisions, candidates, mcParticles, tracks, bcs); } PROCESS_SWITCH(HfTreeCreatorD0ToKPi, processMcWithDCAFitterAll, "Process MC with DCAFitterN", false); diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 945b21b71b2..2b7b429d7f3 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -266,8 +266,6 @@ struct HfTreeCreatorDplusToPiKPi { using SelectedCandidatesMc = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; using SelectedCandidatesMcWithMl = soa::Filtered>; - // using MatchedGenCandidatesMcCorrBkgs = soa::Join; - // using SelectedCandidatesMcCorrBkgsWithMl = soa::Join; using TracksWPid = soa::Join; using CollisionsCent = soa::Join; @@ -278,7 +276,6 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = (nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) || (fillCorrBkgs && (nabs(o2::aod::hf_cand_3prong::flagMcMatchRec) != 0)); Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); Partition reconstructedCandSigMl = (nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) || (fillCorrBkgs && (nabs(o2::aod::hf_cand_3prong::flagMcMatchRec) != 0)); - // Partition reconstructedCandCorrBkgsMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) != 0; // static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi); void init(InitContext const&) { @@ -528,7 +525,6 @@ struct HfTreeCreatorDplusToPiKPi { fillEvent(collision, 0, 1); } - LOG(info) << "Filling reconstructed " << candidates.size() << " candidates"; // Filling candidate properties if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); @@ -548,10 +544,6 @@ struct HfTreeCreatorDplusToPiKPi { // Filling particle properties rowCandidateFullParticles.reserve(particles.size()); for (const auto& particle : particles) { - // LOG(info) << "Filling particle with pt: " << particle.pt() << ", eta: " << particle.eta() << ", phi: " << particle.phi(); - // LOG(info) << "Flag MC match gen: " << static_cast(particle.flagMcMatchGen()); - // LOG(info) << "Flag MC decay chan gen: " << static_cast(particle.flagMcDecayChanGen()); - // LOG(info) << "Origin MC gen: " << static_cast(particle.originMcGen()); rowCandidateFullParticles( particle.mcCollision().bcId(), particle.pt(), @@ -599,39 +591,27 @@ struct HfTreeCreatorDplusToPiKPi { PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcWCent, "Process MC with cent", false); void processMcSgnWMl(aod::Collisions const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, - MatchedGenCandidatesMc const& particles, - TracksWPid const& tracks) - { - fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); - } + aod::McCollisions const& mccollisions, + SelectedCandidatesMcWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); + } - PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWMl, "Process MC signal with ML info", false); + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWMl, "Process MC signal with ML info", false); void processMcSgnWCentMl(CollisionsCent const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, - MatchedGenCandidatesMc const& particles, - TracksWPid const& tracks) - { - fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); - } - - PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); - - void processMcCorrBkgsSgnWCentMl(aod::Collisions const& collisions, - aod::McCollisions const& mccollisions, - SelectedCandidatesMcWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, // SelectedCandidatesMcCorrBkgsWithMl const&, - MatchedGenCandidatesMc const& particles, // MatchedGenCandidatesMcCorrBkgs const& particles, - TracksWPid const& tracks) - { - LOG(info) << "processMcCorrBkgsSgnWCentMl with " << reconstructedCandSigMl.size() << " reco particles"; - LOG(info) << "processMcCorrBkgsSgnWCentMl with " << particles.size() << " generated particles"; - fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); + aod::McCollisions const& mccollisions, + SelectedCandidatesMcWithMl const&, + MatchedGenCandidatesMc const& particles, + TracksWPid const& tracks) + { + fillMcTables(collisions, mccollisions, reconstructedCandSigMl, particles, tracks); } - PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcCorrBkgsSgnWCentMl, "Process MC correlated bkgs with cent and ML info", false); + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); + }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) From efbddc9aba3dfa7f602a843f89db3c23e57855fc Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Mon, 9 Jun 2025 21:09:48 +0200 Subject: [PATCH 18/47] Restore matching in D0 tree --- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index e278c1a4011..d1eccb74ec7 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -243,17 +243,17 @@ struct HfTreeCreatorD0ToKPi { using MatchedGenCandidatesMc = soa::Filtered>; Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= 1 || aod::hf_sel_candidate_d0::isSelD0bar >= 1; - Filter filterMcGenMatching = (nabs(aod::hf_cand_2prong::flagMcMatchGen) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); + Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); - Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); - Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; - Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); - Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; + Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); - Partition reconstructedCandBkgMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; - Partition reconstructedCandSigKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == aod::hf_cand_2prong::DecayType::D0ToPiK || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); - Partition reconstructedCandBkgKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != aod::hf_cand_2prong::DecayType::D0ToPiK; + Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); + Partition reconstructedCandSigKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandBkgKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); void init(InitContext const&) { @@ -513,7 +513,7 @@ struct HfTreeCreatorD0ToKPi { LOG(info) << "Processing " << candidates.size() << " candidates"; for (const auto& candidate : candidates) { if constexpr (onlyBkg) { - if ( (std::abs(candidate.flagMcMatchRec() == aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + if ( TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { continue; } if (downSampleBkgFactor < 1.) { @@ -524,7 +524,7 @@ struct HfTreeCreatorD0ToKPi { } } if constexpr (onlySig) { - if ( !(std::abs(candidate.flagMcMatchRec()) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + if ( !(TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { continue; } } @@ -552,7 +552,7 @@ struct HfTreeCreatorD0ToKPi { // Filling particle properties rowCandidateFullParticles.reserve(mcParticles.size()); for (const auto& particle : mcParticles) { - if ((nabs(aod::hf_cand_2prong::flagMcMatchGen) == aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0))) { + if ( TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && particle.flagMcMatchGen() != 0) ) { rowCandidateFullParticles( particle.mcCollisionId(), particle.pt(), From 7e66dec1075786d110bd173a34e32f654947e6a5 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 10 Jun 2025 12:08:58 +0200 Subject: [PATCH 19/47] Add break statements in 3prong matching --- PWGHF/Core/DecayChannels.h | 2 +- .../TableProducer/candidateCreator3Prong.cxx | 38 +++++-------------- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 4 +- PWGHF/Utils/utilsMcGen.h | 21 +++++----- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index afb0498fe89..426a14849ac 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -445,8 +445,8 @@ namespace o2::hf_corrbkg break; } } + LOG(info) << "Leaving function with channel: " << static_cast(*channel); // if (abs(motherPdg) == Pdg::kDStar) { - // LOG(info) << "Leaving function with channel: " << static_cast(*channel); // } } else { if (motherPdg != Pdg::kD0) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index bd223af0c53..906692cd9ab 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -945,25 +945,17 @@ struct HfCandidateCreator3ProngExpressions { } } - // LOG(info) << "CIAO REC MATCHING"; if (matchCorrBkgs) { - // LOG(info) << "CIAO 1"; - // LOG(info) << "--------------------------------------------"; - // LOG(info) << "Matching correlated bkgs"; std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; indexRec = -1; // Index of the matched reconstructed candidate - - // LOG(info) << "CIAO 2"; + for (const auto& pdg : mothersPdgCodes) { int depth = 2; if (pdg == Pdg::kDStar) { depth = 3; // D0 resonant decays are active } - // LOG(info) << "CIAO 3"; auto finalStates = getDecayChannel3Prong(pdg); - // LOG(info) << "CIAO 3.0"; for (const auto& [chn, finalState] : finalStates) { - // LOG(info) << "CIAO 3.0.1"; std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() > 3) { // Partly Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -975,8 +967,7 @@ struct HfCandidateCreator3ProngExpressions { } else { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } - - // LOG(info) << "CIAO 3.0.2"; + if (indexRec != -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); if (finalState.size() == 4) { // Check if the final state has 4 particles @@ -992,10 +983,8 @@ struct HfCandidateCreator3ProngExpressions { if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } - // LOG(info) << "CIAO 3.0.3"; } else if (finalState.size() == 5) { // Check if the final state has 3 particles // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3], sign*finalState[4]}; - // LOG(info) << "CIAO 3.0.4"; std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { @@ -1003,19 +992,13 @@ struct HfCandidateCreator3ProngExpressions { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } - // LOG(info) << "CIAO 3.0.5"; } if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched - // LOG(info) << "CIAO 3.0.6"; } - // LOG(info) << "CIAO 3.0.7"; } - // LOG(info) << "CIAO 3.0.8"; } - // LOG(info) << "CIAO 3.0.9"; } else if (finalState.size() == 3) { // Fully Reco 3-prong decays - // LOG(info) << "CIAO 3.1"; if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -1025,19 +1008,18 @@ struct HfCandidateCreator3ProngExpressions { } else { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } - // LOG(info) << "CIAO 3.2"; } else { LOG(info) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } - // LOG(info) << "CIAO 4"; if (indexRec > -1) { // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; flag = sign * chn; - + // Flag the resonant decay channel int resoMaxDepth = 1; - if (std::abs(pdg) == Pdg::kDStar) { + // if (std::abs(pdg) == Pdg::kDStar) { + if (std::abs(mcParticles.rawIteratorAt(indexRec).pdgCode()) == Pdg::kDStar) { resoMaxDepth = 2; // Flag D0 resonances } std::vector arrResoDaughIndex = {}; @@ -1049,16 +1031,16 @@ struct HfCandidateCreator3ProngExpressions { arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(pdg, &channel, arrPDGDaugh); - // LOG(info) << "CIAO 5"; - // LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); + LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } - // LOG(info) << "CIAO 6"; + } + if (indexRec > -1) { + break; // Exit loop if a match is found } } - // LOG(info) << "CIAO 7"; // LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index d1eccb74ec7..1cc6581c761 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -243,14 +243,14 @@ struct HfTreeCreatorD0ToKPi { using MatchedGenCandidatesMc = soa::Filtered>; Filter filterSelectCandidates = aod::hf_sel_candidate_d0::isSelD0 >= 1 || aod::hf_sel_candidate_d0::isSelD0bar >= 1; - Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); + Filter filterMcGenMatching = nabs(aod::hf_cand_2prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (nabs(aod::hf_cand_2prong::flagMcMatchGen) != 0)); Partition reconstructedCandSig = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); Partition reconstructedCandBkg = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); Partition reconstructedCandSigKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); Partition reconstructedCandBkgKF = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); - Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); + Partition reconstructedCandSigMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); Partition reconstructedCandBkgMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); Partition reconstructedCandSigKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && nabs(aod::hf_cand_2prong::flagMcMatchRec) != 0); Partition reconstructedCandBkgKFMl = nabs(aod::hf_cand_2prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_2prong::DecayType::D0ToPiK)); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 1fedabeffea..2c585dce8f5 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -203,7 +203,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matched) { flag = sign * chn; if (motherPdgCode == Pdg::kDStar) { - std::cout << "Matched final state: " << chn << " with PDG code: " << motherPdgCode << std::endl; + // std::cout << "Found D*: " << static_cast(flag) << " with PDG code: " << motherPdgCode << std::endl; } // Flag the resonant decay channel int resoMaxDepth = 1; @@ -213,7 +213,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " recognized as D0."; + // LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " recognized as D0."; auto daughDstarD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); RecoDecay::getDaughters(daughDstarD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); break; @@ -223,38 +223,41 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(daughDstarDplus, &arrResoDaughIndex, std::array{0}, resoMaxDepth); break; } else { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; + // LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; } - std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; + // std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; } } else { RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); } std::array arrPDGDaugh = {}; if (std::abs(motherPdgCode) == Pdg::kDStar) { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); + // LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); } if (arrResoDaughIndex.size() == NDaughtersResonant) { if (std::abs(motherPdgCode) == Pdg::kDStar) { - LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; } for (auto iProng = 0u; iProng < NDaughtersResonant; ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); if (std::abs(motherPdgCode) == Pdg::kDStar) { - std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; + // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; } arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); if (std::abs(motherPdgCode) == Pdg::kDStar) { - LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); + // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } } break; // Exit loop if a match is found } } + if (matched) { + break; // Exit loop if a match is found + } } } else { From 8334ba925942617d8d732741d95bc8df5824b26d Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 10 Jun 2025 20:50:34 +0200 Subject: [PATCH 20/47] Deleted debug prints --- PWGHF/Core/DecayChannels.h | 36 ++----------------- .../TableProducer/candidateCreator2Prong.cxx | 6 ++-- .../TableProducer/candidateCreator3Prong.cxx | 16 +++------ PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 1 - PWGHF/Utils/utilsMcGen.h | 32 +++-------------- 5 files changed, 15 insertions(+), 76 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 426a14849ac..47e3ac1c155 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -21,9 +21,9 @@ #ifndef PWGHF_CORE_DECAYCHANNELS_H_ #define PWGHF_CORE_DECAYCHANNELS_H_ +#include #include #include -#include using namespace o2::constants::physics; @@ -62,10 +62,10 @@ enum DecayChannelResonant : int8_t { std::unordered_map > finalStates2Prongs = { {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}} + {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, }; std::unordered_map > resoStatesD0 = @@ -388,25 +388,19 @@ namespace o2::hf_corrbkg /// \return true if the resonant channel is matched, false otherwise template bool checkResonantDecay(std::array arrPdgResoChn, std::array arrPdgDaugs) { - // LOG(info) << "Testing: " << arrPdgResoChn[0] << ", " << arrPdgResoChn[1] << " matching PDG codes: " << arrPdgDaugs[0] << ", " << arrPdgDaugs[1]; for (size_t i = 0; i < N; i++) { - // LOG(info) << "Checking daughter index: " << arrPdgResoChn[i]; bool findDaug = false; for (size_t j = 0; j < N; j++) { - // LOG(info) << "Checking daughter PDG: " << arrPdgResoChn[i] << " against resonant PDG: " << arrPdgDaugs[j]; if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { arrPdgDaugs[j] = -1; // Mark as found - // LOG(info) << "Matched!"; findDaug = true; break; } } if (!findDaug) { - // LOG(info) << "Returning false"; return false; } } - // LOG(info) << "Resonant decay found with daughters: " << arrPdgResoChn[0] << ", " << arrPdgResoChn[1] << " matching PDG codes: " << arrPdgDaugs[0] << ", " << arrPdgDaugs[1]; return true; } @@ -421,43 +415,19 @@ namespace o2::hf_corrbkg void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) { if constexpr (is3Prong) { std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); - if (abs(motherPdg) == Pdg::kDPlus) { - std::cout << "Flagging resonant channel for D+ with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; - } - if (abs(motherPdg) == Pdg::kDS) { - std::cout << "Flagging resonant channel for Ds with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; - } - if (abs(motherPdg) == Pdg::kDStar) { - std::cout << "Flagging resonant channel for Dstar with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; - } - if (abs(motherPdg) == Pdg::kLambdaCPlus) { - std::cout << "Flagging resonant channel for LambdaC with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; - } - if (abs(motherPdg) == Pdg::kXiCPlus) { - std::cout << "Flagging resonant channel for XiC with daughters: " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; - } for (const auto& [flag, pdgCodes] : resoStates) { if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; - // if (abs(motherPdg) == Pdg::kDStar) { - // LOG(info) << "Dstar resonant decay found with channel: " << static_cast(*channel); - // } break; } } - LOG(info) << "Leaving function with channel: " << static_cast(*channel); - // if (abs(motherPdg) == Pdg::kDStar) { - // } } else { if (motherPdg != Pdg::kD0) { - // LOG(error) << "Resonant decay flagging is only implemented for D0 resonances in 2-prong decays."; return; } for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { - // std::cout << "Checking D0 resonant decay with flag: " << flag << ", pdgCodes: " << pdgCodes[0] << ", " << pdgCodes[1] << " vs " << arrDaughPdgs[0] << " " << arrDaughPdgs[1] << std::endl; if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; - // LOG(info) << "D0 resonant decay found with channel: " << static_cast(*channel); break; } } diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index daa36fbc5a5..8e3b87b4b22 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -791,17 +791,17 @@ struct HfCandidateCreator2ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); } - if (indexRec != -1) { + if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; - if (sign < 0) { + if (motherParticle.pdgCode() < 0) { for (auto& part : finalStateParts2ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, false, &sign, depth)) { + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 906692cd9ab..9ef5a347148 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -590,7 +590,7 @@ struct HfCandidateCreator3Prong { uint8_t bitmapProngsContributorsPV = 0; if (indexCollision == track0.collisionId() && track0.isPVContributor()) { SETBIT(bitmapProngsContributorsPV, 0); - } + } if (indexCollision == track1.collisionId() && track1.isPVContributor()) { SETBIT(bitmapProngsContributorsPV, 1); } @@ -957,7 +957,7 @@ struct HfCandidateCreator3ProngExpressions { auto finalStates = getDecayChannel3Prong(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() > 3) { // Partly Reco 3-prong decays + if (finalState.size() > 3) { // Partly Reco 4-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -968,11 +968,10 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } - if (indexRec != -1) { + if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); if (finalState.size() == 4) { // Check if the final state has 4 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3]}; if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { @@ -983,8 +982,7 @@ struct HfCandidateCreator3ProngExpressions { if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } - } else if (finalState.size() == 5) { // Check if the final state has 3 particles - // std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], sign*finalState[3], sign*finalState[4]}; + } else if (finalState.size() == 5) { // Check if the final state has 5 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (sign < 0) { for (auto& part : finalStateParts3ProngAll) { @@ -993,7 +991,7 @@ struct HfCandidateCreator3ProngExpressions { } } } - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } } @@ -1013,7 +1011,6 @@ struct HfCandidateCreator3ProngExpressions { continue; // Skip unsupported final states } if (indexRec > -1) { - // std::cout << "Matched final state: " << chn << " with PDG code: " << pdg << std::endl; flag = sign * chn; // Flag the resonant decay channel @@ -1031,8 +1028,6 @@ struct HfCandidateCreator3ProngExpressions { arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(pdg, &channel, arrPDGDaugh); - LOG(info) << "[matchFinalStateCorrBkgs] Matched final state: " << chn << " with PDG code: " << static_cast(pdg) << ", flag: " << static_cast(flag) << ", &sign: " << static_cast(sign); - LOG(info) << "[matchFinalStateCorrBkgs] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); } break; // Exit loop if a match is found } @@ -1041,7 +1036,6 @@ struct HfCandidateCreator3ProngExpressions { break; // Exit loop if a match is found } } - // LOG(info) << "Corr Bkg matching ended with flag " << static_cast(flag) << " and indexRec " << static_cast(indexRec) << ", &sign " << static_cast(sign) << ", channel " << static_cast(channel); } else { // D± → π± K∓ π± if (flag == 0) { diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 1cc6581c761..91199261c53 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -510,7 +510,6 @@ struct HfTreeCreatorD0ToKPi { if constexpr (applyMl) { rowCandidateMl.reserve(candidates.size()); } - LOG(info) << "Processing " << candidates.size() << " candidates"; for (const auto& candidate : candidates) { if constexpr (onlyBkg) { if ( TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 2c585dce8f5..29aab36f47f 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -202,9 +202,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matched) { flag = sign * chn; - if (motherPdgCode == Pdg::kDStar) { - // std::cout << "Found D*: " << static_cast(flag) << " with PDG code: " << motherPdgCode << std::endl; - } // Flag the resonant decay channel int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; @@ -212,45 +209,24 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V std::vector arrResoDaughIndexDStar = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { - if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kD0) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " recognized as D0."; - auto daughDstarD0 = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); - RecoDecay::getDaughters(daughDstarD0, &arrResoDaughIndex, std::array{0}, resoMaxDepth); - break; - } else if (std::abs(mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode()) == Pdg::kDPlus) { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " is a D+."; - auto daughDstarDplus = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); - RecoDecay::getDaughters(daughDstarDplus, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + auto daughDstar = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + if (std::abs(daughDstar.pdgCode()) == Pdg::kD0 || std::abs(daughDstar.pdgCode()) == Pdg::kDPlus) { + RecoDecay::getDaughters(daughDstar, &arrResoDaughIndex, std::array{0}, resoMaxDepth); break; } else { - // LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; + LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; } - - // std::cout << "[matchFinalStateCorrBkgsGen] D* Daughter index: " << arrResoDaughIndexDStar[iDaug] << std::endl; } } else { RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); } std::array arrPDGDaugh = {}; - if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] D* decay detected, arrResoDaughIndex size: " << arrResoDaughIndex.size(); - } if (arrResoDaughIndex.size() == NDaughtersResonant) { - if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flagging resonant decay ... "; - } for (auto iProng = 0u; iProng < NDaughtersResonant; ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); - if (std::abs(motherPdgCode) == Pdg::kDStar) { - // std::cout << "Adding daughter PDG: " << daughI.pdgCode() << std::endl; - } arrPDGDaugh[iProng] = daughI.pdgCode(); } flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); - if (std::abs(motherPdgCode) == Pdg::kDStar) { - // LOG(info) << "[matchFinalStateCorrBkgsGen] Matched final state: " << chn << " with PDG code: " << motherPdgCode << ", flag: " << static_cast(flag) << ", sign: " << static_cast(sign); - // LOG(info) << "[matchFinalStateCorrBkgsGen] Flag set to: " << static_cast(flag) << " sign: " << static_cast(sign) << " for channel: " << static_cast(channel); - } } break; // Exit loop if a match is found } From 1f27e11b77624bcc74342a75691c251face47ee7 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 10 Jun 2025 21:04:54 +0200 Subject: [PATCH 21/47] Implement Mattia comment --- PWGHF/TableProducer/candidateCreator3Prong.cxx | 9 +-------- PWGHF/Utils/utilsMcGen.h | 5 ----- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 9ef5a347148..e09ad4e2ce4 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -979,7 +979,7 @@ struct HfCandidateCreator3ProngExpressions { } } } - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, false, &sign, depth)) { + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } } else if (finalState.size() == 5) { // Check if the final state has 5 particles @@ -1015,7 +1015,6 @@ struct HfCandidateCreator3ProngExpressions { // Flag the resonant decay channel int resoMaxDepth = 1; - // if (std::abs(pdg) == Pdg::kDStar) { if (std::abs(mcParticles.rawIteratorAt(indexRec).pdgCode()) == Pdg::kDStar) { resoMaxDepth = 2; // Flag D0 resonances } @@ -1167,23 +1166,17 @@ struct HfCandidateCreator3ProngExpressions { // Check whether the particle is non-prompt (from a b quark). if (flag != 0) { - // LOG(info) << "Setting origin"; auto particle = mcParticles.rawIteratorAt(indexRec); origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]); - // LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial); } else { - // LOG(info) << "[MCREC] Filling with flag: " << static_cast(flag) << ", origin: " << static_cast(origin) << ", channel: " << static_cast(channel); rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } - // LOG(info) << "BYE REC MATCHING, HELLO GEN MATCHING"; - // LOG(info) << "Filling MC match gen for 3 prong candidates"; - // LOG(info) << "Number of MC collisions: " << mcCollisions.size(); for (const auto& mcCollision : mcCollisions) { // Slice the particles table to get the particles for the current MC collision diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 29aab36f47f..47ff9ad4898 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -312,17 +312,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // Check whether the particle is non-prompt (from a b quark). - // LOG(info) << "[Gen] Flag: " << static_cast(flag); if (flag != 0) { - // LOG(info) << "[Gen] Setting origin gen"; origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); } if (origin == RecoDecay::OriginType::NonPrompt) { - // LOG(info) << "Origin is non-prompt"; - // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]); } else { - // LOG(info) << "[MCGEN] flag " << static_cast(flag) << " origin " << static_cast(origin) << " channel " << static_cast(channel); rowMcMatchGen(flag, origin, channel, -1); } } From 11452d7c4f65eaff9677c1f2e882445dd338a8d2 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 10 Jun 2025 21:24:54 +0200 Subject: [PATCH 22/47] Fix linter errors --- PWGHF/Core/DecayChannels.h | 1 + PWGHF/TableProducer/candidateCreator2Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreator3Prong.cxx | 4 ++-- PWGHF/Utils/utilsMcGen.h | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 47e3ac1c155..8252b8e9342 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -24,6 +24,7 @@ #include #include #include +#include using namespace o2::constants::physics; diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 8e3b87b4b22..48705953b1d 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -795,7 +795,7 @@ struct HfCandidateCreator2ProngExpressions { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; if (motherParticle.pdgCode() < 0) { - for (auto& part : finalStateParts2ProngAll) { + for (const auto& part : finalStateParts2ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index e09ad4e2ce4..2d7e66c9652 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -973,7 +973,7 @@ struct HfCandidateCreator3ProngExpressions { if (finalState.size() == 4) { // Check if the final state has 4 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (sign < 0) { - for (auto& part : finalStateParts3ProngAll) { + for (const auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } @@ -985,7 +985,7 @@ struct HfCandidateCreator3ProngExpressions { } else if (finalState.size() == 5) { // Check if the final state has 5 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (sign < 0) { - for (auto& part : finalStateParts3ProngAll) { + for (const auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 47ff9ad4898..d32ddc191ce 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -64,14 +64,14 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { + for (const auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); - } else if (finalState.size() == 2) { // Fully Reco 3-prong decays + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1]}; matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); } else { @@ -173,7 +173,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (finalState.size() == 5) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { + for (const auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } @@ -184,7 +184,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } else if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { + for (const auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } From 24b72df586efaf4ee88c4e573cd04562053a75bd Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Tue, 10 Jun 2025 19:27:12 +0000 Subject: [PATCH 23/47] Please consider the following formatting changes --- PWGHF/Core/DecayChannels.h | 357 +++++++++--------- .../TableProducer/candidateCreator2Prong.cxx | 16 +- .../TableProducer/candidateCreator3Prong.cxx | 12 +- PWGHF/TableProducer/treeCreatorD0ToKPi.cxx | 6 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 3 +- PWGHF/Utils/utilsMcGen.h | 16 +- 6 files changed, 206 insertions(+), 204 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 8252b8e9342..36bb8295060 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -60,21 +60,21 @@ enum DecayChannelResonant : int8_t { LastChannelResonant }; -std::unordered_map > finalStates2Prongs = -{ - {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, +std::unordered_map> finalStates2Prongs = + { + {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, }; -std::unordered_map > resoStatesD0 = -{ - {DecayChannelResonant::D0ToRhoplusPi, std::array{213, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, std::array{213, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, +std::unordered_map> resoStatesD0 = + { + {DecayChannelResonant::D0ToRhoplusPi, std::array{213, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, std::array{213, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, }; } // namespace hf_cand_2prong @@ -95,13 +95,13 @@ enum DecayChannelMain : int8_t { DsToPiPiPi, // 8, π+ π− π+ DsToPiPiPiPi0, // 9, π+ π− π+ π0 // D*+ - DstarToPiKPi, // 10, π+ K− π+ (from [(D0 → π+ K−) π+]) - DstarToPiKPiPi0, // 11, π+ K− π+ π0 - DstarToPiKPiPi0Pi0, // 12, π+ K− π+ π0 π0 - DstarToPiKK, // 13, π+ K− K+ - DstarToPiKKPi0, // 14, π+ K− K+ π0 - DstarToPiPiPi, // 15, π+ π− π+ - DstarToPiPiPiPi0, // 16, π+ π− π+ π0 + DstarToPiKPi, // 10, π+ K− π+ (from [(D0 → π+ K−) π+]) + DstarToPiKPiPi0, // 11, π+ K− π+ π0 + DstarToPiKPiPi0Pi0, // 12, π+ K− π+ π0 π0 + DstarToPiKK, // 13, π+ K− K+ + DstarToPiKKPi0, // 14, π+ K− K+ π0 + DstarToPiPiPi, // 15, π+ π− π+ + DstarToPiPiPiPi0, // 16, π+ π− π+ π0 // Λc+ LcToPKPi, // 17, p K− π+ LcToPKPiPi0, // 18, p K− π+ π0 @@ -153,99 +153,98 @@ enum DecayChannelResonant : int8_t { LastChannelResonant }; -std::unordered_map > resoStatesDPlus = -{ - {DecayChannelResonant::DplusToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, std::array{+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, std::array{+113, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, std::array{+225, +kPiPlus}}, +std::unordered_map> resoStatesDPlus = + { + {DecayChannelResonant::DplusToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, std::array{+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, std::array{+113, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, std::array{+225, +kPiPlus}}, }; -std::unordered_map > finalStatesDPlus = -{ - {DecayChannelMain::DplusToPiKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, +std::unordered_map> finalStatesDPlus = + { + {DecayChannelMain::DplusToPiKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, }; - + // Ds± → K± K∓ π± -std::unordered_map > resoStatesDs = -{ - {DecayChannelResonant::DsToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, std::array{+kPhi, +213}}, - {DecayChannelResonant::DsToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, std::array{+kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, std::array{113, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, std::array{113, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, std::array{225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, std::array{10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, std::array{221, +kPiPlus}}, +std::unordered_map> resoStatesDs = + { + {DecayChannelResonant::DsToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, std::array{+kPhi, +213}}, + {DecayChannelResonant::DsToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, std::array{+kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, std::array{113, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, std::array{113, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, std::array{225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, std::array{10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, std::array{221, +kPiPlus}}, }; -std::unordered_map > finalStatesDs = -{ - {DecayChannelMain::DsToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDs = + { + {DecayChannelMain::DsToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± -std::unordered_map > resoStatesDstar = -{ - {DecayChannelResonant::DstarToD0ToRhoplusPi, std::array{213, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, std::array{213, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, +std::unordered_map> resoStatesDstar = + { + {DecayChannelResonant::DstarToD0ToRhoplusPi, std::array{213, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, std::array{213, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, }; -std::unordered_map > finalStatesDstar = -{ - {DecayChannelMain::DstarToPiKPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDstar = + { + {DecayChannelMain::DstarToPiKPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± -std::unordered_map > resoStatesLambdaC = -{ - {DecayChannelResonant::LcToPKstar0, std::array{+kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, std::array{+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, std::array{+102134, +kPiPlus}}, +std::unordered_map> resoStatesLambdaC = + { + {DecayChannelResonant::LcToPKstar0, std::array{+kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, std::array{+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, std::array{+102134, +kPiPlus}}, }; -std::unordered_map > finalStatesLc = -{ - {DecayChannelMain::LcToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, std::vector{+kProton, +kKMinus, +kKPlus}} -}; - +std::unordered_map> finalStatesLc = + { + {DecayChannelMain::LcToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}}; + // Xic → p K∓ π± -std::unordered_map > resoStatesXiC = -{ - {DecayChannelResonant::XicToPKstar0, std::array{-kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, std::array{+kProton, +kPhi}}, +std::unordered_map> resoStatesXiC = + { + {DecayChannelResonant::XicToPKstar0, std::array{-kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, std::array{+kProton, +kPhi}}, }; -std::unordered_map > finalStatesXic = -{ - {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, +std::unordered_map> finalStatesXic = + { + {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; } // namespace hf_cand_3prong @@ -338,102 +337,106 @@ enum DecayChannelToJpsiResonant : int8_t { namespace o2::hf_corrbkg { - using namespace o2::hf_decay; +using namespace o2::hf_decay; - /// Returns a map of the possible final states for a specific 3-prong particle specie - /// \param pdgMother PDG code of the mother particle - /// \return a map of final states with their corresponding PDG codes - std::unordered_map > getDecayChannel3Prong(int pdgMother) { - switch (pdgMother) { - case Pdg::kDPlus: - return hf_cand_3prong::finalStatesDPlus; - case Pdg::kDS: - return hf_cand_3prong::finalStatesDs; - case Pdg::kDStar: - return hf_cand_3prong::finalStatesDstar; - case Pdg::kLambdaCPlus: - return hf_cand_3prong::finalStatesLc; - case Pdg::kXiCPlus: - return hf_cand_3prong::finalStatesXic; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } +/// Returns a map of the possible final states for a specific 3-prong particle specie +/// \param pdgMother PDG code of the mother particle +/// \return a map of final states with their corresponding PDG codes +std::unordered_map> getDecayChannel3Prong(int pdgMother) +{ + switch (pdgMother) { + case Pdg::kDPlus: + return hf_cand_3prong::finalStatesDPlus; + case Pdg::kDS: + return hf_cand_3prong::finalStatesDs; + case Pdg::kDStar: + return hf_cand_3prong::finalStatesDstar; + case Pdg::kLambdaCPlus: + return hf_cand_3prong::finalStatesLc; + case Pdg::kXiCPlus: + return hf_cand_3prong::finalStatesXic; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; } +} - /// Returns a map of the resonant decay channels for a specific 3-prong particle specie - /// \param pdgMother PDG code of the mother particle - /// \return a map of resonant decay channels with their corresponding PDG codes - std::unordered_map > getResoChannels3Prong(int pdgMother) { - switch (pdgMother) { - case Pdg::kDPlus: - return hf_cand_3prong::resoStatesDPlus; - case Pdg::kDS: - return hf_cand_3prong::resoStatesDs; - case Pdg::kDStar: - return hf_cand_3prong::resoStatesDstar; - case Pdg::kLambdaCPlus: - return hf_cand_3prong::resoStatesLambdaC; - case Pdg::kXiCPlus: - return hf_cand_3prong::resoStatesXiC; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } +/// Returns a map of the resonant decay channels for a specific 3-prong particle specie +/// \param pdgMother PDG code of the mother particle +/// \return a map of resonant decay channels with their corresponding PDG codes +std::unordered_map> getResoChannels3Prong(int pdgMother) +{ + switch (pdgMother) { + case Pdg::kDPlus: + return hf_cand_3prong::resoStatesDPlus; + case Pdg::kDS: + return hf_cand_3prong::resoStatesDs; + case Pdg::kDStar: + return hf_cand_3prong::resoStatesDstar; + case Pdg::kLambdaCPlus: + return hf_cand_3prong::resoStatesLambdaC; + case Pdg::kXiCPlus: + return hf_cand_3prong::resoStatesXiC; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; } +} - /// Perform the matching for a single resonant channel - /// \tparam N size of the array of daughter PDG codes - /// \param arrPdgResoChn array of daughter indices - /// \param arrPdgDaugs array of PDG codes for the resonant decay - /// \return true if the resonant channel is matched, false otherwise - template - bool checkResonantDecay(std::array arrPdgResoChn, std::array arrPdgDaugs) { - for (size_t i = 0; i < N; i++) { - bool findDaug = false; - for (size_t j = 0; j < N; j++) { - if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { - arrPdgDaugs[j] = -1; // Mark as found - findDaug = true; - break; - } - } - if (!findDaug) { - return false; +/// Perform the matching for a single resonant channel +/// \tparam N size of the array of daughter PDG codes +/// \param arrPdgResoChn array of daughter indices +/// \param arrPdgDaugs array of PDG codes for the resonant decay +/// \return true if the resonant channel is matched, false otherwise +template +bool checkResonantDecay(std::array arrPdgResoChn, std::array arrPdgDaugs) +{ + for (size_t i = 0; i < N; i++) { + bool findDaug = false; + for (size_t j = 0; j < N; j++) { + if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { + arrPdgDaugs[j] = -1; // Mark as found + findDaug = true; + break; } } - return true; + if (!findDaug) { + return false; + } } + return true; +} - /// Flag the resonant decays - /// Function documentation: - /// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay - /// \tparam N size of the array of daughter PDG codes - /// \param motherPdg PDG code of the mother particle - /// \param channel decay channel flag to be set - /// \param arrDaughPdgs array of daughter PDG codes - template - void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) { - if constexpr (is3Prong) { - std::unordered_map > resoStates = getResoChannels3Prong(motherPdg); - for (const auto& [flag, pdgCodes] : resoStates) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; - } - } - } else { - if (motherPdg != Pdg::kD0) { - return; +/// Flag the resonant decays +/// Function documentation: +/// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay +/// \tparam N size of the array of daughter PDG codes +/// \param motherPdg PDG code of the mother particle +/// \param channel decay channel flag to be set +/// \param arrDaughPdgs array of daughter PDG codes +template +void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) +{ + if constexpr (is3Prong) { + std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); + for (const auto& [flag, pdgCodes] : resoStates) { + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + break; } - for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; - } + } + } else { + if (motherPdg != Pdg::kD0) { + return; + } + for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + break; } } } +} } // namespace o2::hf_corrbkg #endif // PWGHF_CORE_DECAYCHANNELS_H_ diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 48705953b1d..5ef9bd1b736 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -780,9 +780,9 @@ struct HfCandidateCreator2ProngExpressions { int depth = 2; for (const auto& [chn, finalState] : finalStates2Prongs) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; - if (finalState.size() == 3) { // Partly Reco 2-prong decays + if (finalState.size() == 3) { // Partly Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -790,7 +790,7 @@ struct HfCandidateCreator2ProngExpressions { } else { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); } - + if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; @@ -805,15 +805,15 @@ struct HfCandidateCreator2ProngExpressions { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); } } else { LOG(info) << "Final state size not supported: " << finalStateParts2Prong.size(); diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 2d7e66c9652..f4fd058589b 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -957,9 +957,9 @@ struct HfCandidateCreator3ProngExpressions { auto finalStates = getDecayChannel3Prong(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() > 3) { // Partly Reco 4-prong decays + if (finalState.size() > 3) { // Partly Reco 4-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -996,7 +996,7 @@ struct HfCandidateCreator3ProngExpressions { } } } - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -1015,8 +1015,8 @@ struct HfCandidateCreator3ProngExpressions { // Flag the resonant decay channel int resoMaxDepth = 1; - if (std::abs(mcParticles.rawIteratorAt(indexRec).pdgCode()) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances + if (std::abs(mcParticles.rawIteratorAt(indexRec).pdgCode()) == Pdg::kDStar) { + resoMaxDepth = 2; // Flag D0 resonances } std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); @@ -1176,7 +1176,7 @@ struct HfCandidateCreator3ProngExpressions { rowMcMatchRec(flag, origin, swapping, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial); } } - + for (const auto& mcCollision : mcCollisions) { // Slice the particles table to get the particles for the current MC collision diff --git a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx index 91199261c53..59bf26581c5 100644 --- a/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorD0ToKPi.cxx @@ -512,7 +512,7 @@ struct HfTreeCreatorD0ToKPi { } for (const auto& candidate : candidates) { if constexpr (onlyBkg) { - if ( TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + if (TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0))) { continue; } if (downSampleBkgFactor < 1.) { @@ -523,7 +523,7 @@ struct HfTreeCreatorD0ToKPi { } } if constexpr (onlySig) { - if ( !(TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0)) ) { + if (!(TESTBIT(std::abs(candidate.flagMcMatchRec()), aod::hf_cand_2prong::DecayType::D0ToPiK)) || (fillCorrBkgs && (candidate.flagMcMatchRec() != 0))) { continue; } } @@ -551,7 +551,7 @@ struct HfTreeCreatorD0ToKPi { // Filling particle properties rowCandidateFullParticles.reserve(mcParticles.size()); for (const auto& particle : mcParticles) { - if ( TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && particle.flagMcMatchGen() != 0) ) { + if (TESTBIT(std::abs(particle.flagMcMatchGen()), aod::hf_cand_2prong::DecayType::D0ToPiK) || (fillCorrBkgs && particle.flagMcMatchGen() != 0)) { rowCandidateFullParticles( particle.mcCollisionId(), particle.pt(), diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 2b7b429d7f3..9f7e544ad74 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -245,7 +245,7 @@ DECLARE_SOA_TABLE(HfCandDpFullPs, "AOD", "HFCANDDPFULLP", /// Writes the full information in an output TTree struct HfTreeCreatorDplusToPiKPi { Produces rowCandidateFull; - Produces rowCandidateFullEvents; + Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; Produces rowCandidateMl; @@ -611,7 +611,6 @@ struct HfTreeCreatorDplusToPiKPi { } PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processMcSgnWCentMl, "Process MC signal with cent and ML info", false); - }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index d32ddc191ce..383fc1d4fa6 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -61,7 +61,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V bool matched = false; for (const auto& [chn, finalState] : finalStates2Prongs) { - if (finalState.size() == 3) { // Partly Reco 3-prong decays + if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { for (const auto& part : finalStateParts) { @@ -71,7 +71,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1]}; matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); } else { @@ -165,12 +165,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V int maxDepth = 2; bool matched = false; if (motherPdgCode == Pdg::kDStar) { - maxDepth = 3; // D0 resonant decays are switched on + maxDepth = 3; // D0 resonant decays are switched on } - + std::vector arrAllDaughtersIndex; for (const auto& [chn, finalState] : finalStates) { - if (finalState.size() == 5) { // Partly Reco 3-prong decays + if (finalState.size() == 5) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (particle.pdgCode() < 0) { for (const auto& part : finalStateParts) { @@ -181,7 +181,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 4) { // Partly Reco 3-prong decays + } else if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (particle.pdgCode() < 0) { for (const auto& part : finalStateParts) { @@ -192,7 +192,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); @@ -205,7 +205,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V // Flag the resonant decay channel int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; - if (std::abs(motherPdgCode) == Pdg::kDStar) { + if (std::abs(motherPdgCode) == Pdg::kDStar) { std::vector arrResoDaughIndexDStar = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { From 1010e4746d75c59b05d051ec499b5423a9f2317b Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 10 Jun 2025 21:46:07 +0200 Subject: [PATCH 24/47] Remove const qualifier --- PWGHF/TableProducer/candidateCreator2Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreator3Prong.cxx | 4 ++-- PWGHF/Utils/utilsMcGen.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 5ef9bd1b736..5118a923159 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -795,7 +795,7 @@ struct HfCandidateCreator2ProngExpressions { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; if (motherParticle.pdgCode() < 0) { - for (const auto& part : finalStateParts2ProngAll) { + for (auto& part : finalStateParts2ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index f4fd058589b..1ba3a1c873a 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -973,7 +973,7 @@ struct HfCandidateCreator3ProngExpressions { if (finalState.size() == 4) { // Check if the final state has 4 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (sign < 0) { - for (const auto& part : finalStateParts3ProngAll) { + for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } @@ -985,7 +985,7 @@ struct HfCandidateCreator3ProngExpressions { } else if (finalState.size() == 5) { // Check if the final state has 5 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (sign < 0) { - for (const auto& part : finalStateParts3ProngAll) { + for (auto& part : finalStateParts3ProngAll) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 383fc1d4fa6..1c5de513f05 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -64,7 +64,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { - for (const auto& part : finalStateParts) { + for (auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } @@ -173,7 +173,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (finalState.size() == 5) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; if (particle.pdgCode() < 0) { - for (const auto& part : finalStateParts) { + for (auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } @@ -184,7 +184,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } else if (finalState.size() == 4) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; if (particle.pdgCode() < 0) { - for (const auto& part : finalStateParts) { + for (auto& part : finalStateParts) { if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } From 73dcb0b5860a9e9736abf514cc4552850eba630e Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 11 Jun 2025 12:42:54 +0200 Subject: [PATCH 25/47] New header for matching functions --- PWGHF/Core/DecayChannels.h | 222 ---------------- .../TableProducer/candidateCreator2Prong.cxx | 1 + .../TableProducer/candidateCreator3Prong.cxx | 1 + PWGHF/Utils/utilsMcGen.h | 1 + PWGHF/Utils/utilsMcMatching.h | 251 ++++++++++++++++++ 5 files changed, 254 insertions(+), 222 deletions(-) create mode 100644 PWGHF/Utils/utilsMcMatching.h diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 36bb8295060..745d017a644 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -12,7 +12,6 @@ /// \file DecayChannels.h /// \brief Definitions of constants for MC flagging of HF decay channels. /// \author Vít Kučera , Inha University -/// \author Marcello Di Costanzo , Polytechnic University of Turin and INFN /// \note DecayChannelMain enums define unique combinations of the mother and the daughters for main channels. /// \note DecayChannelResonant enums define unique combinations of the mother and the daughters for resonant channels. /// \note Value 0 is reserved to indicate no match. @@ -21,12 +20,7 @@ #ifndef PWGHF_CORE_DECAYCHANNELS_H_ #define PWGHF_CORE_DECAYCHANNELS_H_ -#include #include -#include -#include - -using namespace o2::constants::physics; namespace o2::hf_decay { @@ -59,24 +53,6 @@ enum DecayChannelResonant : int8_t { // LastChannelResonant }; - -std::unordered_map> finalStates2Prongs = - { - {DecayChannelMain::D0ToPiK, std::vector{+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, std::vector{+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, std::vector{+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, std::vector{+kKMinus, +kKPlus}}, -}; - -std::unordered_map> resoStatesD0 = - { - {DecayChannelResonant::D0ToRhoplusPi, std::array{213, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, std::array{213, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, -}; - } // namespace hf_cand_2prong namespace hf_cand_3prong @@ -152,100 +128,6 @@ enum DecayChannelResonant : int8_t { // LastChannelResonant }; - -std::unordered_map> resoStatesDPlus = - { - {DecayChannelResonant::DplusToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, std::array{+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, std::array{+113, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, std::array{+225, +kPiPlus}}, -}; - -std::unordered_map> finalStatesDPlus = - { - {DecayChannelMain::DplusToPiKPi, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, -}; - -// Ds± → K± K∓ π± -std::unordered_map> resoStatesDs = - { - {DecayChannelResonant::DsToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, std::array{+kPhi, +213}}, - {DecayChannelResonant::DsToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, std::array{+kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, std::array{113, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, std::array{113, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, std::array{225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, std::array{10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, std::array{221, +kPiPlus}}, -}; - -std::unordered_map> finalStatesDs = - { - {DecayChannelMain::DsToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, std::vector{+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, -}; - -// Dstar → K± K∓ π± -std::unordered_map> resoStatesDstar = - { - {DecayChannelResonant::DstarToD0ToRhoplusPi, std::array{213, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, std::array{213, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, std::array{-kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, std::array{-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, std::array{+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, std::array{-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, std::array{+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, std::array{+113, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, std::array{+225, +kPiPlus}}, -}; - -std::unordered_map> finalStatesDstar = - { - {DecayChannelMain::DstarToPiKPi, std::vector{+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, std::vector{+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, std::vector{+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, std::vector{+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, std::vector{+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, std::vector{+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, -}; - -// Lc → p K∓ π± -std::unordered_map> resoStatesLambdaC = - { - {DecayChannelResonant::LcToPKstar0, std::array{+kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, std::array{+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, std::array{+102134, +kPiPlus}}, -}; - -std::unordered_map> finalStatesLc = - { - {DecayChannelMain::LcToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, std::vector{+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, std::vector{+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}}; - -// Xic → p K∓ π± -std::unordered_map> resoStatesXiC = - { - {DecayChannelResonant::XicToPKstar0, std::array{-kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, std::array{+kProton, +kPhi}}, -}; - -std::unordered_map> finalStatesXic = - { - {DecayChannelMain::XicToPKPi, std::vector{+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, std::vector{+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, std::vector{+kSigmaPlus, +kPiMinus, +kPiPlus}}, -}; } // namespace hf_cand_3prong namespace hf_cand_dstar @@ -335,108 +217,4 @@ enum DecayChannelToJpsiResonant : int8_t { } // namespace hf_cand_beauty } // namespace o2::hf_decay -namespace o2::hf_corrbkg -{ -using namespace o2::hf_decay; - -/// Returns a map of the possible final states for a specific 3-prong particle specie -/// \param pdgMother PDG code of the mother particle -/// \return a map of final states with their corresponding PDG codes -std::unordered_map> getDecayChannel3Prong(int pdgMother) -{ - switch (pdgMother) { - case Pdg::kDPlus: - return hf_cand_3prong::finalStatesDPlus; - case Pdg::kDS: - return hf_cand_3prong::finalStatesDs; - case Pdg::kDStar: - return hf_cand_3prong::finalStatesDstar; - case Pdg::kLambdaCPlus: - return hf_cand_3prong::finalStatesLc; - case Pdg::kXiCPlus: - return hf_cand_3prong::finalStatesXic; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } -} - -/// Returns a map of the resonant decay channels for a specific 3-prong particle specie -/// \param pdgMother PDG code of the mother particle -/// \return a map of resonant decay channels with their corresponding PDG codes -std::unordered_map> getResoChannels3Prong(int pdgMother) -{ - switch (pdgMother) { - case Pdg::kDPlus: - return hf_cand_3prong::resoStatesDPlus; - case Pdg::kDS: - return hf_cand_3prong::resoStatesDs; - case Pdg::kDStar: - return hf_cand_3prong::resoStatesDstar; - case Pdg::kLambdaCPlus: - return hf_cand_3prong::resoStatesLambdaC; - case Pdg::kXiCPlus: - return hf_cand_3prong::resoStatesXiC; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } -} - -/// Perform the matching for a single resonant channel -/// \tparam N size of the array of daughter PDG codes -/// \param arrPdgResoChn array of daughter indices -/// \param arrPdgDaugs array of PDG codes for the resonant decay -/// \return true if the resonant channel is matched, false otherwise -template -bool checkResonantDecay(std::array arrPdgResoChn, std::array arrPdgDaugs) -{ - for (size_t i = 0; i < N; i++) { - bool findDaug = false; - for (size_t j = 0; j < N; j++) { - if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { - arrPdgDaugs[j] = -1; // Mark as found - findDaug = true; - break; - } - } - if (!findDaug) { - return false; - } - } - return true; -} - -/// Flag the resonant decays -/// Function documentation: -/// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay -/// \tparam N size of the array of daughter PDG codes -/// \param motherPdg PDG code of the mother particle -/// \param channel decay channel flag to be set -/// \param arrDaughPdgs array of daughter PDG codes -template -void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) -{ - if constexpr (is3Prong) { - std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); - for (const auto& [flag, pdgCodes] : resoStates) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; - } - } - } else { - if (motherPdg != Pdg::kD0) { - return; - } - for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; - } - } - } -} -} // namespace o2::hf_corrbkg - #endif // PWGHF_CORE_DECAYCHANNELS_H_ diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 5118a923159..62dbb91c0b4 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -54,6 +54,7 @@ #include "PWGHF/Utils/utilsMcGen.h" #include "PWGHF/Utils/utilsPid.h" #include "PWGHF/Utils/utilsTrkCandHf.h" +#include "PWGHF/Utils/utilsMcMatching.h" using namespace o2; using namespace o2::analysis; diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 1ba3a1c873a..596b09b0109 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -53,6 +53,7 @@ #include "PWGHF/Utils/utilsMcGen.h" #include "PWGHF/Utils/utilsPid.h" #include "PWGHF/Utils/utilsTrkCandHf.h" +#include "PWGHF/Utils/utilsMcMatching.h" using namespace o2; using namespace o2::hf_evsel; diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 1c5de513f05..14fc24140d1 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -30,6 +30,7 @@ #include "PWGHF/Core/DecayChannels.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" +#include "PWGHF/Utils/utilsMcMatching.h" using namespace o2::hf_decay::hf_cand_2prong; using namespace o2::hf_decay::hf_cand_3prong; diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h new file mode 100644 index 00000000000..6125a80024a --- /dev/null +++ b/PWGHF/Utils/utilsMcMatching.h @@ -0,0 +1,251 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file utilsMcMatching.h +/// \brief Mapping of MC flags contained in DecayChannels.h +/// \author Marcello Di Costanzo , Polytechnic University of Turin and INFN + +#ifndef PWGHF_UTILS_UTILSMCMATCHING_H_ +#define PWGHF_UTILS_UTILSMCMATCHING_H_ + +#include +#include +#include +#include + +#include "PWGHF/Core/DecayChannels.h" + +namespace o2::hf_corrbkg +{ +using namespace o2::hf_decay +using namespace o2::constants::physics; + +namespace 2prong +{ + +std::unordered_map> finalStates2Prongs = + { + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, +}; + +std::unordered_map> resoStatesD0 = + { + {DecayChannelResonant::D0ToRhoplusPi, {213, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {213, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, +}; + +} // namespace 2prong + +namespace 3prong +{ + +std::unordered_map> resoStatesDPlus = + { + {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+113, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, +}; + +std::unordered_map> finalStatesDPlus = + { + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +}; + +// Ds± → K± K∓ π± +std::unordered_map> resoStatesDs = + { + {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +213}}, + {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {113, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {113, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, +}; + +std::unordered_map> finalStatesDs = + { + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +}; + +// Dstar → K± K∓ π± +std::unordered_map> resoStatesDstar = + { + {DecayChannelResonant::DstarToD0ToRhoplusPi, {213, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {213, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+113, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, +}; + +std::unordered_map> finalStatesDstar = + { + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +}; + +// Lc → p K∓ π± +std::unordered_map> resoStatesLambdaC = + { + {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, +}; + +std::unordered_map> finalStatesLc = + { + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; + +// Xic → p K∓ π± +std::unordered_map> resoStatesXiC = + { + {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, +}; + +std::unordered_map> finalStatesXic = + { + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, +}; +} + +/// Returns a map of the possible final states for a specific 3-prong particle specie +/// \param pdgMother PDG code of the mother particle +/// \return a map of final states with their corresponding PDG codes +std::unordered_map> getDecayChannel3Prong(int pdgMother) +{ + switch (pdgMother) { + case Pdg::kDPlus: + return 3prong::finalStatesDPlus; + case Pdg::kDS: + return 3prong::finalStatesDs; + case Pdg::kDStar: + return 3prong::finalStatesDstar; + case Pdg::kLambdaCPlus: + return 3prong::finalStatesLc; + case Pdg::kXiCPlus: + return 3prong::finalStatesXic; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; + } +} + +/// Returns a map of the resonant decay channels for a specific 3-prong particle specie +/// \param pdgMother PDG code of the mother particle +/// \return a map of resonant decay channels with their corresponding PDG codes +std::unordered_map> getResoChannels3Prong(int pdgMother) +{ + switch (pdgMother) { + case Pdg::kDPlus: + return 3prong::resoStatesDPlus; + case Pdg::kDS: + return 3prong::resoStatesDs; + case Pdg::kDStar: + return 3prong::resoStatesDstar; + case Pdg::kLambdaCPlus: + return 3prong::resoStatesLambdaC; + case Pdg::kXiCPlus: + return 3prong::resoStatesXiC; + default: + LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + return {}; + } +} + +/// Perform the matching for a single resonant channel +/// \tparam N size of the array of daughter PDG codes +/// \param arrPdgResoChn array of daughter indices +/// \param arrPdgDaugs array of PDG codes for the resonant decay +/// \return true if the resonant channel is matched, false otherwise +template +bool checkResonantDecay(std::array const& arrPdgResoChn, std::array const& arrPdgDaugs) +{ + for (std::size_t i = 0; i < N; i++) { + bool findDaug = false; + for (std::size_t j = 0; j < N; j++) { + if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { + arrPdgDaugs[j] = -1; // Mark as found + findDaug = true; + break; + } + } + if (!findDaug) { + return false; + } + } + return true; +} + +/// Flag the resonant decays +/// Function documentation: +/// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay +/// \tparam N size of the array of daughter PDG codes +/// \param motherPdg PDG code of the mother particle +/// \param channel decay channel flag to be set +/// \param arrDaughPdgs array of daughter PDG codes +template +void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) +{ + if constexpr (is3Prong) { + std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); + for (const auto& [flag, pdgCodes] : resoStates) { + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + break; + } + } + } else { + if (motherPdg != Pdg::kD0) { + return; + } + for (const auto& [flag, pdgCodes] : 3prong::resoStatesD0) { + if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + *channel = flag; + break; + } + } + } +} +} // namespace o2::hf_corrbkg + +#endif // PWGHF_UTILS_UTILSMCMATCHING_H_ From 5ffc6a5d82e1496f9482bc3d1ea0538f39388a3a Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 11 Jun 2025 16:18:29 +0200 Subject: [PATCH 26/47] Implement Mattia and Vit comments --- .../TableProducer/candidateCreator2Prong.cxx | 2 +- .../TableProducer/candidateCreator3Prong.cxx | 10 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 1 - PWGHF/Utils/utilsMcGen.h | 13 +- PWGHF/Utils/utilsMcMatching.h | 210 +++++++++--------- 5 files changed, 117 insertions(+), 119 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 62dbb91c0b4..d53338523f0 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -779,7 +779,7 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { indexRec = -1; // Index of the matched reconstructed candidate int depth = 2; - for (const auto& [chn, finalState] : finalStates2Prongs) { + for (const auto& [chn, finalState] : hf_chns_2prong::finalStates2Prongs) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; if (finalState.size() == 3) { // Partly Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 596b09b0109..1a9be5ff251 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -59,14 +59,14 @@ using namespace o2; using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_3prong; -using namespace o2::hf_decay; +using namespace o2::hf_decay::hf_cand_3prong; +using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::aod::pid_tpc_tof_utils; -using namespace o2::hf_corrbkg; /// Reconstruction of heavy-flavour 3-prong decay candidates struct HfCandidateCreator3Prong { @@ -853,6 +853,7 @@ struct HfCandidateCreator3ProngExpressions { Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; + Configurable> mothersCorrBkgsPdgs{"mothersCorrBkgsPdgs", {411, 413, 431, 4122, 4232}, "PDG codes of the mother particles of correlated background candidates"}; constexpr static std::size_t NDaughtersResonant{2u}; @@ -947,10 +948,9 @@ struct HfCandidateCreator3ProngExpressions { } if (matchCorrBkgs) { - std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; indexRec = -1; // Index of the matched reconstructed candidate - for (const auto& pdg : mothersPdgCodes) { + for (const auto& pdg : mothersCorrBkgsPdgs.value) { int depth = 2; if (pdg == Pdg::kDStar) { depth = 3; // D0 resonant decays are active @@ -1206,7 +1206,7 @@ struct HfCandidateCreator3ProngExpressions { continue; } if (matchCorrBkgs) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, mothersCorrBkgsPdgs.value); } else { hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 9f7e544ad74..eb861f1b626 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -31,7 +31,6 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::hf_centrality; -using namespace o2::hf_corrbkg; namespace o2::aod { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 14fc24140d1..5adaeafe0d8 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -32,13 +32,11 @@ #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/Utils/utilsMcMatching.h" -using namespace o2::hf_decay::hf_cand_2prong; -using namespace o2::hf_decay::hf_cand_3prong; -using namespace o2::hf_corrbkg; - namespace hf_mc_gen { +using namespace o2::hf_corrbkg; + template void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { @@ -61,7 +59,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matchCorrBkgs) { bool matched = false; - for (const auto& [chn, finalState] : finalStates2Prongs) { + for (const auto& [chn, finalState] : o2::hf_corrbkg::hf_chns_2prong::finalStates2Prongs) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { @@ -131,7 +129,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } template -void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) +void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, std::vector const& corrBkgMothersPdgs = {}) { using namespace o2::constants::physics; constexpr std::size_t NDaughtersResonant{2u}; @@ -157,8 +155,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (matchCorrBkgs) { - std::array mothersPdgCodes = {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}; - for (const auto& motherPdgCode : mothersPdgCodes) { + for (const auto& motherPdgCode : corrBkgMothersPdgs) { if (std::abs(particle.pdgCode()) != motherPdgCode) { continue; // Skip if the particle PDG code does not match the mother PDG code } diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 6125a80024a..02522a40b4b 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -25,145 +25,147 @@ namespace o2::hf_corrbkg { -using namespace o2::hf_decay +using namespace o2::hf_decay; using namespace o2::constants::physics; -namespace 2prong +namespace hf_chns_2prong { -std::unordered_map> finalStates2Prongs = - { - {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, +using namespace o2::hf_decay::hf_cand_2prong; +std::unordered_map> finalStates2Prongs = +{ + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; -std::unordered_map> resoStatesD0 = - { - {DecayChannelResonant::D0ToRhoplusPi, {213, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, {213, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, +std::unordered_map> resoStatesD0 = +{ + {DecayChannelResonant::D0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {kRho770Plus, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, }; } // namespace 2prong - -namespace 3prong + +namespace hf_chns_3prong { -std::unordered_map> resoStatesDPlus = - { - {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, {+113, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, +using namespace o2::hf_decay::hf_cand_3prong; +std::unordered_map> resoStatesDPlus = +{ + {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDPlus = - { - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +std::unordered_map> finalStatesDPlus = +{ + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± -std::unordered_map> resoStatesDs = - { - {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +213}}, - {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, {113, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, {113, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, +std::unordered_map> resoStatesDs = +{ + {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +kRho770Plus}}, + {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; -std::unordered_map> finalStatesDs = - { - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDs = +{ + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± -std::unordered_map> resoStatesDstar = - { - {DecayChannelResonant::DstarToD0ToRhoplusPi, {213, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, {213, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, {+113, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, +std::unordered_map> resoStatesDstar = +{ + {DecayChannelResonant::DstarToD0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {kRho770Plus, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDstar = - { - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDstar = +{ + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± -std::unordered_map> resoStatesLambdaC = - { - {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, +std::unordered_map> resoStatesLambdaC = +{ + {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; -std::unordered_map> finalStatesLc = - { - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; +std::unordered_map> finalStatesLc = +{ + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± -std::unordered_map> resoStatesXiC = - { - {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, +std::unordered_map> resoStatesXiC = +{ + {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, }; -std::unordered_map> finalStatesXic = - { - {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, +std::unordered_map> finalStatesXic = +{ + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; } /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -std::unordered_map> getDecayChannel3Prong(int pdgMother) +std::unordered_map> getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { case Pdg::kDPlus: - return 3prong::finalStatesDPlus; + return hf_chns_3prong::finalStatesDPlus; case Pdg::kDS: - return 3prong::finalStatesDs; + return hf_chns_3prong::finalStatesDs; case Pdg::kDStar: - return 3prong::finalStatesDstar; + return hf_chns_3prong::finalStatesDstar; case Pdg::kLambdaCPlus: - return 3prong::finalStatesLc; + return hf_chns_3prong::finalStatesLc; case Pdg::kXiCPlus: - return 3prong::finalStatesXic; + return hf_chns_3prong::finalStatesXic; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -173,19 +175,19 @@ std::unordered_map> getDecayC /// Returns a map of the resonant decay channels for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of resonant decay channels with their corresponding PDG codes -std::unordered_map> getResoChannels3Prong(int pdgMother) +std::unordered_map> getResoChannels3Prong(int pdgMother) { switch (pdgMother) { case Pdg::kDPlus: - return 3prong::resoStatesDPlus; + return hf_chns_3prong::resoStatesDPlus; case Pdg::kDS: - return 3prong::resoStatesDs; + return hf_chns_3prong::resoStatesDs; case Pdg::kDStar: - return 3prong::resoStatesDstar; + return hf_chns_3prong::resoStatesDstar; case Pdg::kLambdaCPlus: - return 3prong::resoStatesLambdaC; + return hf_chns_3prong::resoStatesLambdaC; case Pdg::kXiCPlus: - return 3prong::resoStatesXiC; + return hf_chns_3prong::resoStatesXiC; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -198,7 +200,7 @@ std::unordered_map> get /// \param arrPdgDaugs array of PDG codes for the resonant decay /// \return true if the resonant channel is matched, false otherwise template -bool checkResonantDecay(std::array const& arrPdgResoChn, std::array const& arrPdgDaugs) +bool checkResonantDecay(std::array const& arrPdgResoChn, std::array arrPdgDaugs) { for (std::size_t i = 0; i < N; i++) { bool findDaug = false; @@ -224,10 +226,10 @@ bool checkResonantDecay(std::array const& arrPdgResoChn, std::array -void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDaughPdgs) +void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) { if constexpr (is3Prong) { - std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); + std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); for (const auto& [flag, pdgCodes] : resoStates) { if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; @@ -238,7 +240,7 @@ void flagResonantDecay(int motherPdg, int8_t* channel, std::array arrDau if (motherPdg != Pdg::kD0) { return; } - for (const auto& [flag, pdgCodes] : 3prong::resoStatesD0) { + for (const auto& [flag, pdgCodes] : hf_chns_2prong::resoStatesD0) { if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; break; From 4a206594d558de2038aa34318fcf22f9028a8787 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Wed, 11 Jun 2025 14:40:57 +0000 Subject: [PATCH 27/47] Please consider the following formatting changes --- PWGHF/Utils/utilsMcMatching.h | 150 +++++++++++++++++----------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 02522a40b4b..22d035c6059 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -33,122 +33,122 @@ namespace hf_chns_2prong using namespace o2::hf_decay::hf_cand_2prong; std::unordered_map> finalStates2Prongs = -{ - {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, + { + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; std::unordered_map> resoStatesD0 = -{ - {DecayChannelResonant::D0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, {kRho770Plus, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, + { + {DecayChannelResonant::D0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {kRho770Plus, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, }; -} // namespace 2prong - +} // namespace hf_chns_2prong + namespace hf_chns_3prong { using namespace o2::hf_decay::hf_cand_3prong; std::unordered_map> resoStatesDPlus = -{ - {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, + { + {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; std::unordered_map> finalStatesDPlus = -{ - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + { + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± std::unordered_map> resoStatesDs = -{ - {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +kRho770Plus}}, - {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, + { + {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +kRho770Plus}}, + {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; std::unordered_map> finalStatesDs = -{ - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + { + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± std::unordered_map> resoStatesDstar = -{ - {DecayChannelResonant::DstarToD0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, {kRho770Plus, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, + { + {DecayChannelResonant::DstarToD0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {kRho770Plus, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; std::unordered_map> finalStatesDstar = -{ - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + { + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± std::unordered_map> resoStatesLambdaC = -{ - {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, + { + {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; std::unordered_map> finalStatesLc = -{ - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; + { + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± std::unordered_map> resoStatesXiC = -{ - {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, + { + {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, }; std::unordered_map> finalStatesXic = -{ - {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, + { + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; -} +} // namespace hf_chns_3prong /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle From d57cc0e2a82a5e83bba3d3e4760a06f5a74ce070 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 12 Jun 2025 09:00:45 +0200 Subject: [PATCH 28/47] Implement Mattia and Vit comments --- .../TableProducer/candidateCreator3Prong.cxx | 18 +- PWGHF/Utils/utilsMcMatching.h | 220 +++++++++--------- 2 files changed, 117 insertions(+), 121 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 1a9be5ff251..d030943c36c 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -60,13 +60,13 @@ using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_3prong; using namespace o2::hf_decay::hf_cand_3prong; -using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::aod::pid_tpc_tof_utils; +using namespace o2::hf_corrbkg; /// Reconstruction of heavy-flavour 3-prong decay candidates struct HfCandidateCreator3Prong { @@ -853,7 +853,7 @@ struct HfCandidateCreator3ProngExpressions { Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; - Configurable> mothersCorrBkgsPdgs{"mothersCorrBkgsPdgs", {411, 413, 431, 4122, 4232}, "PDG codes of the mother particles of correlated background candidates"}; + Configurable> mothersCorrBkgsPdgs{"mothersCorrBkgsPdgs", {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}, "PDG codes of the mother particles of correlated background candidates"}; constexpr static std::size_t NDaughtersResonant{2u}; @@ -1049,7 +1049,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * hf_cand_3prong::DecayChannelMain::DplusToPiKPi; + flag = sign * DecayChannelMain::DplusToPiKPi; } } @@ -1078,7 +1078,7 @@ struct HfCandidateCreator3ProngExpressions { } } if (indexRec > -1) { - flag = sign * (isDplus ? hf_cand_3prong::DecayChannelMain::DplusToPiKK : hf_cand_3prong::DecayChannelMain::DsToPiKK); + flag = sign * (isDplus ? DecayChannelMain::DplusToPiKK : DecayChannelMain::DsToPiKK); if (arrayDaughters[0].has_mcParticle()) { swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); } @@ -1089,9 +1089,9 @@ struct HfCandidateCreator3ProngExpressions { arrPDGDaugh[iProng] = std::abs(daughI.pdgCode()); } if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) { - channel = isDplus ? hf_cand_3prong::DecayChannelResonant::DplusToPhiPi : hf_cand_3prong::DecayChannelResonant::DsToPhiPi; + channel = isDplus ? DecayChannelResonant::DplusToPhiPi : DecayChannelResonant::DsToPhiPi; } else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) { - channel = isDplus ? hf_cand_3prong::DecayChannelResonant::DplusToKstar0K : hf_cand_3prong::DecayChannelResonant::DsToKstar0K; + channel = isDplus ? DecayChannelResonant::DplusToKstar0K : DecayChannelResonant::DsToKstar0K; } } } @@ -1105,7 +1105,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * hf_cand_3prong::DecayChannelMain::DstarToPiKPi; + flag = sign * DecayChannelMain::DstarToPiKPi; channel = 1; } } @@ -1122,7 +1122,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * hf_cand_3prong::DecayChannelMain::LcToPKPi; + flag = sign * DecayChannelMain::LcToPKPi; // Flagging the different Λc± → p± K∓ π± decay channels if (arrayDaughters[0].has_mcParticle()) { @@ -1157,7 +1157,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2); } if (indexRec > -1) { - flag = sign * hf_cand_3prong::DecayChannelMain::XicToPKPi; + flag = sign * DecayChannelMain::XicToPKPi; if (arrayDaughters[0].has_mcParticle()) { swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); } diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 22d035c6059..9e81cd60c23 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -25,28 +25,25 @@ namespace o2::hf_corrbkg { -using namespace o2::hf_decay; -using namespace o2::constants::physics; namespace hf_chns_2prong { -using namespace o2::hf_decay::hf_cand_2prong; -std::unordered_map> finalStates2Prongs = - { - {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, +std::unordered_map> finalStates2Prongs = +{ + {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; -std::unordered_map> resoStatesD0 = - { - {DecayChannelResonant::D0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, {kRho770Plus, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, +std::unordered_map> resoStatesD0 = +{ + {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, }; } // namespace hf_chns_2prong @@ -54,118 +51,117 @@ std::unordered_map> resoStatesD0 namespace hf_chns_3prong { -using namespace o2::hf_decay::hf_cand_3prong; -std::unordered_map> resoStatesDPlus = - { - {DecayChannelResonant::DplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, +std::unordered_map> resoStatesDPlus = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDPlus = - { - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +std::unordered_map> finalStatesDPlus = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± -std::unordered_map> resoStatesDs = - { - {DecayChannelResonant::DsToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, {+kPhi, +kRho770Plus}}, - {DecayChannelResonant::DsToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, {+kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, +std::unordered_map> resoStatesDs = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; -std::unordered_map> finalStatesDs = - { - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDs = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± -std::unordered_map> resoStatesDstar = - { - {DecayChannelResonant::DstarToD0ToRhoplusPi, {kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, {kRho770Plus, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, {-kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, {+kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, {-kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, +std::unordered_map> resoStatesDstar = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDstar = - { - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +std::unordered_map> finalStatesDstar = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± -std::unordered_map> resoStatesLambdaC = - { - {DecayChannelResonant::LcToPKstar0, {+kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, +std::unordered_map> resoStatesLambdaC = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; -std::unordered_map> finalStatesLc = - { - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; +std::unordered_map> finalStatesLc = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± -std::unordered_map> resoStatesXiC = - { - {DecayChannelResonant::XicToPKstar0, {-kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +kPhi}}, +std::unordered_map> resoStatesXiC = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, }; -std::unordered_map> finalStatesXic = - { - {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, +std::unordered_map> finalStatesXic = +{ + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; } // namespace hf_chns_3prong /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -std::unordered_map> getDecayChannel3Prong(int pdgMother) +std::unordered_map> getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { - case Pdg::kDPlus: - return hf_chns_3prong::finalStatesDPlus; - case Pdg::kDS: - return hf_chns_3prong::finalStatesDs; - case Pdg::kDStar: - return hf_chns_3prong::finalStatesDstar; - case Pdg::kLambdaCPlus: - return hf_chns_3prong::finalStatesLc; - case Pdg::kXiCPlus: - return hf_chns_3prong::finalStatesXic; + case o2::constants::physics::Pdg::kDPlus: + return o2::hf_corrbkg::hf_chns_3prong::finalStatesDPlus; + case o2::constants::physics::Pdg::kDS: + return o2::hf_corrbkg::hf_chns_3prong::finalStatesDs; + case o2::constants::physics::Pdg::kDStar: + return o2::hf_corrbkg::hf_chns_3prong::finalStatesDstar; + case o2::constants::physics::Pdg::kLambdaCPlus: + return o2::hf_corrbkg::hf_chns_3prong::finalStatesLc; + case o2::constants::physics::Pdg::kXiCPlus: + return o2::hf_corrbkg::hf_chns_3prong::finalStatesXic; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -175,19 +171,19 @@ std::unordered_map> get /// Returns a map of the resonant decay channels for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of resonant decay channels with their corresponding PDG codes -std::unordered_map> getResoChannels3Prong(int pdgMother) +std::unordered_map> getResoChannels3Prong(int pdgMother) { switch (pdgMother) { - case Pdg::kDPlus: - return hf_chns_3prong::resoStatesDPlus; - case Pdg::kDS: - return hf_chns_3prong::resoStatesDs; - case Pdg::kDStar: - return hf_chns_3prong::resoStatesDstar; - case Pdg::kLambdaCPlus: - return hf_chns_3prong::resoStatesLambdaC; - case Pdg::kXiCPlus: - return hf_chns_3prong::resoStatesXiC; + case o2::constants::physics::Pdg::kDPlus: + return o2::hf_corrbkg::hf_chns_3prong::resoStatesDPlus; + case o2::constants::physics::Pdg::kDS: + return o2::hf_corrbkg::hf_chns_3prong::resoStatesDs; + case o2::constants::physics::Pdg::kDStar: + return o2::hf_corrbkg::hf_chns_3prong::resoStatesDstar; + case o2::constants::physics::Pdg::kLambdaCPlus: + return o2::hf_corrbkg::hf_chns_3prong::resoStatesLambdaC; + case o2::constants::physics::Pdg::kXiCPlus: + return o2::hf_corrbkg::hf_chns_3prong::resoStatesXiC; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -229,7 +225,7 @@ template void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) { if constexpr (is3Prong) { - std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); + std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); for (const auto& [flag, pdgCodes] : resoStates) { if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; @@ -237,7 +233,7 @@ void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& } } } else { - if (motherPdg != Pdg::kD0) { + if (motherPdg != o2::constants::physics::Pdg::kD0) { return; } for (const auto& [flag, pdgCodes] : hf_chns_2prong::resoStatesD0) { From 5c5cdb74abcb4e4148ff88dd48de67e1372c9fc9 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 12 Jun 2025 14:59:04 +0200 Subject: [PATCH 29/47] Use old flag scheme for 2prongs --- .../TableProducer/candidateCreator2Prong.cxx | 6 +- .../TableProducer/candidateCreator3Prong.cxx | 2 +- PWGHF/Utils/utilsMcGen.h | 12 +- PWGHF/Utils/utilsMcMatching.h | 194 +++++++++--------- 4 files changed, 107 insertions(+), 107 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index d53338523f0..1667e8e5ec0 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -61,8 +61,8 @@ using namespace o2::analysis; using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_2prong; +using namespace o2::hf_decay; using namespace o2::hf_decay::hf_cand_2prong; -using namespace o2::hf_corrbkg; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; using namespace o2::constants::physics; @@ -779,7 +779,7 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { indexRec = -1; // Index of the matched reconstructed candidate int depth = 2; - for (const auto& [chn, finalState] : hf_chns_2prong::finalStates2Prongs) { + for (const auto& [chn, finalState] : hf_cand_2prong::finalStates2Prongs) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; if (finalState.size() == 3) { // Partly Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { @@ -821,7 +821,7 @@ struct HfCandidateCreator2ProngExpressions { continue; } if (indexRec > -1) { - flag = sign * chn; + flag = sign * (1 << chn); // Flag the resonant decay channel int resoMaxDepth = 1; diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index d030943c36c..28b64e5e0ab 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -59,6 +59,7 @@ using namespace o2; using namespace o2::hf_evsel; using namespace o2::hf_trkcandsel; using namespace o2::aod::hf_cand_3prong; +using namespace o2::hf_decay; using namespace o2::hf_decay::hf_cand_3prong; using namespace o2::hf_centrality; using namespace o2::hf_occupancy; @@ -66,7 +67,6 @@ using namespace o2::constants::physics; using namespace o2::framework; using namespace o2::framework::expressions; using namespace o2::aod::pid_tpc_tof_utils; -using namespace o2::hf_corrbkg; /// Reconstruction of heavy-flavour 3-prong decay candidates struct HfCandidateCreator3Prong { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 5adaeafe0d8..7b1787a85db 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -35,8 +35,6 @@ namespace hf_mc_gen { -using namespace o2::hf_corrbkg; - template void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { @@ -59,7 +57,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matchCorrBkgs) { bool matched = false; - for (const auto& [chn, finalState] : o2::hf_corrbkg::hf_chns_2prong::finalStates2Prongs) { + for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::finalStates2Prongs) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { @@ -78,7 +76,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matched) { - flag = sign * chn; + flag = sign * (1 << chn); // Flag the resonant decay channel int resoMaxDepth = 1; @@ -90,7 +88,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); + o2::hf_decay::flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); } break; } @@ -159,7 +157,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (std::abs(particle.pdgCode()) != motherPdgCode) { continue; // Skip if the particle PDG code does not match the mother PDG code } - auto finalStates = getDecayChannel3Prong(motherPdgCode); + auto finalStates = o2::hf_decay::hf_cand_3prong::getDecayChannel3Prong(motherPdgCode); int maxDepth = 2; bool matched = false; if (motherPdgCode == Pdg::kDStar) { @@ -224,7 +222,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); + o2::hf_decay::flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); } break; // Exit loop if a match is found } diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 9e81cd60c23..2aec406d7f6 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -23,145 +23,144 @@ #include "PWGHF/Core/DecayChannels.h" -namespace o2::hf_corrbkg +namespace o2::hf_decay { -namespace hf_chns_2prong +namespace hf_cand_2prong { -std::unordered_map> finalStates2Prongs = +std::unordered_map> finalStates2Prongs = { - {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; -std::unordered_map> resoStatesD0 = +std::unordered_map> resoStatesD0 = { - {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {o2::hf_decay::hf_cand_2prong::DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, }; -} // namespace hf_chns_2prong +} // namespace hf_cand_2prong -namespace hf_chns_3prong +namespace hf_cand_3prong { -std::unordered_map> resoStatesDPlus = +std::unordered_map> resoStatesDPlus = { - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, + {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDPlus = +std::unordered_map> finalStatesDPlus = { - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± -std::unordered_map> resoStatesDs = -{ - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, +std::unordered_map> resoStatesDs = +{ + {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, + {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; -std::unordered_map> finalStatesDs = +std::unordered_map> finalStatesDs = { - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± -std::unordered_map> resoStatesDstar = -{ - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, +std::unordered_map> resoStatesDstar = +{ + {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDstar = +std::unordered_map> finalStatesDstar = { - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± -std::unordered_map> resoStatesLambdaC = +std::unordered_map> resoStatesLambdaC = { - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, + {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; -std::unordered_map> finalStatesLc = +std::unordered_map> finalStatesLc = { - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± -std::unordered_map> resoStatesXiC = +std::unordered_map> resoStatesXiC = { - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, + {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, }; -std::unordered_map> finalStatesXic = +std::unordered_map> finalStatesXic = { - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {o2::hf_decay::hf_cand_3prong::DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; -} // namespace hf_chns_3prong /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -std::unordered_map> getDecayChannel3Prong(int pdgMother) +std::unordered_map> getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: - return o2::hf_corrbkg::hf_chns_3prong::finalStatesDPlus; + return finalStatesDPlus; case o2::constants::physics::Pdg::kDS: - return o2::hf_corrbkg::hf_chns_3prong::finalStatesDs; + return finalStatesDs; case o2::constants::physics::Pdg::kDStar: - return o2::hf_corrbkg::hf_chns_3prong::finalStatesDstar; + return finalStatesDstar; case o2::constants::physics::Pdg::kLambdaCPlus: - return o2::hf_corrbkg::hf_chns_3prong::finalStatesLc; + return finalStatesLc; case o2::constants::physics::Pdg::kXiCPlus: - return o2::hf_corrbkg::hf_chns_3prong::finalStatesXic; + return finalStatesXic; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -171,25 +170,28 @@ std::unordered_map> getResoChannels3Prong(int pdgMother) +std::unordered_map> getResoChannels3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: - return o2::hf_corrbkg::hf_chns_3prong::resoStatesDPlus; + return resoStatesDPlus; case o2::constants::physics::Pdg::kDS: - return o2::hf_corrbkg::hf_chns_3prong::resoStatesDs; + return resoStatesDs; case o2::constants::physics::Pdg::kDStar: - return o2::hf_corrbkg::hf_chns_3prong::resoStatesDstar; + return resoStatesDstar; case o2::constants::physics::Pdg::kLambdaCPlus: - return o2::hf_corrbkg::hf_chns_3prong::resoStatesLambdaC; + return resoStatesLambdaC; case o2::constants::physics::Pdg::kXiCPlus: - return o2::hf_corrbkg::hf_chns_3prong::resoStatesXiC; + return resoStatesXiC; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; } } +} // namespace hf_cand_3prong + + /// Perform the matching for a single resonant channel /// \tparam N size of the array of daughter PDG codes /// \param arrPdgResoChn array of daughter indices @@ -225,9 +227,9 @@ template void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) { if constexpr (is3Prong) { - std::unordered_map> resoStates = getResoChannels3Prong(motherPdg); + std::unordered_map> resoStates = o2::hf_decay::hf_cand_3prong::getResoChannels3Prong(motherPdg); for (const auto& [flag, pdgCodes] : resoStates) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + if (o2::hf_decay::checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; break; } @@ -236,14 +238,14 @@ void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& if (motherPdg != o2::constants::physics::Pdg::kD0) { return; } - for (const auto& [flag, pdgCodes] : hf_chns_2prong::resoStatesD0) { - if (checkResonantDecay(arrDaughPdgs, pdgCodes)) { + for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { + if (o2::hf_decay::checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; break; } } } } -} // namespace o2::hf_corrbkg +} // namespace o2::hf_decay #endif // PWGHF_UTILS_UTILSMCMATCHING_H_ From a4a37c1651fecee0d09dc578a7104224e01be60e Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Thu, 12 Jun 2025 13:02:02 +0000 Subject: [PATCH 30/47] Please consider the following formatting changes --- PWGHF/Utils/utilsMcMatching.h | 145 +++++++++++++++++----------------- 1 file changed, 72 insertions(+), 73 deletions(-) diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 2aec406d7f6..415952a5fc7 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -30,20 +30,20 @@ namespace hf_cand_2prong { std::unordered_map> finalStates2Prongs = -{ - {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, + { + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; std::unordered_map> resoStatesD0 = -{ - {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + { + {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, }; } // namespace hf_cand_2prong @@ -52,97 +52,97 @@ namespace hf_cand_3prong { std::unordered_map> resoStatesDPlus = -{ - {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, + { + {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; std::unordered_map> finalStatesDPlus = -{ - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + { + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± std::unordered_map> resoStatesDs = -{ - {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, - {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, + { + {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, + {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; std::unordered_map> finalStatesDs = -{ - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + { + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± std::unordered_map> resoStatesDstar = -{ - {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, + { + {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; std::unordered_map> finalStatesDstar = -{ - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, + { + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± std::unordered_map> resoStatesLambdaC = -{ - {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, + { + {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; std::unordered_map> finalStatesLc = -{ - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; + { + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± std::unordered_map> resoStatesXiC = -{ - {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, + { + {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, }; std::unordered_map> finalStatesXic = -{ - {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, + { + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; /// Returns a map of the possible final states for a specific 3-prong particle specie @@ -191,7 +191,6 @@ std::unordered_map> getResoChanne } // namespace hf_cand_3prong - /// Perform the matching for a single resonant channel /// \tparam N size of the array of daughter PDG codes /// \param arrPdgResoChn array of daughter indices From 9d738108bc31e129be171c9ed67fac8f358a1c0d Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 13 Jun 2025 20:38:02 +0200 Subject: [PATCH 31/47] Implement Vit Comments --- PWGHF/Core/DecayChannels.h | 102 ++++----- .../TableProducer/candidateCreator2Prong.cxx | 2 +- PWGHF/Utils/utilsMcGen.h | 2 +- PWGHF/Utils/utilsMcMatching.h | 193 +++++++++--------- 4 files changed, 148 insertions(+), 151 deletions(-) diff --git a/PWGHF/Core/DecayChannels.h b/PWGHF/Core/DecayChannels.h index 745d017a644..986ad0b0c88 100644 --- a/PWGHF/Core/DecayChannels.h +++ b/PWGHF/Core/DecayChannels.h @@ -60,71 +60,71 @@ namespace hf_cand_3prong /// @brief 3-prong candidates: main channels enum DecayChannelMain : int8_t { // D+ - DplusToPiKPi = 1, // 1, π+ K− π+ - DplusToPiKPiPi0, // 2, π+ K− π+ π0 - DplusToPiPiPi, // 3, π+ π− π+ - DplusToPiKK, // 4, π+ K− K+ + DplusToPiKPi = 1, // π+ K− π+ + DplusToPiKPiPi0, // π+ K− π+ π0 + DplusToPiPiPi, // π+ π− π+ + DplusToPiKK, // π+ K− K+ // Ds+ - DsToPiKK, // 5, π+ K− K+ - DsToPiKKPi0, // 6, π+ K− K+ π0 - DsToPiPiK, // 7, π+ π− K+ - DsToPiPiPi, // 8, π+ π− π+ - DsToPiPiPiPi0, // 9, π+ π− π+ π0 + DsToPiKK, // π+ K− K+ + DsToPiKKPi0, // π+ K− K+ π0 + DsToPiPiK, // π+ π− K+ + DsToPiPiPi, // π+ π− π+ + DsToPiPiPiPi0, // π+ π− π+ π0 // D*+ - DstarToPiKPi, // 10, π+ K− π+ (from [(D0 → π+ K−) π+]) - DstarToPiKPiPi0, // 11, π+ K− π+ π0 - DstarToPiKPiPi0Pi0, // 12, π+ K− π+ π0 π0 - DstarToPiKK, // 13, π+ K− K+ - DstarToPiKKPi0, // 14, π+ K− K+ π0 - DstarToPiPiPi, // 15, π+ π− π+ - DstarToPiPiPiPi0, // 16, π+ π− π+ π0 + DstarToPiKPi, // π+ K− π+ (from [(D0 → π+ K−) π+]) + DstarToPiKPiPi0, // π+ K− π+ π0 + DstarToPiKPiPi0Pi0, // π+ K− π+ π0 π0 + DstarToPiKK, // π+ K− K+ + DstarToPiKKPi0, // π+ K− K+ π0 + DstarToPiPiPi, // π+ π− π+ + DstarToPiPiPiPi0, // π+ π− π+ π0 // Λc+ - LcToPKPi, // 17, p K− π+ - LcToPKPiPi0, // 18, p K− π+ π0 - LcToPPiPi, // 19, p π− π+ - LcToPKK, // 20, p K− K+ + LcToPKPi, // p K− π+ + LcToPKPiPi0, // p K− π+ π0 + LcToPPiPi, // p π− π+ + LcToPKK, // p K− K+ // Ξc+ - XicToPKPi, // 21, p K− π+ - XicToPKK, // 22, p K− K+ - XicToSPiPi, // 23, Σ+ π− π+ + XicToPKPi, // p K− π+ + XicToPKK, // p K− K+ + XicToSPiPi, // Σ+ π− π+ // LastChannelMain }; /// @brief 3-prong candidates: resonant channels enum DecayChannelResonant : int8_t { // D+ - DplusToPhiPi = 1, // 1, φ π+ - DplusToKstar0K, // 2, anti-K*0 K+ - DplusToKstar1430_0K, // 3, anti-K*0(1430) K+ - DplusToRho0Pi, // 4, ρ0 π+ - DplusToF2_1270Pi, // 5, f2(1270) π+ + DplusToPhiPi = 1, // φ π+ + DplusToKstar0K, // anti-K*0 K+ + DplusToKstar1430_0K, // anti-K*0(1430) K+ + DplusToRho0Pi, // ρ0 π+ + DplusToF2_1270Pi, // f2(1270) π+ // Ds+ - DsToPhiPi, // 6, φ π+ - DsToPhiRhoplus, // 7, φ ρ+ - DsToKstar0K, // 8, anti-K*0 K+ - DsToKstar0Pi, // 9, anti-K*0 π+ - DsToRho0Pi, // 10, ρ0 π+ - DsToRho0K, // 11, ρ0 K+ - DsToF2_1270Pi, // 12, f2(1270) π+ - DsToF0_1370K, // 13, f0(1370) K+ - DsToEtaPi, // 14, η π+ + DsToPhiPi, // φ π+ + DsToPhiRhoplus, // φ ρ+ + DsToKstar0K, // anti-K*0 K+ + DsToKstar0Pi, // anti-K*0 π+ + DsToRho0Pi, // ρ0 π+ + DsToRho0K, // ρ0 K+ + DsToF2_1270Pi, // f2(1270) π+ + DsToF0_1370K, // f0(1370) K+ + DsToEtaPi, // η π+ // D*+ - DstarToD0ToRhoplusPi, // 15, ρ+ π− - DstarToD0ToRhoplusK, // 16, ρ+ K− - DstarToD0ToKstar0Pi0, // 17, anti-K*0 π0 - DstarToD0ToKstarPi, // 18, K*− π+ - DstarToDplusToPhiPi, // 19, φ π+ - DstarToDplusToKstar0K, // 20, anti-K*0 K+ - DstarToDplusToKstar1430_0K, // 21, anti-K*0(1430) K+ - DstarToDplusToRho0Pi, // 22, ρ0 π+ - DstarToDplusToF2_1270Pi, // 23, f2(1270) π+ + DstarToD0ToRhoplusPi, // ρ+ π− + DstarToD0ToRhoplusK, // ρ+ K− + DstarToD0ToKstar0Pi0, // anti-K*0 π0 + DstarToD0ToKstarPi, // K*− π+ + DstarToDplusToPhiPi, // φ π+ + DstarToDplusToKstar0K, // anti-K*0 K+ + DstarToDplusToKstar1430_0K, // anti-K*0(1430) K+ + DstarToDplusToRho0Pi, // ρ0 π+ + DstarToDplusToF2_1270Pi, // f2(1270) π+ // Λc+ - LcToPKstar0, // 24, p K*0(892) - LcToDeltaplusplusK, // 25, Δ++ K− - LcToL1520Pi, // 26, Λ(1520) π+ + LcToPKstar0, // p K*0(892) + LcToDeltaplusplusK, // Δ++ K− + LcToL1520Pi, // Λ(1520) π+ // Ξc+ - XicToPKstar0, // 27, p anti-K*0(892) - XicToPPhi, // 28, p φ + XicToPKstar0, // p anti-K*0(892) + XicToPPhi, // p φ // LastChannelResonant }; diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 1667e8e5ec0..80fc2c8ba57 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -779,7 +779,7 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { indexRec = -1; // Index of the matched reconstructed candidate int depth = 2; - for (const auto& [chn, finalState] : hf_cand_2prong::finalStates2Prongs) { + for (const auto& [chn, finalState] : hf_cand_2prong::DaughtersD0Main) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; if (finalState.size() == 3) { // Partly Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 7b1787a85db..7c4b1fcbba9 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -57,7 +57,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matchCorrBkgs) { bool matched = false; - for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::finalStates2Prongs) { + for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::DaughtersD0Main) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; if (particle.pdgCode() < 0) { diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 415952a5fc7..1328d27e5a0 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -16,34 +16,41 @@ #ifndef PWGHF_UTILS_UTILSMCMATCHING_H_ #define PWGHF_UTILS_UTILSMCMATCHING_H_ +#include "PWGHF/Core/DecayChannels.h" + +// O2 includes +#include +#include + +// ROOT includes +#include + +// C++ includes #include +#include #include #include #include -#include "PWGHF/Core/DecayChannels.h" - namespace o2::hf_decay { namespace hf_cand_2prong { -std::unordered_map> finalStates2Prongs = - { - {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, - {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, +static const std::unordered_map> DaughtersD0Main{ + {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, + {DecayChannelMain::D0ToPiPiPi0, {+kPiMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; -std::unordered_map> resoStatesD0 = - { - {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, +static const std::unordered_map> DaughtersD0Resonant{ + {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::D0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, }; } // namespace hf_cand_2prong @@ -51,116 +58,106 @@ std::unordered_map> resoStatesD0 namespace hf_cand_3prong { -std::unordered_map> resoStatesDPlus = - { - {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, +static const std::unordered_map> DaughtersDPlusResonant{ + {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDPlus = - { - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +static const std::unordered_map> DaughtersDPlusMain{ + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, }; // Ds± → K± K∓ π± -std::unordered_map> resoStatesDs = - { - {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, - {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, - {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, - {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, - {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, - {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, +static const std::unordered_map> DaughtersDsResonant{ + {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, + {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DsToKstar0Pi, {+o2::constants::physics::kK0Star892, +kPiPlus}}, + {DecayChannelResonant::DsToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DsToRho0K, {+kRho770_0, +kKPlus}}, + {DecayChannelResonant::DsToF2_1270Pi, {225, +kPiPlus}}, + {DecayChannelResonant::DsToF0_1370K, {10221, +kKPlus}}, + {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; -std::unordered_map> finalStatesDs = - { - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +static const std::unordered_map> DaughtersDsMain{ + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Dstar → K± K∓ π± -std::unordered_map> resoStatesDstar = - { - {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, - {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, - {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, - {DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, - {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, - {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, +static const std::unordered_map> DaughtersDstarResonant{ + {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, + {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, + {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, + {DecayChannelResonant::DstarToD0ToKstarPi, {-o2::constants::physics::kKPlusStar892, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToKstar1430_0K, {+10311, +kKPlus}}, + {DecayChannelResonant::DstarToDplusToRho0Pi, {+kRho770_0, +kPiPlus}}, + {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; -std::unordered_map> finalStatesDstar = - { - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +static const std::unordered_map> DaughtersDstarMain{ + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; // Lc → p K∓ π± -std::unordered_map> resoStatesLambdaC = - { - {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, - {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, - {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, +static const std::unordered_map> DaughtersLcResonant{ + {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, + {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; -std::unordered_map> finalStatesLc = - { - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; +static const std::unordered_map> DaughtersLcMain{ + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; // Xic → p K∓ π± -std::unordered_map> resoStatesXiC = - { - {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, +static const std::unordered_map> DaughtersXiCResonant{ + {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, }; -std::unordered_map> finalStatesXic = - { - {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, - {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, +static const std::unordered_map> DaughtersXiCMain{ + {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, + {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -std::unordered_map> getDecayChannel3Prong(int pdgMother) +static const std::unordered_map> getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: - return finalStatesDPlus; + return DaughtersDPlusMain; case o2::constants::physics::Pdg::kDS: - return finalStatesDs; + return DaughtersDsMain; case o2::constants::physics::Pdg::kDStar: - return finalStatesDstar; + return DaughtersDstarMain; case o2::constants::physics::Pdg::kLambdaCPlus: - return finalStatesLc; + return DaughtersLcMain; case o2::constants::physics::Pdg::kXiCPlus: - return finalStatesXic; + return DaughtersXiCMain; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -174,15 +171,15 @@ std::unordered_map> getResoChanne { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: - return resoStatesDPlus; + return DaughtersDPlusResonant; case o2::constants::physics::Pdg::kDS: - return resoStatesDs; + return DaughtersDsResonant; case o2::constants::physics::Pdg::kDStar: - return resoStatesDstar; + return DaughtersDstarResonant; case o2::constants::physics::Pdg::kLambdaCPlus: - return resoStatesLambdaC; + return DaughtersLcResonant; case o2::constants::physics::Pdg::kXiCPlus: - return resoStatesXiC; + return DaughtersXiCResonant; default: LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; @@ -237,7 +234,7 @@ void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& if (motherPdg != o2::constants::physics::Pdg::kD0) { return; } - for (const auto& [flag, pdgCodes] : hf_cand_2prong::resoStatesD0) { + for (const auto& [flag, pdgCodes] : hf_cand_2prong::DaughtersD0Resonant) { if (o2::hf_decay::checkResonantDecay(arrDaughPdgs, pdgCodes)) { *channel = flag; break; From 5139e4f29ae3873a154ec81a887179107dc797a8 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 09:08:00 +0200 Subject: [PATCH 32/47] Mark functions in header as inline --- PWGHF/Utils/utilsMcMatching.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 1328d27e5a0..70b8445e828 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -18,14 +18,11 @@ #include "PWGHF/Core/DecayChannels.h" -// O2 includes #include #include -// ROOT includes #include -// C++ includes #include #include #include @@ -145,7 +142,7 @@ static const std::unordered_map> Daught /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -static const std::unordered_map> getDecayChannel3Prong(int pdgMother) +inline std::unordered_map> getDecayChannel3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: @@ -167,7 +164,7 @@ static const std::unordered_map> getDec /// Returns a map of the resonant decay channels for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of resonant decay channels with their corresponding PDG codes -std::unordered_map> getResoChannels3Prong(int pdgMother) +inline std::unordered_map> getResoChannels3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: @@ -194,7 +191,7 @@ std::unordered_map> getResoChanne /// \param arrPdgDaugs array of PDG codes for the resonant decay /// \return true if the resonant channel is matched, false otherwise template -bool checkResonantDecay(std::array const& arrPdgResoChn, std::array arrPdgDaugs) +inline bool checkResonantDecay(std::array const& arrPdgResoChn, std::array arrPdgDaugs) { for (std::size_t i = 0; i < N; i++) { bool findDaug = false; @@ -220,7 +217,7 @@ bool checkResonantDecay(std::array const& arrPdgResoChn, std::array -void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) +inline void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) { if constexpr (is3Prong) { std::unordered_map> resoStates = o2::hf_decay::hf_cand_3prong::getResoChannels3Prong(motherPdg); From fc47508167649ce145f8e1d3758bde3b4576e985 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 17:39:14 +0200 Subject: [PATCH 33/47] Rename variables and adjust map ordering --- .../TableProducer/candidateCreator2Prong.cxx | 36 +++--- .../TableProducer/candidateCreator3Prong.cxx | 8 +- PWGHF/Utils/utilsMcGen.h | 32 +++--- PWGHF/Utils/utilsMcMatching.h | 104 +++++++++--------- 4 files changed, 88 insertions(+), 92 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 80fc2c8ba57..ed80b4196fe 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -778,46 +778,42 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { indexRec = -1; // Index of the matched reconstructed candidate - int depth = 2; - for (const auto& [chn, finalState] : hf_cand_2prong::DaughtersD0Main) { + constexpr int FinalStateDepth = 2; + constexpr int ResoDepth = 1; + + // D0(bar) → π+ K−, π+ K− π0, π+ π−, π+ π− π0, K+ K− + for (const auto& [chn, finalState] : hf_cand_2prong::daughtersD0Main) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; if (finalState.size() == 3) { // Partly Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth); } if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; - if (motherParticle.pdgCode() < 0) { - for (auto& part : finalStateParts2ProngAll) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } - if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, depth)) { + if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, FinalStateDepth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } } else if (finalState.size() == 2) { // Fully Reco 2-prong decays if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, &nKinkedTracks); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks); } else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth, nullptr, &nInteractionsWithMaterial); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, nullptr, &nInteractionsWithMaterial); } else { - indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, depth); + indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth); } } else { - LOG(info) << "Final state size not supported: " << finalStateParts2Prong.size(); + LOG(fatal) << "Final state size not supported: " << finalState.size(); continue; } if (indexRec > -1) { @@ -826,7 +822,7 @@ struct HfCandidateCreator2ProngExpressions { // Flag the resonant decay channel int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, ResoDepth); std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 28b64e5e0ab..e2e187569a1 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -949,11 +949,13 @@ struct HfCandidateCreator3ProngExpressions { if (matchCorrBkgs) { indexRec = -1; // Index of the matched reconstructed candidate + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching for (const auto& pdg : mothersCorrBkgsPdgs.value) { - int depth = 2; + int depth = MaxDepth; if (pdg == Pdg::kDStar) { - depth = 3; // D0 resonant decays are active + depth = MaxDepth+1; // D0 resonant decays are active } auto finalStates = getDecayChannel3Prong(pdg); for (const auto& [chn, finalState] : finalStates) { @@ -1008,7 +1010,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth); } } else { - LOG(info) << "Final state size not supported: " << finalState.size(); + LOG(fatal) << "Final state size not supported: " << finalState.size(); continue; // Skip unsupported final states } if (indexRec > -1) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 7c4b1fcbba9..516499c218b 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -55,22 +55,17 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matchCorrBkgs) { + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching bool matched = false; - for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::DaughtersD0Main) { + for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } - matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); } else if (finalState.size() == 2) { // Fully Reco 2-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1]}; - matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, maxDepth); + matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); } else { LOG(info) << "Final state size not supported: " << finalState.size(); continue; @@ -81,7 +76,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V // Flag the resonant decay channel int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; - RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) { @@ -157,11 +152,14 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (std::abs(particle.pdgCode()) != motherPdgCode) { continue; // Skip if the particle PDG code does not match the mother PDG code } - auto finalStates = o2::hf_decay::hf_cand_3prong::getDecayChannel3Prong(motherPdgCode); - int maxDepth = 2; + auto finalStates = o2::hf_decay::hf_cand_3prong::getDecayChannelMain(motherPdgCode); + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching + + int maxDepth = MaxDepth; bool matched = false; if (motherPdgCode == Pdg::kDStar) { - maxDepth = 3; // D0 resonant decays are switched on + maxDepth = MaxDepth+1; // D0 resonant decays are switched on } std::vector arrAllDaughtersIndex; @@ -203,18 +201,18 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V std::vector arrResoDaughIndex = {}; if (std::abs(motherPdgCode) == Pdg::kDStar) { std::vector arrResoDaughIndexDStar = {}; - RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, resoMaxDepth); + RecoDecay::getDaughters(particle, &arrResoDaughIndexDStar, std::array{0}, ResoMaxDepth); for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { auto daughDstar = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); if (std::abs(daughDstar.pdgCode()) == Pdg::kD0 || std::abs(daughDstar.pdgCode()) == Pdg::kDPlus) { - RecoDecay::getDaughters(daughDstar, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + RecoDecay::getDaughters(daughDstar, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); break; } else { LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; } } } else { - RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, resoMaxDepth); + RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); } std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 70b8445e828..81d57dbf7b2 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -35,7 +35,7 @@ namespace o2::hf_decay namespace hf_cand_2prong { -static const std::unordered_map> DaughtersD0Main{ +static const std::unordered_map> daughtersD0Main{ {DecayChannelMain::D0ToPiK, {+kKMinus, +kPiPlus}}, {DecayChannelMain::D0ToPiKPi0, {+kKMinus, +kPiPlus, +kPi0}}, {DecayChannelMain::D0ToPiPi, {+kPiMinus, +kPiPlus}}, @@ -43,7 +43,7 @@ static const std::unordered_map> Daught {DecayChannelMain::D0ToKK, {+kKMinus, +kKPlus}}, }; -static const std::unordered_map> DaughtersD0Resonant{ +static const std::unordered_map> daughtersD0Resonant{ {DecayChannelResonant::D0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, {DecayChannelResonant::D0ToRhoplusK, {+kRho770Plus, +kKMinus}}, {DecayChannelResonant::D0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, @@ -55,7 +55,15 @@ static const std::unordered_map> namespace hf_cand_3prong { -static const std::unordered_map> DaughtersDPlusResonant{ +// D± +static const std::unordered_map> daughtersDplusMain{ + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + }; + +static const std::unordered_map> daughtersDplusResonant{ {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, {DecayChannelResonant::DplusToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, {DecayChannelResonant::DplusToKstar1430_0K, {+10311, +kKPlus}}, @@ -63,15 +71,16 @@ static const std::unordered_map> {DecayChannelResonant::DplusToF2_1270Pi, {+225, +kPiPlus}}, }; -static const std::unordered_map> DaughtersDPlusMain{ - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +// Ds± +static const std::unordered_map> daughtersDsMain{ + {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, + {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; -// Ds± → K± K∓ π± -static const std::unordered_map> DaughtersDsResonant{ +static const std::unordered_map> daughtersDsResonant{ {DecayChannelResonant::DsToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, {DecayChannelResonant::DsToPhiRhoplus, {+o2::constants::physics::kPhi, +kRho770Plus}}, {DecayChannelResonant::DsToKstar0K, {-o2::constants::physics::kK0Star892, +kKPlus}}, @@ -83,16 +92,18 @@ static const std::unordered_map> {DecayChannelResonant::DsToEtaPi, {221, +kPiPlus}}, }; -static const std::unordered_map> DaughtersDsMain{ - {DecayChannelMain::DsToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DsToPiPiK, {+kKPlus, +kPiPlus, +kPiMinus}}, - {DecayChannelMain::DsToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DsToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +// Dstar +static const std::unordered_map> daughtersDstarMain{ + {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, + {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, }; -// Dstar → K± K∓ π± -static const std::unordered_map> DaughtersDstarResonant{ +static const std::unordered_map> daughtersDstarResonant{ {DecayChannelResonant::DstarToD0ToRhoplusPi, {+kRho770Plus, +kPiMinus}}, {DecayChannelResonant::DstarToD0ToRhoplusK, {+kRho770Plus, +kKMinus}}, {DecayChannelResonant::DstarToD0ToKstar0Pi0, {-o2::constants::physics::kK0Star892, +kPi0}}, @@ -104,67 +115,56 @@ static const std::unordered_map> {DecayChannelResonant::DstarToDplusToF2_1270Pi, {+225, +kPiPlus}}, }; -static const std::unordered_map> DaughtersDstarMain{ - {DecayChannelMain::DstarToPiKPi, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiKPiPi0Pi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0, +kPi0}}, - {DecayChannelMain::DstarToPiKK, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiKKPi0, {+kKMinus, +kKPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DstarToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DstarToPiPiPiPi0, {+kPiMinus, +kPiPlus, +kPiPlus, +kPi0}}, +// Lc +static const std::unordered_map> daughtersLcMain{ + {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, + {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}} }; -// Lc → p K∓ π± -static const std::unordered_map> DaughtersLcResonant{ +static const std::unordered_map> daughtersLcResonant{ {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, {DecayChannelResonant::LcToDeltaplusplusK, {+2224, +kKMinus}}, {DecayChannelResonant::LcToL1520Pi, {+102134, +kPiPlus}}, }; -static const std::unordered_map> DaughtersLcMain{ - {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, - {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; - -// Xic → p K∓ π± -static const std::unordered_map> DaughtersXiCResonant{ - {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, - {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, -}; - -static const std::unordered_map> DaughtersXiCMain{ +// Xic +static const std::unordered_map> daughtersXicMain{ {DecayChannelMain::XicToPKPi, {+kProton, +kKMinus, +kPiPlus}}, {DecayChannelMain::XicToPKK, {+kProton, +kKMinus, +kKPlus}}, {DecayChannelMain::XicToSPiPi, {+kSigmaPlus, +kPiMinus, +kPiPlus}}, }; +static const std::unordered_map> daughtersXicResonant{ + {DecayChannelResonant::XicToPKstar0, {-o2::constants::physics::kK0Star892, +kProton}}, + {DecayChannelResonant::XicToPPhi, {+kProton, +o2::constants::physics::kPhi}}, +}; + /// Returns a map of the possible final states for a specific 3-prong particle specie /// \param pdgMother PDG code of the mother particle /// \return a map of final states with their corresponding PDG codes -inline std::unordered_map> getDecayChannel3Prong(int pdgMother) +inline std::unordered_map> getDecayChannelMain(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: - return DaughtersDPlusMain; + return daughtersDplusMain; case o2::constants::physics::Pdg::kDS: - return DaughtersDsMain; + return daughtersDsMain; case o2::constants::physics::Pdg::kDStar: - return DaughtersDstarMain; + return daughtersDstarMain; case o2::constants::physics::Pdg::kLambdaCPlus: - return DaughtersLcMain; + return daughtersLcMain; case o2::constants::physics::Pdg::kXiCPlus: - return DaughtersXiCMain; + return daughtersXicMain; default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; + LOG(fatal) << "Unknown PDG code for 3-prong final states: " << pdgMother; return {}; } } +} // namespace hf_cand_3prong + -/// Returns a map of the resonant decay channels for a specific 3-prong particle specie -/// \param pdgMother PDG code of the mother particle -/// \return a map of resonant decay channels with their corresponding PDG codes -inline std::unordered_map> getResoChannels3Prong(int pdgMother) { switch (pdgMother) { case o2::constants::physics::Pdg::kDPlus: From ddc75d2759c7afe065e0be8aaf157d869667dfd3 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 21:22:56 +0200 Subject: [PATCH 34/47] Factorize function to change Pi0 sign for antiparticles --- .../TableProducer/candidateCreator2Prong.cxx | 4 +- .../TableProducer/candidateCreator3Prong.cxx | 37 +++---- PWGHF/Utils/utilsMcGen.h | 28 ++--- PWGHF/Utils/utilsMcMatching.h | 101 +++++++++++------- 4 files changed, 88 insertions(+), 82 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index ed80b4196fe..fb89f849976 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -798,6 +798,7 @@ struct HfCandidateCreator2ProngExpressions { if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; + convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts2ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, FinalStateDepth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } @@ -820,7 +821,6 @@ struct HfCandidateCreator2ProngExpressions { flag = sign * (1 << chn); // Flag the resonant decay channel - int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, ResoDepth); std::array arrPDGDaugh = {}; @@ -829,7 +829,7 @@ struct HfCandidateCreator2ProngExpressions { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); + channel = flagResonantDecay(Pdg::kD0, arrPDGDaugh); } break; } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index e2e187569a1..19ce53e595f 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -957,7 +957,7 @@ struct HfCandidateCreator3ProngExpressions { if (pdg == Pdg::kDStar) { depth = MaxDepth+1; // D0 resonant decays are active } - auto finalStates = getDecayChannel3Prong(pdg); + auto finalStates = getDecayChannelMain(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; if (finalState.size() > 3) { // Partly Reco 4-prong decays @@ -975,25 +975,13 @@ struct HfCandidateCreator3ProngExpressions { auto motherParticle = mcParticles.rawIteratorAt(indexRec); if (finalState.size() == 4) { // Check if the final state has 4 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - if (sign < 0) { - for (auto& part : finalStateParts3ProngAll) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } + convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } } else if (finalState.size() == 5) { // Check if the final state has 5 particles std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; - if (sign < 0) { - for (auto& part : finalStateParts3ProngAll) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } + convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } @@ -1017,19 +1005,26 @@ struct HfCandidateCreator3ProngExpressions { flag = sign * chn; // Flag the resonant decay channel - int resoMaxDepth = 1; - if (std::abs(mcParticles.rawIteratorAt(indexRec).pdgCode()) == Pdg::kDStar) { - resoMaxDepth = 2; // Flag D0 resonances - } std::vector arrResoDaughIndex = {}; - RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, resoMaxDepth); + if (pdg == Pdg::kDStar) { + std::vector arrResoDaughIndexDStar = {}; + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndexDStar, std::array{0}, ResoMaxDepth); + for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { + auto daughDstar = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); + if (std::abs(daughDstar.pdgCode()) == Pdg::kD0 || std::abs(daughDstar.pdgCode()) == Pdg::kDPlus) { + break; + } + } + } else { + RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, ResoMaxDepth); + } std::array arrPDGDaugh = {}; if (arrResoDaughIndex.size() == NDaughtersResonant) { for (auto iProng = 0u; iProng < NDaughtersResonant; ++iProng) { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - flagResonantDecay(pdg, &channel, arrPDGDaugh); + channel = flagResonantDecay(pdg, arrPDGDaugh); } break; // Exit loop if a match is found } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 516499c218b..e89ca3c789b 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -42,7 +42,6 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V constexpr std::size_t NDaughtersResonant{2u}; // Match generated particles. - int maxDepth = 2; // Default depth for matching for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; @@ -62,6 +61,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) { if (finalState.size() == 3) { // Partly Reco 3-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; + o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); } else if (finalState.size() == 2) { // Fully Reco 2-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1]}; @@ -74,7 +74,6 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V flag = sign * (1 << chn); // Flag the resonant decay channel - int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; RecoDecay::getDaughters(particle, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); std::array arrPDGDaugh = {}; @@ -83,7 +82,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - o2::hf_decay::flagResonantDecay(Pdg::kD0, &channel, arrPDGDaugh); + channel = o2::hf_decay::flagResonantDecay(Pdg::kD0, arrPDGDaugh); } break; } @@ -164,26 +163,14 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V std::vector arrAllDaughtersIndex; for (const auto& [chn, finalState] : finalStates) { - if (finalState.size() == 5) { // Partly Reco 3-prong decays + if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; - if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } + o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 4) { // Partly Reco 3-prong decays + } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - if (particle.pdgCode() < 0) { - for (auto& part : finalStateParts) { - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } - } - } + o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 3) { // Fully Reco 3-prong decays @@ -197,7 +184,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (matched) { flag = sign * chn; // Flag the resonant decay channel - int resoMaxDepth = 1; std::vector arrResoDaughIndex = {}; if (std::abs(motherPdgCode) == Pdg::kDStar) { std::vector arrResoDaughIndexDStar = {}; @@ -220,7 +206,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - o2::hf_decay::flagResonantDecay(motherPdgCode, &channel, arrPDGDaugh); + channel = o2::hf_decay::flagResonantDecay(motherPdgCode, arrPDGDaugh); } break; // Exit loop if a match is found } diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 81d57dbf7b2..9849653ec08 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -164,34 +164,13 @@ inline std::unordered_map> getDecayChan } } // namespace hf_cand_3prong - -{ - switch (pdgMother) { - case o2::constants::physics::Pdg::kDPlus: - return DaughtersDPlusResonant; - case o2::constants::physics::Pdg::kDS: - return DaughtersDsResonant; - case o2::constants::physics::Pdg::kDStar: - return DaughtersDstarResonant; - case o2::constants::physics::Pdg::kLambdaCPlus: - return DaughtersLcResonant; - case o2::constants::physics::Pdg::kXiCPlus: - return DaughtersXiCResonant; - default: - LOG(error) << "Unknown PDG code for 3-prong final states: " << pdgMother; - return {}; - } -} - -} // namespace hf_cand_3prong - /// Perform the matching for a single resonant channel /// \tparam N size of the array of daughter PDG codes /// \param arrPdgResoChn array of daughter indices /// \param arrPdgDaugs array of PDG codes for the resonant decay /// \return true if the resonant channel is matched, false otherwise template -inline bool checkResonantDecay(std::array const& arrPdgResoChn, std::array arrPdgDaugs) +inline bool checkDecayChannel(std::array const& arrPdgResoChn, std::array arrPdgDaugs) { for (std::size_t i = 0; i < N; i++) { bool findDaug = false; @@ -217,24 +196,70 @@ inline bool checkResonantDecay(std::array const& arrPdgResoChn, std::arr /// \param channel decay channel flag to be set /// \param arrDaughPdgs array of daughter PDG codes template -inline void flagResonantDecay(int motherPdg, int8_t* channel, std::array const& arrDaughPdgs) +inline int8_t flagResonantDecay(int motherPdg, std::array const& arrDaughPdgs) { - if constexpr (is3Prong) { - std::unordered_map> resoStates = o2::hf_decay::hf_cand_3prong::getResoChannels3Prong(motherPdg); - for (const auto& [flag, pdgCodes] : resoStates) { - if (o2::hf_decay::checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; + switch (motherPdg) { + case o2::constants::physics::Pdg::kD0: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_2prong::daughtersD0Resonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } } - } - } else { - if (motherPdg != o2::constants::physics::Pdg::kD0) { - return; - } - for (const auto& [flag, pdgCodes] : hf_cand_2prong::DaughtersD0Resonant) { - if (o2::hf_decay::checkResonantDecay(arrDaughPdgs, pdgCodes)) { - *channel = flag; - break; + break; + case o2::constants::physics::Pdg::kDPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::daughtersDplusResonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } + } + break; + case o2::constants::physics::Pdg::kDS: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::daughtersDsResonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } + } + break; + case o2::constants::physics::Pdg::kDStar: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::daughtersDstarResonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } + } + break; + case o2::constants::physics::Pdg::kLambdaCPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::daughtersLcResonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } + } + break; + case o2::constants::physics::Pdg::kXiCPlus: + for (const auto& [flag, pdgCodes] : o2::hf_decay::hf_cand_3prong::daughtersXicResonant) { + if (o2::hf_decay::checkDecayChannel(arrDaughPdgs, pdgCodes)) { + return flag; + } + } + break; + default: + LOG(fatal) << "Unknown PDG code for 3-prong final states: " << motherPdg; + return {}; + } + return 0; +} + +/// Convert Pi0 to AntiPi0 in the array of PDG codes for antiparticles since +/// the Pi0s stemming from antiparticle decays keep the pdg code 111. +/// \tparam N size of the array of PDG codes +/// \param partPdgCode PDG code of the particle +/// \param arrPdgIndexes array of PDG codes to be modified +template +inline void convertPi0ToAntiPi0(const int partPdgCode, std::array& arrPdgIndexes) +{ + if (partPdgCode < 0) { + for (auto& part : arrPdgIndexes) { // o2-linter: disable=const-ref-in-for-loop (int elements) + if (part == kPi0) { + part = -part; // The Pi0 pdg code does not change between particle and antiparticle } } } From e49fa7afe25d0f27bc8c16ae9952999d3b741331 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Tue, 17 Jun 2025 19:25:46 +0000 Subject: [PATCH 35/47] Please consider the following formatting changes --- .../TableProducer/candidateCreator2Prong.cxx | 47 ++++++++-------- .../TableProducer/candidateCreator3Prong.cxx | 55 +++++++++---------- PWGHF/Utils/utilsMcGen.h | 29 +++++----- PWGHF/Utils/utilsMcMatching.h | 15 +++-- 4 files changed, 72 insertions(+), 74 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index fb89f849976..c161b0d72fb 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -20,41 +20,40 @@ #define HomogeneousField // o2-linter: disable=name/macro (required by KFParticle) #endif -#include -#include -#include - -#include -#include -#include -#include -#include +#include "PWGHF/Core/CentralityEstimation.h" +#include "PWGHF/Core/DecayChannels.h" +#include "PWGHF/Core/SelectorCuts.h" +#include "PWGHF/DataModel/CandidateReconstructionTables.h" +#include "PWGHF/Utils/utilsBfieldCCDB.h" +#include "PWGHF/Utils/utilsEvSelHf.h" +#include "PWGHF/Utils/utilsMcGen.h" +#include "PWGHF/Utils/utilsMcMatching.h" +#include "PWGHF/Utils/utilsPid.h" +#include "PWGHF/Utils/utilsTrkCandHf.h" +#include "PWGLF/DataModel/mcCentrality.h" -#include +#include "Common/Core/trackUtilities.h" +#include "Tools/KFparticle/KFUtilities.h" #include "CommonConstants/PhysicsConstants.h" #include "DCAFitter/DCAFitterN.h" #include "Framework/AnalysisTask.h" #include "Framework/HistogramRegistry.h" -#include "Framework/runDataProcessing.h" #include "Framework/RunningWorkflowInfo.h" +#include "Framework/runDataProcessing.h" #include "ReconstructionDataFormats/DCA.h" -#include "Common/Core/trackUtilities.h" -#include "Tools/KFparticle/KFUtilities.h" +#include -#include "PWGLF/DataModel/mcCentrality.h" +#include +#include +#include +#include +#include -#include "PWGHF/Core/CentralityEstimation.h" -#include "PWGHF/Core/SelectorCuts.h" -#include "PWGHF/Core/DecayChannels.h" -#include "PWGHF/DataModel/CandidateReconstructionTables.h" -#include "PWGHF/Utils/utilsBfieldCCDB.h" -#include "PWGHF/Utils/utilsEvSelHf.h" -#include "PWGHF/Utils/utilsMcGen.h" -#include "PWGHF/Utils/utilsPid.h" -#include "PWGHF/Utils/utilsTrkCandHf.h" -#include "PWGHF/Utils/utilsMcMatching.h" +#include +#include +#include using namespace o2; using namespace o2::analysis; diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 19ce53e595f..e8d47fc19d9 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -19,41 +19,40 @@ #define HomogeneousField // o2-linter: disable=name/macro (required by KFParticle) #endif -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include "PWGHF/Core/CentralityEstimation.h" +#include "PWGHF/Core/DecayChannels.h" +#include "PWGHF/DataModel/CandidateReconstructionTables.h" +#include "PWGHF/Utils/utilsBfieldCCDB.h" +#include "PWGHF/Utils/utilsEvSelHf.h" +#include "PWGHF/Utils/utilsMcGen.h" +#include "PWGHF/Utils/utilsMcMatching.h" +#include "PWGHF/Utils/utilsPid.h" +#include "PWGHF/Utils/utilsTrkCandHf.h" +#include "PWGLF/DataModel/mcCentrality.h" -#include +#include "Common/Core/trackUtilities.h" +#include "Tools/KFparticle/KFUtilities.h" #include "CommonConstants/PhysicsConstants.h" #include "DCAFitter/DCAFitterN.h" #include "Framework/AnalysisTask.h" #include "Framework/HistogramRegistry.h" -#include "Framework/runDataProcessing.h" #include "Framework/RunningWorkflowInfo.h" +#include "Framework/runDataProcessing.h" #include "ReconstructionDataFormats/DCA.h" -#include "Common/Core/trackUtilities.h" -#include "Tools/KFparticle/KFUtilities.h" +#include -#include "PWGLF/DataModel/mcCentrality.h" +#include +#include +#include +#include +#include -#include "PWGHF/Core/CentralityEstimation.h" -#include "PWGHF/Core/DecayChannels.h" -#include "PWGHF/DataModel/CandidateReconstructionTables.h" -#include "PWGHF/Utils/utilsBfieldCCDB.h" -#include "PWGHF/Utils/utilsEvSelHf.h" -#include "PWGHF/Utils/utilsMcGen.h" -#include "PWGHF/Utils/utilsPid.h" -#include "PWGHF/Utils/utilsTrkCandHf.h" -#include "PWGHF/Utils/utilsMcMatching.h" +#include +#include +#include +#include using namespace o2; using namespace o2::hf_evsel; @@ -948,14 +947,14 @@ struct HfCandidateCreator3ProngExpressions { } if (matchCorrBkgs) { - indexRec = -1; // Index of the matched reconstructed candidate - constexpr int MaxDepth = 2; // Depth for final state matching - constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching + indexRec = -1; // Index of the matched reconstructed candidate + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching for (const auto& pdg : mothersCorrBkgsPdgs.value) { int depth = MaxDepth; if (pdg == Pdg::kDStar) { - depth = MaxDepth+1; // D0 resonant decays are active + depth = MaxDepth + 1; // D0 resonant decays are active } auto finalStates = getDecayChannelMain(pdg); for (const auto& [chn, finalState] : finalStates) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index e89ca3c789b..4ba17f29cc8 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -17,21 +17,22 @@ #ifndef PWGHF_UTILS_UTILSMCGEN_H_ #define PWGHF_UTILS_UTILSMCGEN_H_ -#include -#include +#include "PWGHF/Core/DecayChannels.h" +#include "PWGHF/DataModel/CandidateReconstructionTables.h" +#include "PWGHF/Utils/utilsMcMatching.h" + +#include "Common/Core/RecoDecay.h" #include +#include + +#include + #include #include #include -#include "Common/Core/RecoDecay.h" - -#include "PWGHF/Core/DecayChannels.h" -#include "PWGHF/DataModel/CandidateReconstructionTables.h" -#include "PWGHF/Utils/utilsMcMatching.h" - namespace hf_mc_gen { @@ -54,8 +55,8 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } if (matchCorrBkgs) { - constexpr int MaxDepth = 2; // Depth for final state matching - constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching bool matched = false; for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) { @@ -152,13 +153,13 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; // Skip if the particle PDG code does not match the mother PDG code } auto finalStates = o2::hf_decay::hf_cand_3prong::getDecayChannelMain(motherPdgCode); - constexpr int MaxDepth = 2; // Depth for final state matching - constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching + constexpr int MaxDepth = 2; // Depth for final state matching + constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching int maxDepth = MaxDepth; bool matched = false; if (motherPdgCode == Pdg::kDStar) { - maxDepth = MaxDepth+1; // D0 resonant decays are switched on + maxDepth = MaxDepth + 1; // D0 resonant decays are switched on } std::vector arrAllDaughtersIndex; @@ -170,7 +171,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); + o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 3) { // Fully Reco 3-prong decays diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 9849653ec08..3c93ef36321 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -57,11 +57,11 @@ namespace hf_cand_3prong // D± static const std::unordered_map> daughtersDplusMain{ - {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, - {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, - {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, - }; + {DecayChannelMain::DplusToPiKPi, {+kKMinus, +kKPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKK, {+kKMinus, +kPiPlus, +kPiPlus}}, + {DecayChannelMain::DplusToPiKPiPi0, {+kKMinus, +kPiPlus, +kPiPlus, +kPi0}}, + {DecayChannelMain::DplusToPiPiPi, {+kPiMinus, +kPiPlus, +kPiPlus}}, +}; static const std::unordered_map> daughtersDplusResonant{ {DecayChannelResonant::DplusToPhiPi, {+o2::constants::physics::kPhi, +kPiPlus}}, @@ -120,8 +120,7 @@ static const std::unordered_map> daught {DecayChannelMain::LcToPKPi, {+kProton, +kKMinus, +kPiPlus}}, {DecayChannelMain::LcToPKPiPi0, {+kProton, +kKMinus, +kPiPlus, +kPi0}}, {DecayChannelMain::LcToPPiPi, {+kProton, +kPiMinus, +kPiPlus}}, - {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}} -}; + {DecayChannelMain::LcToPKK, {+kProton, +kKMinus, +kKPlus}}}; static const std::unordered_map> daughtersLcResonant{ {DecayChannelResonant::LcToPKstar0, {+o2::constants::physics::kK0Star892, +kProton}}, @@ -257,7 +256,7 @@ template inline void convertPi0ToAntiPi0(const int partPdgCode, std::array& arrPdgIndexes) { if (partPdgCode < 0) { - for (auto& part : arrPdgIndexes) { // o2-linter: disable=const-ref-in-for-loop (int elements) + for (auto& part : arrPdgIndexes) { // o2-linter: disable=const-ref-in-for-loop (int elements) if (part == kPi0) { part = -part; // The Pi0 pdg code does not change between particle and antiparticle } From 9d7709bb67aa3bc3187b40fa0fd3e7d4598ecc57 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 21:56:25 +0200 Subject: [PATCH 36/47] Re-trigger tests --- PWGHF/Utils/utilsMcGen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 4ba17f29cc8..fc3684a4401 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -170,7 +170,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); From 0caac1710fdd3cae8956c211b11547291271bde2 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Tue, 17 Jun 2025 19:58:45 +0000 Subject: [PATCH 37/47] Please consider the following formatting changes --- PWGHF/Utils/utilsMcGen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index fc3684a4401..4ba17f29cc8 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -170,7 +170,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); From 179c21452b63c84d9b347257c528155ca5a8cd22 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 22:37:08 +0200 Subject: [PATCH 38/47] Generalize pdg switcher + suppress linter warnings --- .../TableProducer/candidateCreator2Prong.cxx | 6 ++--- .../TableProducer/candidateCreator3Prong.cxx | 14 +++++----- PWGHF/Utils/utilsMcGen.h | 22 +++++++-------- PWGHF/Utils/utilsMcMatching.h | 27 ++++++++++--------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index c161b0d72fb..90ba7032bb9 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -783,7 +783,7 @@ struct HfCandidateCreator2ProngExpressions { // D0(bar) → π+ K−, π+ K− π0, π+ π−, π+ π− π0, K+ K− for (const auto& [chn, finalState] : hf_cand_2prong::daughtersD0Main) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; - if (finalState.size() == 3) { // Partly Reco 2-prong decays + if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -797,12 +797,12 @@ struct HfCandidateCreator2ProngExpressions { if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); std::array finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]}; - convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts2ProngAll); + changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts2ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, FinalStateDepth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index e8d47fc19d9..aa2b10fd822 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -959,7 +959,7 @@ struct HfCandidateCreator3ProngExpressions { auto finalStates = getDecayChannelMain(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() > 3) { // Partly Reco 4-prong decays + if (finalState.size() > 3) { // Partly Reco decays with 4 or 5 final state particles, o2-linter: disable=magic-number if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -972,21 +972,21 @@ struct HfCandidateCreator3ProngExpressions { if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); - if (finalState.size() == 4) { // Check if the final state has 4 particles + if (finalState.size() == 4) { // Check if the final state has 4 particles, o2-linter: disable=magic-number std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll); + changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } - } else if (finalState.size() == 5) { // Check if the final state has 5 particles + } else if (finalState.size() == 5) { // Check if the final state has 5 particles, o2-linter: disable=magic-number std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; - convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll); + changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } } } - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -1023,7 +1023,7 @@ struct HfCandidateCreator3ProngExpressions { auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - channel = flagResonantDecay(pdg, arrPDGDaugh); + channel = flagResonantDecay(pdg, arrPDGDaugh); } break; // Exit loop if a match is found } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 4ba17f29cc8..e1d5aa5b033 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -60,11 +60,11 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V bool matched = false; for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) { - if (finalState.size() == 3) { // Partly Reco 3-prong decays + if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; - o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); + o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays + } else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number std::array finalStateParts = std::array{finalState[0], finalState[1]}; matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); } else { @@ -164,17 +164,17 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V std::vector arrAllDaughtersIndex; for (const auto& [chn, finalState] : finalStates) { - if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays + if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays, o2-linter: disable=magic-number std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; - o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); + o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; - o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts); + } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays, o2-linter: disable=magic-number + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays + } else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); @@ -207,7 +207,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]); arrPDGDaugh[iProng] = daughI.pdgCode(); } - channel = o2::hf_decay::flagResonantDecay(motherPdgCode, arrPDGDaugh); + channel = o2::hf_decay::flagResonantDecay(motherPdgCode, arrPDGDaugh); } break; // Exit loop if a match is found } @@ -240,7 +240,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } if (flag != 0) { RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1); - if (arrDaughIndex.size() == 2) { + if (arrDaughIndex.size() == NDaughtersResonant) { for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) { auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]); arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode()); diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index 3c93ef36321..ce71de44ef1 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -194,8 +194,8 @@ inline bool checkDecayChannel(std::array const& arrPdgResoChn, std::arra /// \param motherPdg PDG code of the mother particle /// \param channel decay channel flag to be set /// \param arrDaughPdgs array of daughter PDG codes -template -inline int8_t flagResonantDecay(int motherPdg, std::array const& arrDaughPdgs) +template +inline int8_t flagResonantDecay(const int motherPdg, std::array const& arrDaughPdgs) { switch (motherPdg) { case o2::constants::physics::Pdg::kD0: @@ -242,24 +242,25 @@ inline int8_t flagResonantDecay(int motherPdg, std::array const& arrDaug break; default: LOG(fatal) << "Unknown PDG code for 3-prong final states: " << motherPdg; - return {}; + return -1; } return 0; } -/// Convert Pi0 to AntiPi0 in the array of PDG codes for antiparticles since -/// the Pi0s stemming from antiparticle decays keep the pdg code 111. +/// Flip the sign of a specific PDG code in an array +/// of PDG codes representing either a final or a resonant state /// \tparam N size of the array of PDG codes -/// \param partPdgCode PDG code of the particle -/// \param arrPdgIndexes array of PDG codes to be modified +/// \param motherPdgCode PDG code of the mother particle +/// \param partPdgCode PDG code of the target particle +/// \param arrFinalStatePdgs array of PDG codes to be modified template -inline void convertPi0ToAntiPi0(const int partPdgCode, std::array& arrPdgIndexes) +inline void changeFinalStatePdgSign(const int motherPdgCode, const int partPdgCode, std::array& arrFinalStatePdgs) { - if (partPdgCode < 0) { - for (auto& part : arrPdgIndexes) { // o2-linter: disable=const-ref-in-for-loop (int elements) - if (part == kPi0) { - part = -part; // The Pi0 pdg code does not change between particle and antiparticle - } + if (motherPdgCode >= 0) + return; + for (auto& part : arrFinalStatePdgs) { // o2-linter: disable=const-ref-in-for-loop (arrFinalStatePdgs entries are modified) + if (part == partPdgCode) { + part = -part; } } } From 1383cedaa463edea2504761cef64cf0389b6fe5b Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Tue, 17 Jun 2025 20:40:10 +0000 Subject: [PATCH 39/47] Please consider the following formatting changes --- PWGHF/TableProducer/candidateCreator3Prong.cxx | 2 +- PWGHF/Utils/utilsMcGen.h | 2 +- PWGHF/Utils/utilsMcMatching.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index aa2b10fd822..e1b4e1374bb 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -959,7 +959,7 @@ struct HfCandidateCreator3ProngExpressions { auto finalStates = getDecayChannelMain(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() > 3) { // Partly Reco decays with 4 or 5 final state particles, o2-linter: disable=magic-number + if (finalState.size() > 3) { // Partly Reco decays with 4 or 5 final state particles, o2-linter: disable=magic-number if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index e1d5aa5b033..14b5514229c 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -170,7 +170,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays, o2-linter: disable=magic-number - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index ce71de44ef1..ac28dd57962 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -247,7 +247,7 @@ inline int8_t flagResonantDecay(const int motherPdg, std::array const& a return 0; } -/// Flip the sign of a specific PDG code in an array +/// Flip the sign of a specific PDG code in an array /// of PDG codes representing either a final or a resonant state /// \tparam N size of the array of PDG codes /// \param motherPdgCode PDG code of the mother particle From 702fa9520799aa56f23db9f522826ad07b0fa4db Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 17 Jun 2025 23:01:48 +0200 Subject: [PATCH 40/47] Fix o2-linter: disable comments --- PWGHF/TableProducer/candidateCreator2Prong.cxx | 4 ++-- PWGHF/TableProducer/candidateCreator3Prong.cxx | 8 ++++---- PWGHF/Utils/utilsMcGen.h | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 90ba7032bb9..4fed12f7067 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -783,7 +783,7 @@ struct HfCandidateCreator2ProngExpressions { // D0(bar) → π+ K−, π+ K− π0, π+ π−, π+ π− π0, K+ K− for (const auto& [chn, finalState] : hf_cand_2prong::daughtersD0Main) { std::array finalStateParts2Prong = std::array{finalState[0], finalState[1]}; - if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number + if (finalState.size() == 3) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays) if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -802,7 +802,7 @@ struct HfCandidateCreator2ProngExpressions { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one } } - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number + } else if (finalState.size() == 2) { // o2-linter: disable=magic-number (Fully Reco 2-prong decays) if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index e1b4e1374bb..b5aecc1777f 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -959,7 +959,7 @@ struct HfCandidateCreator3ProngExpressions { auto finalStates = getDecayChannelMain(pdg); for (const auto& [chn, finalState] : finalStates) { std::array finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]}; - if (finalState.size() > 3) { // Partly Reco decays with 4 or 5 final state particles, o2-linter: disable=magic-number + if (finalState.size() > 3) { // o2-linter: disable=magic-number (Partly Reco decays with 4 or 5 final state particles) if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { @@ -972,13 +972,13 @@ struct HfCandidateCreator3ProngExpressions { if (indexRec > -1) { auto motherParticle = mcParticles.rawIteratorAt(indexRec); - if (finalState.size() == 4) { // Check if the final state has 4 particles, o2-linter: disable=magic-number + if (finalState.size() == 4) { // o2-linter: disable=magic-number (Check if the final state has 4 particles) std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched } - } else if (finalState.size() == 5) { // Check if the final state has 5 particles, o2-linter: disable=magic-number + } else if (finalState.size() == 5) { // o2-linter: disable=magic-number (Check if the final state has 5 particles) std::array finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll); if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) { @@ -986,7 +986,7 @@ struct HfCandidateCreator3ProngExpressions { } } } - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number + } else if (finalState.size() == 3) { // o2-linter: disable=magic-number(Fully Reco 3-prong decays) if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial); } else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 14b5514229c..46b0be8a0e9 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -60,11 +60,11 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V bool matched = false; for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) { - if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number + if (finalState.size() == 3) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays) std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); - } else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number + } else if (finalState.size() == 2) { // o2-linter: disable=magic-number (Fully Reco 2-prong decays) std::array finalStateParts = std::array{finalState[0], finalState[1]}; matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth); } else { @@ -164,17 +164,17 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V std::vector arrAllDaughtersIndex; for (const auto& [chn, finalState] : finalStates) { - if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays, o2-linter: disable=magic-number + if (finalState.size() == 5) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 5-prong decays) std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays, o2-linter: disable=magic-number - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + } else if (finalState.size() == 4) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 4-prong decays) + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number + } else if (finalState.size() == 3) { // o2-linter: disable=magic-number (Fully Reco 3-prong decays) std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2]}; RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth); From e16bb081bd1c986d1ae572fe2cb9a0e2f8fbf0c8 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Tue, 17 Jun 2025 21:05:16 +0000 Subject: [PATCH 41/47] Please consider the following formatting changes --- PWGHF/Utils/utilsMcGen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 46b0be8a0e9..e101efd7ee3 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -170,7 +170,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 4-prong decays) - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); From 3ec1a01e385e2d3226bc9f753de538cd6192379f Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 18 Jun 2025 09:48:33 +0200 Subject: [PATCH 42/47] Fix to Dstar matching in reco candidates --- PWGHF/TableProducer/candidateCreator3Prong.cxx | 1 + PWGHF/Utils/utilsMcGen.h | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index b5aecc1777f..16b895f5479 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1011,6 +1011,7 @@ struct HfCandidateCreator3ProngExpressions { for (size_t iDaug = 0; iDaug < arrResoDaughIndexDStar.size(); iDaug++) { auto daughDstar = mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]); if (std::abs(daughDstar.pdgCode()) == Pdg::kD0 || std::abs(daughDstar.pdgCode()) == Pdg::kDPlus) { + RecoDecay::getDaughters(daughDstar, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); break; } } diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index e101efd7ee3..deb06a7a278 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -169,8 +169,8 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); - } else if (finalState.size() == 4) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 4-prong decays) - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + } else if (finalState.size() == 4) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 4-prong decays) + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); @@ -194,8 +194,6 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (std::abs(daughDstar.pdgCode()) == Pdg::kD0 || std::abs(daughDstar.pdgCode()) == Pdg::kDPlus) { RecoDecay::getDaughters(daughDstar, &arrResoDaughIndex, std::array{0}, ResoMaxDepth); break; - } else { - LOG(info) << "[matchFinalStateCorrBkgsGen] D* Daughter with PDG code: " << mcParticles.rawIteratorAt(arrResoDaughIndexDStar[iDaug]).pdgCode() << " not recognized."; } } } else { From cc948d476afa987d017399d4bcac4deb039ae1fc Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Wed, 18 Jun 2025 07:50:36 +0000 Subject: [PATCH 43/47] Please consider the following formatting changes --- PWGHF/Utils/utilsMcGen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index deb06a7a278..f5213c6c2f1 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -170,7 +170,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); } else if (finalState.size() == 4) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays from 4-prong decays) - std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; + std::array finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]}; o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts); RecoDecay::getDaughters(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth); matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1); From 5628babc578fceb94c45660d6b077699dc05f540 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 18 Jun 2025 12:52:36 +0200 Subject: [PATCH 44/47] Implement Vit comments --- .../TableProducer/candidateCreator2Prong.cxx | 2 +- .../TableProducer/candidateCreator3Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreatorMcGen.cxx | 4 +-- PWGHF/Utils/utilsMcGen.h | 6 ++-- PWGHF/Utils/utilsMcMatching.h | 33 +++++++++---------- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 4fed12f7067..1eb91956aa5 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -916,7 +916,7 @@ struct HfCandidateCreator2ProngExpressions { if (matchCorrBkgs) { hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } else { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 16b895f5479..90d25e5cef0 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1205,7 +1205,7 @@ struct HfCandidateCreator3ProngExpressions { if (matchCorrBkgs) { hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, mothersCorrBkgsPdgs.value); } else { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } } diff --git a/PWGHF/TableProducer/candidateCreatorMcGen.cxx b/PWGHF/TableProducer/candidateCreatorMcGen.cxx index 3c5f7a2c3c1..238ec56ca7c 100644 --- a/PWGHF/TableProducer/candidateCreatorMcGen.cxx +++ b/PWGHF/TableProducer/candidateCreatorMcGen.cxx @@ -55,10 +55,10 @@ struct HfCandidateCreatorMcGen { for (const auto& mcCollision : mcCollisions) { const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex()); if (fill2Prong) { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong); + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong); } if (fill3Prong) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong); } } if (fillBplus) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index f5213c6c2f1..875faef72e9 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -36,7 +36,7 @@ namespace hf_mc_gen { -template +template void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { using namespace o2::constants::physics; @@ -46,7 +46,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V for (const auto& particle : mcParticlesPerMcColl) { int8_t flag = 0; int8_t origin = 0; - int8_t channel = 0; // Not used in 2-prong decays + int8_t channel = 0; int8_t sign = 0; std::vector idxBhadMothers{}; // Reject particles from background events @@ -121,7 +121,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } -template +template void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, std::vector const& corrBkgMothersPdgs = {}) { using namespace o2::constants::physics; diff --git a/PWGHF/Utils/utilsMcMatching.h b/PWGHF/Utils/utilsMcMatching.h index ac28dd57962..5736e6ab278 100644 --- a/PWGHF/Utils/utilsMcMatching.h +++ b/PWGHF/Utils/utilsMcMatching.h @@ -163,24 +163,24 @@ inline std::unordered_map> getDecayChan } } // namespace hf_cand_3prong -/// Perform the matching for a single resonant channel -/// \tparam N size of the array of daughter PDG codes -/// \param arrPdgResoChn array of daughter indices -/// \param arrPdgDaugs array of PDG codes for the resonant decay -/// \return true if the resonant channel is matched, false otherwise +/// Compare an array of PDG codes with an expected array +/// \tparam N size of the arrays to be compared +/// \param arrPdgTested array of PDG codes to be tested +/// \param arrPdgExpected array of the expected PDG codes +/// \return true if the arrays are equal, false otherwise template -inline bool checkDecayChannel(std::array const& arrPdgResoChn, std::array arrPdgDaugs) +inline bool checkDecayChannel(std::array const& arrPdgTested, std::array arrPdgExpected) { for (std::size_t i = 0; i < N; i++) { - bool findDaug = false; + bool foundPdg = false; for (std::size_t j = 0; j < N; j++) { - if (std::abs(arrPdgResoChn[i]) == std::abs(arrPdgDaugs[j])) { - arrPdgDaugs[j] = -1; // Mark as found - findDaug = true; + if (std::abs(arrPdgTested[i]) == std::abs(arrPdgExpected[j])) { + arrPdgExpected[j] = -1; // Mark as found + foundPdg = true; break; } } - if (!findDaug) { + if (!foundPdg) { return false; } } @@ -188,12 +188,10 @@ inline bool checkDecayChannel(std::array const& arrPdgResoChn, std::arra } /// Flag the resonant decays -/// Function documentation: -/// \tparam is3Prong bool to specify if the mother decays with a 3-prong decay /// \tparam N size of the array of daughter PDG codes /// \param motherPdg PDG code of the mother particle -/// \param channel decay channel flag to be set /// \param arrDaughPdgs array of daughter PDG codes +/// \return the flag for the matched resonant decay channel template inline int8_t flagResonantDecay(const int motherPdg, std::array const& arrDaughPdgs) { @@ -248,16 +246,17 @@ inline int8_t flagResonantDecay(const int motherPdg, std::array const& a } /// Flip the sign of a specific PDG code in an array -/// of PDG codes representing either a final or a resonant state +/// of PDG codes associated to an antiparticle. /// \tparam N size of the array of PDG codes /// \param motherPdgCode PDG code of the mother particle -/// \param partPdgCode PDG code of the target particle +/// \param partPdgCode PDG code to be flipped /// \param arrFinalStatePdgs array of PDG codes to be modified template inline void changeFinalStatePdgSign(const int motherPdgCode, const int partPdgCode, std::array& arrFinalStatePdgs) { - if (motherPdgCode >= 0) + if (motherPdgCode >= 0) { return; + } for (auto& part : arrFinalStatePdgs) { // o2-linter: disable=const-ref-in-for-loop (arrFinalStatePdgs entries are modified) if (part == partPdgCode) { part = -part; From b585e1949a35286e7c43a7e891be07f75e46deb6 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 18 Jun 2025 16:30:27 +0200 Subject: [PATCH 45/47] Rename configurable --- PWGHF/TableProducer/candidateCreator2Prong.cxx | 4 ++-- PWGHF/TableProducer/candidateCreator3Prong.cxx | 4 ++-- PWGHF/Utils/utilsMcGen.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 1eb91956aa5..de656ff2f40 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -694,7 +694,7 @@ struct HfCandidateCreator2ProngExpressions { Configurable rejectBackground{"rejectBackground", true, "Reject particles from background events"}; Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; - Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; + Configurable matchCorrelatedBackgrounds{"matchCorrelatedBackgrounds", false, "Match correlated background candidates"}; HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring @@ -775,7 +775,7 @@ struct HfCandidateCreator2ProngExpressions { } std::vector idxBhadMothers{}; - if (matchCorrBkgs) { + if (matchCorrelatedBackgrounds) { indexRec = -1; // Index of the matched reconstructed candidate constexpr int FinalStateDepth = 2; constexpr int ResoDepth = 1; diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 90d25e5cef0..37dfae3efe1 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -851,7 +851,7 @@ struct HfCandidateCreator3ProngExpressions { Configurable rejectBackground{"rejectBackground", true, "Reject particles from background events"}; Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; - Configurable matchCorrBkgs{"matchCorrBkgs", false, "Match correlated background candidates"}; + Configurable matchCorrelatedBackgrounds{"matchCorrelatedBackgrounds", false, "Match correlated background candidates"}; Configurable> mothersCorrBkgsPdgs{"mothersCorrBkgsPdgs", {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}, "PDG codes of the mother particles of correlated background candidates"}; constexpr static std::size_t NDaughtersResonant{2u}; @@ -946,7 +946,7 @@ struct HfCandidateCreator3ProngExpressions { } } - if (matchCorrBkgs) { + if (matchCorrelatedBackgrounds) { indexRec = -1; // Index of the matched reconstructed candidate constexpr int MaxDepth = 2; // Depth for final state matching constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 875faef72e9..87070564f2a 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -54,7 +54,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V rowMcMatchGen(flag, origin, channel, -1); continue; } - if (matchCorrBkgs) { + if (matchCorrelatedBackgrounds) { constexpr int MaxDepth = 2; // Depth for final state matching constexpr int ResoMaxDepth = 1; // Depth for resonant decay matching bool matched = false; From f2c41407499cb7ccfee19ff12bc99a963243bd81 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 18 Jun 2025 17:01:11 +0200 Subject: [PATCH 46/47] Remove unnecessary templetization --- PWGHF/TableProducer/candidateCreator2Prong.cxx | 6 +----- PWGHF/TableProducer/candidateCreator3Prong.cxx | 6 +----- PWGHF/TableProducer/candidateCreatorMcGen.cxx | 4 ++-- PWGHF/Utils/utilsMcGen.h | 8 ++++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index de656ff2f40..03b24531a80 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -913,11 +913,7 @@ struct HfCandidateCreator2ProngExpressions { } continue; } - if (matchCorrBkgs) { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); - } else { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); - } + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds.value); } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 37dfae3efe1..ff3b0cbc4d8 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1202,11 +1202,7 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - if (matchCorrBkgs) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, mothersCorrBkgsPdgs.value); - } else { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); - } + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds ? mothersCorrBkgsPdgs.value : std::vector{}); } } diff --git a/PWGHF/TableProducer/candidateCreatorMcGen.cxx b/PWGHF/TableProducer/candidateCreatorMcGen.cxx index 238ec56ca7c..7387f2ee5fa 100644 --- a/PWGHF/TableProducer/candidateCreatorMcGen.cxx +++ b/PWGHF/TableProducer/candidateCreatorMcGen.cxx @@ -55,10 +55,10 @@ struct HfCandidateCreatorMcGen { for (const auto& mcCollision : mcCollisions) { const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex()); if (fill2Prong) { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong); + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong, false); } if (fill3Prong) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, std::vector{}); } } if (fillBplus) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 87070564f2a..6f9ed6f4fed 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -36,8 +36,8 @@ namespace hf_mc_gen { -template -void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) +template +void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool matchCorrelatedBackgrounds) { using namespace o2::constants::physics; constexpr std::size_t NDaughtersResonant{2u}; @@ -121,7 +121,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } -template +template void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, std::vector const& corrBkgMothersPdgs = {}) { using namespace o2::constants::physics; @@ -147,7 +147,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V continue; } - if (matchCorrBkgs) { + if (corrBkgMothersPdgs.size() > 0) { for (const auto& motherPdgCode : corrBkgMothersPdgs) { if (std::abs(particle.pdgCode()) != motherPdgCode) { continue; // Skip if the particle PDG code does not match the mother PDG code From 3cd7c3939a3f34da5986957d6c68b481eb10d622 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 18 Jun 2025 19:12:31 +0200 Subject: [PATCH 47/47] Allow for corr bkg matching in candidateCreatorMcGen --- PWGHF/TableProducer/candidateCreator2Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreator3Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreatorMcGen.cxx | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator2Prong.cxx b/PWGHF/TableProducer/candidateCreator2Prong.cxx index 03b24531a80..7396a0b6f0f 100644 --- a/PWGHF/TableProducer/candidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator2Prong.cxx @@ -913,7 +913,7 @@ struct HfCandidateCreator2ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds.value); + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds); } } diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index ff3b0cbc4d8..3460ff0a8a3 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1202,7 +1202,7 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds ? mothersCorrBkgsPdgs.value : std::vector{}); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, matchCorrelatedBackgrounds ? mothersCorrBkgsPdgs : std::vector{}); } } diff --git a/PWGHF/TableProducer/candidateCreatorMcGen.cxx b/PWGHF/TableProducer/candidateCreatorMcGen.cxx index 7387f2ee5fa..8da97722b8b 100644 --- a/PWGHF/TableProducer/candidateCreatorMcGen.cxx +++ b/PWGHF/TableProducer/candidateCreatorMcGen.cxx @@ -31,6 +31,7 @@ using namespace o2; using namespace o2::framework; +using namespace o2::constants::physics; /// Reconstruction of heavy-flavour 2-prong decay candidates struct HfCandidateCreatorMcGen { @@ -41,6 +42,8 @@ struct HfCandidateCreatorMcGen { Produces rowMcMatchGenB0; Configurable fill2Prong{"fill2Prong", false, "fill table for 2 prong candidates"}; Configurable fill3Prong{"fill3Prong", false, "fill table for 3 prong candidates"}; + Configurable matchCorrelatedBackgrounds{"matchCorrelatedBackgrounds", false, "Match correlated background candidates"}; + Configurable> mothersCorrBkgsPdgs{"mothersCorrBkgsPdgs", {Pdg::kDPlus, Pdg::kDS, Pdg::kDStar, Pdg::kLambdaCPlus, Pdg::kXiCPlus}, "PDG codes of the mother particles of correlated background candidates"}; Configurable fillBplus{"fillBplus", false, "fill table for for B+ candidates"}; Configurable fillB0{"fillB0", false, "fill table for B0 candidates"}; Configurable rejectBackground2Prong{"rejectBackground2Prong", false, "Reject particles from PbPb background for 2 prong candidates"}; @@ -55,10 +58,10 @@ struct HfCandidateCreatorMcGen { for (const auto& mcCollision : mcCollisions) { const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex()); if (fill2Prong) { - hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong, false); + hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong, matchCorrelatedBackgrounds); } if (fill3Prong) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, std::vector{}); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, matchCorrelatedBackgrounds ? mothersCorrBkgsPdgs : std::vector{}); } } if (fillBplus) {