ATLAS Offline Software
OfflineJetDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "OfflineJetDecoratorAlg.h"
12 #include "TrackParametersHelper.h"
13 
14 
19  const std::string& name,
20  ISvcLocator* pSvcLocator ) :
21  AthReentrantAlgorithm( name, pSvcLocator ) { }
22 
23 
28 
29  ATH_CHECK( m_offlineTrkParticlesName.initialize(
30  not m_offlineTrkParticlesName.key().empty() ) );
31 
32  ATH_CHECK( m_jetsName.initialize( not m_jetsName.key().empty() ) );
33 
36  *this, m_offlineTrkParticlesName,
37  m_prefix.value(), m_decor_jet_names, m_decor_jet );
38 
39  if( m_decor_jet.size() != NDecorations ) {
40  ATH_MSG_ERROR( "Incorrect booking of jet decorations" );
41  return StatusCode::FAILURE;
42  }
43 
44  return StatusCode::SUCCESS;
45 }
46 
47 
51 StatusCode IDTPM::OfflineJetDecoratorAlg::execute( const EventContext& ctx ) const {
52 
54  SG::ReadHandle< xAOD::TrackParticleContainer > ptracks( m_offlineTrkParticlesName, ctx );
55  if( not ptracks.isValid() ) {
56  ATH_MSG_ERROR( "Failed to retrieve track particles container" );
57  return StatusCode::FAILURE;
58  }
59 
61  SG::ReadHandle< xAOD::JetContainer > pjets( m_jetsName, ctx );
62  if( not pjets.isValid() ) {
63  ATH_MSG_ERROR( "Failed to retrieve jets container" );
64  return StatusCode::FAILURE;
65  }
66 
68  if( IDTPM::decorationsAllExist( *ptracks, m_decor_jet ) ) {
69  ATH_MSG_DEBUG( "All decorations already exist. Exiting gracefully" );
70  return StatusCode::SUCCESS;
71  }
72 
74  std::vector< IDTPM::OptionalDecoration<xAOD::TrackParticleContainer, ElementJetLink_t> >
75  jet_decor( IDTPM::createDecoratorsIfNeeded( *ptracks, m_decor_jet, ctx ) );
76 
77  if( jet_decor.empty() ) {
78  ATH_MSG_ERROR( "Failed to book jet decorations" );
79  return StatusCode::FAILURE;
80  }
81 
82  for( const xAOD::TrackParticle* track : *ptracks ) {
84  ATH_CHECK( decorateJetTrack( *track, jet_decor, *pjets.ptr() ) );
85  }
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 
97  ElementJetLink_t > >& jet_decor,
98  const xAOD::JetContainer& jets ) const
99 {
101  //static const SG::ConstAccessor<
102  // std::vector< ElementLink< xAOD::IParticleContainer > > > ghostTruth( "GhostTruth" );
103  static const SG::ConstAccessor< int > truthJetTagLabel( "HadronConeExclTruthLabelID" );
104 
106  for( const xAOD::Jet* jet : jets ) {
108  if( not passJetCuts( *jet ) ) continue;
109 
111  if( deltaR( *jet, track ) > m_maxTrkJetDR.value() ) continue;
112 
114  bool isTruthCjet = false;
115  bool isTruthBjet = false;
116  if( not truthJetTagLabel.isAvailable( *jet ) ) {
117  ATH_MSG_WARNING( "Failed to extract b-tag truth label from jet" );
118  } else {
119  isTruthCjet = ( truthJetTagLabel( *jet ) == 4 );
120  isTruthBjet = ( truthJetTagLabel( *jet ) == 5 );
121  }
122 
124  ElementJetLink_t jetLink;
125  jetLink.toContainedElement( jets, jet );
126 
127  ATH_MSG_DEBUG( "Found matching jet (en=" << jet->e() << "). Decorating track." );
128 
130  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthJet], jetLink );
131 
132  if( isTruthBjet ) {
134  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthBjet], jetLink );
136  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthHeavyJet], jetLink );
137  } else if( isTruthCjet ) {
139  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthCjet], jetLink );
141  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthHeavyJet], jetLink );
142  } else {
144  IDTPM::decorateOrRejectQuietly( track, jet_decor[DRtruthLightJet], jetLink );
145  }
146 
149 
150  } // close jets loop
151 
152  return StatusCode::SUCCESS;
153 }
154 
156 {
157  const float jetPt = jet.pt();
158  const float jetEta = std::abs( jet.eta() );
159 
160  if( jetEta < m_jetAbsEtaMin ) return false;
161  if( jetEta > m_jetAbsEtaMax ) return false;
162  if( jetPt < m_jetPtMin ) return false;
163  if( jetPt > m_jetPtMax ) return false;
164  return true;
165 }
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
OfflineJetDecoratorAlg.h
Algorithm to decorate offline tracks with the corresponding (reco or truth) jet object.
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
IDTPM::OfflineJetDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: OfflineJetDecoratorAlg.cxx:51
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
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
SG::ConstAccessor< int >
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
IDTPM::OfflineJetDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: OfflineJetDecoratorAlg.cxx:27
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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::OfflineJetDecoratorAlg::passJetCuts
bool passJetCuts(const xAOD::Jet &jet) const
Definition: OfflineJetDecoratorAlg.cxx:155
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::OfflineJetDecoratorAlg::OfflineJetDecoratorAlg
OfflineJetDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
Definition: OfflineJetDecoratorAlg.cxx:18
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::deltaR
float deltaR(const U1 &p1, const U2 &p2)
Accessor utility function for getting the DeltaR betwen two tracks.
Definition: TrackParametersHelper.h:250
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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:240
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
IDTPM::OfflineJetDecoratorAlg::decorateJetTrack
StatusCode decorateJetTrack(const xAOD::TrackParticle &track, std::vector< IDTPM::OptionalDecoration< xAOD::TrackParticleContainer, ElementJetLink_t > > &jet_decor, const xAOD::JetContainer &jets) const
Definition: OfflineJetDecoratorAlg.cxx:94
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
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