2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
6 * @file TrackAnalysisInfoWriteTool.icc
7 * @author Marco Aparo <marco.aparo@cern.ch>
11#include "TrackMatchingLookup.h"
12#include "TrackParametersHelper.h"
19///-------------------------
20///----- getMatchInfo ------
21///-------------------------
22template< typename Tcoll_t, typename Rcoll_t >
23IDTPM::MatchInfo_t< Tcoll_t, Rcoll_t >
24IDTPM::TrackAnalysisInfoWriteTool::getMatchInfo(
25 const Vec_t< Tcoll_t >& Tvec,
26 const Vec_t< Rcoll_t >& Rvec,
29 const ITrackMatchingLookup* matches ) const
31 VecEL_t< Tcoll_t > testVec;
32 VecEL_t< Rcoll_t > refVec;
34 Vec_t< Rcoll_t > matchedRefVec;
36 auto matches_c = dynamic_cast< const TrackMatchingLookupBase<
37 typename Tcoll_t::base_value_type,
38 typename Rcoll_t::base_value_type >* >( matches );
40 /// Loop over test vector
41 for( typename Tcoll_t::const_value_type thisTest : Tvec ) {
42 EL_t< Tcoll_t > testLink;
43 EL_t< Rcoll_t > refLink;
46 testLink.toContainedElement( *Tcoll, thisTest );
48 if( matches_c->isTestInMaps( *thisTest ) ) {
49 typename Rcoll_t::const_value_type thisRef =
50 matches_c->getMatchedRef( *thisTest );
51 refLink.toContainedElement( *Rcoll, thisRef );
52 dist = matches_c->getDist( *thisTest );
53 matchedRefVec.push_back( thisRef );
56 /// Fill both matched and unmatched tests
57 testVec.push_back( testLink );
58 refVec.push_back( refLink );
59 distVec.push_back( dist );
60 } // Close loop over test vector
62 /// Loop over reference vector
63 /// for remaining/unmatched reference only
64 for( typename Rcoll_t::const_value_type thisRef : Rvec ) {
65 EL_t< Tcoll_t > testLink;
66 EL_t< Rcoll_t > refLink;
69 /// Skip already-recorded matched references
70 if( std::find( matchedRefVec.begin(), matchedRefVec.end(), thisRef ) !=
71 matchedRefVec.end() ) continue;
73 if( matches_c->isRefInMaps( *thisRef ) ) {
74 ATH_MSG_WARNING( "Remaining reference is matched and it should not be." );
77 refLink.toContainedElement( *Rcoll, thisRef );
79 /// Fill remaining unmatched reference
80 testVec.push_back( testLink );
81 refVec.push_back( refLink );
82 distVec.push_back( dist );
83 } // Close loop over reference vector
85 return std::make_tuple( testVec, refVec, distVec );
89///---------------------------
90///----- printMatchInfo ------
91///---------------------------
92template< typename Tcoll_t, typename Rcoll_t >
93std::string IDTPM::TrackAnalysisInfoWriteTool::printMatchInfo(
94 const VecEL_t< Tcoll_t >& testVec,
95 const VecEL_t< Rcoll_t >& refVec,
96 const VecF_t& distVec ) const
100 if( testVec.size() != refVec.size() or testVec.size() != distVec.size() ) {
101 ATH_MSG_ERROR( "Vector size mismatch" );
105 for( size_t iv=0; iv<distVec.size(); iv++ ) {
106 /// return the (track or truth) particle pT
107 /// if their ElementLink is valid, i.e. if the particle exists
108 std::string testPt = testVec.at(iv).isValid() ? std::to_string( pT( **testVec.at(iv) ) ) : "N/A";
109 std::string refPt = refVec.at(iv).isValid() ? std::to_string( pT( **refVec.at(iv) ) ) : "N/A";
110 std::string dist = std::to_string( distVec.at(iv) );
111 ss << "\t\t\t\t" << testPt << " --> " << refPt << " ( " << dist << " )\n";
112 if( iv > 20 ) { ss << "\t\t\t\tet al....\n"; break; }