ATLAS Offline Software
Loading...
Searching...
No Matches
TrackLeptonDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
10
12
15
16
17namespace 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:" );
31
32 ATH_CHECK( m_TrackContainerKey.initialize() );
33 ATH_CHECK( m_ElectronContainerKey.initialize() );
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 // Initialize decorators
43 ATH_MSG_DEBUG( "Inizializing decorators:" );
44 ATH_MSG_DEBUG( " ** " << m_dec_lepton_id );
49
50 ATH_CHECK( m_dec_lepton_id.initialize() );
51 ATH_CHECK( m_dec_muon_quality.initialize() );
52 ATH_CHECK( m_dec_muon_qOverPratio.initialize() );
55
56 return StatusCode::SUCCESS;
57 }
58
59 StatusCode TrackLeptonDecoratorAlg::execute(const EventContext& ctx) const {
60 ATH_MSG_DEBUG( "Executing " << name() << "... " );
61
62 // read collections
65 CHECK( tracks.isValid() );
66 ATH_MSG_DEBUG( "Retrieved " << tracks->size() << " tracks..." );
69 CHECK( tracks.isValid() );
70 ATH_MSG_DEBUG( "Retrieved " << electrons->size() << " electrons..." );
73 CHECK( tracks.isValid() );
74 ATH_MSG_DEBUG( "Retrieved " << muons->size() << " muons..." );
75
80 SG::WriteDecorHandle<TPC, float> decor_muon_momentumBalanceSignificance(m_dec_muon_momentumBalanceSignificance, ctx);
81 SG::WriteDecorHandle<TPC, float> decor_muon_scatteringNeighbourSignificance(m_dec_muon_scatteringNeighbourSignificance, ctx);
82
83 // give all tracks a default starting value
84 for ( const xAOD::TrackParticle* track : *tracks ) {
85 decor_lepton_id(*track) = 0;
86 decor_muon_quality(*track) = -1;
87 decor_muon_qOverPratio(*track) = -99.;
88 decor_muon_momentumBalanceSignificance(*track) = -99.;
89 decor_muon_scatteringNeighbourSignificance(*track) = -99.;
90 }
91
92 // loop over electrons
93 for ( const auto electron : *electrons ) {
94
95 // get associated InDet track (not the GSF track which is likely to have improved parameters,
96 // more info: https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/EGammaD3PDtoxAOD#TrackParticle)
98 if ( !track ) { continue; }
99
100 // apply electron ID requirement
101 bool LH_selection = bool{m_electronID_tool->accept(electron)};
102 if (!LH_selection) { continue; }
103
104 // decorate the track
105 decor_lepton_id(*track) = -11 * electron->charge();
106 }
107
108 // loop over muons - do it last in case we have a track that was used in the
109 // reconstruction of an electron and a muon (which can happen in rare cases)
110 for ( const auto muon : *muons ) {
111
112 if ( !m_muonID_tool->accept(*muon) ) {
113 continue;
114 }
115 // get associated InDet track
116 auto track_link = muon->inDetTrackParticleLink();
117 if ( !track_link.isValid() ) { continue; }
118 auto track = *track_link;
119
120 // get associated muon spectrometer track
121 auto ms_track_link = muon->extrapolatedMuonSpectrometerTrackParticleLink();
122 if ( !ms_track_link.isValid() ) { continue; }
123 auto ms_track = *ms_track_link;
124
125 float momBalSig = 0.;
126 float scatNeighSig = 0.;
127 muon->parameter(momBalSig, xAOD::Muon::momentumBalanceSignificance);
128 muon->parameter(scatNeighSig, xAOD::Muon::scatteringNeighbourSignificance);
129
130 // decorate the track
131 decor_lepton_id(*track) = -13 * muon->charge();
132 decor_muon_quality(*track) = m_muonID_tool->getQuality(*muon);
133 decor_muon_qOverPratio(*track) = track->qOverP() / ms_track->qOverP();
134 decor_muon_momentumBalanceSignificance(*track) = momBalSig;
135 decor_muon_scatteringNeighbourSignificance(*track) = scatNeighSig;
136 }
137
138 return StatusCode::SUCCESS;
139 }
140
141}
142
143
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_qOverPratio
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_lepton_id
ToolHandle< IAsgElectronLikelihoodTool > m_electronID_tool
ToolHandle< CP::IMuonSelectionTool > m_muonID_tool
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
virtual StatusCode execute(const EventContext &) const override
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_momentumBalanceSignificance
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_quality
TrackLeptonDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_muon_scatteringNeighbourSignificance
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".