Skip to content

Commit 0b62b01

Browse files
authored
[PWGDQ] matchingQA: added match attempts analysis (#15235)
1 parent 0b3a5c8 commit 0b62b01

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

PWGDQ/Tasks/qaMatching.cxx

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct qaMatching {
9595
double matchScoreProd{-1};
9696
double matchChi2Prod{-1};
9797
int matchRankingProd{-1};
98+
int mftMchMatchAttempts{0};
9899
MuonMatchType matchType{kMatchTypeUndefined};
99100
};
100101

@@ -442,6 +443,7 @@ struct qaMatching {
442443
o2::framework::HistPtr histVsPt;
443444
o2::framework::HistPtr histVsMcParticleDz;
444445
o2::framework::HistPtr histVsMftTrackMult;
446+
o2::framework::HistPtr histVsMatchAttempts;
445447
o2::framework::HistPtr histVsMftTrackType;
446448
o2::framework::HistPtr histVsDeltaChi2;
447449
o2::framework::HistPtr histVsProdRanking;
@@ -450,8 +452,9 @@ struct qaMatching {
450452
{
451453
AxisSpec pAxis = {100, 0, 100, "p (GeV/c)"};
452454
AxisSpec ptAxis = {100, 0, 10, "p_{T} (GeV/c)"};
453-
AxisSpec dzAxis = {100, 0, 50, "#Deltaz (cm)"};
455+
AxisSpec dzAxis = {100, -1, 4, "#Deltaz (cm)"};
454456
AxisSpec trackMultAxis = {static_cast<int>(mftMultMax) / 10, 0, static_cast<double>(mftMultMax), "MFT track mult."};
457+
AxisSpec matchAttemptsAxis = {static_cast<int>(mftMultMax) / 10, 0, static_cast<double>(mftMultMax), "match attempts"};
455458
AxisSpec trackTypeAxis = {2, 0, 2, "MFT track type"};
456459
int matchTypeMax = static_cast<int>(kMatchTypeUndefined);
457460
AxisSpec matchTypeAxis = {matchTypeMax, 0, static_cast<double>(matchTypeMax), "match type"};
@@ -465,6 +468,7 @@ struct qaMatching {
465468
histVsPt = registry->add((histName + "VsPt").c_str(), (histTitle + " vs. p_{T}").c_str(), {HistType::kTH2F, {ptAxis, indexAxis}});
466469
histVsMcParticleDz = registry->add((histName + "VsMcParticleDz").c_str(), (histTitle + " vs. MC particle #Deltaz").c_str(), {HistType::kTH2F, {dzAxis, indexAxis}});
467470
histVsMftTrackMult = registry->add((histName + "VsMftTrackMult").c_str(), (histTitle + " vs. MFT track multiplicity").c_str(), {HistType::kTH2F, {trackMultAxis, indexAxis}});
471+
histVsMatchAttempts = registry->add((histName + "VsMatchAttempts").c_str(), (histTitle + " vs. MFT track multiplicity").c_str(), {HistType::kTH2F, {matchAttemptsAxis, indexAxis}});
468472
histVsMftTrackType = registry->add((histName + "VsMftTrackType").c_str(), (histTitle + " vs. MFT track type").c_str(), {HistType::kTH2F, {trackTypeAxis, indexAxis}});
469473
std::get<std::shared_ptr<TH2>>(histVsMftTrackType)->GetXaxis()->SetBinLabel(1, "Kalman");
470474
std::get<std::shared_ptr<TH2>>(histVsMftTrackType)->GetXaxis()->SetBinLabel(2, "CA");
@@ -1757,6 +1761,41 @@ struct qaMatching {
17571761
return dimuon.M();
17581762
}
17591763

1764+
template <class EVT, class BC, class TMUON, class TMFTS>
1765+
int GetMftMchMatchAttempts(EVT const& collisions,
1766+
BC const& bcs,
1767+
TMUON const& mchTrack,
1768+
TMFTS const& mftTracks)
1769+
{
1770+
if (!mchTrack.has_collision()) {
1771+
return 0;
1772+
}
1773+
const auto& collMch = collisions.rawIteratorAt(mchTrack.collisionId());
1774+
const auto& bcMch = bcs.rawIteratorAt(collMch.bcId());
1775+
1776+
int attempts{0};
1777+
for (const auto& mftTrack : mftTracks) {
1778+
if (!mftTrack.has_collision()) {
1779+
continue;
1780+
}
1781+
1782+
const auto& collMft = collisions.rawIteratorAt(mftTrack.collisionId());
1783+
const auto& bcMft = bcs.rawIteratorAt(collMft.bcId());
1784+
1785+
int64_t deltaBc = static_cast<int64_t>(bcMft.globalBC()) - static_cast<int64_t>(bcMch.globalBC());
1786+
double deltaBcNS = o2::constants::lhc::LHCBunchSpacingNS * deltaBc;
1787+
double deltaTrackTime = mftTrack.trackTime() - mchTrack.trackTime() + deltaBcNS;
1788+
double trackTimeResTot = mftTrack.trackTimeRes() + mchTrack.trackTimeRes();
1789+
1790+
if (std::fabs(deltaTrackTime) > trackTimeResTot) {
1791+
continue;
1792+
}
1793+
attempts += 1;
1794+
}
1795+
1796+
return attempts;
1797+
}
1798+
17601799
template <class EVT, class BC, class TMUON, class TMFT>
17611800
void FillCollisions(EVT const& collisions,
17621801
BC const& bcs,
@@ -1838,6 +1877,7 @@ struct qaMatching {
18381877
matchScore,
18391878
matchChi2,
18401879
-1,
1880+
0,
18411881
kMatchTypeUndefined});
18421882
} else {
18431883
collisionInfo.matchingCandidates[mchTrackIndex].emplace_back(MatchingCandidate{
@@ -1851,6 +1891,7 @@ struct qaMatching {
18511891
matchScore,
18521892
matchChi2,
18531893
-1,
1894+
0,
18541895
kMatchTypeUndefined});
18551896
}
18561897
}
@@ -1885,13 +1926,16 @@ struct qaMatching {
18851926
for (auto& [mchIndex, globalTracksVector] : collisionInfo.matchingCandidates) {
18861927
std::sort(globalTracksVector.begin(), globalTracksVector.end(), compareMatchingScore);
18871928

1929+
const auto& mchTrack = muonTracks.rawIteratorAt(mchIndex);
1930+
auto mftMchMatchAttempts = GetMftMchMatchAttempts(collisions, bcs, mchTrack, mftTracks);
18881931
int ranking = 1;
18891932
for (auto& candidate : globalTracksVector) {
18901933
const auto& muonTrack = muonTracks.rawIteratorAt(candidate.globalTrackId);
18911934

18921935
candidate.matchRanking = ranking;
18931936
candidate.matchRankingProd = ranking;
18941937
candidate.matchType = GetMatchType(muonTrack, muonTracks, mftTracks, collisionInfo.matchablePairs, ranking);
1938+
candidate.mftMchMatchAttempts = mftMchMatchAttempts;
18951939
ranking += 1;
18961940
}
18971941
}
@@ -1950,11 +1994,14 @@ struct qaMatching {
19501994
mcParticleDz = collision.posZ() - mchMcParticle.vz();
19511995
}
19521996

1997+
int matchAttempts = globalTracksVector[0].mftMchMatchAttempts;
1998+
19531999
std::get<std::shared_ptr<TH1>>(plotter->fMatchRanking->hist)->Fill(trueMatchIndex);
19542000
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsP)->Fill(mchMom, trueMatchIndex);
19552001
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsPt)->Fill(mchPt, trueMatchIndex);
19562002
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsMcParticleDz)->Fill(mcParticleDz, trueMatchIndex);
19572003
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsMftTrackMult)->Fill(mftTrackMult, trueMatchIndex);
2004+
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsMatchAttempts)->Fill(matchAttempts, trueMatchIndex);
19582005
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsMftTrackType)->Fill(mftTrackType, trueMatchIndex);
19592006
std::get<std::shared_ptr<TH2>>(plotter->fMatchRanking->histVsProdRanking)->Fill(trueMatchIndexProd, trueMatchIndex);
19602007
if (dchi2 >= 0)
@@ -1966,6 +2013,7 @@ struct qaMatching {
19662013
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsPt)->Fill(mchPt, trueMatchIndex);
19672014
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsMcParticleDz)->Fill(mcParticleDz, trueMatchIndex);
19682015
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsMftTrackMult)->Fill(mftTrackMult, trueMatchIndex);
2016+
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsMatchAttempts)->Fill(matchAttempts, trueMatchIndex);
19692017
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsMftTrackType)->Fill(mftTrackType, trueMatchIndex);
19702018
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingGoodMCH->histVsProdRanking)->Fill(trueMatchIndexProd, trueMatchIndex);
19712019
if (dchi2 >= 0)
@@ -1978,6 +2026,7 @@ struct qaMatching {
19782026
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsPt)->Fill(mchPt, trueMatchIndex);
19792027
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsMcParticleDz)->Fill(mcParticleDz, trueMatchIndex);
19802028
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsMftTrackMult)->Fill(mftTrackMult, trueMatchIndex);
2029+
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsMatchAttempts)->Fill(matchAttempts, trueMatchIndex);
19812030
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsMftTrackType)->Fill(mftTrackType, trueMatchIndex);
19822031
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPaired->histVsProdRanking)->Fill(trueMatchIndexProd, trueMatchIndex);
19832032
if (dchi2 >= 0)
@@ -1990,6 +2039,7 @@ struct qaMatching {
19902039
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsPt)->Fill(mchPt, trueMatchIndex);
19912040
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsMcParticleDz)->Fill(mcParticleDz, trueMatchIndex);
19922041
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsMftTrackMult)->Fill(mftTrackMult, trueMatchIndex);
2042+
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsMatchAttempts)->Fill(matchAttempts, trueMatchIndex);
19932043
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsMftTrackType)->Fill(mftTrackType, trueMatchIndex);
19942044
std::get<std::shared_ptr<TH2>>(plotter->fMatchRankingPairedGoodMCH->histVsProdRanking)->Fill(trueMatchIndexProd, trueMatchIndex);
19952045
if (dchi2 >= 0)
@@ -2311,8 +2361,9 @@ struct qaMatching {
23112361
}
23122362
}
23132363

