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 
69  std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementTauLink_t> >
70  tau_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_tau, ctx ) );
71 
72  if( tau_decor.empty() ) {
73  ATH_MSG_ERROR( "Failed to book tau " <<
74  m_tauType.value() << " " <<
75  m_tauNprongs.value() <<
76  "prong decorations" );
77  return StatusCode::FAILURE;
78  }
79 
80  for( const xAOD::TrackParticle* track : *ptracks ) {
82  ATH_CHECK( decorateTauTrack( *track, tau_decor, *ptaus.ptr() ) );
83  }
84 
85  return StatusCode::SUCCESS;
86 }
87 
88 
95  ElementTauLink_t > >& tau_decor,
96  const xAOD::TauJetContainer& taus ) const {
97 
99  for( const xAOD::TauJet* tau : taus ) {
100 
102  int NTauTracks = tau->nTracks();
103  if( m_tauNprongs.value() > 0 and NTauTracks != (int)m_tauNprongs.value() ) continue;
104 
106  std::vector< const xAOD::TrackParticle* > tauTracks;
107  for( size_t iprong=0; iprong<(size_t)NTauTracks; iprong++ ) {
108 
109  std::vector< ElementTrackLink_t > tracklink = tau->track( iprong )->trackLinks();
110  ATH_MSG_DEBUG( "TauLinkVec size (" << m_tauNprongs.value() <<
111  "prong " << m_tauType.value() << "tau) = " << tracklink.size() );
112 
114  for( size_t ilink=0; ilink<tracklink.size() ; ilink++ ) {
115  if( tracklink.at(ilink).isValid() ) tauTracks.push_back( *(tracklink.at(ilink)) );
116  }
117 
118  } // close NTauTracks loop
119 
120  ATH_MSG_DEBUG( "TauVec size (" << m_tauNprongs.value() << "prong " <<
121  m_tauType.value() << "tau) = " << tauTracks.size() );
122 
124  for( const xAOD::TrackParticle* tauTrack : tauTracks ) {
125 
126  if( not tauTrack ) {
127  ATH_MSG_ERROR( "Corrupted matching tau ID track" );
128  continue;
129  }
130 
131  if( tauTrack == &track ) {
133  ElementTauLink_t tauLink;
134  tauLink.toContainedElement( taus, tau );
135 
136  bool isTight( false ), isMedium( false );
137  bool isLoose( false ), isVeryLoose( false );
138 
139  if( m_tauType.value() == "BDT" ) {
140  isTight = tau->isTau( xAOD::TauJetParameters::JetBDTSigTight );
141  isMedium = tau->isTau( xAOD::TauJetParameters::JetBDTSigMedium );
142  isLoose = tau->isTau( xAOD::TauJetParameters::JetBDTSigLoose );
143  isVeryLoose = tau->isTau( xAOD::TauJetParameters::JetBDTSigVeryLoose );
144 
145  } else if( m_tauType.value() == "RNN" ) {
146  isTight = tau->isTau( xAOD::TauJetParameters::JetRNNSigTight );
147  isMedium = tau->isTau( xAOD::TauJetParameters::JetRNNSigMedium );
148  isLoose = tau->isTau( xAOD::TauJetParameters::JetRNNSigLoose );
149  isVeryLoose = tau->isTau( xAOD::TauJetParameters::JetRNNSigVeryLoose );
150 
151  } else {
152  ATH_MSG_ERROR( "Unknown Tau type: " << m_tauType.value() );
153  return StatusCode::FAILURE;
154  }
155 
157  if( isTight or isMedium or isLoose or isVeryLoose ) {
158  ATH_MSG_DEBUG( "Found matching tau " <<
159  m_tauType.value() << " " <<
160  m_tauNprongs.value() <<
161  "prong (pt=" << tau->pt() <<
162  "). Decorating track." );
163  IDTPM::decorateOrRejectQuietly( track, tau_decor[All], tauLink );
164  return StatusCode::SUCCESS;
165  }
166 
168  if( isTight ) {
169  IDTPM::decorateOrRejectQuietly( track, tau_decor[Tight], tauLink );
170  }
171 
173  if( isMedium ) {
174  IDTPM::decorateOrRejectQuietly( track, tau_decor[Medium], tauLink );
175  }
176 
178  if( isLoose ) {
179  IDTPM::decorateOrRejectQuietly( track, tau_decor[Loose], tauLink );
180  }
181 
183  if( isVeryLoose ) {
184  IDTPM::decorateOrRejectQuietly( track, tau_decor[VeryLoose], tauLink );
185  }
186 
187  } // if( tauTrack == &track )
188 
189  } // close tauTracks loop
190 
191  } // close tau loop
192 
193  return StatusCode::SUCCESS;
194 }
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
LikeEnum::VeryLoose
@ VeryLoose
Definition: LikelihoodEnums.h:11
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
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)
Like above - FIXME: maybe not needed.
Definition: SafeDecorator.h:114
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:92
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
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:581
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:221
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