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