ATLAS Offline Software
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 
12 
13 
18  const std::string& name,
19  ISvcLocator* pSvcLocator ) :
20  AthReentrantAlgorithm( name, pSvcLocator ) { }
21 
22 
27 
28  ATH_CHECK( m_offlineTrkParticlesName.initialize(
29  not m_offlineTrkParticlesName.key().empty() ) );
30 
32  ATH_CHECK( m_muonsName.initialize( not m_muonsName.key().empty() ) );
33 
36  *this, m_offlineTrkParticlesName,
37  m_prefix.value(), m_decor_mu_names, m_decor_mu );
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 
51 StatusCode IDTPM::OfflineMuonDecoratorAlg::execute( const EventContext& ctx ) const {
52 
54  SG::ReadHandle< xAOD::TrackParticleContainer > ptracks( m_offlineTrkParticlesName, ctx );
55  if( not ptracks.isValid() ) {
56  ATH_MSG_ERROR( "Failed to retrieve track particles container" );
57  return StatusCode::FAILURE;
58  }
59 
61  SG::ReadHandle< xAOD::MuonContainer > pmuons( m_muonsName, ctx );
62  if( not pmuons.isValid() ) {
63  ATH_MSG_ERROR( "Failed to retrieve muons container" );
64  return StatusCode::FAILURE;
65  }
66 
67  std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementMuonLink_t> >
68  mu_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_mu, ctx ) );
69 
70  if( mu_decor.empty() ) {
71  ATH_MSG_ERROR( "Failed to book muon decorations" );
72  return StatusCode::FAILURE;
73  }
74 
75  for( const xAOD::TrackParticle* track : *ptracks ) {
77  ATH_CHECK( decorateMuonTrack( *track, mu_decor, *pmuons.ptr() ) );
78  }
79 
80  return StatusCode::SUCCESS;
81 }
82 
83 
90  ElementMuonLink_t > >& mu_decor,
91  const xAOD::MuonContainer& muons ) const {
92 
94  for( const xAOD::Muon* muon : muons ) {
95 
97  if( muon->muonType() != xAOD::Muon::Combined ) continue;
98 
100  const xAOD::TrackParticle* muTrack = m_useCombinedMuonTracks.value() ?
101  *( muon->combinedTrackParticleLink() ) : // Combined track
102  *( muon->inDetTrackParticleLink() ); // ID track
103 
104  if( not muTrack ) {
105  ATH_MSG_ERROR( "Corrupted matched muon ID track" );
106  return StatusCode::FAILURE;
107  }
108 
109  if( muTrack == &track ) {
111  ElementMuonLink_t muLink;
112  muLink.toContainedElement( muons, muon );
113 
114  ATH_MSG_DEBUG( "Found matched muon (pt=" << muon->pt() << "). Decorating track." );
115 
117  IDTPM::decorateOrRejectQuietly( track, mu_decor[All], muLink );
118 
120  if( muon->quality() <= xAOD::Muon::Tight ) {
121  IDTPM::decorateOrRejectQuietly( track, mu_decor[Tight], muLink );
122  }
123 
125  if( muon->quality() <= xAOD::Muon::Medium ) {
126  IDTPM::decorateOrRejectQuietly( track, mu_decor[Medium], muLink );
127  }
128 
130  if( muon->quality() <= xAOD::Muon::Loose ) {
131  IDTPM::decorateOrRejectQuietly( track, mu_decor[Loose], muLink );
132  }
133 
135  if( muon->quality() <= xAOD::Muon::VeryLoose ) {
136  IDTPM::decorateOrRejectQuietly( track, mu_decor[VeryLoose], muLink );
137  }
138 
139  return StatusCode::SUCCESS;
140  } // if( muTrack == &track )
141 
142  } // close muon loop
143 
144  return StatusCode::SUCCESS;
145 }
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
LikeEnum::VeryLoose
@ VeryLoose
Definition: LikelihoodEnums.h:11
OfflineMuonDecoratorAlg.h
Algorithm to decorate offline tracks with the corresponding offline muon object (if required for trig...
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
IDTPM::decorateOrRejectQuietly
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.
Definition: SafeDecorator.h:197
IDTPM::createDecoratorsIfNeeded
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)
Like above - FIXME: maybe not needed.
Definition: SafeDecorator.h:114
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
IDTPM::OfflineMuonDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: OfflineMuonDecoratorAlg.cxx:51
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector< xAOD::TrackParticle_v1 >
IDTPM::OfflineMuonDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: OfflineMuonDecoratorAlg.cxx:26
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
LikeEnum::Tight
@ Tight
Definition: LikelihoodEnums.h:15
IDTPM::createDecoratorKeysAndAccessor
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...
Definition: SafeDecorator.h:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
IDTPM::OfflineMuonDecoratorAlg::OfflineMuonDecoratorAlg
OfflineMuonDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
Definition: OfflineMuonDecoratorAlg.cxx:17
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
IDTPM::OfflineMuonDecoratorAlg::decorateMuonTrack
StatusCode decorateMuonTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementMuonLink_t > > &mu_decor, const xAOD::MuonContainer &muons) const
Definition: OfflineMuonDecoratorAlg.cxx:87
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
IDTPM::OptionalDecoration
std::pair< SG::WriteDecorHandle< ContainerType, VariableType >, bool > OptionalDecoration
Definition: SafeDecorator.h:47