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
36 changes: 24 additions & 12 deletions Common/Core/TrackSelectorPID.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ class TrackSelectorPidBase
/// Checks if track is compatible with given particle species hypothesis within given TPC nσ range.
/// \param track track
/// \param conditionalTof variable to store the result of selection with looser cuts for conditional accepting of track if combined with TOF
/// \param tpcNSigmaCustom custom TPC nσ value to be used for the selection, in case the desired value cannot be taken from the track table
/// \return true if track satisfies TPC PID hypothesis for given TPC nσ range
template <typename T>
bool isSelectedByTpc(const T& track, bool& conditionalTof)
bool isSelectedByTpc(const T& track, bool& conditionalTof, float tpcNSigmaCustom = -999.f)
{
// Accept if selection is disabled via large values.
if (mNSigmaTpcMin < -999. && mNSigmaTpcMax > 999.) {
Expand All @@ -128,6 +129,11 @@ class TrackSelectorPidBase
errorPdg();
}

/// use custom TPC nσ, if a valid value is provided
if (tpcNSigmaCustom > -999.f) {
nSigma = tpcNSigmaCustom;
}

if (mNSigmaTpcMinCondTof < -999. && mNSigmaTpcMaxCondTof > 999.) {
conditionalTof = true;
} else {
Expand All @@ -140,13 +146,13 @@ class TrackSelectorPidBase
/// \param track track
/// \return TPC selection status (see TrackSelectorPID::Status)
template <typename T>
TrackSelectorPID::Status statusTpc(const T& track)
TrackSelectorPID::Status statusTpc(const T& track, float tpcNSigmaCustom = -999.f)
{
if (!isValidForTpc(track)) {
return TrackSelectorPID::NotApplicable;
}
bool condTof = false;
if (isSelectedByTpc(track, condTof)) {
if (isSelectedByTpc(track, condTof, tpcNSigmaCustom)) {
return TrackSelectorPID::Accepted;
} else if (condTof) {
return TrackSelectorPID::Conditional; // potential to be accepted if combined with TOF
Expand Down Expand Up @@ -191,9 +197,10 @@ class TrackSelectorPidBase
/// Checks if track is compatible with given particle species hypothesis within given TOF nσ range.
/// \param track track
/// \param conditionalTpc variable to store the result of selection with looser cuts for conditional accepting of track if combined with TPC
/// \param tofNSigmaCustom custom TOF nσ value to be used for the selection, in case the desired value cannot be taken from the track table
/// \return true if track satisfies TOF PID hypothesis for given TOF nσ range
template <typename T>
bool isSelectedByTof(const T& track, bool& conditionalTpc)
bool isSelectedByTof(const T& track, bool& conditionalTpc, float tofNSigmaCustom = -999.f)
{
// Accept if selection is disabled via large values.
if (mNSigmaTofMin < -999. && mNSigmaTofMax > 999.) {
Expand All @@ -216,6 +223,11 @@ class TrackSelectorPidBase
errorPdg();
}

/// use custom TOF nσ, if a valid value is provided
if (tofNSigmaCustom > -999.f) {
nSigma = tofNSigmaCustom;
}

if (mNSigmaTofMinCondTpc < -999. && mNSigmaTofMaxCondTpc > 999.) {
conditionalTpc = true;
} else {
Expand All @@ -228,13 +240,13 @@ class TrackSelectorPidBase
/// \param track track
/// \return TOF selection status (see TrackSelectorPID::Status)
template <typename T>
TrackSelectorPID::Status statusTof(const T& track)
TrackSelectorPID::Status statusTof(const T& track, float tofNSigmaCustom = -999.f)
{
if (!isValidForTof(track)) {
return TrackSelectorPID::NotApplicable;
}
bool condTpc = false;
if (isSelectedByTof(track, condTpc)) {
if (isSelectedByTof(track, condTpc, tofNSigmaCustom)) {
return TrackSelectorPID::Accepted;
} else if (condTpc) {
return TrackSelectorPID::Conditional; // potential to be accepted if combined with TPC
Expand Down Expand Up @@ -391,10 +403,10 @@ class TrackSelectorPidBase
/// \param track track
/// \return status of combined PID (TPC or TOF) (see TrackSelectorPID::Status)
template <typename T>
TrackSelectorPID::Status statusTpcOrTof(const T& track)
TrackSelectorPID::Status statusTpcOrTof(const T& track, float tpcNSigmaCustom = -999.f, float tofNSigmaCustom = -999.f)
{
int pidTpc = statusTpc(track);
int pidTof = statusTof(track);
int pidTpc = statusTpc(track, tpcNSigmaCustom);
int pidTof = statusTof(track, tofNSigmaCustom);

if (pidTpc == TrackSelectorPID::Accepted || pidTof == TrackSelectorPID::Accepted) {
return TrackSelectorPID::Accepted;
Expand All @@ -412,15 +424,15 @@ class TrackSelectorPidBase
/// \param track track
/// \return status of combined PID (TPC and TOF) (see TrackSelectorPID::Status)
template <typename T>
TrackSelectorPID::Status statusTpcAndTof(const T& track)
TrackSelectorPID::Status statusTpcAndTof(const T& track, float tpcNSigmaCustom = -999.f, float tofNSigmaCustom = -999.f)
{
int pidTpc = TrackSelectorPID::NotApplicable;
if (track.hasTPC()) {
pidTpc = statusTpc(track);
pidTpc = statusTpc(track, tpcNSigmaCustom);
}
int pidTof = TrackSelectorPID::NotApplicable;
if (track.hasTOF()) {
pidTof = statusTof(track);
pidTof = statusTof(track, tofNSigmaCustom);
}

if (pidTpc == TrackSelectorPID::Accepted && pidTof == TrackSelectorPID::Accepted) {
Expand Down
86 changes: 54 additions & 32 deletions PWGHF/Core/HfMlResponseD0ToKPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
// Fill the map of available input features
// the key is the feature's name (std::string)
// the value is the corresponding value in EnumInputFeatures
#define FILL_MAP_D0(FEATURE) \
{ \
#FEATURE, static_cast < uint8_t>(InputFeaturesD0ToKPi::FEATURE) \
#define FILL_MAP_D0(FEATURE) \
{ \
#FEATURE, static_cast<uint8_t>(InputFeaturesD0ToKPi::FEATURE) \
}

// Check if the index of mCachedIndices (index associated to a FEATURE)
Expand Down Expand Up @@ -86,6 +86,19 @@
break; \
}

// Variation of CHECK_AND_FILL_VEC_D0_HFHELPER_SIGNED(OBJECT, FEATURE, GETTER1, GETTER2)
// where GETTER1 and GETTER2 are methods of the OBJECT, and the variable
// is filled depending on whether it is a D0 or a D0bar
#define CHECK_AND_FILL_VEC_D0_SIGNED(OBJECT, FEATURE, GETTER1, GETTER2) \
case static_cast<uint8_t>(InputFeaturesD0ToKPi::FEATURE): { \
if (pdgCode == o2::constants::physics::kD0) { \
inputFeatures.emplace_back(OBJECT.GETTER1()); \
} else { \
inputFeatures.emplace_back(OBJECT.GETTER2()); \
} \
break; \
}

namespace o2::analysis
{
enum class InputFeaturesD0ToKPi : uint8_t {
Expand Down Expand Up @@ -146,12 +159,9 @@ class HfMlResponseD0ToKPi : public HfMlResponse<TypeOutputScore>

/// Method to get the input features vector needed for ML inference
/// \param candidate is the D0 candidate
/// \param prong0 is the candidate's prong0
/// \param prong1 is the candidate's prong1
/// \return inputFeatures vector
template <typename T1, typename T2>
std::vector<float> getInputFeatures(T1 const& candidate,
T2 const& prong0, T2 const& prong1, int const& pdgCode)
template <typename T1>
std::vector<float> getInputFeatures(T1 const& candidate, int const& pdgCode)
{
std::vector<float> inputFeatures;

Expand All @@ -169,32 +179,44 @@ class HfMlResponseD0ToKPi : public HfMlResponse<TypeOutputScore>
CHECK_AND_FILL_VEC_D0(impactParameterZ0);
CHECK_AND_FILL_VEC_D0(impactParameterZ1);
// TPC PID variables
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTpcPi0, tpcNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTpcKa0, tpcNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTpcPi1, tpcNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTpcKa1, tpcNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcPiExpPi, tpcNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcKaExpPi, tpcNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcPiExpKa, tpcNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcKaExpKa, tpcNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcPi0, /*getter*/ nSigTpcPi0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcKa0, /*getter*/ nSigTpcKa0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcPi1, /*getter*/ nSigTpcPi1);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcKa1, /*getter*/ nSigTpcKa1);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcPiExpPi, tpcNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcKaExpPi, tpcNSigmaKa);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcPiExpKa, tpcNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcKaExpKa, tpcNSigmaKa);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcPiExpPi, nSigTpcPi0, nSigTpcPi1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcKaExpPi, nSigTpcKa0, nSigTpcKa1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcPiExpKa, nSigTpcPi1, nSigTpcPi0);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcKaExpKa, nSigTpcKa1, nSigTpcKa0);
// TOF PID variables
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTofPi0, tofNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTofKa0, tofNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTofPi1, tofNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTofKa1, tofNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTofPiExpPi, tofNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTofKaExpPi, tofNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTofPiExpKa, tofNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTofKaExpKa, tofNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTofPi0, /*getter*/ nSigTofPi0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTofKa0, /*getter*/ nSigTofKa0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTofPi1, /*getter*/ nSigTofPi1);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTofKa1, /*getter*/ nSigTofKa1);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTofPiExpPi, tofNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTofKaExpPi, tofNSigmaKa);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTofPiExpKa, tofNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTofKaExpKa, tofNSigmaKa);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTofPiExpPi, nSigTofPi0, nSigTofPi1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTofKaExpPi, nSigTofKa0, nSigTofKa1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTofPiExpKa, nSigTofPi1, nSigTofPi0);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTofKaExpKa, nSigTofKa1, nSigTofKa0);
// Combined PID variables
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTpcTofPi0, tpcTofNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong0, nSigTpcTofKa0, tpcTofNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTpcTofPi1, tpcTofNSigmaPi);
CHECK_AND_FILL_VEC_D0_FULL(prong1, nSigTpcTofKa1, tpcTofNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcTofPiExpPi, tpcTofNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcTofKaExpPi, tpcTofNSigmaKa);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcTofPiExpKa, tpcTofNSigmaPi);
CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcTofKaExpKa, tpcTofNSigmaKa);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcTofPi0, tpcTofNSigmaPi0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcTofKa0, tpcTofNSigmaKa0);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcTofPi1, tpcTofNSigmaPi1);
CHECK_AND_FILL_VEC_D0_FULL(candidate, nSigTpcTofKa1, tpcTofNSigmaKa1);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcTofPiExpPi, tpcTofNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong0, prong1, nSigTpcTofKaExpPi, tpcTofNSigmaKa);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcTofPiExpKa, tpcTofNSigmaPi);
// CHECK_AND_FILL_VEC_D0_OBJECT_HFHELPER_SIGNED(prong1, prong0, nSigTpcTofKaExpKa, tpcTofNSigmaKa);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcTofPiExpPi, tpcTofNSigmaPi0, tpcTofNSigmaPi1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcTofKaExpPi, tpcTofNSigmaKa0, tpcTofNSigmaKa1);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcTofPiExpKa, tpcTofNSigmaPi1, tpcTofNSigmaPi0);
CHECK_AND_FILL_VEC_D0_SIGNED(candidate, nSigTpcTofKaExpKa, tpcTofNSigmaKa1, tpcTofNSigmaKa0);

CHECK_AND_FILL_VEC_D0(maxNormalisedDeltaIP);
CHECK_AND_FILL_VEC_D0_FULL(candidate, impactParameterProduct, impactParameterProduct);
Expand Down
Loading