ATLAS Offline Software
Loading...
Searching...
No Matches
OfflineMuonDecoratorAlg.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
12
13
18 const std::string& name,
19 ISvcLocator* pSvcLocator ) :
20 AthReentrantAlgorithm( name, pSvcLocator ) { }
21
22
27
29 not m_offlineTrkParticlesName.key().empty() ) );
30
32 ATH_CHECK( m_muonsName.initialize( not m_muonsName.key().empty() ) );
33
38
39 if( m_decor_mu.size() != NDecorations ) {
40 ATH_MSG_ERROR( "Incorrect booking of muon decorations" );
41 return StatusCode::FAILURE;
42 }
43
44 return StatusCode::SUCCESS;
45}
46
47
51StatusCode IDTPM::OfflineMuonDecoratorAlg::execute( const EventContext& ctx ) const {
52
55 if( not ptracks.isValid() ) {
56 ATH_MSG_ERROR( "Failed to retrieve track particles container" );
57 return StatusCode::FAILURE;
58 }
59
62 if( not pmuons.isValid() ) {
63 ATH_MSG_ERROR( "Failed to retrieve muons container" );
64 return StatusCode::FAILURE;
65 }
66
68 if( IDTPM::decorationsAllExist( *ptracks, m_decor_mu ) ) {
69 ATH_MSG_DEBUG( "All decorations already exist. Exiting gracefully" );
70 return StatusCode::SUCCESS;
71 }
72
74 std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementMuonLink_t> >
75 mu_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_mu, ctx ) );
76
77 if( mu_decor.empty() ) {
78 ATH_MSG_ERROR( "Failed to book muon decorations" );
79 return StatusCode::FAILURE;
80 }
81
82 for( const xAOD::TrackParticle* track : *ptracks ) {
84 ATH_CHECK( decorateMuonTrack( *track, mu_decor, *pmuons.ptr() ) );
85 }
86
87 return StatusCode::SUCCESS;
88}
89
90
95 const xAOD::TrackParticle& track,
97 ElementMuonLink_t > >& mu_decor,
98 const xAOD::MuonContainer& muons ) const {
99
101 for( const xAOD::Muon* muon : muons ) {
102
104 if( muon->muonType() != xAOD::Muon::Combined ) continue;
105
107 const xAOD::TrackParticle* muTrack = m_useCombinedMuonTracks.value() ?
108 *( muon->combinedTrackParticleLink() ) : // Combined track
109 *( muon->inDetTrackParticleLink() ); // ID track
110
111 if( not muTrack ) {
112 ATH_MSG_ERROR( "Corrupted matched muon ID track" );
113 return StatusCode::FAILURE;
114 }
115
116 if( muTrack == &track ) {
118 ElementMuonLink_t muLink;
119 muLink.toContainedElement( muons, muon );
120
121 ATH_MSG_DEBUG( "Found matched muon (pt=" << muon->pt() << "). Decorating track." );
122
124 IDTPM::decorateOrRejectQuietly( track, mu_decor[All], muLink );
125
127 if( muon->quality() <= xAOD::Muon::Tight ) {
128 IDTPM::decorateOrRejectQuietly( track, mu_decor[Tight], muLink );
129 }
130
132 if( muon->quality() <= xAOD::Muon::Medium ) {
133 IDTPM::decorateOrRejectQuietly( track, mu_decor[Medium], muLink );
134 }
135
137 if( muon->quality() <= xAOD::Muon::Loose ) {
138 IDTPM::decorateOrRejectQuietly( track, mu_decor[Loose], muLink );
139 }
140
142 if( muon->quality() <= xAOD::Muon::VeryLoose ) {
143 IDTPM::decorateOrRejectQuietly( track, mu_decor[VeryLoose], muLink );
144 }
145
146 return StatusCode::SUCCESS;
147 } // if( muTrack == &track )
148
149 } // close muon loop
150
151 return StatusCode::SUCCESS;
152}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Algorithm to decorate offline tracks with the corresponding offline muon object (if required for trig...
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsName
ElementLink< xAOD::MuonContainer > ElementMuonLink_t
OfflineMuonDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
std::vector< IDTPM::WriteKeyAccessorPair< xAOD::TrackParticleContainer, ElementMuonLink_t > > m_decor_mu
virtual StatusCode execute(const EventContext &ctx) const override
const std::vector< std::string > m_decor_mu_names
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticlesName
StatusCode decorateMuonTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementMuonLink_t > > &mu_decor, const xAOD::MuonContainer &muons) const
const_pointer_type ptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::pair< SG::WriteDecorHandle< ContainerType, VariableType >, bool > OptionalDecoration
bool decorationsAllExist(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, bool verbose=false)
Like above - FIXME: maybe not needed.
void createDecoratorKeysAndAccessor(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< WriteKeyAccessorPair< T_Cont, T > > &decor_out)
create a pair composed of a WriteDecorHandleKey to create a decorator handle and an accessor to check...
std::vector< OptionalDecoration< T_Cont, T > > createDecoratorsIfNeeded(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, const EventContext &ctx, bool verbose=false)
create/book the decorations if they do not exist already
void decorateOrRejectQuietly(const T_Cont_Elm &particle, OptionalDecoration< T_Cont, T > &decorator, const T &value)
Safe method to fill the decoration if decor flag is true.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".