Skip to content

Commit 62e4d4f

Browse files
PWGHF: optimise cand. creator logic (#7013)
* PWGHF: optimise cand. creator logic to reject candidates from rejected events * Please consider the following formatting changes --------- Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent ff40af8 commit 62e4d4f

6 files changed

Lines changed: 388 additions & 360 deletions

PWGHF/TableProducer/candidateCreator2Prong.cxx

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ struct HfCandidateCreator2ProngExpressions {
664664
PresliceUnsorted<McCollisionsNoCents> colPerMcCollision = aod::mccollisionlabel::mcCollisionId;
665665
PresliceUnsorted<McCollisionsFT0Cs> colPerMcCollisionFT0C = aod::mccollisionlabel::mcCollisionId;
666666
PresliceUnsorted<McCollisionsFT0Ms> colPerMcCollisionFT0M = aod::mccollisionlabel::mcCollisionId;
667+
Preslice<aod::McParticles> mcParticlesPerMcCollision = aod::mcparticle::mcCollisionId;
667668

668669
using BCsInfo = soa::Join<aod::BCs, aod::Timestamps, aod::BcSels>;
669670
HistogramRegistry registry{"registry"};
@@ -691,7 +692,7 @@ struct HfCandidateCreator2ProngExpressions {
691692
void runCreator2ProngMc(aod::TracksWMc const& tracks,
692693
aod::McParticles const& mcParticles,
693694
CCs const& collInfos,
694-
aod::McCollisions const&,
695+
aod::McCollisions const& mcCollisions,
695696
BCsInfo const&)
696697
{
697698
rowCandidateProng2->bindExternalIndices(&tracks);
@@ -762,19 +763,11 @@ struct HfCandidateCreator2ProngExpressions {
762763
}
763764
}
764765

765-
// Match generated particles.
766-
for (const auto& particle : mcParticles) {
767-
flag = 0;
768-
origin = 0;
769-
std::vector<int> idxBhadMothers{};
770-
// Reject particles from background events
771-
if (particle.fromBackgroundEvent() && rejectBackground) {
772-
rowMcMatchGen(flag, origin, -1);
773-
continue;
774-
}
766+
for (const auto& mcCollision : mcCollisions) {
775767

768+
// Slice the particles table to get the particles for the current MC collision
769+
const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex());
776770
// Slice the collisions table to get the collision info for the current MC collision
777-
auto mcCollision = particle.mcCollision();
778771
float centrality{-1.f};
779772
uint16_t rejectionMask{0};
780773
if constexpr (centEstimator == CentralityEstimator::FT0C) {
@@ -789,38 +782,52 @@ struct HfCandidateCreator2ProngExpressions {
789782
}
790783
hfEvSelMc.fillHistograms(rejectionMask);
791784
if (rejectionMask != 0) {
792-
/// at least one event selection not satisfied --> reject the gen particle
793-
rowMcMatchGen(flag, origin, -1);
785+
// at least one event selection not satisfied --> reject all particles from this collision
786+
for (unsigned int i = 0; i < mcParticlesPerMcColl.size(); ++i) {
787+
rowMcMatchGen(0, 0, -1);
788+
}
794789
continue;
795790
}
796791

797-
// D0(bar) → π± K∓
798-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) {
799-
flag = sign * (1 << DecayType::D0ToPiK);
800-
}
792+
// Match generated particles.
793+
for (const auto& particle : mcParticlesPerMcColl) {
794+
flag = 0;
795+
origin = 0;
796+
std::vector<int> idxBhadMothers{};
797+
// Reject particles from background events
798+
if (particle.fromBackgroundEvent() && rejectBackground) {
799+
rowMcMatchGen(flag, origin, -1);
800+
continue;
801+
}
801802

802-
// J/ψ → e+ e−
803-
if (flag == 0) {
804-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true)) {
805-
flag = 1 << DecayType::JpsiToEE;
803+
// D0(bar) → π± K∓
804+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) {
805+
flag = sign * (1 << DecayType::D0ToPiK);
806806
}
807-
}
808807

809-
// J/ψ → μ+ μ−
810-
if (flag == 0) {
811-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true)) {
812-
flag = 1 << DecayType::JpsiToMuMu;
808+
// J/ψ → e+ e−
809+
if (flag == 0) {
810+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true)) {
811+
flag = 1 << DecayType::JpsiToEE;
812+
}
813813
}
814-
}
815814

