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 
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_INFO( "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->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
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() ) {
171  ss << printMatchInfo< xAOD::TrackParticleContainer, xAOD::TruthParticleContainer >(
172  testTracksCAcc( *(wh->at(icr)) ),
173  refTruthsCAcc( *(wh->at(icr)) ),
174  matchDistsCAcc( *(wh->at(icr)) ) );
175  }
177  else if( m_trkAnaDefSvc->isTestTruth() ) {
178  ss << printMatchInfo< xAOD::TruthParticleContainer, xAOD::TrackParticleContainer >(
179  testTruthsCAcc( *(wh->at(icr)) ),
180  refTracksCAcc( *(wh->at(icr)) ),
181  matchDistsCAcc( *(wh->at(icr)) ) );
182  }
184  else {
185  ss << printMatchInfo< xAOD::TrackParticleContainer, xAOD::TrackParticleContainer >(
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 }
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:46
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
IDTPM::TrackAnalysisInfoWriteTool::initialize
virtual StatusCode initialize() override
RoiSelectionTool methods.
Definition: TrackAnalysisInfoWriteTool.cxx:34
IDTPM::TrackAnalysisInfoWriteTool::TrackAnalysisInfoWriteTool
TrackAnalysisInfoWriteTool(const std::string &name)
Constructor.
Definition: TrackAnalysisInfoWriteTool.cxx:26
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 track containers
Definition: TrackAnalysisCollections.cxx:721
IDTPM::TrackAnalysisCollections::testTrackVec
const std::vector< const xAOD::TrackParticle * > & testTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:789
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()
get track matching information
Definition: TrackAnalysisCollections.h:261
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:136
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IDTPM::TrackAnalysisCollections::refTruthContainer
const xAOD::TruthParticleContainer * refTruthContainer()
get full REFERENCE track containers
Definition: TrackAnalysisCollections.cxx:747
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:732
IDTPM::TrackAnalysisCollections::refTrackVec
const std::vector< const xAOD::TrackParticle * > & refTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:819
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:54
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:776
IDTPM::TrackAnalysisCollections::refTrackContainer
const xAOD::TrackParticleContainer * refTrackContainer()
REFERENCE = Track.
Definition: TrackAnalysisCollections.cxx:758
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:51
IDTPM::TrackAnalysisCollections::refTruthVec
const std::vector< const xAOD::TruthParticle * > & refTruthVec(Stage stage=FULL)
get REFERENCE track vectors
Definition: TrackAnalysisCollections.cxx:806