Skip to content
Merged
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
34 changes: 15 additions & 19 deletions PWGHF/TableProducer/treeCreatorLcToK0sP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <Framework/AnalysisTask.h>
#include <Framework/Configurable.h>
#include <Framework/InitContext.h>
#include <Framework/Logger.h>
#include <Framework/runDataProcessing.h>

#include <algorithm>
Expand Down Expand Up @@ -251,6 +252,13 @@ struct HfTreeCreatorLcToK0sP {
{
}

void checkMlScoresSize(int64_t candidateCount, aod::HfMlLcToK0sP const& candidateMlScores)
{
if (applyMl && candidateCount != candidateMlScores.size()) {
LOGP(fatal, "Candidate and ML score tables have different row counts ({} vs {}) while applyMl is enabled. Check applyMl in the Lc to K0s p candidate selector.", candidateCount, candidateMlScores.size());
}
}

/// \brief function to get ML score values for the current candidate and assign them to input parameters
/// \param candidate candidate instance
/// \param candidateMlScore instance of handler of vectors with ML scores associated with the current candidate
Expand All @@ -276,14 +284,16 @@ struct HfTreeCreatorLcToK0sP {
}

template <typename T, typename U>
void fillCandidate(const T& candidate, const U& bach, int8_t flagMc, int8_t originMcRec, aod::HfMlLcToK0sP::iterator const& candidateMlScore)
void fillCandidate(const T& candidate, const U& bach, int8_t flagMc, int8_t originMcRec, aod::HfMlLcToK0sP const& candidateMlScores)
{

float mlScoreFirstClass{UndefValueFloat};
float mlScoreSecondClass{UndefValueFloat};
float mlScoreThirdClass{UndefValueFloat};

if (applyMl) {
// The selector writes scores in unfiltered candidate order.
const auto candidateMlScore = candidateMlScores.rawIteratorAt(candidate.mRowIndex);
assignMlScores(candidateMlScore, mlScoreFirstClass, mlScoreSecondClass, mlScoreThirdClass);
}

Expand Down Expand Up @@ -422,11 +432,7 @@ struct HfTreeCreatorLcToK0sP {
soa::Join<aod::McParticles, aod::HfCandCascadeMcGen> const& particles,
TracksWPid const&)
{

if (applyMl && candidateMlScores.size() == 0) {
LOG(fatal) << "ML enabled but table with the ML scores is empty! Please check your configurables.";
return;
}
checkMlScoresSize(candidates.tableSize(), candidateMlScores);

// Filling event properties
rowCandidateFullEvents.reserve(collisions.size());
Expand All @@ -440,15 +446,12 @@ struct HfTreeCreatorLcToK0sP {
rowCandidateFull.reserve(candidates.size());
}

int iCand{0};
for (const auto& candidate : candidates) {
auto candidateMlScore = candidateMlScores.rawIteratorAt(iCand);
++iCand;
auto bach = candidate.prong0_as<TracksWPid>(); // bachelor
const int flag = candidate.flagMcMatchRec();

if ((fillOnlySignal && flag != 0) || (fillOnlyBackground && flag == 0) || (!fillOnlySignal && !fillOnlyBackground)) {
fillCandidate(candidate, bach, candidate.flagMcMatchRec(), candidate.originMcRec(), candidateMlScore);
fillCandidate(candidate, bach, candidate.flagMcMatchRec(), candidate.originMcRec(), candidateMlScores);
}
}

Expand All @@ -474,11 +477,7 @@ struct HfTreeCreatorLcToK0sP {
aod::HfMlLcToK0sP const& candidateMlScores,
TracksWPid const&)
{

if (applyMl && candidateMlScores.size() == 0) {
LOG(fatal) << "ML enabled but table with the ML scores is empty! Please check your configurables.";
return;
}
checkMlScoresSize(candidates.size(), candidateMlScores);

// Filling event properties
rowCandidateFullEvents.reserve(collisions.size());
Expand All @@ -493,14 +492,11 @@ struct HfTreeCreatorLcToK0sP {
rowCandidateFull.reserve(candidates.size());
}

int iCand{0};
for (const auto& candidate : candidates) {
auto candidateMlScore = candidateMlScores.rawIteratorAt(iCand);
++iCand;
auto bach = candidate.prong0_as<TracksWPid>(); // bachelor
double const pseudoRndm = bach.pt() * 1000. - static_cast<int16_t>(bach.pt() * 1000);
if (candidate.isSelLcToK0sP() >= 1 && pseudoRndm < downSampleBkgFactor) {
fillCandidate(candidate, bach, 0, 0, candidateMlScore);
fillCandidate(candidate, bach, 0, 0, candidateMlScores);
}
}
}
Expand Down
Loading