Skip to content

Commit 08dc892

Browse files
authored
[PWGDQ] add computation of chi2-like values from ML score (#16716)
1 parent 2d37b26 commit 08dc892

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

PWGDQ/Tasks/qaMatching.cxx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,21 @@ struct QaMatching {
19921992
return attempts;
19931993
}
19941994

1995+
template <class TMUON>
1996+
void getMatchChi2AndScore(TMUON const& muonTrack, float& matchChi2, float& matchScore)
1997+
{
1998+
matchChi2 = muonTrack.chi2MatchMCHMFT() / MatchingDegreesOfFreedom;
1999+
matchScore = muonTrack.matchScoreMCHMFT();
2000+
if (matchScore >= 0 && matchChi2 < 0) {
2001+
// match score from ML-based matching, we compute a chi2-like value from the score
2002+
float matchScoreInv = (matchScore > 0) ? 1.0 / matchScore : std::numeric_limits<float>::max();
2003+
matchChi2 = matchScoreInv - 1.f;
2004+
} else {
2005+
// we assume a standard chi2-based matching, and compute the score value from the chi2
2006+
matchScore = chi2ToScore(muonTrack.chi2MatchMCHMFT(), MatchingDegreesOfFreedom, MatchingScoreChi2Max);
2007+
}
2008+
}
2009+
19952010
template <bool isMC, class EVT, class BC, class TMUON, class TMFT>
19962011
void fillCollisions(EVT const& collisions,
19972012
BC const& bcs,
@@ -2045,8 +2060,10 @@ struct QaMatching {
20452060
} else {
20462061
// global muon tracks (MFT-MCH or MFT-MCH-MID)
20472062
int64_t muonTrackIndex = muonTrack.globalIndex();
2048-
double matchChi2 = muonTrack.chi2MatchMCHMFT() / MatchingDegreesOfFreedom;
2049-
double matchScore = chi2ToScore(muonTrack.chi2MatchMCHMFT(), MatchingDegreesOfFreedom, MatchingScoreChi2Max);
2063+
float matchChi2{-1};
2064+
float matchScore{-1};
2065+
getMatchChi2AndScore(muonTrack, matchChi2, matchScore);
2066+
20502067
auto const& mchTrack = muonTrack.template matchMCHTrack_as<TMUON>();
20512068
int64_t mchTrackIndex = mchTrack.globalIndex();
20522069
auto const& mftTrack = muonTrack.template matchMFTTrack_as<TMFT>();
@@ -2881,8 +2898,12 @@ struct QaMatching {
28812898
std::vector<float> inputML = mlResponse.getInputFeatures(muonTrack, mftTrack, mchTrack, mftTrackProp, mchTrackProp, collision);
28822899
mlResponse.isSelectedMl(inputML, 0, output);
28832900
float matchScore = output[0];
2884-
float matchChi2Prod = muonTrack.chi2MatchMCHMFT() / MatchingDegreesOfFreedom;
2885-
float matchScoreProd = chi2ToScore(muonTrack.chi2MatchMCHMFT(), MatchingDegreesOfFreedom, MatchingScoreChi2Max);
2901+
float matchScoreInv = (matchScore > 0) ? 1.0 / matchScore : std::numeric_limits<float>::max();
2902+
float matchChi2 = matchScoreInv - 1.f;
2903+
2904+
float matchChi2Prod{-1};
2905+
float matchScoreProd{-1};
2906+
getMatchChi2AndScore(muonTrack, matchChi2Prod, matchScoreProd);
28862907

28872908
// check if a vector of global muon candidates is already available for the current MCH index
28882909
// if not, initialize a new one and add the current global muon track
@@ -2897,7 +2918,7 @@ struct QaMatching {
28972918
mftTrackProp,
28982919
mchTrackProp,
28992920
matchScore,
2900-
-1,
2921+
matchChi2,
29012922
-1,
29022923
matchScoreProd,
29032924
matchChi2Prod,
@@ -2913,7 +2934,7 @@ struct QaMatching {
29132934
mftTrackProp,
29142935
mchTrackProp,
29152936
matchScore,
2916-
-1,
2937+
matchChi2,
29172938
-1,
29182939
matchScoreProd,
29192940
matchChi2Prod,

0 commit comments

Comments
 (0)