ATLAS Offline Software
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 
10 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/Service.h"
13 #include "CxxUtils/starts_with.h"
14 
18 #include "TrackMatchingLookup.h"
19 
21 #include <sstream>
22 
23 
28  const std::string& name ) :
29  asg::AsgTool( name ), m_trkAnaDefSvc( nullptr ) { }
30 
31 
36 {
37  ATH_MSG_INFO( "Initializing " << name() );
38 
40 
42  ISvcLocator* svcLoc = Gaudi::svcLocator();
43  ATH_CHECK( svcLoc->service( "TrkAnaDefSvc" + m_anaTag.value(), m_trkAnaDefSvc ) );
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 
54  TrackAnalysisCollections& trkAnaColls,
55  const std::string& chain,
56  unsigned int roiIdx,
57  const std::string& roiStr ) const
58 {
59  ATH_MSG_DEBUG( "Writing TrackAnalysisInfo to StoreGate" );
60 
61  if( not CxxUtils::ends_with( wh.key(), m_anaTag.value() ) ) {
62  ATH_MSG_ERROR( "Invalid TrkAnaInfo container name: " << wh.key() );
63  return StatusCode::FAILURE;
64  }
65 
67  static const SG::Accessor< std::string > chainAcc( "chain" );
68  static const SG::Accessor< unsigned int > roiIdxAcc( "roiIdx" );
69  static const SG::Accessor< std::string > roiStrAcc( "roiStr" );
70  static const SG::Accessor< VecEL_t<xAOD::TrackParticleContainer> > testTracksAcc( "testTracks" );
71  static const SG::Accessor< VecEL_t<xAOD::TruthParticleContainer> > testTruthsAcc( "testTruths" );
72  static const SG::Accessor< VecEL_t<xAOD::TrackParticleContainer> > refTracksAcc( "refTracks" );
73  static const SG::Accessor< VecEL_t<xAOD::TruthParticleContainer> > refTruthsAcc( "refTruths" );
74  static const SG::Accessor< VecF_t > matchDistsAcc( "matchDists" );
75 
77  wh->push_back( std::make_unique< SG::AuxElement >() );
78 
80  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
81  chainAcc( *(wh->back()) ) = chain;
82  roiIdxAcc( *(wh->back()) ) = roiIdx;
83  roiStrAcc( *(wh->back()) ) = roiStr;
84  }
85 
88  if( m_trkAnaDefSvc->isReferenceTruth() ) {
90  matchInfo = getMatchInfo(
93  trkAnaColls.testTrackContainer(),
94  trkAnaColls.refTruthContainer(),
95  &(trkAnaColls.matches()) );
96 
97  testTracksAcc( *(wh->back()) ) = std::get<0>( matchInfo );
98  refTruthsAcc( *(wh->back()) ) = std::get<1>( matchInfo );
99  matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
100  }
102  else if( m_trkAnaDefSvc->isTestTruth() ) {
104  matchInfo = getMatchInfo(
107  trkAnaColls.testTruthContainer(),
108  trkAnaColls.refTrackContainer(),
109  &(trkAnaColls.matches()) );
110 
111  testTruthsAcc( *(wh->back()) ) = std::get<0>( matchInfo );
112  refTracksAcc( *(wh->back()) ) = std::get<1>( matchInfo );
113  matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
114  }
116  else {
118  matchInfo = getMatchInfo(
121  trkAnaColls.testTrackContainer(),
122  trkAnaColls.refTrackContainer(),
123  &(trkAnaColls.matches()) );
124 
125  testTracksAcc( *(wh->back()) ) = std::get<0>( matchInfo );
126  refTracksAcc( *(wh->back()) ) = std::get<1>( matchInfo );
127  matchDistsAcc( *(wh->back()) ) = std::get<2>( matchInfo );
128  }
129 
130  return StatusCode::SUCCESS;
131 }
132 
133 
139 {
140  if( not wh.isValid() ) {
141  ATH_MSG_ERROR( "Invalid collection" ); return "";
142  }
143 
145  static const SG::ConstAccessor< std::string > chainCAcc( "chain" );
146  static const SG::ConstAccessor< unsigned int > roiIdxCAcc( "roiIdx" );
147  static const SG::ConstAccessor< std::string > roiStrCAcc( "roiStr" );
148  static const SG::ConstAccessor< VecEL_t<xAOD::TrackParticleContainer> > testTracksCAcc( "testTracks" );
149  static const SG::ConstAccessor< VecEL_t<xAOD::TruthParticleContainer> > testTruthsCAcc( "testTruths" );
150  static const SG::ConstAccessor< VecEL_t<xAOD::TrackParticleContainer> > refTracksCAcc( "refTracks" );
151  static const SG::ConstAccessor< VecEL_t<xAOD::TruthParticleContainer> > refTruthsCAcc( "refTruths" );
152  static const SG::ConstAccessor< VecF_t > matchDistsCAcc( "matchDists" );
153 
154  std::stringstream ss;
155  ss << wh.key() << " : " << m_trkAnaDefSvc->testType()
156  << " --> " << m_trkAnaDefSvc->referenceType() << " ( dist ) :\n";
157 
158  for( size_t icr=0; icr<wh->size(); icr++ ) {
159  std::string chain = chainCAcc.isAvailable( *(wh->at(icr)) ) ?
160  chainCAcc( *(wh->at(icr)) ) : "Offline";
161  std::string roiIdx = roiIdxCAcc.isAvailable( *(wh->at(icr)) ) ?
162  std::to_string( roiIdxCAcc( *(wh->at(icr)) ) ) : "N/A";
163  std::string roiStr = roiStrCAcc.isAvailable( *(wh->at(icr)) ) ?
164  roiStrCAcc( *(wh->at(icr)) ) : "N/A";
165 
166  ss << "\t\tChain : " << chain << "\n";
167  ss << "\t\tRoI ( " << roiIdx << " ) : " << roiStr << "\n";
168  ss << "\t\tMatch Info (pT) : " << "\n";
169 
171  if( m_trkAnaDefSvc->isReferenceTruth() ) {
172  ss << printMatchInfo< xAOD::TrackParticleContainer, xAOD::TruthParticleContainer >(
173  testTracksCAcc( *(wh->at(icr)) ),
174  refTruthsCAcc( *(wh->at(icr)) ),
175  matchDistsCAcc( *(wh->at(icr)) ) );
176  }
178  else if( m_trkAnaDefSvc->isTestTruth() ) {
179  ss << printMatchInfo< xAOD::TruthParticleContainer, xAOD::TrackParticleContainer >(
180  testTruthsCAcc( *(wh->at(icr)) ),
181  refTracksCAcc( *(wh->at(icr)) ),
182  matchDistsCAcc( *(wh->at(icr)) ) );
183  }
185  else {
186  ss << printMatchInfo< xAOD::TrackParticleContainer, xAOD::TrackParticleContainer >(
187  testTracksCAcc( *(wh->at(icr)) ),
188  refTracksCAcc( *(wh->at(icr)) ),
189  matchDistsCAcc( *(wh->at(icr)) ) );
190  }
191 
192  } // close loop over collection
193 
194  return ss.str();
195 }
IDTPM::MatchInfo_t
std::tuple< VecEL_t< Tcoll_t >, VecEL_t< Rcoll_t >, VecF_t > MatchInfo_t
Definition: TrackAnalysisInfoWriteTool.h:45
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
CxxUtils::ends_with
bool ends_with(const char *s, const char *suffix)
Test whether one null-terminated byte string ends with another.
IDTPM::TrackAnalysisInfoWriteTool::initialize
virtual StatusCode initialize() override
RoiSelectionTool methods.
Definition: TrackAnalysisInfoWriteTool.cxx:35
IDTPM::TrackAnalysisInfoWriteTool::TrackAnalysisInfoWriteTool
TrackAnalysisInfoWriteTool(const std::string &name)
Constructor.
Definition: TrackAnalysisInfoWriteTool.cxx:27
asg
Definition: DataHandleTestTool.h:28
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
IDTPM::TrackAnalysisCollections::testTruthContainer
const xAOD::TruthParticleContainer * testTruthContainer()
get full TEST containers
Definition: TrackAnalysisCollections.cxx:434
IDTPM::TrackAnalysisCollections::testTrackVec
const std::vector< const xAOD::TrackParticle * > & testTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:502
TrackMatchingLookup.h
Look-up table (templated) class to store (internally to IDTPM) all the matches between test and refer...
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IDTPM::TrackAnalysisCollections::matches
ITrackMatchingLookup & matches()
return matching information
Definition: TrackAnalysisCollections.h:170
parseDir.wh
wh
Definition: parseDir.py:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackAnalysisInfoWriteTool.h
Tool to write Track Analysis Info to StoreGate.
IDTPM::TrackAnalysisInfoWriteTool::printInfo
std::string printInfo(SG::WriteHandle< xAOD::BaseContainer > &wh) const
Print info (for debug)
Definition: TrackAnalysisInfoWriteTool.cxx:137
starts_with.h
C++20-like starts_with/ends_with for strings.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
IDTPM::TrackAnalysisCollections::refTruthContainer
const xAOD::TruthParticleContainer * refTruthContainer()
get full REFERENCE containers
Definition: TrackAnalysisCollections.cxx:460
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IDTPM::TrackAnalysisCollections::testTrackContainer
const xAOD::TrackParticleContainer * testTrackContainer()
TEST = Track.
Definition: TrackAnalysisCollections.cxx:445
IDTPM::TrackAnalysisCollections::refTrackVec
const std::vector< const xAOD::TrackParticle * > & refTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:532
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:52
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
IDTPM::TrackAnalysisCollections::testTruthVec
const std::vector< const xAOD::TruthParticle * > & testTruthVec(Stage stage=FULL)
get TEST track vectors
Definition: TrackAnalysisCollections.cxx:489
IDTPM::TrackAnalysisCollections::refTrackContainer
const xAOD::TrackParticleContainer * refTrackContainer()
REFERENCE = Track.
Definition: TrackAnalysisCollections.cxx:471
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
IDTPM::TrackAnalysisInfoWriteTool::write
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.
Definition: TrackAnalysisInfoWriteTool.cxx:52
IDTPM::TrackAnalysisCollections::refTruthVec
const std::vector< const xAOD::TruthParticle * > & refTruthVec(Stage stage=FULL)
get REFERENCE track vectors
Definition: TrackAnalysisCollections.cxx:519