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