ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
12
13
18 const std::string& name,
19 ISvcLocator* pSvcLocator ) :
20 AthReentrantAlgorithm( name, pSvcLocator ) { }
21
22
27
29 not m_offlineTrkParticlesName.key().empty() ) );
30
31 ATH_CHECK( m_tausName.initialize( not m_tausName.key().empty() ) );
32
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
53StatusCode IDTPM::OfflineTauDecoratorAlg::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 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_DEBUG( "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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static Double_t taus
Algorithm to decorate offline tracks with the corresponding offline tau object (if required for trigg...
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
ElementLink< xAOD::TauJetContainer > ElementTauLink_t
const std::vector< std::string > m_decor_tau_names
StatusCode decorateTauTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementTauLink_t > > &tau_decor, const xAOD::TauJetContainer &taus) const
OfflineTauDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
UnsignedIntegerProperty m_tauNprongs
std::vector< IDTPM::WriteKeyAccessorPair< xAOD::TrackParticleContainer, ElementTauLink_t > > m_decor_tau
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticlesName
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::TauJetContainer > m_tausName
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.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TauJet_v3 TauJet
Definition of the current "tau version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".