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 
70  if( IDTPM::decorationsAllExist( *ptracks, m_decor_ele ) ) {
71  ATH_MSG_INFO( "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 
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;
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 }
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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:221
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)
create/book the decorations if they do not exist already
Definition: SafeDecorator.h:138
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:96
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::decorationsAllExist
bool decorationsAllExist(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, bool verbose=false)
Like above - FIXME: maybe not needed.
Definition: SafeDecorator.h:113
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
Derived DataVector<T>.
Definition: DataVector.h:794
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:228
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