Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions PWGHF/Core/HfMlResponseDstarToD0Pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,28 +221,6 @@ class HfMlResponseDstarToD0Pi : public HfMlResponse<TypeOutputScore>
return inputFeatures;
}

/// Method to get the input features used for D0 in HF triggers
/// \param candidate is the D* candidate
/// \return inputFeatures vector
template <typename T1>
std::vector<float> getInputFeaturesTrigger(T1 const& candidate)
{
std::vector<float> inputFeatures;

for (const auto& idx : MlResponse<TypeOutputScore>::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()
Expand Down
2 changes: 0 additions & 2 deletions PWGHF/DataModel/CandidateReconstructionTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 6 additions & 45 deletions PWGHF/TableProducer/candidateSelectorDstarToD0Pi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,23 @@ struct HfCandidateSelectorDstarToD0Pi {
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"};
Configurable<int> nClassesMl{"nClassesMl", static_cast<int>(hf_cuts_ml::NCutScores), "Number of classes in ML model"};
Configurable<std::vector<std::string>> namesInputFeatures{"namesInputFeatures", std::vector<std::string>{"feature1", "feature2"}, "Names of ML model input features"};
// ML inference D0
Configurable<bool> applyMlD0Daug{"applyMlD0Daug", false, "Flag to apply ML selections on D0 daughter"};
Configurable<std::vector<double>> binsPtMlD0Daug{"binsPtMlD0Daug", std::vector<double>{hf_cuts_ml::vecBinsPt}, "pT bin limits for ML application on D0 daughter"};
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"};
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"};
Configurable<int> nClassesMlD0Daug{"nClassesMlD0Daug", static_cast<int>(hf_cuts_ml::NCutScores), "Number of classes in ML model on D0 daughter"};
Configurable<std::vector<std::string>> namesInputFeaturesD0Daug{"namesInputFeaturesD0Daug", std::vector<std::string>{"feature1", "feature2"}, "Names of ML model input features on D0 daughter"};

// CCDB configuration
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::vector<std::string>> modelPathsCCDB{"modelPathsCCDB", std::vector<std::string>{""}, "Paths of models on CCDB"};
Configurable<std::vector<std::string>> modelPathsCCDBD0Daug{"modelPathsCCDBD0Daug", std::vector<std::string>{""}, "Paths of models on CCDB for D0 daughter"};
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)"};
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"};
Configurable<int64_t> timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"};
Configurable<bool> 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<float> hfMlResponse;
o2::analysis::HfMlResponseDstarToD0Pi<float> hfMlResponseD0Daughter;
std::vector<float> outputMlDstarToD0Pi = {};
std::vector<float> outputMlD0ToKPi = {};
o2::ccdb::CcdbApi ccdbApi;

TrackSelectorPi selectorPion;
TrackSelectorKa selectorKaon;

using TracksSel = soa::Join<aod::TracksWDcaExtra, aod::TracksPidPi, aod::PidTpcTofFullPi, aod::TracksPidKa, aod::PidTpcTofFullKa>;
// using TracksSel = soa::Join<aod::Tracks, aod::TracksPidPi, aod::TracksPidKa>;
using HfFullDstarCandidate = soa::Join<aod::HfD0FromDstar, aod::HfCandDstarsWPid>;

AxisSpec axisBdtScore{100, 0.f, 1.f};
Expand All @@ -139,9 +124,6 @@ struct HfCandidateSelectorDstarToD0Pi {

void init(InitContext&)
{
massPi = MassPiPlus;
massK = MassKPlus;
massD0 = MassD0;

selectorPion.setRangePtTpc(ptPidTpcMin, ptPidTpcMax);
selectorPion.setRangeNSigmaTpc(-nSigmaTpcMax, nSigmaTpcMax);
Expand Down Expand Up @@ -183,18 +165,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
Expand Down Expand Up @@ -258,14 +228,6 @@ struct HfCandidateSelectorDstarToD0Pi {
return false;
}

if (applyMlD0Daug) {
outputMlD0ToKPi.clear();
std::vector<float> inputFeaturesD0 = hfMlResponseD0Daughter.getInputFeaturesTrigger(candidate);
bool isSelectedMlD0 = hfMlResponseD0Daughter.isSelectedMl(inputFeaturesD0, candpT, outputMlD0ToKPi);
if (!isSelectedMlD0) {
return false;
}
}
return true;
}

Expand Down Expand Up @@ -323,10 +285,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
Expand All @@ -351,10 +313,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
Expand All @@ -379,11 +341,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;
}
}
Expand Down Expand Up @@ -499,7 +461,6 @@ struct HfCandidateSelectorDstarToD0Pi {
if (applyMl) {
// ML selections
bool isSelectedMlDstar = false;

std::vector<float> inputFeatures = hfMlResponse.getInputFeatures(candDstar);
isSelectedMlDstar = hfMlResponse.isSelectedMl(inputFeatures, ptCand, outputMlDstarToD0Pi);

Expand Down
Loading