From 2e3f7ae2e82c7b2eed62df0d597a6ac385180d85 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 26 Aug 2025 11:29:59 +0200 Subject: [PATCH 1/3] Remove redundant configurables in D* selector --- .../candidateSelectorDstarToD0Pi.cxx | 51 +++++-------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx index bd3cb47b28f..aa23b7e260e 100644 --- a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx +++ b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx @@ -99,18 +99,11 @@ struct HfCandidateSelectorDstarToD0Pi { Configurable> namesInputFeatures{"namesInputFeatures", std::vector{"feature1", "feature2"}, "Names of ML model input features"}; // ML inference D0 Configurable applyMlD0Daug{"applyMlD0Daug", false, "Flag to apply ML selections on D0 daughter"}; - Configurable> binsPtMlD0Daug{"binsPtMlD0Daug", std::vector{hf_cuts_ml::vecBinsPt}, "pT bin limits for ML application on D0 daughter"}; - Configurable> cutDirMlD0Daug{"cutDirMlD0Daug", std::vector{hf_cuts_ml::vecCutDir}, "Whether to reject score values greater or smaller than the threshold on D0 daughter"}; - Configurable> cutsMlD0Daug{"cutsMlD0Daug", {hf_cuts_ml::Cuts[0], hf_cuts_ml::NBinsPt, hf_cuts_ml::NCutScores, hf_cuts_ml::labelsPt, hf_cuts_ml::labelsCutScore}, "ML selections per pT bin on D0 daughter"}; - Configurable nClassesMlD0Daug{"nClassesMlD0Daug", static_cast(hf_cuts_ml::NCutScores), "Number of classes in ML model on D0 daughter"}; - Configurable> namesInputFeaturesD0Daug{"namesInputFeaturesD0Daug", std::vector{"feature1", "feature2"}, "Names of ML model input features on D0 daughter"}; // CCDB configuration Configurable ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Configurable> modelPathsCCDB{"modelPathsCCDB", std::vector{""}, "Paths of models on CCDB"}; - Configurable> modelPathsCCDBD0Daug{"modelPathsCCDBD0Daug", std::vector{""}, "Paths of models on CCDB for D0 daughter"}; Configurable> onnxFileNames{"onnxFileNames", std::vector{"Model.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"}; - Configurable> onnxFileNamesD0Daug{"onnxFileNamesD0Daug", std::vector{"Model.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path) for D0 daughter"}; Configurable timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"}; Configurable loadModelsFromCCDB{"loadModelsFromCCDB", false, "Flag to enable or disable the loading of models from CCDB"}; @@ -119,16 +112,13 @@ struct HfCandidateSelectorDstarToD0Pi { HfHelper hfHelper; o2::analysis::HfMlResponseDstarToD0Pi hfMlResponse; - o2::analysis::HfMlResponseDstarToD0Pi hfMlResponseD0Daughter; std::vector outputMlDstarToD0Pi = {}; - std::vector outputMlD0ToKPi = {}; o2::ccdb::CcdbApi ccdbApi; TrackSelectorPi selectorPion; TrackSelectorKa selectorKaon; using TracksSel = soa::Join; - // using TracksSel = soa::Join; using HfFullDstarCandidate = soa::Join; AxisSpec axisBdtScore{100, 0.f, 1.f}; @@ -165,14 +155,14 @@ struct HfCandidateSelectorDstarToD0Pi { registry.get(HIST("QA/hSelections"))->GetXaxis()->SetBinLabel(iBin + 1, labels[iBin].data()); } - if (applyMl) { + if (applyMl || applyMlD0Daug) { registry.add("QA/hBdtScore1VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); registry.add("QA/hBdtScore2VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); registry.add("QA/hBdtScore3VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); } } - if (applyMl) { + if (applyMl || applyMlD0Daug) { hfMlResponse.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); if (loadModelsFromCCDB) { ccdbApi.init(ccdbUrl); @@ -183,18 +173,6 @@ struct HfCandidateSelectorDstarToD0Pi { hfMlResponse.cacheInputFeaturesIndices(namesInputFeatures); hfMlResponse.init(); } - - if (applyMlD0Daug) { - hfMlResponseD0Daughter.configure(binsPtMlD0Daug, cutsMlD0Daug, cutDirMlD0Daug, nClassesMlD0Daug); - if (loadModelsFromCCDB) { - ccdbApi.init(ccdbUrl); - hfMlResponseD0Daughter.setModelPathsCCDB(onnxFileNamesD0Daug, ccdbApi, modelPathsCCDBD0Daug, timestampCCDB); - } else { - hfMlResponseD0Daughter.setModelPathsLocal(onnxFileNamesD0Daug); - } - hfMlResponseD0Daughter.cacheInputFeaturesIndices(namesInputFeaturesD0Daug); - hfMlResponseD0Daughter.init(); - } } /// Conjugate-independent topological cuts on D0 @@ -258,14 +236,6 @@ struct HfCandidateSelectorDstarToD0Pi { return false; } - if (applyMlD0Daug) { - outputMlD0ToKPi.clear(); - std::vector inputFeaturesD0 = hfMlResponseD0Daughter.getInputFeaturesTrigger(candidate); - bool isSelectedMlD0 = hfMlResponseD0Daughter.isSelectedMl(inputFeaturesD0, candpT, outputMlD0ToKPi); - if (!isSelectedMlD0) { - return false; - } - } return true; } @@ -404,7 +374,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (!TESTBIT(candDstar.hfflag(), aod::hf_cand_2prong::DecayType::D0ToPiK)) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl) { + if (applyMl || applyMlD0Daug) { hfMlDstarCandidate(outputMlDstarToD0Pi); } if (activateQA) { @@ -420,7 +390,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (!selectionDstar(candDstar)) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl) { + if (applyMl || applyMlD0Daug) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -433,7 +403,7 @@ struct HfCandidateSelectorDstarToD0Pi { bool topoDstar = selectionTopolConjugate(candDstar); if (!topoDstar) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl) { + if (applyMl || applyMlD0Daug) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -481,7 +451,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (pidDstar == 0) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl) { + if (applyMl || applyMlD0Daug) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -496,11 +466,16 @@ struct HfCandidateSelectorDstarToD0Pi { } statusPID = true; - if (applyMl) { + if (applyMl || applyMlD0Daug) { // ML selections bool isSelectedMlDstar = false; - std::vector inputFeatures = hfMlResponse.getInputFeatures(candDstar); + std::vector inputFeatures{}; + if (applyMlD0Daug) { + inputFeatures = hfMlResponse.getInputFeaturesTrigger(candDstar); + } else { + inputFeatures = hfMlResponse.getInputFeatures(candDstar); + } isSelectedMlDstar = hfMlResponse.isSelectedMl(inputFeatures, ptCand, outputMlDstarToD0Pi); hfMlDstarCandidate(outputMlDstarToD0Pi); From 2d490268f379039f616f8d5a5e9eca4b5b91ba84 Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Tue, 26 Aug 2025 12:04:04 +0200 Subject: [PATCH 2/3] Remove redundant mass variables --- .../candidateSelectorDstarToD0Pi.cxx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx index aa23b7e260e..9bdbf27dc20 100644 --- a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx +++ b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx @@ -107,9 +107,6 @@ struct HfCandidateSelectorDstarToD0Pi { Configurable timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"}; Configurable loadModelsFromCCDB{"loadModelsFromCCDB", false, "Flag to enable or disable the loading of models from CCDB"}; - // PDG mass for kaon, pion and D0 - double massD0, massPi, massK; - HfHelper hfHelper; o2::analysis::HfMlResponseDstarToD0Pi hfMlResponse; std::vector outputMlDstarToD0Pi = {}; @@ -129,9 +126,6 @@ struct HfCandidateSelectorDstarToD0Pi { void init(InitContext&) { - massPi = MassPiPlus; - massK = MassKPlus; - massD0 = MassD0; selectorPion.setRangePtTpc(ptPidTpcMin, ptPidTpcMax); selectorPion.setRangeNSigmaTpc(-nSigmaTpcMax, nSigmaTpcMax); @@ -293,10 +287,10 @@ struct HfCandidateSelectorDstarToD0Pi { if (prongSoftPi.sign() > 0.) { // Selection of D*+ mInvDstar = candidate.invMassDstar(); mInvD0 = candidate.invMassD0(); - if (std::abs(mInvD0 - massD0) > cutsD0->get(binPt, "m")) { + if (std::abs(mInvD0 - MassD0) > cutsD0->get(binPt, "m")) { return false; } - if (useTriggerMassCut && !isCandidateInMassRange(mInvD0, massD0, candidate.ptD0(), hfTriggerCuts)) { + if (useTriggerMassCut && !isCandidateInMassRange(mInvD0, MassD0, candidate.ptD0(), hfTriggerCuts)) { return false; } // cut on daughter pT @@ -321,10 +315,10 @@ struct HfCandidateSelectorDstarToD0Pi { } else if (prongSoftPi.sign() < 0.) { // Selection of D*- mInvAntiDstar = candidate.invMassAntiDstar(); mInvD0Bar = candidate.invMassD0Bar(); - if (std::abs(mInvD0Bar - massD0) > cutsD0->get(binPt, "m")) { + if (std::abs(mInvD0Bar - MassD0) > cutsD0->get(binPt, "m")) { return false; } - if (useTriggerMassCut && !isCandidateInMassRange(mInvD0Bar, massD0, candidate.ptD0(), hfTriggerCuts)) { + if (useTriggerMassCut && !isCandidateInMassRange(mInvD0Bar, MassD0, candidate.ptD0(), hfTriggerCuts)) { return false; } // cut on daughter pT @@ -349,11 +343,11 @@ struct HfCandidateSelectorDstarToD0Pi { // in case only sideband candidates have to be stored, additional invariant-mass cut if (keepOnlySidebandCandidates && prongSoftPi.sign() > 0.) { - if (std::abs((mInvDstar - mInvD0) - massPi) < distanceFromDeltaMassForSidebands) { + if (std::abs((mInvDstar - mInvD0) - MassPiPlus) < distanceFromDeltaMassForSidebands) { return false; } } else if (keepOnlySidebandCandidates && prongSoftPi.sign() < 0.) { - if (std::abs((mInvAntiDstar - mInvD0Bar) - massPi) < distanceFromDeltaMassForSidebands) { + if (std::abs((mInvAntiDstar - mInvD0Bar) - MassPiPlus) < distanceFromDeltaMassForSidebands) { return false; } } From ae9c1a0ea52d717b2cb74456ca4f2bc3626bcf3d Mon Sep 17 00:00:00 2001 From: marcellocosti Date: Wed, 27 Aug 2025 12:20:11 +0200 Subject: [PATCH 3/3] Remove redundant D0 ML implementation --- PWGHF/Core/HfMlResponseDstarToD0Pi.h | 22 ----------------- .../DataModel/CandidateReconstructionTables.h | 2 -- .../candidateSelectorDstarToD0Pi.cxx | 24 +++++++------------ 3 files changed, 8 insertions(+), 40 deletions(-) diff --git a/PWGHF/Core/HfMlResponseDstarToD0Pi.h b/PWGHF/Core/HfMlResponseDstarToD0Pi.h index af0351b2a73..c7e43065495 100644 --- a/PWGHF/Core/HfMlResponseDstarToD0Pi.h +++ b/PWGHF/Core/HfMlResponseDstarToD0Pi.h @@ -221,28 +221,6 @@ class HfMlResponseDstarToD0Pi : public HfMlResponse return inputFeatures; } - /// Method to get the input features used for D0 in HF triggers - /// \param candidate is the D* candidate - /// \return inputFeatures vector - template - std::vector getInputFeaturesTrigger(T1 const& candidate) - { - std::vector inputFeatures; - - for (const auto& idx : MlResponse::mCachedIndices) { - switch (idx) { - CHECK_AND_FILL_VEC_DSTAR(ptProng0); - CHECK_AND_FILL_VEC_DSTAR_GETTER(impactParameterXY0, impactParameter0); - CHECK_AND_FILL_VEC_DSTAR(impactParameterZ0); - CHECK_AND_FILL_VEC_DSTAR(ptProng1); - CHECK_AND_FILL_VEC_DSTAR_GETTER(impactParameterXY1, impactParameter1); - CHECK_AND_FILL_VEC_DSTAR(impactParameterZ1); - } - } - - return inputFeatures; - } - protected: /// Method to fill the map of available input features void setAvailableInputFeatures() diff --git a/PWGHF/DataModel/CandidateReconstructionTables.h b/PWGHF/DataModel/CandidateReconstructionTables.h index c24c9badbc3..37c96d5627a 100644 --- a/PWGHF/DataModel/CandidateReconstructionTables.h +++ b/PWGHF/DataModel/CandidateReconstructionTables.h @@ -982,8 +982,6 @@ enum DecayType { DplusToPiKPi = 0, XicToPKPi, N3ProngDecays }; // always keep N3ProngDecays at the end -static constexpr int DstarToPiKPiBkg = DecayType::N3ProngDecays; - // Ds± → K± K∓ π± or D± → K± K∓ π± enum DecayChannelDToKKPi { diff --git a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx index 9bdbf27dc20..c0c02b6eed6 100644 --- a/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx +++ b/PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx @@ -97,8 +97,6 @@ struct HfCandidateSelectorDstarToD0Pi { Configurable> cutsMl{"cutsMl", {hf_cuts_ml::Cuts[0], hf_cuts_ml::NBinsPt, hf_cuts_ml::NCutScores, hf_cuts_ml::labelsPt, hf_cuts_ml::labelsCutScore}, "ML selections per pT bin"}; Configurable nClassesMl{"nClassesMl", static_cast(hf_cuts_ml::NCutScores), "Number of classes in ML model"}; Configurable> namesInputFeatures{"namesInputFeatures", std::vector{"feature1", "feature2"}, "Names of ML model input features"}; - // ML inference D0 - Configurable applyMlD0Daug{"applyMlD0Daug", false, "Flag to apply ML selections on D0 daughter"}; // CCDB configuration Configurable ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; @@ -149,14 +147,14 @@ struct HfCandidateSelectorDstarToD0Pi { registry.get(HIST("QA/hSelections"))->GetXaxis()->SetBinLabel(iBin + 1, labels[iBin].data()); } - if (applyMl || applyMlD0Daug) { + if (applyMl) { registry.add("QA/hBdtScore1VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); registry.add("QA/hBdtScore2VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); registry.add("QA/hBdtScore3VsStatus", ";BDT score", {HistType::kTH1F, {axisBdtScore}}); } } - if (applyMl || applyMlD0Daug) { + if (applyMl) { hfMlResponse.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); if (loadModelsFromCCDB) { ccdbApi.init(ccdbUrl); @@ -368,7 +366,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (!TESTBIT(candDstar.hfflag(), aod::hf_cand_2prong::DecayType::D0ToPiK)) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl || applyMlD0Daug) { + if (applyMl) { hfMlDstarCandidate(outputMlDstarToD0Pi); } if (activateQA) { @@ -384,7 +382,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (!selectionDstar(candDstar)) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl || applyMlD0Daug) { + if (applyMl) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -397,7 +395,7 @@ struct HfCandidateSelectorDstarToD0Pi { bool topoDstar = selectionTopolConjugate(candDstar); if (!topoDstar) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl || applyMlD0Daug) { + if (applyMl) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -445,7 +443,7 @@ struct HfCandidateSelectorDstarToD0Pi { if (pidDstar == 0) { hfSelDstarCandidate(statusDstar, statusD0Flag, statusTopol, statusCand, statusPID); - if (applyMl || applyMlD0Daug) { + if (applyMl) { hfMlDstarCandidate(outputMlDstarToD0Pi); } continue; @@ -460,16 +458,10 @@ struct HfCandidateSelectorDstarToD0Pi { } statusPID = true; - if (applyMl || applyMlD0Daug) { + if (applyMl) { // ML selections bool isSelectedMlDstar = false; - - std::vector inputFeatures{}; - if (applyMlD0Daug) { - inputFeatures = hfMlResponse.getInputFeaturesTrigger(candDstar); - } else { - inputFeatures = hfMlResponse.getInputFeatures(candDstar); - } + std::vector inputFeatures = hfMlResponse.getInputFeatures(candDstar); isSelectedMlDstar = hfMlResponse.isSelectedMl(inputFeatures, ptCand, outputMlDstarToD0Pi); hfMlDstarCandidate(outputMlDstarToD0Pi);