Skip to content

Commit d986644

Browse files
[PWGHF] ML selections for D0 in D* selector (#12176)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent 807ddcb commit d986644

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

PWGHF/Core/HfMlResponseDstarToD0Pi.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ enum class InputFeaturesDstarToD0Pi : uint8_t {
113113
ptSoftPi,
114114
impactParameter0,
115115
impactParameter1,
116+
impactParameterXY0,
117+
impactParameterXY1,
116118
impactParameterZ0,
117119
impactParameterZ1,
118120
impParamSoftPi,
@@ -219,6 +221,28 @@ class HfMlResponseDstarToD0Pi : public HfMlResponse<TypeOutputScore>
219221
return inputFeatures;
220222
}
221223

224+
/// Method to get the input features used for D0 in HF triggers
225+
/// \param candidate is the D* candidate
226+
/// \return inputFeatures vector
227+
template <typename T1>
228+
std::vector<float> getInputFeaturesTrigger(T1 const& candidate)
229+
{
230+
std::vector<float> inputFeatures;
231+
232+
for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) {
233+
switch (idx) {
234+
CHECK_AND_FILL_VEC_DSTAR(ptProng0);
235+
CHECK_AND_FILL_VEC_DSTAR_GETTER(impactParameterXY0, impactParameter0);
236+
CHECK_AND_FILL_VEC_DSTAR(impactParameterZ0);
237+
CHECK_AND_FILL_VEC_DSTAR(ptProng1);
238+
CHECK_AND_FILL_VEC_DSTAR_GETTER(impactParameterXY1, impactParameter1);
239+
CHECK_AND_FILL_VEC_DSTAR(impactParameterZ1);
240+
}
241+
}
242+
243+
return inputFeatures;
244+
}
245+
222246
protected:
223247
/// Method to fill the map of available input features
224248
void setAvailableInputFeatures()
@@ -238,6 +262,8 @@ class HfMlResponseDstarToD0Pi : public HfMlResponse<TypeOutputScore>
238262
FILL_MAP_DSTAR(ptSoftPi),
239263
FILL_MAP_DSTAR(impactParameter0),
240264
FILL_MAP_DSTAR(impactParameter1),
265+
FILL_MAP_DSTAR(impactParameterXY0),
266+
FILL_MAP_DSTAR(impactParameterXY1),
241267
FILL_MAP_DSTAR(impactParameterZ0),
242268
FILL_MAP_DSTAR(impactParameterZ1),
243269
FILL_MAP_DSTAR(impParamSoftPi),

PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// \author Fabrizio Grosa <fabrizio.grosa@cern.ch>, CERN
1717

