ATLAS Offline Software
Loading...
Searching...
No Matches
TrackAnalysisInfoWriteTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9
11#include "GaudiKernel/ISvcLocator.h"
12#include "GaudiKernel/Service.h"
13
17#include "TrackMatchingLookup.h"
18
20#include <sstream>
21
22
27 const std::string& name ) :
28 asg::AsgTool( name ) { }
29
30
35{
36 ATH_MSG_DEBUG( "Initializing " << name() );
37
39
41 m_trkAnaDefSvc = Gaudi::svcLocator()->service( "TrkAnaDefSvc" + m_anaTag.value());
42 ATH_CHECK( m_trkAnaDefSvc.isValid() );
43
44 return StatusCode::SUCCESS;
45}
46
47
53 TrackAnalysisCollections& trkAnaColls,
54 const std::string& chain,
55 unsigned int roiIdx,
56 const std::string& roiStr ) const
57{
58 ATH_MSG_DEBUG( "Writing TrackAnalysisInfo to StoreGate" );
59
60 if( not wh.key().ends_with( m_anaTag.value() ) ) {
61 ATH_MSG_ERROR( "Invalid TrkAnaInfo container name: " << wh.key() );
62 return StatusCode::FAILURE;
63 }
64
66 static const SG::Accessor< std::string > chainAcc( "chain" );
67 static const SG::Accessor< unsigned int > roiIdxAcc( "roiIdx" );
68 static const SG::Accessor< std::string > roiStrAcc( "roiStr" );
69 static const SG::Accessor< VecEL_t<xAOD::TrackParticleContainer> > testTracksAcc( "testTracks" );
70 static const SG::Accessor< VecEL_t<xAOD::TruthParticleContainer> > testTruthsAcc( "testTruths" );
71 static const SG::Accessor< VecEL_t<xAOD::TrackParticleContainer> > refTracksAcc( "refTracks" );
72 static const SG::Accessor< VecEL_t<xAOD::TruthParticleContainer> > refTruthsAcc( "refTruths" );
73 static const SG::Accessor< VecF_t > matchDistsAcc( "matchDists" );
74
76 wh->push_back( std::make_unique< SG::AuxElement >() );
77
79 if( m_trkAnaDefSvc->doTrigNavigation() ) {
80 chainAcc( *(wh->back()) ) = chain;
81 roiIdxAcc( *(wh->back()) ) = roiIdx;
82 roiStrAcc( *(wh->back()) ) = roiStr;
83 }
84
87 if( m_trkAnaDefSvc->isReferenceTruth() ) {
89 matchInfo = getMatchInfo(
92 trkAnaColls.testTrackContainer(),
93 trkAnaColls.refTruthContainer(),
94 &(trkAnaColls.matches()) );
95
96 testTracksAcc( *(wh->back()) ) = std::get<0>( matchInfo );
97 refTruthsAcc( *(wh->back()) ) = std::get<1>( matchInfo );
98 matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
99 }
101 else if( m_trkAnaDefSvc->isTestTruth() ) {
103 matchInfo = getMatchInfo(
106 trkAnaColls.testTruthContainer(),
107 trkAnaColls.refTrackContainer(),
108 &(trkAnaColls.matches()) );
109
110 testTruthsAcc( *(wh->back()) ) = std::get<0>( matchInfo );
111 refTracksAcc( *(wh->back()) ) = std::get<1>( matchInfo );
112 matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
113 }
115 else {
117 matchInfo = getMatchInfo(
120 trkAnaColls.testTrackContainer(),
121 trkAnaColls.refTrackContainer(),
122 &(trkAnaColls.matches()) );
123
124 testTracksAcc( *(wh->back()) ) = std::get<0>( matchInfo );
125 refTracksAcc( *(wh->back()) ) = std::get<1>( matchInfo );
126 matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
127 }
128
129 return StatusCode::SUCCESS;
130}
131
132
138{
139 if( not wh.isValid() ) {
140 ATH_MSG_ERROR( "Invalid collection" ); return "";
141 }
142
144 static const SG::ConstAccessor< std::string > chainCAcc( "chain" );
145 static const SG::ConstAccessor< unsigned int > roiIdxCAcc( "roiIdx" );
146 static const SG::ConstAccessor< std::string > roiStrCAcc( "roiStr" );
147 static const SG::ConstAccessor< VecEL_t<xAOD::TrackParticleContainer> > testTracksCAcc( "testTracks" );
148 static const SG::ConstAccessor< VecEL_t<xAOD::TruthParticleContainer> > testTruthsCAcc( "testTruths" );
149 static const SG::ConstAccessor< VecEL_t<xAOD::TrackParticleContainer> > refTracksCAcc( "refTracks" );
150 static const SG::ConstAccessor< VecEL_t<xAOD::TruthParticleContainer> > refTruthsCAcc( "refTruths" );
151 static const SG::ConstAccessor< VecF_t > matchDistsCAcc( "matchDists" );
152
153 std::stringstream ss;
154 ss << wh.key() << " : " << m_trkAnaDefSvc->testType()
155 << " --> " << m_trkAnaDefSvc->referenceType() << " ( dist ) :\n";
156
157 for( size_t icr=0; icr<wh->size(); icr++ ) {
158 std::string chain = chainCAcc.isAvailable( *(wh->at(icr)) ) ?
159 chainCAcc( *(wh->at(icr)) ) : "Offline";
160 std::string roiIdx = roiIdxCAcc.isAvailable( *(wh->at(icr)) ) ?
161 std::to_string( roiIdxCAcc( *(wh->at(icr)) ) ) : "N/A";
162 std::string roiStr = roiStrCAcc.isAvailable( *(wh->at(icr)) ) ?
163 roiStrCAcc( *(wh->at(icr)) ) : "N/A";
164
165 ss << "\t\tChain : " << chain << "\n";
166 ss << "\t\tRoI ( " << roiIdx << " ) : " << roiStr << "\n";
167 ss << "\t\tMatch Info (pT) : " << "\n";
168
170 if( m_trkAnaDefSvc->isReferenceTruth() ) {
172 testTracksCAcc( *(wh->at(icr)) ),
173 refTruthsCAcc( *(wh->at(icr)) ),
174 matchDistsCAcc( *(wh->at(icr)) ) );
175 }
177 else if( m_trkAnaDefSvc->isTestTruth() ) {
179 testTruthsCAcc( *(wh->at(icr)) ),
180 refTracksCAcc( *(wh->at(icr)) ),
181 matchDistsCAcc( *(wh->at(icr)) ) );
182 }
184 else {
186 testTracksCAcc( *(wh->at(icr)) ),
187 refTracksCAcc( *(wh->at(icr)) ),
188 matchDistsCAcc( *(wh->at(icr)) ) );
189 }
190
191 } // close loop over collection
192
193 return ss.str();
194}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static Double_t ss
Class to hold for each event collections needed in the TrkAnalsis.
Tool to write Track Analysis Info to StoreGate.
Look-up table (templated) class to store (internally to IDTPM) all the matches between test and refer...
const std::vector< const xAOD::TruthParticle * > & testTruthVec(Stage stage=FULL)
get TEST track vectors
const xAOD::TrackParticleContainer * refTrackContainer()
REFERENCE = Track.
const xAOD::TruthParticleContainer * testTruthContainer()
get full TEST track containers
ITrackMatchingLookup & matches()
get track matching information
const xAOD::TruthParticleContainer * refTruthContainer()
get full REFERENCE track containers
const xAOD::TrackParticleContainer * testTrackContainer()
TEST = Track.
const std::vector< const xAOD::TrackParticle * > & testTrackVec(Stage stage=FULL)
TEST = Track.
const std::vector< const xAOD::TruthParticle * > & refTruthVec(Stage stage=FULL)
get REFERENCE track vectors
const std::vector< const xAOD::TrackParticle * > & refTrackVec(Stage stage=FULL)
TEST = Track.
std::string printInfo(SG::WriteHandle< xAOD::BaseContainer > &wh) const
Print info (for debug)
TrackAnalysisInfoWriteTool(const std::string &name)
Constructor.
virtual StatusCode initialize() override
RoiSelectionTool methods.
SmartIF< ITrackAnalysisDefinitionSvc > m_trkAnaDefSvc
MatchInfo_t< Tcoll_t, Rcoll_t > getMatchInfo(const Vec_t< Tcoll_t > &Tvec, const Vec_t< Rcoll_t > &Rvec, const Tcoll_t *Tcoll, const Rcoll_t *Rcoll, const ITrackMatchingLookup *matches) const
getMatchInfo
StatusCode write(SG::WriteHandle< xAOD::BaseContainer > &wh, TrackAnalysisCollections &trkAnaColls, const std::string &chain="", unsigned int roiIdx=0, const std::string &roiStr="") const
Main writing function.
Helper class to provide type-safe access to aux data.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133
std::tuple< VecEL_t< Tcoll_t >, VecEL_t< Rcoll_t >, VecF_t > MatchInfo_t