2314-
template <class C, class TMUON, class TMFT, class CMFT>
2364+
template <class C, class BC, class TMUON, class TMFT, class CMFT>
23152365
void RunChi2Matching(C const& collisions,
2366+
BC const& bcs,
23162367
TMUON const& muonTracks,
23172368
TMFT const& mftTracks,
23182369
CMFT const& mftCovs,
@@ -2410,19 +2461,23 @@ struct qaMatching {
24102461
for (auto& [mchIndex, globalTracksVector] : newMatchingCandidates) {
24112462
std::sort(globalTracksVector.begin(), globalTracksVector.end(), compareMatchingScore);
24122463

2464+
const auto& mchTrack = muonTracks.rawIteratorAt(mchIndex);
2465+
auto mftMchMatchAttempts = GetMftMchMatchAttempts(collisions, bcs, mchTrack, mftTracks);
24132466
int ranking = 1;
24142467
for (auto& candidate : globalTracksVector) {
24152468
const auto& muonTrack = muonTracks.rawIteratorAt(candidate.globalTrackId);
24162469

24172470
candidate.matchRanking = ranking;
24182471
candidate.matchType = GetMatchType(muonTrack, muonTracks, mftTracks, matchablePairs, ranking);
2472+
candidate.mftMchMatchAttempts = mftMchMatchAttempts;
24192473
ranking += 1;
24202474
}
24212475
}
24222476
}
24232477

2424-
template <class C, class TMUON, class TMFT, class CMFT>
2478+
template <class C, class BC, class TMUON, class TMFT, class CMFT>
24252479
void RunChi2Matching(C const& collisions,
2480+
BC const& bcs,
24262481
TMUON const& muonTracks,
24272482
TMFT const& mftTracks,
24282483
CMFT const& mftCovs,
@@ -2451,11 +2506,12 @@ struct qaMatching {
24512506
auto matchingPlaneZ = matchingPlanesZ[label];
24522507
auto extrapMethod = matchingExtrapMethod[label];
24532508

2454-
RunChi2Matching(collisions, muonTracks, mftTracks, mftCovs, funcName, matchingPlaneZ, extrapMethod, matchablePairs, matchingCandidates, newMatchingCandidates);
2509+
RunChi2Matching(collisions, bcs, muonTracks, mftTracks, mftCovs, funcName, matchingPlaneZ, extrapMethod, matchablePairs, matchingCandidates, newMatchingCandidates);
24552510
}
24562511

2457-
template <class C, class TMUON, class TMFT, class CMFT>
2512+
template <class C, class BC, class TMUON, class TMFT, class CMFT>
24582513
void RunMLMatching(C const& collisions,
2514+
BC const& bcs,
24592515
TMUON const& muonTracks,
24602516
TMFT const& mftTracks,
24612517
CMFT const& mftCovs,
@@ -2550,20 +2606,24 @@ struct qaMatching {
25502606
for (auto& [mchIndex, globalTracksVector] : newMatchingCandidates) {
25512607
std::sort(globalTracksVector.begin(), globalTracksVector.end(), compareMatchingScore);
25522608

2609+
const auto& mchTrack = muonTracks.rawIteratorAt(mchIndex);
2610+
auto mftMchMatchAttempts = GetMftMchMatchAttempts(collisions, bcs, mchTrack, mftTracks);
25532611
int ranking = 1;
25542612
for (auto& candidate : globalTracksVector) {
25552613
const auto& muonTrack = muonTracks.rawIteratorAt(candidate.globalTrackId);
25562614

25572615
candidate.matchRanking = ranking;
25582616
candidate.matchType = GetMatchType(muonTrack, muonTracks, mftTracks, matchablePairs, ranking);
2617+
candidate.mftMchMatchAttempts = mftMchMatchAttempts;
25592618
ranking += 1;
25602619
}
25612620
}
25622621
}
25632622

2564-
template <class C, class TMUON, class TMFT, class CMFT>
2623+
template <class C, class BC, class TMUON, class TMFT, class CMFT>
25652624
void ProcessCollisionMC(const CollisionInfo& collisionInfo,
25662625
C const& collisions,
2626+
BC const& bcs,
25672627
TMUON const& muonTracks,
25682628
TMFT const& mftTracks,
25692629
CMFT const& mftCovs)
@@ -2577,7 +2637,7 @@ struct qaMatching {
25772637
FillMatchingPlotsMC(collision, collisionInfo, muonTracks, mftTracks, collisionInfo.matchingCandidates, collisionInfo.matchingCandidates, collisionInfo.matchablePairs, fMatchingChi2ScoreMftMchLow, fChi2MatchingPlotter.get(), false);
25782638
for (auto& [label, func] : matchingChi2Functions) {
25792639
MatchingCandidates matchingCandidates;
2580-
RunChi2Matching(collisions, muonTracks, mftTracks, mftCovs, label, collisionInfo.matchablePairs, collisionInfo.matchingCandidates, matchingCandidates);
2640+
RunChi2Matching(collisions, bcs, muonTracks, mftTracks, mftCovs, label, collisionInfo.matchablePairs, collisionInfo.matchingCandidates, matchingCandidates);
25812641

25822642
auto* plotter = fMatchingPlotters.at(label).get();
25832643
double matchingScoreCut = matchingScoreCuts.at(label);
@@ -2588,7 +2648,7 @@ struct qaMatching {
25882648
// ML-based matching analysis
25892649
for (auto& [label, mlResponse] : matchingMlResponses) {
25902650
MatchingCandidates matchingCandidates;
2591-
RunMLMatching(collisions, muonTracks, mftTracks, mftCovs, label, collisionInfo.matchablePairs, collisionInfo.matchingCandidates, matchingCandidates);
2651+
RunMLMatching(collisions, bcs, muonTracks, mftTracks, mftCovs, label, collisionInfo.matchablePairs, collisionInfo.matchingCandidates, matchingCandidates);
25922652

25932653
auto* plotter = fMatchingPlotters.at(label).get();
25942654
double matchingScoreCut = matchingScoreCuts.at(label);
@@ -2668,7 +2728,7 @@ struct qaMatching {
26682728
}
26692729

26702730
for (auto const& [collisionIndex, collisionInfo] : fCollisionInfos) {
2671-
ProcessCollisionMC(collisionInfo, collisions, muonTracks, mftTracks, mftCovs);
2731+
ProcessCollisionMC(collisionInfo, collisions, bcs, muonTracks, mftTracks, mftCovs);
26722732
}
26732733
}
26742734

0 commit comments

Comments
 (0)