From 6743b522612a985157538617d2d451c8e3f6c35d Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 19 Feb 2025 09:57:48 +0100 Subject: [PATCH 01/12] add table with ML outputs for reco MC --- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 7b8b26c4410..a6ad9a80087 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -23,10 +23,12 @@ #include "PWGHF/Core/HfHelper.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/DataModel/CandidateSelectionTables.h" +#include "PWGHF/Core/CentralityEstimation.h" using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; +using namespace o2::hf_centrality; namespace o2::aod { @@ -79,8 +81,20 @@ DECLARE_SOA_COLUMN(Ct, ct, float); // Events DECLARE_SOA_COLUMN(IsEventReject, isEventReject, int); //! Event rejection flag DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! Run number +DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Collision centrality (for reco MC) +// ML scores +DECLARE_SOA_COLUMN(BkgScore, bkgScore, float); //! Bkg score (for reco MC candidates) +DECLARE_SOA_COLUMN(FdScore, fdScore, float); //! FD score (for reco MC candidates) } // namespace full - +DECLARE_SOA_TABLE(HfCandDpMls, "AOD", "HFCANDDPML", + full::M, + full::Pt, + full::Centrality, + full::BkgScore, + full::FdScore, + hf_cand_3prong::FlagMcMatchRec, + hf_cand_3prong::OriginMcRec, + hf_cand_3prong::FlagMcDecayChanRec) DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE", hf_cand::Chi2PCA, full::DecayLength, @@ -233,26 +247,32 @@ struct HfTreeCreatorDplusToPiKPi { Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; + Produces rowCandidateMl; Configurable selectionFlagDplus{"selectionFlagDplus", 1, "Selection Flag for Dplus"}; 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 fillOnlySignalMl{"fillOnlySignalMl", false, "Flag to fill derived tables with MC and ML info"}; 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"}; + Configurable> classMl{"classMlindexes", {0, 2}, "Indexes of ML bkg and non-prompt scores."}; HfHelper hfHelper; using SelectedCandidatesMc = soa::Filtered>; using MatchedGenCandidatesMc = soa::Filtered>; + using SelectedCandidatesMcWithMl = soa::Filtered>; using TracksWPid = soa::Join; + using McRecoCollisionsCent = soa::Join; Filter filterSelectCandidates = aod::hf_sel_candidate_dplus::isSelDplusToPiKPi >= selectionFlagDplus; Filter filterMcGenMatching = nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); + Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -271,7 +291,7 @@ struct HfTreeCreatorDplusToPiKPi { runNumber); } - template + template void fillCandidateTable(const T& candidate) { int8_t flagMc = 0; @@ -282,11 +302,18 @@ struct HfTreeCreatorDplusToPiKPi { originMc = candidate.originMcRec(); channelMc = candidate.flagMcDecayChanRec(); } - + + std::vector outputMl = {-999., -999.}; + if constexpr (doMl) { + for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { + outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; + } + } + auto prong0 = candidate.template prong0_as(); auto prong1 = candidate.template prong1_as(); auto prong2 = candidate.template prong2_as(); - + if (fillCandidateLiteTable) { rowCandidateLite( candidate.chi2PCA(), @@ -333,7 +360,20 @@ struct HfTreeCreatorDplusToPiKPi { flagMc, originMc, channelMc); - } else { + } else if (fillOnlySignalMl) { + auto collision = candidate.template collision_as(); + double cent = getCentralityColl(collision, CentralityEstimator::FT0C); + rowCandidateMl( + hfHelper.invMassDplusToPiKPi(candidate), + candidate.pt(), + cent, + outputMl[0], + outputMl[1], + flagMc, + originMc, + channelMc + ); + } else { rowCandidateFull( candidate.collision().bcId(), candidate.collision().numContrib(), @@ -414,8 +454,8 @@ struct HfTreeCreatorDplusToPiKPi { flagMc, originMc, channelMc); + } } - } void processData(aod::Collisions const& collisions, soa::Filtered> const& candidates, @@ -450,6 +490,8 @@ struct HfTreeCreatorDplusToPiKPi { aod::McCollisions const&, SelectedCandidatesMc const& candidates, MatchedGenCandidatesMc const& particles, + SelectedCandidatesMcWithMl const& candidateswithml, + McRecoCollisionsCent const&, TracksWPid const&) { // Filling event properties @@ -483,7 +525,19 @@ struct HfTreeCreatorDplusToPiKPi { } fillCandidateTable(candidate); } - } else { + } else if (fillOnlySignalMl) { + rowCandidateMl.reserve(candidateswithml.size()); + for (const auto& candidate : candidateswithml) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; + } + } + fillCandidateTable(candidate); + } + } + else { if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); } else { From 0a1c65b094c65a383cd43d7100d390d87c661d56 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 20 Feb 2025 09:33:43 +0100 Subject: [PATCH 02/12] implemented D* in 3prongcreator --- .../DataModel/CandidateReconstructionTables.h | 2 ++ .../TableProducer/candidateCreator3Prong.cxx | 21 +++++++++++++++++-- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 6 +++--- PWGHF/Utils/utilsMcGen.h | 7 +++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/PWGHF/DataModel/CandidateReconstructionTables.h b/PWGHF/DataModel/CandidateReconstructionTables.h index 7da70658ff0..4688148d5b8 100644 --- a/PWGHF/DataModel/CandidateReconstructionTables.h +++ b/PWGHF/DataModel/CandidateReconstructionTables.h @@ -949,6 +949,8 @@ enum DecayType { DplusToPiKPi = 0, XicToPKPi, N3ProngDecays }; // always keep N3ProngDecays at the end +static const int DstarToPiKPiBkg = DecayType::N3ProngDecays; + // Ds± → K± K∓ π± or D± → K± K∓ π± enum DecayChannelDToKKPi { diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 9743725dae6..6007de83bf3 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -85,6 +85,7 @@ struct HfCandidateCreator3Prong { Configurable createDs{"createDs", false, "enable Ds+/- candidate creation"}; Configurable createLc{"createLc", false, "enable Lc+/- candidate creation"}; Configurable createXic{"createXic", false, "enable Xic+/- candidate creation"}; + Configurable createDstarDplusBkg{"createDstarDplusBkg", false, "enable D* candidate creation"}; HfEventSelection hfEvSel; // event selection and monitoring o2::vertexing::DCAFitterN<3> df; // 3-prong vertex fitter @@ -144,7 +145,7 @@ struct HfCandidateCreator3Prong { } } - std::array creationFlags = {createDplus, createDs, createLc, createXic}; + std::array creationFlags = {createDplus, createDs, createLc, createXic, createDstarDplusBkg}; if (std::accumulate(creationFlags.begin(), creationFlags.end(), 0) == 0) { LOGP(fatal, "At least one particle specie should be enabled for the creation."); } @@ -791,6 +792,7 @@ struct HfCandidateCreator3ProngExpressions { bool createDs{false}; bool createLc{false}; bool createXic{false}; + bool createDstarDplusBkg{false}; HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring using BCsInfo = soa::Join; @@ -826,7 +828,9 @@ struct HfCandidateCreator3ProngExpressions { createLc = option.defaultValue.get(); } else if (option.name.compare("createXic") == 0) { createXic = option.defaultValue.get(); - } + } else if (option.name.compare("createDstarDplusBkg") == 0) { + createDstarDplusBkg = option.defaultValue.get(); + } } break; } @@ -839,6 +843,7 @@ struct HfCandidateCreator3ProngExpressions { LOGP(info, " --> createDs = {}", createDs); LOGP(info, " --> createLc = {}", createLc); LOGP(info, " --> createXic = {}", createXic); + LOGP(info, " --> createDstarDplusBkg = {}", createDstarDplusBkg); } /// Performs MC matching. @@ -958,6 +963,18 @@ struct HfCandidateCreator3ProngExpressions { } } + // D* → D0π → Kππ + if (flag == 0 && createDstarDplusBkg) { + 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 * (1 << DstarToPiKPiBkg); + } + } + // Λc± → p± K∓ π± if (flag == 0 && createLc) { if (matchKinkedDecayTopology && matchInteractionsWithMaterial) { diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index a6ad9a80087..b4b3f94f457 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -272,7 +272,8 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); - Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DstarToPiKPiBkg)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + // Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DstarToD0Pi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -536,8 +537,7 @@ struct HfTreeCreatorDplusToPiKPi { } fillCandidateTable(candidate); } - } - else { + } else { if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); } else { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index ffadc82f95a..fa953571ce3 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -169,6 +169,13 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } + if (flag == 0 && createDstarDplusBkg) { + // D*± → D0(bar) π± + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { + flag = sign * (1 << DstarToPiKPiBkg); + } + } + // Check whether the particle is non-prompt (from a b quark). if (flag != 0) { origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); From 4bb93d22c44f481df455d3fa1eb2e490a8938d4c Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Thu, 20 Feb 2025 23:54:17 +0100 Subject: [PATCH 03/12] small fixes --- .../TableProducer/candidateCreator3Prong.cxx | 2 +- PWGHF/TableProducer/candidateCreatorMcGen.cxx | 3 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 64 +++++++++++-------- PWGHF/Utils/utilsMcGen.h | 4 +- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 6007de83bf3..10c1c333434 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -1066,7 +1066,7 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic, createDstarDplusBkg); } } diff --git a/PWGHF/TableProducer/candidateCreatorMcGen.cxx b/PWGHF/TableProducer/candidateCreatorMcGen.cxx index f2e9c685b55..0f7a077a138 100644 --- a/PWGHF/TableProducer/candidateCreatorMcGen.cxx +++ b/PWGHF/TableProducer/candidateCreatorMcGen.cxx @@ -50,6 +50,7 @@ struct HfCandidateCreatorMcGen { Configurable createDs{"createDs", false, "Create Ds in 3 prong"}; Configurable createLc{"createLc", false, "Create Lc in 3 prong"}; Configurable createXic{"createXic", false, "Create Xic in 3 prong"}; + Configurable createDstarToPiKPiBkg{"createDstarToPiKPiBkg", false, "Create DstarBkg in 3 prong"}; Preslice mcParticlesPerMcCollision = aod::mcparticle::mcCollisionId; @@ -63,7 +64,7 @@ struct HfCandidateCreatorMcGen { hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong); } if (fill3Prong) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, createDplus, createDs, createLc, createXic); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg); } } if (fillBplus) { diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index b4b3f94f457..5342a0c0138 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -23,12 +23,10 @@ #include "PWGHF/Core/HfHelper.h" #include "PWGHF/DataModel/CandidateReconstructionTables.h" #include "PWGHF/DataModel/CandidateSelectionTables.h" -#include "PWGHF/Core/CentralityEstimation.h" using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; -using namespace o2::hf_centrality; namespace o2::aod { @@ -295,6 +293,7 @@ struct HfTreeCreatorDplusToPiKPi { template void fillCandidateTable(const T& candidate) { + LOG(info) << "fillCandidateTable"; int8_t flagMc = 0; int8_t originMc = 0; int8_t channelMc = 0; @@ -316,6 +315,7 @@ struct HfTreeCreatorDplusToPiKPi { auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { + LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; rowCandidateLite( candidate.chi2PCA(), candidate.decayLength(), @@ -362,6 +362,7 @@ struct HfTreeCreatorDplusToPiKPi { originMc, channelMc); } else if (fillOnlySignalMl) { + LOG(info) << "in filler fillOnlySignalMl: " << fillOnlySignalMl; auto collision = candidate.template collision_as(); double cent = getCentralityColl(collision, CentralityEstimator::FT0C); rowCandidateMl( @@ -456,18 +457,19 @@ struct HfTreeCreatorDplusToPiKPi { originMc, channelMc); } + LOG(info) << "End fillCandidateTable"; } - - void processData(aod::Collisions const& collisions, - soa::Filtered> const& candidates, - TracksWPid const&) + + void processData(aod::Collisions const& collisions, + soa::Filtered> const& candidates, + TracksWPid const&) { // Filling event properties rowCandidateFullEvents.reserve(collisions.size()); for (const auto& collision : collisions) { fillEvent(collision, 0, 1); } - + // Filling candidate properties if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); @@ -484,9 +486,9 @@ struct HfTreeCreatorDplusToPiKPi { fillCandidateTable(candidate); } } - + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processData, "Process data", true); - + void processMc(aod::Collisions const& collisions, aod::McCollisions const&, SelectedCandidatesMc const& candidates, @@ -494,25 +496,30 @@ struct HfTreeCreatorDplusToPiKPi { SelectedCandidatesMcWithMl const& candidateswithml, McRecoCollisionsCent const&, TracksWPid const&) - { - // Filling event properties - rowCandidateFullEvents.reserve(collisions.size()); - for (const auto& collision : collisions) { - fillEvent(collision, 0, 1); - } - - // Filling candidate properties - if (fillOnlySignal) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSig.size()); - } else { - rowCandidateFull.reserve(reconstructedCandSig.size()); - } - for (const auto& candidate : reconstructedCandSig) { - fillCandidateTable(candidate); - } - } else if (fillOnlyBackground) { - if (fillCandidateLiteTable) { + { + LOG(info) << "Process MC"; + // Filling event properties + rowCandidateFullEvents.reserve(collisions.size()); + for (const auto& collision : collisions) { + fillEvent(collision, 0, 1); + } + + LOG(info) << "fillOnlySignal: " << fillOnlySignal; + LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; + // Filling candidate properties + if (fillOnlySignal) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSig.size()); + } else { + rowCandidateFull.reserve(reconstructedCandSig.size()); + } + LOG(info) << "reconstructedCandSig.size(): " << reconstructedCandSig.size(); + for (const auto& candidate : reconstructedCandSig) { + LOG(info) << "fillCandidateTable(candidate)"; + fillCandidateTable(candidate); + } + } else if (fillOnlyBackground) { + if (fillCandidateLiteTable) { rowCandidateLite.reserve(reconstructedCandBkg.size()); } else { rowCandidateFull.reserve(reconstructedCandBkg.size()); @@ -527,6 +534,7 @@ struct HfTreeCreatorDplusToPiKPi { fillCandidateTable(candidate); } } else if (fillOnlySignalMl) { + LOG(info) << "fillOnlySignalMl: " << fillOnlySignalMl; rowCandidateMl.reserve(candidateswithml.size()); for (const auto& candidate : candidateswithml) { if (downSampleBkgFactor < 1.) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index fa953571ce3..ae0bdeaee34 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -79,7 +79,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } template -void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool createDplus, bool createDs, bool createLc, bool createXic) +void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool createDplus, bool createDs, bool createLc, bool createXic, bool createDstarDplusBkg) { using namespace o2::constants::physics; @@ -172,7 +172,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V if (flag == 0 && createDstarDplusBkg) { // D*± → D0(bar) π± if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { - flag = sign * (1 << DstarToPiKPiBkg); + flag = sign * (1 << o2::aod::hf_cand_3prong::DstarToPiKPiBkg); } } From a1d4559b89c58cf3a8a2d858bba79c7490d60980 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 21 Feb 2025 11:52:30 +0100 Subject: [PATCH 04/12] remove comments --- .../TableProducer/candidateCreator3Prong.cxx | 17 +-- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 121 ++++++++---------- 2 files changed, 62 insertions(+), 76 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 10c1c333434..c0d573d0062 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -85,7 +85,7 @@ struct HfCandidateCreator3Prong { Configurable createDs{"createDs", false, "enable Ds+/- candidate creation"}; Configurable createLc{"createLc", false, "enable Lc+/- candidate creation"}; Configurable createXic{"createXic", false, "enable Xic+/- candidate creation"}; - Configurable createDstarDplusBkg{"createDstarDplusBkg", false, "enable D* candidate creation"}; + Configurable createDstarToPiKPiBkg{"createDstarToPiKPiBkg", false, "enable D* candidate creation"}; HfEventSelection hfEvSel; // event selection and monitoring o2::vertexing::DCAFitterN<3> df; // 3-prong vertex fitter @@ -145,7 +145,7 @@ struct HfCandidateCreator3Prong { } } - std::array creationFlags = {createDplus, createDs, createLc, createXic, createDstarDplusBkg}; + std::array creationFlags = {createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg}; if (std::accumulate(creationFlags.begin(), creationFlags.end(), 0) == 0) { LOGP(fatal, "At least one particle specie should be enabled for the creation."); } @@ -792,7 +792,7 @@ struct HfCandidateCreator3ProngExpressions { bool createDs{false}; bool createLc{false}; bool createXic{false}; - bool createDstarDplusBkg{false}; + bool createDstarToPiKPiBkg{false}; HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring using BCsInfo = soa::Join; @@ -828,8 +828,8 @@ struct HfCandidateCreator3ProngExpressions { createLc = option.defaultValue.get(); } else if (option.name.compare("createXic") == 0) { createXic = option.defaultValue.get(); - } else if (option.name.compare("createDstarDplusBkg") == 0) { - createDstarDplusBkg = option.defaultValue.get(); + } else if (option.name.compare("createDstarToPiKPiBkg") == 0) { + createDstarToPiKPiBkg = option.defaultValue.get(); } } break; @@ -843,7 +843,7 @@ struct HfCandidateCreator3ProngExpressions { LOGP(info, " --> createDs = {}", createDs); LOGP(info, " --> createLc = {}", createLc); LOGP(info, " --> createXic = {}", createXic); - LOGP(info, " --> createDstarDplusBkg = {}", createDstarDplusBkg); + LOGP(info, " --> createDstarToPiKPiBkg = {}", createDstarToPiKPiBkg); } /// Performs MC matching. @@ -964,7 +964,7 @@ struct HfCandidateCreator3ProngExpressions { } // D* → D0π → Kππ - if (flag == 0 && createDstarDplusBkg) { + if (flag == 0 && createDstarToPiKPiBkg) { if (matchKinkedDecayTopology) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); } else { @@ -972,6 +972,7 @@ struct HfCandidateCreator3ProngExpressions { } if (indexRec > -1) { flag = sign * (1 << DstarToPiKPiBkg); + channel = 1; } } @@ -1066,7 +1067,7 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic, createDstarDplusBkg); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg); } } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 5342a0c0138..e714aaab0e4 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -82,17 +82,13 @@ DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! Run number DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Collision centrality (for reco MC) // ML scores DECLARE_SOA_COLUMN(BkgScore, bkgScore, float); //! Bkg score (for reco MC candidates) +DECLARE_SOA_COLUMN(PromptScore, promptScore, float); //! Prompt score (for reco MC candidates) DECLARE_SOA_COLUMN(FdScore, fdScore, float); //! FD score (for reco MC candidates) } // namespace full -DECLARE_SOA_TABLE(HfCandDpMls, "AOD", "HFCANDDPML", - full::M, - full::Pt, - full::Centrality, +DECLARE_SOA_TABLE(HfCandDpMlScores, "AOD", "HFCANDDPMLSCORES", full::BkgScore, - full::FdScore, - hf_cand_3prong::FlagMcMatchRec, - hf_cand_3prong::OriginMcRec, - hf_cand_3prong::FlagMcDecayChanRec) + full::FdScore) + DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE", hf_cand::Chi2PCA, full::DecayLength, @@ -245,13 +241,13 @@ struct HfTreeCreatorDplusToPiKPi { Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; - Produces rowCandidateMl; + Produces rowCandidateMl; Configurable selectionFlagDplus{"selectionFlagDplus", 1, "Selection Flag for Dplus"}; 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 fillOnlySignalMl{"fillOnlySignalMl", false, "Flag to fill derived tables with MC and ML info"}; + Configurable fillMlScores{"fillMlScores", false, "Flag to fill derived tables with ML info"}; 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"}; @@ -271,7 +267,6 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DstarToPiKPiBkg)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± - // Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DstarToD0Pi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -303,11 +298,15 @@ struct HfTreeCreatorDplusToPiKPi { channelMc = candidate.flagMcDecayChanRec(); } - std::vector outputMl = {-999., -999.}; if constexpr (doMl) { + std::vector outputMl = {-999., -999.}; for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; } + rowCandidateMl( + outputMl[0], + outputMl[1] + ); } auto prong0 = candidate.template prong0_as(); @@ -315,7 +314,6 @@ struct HfTreeCreatorDplusToPiKPi { auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { - LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; rowCandidateLite( candidate.chi2PCA(), candidate.decayLength(), @@ -361,20 +359,6 @@ struct HfTreeCreatorDplusToPiKPi { flagMc, originMc, channelMc); - } else if (fillOnlySignalMl) { - LOG(info) << "in filler fillOnlySignalMl: " << fillOnlySignalMl; - auto collision = candidate.template collision_as(); - double cent = getCentralityColl(collision, CentralityEstimator::FT0C); - rowCandidateMl( - hfHelper.invMassDplusToPiKPi(candidate), - candidate.pt(), - cent, - outputMl[0], - outputMl[1], - flagMc, - originMc, - channelMc - ); } else { rowCandidateFull( candidate.collision().bcId(), @@ -497,45 +481,22 @@ struct HfTreeCreatorDplusToPiKPi { McRecoCollisionsCent const&, TracksWPid const&) { - LOG(info) << "Process MC"; - // Filling event properties - rowCandidateFullEvents.reserve(collisions.size()); - for (const auto& collision : collisions) { - fillEvent(collision, 0, 1); - } - - LOG(info) << "fillOnlySignal: " << fillOnlySignal; - LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; - // Filling candidate properties - if (fillOnlySignal) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSig.size()); - } else { - rowCandidateFull.reserve(reconstructedCandSig.size()); - } - LOG(info) << "reconstructedCandSig.size(): " << reconstructedCandSig.size(); - for (const auto& candidate : reconstructedCandSig) { - LOG(info) << "fillCandidateTable(candidate)"; - fillCandidateTable(candidate); - } - } else if (fillOnlyBackground) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandBkg.size()); + LOG(info) << "Process MC"; + // Filling event properties + rowCandidateFullEvents.reserve(collisions.size()); + for (const auto& collision : collisions) { + fillEvent(collision, 0, 1); + } + + // Filling candidate properties + if (fillOnlySignal) { + if (fillMlScores) { + rowCandidateMl.reserve(reconstructedCandSigMl.size()); + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSigMl.size()); } else { - rowCandidateFull.reserve(reconstructedCandBkg.size()); + rowCandidateFull.reserve(reconstructedCandSigMl.size()); } - for (const auto& candidate : reconstructedCandBkg) { - if (downSampleBkgFactor < 1.) { - float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); - if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { - continue; - } - } - fillCandidateTable(candidate); - } - } else if (fillOnlySignalMl) { - LOG(info) << "fillOnlySignalMl: " << fillOnlySignalMl; - rowCandidateMl.reserve(candidateswithml.size()); for (const auto& candidate : candidateswithml) { if (downSampleBkgFactor < 1.) { float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); @@ -545,16 +506,40 @@ struct HfTreeCreatorDplusToPiKPi { } fillCandidateTable(candidate); } - } else { + } else if (fillCandidateLiteTable) { - rowCandidateLite.reserve(candidates.size()); + rowCandidateLite.reserve(reconstructedCandSig.size()); } else { - rowCandidateFull.reserve(candidates.size()); + rowCandidateFull.reserve(reconstructedCandSig.size()); } - for (const auto& candidate : candidates) { + for (const auto& candidate : reconstructedCandSig) { fillCandidateTable(candidate); } + } else if (fillOnlyBackground) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandBkg.size()); + } else { + rowCandidateFull.reserve(reconstructedCandBkg.size()); + } + for (const auto& candidate : reconstructedCandBkg) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; + } + } + fillCandidateTable(candidate); } + } else { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(candidates.size()); + } else { + rowCandidateFull.reserve(candidates.size()); + } + for (const auto& candidate : candidates) { + fillCandidateTable(candidate); + } + } // Filling particle properties rowCandidateFullParticles.reserve(particles.size()); From eebb3d6e3266b24be459dbb6c3a7de60e41e3f35 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 21 Feb 2025 15:47:00 +0100 Subject: [PATCH 05/12] rename variables --- PWGHF/TableProducer/candidateCreator3Prong.cxx | 1 + PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx | 8 ++++++-- PWGHF/Utils/utilsMcGen.h | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index c0d573d0062..c68b3d3f47d 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -971,6 +971,7 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); } if (indexRec > -1) { + LOG(info) << "MATCHED DSTAR"; flag = sign * (1 << DstarToPiKPiBkg); channel = 1; } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index e714aaab0e4..2686cc45fc0 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -85,6 +85,7 @@ DECLARE_SOA_COLUMN(BkgScore, bkgScore, float); //! Bkg score (for reco MC DECLARE_SOA_COLUMN(PromptScore, promptScore, float); //! Prompt score (for reco MC candidates) DECLARE_SOA_COLUMN(FdScore, fdScore, float); //! FD score (for reco MC candidates) } // namespace full + DECLARE_SOA_TABLE(HfCandDpMlScores, "AOD", "HFCANDDPMLSCORES", full::BkgScore, full::FdScore) @@ -299,6 +300,7 @@ struct HfTreeCreatorDplusToPiKPi { } if constexpr (doMl) { + LOG(info) << "fillMl"; std::vector outputMl = {-999., -999.}; for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; @@ -314,6 +316,7 @@ struct HfTreeCreatorDplusToPiKPi { auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { + LOG(info) << "fillLite"; rowCandidateLite( candidate.chi2PCA(), candidate.decayLength(), @@ -481,7 +484,6 @@ struct HfTreeCreatorDplusToPiKPi { McRecoCollisionsCent const&, TracksWPid const&) { - LOG(info) << "Process MC"; // Filling event properties rowCandidateFullEvents.reserve(collisions.size()); for (const auto& collision : collisions) { @@ -497,6 +499,7 @@ struct HfTreeCreatorDplusToPiKPi { } else { rowCandidateFull.reserve(reconstructedCandSigMl.size()); } + LOG(info) << "Fill candidate with ml"; for (const auto& candidate : candidateswithml) { if (downSampleBkgFactor < 1.) { float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); @@ -506,7 +509,7 @@ struct HfTreeCreatorDplusToPiKPi { } fillCandidateTable(candidate); } - } else + } else { if (fillCandidateLiteTable) { rowCandidateLite.reserve(reconstructedCandSig.size()); } else { @@ -515,6 +518,7 @@ struct HfTreeCreatorDplusToPiKPi { for (const auto& candidate : reconstructedCandSig) { fillCandidateTable(candidate); } + } } else if (fillOnlyBackground) { if (fillCandidateLiteTable) { rowCandidateLite.reserve(reconstructedCandBkg.size()); diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index ae0bdeaee34..63db860bc2a 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -79,7 +79,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } template -void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool createDplus, bool createDs, bool createLc, bool createXic, bool createDstarDplusBkg) +void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool createDplus, bool createDs, bool createLc, bool createXic, bool createDstarToPiKPiBkg) { using namespace o2::constants::physics; @@ -169,7 +169,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } - if (flag == 0 && createDstarDplusBkg) { + if (flag == 0 && createDstarToPiKPiBkg) { // D*± → D0(bar) π± if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { flag = sign * (1 << o2::aod::hf_cand_3prong::DstarToPiKPiBkg); From b256fe9b8173f63055e8936642c7837bebec42b0 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 21 Feb 2025 17:58:52 +0100 Subject: [PATCH 06/12] reduce scores table --- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 136 +++++++++--------- 1 file changed, 71 insertions(+), 65 deletions(-) diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 2686cc45fc0..7144de9f4dc 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -82,13 +82,12 @@ DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! Run number DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Collision centrality (for reco MC) // ML scores DECLARE_SOA_COLUMN(BkgScore, bkgScore, float); //! Bkg score (for reco MC candidates) -DECLARE_SOA_COLUMN(PromptScore, promptScore, float); //! Prompt score (for reco MC candidates) DECLARE_SOA_COLUMN(FdScore, fdScore, float); //! FD score (for reco MC candidates) } // namespace full - -DECLARE_SOA_TABLE(HfCandDpMlScores, "AOD", "HFCANDDPMLSCORES", +DECLARE_SOA_TABLE(HfCandDpMls, "AOD", "HFCANDDPML", + full::Centrality, full::BkgScore, - full::FdScore) + full::FdScore,) DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE", hf_cand::Chi2PCA, @@ -242,13 +241,13 @@ struct HfTreeCreatorDplusToPiKPi { Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; - Produces rowCandidateMl; + Produces rowCandidateMl; Configurable selectionFlagDplus{"selectionFlagDplus", 1, "Selection Flag for Dplus"}; 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 fillMlScores{"fillMlScores", false, "Flag to fill derived tables with ML info"}; + Configurable fillOnlySignalMl{"fillOnlySignalMl", false, "Flag to fill derived tables with MC and ML info"}; 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"}; @@ -268,6 +267,7 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DstarToPiKPiBkg)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± + // Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DstarToD0Pi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -299,15 +299,18 @@ struct HfTreeCreatorDplusToPiKPi { channelMc = candidate.flagMcDecayChanRec(); } + std::vector outputMl = {-999., -999.}; if constexpr (doMl) { - LOG(info) << "fillMl"; - std::vector outputMl = {-999., -999.}; + LOG(info) << "in filler fillOnlySignalMl: " << fillOnlySignalMl; for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; } + auto collision = candidate.template collision_as(); + double cent = getCentralityColl(collision, CentralityEstimator::FT0C); rowCandidateMl( + cent, outputMl[0], - outputMl[1] + outputMl[1], ); } @@ -316,7 +319,7 @@ struct HfTreeCreatorDplusToPiKPi { auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { - LOG(info) << "fillLite"; + LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; rowCandidateLite( candidate.chi2PCA(), candidate.decayLength(), @@ -484,66 +487,69 @@ struct HfTreeCreatorDplusToPiKPi { McRecoCollisionsCent const&, TracksWPid const&) { - // Filling event properties - rowCandidateFullEvents.reserve(collisions.size()); - for (const auto& collision : collisions) { - fillEvent(collision, 0, 1); - } - - // Filling candidate properties - if (fillOnlySignal) { - if (fillMlScores) { - rowCandidateMl.reserve(reconstructedCandSigMl.size()); - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSigMl.size()); - } else { - rowCandidateFull.reserve(reconstructedCandSigMl.size()); - } - LOG(info) << "Fill candidate with ml"; - for (const auto& candidate : candidateswithml) { - if (downSampleBkgFactor < 1.) { - float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); - if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { - continue; + LOG(info) << "Process MC"; + // Filling event properties + rowCandidateFullEvents.reserve(collisions.size()); + for (const auto& collision : collisions) { + fillEvent(collision, 0, 1); + } + + LOG(info) << "fillOnlySignal: " << fillOnlySignal; + LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; + // Filling candidate properties + if (fillOnlySignal) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSig.size()); + } else { + rowCandidateFull.reserve(reconstructedCandSig.size()); + } + LOG(info) << "reconstructedCandSig.size(): " << reconstructedCandSig.size(); + for (const auto& candidate : reconstructedCandSig) { + LOG(info) << "fillCandidateTable(candidate)"; + fillCandidateTable(candidate); + } + } else if (fillOnlySignalMl) { + LOG(info) << "fillOnlySignalMl: " << fillOnlySignalMl; + rowCandidateMl.reserve(reconstructedCandSigMl.size()); + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSigMl.size()); + } else { + rowCandidateFull.reserve(reconstructedCandSigMl.size()); + } + for (const auto& candidate : reconstructedCandSigMl) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; + } } + fillCandidateTable(candidate); + } + } else if (fillOnlyBackground) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandBkg.size()); + } else { + rowCandidateFull.reserve(reconstructedCandBkg.size()); + } + for (const auto& candidate : reconstructedCandBkg) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; + } + } + fillCandidateTable(candidate); } - fillCandidateTable(candidate); - } - } else { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSig.size()); } else { - rowCandidateFull.reserve(reconstructedCandSig.size()); - } - for (const auto& candidate : reconstructedCandSig) { - fillCandidateTable(candidate); - } - } - } else if (fillOnlyBackground) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandBkg.size()); - } else { - rowCandidateFull.reserve(reconstructedCandBkg.size()); - } - for (const auto& candidate : reconstructedCandBkg) { - if (downSampleBkgFactor < 1.) { - float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); - if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { - continue; + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(candidates.size()); + } else { + rowCandidateFull.reserve(candidates.size()); + } + for (const auto& candidate : candidates) { + fillCandidateTable(candidate); } } - fillCandidateTable(candidate); - } - } else { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(candidates.size()); - } else { - rowCandidateFull.reserve(candidates.size()); - } - for (const auto& candidate : candidates) { - fillCandidateTable(candidate); - } - } // Filling particle properties rowCandidateFullParticles.reserve(particles.size()); From 6c2f294c99a4e2567a7e05c0c45db3b6b0253335 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Fri, 21 Feb 2025 23:31:33 +0100 Subject: [PATCH 07/12] remove centrality and debug prints --- .../TableProducer/candidateCreator3Prong.cxx | 1 - .../TableProducer/treeCreatorDplusToPiKPi.cxx | 30 ++++--------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index c68b3d3f47d..c0d573d0062 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -971,7 +971,6 @@ struct HfCandidateCreator3ProngExpressions { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2); } if (indexRec > -1) { - LOG(info) << "MATCHED DSTAR"; flag = sign * (1 << DstarToPiKPiBkg); channel = 1; } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 7144de9f4dc..97ed081912f 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -79,15 +79,13 @@ DECLARE_SOA_COLUMN(Ct, ct, float); // Events DECLARE_SOA_COLUMN(IsEventReject, isEventReject, int); //! Event rejection flag DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! Run number -DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Collision centrality (for reco MC) // ML scores -DECLARE_SOA_COLUMN(BkgScore, bkgScore, float); //! Bkg score (for reco MC candidates) -DECLARE_SOA_COLUMN(FdScore, fdScore, float); //! FD score (for reco MC candidates) +DECLARE_SOA_COLUMN(MlScore0, mlScore0, float); //! ML score of the first configured index +DECLARE_SOA_COLUMN(MlScore1, mlScore1, float); //! ML score of the second configured index } // namespace full DECLARE_SOA_TABLE(HfCandDpMls, "AOD", "HFCANDDPML", - full::Centrality, - full::BkgScore, - full::FdScore,) + full::MlScore0, + full::MlScore1) DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE", hf_cand::Chi2PCA, @@ -259,7 +257,6 @@ struct HfTreeCreatorDplusToPiKPi { using MatchedGenCandidatesMc = soa::Filtered>; using SelectedCandidatesMcWithMl = soa::Filtered>; using TracksWPid = soa::Join; - using McRecoCollisionsCent = soa::Join; Filter filterSelectCandidates = aod::hf_sel_candidate_dplus::isSelDplusToPiKPi >= selectionFlagDplus; Filter filterMcGenMatching = nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); @@ -267,7 +264,6 @@ struct HfTreeCreatorDplusToPiKPi { Partition reconstructedCandSig = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± Partition reconstructedCandBkg = nabs(aod::hf_cand_3prong::flagMcMatchRec) != static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)); Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DstarToPiKPiBkg)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± - // Partition reconstructedCandSigMl = nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DsToKKPi)) || nabs(aod::hf_cand_3prong::flagMcMatchRec) == static_cast(BIT(aod::hf_cand_3prong::DecayType::DstarToD0Pi)); // DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π± void init(InitContext const&) { @@ -289,7 +285,6 @@ struct HfTreeCreatorDplusToPiKPi { template void fillCandidateTable(const T& candidate) { - LOG(info) << "fillCandidateTable"; int8_t flagMc = 0; int8_t originMc = 0; int8_t channelMc = 0; @@ -301,16 +296,12 @@ struct HfTreeCreatorDplusToPiKPi { std::vector outputMl = {-999., -999.}; if constexpr (doMl) { - LOG(info) << "in filler fillOnlySignalMl: " << fillOnlySignalMl; for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; } - auto collision = candidate.template collision_as(); - double cent = getCentralityColl(collision, CentralityEstimator::FT0C); rowCandidateMl( - cent, outputMl[0], - outputMl[1], + outputMl[1] ); } @@ -319,7 +310,6 @@ struct HfTreeCreatorDplusToPiKPi { auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { - LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; rowCandidateLite( candidate.chi2PCA(), candidate.decayLength(), @@ -447,7 +437,6 @@ struct HfTreeCreatorDplusToPiKPi { originMc, channelMc); } - LOG(info) << "End fillCandidateTable"; } void processData(aod::Collisions const& collisions, @@ -480,22 +469,18 @@ struct HfTreeCreatorDplusToPiKPi { PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processData, "Process data", true); void processMc(aod::Collisions const& collisions, - aod::McCollisions const&, + aod::McCollisions const& mccollisions, SelectedCandidatesMc const& candidates, MatchedGenCandidatesMc const& particles, SelectedCandidatesMcWithMl const& candidateswithml, - McRecoCollisionsCent const&, TracksWPid const&) { - LOG(info) << "Process MC"; // Filling event properties rowCandidateFullEvents.reserve(collisions.size()); for (const auto& collision : collisions) { fillEvent(collision, 0, 1); } - LOG(info) << "fillOnlySignal: " << fillOnlySignal; - LOG(info) << "fillCandidateLiteTable: " << fillCandidateLiteTable; // Filling candidate properties if (fillOnlySignal) { if (fillCandidateLiteTable) { @@ -503,13 +488,10 @@ struct HfTreeCreatorDplusToPiKPi { } else { rowCandidateFull.reserve(reconstructedCandSig.size()); } - LOG(info) << "reconstructedCandSig.size(): " << reconstructedCandSig.size(); for (const auto& candidate : reconstructedCandSig) { - LOG(info) << "fillCandidateTable(candidate)"; fillCandidateTable(candidate); } } else if (fillOnlySignalMl) { - LOG(info) << "fillOnlySignalMl: " << fillOnlySignalMl; rowCandidateMl.reserve(reconstructedCandSigMl.size()); if (fillCandidateLiteTable) { rowCandidateLite.reserve(reconstructedCandSigMl.size()); From 98473c5bdcc3eb252b921945ed6a6929a6d09057 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sat, 22 Feb 2025 00:27:29 +0100 Subject: [PATCH 08/12] Solve conflicts --- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 118 +++++++++--------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 97ed081912f..6535352d86f 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -308,7 +308,7 @@ struct HfTreeCreatorDplusToPiKPi { auto prong0 = candidate.template prong0_as(); auto prong1 = candidate.template prong1_as(); auto prong2 = candidate.template prong2_as(); - + if (fillCandidateLiteTable) { rowCandidateLite( candidate.chi2PCA(), @@ -438,17 +438,17 @@ struct HfTreeCreatorDplusToPiKPi { channelMc); } } - - void processData(aod::Collisions const& collisions, - soa::Filtered> const& candidates, - TracksWPid const&) + + void processData(aod::Collisions const& collisions, + soa::Filtered> const& candidates, + TracksWPid const&) { // Filling event properties rowCandidateFullEvents.reserve(collisions.size()); for (const auto& collision : collisions) { fillEvent(collision, 0, 1); } - + // Filling candidate properties if (fillCandidateLiteTable) { rowCandidateLite.reserve(candidates.size()); @@ -465,73 +465,73 @@ struct HfTreeCreatorDplusToPiKPi { fillCandidateTable(candidate); } } - + PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processData, "Process data", true); void processMc(aod::Collisions const& collisions, - aod::McCollisions const& mccollisions, + aod::McCollisions const&, SelectedCandidatesMc const& candidates, MatchedGenCandidatesMc const& particles, SelectedCandidatesMcWithMl const& candidateswithml, TracksWPid const&) - { - // Filling event properties - rowCandidateFullEvents.reserve(collisions.size()); - for (const auto& collision : collisions) { - fillEvent(collision, 0, 1); - } + { + // Filling event properties + rowCandidateFullEvents.reserve(collisions.size()); + for (const auto& collision : collisions) { + fillEvent(collision, 0, 1); + } - // Filling candidate properties - if (fillOnlySignal) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSig.size()); - } else { - rowCandidateFull.reserve(reconstructedCandSig.size()); - } - for (const auto& candidate : reconstructedCandSig) { - fillCandidateTable(candidate); - } - } else if (fillOnlySignalMl) { - rowCandidateMl.reserve(reconstructedCandSigMl.size()); - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandSigMl.size()); - } else { - rowCandidateFull.reserve(reconstructedCandSigMl.size()); - } - for (const auto& candidate : reconstructedCandSigMl) { - if (downSampleBkgFactor < 1.) { - float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); - if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { - continue; - } + // Filling candidate properties + if (fillOnlySignal) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSig.size()); + } else { + rowCandidateFull.reserve(reconstructedCandSig.size()); + } + for (const auto& candidate : reconstructedCandSig) { + fillCandidateTable(candidate); + } + } else if (fillOnlySignalMl) { + rowCandidateMl.reserve(reconstructedCandSigMl.size()); + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandSigMl.size()); + } else { + rowCandidateFull.reserve(reconstructedCandSigMl.size()); + } + for (const auto& candidate : reconstructedCandSigMl) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - (int64_t)(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; } - fillCandidateTable(candidate); } - } else if (fillOnlyBackground) { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(reconstructedCandBkg.size()); - } else { - rowCandidateFull.reserve(reconstructedCandBkg.size()); - } - for (const auto& candidate : reconstructedCandBkg) { - if (downSampleBkgFactor < 1.) { - float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); - if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { - continue; - } + fillCandidateTable(candidate); + } + } else if (fillOnlyBackground) { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(reconstructedCandBkg.size()); + } else { + rowCandidateFull.reserve(reconstructedCandBkg.size()); + } + for (const auto& candidate : reconstructedCandBkg) { + if (downSampleBkgFactor < 1.) { + float pseudoRndm = candidate.ptProng0() * 1000. - static_cast(candidate.ptProng0() * 1000); + if (candidate.pt() < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) { + continue; } - fillCandidateTable(candidate); } + fillCandidateTable(candidate); + } + } else { + if (fillCandidateLiteTable) { + rowCandidateLite.reserve(candidates.size()); } else { - if (fillCandidateLiteTable) { - rowCandidateLite.reserve(candidates.size()); - } else { - rowCandidateFull.reserve(candidates.size()); - } - for (const auto& candidate : candidates) { - fillCandidateTable(candidate); - } + rowCandidateFull.reserve(candidates.size()); } + for (const auto& candidate : candidates) { + fillCandidateTable(candidate); + } + } // Filling particle properties rowCandidateFullParticles.reserve(particles.size()); From b329854297a3513498f5d51b874613c43187adc9 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Fri, 21 Feb 2025 23:29:00 +0000 Subject: [PATCH 09/12] Please consider the following formatting changes --- .../TableProducer/candidateCreator3Prong.cxx | 2 +- .../TableProducer/treeCreatorDplusToPiKPi.cxx | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index c0d573d0062..40aaf96839c 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -830,7 +830,7 @@ struct HfCandidateCreator3ProngExpressions { createXic = option.defaultValue.get(); } else if (option.name.compare("createDstarToPiKPiBkg") == 0) { createDstarToPiKPiBkg = option.defaultValue.get(); - } + } } break; } diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 6535352d86f..72bb221be9d 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -80,12 +80,12 @@ DECLARE_SOA_COLUMN(Ct, ct, float); DECLARE_SOA_COLUMN(IsEventReject, isEventReject, int); //! Event rejection flag DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! Run number // ML scores -DECLARE_SOA_COLUMN(MlScore0, mlScore0, float); //! ML score of the first configured index -DECLARE_SOA_COLUMN(MlScore1, mlScore1, float); //! ML score of the second configured index +DECLARE_SOA_COLUMN(MlScore0, mlScore0, float); //! ML score of the first configured index +DECLARE_SOA_COLUMN(MlScore1, mlScore1, float); //! ML score of the second configured index } // namespace full DECLARE_SOA_TABLE(HfCandDpMls, "AOD", "HFCANDDPML", - full::MlScore0, - full::MlScore1) + full::MlScore0, + full::MlScore1) DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE", hf_cand::Chi2PCA, @@ -293,7 +293,7 @@ struct HfTreeCreatorDplusToPiKPi { originMc = candidate.originMcRec(); channelMc = candidate.flagMcDecayChanRec(); } - + std::vector outputMl = {-999., -999.}; if constexpr (doMl) { for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { @@ -301,10 +301,9 @@ struct HfTreeCreatorDplusToPiKPi { } rowCandidateMl( outputMl[0], - outputMl[1] - ); + outputMl[1]); } - + auto prong0 = candidate.template prong0_as(); auto prong1 = candidate.template prong1_as(); auto prong2 = candidate.template prong2_as(); @@ -355,7 +354,7 @@ struct HfTreeCreatorDplusToPiKPi { flagMc, originMc, channelMc); - } else { + } else { rowCandidateFull( candidate.collision().bcId(), candidate.collision().numContrib(), @@ -436,8 +435,8 @@ struct HfTreeCreatorDplusToPiKPi { flagMc, originMc, channelMc); - } } + } void processData(aod::Collisions const& collisions, soa::Filtered> const& candidates, @@ -467,7 +466,7 @@ struct HfTreeCreatorDplusToPiKPi { } PROCESS_SWITCH(HfTreeCreatorDplusToPiKPi, processData, "Process data", true); - + void processMc(aod::Collisions const& collisions, aod::McCollisions const&, SelectedCandidatesMc const& candidates, @@ -480,7 +479,7 @@ struct HfTreeCreatorDplusToPiKPi { for (const auto& collision : collisions) { fillEvent(collision, 0, 1); } - + // Filling candidate properties if (fillOnlySignal) { if (fillCandidateLiteTable) { From ba768d312778e9ccd0535c4d7fcd0dd36e758404 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sat, 22 Feb 2025 00:46:11 +0100 Subject: [PATCH 10/12] removed unused parameter --- PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx index 72bb221be9d..b75aa3a4a3c 100644 --- a/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDplusToPiKPi.cxx @@ -471,7 +471,7 @@ struct HfTreeCreatorDplusToPiKPi { aod::McCollisions const&, SelectedCandidatesMc const& candidates, MatchedGenCandidatesMc const& particles, - SelectedCandidatesMcWithMl const& candidateswithml, + SelectedCandidatesMcWithMl const&, TracksWPid const&) { // Filling event properties From 820871746f6cbf6584339379604ee4128c6ddb89 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Sun, 23 Feb 2025 16:20:23 +0100 Subject: [PATCH 11/12] Implement Fabrizio's comment --- .../TableProducer/candidateCreator3Prong.cxx | 40 ++++--------------- PWGHF/TableProducer/candidateCreatorMcGen.cxx | 7 +--- PWGHF/Utils/utilsMcGen.h | 24 +++++------ 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 40aaf96839c..269abba89a2 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -85,7 +85,6 @@ struct HfCandidateCreator3Prong { Configurable createDs{"createDs", false, "enable Ds+/- candidate creation"}; Configurable createLc{"createLc", false, "enable Lc+/- candidate creation"}; Configurable createXic{"createXic", false, "enable Xic+/- candidate creation"}; - Configurable createDstarToPiKPiBkg{"createDstarToPiKPiBkg", false, "enable D* candidate creation"}; HfEventSelection hfEvSel; // event selection and monitoring o2::vertexing::DCAFitterN<3> df; // 3-prong vertex fitter @@ -145,7 +144,7 @@ struct HfCandidateCreator3Prong { } } - std::array creationFlags = {createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg}; + std::array creationFlags = {createDplus, createDs, createLc, createXic}; if (std::accumulate(creationFlags.begin(), creationFlags.end(), 0) == 0) { LOGP(fatal, "At least one particle specie should be enabled for the creation."); } @@ -788,12 +787,6 @@ struct HfCandidateCreator3ProngExpressions { o2::framework::Configurable matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"}; o2::framework::Configurable matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"}; - bool createDplus{false}; - bool createDs{false}; - bool createLc{false}; - bool createXic{false}; - bool createDstarToPiKPiBkg{false}; - HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring using BCsInfo = soa::Join; HistogramRegistry registry{"registry"}; @@ -819,31 +812,12 @@ struct HfCandidateCreator3ProngExpressions { for (const DeviceSpec& device : workflows.devices) { if (device.name.compare("hf-candidate-creator-3prong") == 0) { hfEvSelMc.configureFromDevice(device); - for (const auto& option : device.options) { - if (option.name.compare("createDplus") == 0) { - createDplus = option.defaultValue.get(); - } else if (option.name.compare("createDs") == 0) { - createDs = option.defaultValue.get(); - } else if (option.name.compare("createLc") == 0) { - createLc = option.defaultValue.get(); - } else if (option.name.compare("createXic") == 0) { - createXic = option.defaultValue.get(); - } else if (option.name.compare("createDstarToPiKPiBkg") == 0) { - createDstarToPiKPiBkg = option.defaultValue.get(); - } - } break; } } hfEvSelMc.addHistograms(registry); // particles monitoring - LOGP(info, "Flags for candidate creation from the reco workflow:"); - LOGP(info, " --> createDplus = {}", createDplus); - LOGP(info, " --> createDs = {}", createDs); - LOGP(info, " --> createLc = {}", createLc); - LOGP(info, " --> createXic = {}", createXic); - LOGP(info, " --> createDstarToPiKPiBkg = {}", createDstarToPiKPiBkg); } /// Performs MC matching. @@ -902,7 +876,7 @@ struct HfCandidateCreator3ProngExpressions { } // D± → π± K∓ π± - if (createDplus) { + 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) { @@ -918,7 +892,7 @@ struct HfCandidateCreator3ProngExpressions { } // Ds± → K± K∓ π± and D± → K± K∓ π± - if (flag == 0 && createDs) { + 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); @@ -964,7 +938,7 @@ struct HfCandidateCreator3ProngExpressions { } // D* → D0π → Kππ - if (flag == 0 && createDstarToPiKPiBkg) { + if (flag == 0) { if (matchKinkedDecayTopology) { indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2, &nKinkedTracks); } else { @@ -977,7 +951,7 @@ struct HfCandidateCreator3ProngExpressions { } // Λc± → p± K∓ π± - if (flag == 0 && createLc) { + 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) { @@ -1012,7 +986,7 @@ struct HfCandidateCreator3ProngExpressions { } // Ξc± → p± K∓ π± - if (flag == 0 && createXic) { + 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) { @@ -1067,7 +1041,7 @@ struct HfCandidateCreator3ProngExpressions { } continue; } - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen, rejectBackground); } } diff --git a/PWGHF/TableProducer/candidateCreatorMcGen.cxx b/PWGHF/TableProducer/candidateCreatorMcGen.cxx index 0f7a077a138..c27a2f8b734 100644 --- a/PWGHF/TableProducer/candidateCreatorMcGen.cxx +++ b/PWGHF/TableProducer/candidateCreatorMcGen.cxx @@ -46,11 +46,6 @@ struct HfCandidateCreatorMcGen { Configurable fillB0{"fillB0", false, "fill table for B0 candidates"}; Configurable rejectBackground2Prong{"rejectBackground2Prong", false, "Reject particles from PbPb background for 2 prong candidates"}; Configurable rejectBackground3Prong{"rejectBackground3Prong", false, "Reject particles from PbPb background for 3 prong candidates"}; - Configurable createDplus{"createDplus", false, "Create D+ in 3 prong"}; - Configurable createDs{"createDs", false, "Create Ds in 3 prong"}; - Configurable createLc{"createLc", false, "Create Lc in 3 prong"}; - Configurable createXic{"createXic", false, "Create Xic in 3 prong"}; - Configurable createDstarToPiKPiBkg{"createDstarToPiKPiBkg", false, "Create DstarBkg in 3 prong"}; Preslice mcParticlesPerMcCollision = aod::mcparticle::mcCollisionId; @@ -64,7 +59,7 @@ struct HfCandidateCreatorMcGen { hf_mc_gen::fillMcMatchGen2Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen2Prong, rejectBackground2Prong); } if (fill3Prong) { - hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong, createDplus, createDs, createLc, createXic, createDstarToPiKPiBkg); + hf_mc_gen::fillMcMatchGen3Prong(mcParticles, mcParticlesPerMcColl, rowMcMatchGen3Prong, rejectBackground3Prong); } } if (fillBplus) { diff --git a/PWGHF/Utils/utilsMcGen.h b/PWGHF/Utils/utilsMcGen.h index 63db860bc2a..23fcbe6d61d 100644 --- a/PWGHF/Utils/utilsMcGen.h +++ b/PWGHF/Utils/utilsMcGen.h @@ -79,7 +79,7 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } template -void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground, bool createDplus, bool createDs, bool createLc, bool createXic, bool createDstarToPiKPiBkg) +void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V& rowMcMatchGen, bool rejectBackground) { using namespace o2::constants::physics; @@ -104,14 +104,14 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // D± → π± K∓ π± - if (createDplus) { + if (flag == 0) { if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) { flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::DplusToPiKPi); } } // Ds± → K± K∓ π± and D± → K± K∓ π± - if (flag == 0 && createDs) { + 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∓ π± @@ -139,8 +139,15 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } } + // D*± → D0(bar) π± + if (flag == 0) { + if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { + flag = sign * (1 << o2::aod::hf_cand_3prong::DstarToPiKPiBkg); + } + } + // Λc± → p± K∓ π± - if (flag == 0 && createLc) { + if (flag == 0) { if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::LcToPKPi); @@ -163,19 +170,12 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V } // Ξc± → p± K∓ π± - if (flag == 0 && createXic) { + if (flag == 0) { if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) { flag = sign * (1 << o2::aod::hf_cand_3prong::DecayType::XicToPKPi); } } - if (flag == 0 && createDstarToPiKPiBkg) { - // D*± → D0(bar) π± - if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDStar, std::array{+kPiPlus, +kPiPlus, -kKPlus}, true, &sign, 2)) { - flag = sign * (1 << o2::aod::hf_cand_3prong::DstarToPiKPiBkg); - } - } - // Check whether the particle is non-prompt (from a b quark). if (flag != 0) { origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers); From 59614ddc389ded9a2c3d67b88a322114da3fc434 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Sun, 23 Feb 2025 15:22:27 +0000 Subject: [PATCH 12/12] Please consider the following formatting changes --- PWGHF/TableProducer/candidateCreator3Prong.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/PWGHF/TableProducer/candidateCreator3Prong.cxx b/PWGHF/TableProducer/candidateCreator3Prong.cxx index 269abba89a2..3918752570c 100644 --- a/PWGHF/TableProducer/candidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/candidateCreator3Prong.cxx @@ -817,7 +817,6 @@ struct HfCandidateCreator3ProngExpressions { } hfEvSelMc.addHistograms(registry); // particles monitoring - } /// Performs MC matching.