ATLAS Offline Software
TrackLeptonDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 
10 
12 
15 
16 
17 namespace FlavorTagDiscriminants {
18 
20  const std::string& name, ISvcLocator* loc )
21  : AthReentrantAlgorithm(name, loc) {}
22 
24  ATH_MSG_INFO( "Inizializing " << name() << "... " );
25 
26  // Initialize Container keys
27  ATH_MSG_DEBUG( "Inizializing containers:" );
30  ATH_MSG_DEBUG( " ** " << m_MuonContainerKey );
31 
34  ATH_CHECK( m_MuonContainerKey.initialize() );
35 
36  // Initialise electron ID tool
37  ATH_CHECK(m_electronID_tool.retrieve());
38 
39  // Initialise muon ID tool
40  ATH_CHECK(m_muonID_tool.retrieve());
41 
42  // Prepare decorators
48 
49  // Initialize decorators
50  ATH_MSG_DEBUG( "Inizializing decorators:" );
51  ATH_MSG_DEBUG( " ** " << m_dec_lepton_id );
52  ATH_MSG_DEBUG( " ** " << m_dec_muon_quality );
56 
62 
63  return StatusCode::SUCCESS;
64  }
65 
66  StatusCode TrackLeptonDecoratorAlg::execute(const EventContext& ctx) const {
67  ATH_MSG_DEBUG( "Executing " << name() << "... " );
68 
69  // read collections
72  CHECK( tracks.isValid() );
73  ATH_MSG_DEBUG( "Retrieved " << tracks->size() << " tracks..." );
76  CHECK( tracks.isValid() );
77  ATH_MSG_DEBUG( "Retrieved " << electrons->size() << " electrons..." );
79  m_MuonContainerKey,ctx);
80  CHECK( tracks.isValid() );
81  ATH_MSG_DEBUG( "Retrieved " << muons->size() << " muons..." );
82 
83  using TPC = xAOD::TrackParticleContainer;
85  SG::WriteDecorHandle<TPC, char> decor_muon_quality(m_dec_muon_quality, ctx);
86  SG::WriteDecorHandle<TPC, float> decor_muon_qOverPratio(m_dec_muon_qOverPratio, ctx);
87  SG::WriteDecorHandle<TPC, float> decor_muon_momentumBalanceSignificance(m_dec_muon_momentumBalanceSignificance, ctx);
88  SG::WriteDecorHandle<TPC, float> decor_muon_scatteringNeighbourSignificance(m_dec_muon_scatteringNeighbourSignificance, ctx);
89 
90  // give all tracks a default starting value
91  for ( const xAOD::TrackParticle* track : *tracks ) {
92  decor_lepton_id(*track) = 0;
93  decor_muon_quality(*track) = -1;
94  decor_muon_qOverPratio(*track) = -99.;
95  decor_muon_momentumBalanceSignificance(*track) = -99.;
96  decor_muon_scatteringNeighbourSignificance(*track) = -99.;
97  }
98 
99  // loop over electrons
100  for ( const auto electron : *electrons ) {
101 
102  // get associated InDet track (not the GSF track which is likely to have improved parameters,
103  // more info: https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/EGammaD3PDtoxAOD#TrackParticle)
105  if ( !track ) { continue; }
106 
107  // apply electron ID requirement
108  bool LH_selection = bool{m_electronID_tool->accept(electron)};
109  if (!LH_selection) { continue; }
110 
111  // decorate the track
112  decor_lepton_id(*track) = -11 * electron->charge();
113  }
114 
115  // loop over muons - do it last in case we have a track that was used in the
116  // reconstruction of an electron and a muon (which can happen in rare cases)
117  for ( const auto muon : *muons ) {
118 
119  if ( !m_muonID_tool->accept(*muon) ) {
120  continue;
121  }
122  // get associated InDet track
123  auto track_link = muon->inDetTrackParticleLink();
124  if ( !track_link.isValid() ) { continue; }
125  auto track = *track_link;
126 
127  // get associated muon spectrometer track
128  auto ms_track_link = muon->extrapolatedMuonSpectrometerTrackParticleLink();
129  if ( !ms_track_link.isValid() ) { continue; }
130  auto ms_track = *ms_track_link;
131 
132  float momBalSig = 0.;
133  float scatNeighSig = 0.;
134  muon->parameter(momBalSig, xAOD::Muon::momentumBalanceSignificance);
135  muon->parameter(scatNeighSig, xAOD::Muon::scatteringNeighbourSignificance);
136 
137  // decorate the track
138  decor_lepton_id(*track) = -13 * muon->charge();
139  decor_muon_quality(*track) = m_muonID_tool->getQuality(*muon);
140  decor_muon_qOverPratio(*track) = track->qOverP() / ms_track->qOverP();
141  decor_muon_momentumBalanceSignificance(*track) = momBalSig;
142  decor_muon_scatteringNeighbourSignificance(*track) = scatNeighSig;
143  }
144 
145  return StatusCode::SUCCESS;
146  }
147 
148 }
149 
150 
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::TrackLeptonDecoratorAlg
TrackLeptonDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackLeptonDecoratorAlg.cxx:19
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_MuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition: TrackLeptonDecoratorAlg.h:50
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonParameters::scatteringNeighbourSignificance
@ scatteringNeighbourSignificance
Definition: MuonParamDefs.h:135
xAOD::TrackParticleContainer
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticleContainer.h:14
ElectronxAODHelpers.h
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_electronID_tool
ToolHandle< IAsgElectronLikelihoodTool > m_electronID_tool
Definition: TrackLeptonDecoratorAlg.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonParameters::momentumBalanceSignificance
@ momentumBalanceSignificance
Definition: MuonParamDefs.h:136
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_ElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition: TrackLeptonDecoratorAlg.h:47
ElectronSelectorHelpers.h
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_dec_muon_qOverPratio
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_qOverPratio
Definition: TrackLeptonDecoratorAlg.h:59
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
WriteDecorHandle.h
Handle class for adding a decoration to an object.
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_muonID_tool
ToolHandle< CP::IMuonSelectionTool > m_muonID_tool
Definition: TrackLeptonDecoratorAlg.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_dec_muon_momentumBalanceSignificance
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_momentumBalanceSignificance
Definition: TrackLeptonDecoratorAlg.h:61
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: TrackLeptonDecoratorAlg.cxx:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_dec_muon_scatteringNeighbourSignificance
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_scatteringNeighbourSignificance
Definition: TrackLeptonDecoratorAlg.h:63
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_TrackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerKey
Definition: TrackLeptonDecoratorAlg.h:44
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: TrackLeptonDecoratorAlg.cxx:23
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
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_dec_lepton_id
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_lepton_id
Definition: TrackLeptonDecoratorAlg.h:55
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
TrackLeptonDecoratorAlg.h
FlavorTagDiscriminants::TrackLeptonDecoratorAlg::m_dec_muon_quality
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_quality
Definition: TrackLeptonDecoratorAlg.h:57