From f9037155a834119f8d987443f7b5d625eec9cbc4 Mon Sep 17 00:00:00 2001 From: Alexandre Bigot Date: Wed, 5 Oct 2022 11:42:13 +0200 Subject: [PATCH 1/4] Implementing the optimisation tree (only for D0 for the moment) --- EventFiltering/PWGHF/HFFilter.cxx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/EventFiltering/PWGHF/HFFilter.cxx b/EventFiltering/PWGHF/HFFilter.cxx index af195a8169e..34ef39c5270 100644 --- a/EventFiltering/PWGHF/HFFilter.cxx +++ b/EventFiltering/PWGHF/HFFilter.cxx @@ -245,6 +245,21 @@ DECLARE_SOA_TABLE(HFTrigTrain3P, "AOD", "HFTRIGTRAIN3P", //! hftraining3p::FlagOrigin, hftraining3p::Channel, hftraining3p::HFSelBit); + +namespace hfoptimisationTree +{ +DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! +DECLARE_SOA_COLUMN(BkgBDT, bkgBDT, float); //! +DECLARE_SOA_COLUMN(PromptBDT, promptBDT, float); //! +DECLARE_SOA_COLUMN(NonpromptBDT, nonpromptBDT, float); //! +DECLARE_SOA_COLUMN(DCAXY, dcaXY, float); //! +} // namespace hfoptimisationTree +DECLARE_SOA_TABLE(HFOptimisationTree, "AOD", "HFOPTIMTREE", //! + hfoptimisationTree::CollisionIndex, + hfoptimisationTree::BkgBDT, + hfoptimisationTree::PromptBDT, + hfoptimisationTree::NonpromptBDT, + hfoptimisationTree::DCAXY); } // namespace o2::aod struct AddCollisionId { @@ -327,6 +342,9 @@ struct HfFilter { // Main struct for HF triggers Configurable onnxFileXicToPiKPConf{"onnxFileXicToPiKPConf", "", "ONNX file for ML model for Xic+ candidates"}; Configurable> thresholdBDFScoreXicToPiKP{"thresholdBDFScoreXicToPiKP", {hf_cuts_bdt_multiclass::cutsBDT[0], hf_cuts_bdt_multiclass::npTBins, hf_cuts_bdt_multiclass::nCutBDTScores, hf_cuts_bdt_multiclass::pTBinLabels, hf_cuts_bdt_multiclass::cutBDTLabels}, "Threshold values for BDT output scores of Xic+ candidates"}; + // parameter for Optimisation Tree + Configurable applyOptimisation{"applyOptimisation", false, "Flag to enable or disable optimisation"}; + // array of ONNX config and BDT thresholds std::array onnxFiles; std::array, kNCharmParticles> thresholdBDTScores; @@ -791,6 +809,7 @@ struct HfFilter { // Main struct for HF triggers bool isCharmTagged{true}, isBeautyTagged{true}; + float scores[3] = {-1, -1, -1}; // initialize BDT scores array outside ML loop // apply ML models if (applyML && onnxFiles[kD0] != "") { isCharmTagged = false; @@ -816,7 +835,9 @@ struct HfFilter { // Main struct for HF triggers assert(outputTensorD0.size() == outputNamesML[kD0].size() && outputTensorD0[1].IsTensor()); auto typeInfo = outputTensorD0[1].GetTensorTypeAndShapeInfo(); assert(typeInfo.GetElementCount() == 3); // we need multiclass - auto scores = outputTensorD0[1].GetTensorMutableData(); + scores[0] = outputTensorD0[1].GetTensorMutableData()[0]; + scores[1] = outputTensorD0[1].GetTensorMutableData()[1]; + scores[2] = outputTensorD0[1].GetTensorMutableData()[2]; if (applyML && activateQA) { hBDTScoreBkg[kD0]->Fill(scores[0]); @@ -867,6 +888,10 @@ struct HfFilter { // Main struct for HF triggers auto ptCand = RecoDecay::pt(pVecBeauty3Prong); if (isTrackSelected == kRegular && std::abs(massCand - massBPlus) <= deltaMassBPlus) { keepEvent[kBeauty3P] = true; + // fill optimisation tree for D0 + if (applyOptimisation) { + optimisationTree(collision.globalIndex(), scores[0], scores[1], scores[2], track.dcaXY()); + } if (activateQA) { hMassVsPtB[kBplus]->Fill(ptCand, massCand); } From d6d2e84b5b68b4901bf425ec597161a723826047 Mon Sep 17 00:00:00 2001 From: Alexandre Bigot Date: Wed, 5 Oct 2022 11:43:40 +0200 Subject: [PATCH 2/4] Fixing BDT scores cut operator (upper limit for Bkg, lower limit for (Non)Prompt) --- EventFiltering/PWGHF/HFFilter.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EventFiltering/PWGHF/HFFilter.cxx b/EventFiltering/PWGHF/HFFilter.cxx index 34ef39c5270..b89645c8337 100644 --- a/EventFiltering/PWGHF/HFFilter.cxx +++ b/EventFiltering/PWGHF/HFFilter.cxx @@ -744,10 +744,10 @@ struct HfFilter { // Main struct for HF triggers if (scores[0] > thresholdBDTScores[candType].get(0u, "BDTbkg")) { return retValue; } - if (scores[1] < thresholdBDTScores[candType].get(0u, "BDTprompt")) { + if (scores[1] > thresholdBDTScores[candType].get(0u, "BDTprompt")) { retValue |= BIT(RecoDecay::OriginType::Prompt); } - if (scores[2] < thresholdBDTScores[candType].get(0u, "BDTnonprompt")) { + if (scores[2] > thresholdBDTScores[candType].get(0u, "BDTnonprompt")) { retValue |= BIT(RecoDecay::OriginType::NonPrompt); } From dee7b09477b210788186769b0dbb4c7ae4b6938e Mon Sep 17 00:00:00 2001 From: Alexandre Bigot Date: Wed, 5 Oct 2022 14:28:07 +0200 Subject: [PATCH 3/4] Splittingin 2 Tables (1 for 2prong, 1 for 3prong) and adding Dplus in the 3prong Optimisation tree --- EventFiltering/PWGHF/HFFilter.cxx | 83 +++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 14 deletions(-) diff --git a/EventFiltering/PWGHF/HFFilter.cxx b/EventFiltering/PWGHF/HFFilter.cxx index b89645c8337..7065fad35db 100644 --- a/EventFiltering/PWGHF/HFFilter.cxx +++ b/EventFiltering/PWGHF/HFFilter.cxx @@ -246,22 +246,59 @@ DECLARE_SOA_TABLE(HFTrigTrain3P, "AOD", "HFTRIGTRAIN3P", //! hftraining3p::Channel, hftraining3p::HFSelBit); -namespace hfoptimisationTree +namespace hfoptimisationTree2Prong { DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! -DECLARE_SOA_COLUMN(BkgBDT, bkgBDT, float); //! -DECLARE_SOA_COLUMN(PromptBDT, promptBDT, float); //! -DECLARE_SOA_COLUMN(NonpromptBDT, nonpromptBDT, float); //! -DECLARE_SOA_COLUMN(DCAXY, dcaXY, float); //! -} // namespace hfoptimisationTree -DECLARE_SOA_TABLE(HFOptimisationTree, "AOD", "HFOPTIMTREE", //! - hfoptimisationTree::CollisionIndex, - hfoptimisationTree::BkgBDT, - hfoptimisationTree::PromptBDT, - hfoptimisationTree::NonpromptBDT, - hfoptimisationTree::DCAXY); +DECLARE_SOA_COLUMN(BkgBDTD0, bkgBDTD0, float); //! +DECLARE_SOA_COLUMN(PromptBDTD0, promptBDTD0, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTD0, nonpromptBDTD0, float); //! +DECLARE_SOA_COLUMN(DCAXYD0, dcaXYD0, float); //! +} // namespace hfoptimisationTree2Prong +DECLARE_SOA_TABLE(HFOptimisationTree2Prong, "AOD", "HFOPTIMTREE2P", //! + hfoptimisationTree2Prong::CollisionIndex, + hfoptimisationTree2Prong::BkgBDTD0, + hfoptimisationTree2Prong::PromptBDTD0, + hfoptimisationTree2Prong::NonpromptBDTD0, + hfoptimisationTree2Prong::DCAXYD0); + +namespace hfoptimisationTree3Prong +{ +DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! +DECLARE_SOA_COLUMN(BkgBDTDplus, bkgBDTDplus, float); //! +DECLARE_SOA_COLUMN(PromptBDTDplus, promptBDTDplus, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTDplus, nonpromptBDTDplus, float); //! +DECLARE_SOA_COLUMN(DCAXYDplus, dcaXYDplus, float); //! +} // namespace hfoptimisationTree3Prong +DECLARE_SOA_TABLE(HFOptimisationTree3Prong, "AOD", "HFOPTIMTREE3P", //! + hfoptimisationTree3Prong::CollisionIndex, + hfoptimisationTree3Prong::BkgBDTDplus, + hfoptimisationTree3Prong::PromptBDTDplus, + hfoptimisationTree3Prong::NonpromptBDTDplus, + hfoptimisationTree3Prong::DCAXYDplus); } // namespace o2::aod +/* +DECLARE_SOA_COLUMN(BkgBDTLc, bkgBDTLc, float); //! +DECLARE_SOA_COLUMN(PromptBDTLc, promptBDTLc, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTLc, nonpromptBDTLc, float); //! +DECLARE_SOA_COLUMN(DCAXYLc, dcaXYLc, float); //! +DECLARE_SOA_COLUMN(BkgBDTXic, bkgBDTXic, float); //! +DECLARE_SOA_COLUMN(PromptBDTXic, promptBDTXic, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTXic, nonpromptBDTXic, float); //! +DECLARE_SOA_COLUMN(DCAXYXic, dcaXYXic, float); //! +*/ + +/* + hfoptimisationTree::BkgBDTLc, + hfoptimisationTree::PromptBDTLc, + hfoptimisationTree::NonpromptBDTLc, + hfoptimisationTree::DCAXYLc, + hfoptimisationTree::BkgBDTXic, + hfoptimisationTree::PromptBDTXic, + hfoptimisationTree::NonpromptBDTXic, + hfoptimisationTree::DCAXYXic +*/ + struct AddCollisionId { Produces colls2Prong; @@ -285,6 +322,8 @@ struct HfFilter { // Main struct for HF triggers Produces tags; Produces train2P; Produces train3P; + Produces optimisationTree2Prong; + Produces optimisationTree3Prong; Configurable activateQA{"activateQA", false, "flag to enable QA histos"}; @@ -890,8 +929,8 @@ struct HfFilter { // Main struct for HF triggers keepEvent[kBeauty3P] = true; // fill optimisation tree for D0 if (applyOptimisation) { - optimisationTree(collision.globalIndex(), scores[0], scores[1], scores[2], track.dcaXY()); - } + optimisationTree2Prong(collision.globalIndex(), scores[0], scores[1], scores[2], track.dcaXY()); + } if (activateQA) { hMassVsPtB[kBplus]->Fill(ptCand, massCand); } @@ -969,6 +1008,9 @@ struct HfFilter { // Main struct for HF triggers std::array isCharmTagged = is3Prong; std::array isBeautyTagged = is3Prong; + const int scoresSize = kNCharmParticles; + float myscores[scoresSize][3]; + for (int i=0; i< scoresSize; i++) { std::fill_n(myscores[i], 3, -1);} // initialize BDT scores array outside ML loop // apply ML models if (applyML) { isCharmTagged = std::array{0}; @@ -1001,6 +1043,9 @@ struct HfFilter { // Main struct for HF triggers auto typeInfo = outputTensor[1].GetTensorTypeAndShapeInfo(); assert(typeInfo.GetElementCount() == 3); // we need multiclass auto scores = outputTensor[1].GetTensorMutableData(); + myscores[iCharmPart +1][0] = scores[0]; + myscores[iCharmPart +1][1] = scores[1]; + myscores[iCharmPart +1][2] = scores[2]; if (applyML && activateQA) { hBDTScoreBkg[iCharmPart + 1]->Fill(scores[0]); @@ -1054,6 +1099,10 @@ struct HfFilter { // Main struct for HF triggers } } // end high-pT selection + + float dcaXYCharm[scoresSize]; + std::fill_n(dcaXYCharm, scoresSize, -99.); + for (const auto& track : tracks) { // start loop over tracks if (track.globalIndex() == trackFirst.globalIndex() || track.globalIndex() == trackSecond.globalIndex() || track.globalIndex() == trackThird.globalIndex()) { @@ -1071,6 +1120,9 @@ struct HfFilter { // Main struct for HF triggers auto massCandB = RecoDecay::m(std::array{pVec3Prong, pVecFourth}, std::array{massCharmHypos[iHypo], massPi}); if (std::abs(massCandB - massBeautyHypos[iHypo]) <= deltaMassHypos[iHypo]) { keepEvent[kBeauty4P] = true; + if (applyOptimisation) { + dcaXYCharm[iHypo+1] = track.dcaXY(); + } if (activateQA) { auto pVecBeauty4Prong = RecoDecay::pVec(pVec3Prong, pVecFourth); auto ptCandBeauty4Prong = RecoDecay::pt(pVecBeauty4Prong); @@ -1079,6 +1131,9 @@ struct HfFilter { // Main struct for HF triggers } } } + if (applyOptimisation) { + optimisationTree3Prong(collision.globalIndex(), myscores[1][0], myscores[1][1], myscores[1][2], dcaXYCharm[1]); + } } // end beauty selection // 3-prong femto From cffc0061fab62aace9ce290414a5c0aecb4ae1a5 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Wed, 5 Oct 2022 14:12:41 +0000 Subject: [PATCH 4/4] Please consider the following formatting changes --- EventFiltering/PWGHF/HFFilter.cxx | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/EventFiltering/PWGHF/HFFilter.cxx b/EventFiltering/PWGHF/HFFilter.cxx index 6ca64ea3ed5..0ffd62738ae 100644 --- a/EventFiltering/PWGHF/HFFilter.cxx +++ b/EventFiltering/PWGHF/HFFilter.cxx @@ -252,11 +252,11 @@ DECLARE_SOA_TABLE(HFTrigTrain3P, "AOD", "HFTRIGTRAIN3P", //! namespace hfoptimisationTree2Prong { -DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! -DECLARE_SOA_COLUMN(BkgBDTD0, bkgBDTD0, float); //! -DECLARE_SOA_COLUMN(PromptBDTD0, promptBDTD0, float); //! -DECLARE_SOA_COLUMN(NonpromptBDTD0, nonpromptBDTD0, float); //! -DECLARE_SOA_COLUMN(DCAXYD0, dcaXYD0, float); //! +DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! +DECLARE_SOA_COLUMN(BkgBDTD0, bkgBDTD0, float); //! +DECLARE_SOA_COLUMN(PromptBDTD0, promptBDTD0, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTD0, nonpromptBDTD0, float); //! +DECLARE_SOA_COLUMN(DCAXYD0, dcaXYD0, float); //! } // namespace hfoptimisationTree2Prong DECLARE_SOA_TABLE(HFOptimisationTree2Prong, "AOD", "HFOPTIMTREE2P", //! hfoptimisationTree2Prong::CollisionIndex, @@ -267,11 +267,11 @@ DECLARE_SOA_TABLE(HFOptimisationTree2Prong, "AOD", "HFOPTIMTREE2P", //! namespace hfoptimisationTree3Prong { -DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! -DECLARE_SOA_COLUMN(BkgBDTDplus, bkgBDTDplus, float); //! -DECLARE_SOA_COLUMN(PromptBDTDplus, promptBDTDplus, float); //! -DECLARE_SOA_COLUMN(NonpromptBDTDplus, nonpromptBDTDplus, float); //! -DECLARE_SOA_COLUMN(DCAXYDplus, dcaXYDplus, float); //! +DECLARE_SOA_COLUMN(CollisionIndex, collisionIndex, int); //! +DECLARE_SOA_COLUMN(BkgBDTDplus, bkgBDTDplus, float); //! +DECLARE_SOA_COLUMN(PromptBDTDplus, promptBDTDplus, float); //! +DECLARE_SOA_COLUMN(NonpromptBDTDplus, nonpromptBDTDplus, float); //! +DECLARE_SOA_COLUMN(DCAXYDplus, dcaXYDplus, float); //! } // namespace hfoptimisationTree3Prong DECLARE_SOA_TABLE(HFOptimisationTree3Prong, "AOD", "HFOPTIMTREE3P", //! hfoptimisationTree3Prong::CollisionIndex, @@ -1076,7 +1076,9 @@ struct HfFilter { // Main struct for HF triggers const int scoresSize = kNCharmParticles; float myscores[scoresSize][3]; - for (int i=0; i< scoresSize; i++) { std::fill_n(myscores[i], 3, -1);} // initialize BDT scores array outside ML loop + for (int i = 0; i < scoresSize; i++) { + std::fill_n(myscores[i], 3, -1); + } // initialize BDT scores array outside ML loop // apply ML models if (applyML) { isCharmTagged = std::array{0}; @@ -1109,9 +1111,9 @@ struct HfFilter { // Main struct for HF triggers auto typeInfo = outputTensor[1].GetTensorTypeAndShapeInfo(); assert(typeInfo.GetElementCount() == 3); // we need multiclass auto scores = outputTensor[1].GetTensorMutableData(); - myscores[iCharmPart +1][0] = scores[0]; - myscores[iCharmPart +1][1] = scores[1]; - myscores[iCharmPart +1][2] = scores[2]; + myscores[iCharmPart + 1][0] = scores[0]; + myscores[iCharmPart + 1][1] = scores[1]; + myscores[iCharmPart + 1][2] = scores[2]; if (applyML && activateQA) { hBDTScoreBkg[iCharmPart + 1]->Fill(scores[0]); @@ -1165,7 +1167,6 @@ struct HfFilter { // Main struct for HF triggers } } // end high-pT selection - float dcaXYCharm[scoresSize]; std::fill_n(dcaXYCharm, scoresSize, -99.); @@ -1187,7 +1188,7 @@ struct HfFilter { // Main struct for HF triggers if (std::abs(massCandB - massBeautyHypos[iHypo]) <= deltaMassHypos[iHypo]) { keepEvent[kBeauty4P] = true; if (applyOptimisation) { - dcaXYCharm[iHypo+1] = track.dcaXY(); + dcaXYCharm[iHypo + 1] = track.dcaXY(); } if (activateQA) { auto pVecBeauty4Prong = RecoDecay::pVec(pVec3Prong, pVecFourth);