@@ -252,6 +252,7 @@ struct QaMatching {
252252 int64_t globalTrackId{-1 };
253253 int64_t muonTrackId{-1 };
254254 int64_t mftTrackId{-1 };
255+ int trackType{-1 };
255256 o2::track::TrackParCovFwd mftTrackProp;
256257 o2::track::TrackParCovFwd mchTrackProp;
257258 double matchScore{-1 };
@@ -1332,35 +1333,31 @@ struct QaMatching {
13321333 return isGoodMft (mftTrack, cfgTrackChi2MftUp, cfgTrackNClustMftLow);
13331334 }
13341335
1335- template <class TMUON >
1336- bool isGoodGlobalMatching (const TMUON & muonTrack,
1337- double matchingScore,
1336+ bool isGoodGlobalMatching (const MatchingCandidate& candidate,
13381337 double matchingScoreCut)
13391338 {
1340- if (static_cast <int >(muonTrack .trackType () ) > GlobalTrackTypeMax)
1339+ if (static_cast <int >(candidate .trackType ) > GlobalTrackTypeMax)
13411340 return false ;
13421341
13431342 // MFT-MCH matching score cut
1344- if (matchingScore < matchingScoreCut)
1343+ if (candidate. matchScore < matchingScoreCut)
13451344 return false ;
13461345
13471346 return true ;
13481347 }
13491348
1350- template <class TMUON >
1351- bool isGoodGlobalMatching (const TMUON & muonTrack, double matchingScore)
1349+ bool isGoodGlobalMatching (const MatchingCandidate& candidate)
13521350 {
1353- return isGoodGlobalMatching (muonTrack, matchingScore , cfgMatchingChi2ScoreMftMchLow);
1351+ return isGoodGlobalMatching (candidate , cfgMatchingChi2ScoreMftMchLow);
13541352 }
13551353
1356- template <class TMUON >
1357- bool isTrueGlobalMatching (const TMUON & muonTrack, const std::vector<std::pair<int64_t , int64_t >>& matchablePairs)
1354+ bool isTrueGlobalMatching (const MatchingCandidate& candidate, const std::vector<std::pair<int64_t , int64_t >>& matchablePairs)
13581355 {
1359- if (static_cast < int >(muonTrack .trackType ()) > GlobalTrackTypeMax)
1356+ if (candidate .trackType > GlobalTrackTypeMax)
13601357 return false ;
13611358
1362- int64_t mchTrackId = static_cast < int64_t >(muonTrack. matchMCHTrackId ()) ;
1363- int64_t mftTrackId = static_cast < int64_t >(muonTrack. matchMFTTrackId ()) ;
1359+ int64_t mchTrackId = candidate. muonTrackId ;
1360+ int64_t mftTrackId = candidate. mftTrackId ;
13641361
13651362 std::pair<int64_t , int64_t > trackIndexes = std::make_pair (mchTrackId, mftTrackId);
13661363
@@ -1739,19 +1736,15 @@ struct QaMatching {
17391736 }
17401737 }
17411738
1742- template <class TMUON >
1743- int getTrueMatchIndex (TMUON const & muonTracks,
1744- const std::vector<MatchingCandidate>& matchCandidatesVector,
1739+ int getTrueMatchIndex (const std::vector<MatchingCandidate>& matchCandidatesVector,
17451740 const std::vector<std::pair<int64_t , int64_t >>& matchablePairs)
17461741 {
17471742 // find the index of the matching candidate that corresponds to the true match
17481743 // index=1 corresponds to the leading candidate
17491744 // index=0 means no candidate was found that corresponds to the true match
17501745 int trueMatchIndex = 0 ;
17511746 for (size_t i = 0 ; i < matchCandidatesVector.size (); i++) {
1752- auto const & muonTrack = muonTracks.rawIteratorAt (matchCandidatesVector[i].globalTrackId );
1753-
1754- if (isTrueGlobalMatching (muonTrack, matchablePairs)) {
1747+ if (isTrueGlobalMatching (matchCandidatesVector[i], matchablePairs)) {
17551748 trueMatchIndex = i + 1 ;
17561749 break ;
17571750 }
@@ -1795,20 +1788,20 @@ struct QaMatching {
17951788 return isMuon (mchTrack, mftTrack);
17961789 }
17971790
1798- template <class TMUON , class TMUONS , class TMFTS >
1799- MuonMatchType getMatchType (const TMUON & muonTrack ,
1800- TMUONS const & /* muonTracks*/ ,
1791+ template <class TMUONS , class TMFTS >
1792+ MuonMatchType getMatchType (const MatchingCandidate& candidate ,
1793+ TMUONS const & muonTracks,
18011794 TMFTS const & mftTracks,
18021795 const std::vector<std::pair<int64_t , int64_t >>& matchablePairs,
18031796 int ranking)
18041797 {
1805- if (static_cast < int >(muonTrack .trackType ()) > GlobalTrackTypeMax)
1798+ if (candidate .trackType > GlobalTrackTypeMax)
18061799 return kMatchTypeUndefined ;
18071800
1808- auto const & mchTrack = muonTrack. template matchMCHTrack_as < TMUONS >( );
1801+ auto const & mchTrack = muonTracks. rawIteratorAt (candidate. muonTrackId );
18091802
1810- bool isPairable = isMatchableMch (mchTrack. globalIndex () , matchablePairs);
1811- bool isTrueMatch = isTrueGlobalMatching (muonTrack , matchablePairs);
1803+ bool isPairable = isMatchableMch (candidate. muonTrackId , matchablePairs);
1804+ bool isTrueMatch = isTrueGlobalMatching (candidate , matchablePairs);
18121805 int decayRanking = getDecayRanking (mchTrack, mftTracks);
18131806
18141807 MuonMatchType result{kMatchTypeUndefined };
@@ -2069,6 +2062,7 @@ struct QaMatching {
20692062 muonTrackIndex,
20702063 mchTrackIndex,
20712064 mftTrackIndex,
2065+ static_cast <int >(muonTrack.trackType ()),
20722066 mftTrackProp,
20732067 mchTrackProp,
20742068 matchScore,
@@ -2085,6 +2079,7 @@ struct QaMatching {
20852079 muonTrackIndex,
20862080 mchTrackIndex,
20872081 mftTrackIndex,
2082+ static_cast <int >(muonTrack.trackType ()),
20882083 mftTrackProp,
20892084 mchTrackProp,
20902085 matchScore,
@@ -2136,12 +2131,10 @@ struct QaMatching {
21362131 auto mftMchMatchAttempts = getMftMchMatchAttempts (collisions, bcs, mchTrack, mftTracks);
21372132 int ranking = 1 ;
21382133 for (auto & candidate : globalTracksVector) { // o2-linter: disable=const-ref-in-for-loop (object is modified in loop)
2139- const auto & muonTrack = muonTracks.rawIteratorAt (candidate.globalTrackId );
2140-
21412134 candidate.matchRanking = ranking;
21422135 candidate.matchRankingProd = ranking;
21432136 if constexpr (isMC) {
2144- candidate.matchType = getMatchType (muonTrack , muonTracks, mftTracks, collisionInfo.matchablePairs , ranking);
2137+ candidate.matchType = getMatchType (candidate , muonTracks, mftTracks, collisionInfo.matchablePairs , ranking);
21452138 } else {
21462139 candidate.matchType = kMatchTypeUndefined ;
21472140 }
@@ -2217,13 +2210,11 @@ struct QaMatching {
22172210
22182211 // loop over candidates
22192212 for (const auto & candidate : globalTracksVector) {
2220- auto const & muonTrack = muonTracks.rawIteratorAt (candidate.globalTrackId );
2221-
22222213 float matchScore = candidate.matchScore ;
22232214 float matchChi2 = candidate.matchChi2 ;
22242215
2225- float matchChi2Prod = muonTrack. chi2MatchMCHMFT () / 5 . f ;
2226- float matchScoreProd = chi2ToScore (muonTrack. chi2MatchMCHMFT (), 5 , 50 . f ) ;
2216+ float matchChi2Prod = candidate. matchChi2Prod ;
2217+ float matchScoreProd = candidate. matchScoreProd ;
22272218
22282219 std::get<std::shared_ptr<TH2 >>(plotter->fMatchScoreVsProd )->Fill (matchScoreProd, matchScore);
22292220 std::get<std::shared_ptr<TH2 >>(plotter->fMatchChi2VsProd )->Fill (matchChi2Prod, matchChi2);
@@ -2275,8 +2266,9 @@ struct QaMatching {
22752266 // find the index of the matching candidate that corresponds to the true match
22762267 // index=1 corresponds to the leading candidate
22772268 // index=0 means no candidate was found that corresponds to the true match
2278- int trueMatchIndex = getTrueMatchIndex (muonTracks, globalTracksVector, matchablePairs);
2279- int trueMatchIndexProd = getTrueMatchIndex (muonTracks, matchingCandidatesProd.at (mchIndex), matchablePairs);
2269+ int trueMatchIndex = getTrueMatchIndex (globalTracksVector, matchablePairs);
2270+ const auto prodCandidatesIt = matchingCandidatesProd.find (mchIndex);
2271+ int trueMatchIndexProd = (prodCandidatesIt != matchingCandidatesProd.end ()) ? getTrueMatchIndex (prodCandidatesIt->second , matchablePairs) : 0 ;
22802272
22812273 float mcParticleDz = -1000 ;
22822274 if (mchTrack.has_mcParticle ()) {
@@ -2462,18 +2454,16 @@ struct QaMatching {
24622454 if (globalTracksVector.size () < 1 )
24632455 continue ;
24642456
2465- int trueMatchIndex = getTrueMatchIndex (muonTracks, globalTracksVector, matchablePairs);
2457+ int trueMatchIndex = getTrueMatchIndex (globalTracksVector, matchablePairs);
24662458
24672459 // loop over candidates
24682460 int candidateIndex = 1 ;
24692461 for (const auto & candidate : globalTracksVector) {
2470- auto const & muonTrack = muonTracks.rawIteratorAt (candidate.globalTrackId );
2471-
24722462 float matchScore = candidate.matchScore ;
24732463 float matchChi2 = candidate.matchChi2 ;
24742464
2475- float matchChi2Prod = muonTrack. chi2MatchMCHMFT () / 5 . f ;
2476- float matchScoreProd = chi2ToScore (muonTrack. chi2MatchMCHMFT (), 5 , 50 . f ) ;
2465+ float matchChi2Prod = candidate. matchChi2Prod ;
2466+ float matchScoreProd = candidate. matchScoreProd ;
24772467
24782468 std::get<std::shared_ptr<TH2 >>(plotter->fMatchScoreVsProd )->Fill (matchScoreProd, matchScore);
24792469 std::get<std::shared_ptr<TH2 >>(plotter->fMatchChi2VsProd )->Fill (matchChi2Prod, matchChi2);
@@ -2493,10 +2483,6 @@ struct QaMatching {
24932483 if (globalTracksVector.size () < 1 )
24942484 continue ;
24952485
2496- // get the leading matching candidate
2497- auto const & muonTrack = muonTracks.rawIteratorAt (globalTracksVector[0 ].globalTrackId );
2498- double matchingScore = globalTracksVector[0 ].matchScore ;
2499-
25002486 // get the standalone MCH and MFT tracks
25012487 auto const & mchTrack = muonTracks.rawIteratorAt (mchIndex);
25022488
@@ -2505,14 +2491,14 @@ struct QaMatching {
25052491 continue ;
25062492
25072493 // skip candidates that do not pass the matching quality cuts
2508- if (!isGoodGlobalMatching (muonTrack, matchingScore , matchingScoreCut))
2494+ if (!isGoodGlobalMatching (globalTracksVector[ 0 ] , matchingScoreCut))
25092495 continue ;
25102496
25112497 // check if the matching candidate is a true one
2512- bool isTrueMatch = isTrueGlobalMatching (muonTrack , matchablePairs);
2498+ bool isTrueMatch = isTrueGlobalMatching (globalTracksVector[ 0 ] , matchablePairs);
25132499
25142500 // ---- MC ancestry ----
2515- auto motherParticles = getMotherParticles (muonTrack );
2501+ auto motherParticles = getMotherParticles (mchTrack );
25162502 int motherPDG = 0 ;
25172503 if (motherParticles.size () > 1 ) {
25182504 motherPDG = motherParticles[1 ].first ;
@@ -2544,15 +2530,10 @@ struct QaMatching {
25442530 if (matchingCandidates.count (matchableMchIndex) > 0 ) {
25452531 const auto & globalTracksVector = matchingCandidates.at (static_cast <int64_t >(matchableMchIndex));
25462532 if (!globalTracksVector.empty ()) {
2547- // get the leading matching candidate
2548- auto const & muonTrack = muonTracks.rawIteratorAt (globalTracksVector[0 ].globalTrackId );
2549- double matchingScore = globalTracksVector[0 ].matchScore ;
2533+ // get the standalone MFT track index
2534+ auto mftIndex = globalTracksVector[0 ].mftTrackId ;
25502535
2551- // get the standalone MFT track
2552- auto const & mftTrack = muonTrack.template matchMFTTrack_as <TMFT >();
2553- auto mftIndex = mftTrack.globalIndex ();
2554-
2555- goodMatchFound = isGoodGlobalMatching (muonTrack, matchingScore, matchingScoreCut);
2536+ goodMatchFound = isGoodGlobalMatching (globalTracksVector[0 ], matchingScoreCut);
25562537 isTrueMatch = (mftIndex == matchableMftIndex);
25572538 }
25582539 }
@@ -2631,10 +2612,6 @@ struct QaMatching {
26312612
26322613 auto const & collision = collisions.rawIteratorAt (muon1.first );
26332614
2634- auto const & muonTrack1 = muonTracks.rawIteratorAt (candidates1[0 ].globalTrackId );
2635- auto const & muonTrack2 = muonTracks.rawIteratorAt (candidates2[0 ].globalTrackId );
2636- auto matchScore1 = candidates1[0 ].matchScore ;
2637- auto matchScore2 = candidates2[0 ].matchScore ;
26382615 auto const & mchTrack1 = muonTracks.rawIteratorAt (candidates1[0 ].muonTrackId );
26392616 auto const & mchTrack2 = muonTracks.rawIteratorAt (candidates2[0 ].muonTrackId );
26402617 auto const & mftTrack1 = mftTracks.rawIteratorAt (candidates1[0 ].mftTrackId );
@@ -2660,7 +2637,7 @@ struct QaMatching {
26602637 continue ;
26612638 }
26622639
2663- bool goodGlobalMuonMatches = (isGoodGlobalMatching (muonTrack1, matchScore1 ) && isGoodGlobalMatching (muonTrack2, matchScore2 ));
2640+ bool goodGlobalMuonMatches = (isGoodGlobalMatching (candidates1[ 0 ] ) && isGoodGlobalMatching (candidates2[ 0 ] ));
26642641
26652642 double massMCH = getMuMuInvariantMass (propagateToVertexMch (mchTrack1, collision),
26662643 propagateToVertexMch (mchTrack2, collision));
@@ -2747,6 +2724,7 @@ struct QaMatching {
27472724 candidate.globalTrackId ,
27482725 mchIndex,
27492726 mftTrack.globalIndex (),
2727+ candidate.trackType ,
27502728 mftTrackProp,
27512729 mchTrackProp,
27522730 matchScore,
@@ -2762,6 +2740,7 @@ struct QaMatching {
27622740 candidate.globalTrackId ,
27632741 mchIndex,
27642742 mftTrack.globalIndex (),
2743+ candidate.trackType ,
27652744 mftTrackProp,
27662745 mchTrackProp,
27672746 matchScore,
@@ -2787,11 +2766,9 @@ struct QaMatching {
27872766 auto mftMchMatchAttempts = getMftMchMatchAttempts (collisions, bcs, mchTrack, mftTracks);
27882767 int ranking = 1 ;
27892768 for (auto & candidate : globalTracksVector) { // o2-linter: disable=const-ref-in-for-loop (object is modified in loop)
2790- const auto & muonTrack = muonTracks.rawIteratorAt (candidate.globalTrackId );
2791-
27922769 candidate.matchRanking = ranking;
27932770 if constexpr (isMC) {
2794- candidate.matchType = getMatchType (muonTrack , muonTracks, mftTracks, matchablePairs, ranking);
2771+ candidate.matchType = getMatchType (candidate , muonTracks, mftTracks, matchablePairs, ranking);
27952772 } else {
27962773 candidate.matchType = kMatchTypeUndefined ;
27972774 }
@@ -2896,6 +2873,7 @@ struct QaMatching {
28962873 candidate.globalTrackId ,
28972874 mchIndex,
28982875 mftTrack.globalIndex (),
2876+ candidate.trackType ,
28992877 mftTrackProp,
29002878 mchTrackProp,
29012879 matchScore,
@@ -2911,6 +2889,7 @@ struct QaMatching {
29112889 candidate.globalTrackId ,
29122890 mchIndex,
29132891 mftTrack.globalIndex (),
2892+ candidate.trackType ,
29142893 mftTrackProp,
29152894 mchTrackProp,
29162895 matchScore,
@@ -2936,11 +2915,9 @@ struct QaMatching {
29362915 auto mftMchMatchAttempts = getMftMchMatchAttempts (collisions, bcs, mchTrack, mftTracks);
29372916 int ranking = 1 ;
29382917 for (auto & candidate : globalTracksVector) { // o2-linter: disable=const-ref-in-for-loop (object is modified in loop)
2939- const auto & muonTrack = muonTracks.rawIteratorAt (candidate.globalTrackId );
2940-
29412918 candidate.matchRanking = ranking;
29422919 if constexpr (isMC) {
2943- candidate.matchType = getMatchType (muonTrack , muonTracks, mftTracks, matchablePairs, ranking);
2920+ candidate.matchType = getMatchType (candidate , muonTracks, mftTracks, matchablePairs, ranking);
29442921 } else {
29452922 candidate.matchType = kMatchTypeUndefined ;
29462923 }
0 commit comments