1818
#include "PWGHF/Core/HfHelper.h"
19+
#include "PWGHF/Core/HfMlResponseD0ToKPi.h"
1920
#include "PWGHF/Core/HfMlResponseDstarToD0Pi.h"
2021
#include "PWGHF/Core/SelectorCuts.h"
2122
#include "PWGHF/DataModel/CandidateReconstructionTables.h"
@@ -90,18 +91,27 @@ struct HfCandidateSelectorDstarToD0Pi {
9091

9192
// QA switch
9293
Configurable<bool> activateQA{"activateQA", false, "Flag to enable QA histogram"};
93-
// ML inference
94+
// ML inference D*
9495
Configurable<bool> applyMl{"applyMl", false, "Flag to apply ML selections"};
9596
Configurable<std::vector<double>> binsPtMl{"binsPtMl", std::vector<double>{hf_cuts_ml::vecBinsPt}, "pT bin limits for ML application"};
9697
Configurable<std::vector<int>> cutDirMl{"cutDirMl", std::vector<int>{hf_cuts_ml::vecCutDir}, "Whether to reject score values greater or smaller than the threshold"};
9798
Configurable<LabeledArray<double>> 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"};
9899
Configurable<int> nClassesMl{"nClassesMl", static_cast<int>(hf_cuts_ml::NCutScores), "Number of classes in ML model"};
99100
Configurable<std::vector<std::string>> namesInputFeatures{"namesInputFeatures", std::vector<std::string>{"feature1", "feature2"}, "Names of ML model input features"};
101+
// ML inference D0
102+
Configurable<bool> applyMlD0Daug{"applyMlD0Daug", false, "Flag to apply ML selections on D0 daughter"};
103+
Configurable<std::vector<double>> binsPtMlD0Daug{"binsPtMlD0Daug", std::vector<double>{hf_cuts_ml::vecBinsPt}, "pT bin limits for ML application on D0 daughter"};
104+
Configurable<std::vector<int>> cutDirMlD0Daug{"cutDirMlD0Daug", std::vector<int>{hf_cuts_ml::vecCutDir}, "Whether to reject score values greater or smaller than the threshold on D0 daughter"};
105+
Configurable<LabeledArray<double>> 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"};
106+
Configurable<int> nClassesMlD0Daug{"nClassesMlD0Daug", static_cast<int>(hf_cuts_ml::NCutScores), "Number of classes in ML model on D0 daughter"};
107+
Configurable<std::vector<std::string>> namesInputFeaturesD0Daug{"namesInputFeaturesD0Daug", std::vector<std::string>{"feature1", "feature2"}, "Names of ML model input features on D0 daughter"};
100108

101109
// CCDB configuration
102110
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
103111
Configurable<std::vector<std::string>> modelPathsCCDB{"modelPathsCCDB", std::vector<std::string>{""}, "Paths of models on CCDB"};
112+
Configurable<std::vector<std::string>> modelPathsCCDBD0Daug{"modelPathsCCDBD0Daug", std::vector<std::string>{""}, "Paths of models on CCDB for D0 daughter"};
104113
Configurable<std::vector<std::string>> onnxFileNames{"onnxFileNames", std::vector<std::string>{"Model.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"};
114+
Configurable<std::vector<std::string>> onnxFileNamesD0Daug{"onnxFileNamesD0Daug", std::vector<std::string>{"Model.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path) for D0 daughter"};
105115
Configurable<int64_t> timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"};
106116
Configurable<bool> loadModelsFromCCDB{"loadModelsFromCCDB", false, "Flag to enable or disable the loading of models from CCDB"};
107117

@@ -110,7 +120,9 @@ struct HfCandidateSelectorDstarToD0Pi {
110120

111121
HfHelper hfHelper;
112122
o2::analysis::HfMlResponseDstarToD0Pi<float> hfMlResponse;
123+
o2::analysis::HfMlResponseDstarToD0Pi<float> hfMlResponseD0Daughter;
113124
std::vector<float> outputMlDstarToD0Pi = {};
125+
std::vector<float> outputMlD0ToKPi = {};
114126
o2::ccdb::CcdbApi ccdbApi;
115127

116128
TrackSelectorPi selectorPion;
@@ -172,6 +184,18 @@ struct HfCandidateSelectorDstarToD0Pi {
172184
hfMlResponse.cacheInputFeaturesIndices(namesInputFeatures);
173185
hfMlResponse.init();
174186
}
187+
188+
if (applyMlD0Daug) {
189+
hfMlResponseD0Daughter.configure(binsPtMlD0Daug, cutsMlD0Daug, cutDirMlD0Daug, nClassesMlD0Daug);
190+
if (loadModelsFromCCDB) {
191+
ccdbApi.init(ccdbUrl);
192+
hfMlResponseD0Daughter.setModelPathsCCDB(onnxFileNamesD0Daug, ccdbApi, modelPathsCCDBD0Daug, timestampCCDB);
193+
} else {
194+
hfMlResponseD0Daughter.setModelPathsLocal(onnxFileNamesD0Daug);
195+
}
196+
hfMlResponseD0Daughter.cacheInputFeaturesIndices(namesInputFeaturesD0Daug);
197+
hfMlResponseD0Daughter.init();
198+
}
175199
}
176200

177201
/// Conjugate-independent topological cuts on D0
@@ -234,6 +258,15 @@ struct HfCandidateSelectorDstarToD0Pi {
234258
if (candidate.decayLengthXYD0() > cutsD0->get(binPt, "max decay length XY")) {
235259
return false;
236260
}
261+
262+
if (applyMlD0Daug) {
263+
outputMlD0ToKPi.clear();
264+
std::vector<float> inputFeaturesD0 = hfMlResponseD0Daughter.getInputFeaturesTrigger(candidate);
265+
bool isSelectedMlD0 = hfMlResponseD0Daughter.isSelectedMl(inputFeaturesD0, candpT, outputMlD0ToKPi);
266+
if (!isSelectedMlD0) {
267+
return false;
268+
}
269+
}
237270
return true;
238271
}
239272

0 commit comments

Comments
 (0)