ATLAS Offline Software
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 
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 
31  ATH_CHECK( m_offlineTrkParticlesName.initialize(
32  not m_offlineTrkParticlesName.key().empty() ) );
33 
34  ATH_CHECK( m_electronsName.initialize( not m_electronsName.key().empty() ) );
35 
38  *this, m_offlineTrkParticlesName,
39  m_prefix.value(), m_decor_ele_names, m_decor_ele );
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 
53 StatusCode IDTPM::OfflineElectronDecoratorAlg::execute( const EventContext& ctx ) const {
54 
56  SG::ReadHandle< xAOD::TrackParticleContainer > ptracks( m_offlineTrkParticlesName, ctx );
57  if( not ptracks.isValid() ) {
58  ATH_MSG_ERROR( "Failed to retrieve track particles container" );
59  return StatusCode::FAILURE;
60  }
61 
63  SG::ReadHandle< xAOD::ElectronContainer > pelectrons( m_electronsName, ctx );
64  if( not pelectrons.isValid() ) {
65  ATH_MSG_ERROR( "Failed to retrieve electrons container" );
66  return StatusCode::FAILURE;
67  }
68 
69  std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementElectronLink_t> >
70  ele_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_ele, ctx ) );
71 
72  if( ele_decor.empty() ) {
73  ATH_MSG_ERROR( "Failed to book electron decorations" );
74  return StatusCode::FAILURE;
75  }
76 
77  for( const xAOD::TrackParticle* track : *ptracks ) {
79  ATH_CHECK( decorateElectronTrack( *track, ele_decor, *pelectrons.ptr() ) );
80  }
81 
82  return StatusCode::SUCCESS;
83 }
84 
85 
92  ElementElectronLink_t > >& ele_decor,
93  const xAOD::ElectronContainer& electrons ) const {
94 
96  for( const xAOD::Electron* electron : electrons ) {
97 
99  const xAOD::TrackParticle* eleTrack = m_useGSF.value() ?
100  electron->trackParticle() : // with GSF
102 
103  if( not eleTrack ) {
104  ATH_MSG_ERROR( "Corrupted matching electron ID track" );
105  return StatusCode::FAILURE;
106  }
107 
108  if( eleTrack == &track ) {
110  ElementElectronLink_t eleLink;
112 
113  ATH_MSG_DEBUG( "Found matching electron (e=" << electron->e() << "). Decorating track." );
114 
116  IDTPM::decorateOrRejectQuietly( track, ele_decor[All], eleLink );
117 
119  if( electron->passSelection("Tight") ) {
120  IDTPM::decorateOrRejectQuietly( track, ele_decor[Tight], eleLink );
121  }
122 
124  if( electron->passSelection("Medium") ) {
125  IDTPM::decorateOrRejectQuietly( track, ele_decor[Medium], eleLink );
126  }
127 
129  if( electron->passSelection("Loose") ) {
130  IDTPM::decorateOrRejectQuietly( track, ele_decor[Loose], eleLink );
131  }
132 
134  if( electron->passSelection("LHTight") ) {
135  IDTPM::decorateOrRejectQuietly( track, ele_decor[LHTight], eleLink );
136  }
137 
139  if( electron->passSelection("LHMedium") ) {
140  IDTPM::decorateOrRejectQuietly( track, ele_decor[LHMedium], eleLink );
141  }
142 
144  if( electron->passSelection("LHLoose") ) {
145  IDTPM::decorateOrRejectQuietly( track, ele_decor[LHLoose], eleLink );
146  }
147 
148  return StatusCode::SUCCESS;
149  } // if( eleTrack == &track )
150 
151  } // close electron loop
152 
153  return StatusCode::SUCCESS;
154 }
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
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
ElectronxAODHelpers.h
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
IDTPM::OfflineElectronDecoratorAlg::decorateElectronTrack
StatusCode decorateElectronTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementElectronLink_t > > &ele_decor, const xAOD::ElectronContainer &electrons) const
Definition: OfflineElectronDecoratorAlg.cxx:89
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::OfflineElectronDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: OfflineElectronDecoratorAlg.cxx:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector< xAOD::TrackParticle_v1 >
IDTPM::OfflineElectronDecoratorAlg::OfflineElectronDecoratorAlg
OfflineElectronDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
Definition: OfflineElectronDecoratorAlg.cxx:20
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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::OfflineElectronDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: OfflineElectronDecoratorAlg.cxx:29
xAOD::Electron_v1
Definition: Electron_v1.h:34
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
OfflineElectronDecoratorAlg.h
Algorithm to decorate offline tracks with the corresponding offline electron object (if required for ...
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
xAOD::EgammaHelpers::getOriginalTrackParticle
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
Definition: ElectronxAODHelpers.cxx:11
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
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17