ATLAS Offline Software
OfflineTauDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "OfflineTauDecoratorAlg.h"
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 
31  ATH_CHECK( m_tausName.initialize( not m_tausName.key().empty() ) );
32 
35  *this, m_offlineTrkParticlesName,
36  m_prefix.value(), m_decor_tau_names, m_decor_tau );
37 
38  if( m_decor_tau.size() != NDecorations ) {
39  ATH_MSG_ERROR( "Incorrect booking of tau " <<
40  m_tauType.value() << " " <<
41  m_tauNprongs.value() <<
42  "prong decorations" );
43  return StatusCode::FAILURE;
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
49 
53 StatusCode IDTPM::OfflineTauDecoratorAlg::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::TauJetContainer > ptaus( m_tausName, ctx );
64  if( not ptaus.isValid() ) {
65  ATH_MSG_ERROR( "Failed to retrieve taus container" );
66  return StatusCode::FAILURE;
67  }
68 
70  if( IDTPM::decorationsAllExist( *ptracks, m_decor_tau ) ) {
71  ATH_MSG_INFO( "All decorations already exist. Exiting gracefully" );
72  return StatusCode::SUCCESS;
73  }
74 
76  std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementTauLink_t> >
77  tau_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_tau, ctx ) );
78 
79  if( tau_decor.empty() ) {
80  ATH_MSG_ERROR( "Failed to book tau " <<
81  m_tauType.value() << " " <<
82  m_tauNprongs.value() <<
83  "prong decorations" );
84  return StatusCode::FAILURE;
85  }
86 
87  for( const xAOD::TrackParticle* track : *ptracks ) {
89  ATH_CHECK( decorateTauTrack( *track, tau_decor, *ptaus.ptr() ) );
90  }
91 
92  return StatusCode::SUCCESS;
93 }
94 
95 
100  const xAOD::TrackParticle& track,
102  ElementTauLink_t > >& tau_decor,
103  const xAOD::TauJetContainer& taus ) const {
104 
106  for( const xAOD::TauJet* tau : taus ) {
107 
109  int NTauTracks = tau->nTracks();
110  if( m_tauNprongs.value() > 0 and NTauTracks != (int)m_tauNprongs.value() ) continue;
111 
113  std::vector< const xAOD::TrackParticle* > tauTracks;
114  for( size_t iprong=0; iprong<(size_t)NTauTracks; iprong++ ) {
115 
116  std::vector< ElementTrackLink_t > tracklink = tau->track( iprong )->trackLinks();
117  ATH_MSG_DEBUG( "TauLinkVec size (" << m_tauNprongs.value() <<
118  "prong " << m_tauType.value() << "tau) = " << tracklink.size() );
119 
121  for( size_t ilink=0; ilink<tracklink.size() ; ilink++ ) {
122  if( tracklink.at(ilink).isValid() ) tauTracks.push_back( *(tracklink.at(ilink)) );
123  }
124 
125  } // close NTauTracks loop
126 
127  ATH_MSG_DEBUG( "TauVec size (" << m_tauNprongs.value() << "prong " <<
128  m_tauType.value() << "tau) = " << tauTracks.size() );
129 
131  for( const xAOD::TrackParticle* tauTrack : tauTracks ) {
132 
133  if( not tauTrack ) {
134  ATH_MSG_ERROR( "Corrupted matching tau ID track" );
135  continue;
136  }
137 
138  if( tauTrack == &track ) {
140  ElementTauLink_t tauLink;
141  tauLink.toContainedElement( taus, tau );
142 
143  bool isTight( false ), isMedium( false );
144  bool isLoose( false ), isVeryLoose( false );
145 
146  if( m_tauType.value() == "BDT" ) {
147  isTight = tau->isTau( xAOD::TauJetParameters::JetBDTSigTight );
148  isMedium = tau->isTau( xAOD::TauJetParameters::JetBDTSigMedium );
149  isLoose = tau->isTau( xAOD::TauJetParameters::JetBDTSigLoose );
150  isVeryLoose = tau->isTau( xAOD::TauJetParameters::JetBDTSigVeryLoose );
151 
152  } else if( m_tauType.value() == "RNN" ) {
153  isTight = tau->isTau( xAOD::TauJetParameters::JetRNNSigTight );
154  isMedium = tau->isTau( xAOD::TauJetParameters::JetRNNSigMedium );
155  isLoose = tau->isTau( xAOD::TauJetParameters::JetRNNSigLoose );
156  isVeryLoose = tau->isTau( xAOD::TauJetParameters::JetRNNSigVeryLoose );
157 
158  } else {
159  ATH_MSG_ERROR( "Unknown Tau type: " << m_tauType.value() );
160  return StatusCode::FAILURE;
161  }
162 
164  if( isTight or isMedium or isLoose or isVeryLoose ) {
165  ATH_MSG_DEBUG( "Found matching tau " <<
166  m_tauType.value() << " " <<
167  m_tauNprongs.value() <<
168  "prong (pt=" << tau->pt() <<
169  "). Decorating track." );
170  IDTPM::decorateOrRejectQuietly( track, tau_decor[All], tauLink );
171  return StatusCode::SUCCESS;
172  }
173 
175  if( isTight ) {
176  IDTPM::decorateOrRejectQuietly( track, tau_decor[Tight], tauLink );
177  }
178 
180  if( isMedium ) {
181  IDTPM::decorateOrRejectQuietly( track, tau_decor[Medium], tauLink );
182  }
183 
185  if( isLoose ) {
186  IDTPM::decorateOrRejectQuietly( track, tau_decor[Loose], tauLink );
187  }
188 
190  if( isVeryLoose ) {
191  IDTPM::decorateOrRejectQuietly( track, tau_decor[VeryLoose], tauLink );
192  }
193 
194  } // if( tauTrack == &track )
195 
196  } // close tauTracks loop
197 
198  } // close tau loop
199 
200  return StatusCode::SUCCESS;
201 }
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
LikeEnum::VeryLoose
@ VeryLoose
Definition: LikelihoodEnums.h:11
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
xAOD::TauJetParameters::JetBDTSigMedium
@ JetBDTSigMedium
Definition: TauDefs.h:137
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
xAOD::TauJetParameters::JetBDTSigVeryLoose
@ JetBDTSigVeryLoose
Definition: TauDefs.h:135
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
IDTPM::OfflineTauDecoratorAlg::decorateTauTrack
StatusCode decorateTauTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementTauLink_t > > &tau_decor, const xAOD::TauJetContainer &taus) const
Definition: OfflineTauDecoratorAlg.cxx:99
xAOD::TauJetParameters::JetBDTSigLoose
@ JetBDTSigLoose
Definition: TauDefs.h:136
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
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TauJetParameters::JetRNNSigVeryLoose
@ JetRNNSigVeryLoose
Definition: TauDefs.h:145
IDTPM::OfflineTauDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: OfflineTauDecoratorAlg.cxx:26
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
IDTPM::OfflineTauDecoratorAlg::OfflineTauDecoratorAlg
OfflineTauDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
Definition: OfflineTauDecoratorAlg.cxx:17
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LikeEnum::Tight
@ Tight
Definition: LikelihoodEnums.h:15
xAOD::TauJetParameters::JetBDTSigTight
@ JetBDTSigTight
Definition: TauDefs.h:138
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
xAOD::TauJetParameters::JetRNNSigTight
@ JetRNNSigTight
Definition: TauDefs.h:148
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
xAOD::TauJetParameters::JetRNNSigMedium
@ JetRNNSigMedium
Definition: TauDefs.h:147
OfflineTauDecoratorAlg.h
Algorithm to decorate offline tracks with the corresponding offline tau object (if required for trigg...
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
IDTPM::OfflineTauDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: OfflineTauDecoratorAlg.cxx:53
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
xAOD::TauJetParameters::JetRNNSigLoose
@ JetRNNSigLoose
Definition: TauDefs.h:146