ATLAS Offline Software
Loading...
Searching...
No Matches
OfflineElectronDecoratorAlg.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
14#include "xAODEgamma/ElectronxAODHelpers.h" // xAOD::EgammaHelpers::getOriginalTrackParticle
15
16
21 const std::string& name,
22 ISvcLocator* pSvcLocator ) :
23 AthReentrantAlgorithm( name, pSvcLocator ) { }
24
25
30
32 not m_offlineTrkParticlesName.key().empty() ) );
33
34 ATH_CHECK( m_electronsName.initialize( not m_electronsName.key().empty() ) );
35
40
41 if( m_decor_ele.size() != NDecorations ) {
42 ATH_MSG_ERROR( "Incorrect booking of electron decorations" );
43 return StatusCode::FAILURE;
44 }
45
46 return StatusCode::SUCCESS;
47}
48
49
53StatusCode IDTPM::OfflineElectronDecoratorAlg::execute( const EventContext& ctx ) const {
54
57 if( not ptracks.isValid() ) {
58 ATH_MSG_ERROR( "Failed to retrieve track particles container" );
59 return StatusCode::FAILURE;
60 }
61
64 if( not pelectrons.isValid() ) {
65 ATH_MSG_ERROR( "Failed to retrieve electrons container" );
66 return StatusCode::FAILURE;
67 }
68
70 if( IDTPM::decorationsAllExist( *ptracks, m_decor_ele ) ) {
71 ATH_MSG_DEBUG( "All decorations already exist. Exiting gracefully" );
72 return StatusCode::SUCCESS;
73 }
74
76 std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementElectronLink_t> >
77 ele_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_ele, ctx ) );
78
79 if( ele_decor.empty() ) {
80 ATH_MSG_ERROR( "Failed to book electron decorations" );
81 return StatusCode::FAILURE;
82 }
83
84 for( const xAOD::TrackParticle* track : *ptracks ) {
86 ATH_CHECK( decorateElectronTrack( *track, ele_decor, *pelectrons.ptr() ) );
87 }
88
89 return StatusCode::SUCCESS;
90}
91
92
97 const xAOD::TrackParticle& track,
99 ElementElectronLink_t > >& ele_decor,
100 const xAOD::ElectronContainer& electrons ) const {
101
103 for( const xAOD::Electron* electron : electrons ) {
104
106 const xAOD::TrackParticle* eleTrack = m_useGSF.value() ?
107 electron->trackParticle() : // with GSF
109
110 if( not eleTrack ) {
111 ATH_MSG_ERROR( "Corrupted matching electron ID track" );
112 return StatusCode::FAILURE;
113 }
114
115 if( eleTrack == &track ) {
117 ElementElectronLink_t eleLink;
118 eleLink.toContainedElement( electrons, electron );
119
120 ATH_MSG_DEBUG( "Found matching electron (e=" << electron->e() << "). Decorating track." );
121
123 IDTPM::decorateOrRejectQuietly( track, ele_decor[All], eleLink );
124
126 if( electron->passSelection("Tight") ) {
127 IDTPM::decorateOrRejectQuietly( track, ele_decor[Tight], eleLink );
128 }
129
131 if( electron->passSelection("Medium") ) {
132 IDTPM::decorateOrRejectQuietly( track, ele_decor[Medium], eleLink );
133 }
134
136 if( electron->passSelection("Loose") ) {
137 IDTPM::decorateOrRejectQuietly( track, ele_decor[Loose], eleLink );
138 }
139
141 if( electron->passSelection("LHTight") ) {
142 IDTPM::decorateOrRejectQuietly( track, ele_decor[LHTight], eleLink );
143 }
144
146 if( electron->passSelection("LHMedium") ) {
147 IDTPM::decorateOrRejectQuietly( track, ele_decor[LHMedium], eleLink );
148 }
149
151 if( electron->passSelection("LHLoose") ) {
152 IDTPM::decorateOrRejectQuietly( track, ele_decor[LHLoose], eleLink );
153 }
154
155 return StatusCode::SUCCESS;
156 } // if( eleTrack == &track )
157
158 } // close electron loop
159
160 return StatusCode::SUCCESS;
161}
#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 electron object (if required for ...
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticlesName
const std::vector< std::string > m_decor_ele_names
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsName
OfflineElectronDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
virtual StatusCode execute(const EventContext &ctx) const override
std::vector< IDTPM::WriteKeyAccessorPair< xAOD::TrackParticleContainer, ElementElectronLink_t > > m_decor_ele
StatusCode decorateElectronTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementElectronLink_t > > &ele_decor, const xAOD::ElectronContainer &electrons) const
ElementLink< xAOD::ElectronContainer > ElementElectronLink_t
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.
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Electron_v1 Electron
Definition of the current "egamma version".