Skip to content

Commit e529118

Browse files
committed
Implement Fabrizio and Vit comments
1 parent 8a6b04e commit e529118

File tree

5 files changed

+75
-41
lines changed

5 files changed

+75
-41
lines changed

PWGHF/Core/HfMlResponseB0ToDPi.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define PWGHF_CORE_HFMLRESPONSEB0TODPI_H_
1919

2020
#include "PWGHF/Core/HfMlResponse.h"
21-
#include "PWGHF/D2H/DataModel/ReducedDataModel.h"
2221
#include "PWGHF/D2H/Utils/utilsRedDataFormat.h"
2322

2423
#include "Tools/ML/MlResponse.h"
@@ -173,16 +172,17 @@ class HfMlResponseB0ToDPi : public HfMlResponse<TypeOutputScore>
173172
/// Method to get the input features vector needed for ML inference
174173
/// \param candidate is the B0 candidate
175174
/// \param prongBachPi is the candidate's bachelor pion prong
175+
/// \param prongSoftPi is the candidate's soft pion prong
176176
/// \param mlScoresD is the vector of ML scores for the D meson (if available)
177177
/// \note this method is used for B0 → D*∓ π± candidates with D meson ML scores
178178
/// \return inputFeatures vector
179-
template <bool withDmesMl, IsB0ToDstarPiChannel T1, typename T2>
180-
std::vector<float> getInputFeatures(T1 const& candidate,
181-
T2 const& prongBachPi,
182-
const std::vector<float>* mlScoresD = nullptr)
179+
template <bool withDmesMl, typename T1, typename T2, typename T3>
180+
std::vector<float> getInputFeaturesDStarPi(T1 const& candidate,
181+
T2 const& prongBachPi,
182+
T3 const& prongSoftPi,
183+
const std::vector<float>* mlScoresD = nullptr)
183184
{
184185
std::vector<float> inputFeatures;
185-
auto prongSoftPi = candidate.template prongSoftPi_as<o2::soa::Join<o2::aod::HfRedSoftPiBases, o2::aod::HfRedSoftPiCov, o2::aod::HfRedSoftPiPid>>();
186186

187187
for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) {
188188
switch (idx) {

PWGHF/D2H/DataModel/ReducedDataModel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ namespace hf_cand_b0_reduced
749749
{
750750
DECLARE_SOA_INDEX_COLUMN_FULL(Prong0, prong0, int, HfRed3Prongs, "_0"); //! Prong0 index
751751
DECLARE_SOA_INDEX_COLUMN_FULL(Prong1, prong1, int, HfRedTrackBases, "_1"); //! Prong1 index
752-
DECLARE_SOA_INDEX_COLUMN_FULL(ProngD0, prongD0, int, HfRed2Prongs, ""); //! ProngD0 index
753-
DECLARE_SOA_INDEX_COLUMN_FULL(ProngSoftPi, prongSoftPi, int, HfRedTrackBases, ""); //! ProngSoftPi index
754-
DECLARE_SOA_INDEX_COLUMN_FULL(ProngBachPi, prongBachPi, int, HfRedTrackBases, ""); //! ProngBachPi index
752+
DECLARE_SOA_INDEX_COLUMN_FULL(ProngD0, prongD0, int, HfRed2Prongs, "_0"); //! ProngD0 index
753+
DECLARE_SOA_INDEX_COLUMN_FULL(ProngBachPi, prongBachPi, int, HfRedTrackBases, "_1"); //! ProngBachPi index
754+
DECLARE_SOA_INDEX_COLUMN_FULL(ProngSoftPi, prongSoftPi, int, HfRedSoftPiBases, "_2"); //! ProngSoftPi index
755755
DECLARE_SOA_COLUMN(Prong0MlScoreBkg, prong0MlScoreBkg, float); //! Bkg ML score of the D daughter
756756
DECLARE_SOA_COLUMN(Prong0MlScorePrompt, prong0MlScorePrompt, float); //! Prompt ML score of the D daughter
757757
DECLARE_SOA_COLUMN(Prong0MlScoreNonprompt, prong0MlScoreNonprompt, float); //! Nonprompt ML score of the D daughter
@@ -761,7 +761,7 @@ DECLARE_SOA_TABLE(HfRedB0Prongs, "AOD", "HFREDB0PRONG", //! Table with B0 daught
761761
hf_cand_b0_reduced::Prong0Id, hf_cand_b0_reduced::Prong1Id);
762762

763763
DECLARE_SOA_TABLE(HfRedB0ProngDStars, "AOD", "HFREDB0PRONGDST", //! Table with B0 daughter indices
764-
hf_cand_b0_reduced::ProngD0Id, hf_cand_b0_reduced::ProngSoftPiId, hf_cand_b0_reduced::ProngBachPiId);
764+
hf_cand_b0_reduced::ProngD0Id, hf_cand_b0_reduced::ProngBachPiId, hf_cand_b0_reduced::ProngSoftPiId);
765765

766766
DECLARE_SOA_TABLE(HfRedB0DpMls, "AOD", "HFREDB0DPML", //! Table with ML scores for the D+ daughter
767767
hf_cand_b0_reduced::Prong0MlScoreBkg,

PWGHF/D2H/TableProducer/candidateCreatorB0Reduced.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct HfCandidateCreatorB0Reduced {
228228
dcaD.getY(), dcaSoftPion.getY(), dcaBachPion.getY(),
229229
std::sqrt(dcaD.getSigmaY2()), std::sqrt(dcaSoftPion.getSigmaY2()), std::sqrt(dcaBachPion.getSigmaY2()));
230230

231-
rowCandidateProngsDStar(candD.globalIndex(), trackSoftPion.globalIndex(), trackBachPion.globalIndex());
231+
rowCandidateProngsDStar(candD.globalIndex(), trackBachPion.globalIndex(), trackSoftPion.globalIndex());
232232

233233
if constexpr (withDmesMl) {
234234
rowCandidateDmesMlScores(candD.mlScoreBkgMassHypo0(), candD.mlScorePromptMassHypo0(), candD.mlScoreNonpromptMassHypo0());

PWGHF/D2H/TableProducer/candidateSelectorB0ToDPiReduced.cxx

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,51 @@ struct HfCandidateSelectorB0ToDPiReduced {
156156
}
157157
}
158158

159-
// For D* channel
160-
template <IsB0ToDstarPiChannel T>
161-
auto getTrackBachPi(const T& candidate)
162-
{
159+
/// Utility function to retrieve the bach pion track
160+
///from the B0 candidate in the D*-pi decay channel
161+
/// \param candidate is the B0 candidate
162+
/// \return bach pion track
163+
template <IsB0ToDstarPiChannel T1>
164+
auto getTrackBachPi(const T1& candidate) {
163165
return candidate.template prongBachPi_as<TracksBachPion>();
164166
}
165167

166-
// For non-D* channel
167-
template <typename T>
168-
auto getTrackBachPi(const T& candidate)
169-
{
168+
/// Method to get the input features vector needed for ML inference
169+
/// \param candidate is the B0 candidate
170+
/// \param prongBachPi is the candidate's bachelor pion prong
171+
/// \note this method is used for B0 → D*- π+ candidates with D meson ML scores
172+
template <bool withDmesMl, IsB0ToDstarPiChannel T1, typename T2>
173+
auto getMlInputFeatures(const T1& candB0, const T2& prongBachPi) {
174+
auto prongSoftPi = candB0.template prongSoftPi_as<TracksSoftPions>();
175+
if constexpr (withDmesMl) {
176+
return hfMlResponse.getInputFeaturesDStarPi<true>(candB0, prongBachPi, prongSoftPi);
177+
} else {
178+
return hfMlResponse.getInputFeaturesDStarPi<false>(candB0, prongBachPi, prongSoftPi);
179+
}
180+
}
181+
182+
/// Utility function to retrieve the bach pion track
183+
///from the B0 candidate in the D-pi decay channel
184+
/// \param candidate is the B0 candidate
185+
/// \return bach pion track
186+
template <typename T1>
187+
auto getTrackBachPi(const T1& candidate) {
170188
return candidate.template prong1_as<TracksBachPion>();
171189
}
172190

191+
/// Method to get the input features vector needed for ML inference
192+
/// \param candB0 is the B0 candidate
193+
/// \param prongBachPi is the candidate's bachelor pion prong
194+
/// \note this method is used for B0 → D- π+ candidates with D meson ML scores
195+
template <bool withDmesMl, typename T1, typename T2>
196+
auto getMlInputFeatures(const T1& candB0, const T2& prongBachPi) {
197+
if constexpr (withDmesMl) {
198+
return hfMlResponse.getInputFeatures<true>(candB0, prongBachPi);
199+
} else {
200+
return hfMlResponse.getInputFeatures<false>(candB0, prongBachPi);
201+
}
202+
}
203+
173204
/// Main function to perform B0 candidate creation
174205
/// \param withDmesMl is the flag to use the table with ML scores for the D- daughter (only possible if present in the derived data)
175206
/// \param hfCandsB0 B0 candidates
@@ -220,15 +251,15 @@ struct HfCandidateSelectorB0ToDPiReduced {
220251
registry.fill(HIST("hSelections"), 2 + SelectionStep::RecoTopol, ptCandB0);
221252
}
222253

223-
auto trackPiBachPi = getTrackBachPi(hfCandB0);
254+
auto trackBachPi = getTrackBachPi(hfCandB0);
224255
if (pionPidMethod == PidMethod::TpcOrTof || pionPidMethod == PidMethod::TpcAndTof) {
225-
int pidTrackPiBachPi{TrackSelectorPID::Status::NotApplicable};
256+
int pidTrackBachPi{TrackSelectorPID::Status::NotApplicable};
226257
if (pionPidMethod == PidMethod::TpcOrTof) {
227-
pidTrackPiBachPi = selectorPion.statusTpcOrTof(trackPiBachPi);
258+
pidTrackBachPi = selectorPion.statusTpcOrTof(trackBachPi);
228259
} else if (pionPidMethod == PidMethod::TpcAndTof) {
229-
pidTrackPiBachPi = selectorPion.statusTpcAndTof(trackPiBachPi);
260+
pidTrackBachPi = selectorPion.statusTpcAndTof(trackBachPi);
230261
}
231-
if (!hfHelper.selectionB0ToDPiPid(pidTrackPiBachPi, acceptPIDNotApplicable.value)) {
262+
if (!hfHelper.selectionB0ToDPiPid(pidTrackBachPi, acceptPIDNotApplicable.value)) {
232263
// LOGF(info, "B0 candidate selection failed at PID selection");
233264
hfSelB0ToDPiCandidate(statusB0ToDPi);
234265
if (applyB0Ml) {
@@ -243,7 +274,7 @@ struct HfCandidateSelectorB0ToDPiReduced {
243274
}
244275
if (applyB0Ml) {
245276
// B0 ML selections
246-
std::vector<float> inputFeatures = hfMlResponse.getInputFeatures<withDmesMl>(hfCandB0, trackPiBachPi);
277+
std::vector<float> inputFeatures = getMlInputFeatures<withDmesMl>(hfCandB0, trackBachPi);
247278
bool isSelectedMl = hfMlResponse.isSelectedMl(inputFeatures, ptCandB0, outputMl);
248279
hfMlB0ToDPiCandidate(outputMl[1]); // storing ML score for signal class
249280

0 commit comments

Comments
 (0)