816-
// Check whether the particle is non-prompt (from a b quark).
817-
if (flag != 0) {
818-
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
819-
}
820-
if (origin == RecoDecay::OriginType::NonPrompt) {
821-
rowMcMatchGen(flag, origin, idxBhadMothers[0]);
822-
} else {
823-
rowMcMatchGen(flag, origin, -1);
815+
// J/ψ → μ+ μ−
816+
if (flag == 0) {
817+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true)) {
818+
flag = 1 << DecayType::JpsiToMuMu;
819+
}
820+
}
821+
822+
// Check whether the particle is non-prompt (from a b quark).
823+
if (flag != 0) {
824+
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
825+
}
826+
if (origin == RecoDecay::OriginType::NonPrompt) {
827+
rowMcMatchGen(flag, origin, idxBhadMothers[0]);
828+
} else {
829+
rowMcMatchGen(flag, origin, -1);
830+
}
824831
}
825832
}
826833
}

PWGHF/TableProducer/candidateCreator3Prong.cxx

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ struct HfCandidateCreator3ProngExpressions {
471471
PresliceUnsorted<McCollisionsNoCents> colPerMcCollision = aod::mccollisionlabel::mcCollisionId;
472472
PresliceUnsorted<McCollisionsFT0Cs> colPerMcCollisionFT0C = aod::mccollisionlabel::mcCollisionId;
473473
PresliceUnsorted<McCollisionsFT0Ms> colPerMcCollisionFT0M = aod::mccollisionlabel::mcCollisionId;
474+
Preslice<aod::McParticles> mcParticlesPerMcCollision = aod::mcparticle::mcCollisionId;
474475

475476
void init(InitContext& initContext)
476477
{
@@ -513,7 +514,7 @@ struct HfCandidateCreator3ProngExpressions {
513514
void runCreator3ProngMc(aod::TracksWMc const& tracks,
514515
aod::McParticles const& mcParticles,
515516
CCs const& collInfos,
516-
aod::McCollisions const&,
517+
aod::McCollisions const& mcCollisions,
517518
BCsInfo const&)
518519
{
519520
rowCandidateProng3->bindExternalIndices(&tracks);
@@ -647,21 +648,11 @@ struct HfCandidateCreator3ProngExpressions {
647648
}
648649
}
649650

650-
// Match generated particles.
651-
for (const auto& particle : mcParticles) {
652-
flag = 0;
653-
origin = 0;
654-
channel = 0;
655-
arrDaughIndex.clear();
656-
std::vector<int> idxBhadMothers{};
657-
// Reject particles from background events
658-
if (particle.fromBackgroundEvent() && rejectBackground) {
659-
rowMcMatchGen(flag, origin, channel, -1);
660-
continue;
661-
}
651+
for (const auto& mcCollision : mcCollisions) {
662652

653+
// Slice the particles table to get the particles for the current MC collision
654+
const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex());
663655
// Slice the collisions table to get the collision info for the current MC collision
664-
auto mcCollision = particle.mcCollision();
665656
float centrality{-1.f};
666657
uint16_t rejectionMask{0};
667658
if constexpr (centEstimator == CentralityEstimator::FT0C) {
@@ -676,85 +667,101 @@ struct HfCandidateCreator3ProngExpressions {
676667
}
677668
hfEvSelMc.fillHistograms(rejectionMask);
678669
if (rejectionMask != 0) {
679-
/// at least one event selection not satisfied --> reject the gen particle
680-
rowMcMatchGen(flag, origin, channel, -1);
670+
// at least one event selection not satisfied --> reject all gen particles from this collision
671+
for (unsigned int i = 0; i < mcParticlesPerMcColl.size(); ++i) {
672+
rowMcMatchGen(0, 0, 0, -1);
673+
}
681674
continue;
682675
}
683676

684-
// D± → π± K∓ π±
685-
if (createDplus) {
686-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
687-
flag = sign * (1 << DecayType::DplusToPiKPi);
677+
// Match generated particles.
678+
for (const auto& particle : mcParticlesPerMcColl) {
679+
flag = 0;
680+
origin = 0;
681+
channel = 0;
682+
arrDaughIndex.clear();
683+
std::vector<int> idxBhadMothers{};
684+
// Reject particles from background events
685+
if (particle.fromBackgroundEvent() && rejectBackground) {
686+
rowMcMatchGen(flag, origin, channel, -1);
687+
continue;
688688
}
689-
}
690689

691-
// Ds± → K± K∓ π± and D± → K± K∓ π±
692-
if (flag == 0 && createDs) {
693-
bool isDplus = false;
694-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
695-
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
696-
// TODO: move to different and explicit flags
697-
flag = sign * (1 << DecayType::DsToKKPi);
698-
} else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
699-
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
700-
// TODO: move to different and explicit flags
701-
flag = sign * (1 << DecayType::DsToKKPi);
702-
isDplus = true;
690+
// D± → π± K∓ π±
691+
if (createDplus) {
692+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
693+
flag = sign * (1 << DecayType::DplusToPiKPi);
694+
}
703695
}
704-
if (flag != 0) {
705-
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
706-
if (arrDaughIndex.size() == 2) {
707-
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
708-
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
709-
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
710-
}
711-
if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) {
712-
channel = isDplus ? DecayChannelDToKKPi::DplusToPhiPi : DecayChannelDToKKPi::DsToPhiPi;
713-
} else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) {
714-
channel = isDplus ? DecayChannelDToKKPi::DplusToK0starK : DecayChannelDToKKPi::DsToK0starK;
696+
697+
// Ds± → K± K∓ π± and D± → K± K∓ π±
698+
if (flag == 0 && createDs) {
699+
bool isDplus = false;
700+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
701+
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
702+
// TODO: move to different and explicit flags
703+
flag = sign * (1 << DecayType::DsToKKPi);
704+
} else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
705+
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
706+
// TODO: move to different and explicit flags
707+
flag = sign * (1 << DecayType::DsToKKPi);
708+
isDplus = true;
709+
}
710+
if (flag != 0) {
711+
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
712+
if (arrDaughIndex.size() == 2) {
713+
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
714+
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
715+
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
716+
}
717+
if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) {
718+
channel = isDplus ? DecayChannelDToKKPi::DplusToPhiPi : DecayChannelDToKKPi::DsToPhiPi;
719+
} else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) {
720+
channel = isDplus ? DecayChannelDToKKPi::DplusToK0starK : DecayChannelDToKKPi::DsToK0starK;
721+
}
715722
}
716723
}
717724
}
718-
}
719-
720-
// Λc± → p± K∓ π±
721-
if (flag == 0 && createLc) {
722-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
723-
flag = sign * (1 << DecayType::LcToPKPi);
724725

725-
// Flagging the different Λc± → p± K∓ π± decay channels
726-
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
727-
if (arrDaughIndex.size() == 2) {
728-
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
729-
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
730-
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
731-
}
732-
if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) {
733-
channel = 1;
734-
} else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) {
735-
channel = 2;
736-
} else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) {
737-
channel = 3;
726+
// Λc± → p± K∓ π±
727+
if (flag == 0 && createLc) {
728+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
729+
flag = sign * (1 << DecayType::LcToPKPi);
730+
731+
// Flagging the different Λc± → p± K∓ π± decay channels
732+
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
733+
if (arrDaughIndex.size() == 2) {
734+
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
735+
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
736+
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
737+
}
738+
if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) {
739+
channel = 1;
740+
} else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) {
741+
channel = 2;
742+
} else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) {
743+
channel = 3;
744+
}
738745
}
739746
}
740747
}
741-
}
742748

743-
// Ξc± → p± K∓ π±
744-
if (flag == 0 && createXic) {
745-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
746-
flag = sign * (1 << DecayType::XicToPKPi);
749+
// Ξc± → p± K∓ π±
750+
if (flag == 0 && createXic) {
751+
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
752+
flag = sign * (1 << DecayType::XicToPKPi);
753+
}
747754
}
748-
}
749755

750-
// Check whether the particle is non-prompt (from a b quark).
751-
if (flag != 0) {
752-
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
753-
}
754-
if (origin == RecoDecay::OriginType::NonPrompt) {
755-
rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]);
756-
} else {
757-
rowMcMatchGen(flag, origin, channel, -1);
756+
// Check whether the particle is non-prompt (from a b quark).
757+
if (flag != 0) {
758+
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
759+
}
760+
if (origin == RecoDecay::OriginType::NonPrompt) {
761+
rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]);
762+
} else {
763+
rowMcMatchGen(flag, origin, channel, -1);
764+
}
758765
}
759766
}
760767
}

0 commit comments

Comments
 (0)