ATLAS Offline Software
GSFTrackParticleMapCnvAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Gaudi/Athena include(s):
7 
8 // EDM include(s):
14 // Local include(s):
16 
17 namespace xAODMaker {
18 
20  ISvcLocator* svcLoc )
21  : AthAlgorithm( name, svcLoc ) {
22 
23  declareProperty( "AODContainerName", m_aodContainerName = "TrackParticleCandidate" );
24  declareProperty( "xAODContainerName", m_xaodContainerName = "InDetTrackParticles" );
25  declareProperty( "AODContainerNameGSF", m_aodContainerNameGSF = "GSFTrackParticleCandidate" );
26  declareProperty( "xAODContainerNameGSF", m_xaodContainerNameGSF = "GSFTrackParticles" );
27  declareProperty( "TrackMapName", m_trackMapName="GSFTrackAssociation", "Old new Track Map Name" );
28 
29  }
30 
32 
33  ATH_MSG_INFO( "Initializing" );
34  ATH_MSG_INFO( "AODContainerNameGSF = " << m_aodContainerNameGSF );
35  ATH_MSG_INFO( "xAODContainerName = " << m_xaodContainerName );
36  ATH_MSG_INFO( "AODContainerNameGSF = " << m_aodContainerNameGSF );
37  ATH_MSG_INFO( "xAODContainerNameGSF = " << m_xaodContainerNameGSF );
38 
39 
40  // Return gracefully:
41  return StatusCode::SUCCESS;
42  }
43 
45 
47 
48  // Retrieve the track particles from AOD
49  const Rec::TrackParticleContainer* aodContainer = evtStore()->tryConstRetrieve<Rec::TrackParticleContainer>(m_aodContainerName );
50  if( !aodContainer ) {
51  ATH_MSG_WARNING("No AOD TrackParticle container found in TES: StoreGate Key = " <<m_aodContainerName);
52  return StatusCode::SUCCESS;
53  }
54  ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerName );
55 
56 
57  // Retrieve the GSF track particles from AOD
58  const Rec::TrackParticleContainer* aodContainerGSF = evtStore()->tryConstRetrieve<Rec::TrackParticleContainer>(m_aodContainerNameGSF );
59  if( !aodContainerGSF ) {
60  ATH_MSG_WARNING("No AOD GSFTrackParticle container found in TES: StoreGate Key = " << m_aodContainerNameGSF);
61  return StatusCode::SUCCESS;
62  }
63  ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerNameGSF );
64 
65  // Retrieve the GSF track particles from xAOD
66  const xAOD::TrackParticleContainer* xaodContainerGSF = evtStore()->tryConstRetrieve<xAOD::TrackParticleContainer>(m_xaodContainerNameGSF );
67  if( !xaodContainerGSF ) {
68  ATH_MSG_WARNING("No xAOD GSFTrackParticle container found in TES: StoreGate Key = " << m_xaodContainerNameGSF);
69  return StatusCode::SUCCESS;
70  }
71  ATH_MSG_DEBUG( "Retrieved particles with key: " << m_xaodContainerNameGSF );
72 
73  // Retrieve the GSF -> Trk associations
74  const TrackParticleAssocs *trkassocs = nullptr;
75  StatusCode sc=evtStore()->retrieve( trkassocs, m_trackMapName ) ;
76 
77  if( sc.isFailure()) {
78  ATH_MSG_WARNING( "Could not retrieve " << m_trackMapName);
79  return StatusCode::SUCCESS;
80  }
81 
83 
84  // Loop over the GSF track particles from the AOD and the GSF ones from xAOD
85  // assuming they are aligned
86  Rec::TrackParticleContainer::const_iterator aod = aodContainerGSF->begin();
87  Rec::TrackParticleContainer::const_iterator aodEnd = aodContainerGSF->end();
88 
89  xAOD::TrackParticleContainer::const_iterator xaod = xaodContainerGSF->begin();
90  xAOD::TrackParticleContainer::const_iterator xaodEnd = xaodContainerGSF->end();
91 
92  for ( ; aod != aodEnd && xaod != xaodEnd; ++aod, ++xaod){
94 
95  if ( !trkassocs->assocs(*aod, associatedElems) ){
96  ATH_MSG_WARNING("Missing link from GSF track particle to original TP");
97  continue;
98  }
99 
100  // Old link to AOD container
101  ElementLink<Rec::TrackParticleContainer> oldLink(associatedElems.at(0), *aodContainer);
102 
103  // New link to xAOD container of non-GSF track particles
105  newLink.resetWithKeyAndIndex( m_xaodContainerName, oldLink.index() );
106 
107  // Set new link as a decoration of the new GSF track particle
108  if(newLink.isValid()){
109  newLink.toPersistent();
111  originalTrackParticleDec ("originalTrackParticle");
112  originalTrackParticleDec (**xaod) = newLink;
113  }
114  }
115 
116  // Return gracefully:
117  return StatusCode::SUCCESS;
118  }
119 
120 } // namespace xAODMaker
121 
ConstDataVector::at
ElementProxy at(size_type n)
Access an element, as an lvalue.
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TrackParticleAssocs::assocs
bool assocs(const Rec::TrackParticle *object, ConstDataVector< Rec::TrackParticleContainer > &associatedElems) const
Retrieve all the associated-to objects which have been associated to the given.
Definition: TrackParticleAssocs.cxx:47
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::GSFTrackParticleMapCnvAlg::m_aodContainerName
std::string m_aodContainerName
The name of the AOD GSF TrackParticle container.
Definition: GSFTrackParticleMapCnvAlg.h:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TrackParticleAssocs.h
xAODMaker::GSFTrackParticleMapCnvAlg::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: GSFTrackParticleMapCnvAlg.cxx:46
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
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
xAODMaker::GSFTrackParticleMapCnvAlg::GSFTrackParticleMapCnvAlg
GSFTrackParticleMapCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: GSFTrackParticleMapCnvAlg.cxx:19
GSFTrackParticleMapCnvAlg.h
TrackParticleAssocs
Definition: TrackParticleAssocs.h:28
DataVector< xAOD::TrackParticle_v1 >
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Rec::TrackParticleContainer
Definition: Reconstruction/Particle/Particle/TrackParticleContainer.h:33
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
xAODMaker::GSFTrackParticleMapCnvAlg::m_xaodContainerNameGSF
std::string m_xaodContainerNameGSF
The name of the xAOD GSF TrackParticle container.
Definition: GSFTrackParticleMapCnvAlg.h:46
xAODMaker::GSFTrackParticleMapCnvAlg::m_xaodContainerName
std::string m_xaodContainerName
The name of the xAOD non-GSF TrackParticle container.
Definition: GSFTrackParticleMapCnvAlg.h:48
xAODMaker::GSFTrackParticleMapCnvAlg::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: GSFTrackParticleMapCnvAlg.cxx:31
Decorator.h
Helper class to provide type-safe access to aux data.
xAODMaker::GSFTrackParticleMapCnvAlg::m_trackMapName
std::string m_trackMapName
The name of the map from AOD GSF TrackParticles to AOD TrackParticles.
Definition: GSFTrackParticleMapCnvAlg.h:50
xAODMaker::GSFTrackParticleMapCnvAlg::m_aodContainerNameGSF
std::string m_aodContainerNameGSF
The name of the AOD GSF TrackParticle container.
Definition: GSFTrackParticleMapCnvAlg.h:44
TrackParticleContainer.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TrackParticleContainer.h