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