ATLAS Offline Software
Loading...
Searching...
No Matches
ThinTrkTrackAlg.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5*/
6
7// ThinTrkTrackAlg.cxx
8// Author: Christos
9// Lets see if we can write Trk::Tracks in xAOD
11
12#include "ThinTrkTrackAlg.h"
17
18// STL includes
19#include <algorithm>
20
23{
24 ATH_MSG_DEBUG("Initializing " << name() << "...");
25
26 // Print out the used configuration
27 ATH_MSG_DEBUG(" using = " << m_streamName);
28
29 // Is truth thinning required?
30 if (m_doElectrons) {
31 ATH_MSG_INFO("Will thin " << m_electronsKey
32 << " Trk::Tracks with key (electrons) "
34 }
35 if (m_doPhotons) {
36 ATH_MSG_INFO("Will thin " << m_photonsKey
37 << " Trk::Tracks with key (photons) "
39 }
40 if (m_doMuons) {
41 ATH_MSG_INFO("Will thin " << m_muonsKey << " Trk::Tracks with key "
43 }
44
45 if (m_streamName.empty()) {
46 ATH_MSG_ERROR("StreamName property was not initialized");
47 return StatusCode::FAILURE;
48 }
53 ATH_CHECK(m_muonsKey.initialize(m_doMuons));
54
55 ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
56 return StatusCode::SUCCESS;
57}
58
59StatusCode
60ThinTrkTrackAlg::execute(const EventContext& ctx) const
61{
62
64 CHECK(doEGamma(ctx));
65 }
66 if (m_doMuons) {
67 CHECK(doMuons(ctx));
68 }
69 return StatusCode::SUCCESS;
70}
71
72StatusCode
73ThinTrkTrackAlg::doEGamma(const EventContext& ctx) const
74{
75
76 // Prepare for the Thinning of Trk::Tracks
77 std::vector<bool> keptTracks;
79 ATH_MSG_DEBUG("Number of " << m_GSFTracksKey.key() << " " << trackPC->size());
80 if (keptTracks.size() < trackPC->size()) {
81 keptTracks.resize(trackPC->size(), false);
82 }
83
84 size_t kept(0);
85
86 if (m_doElectrons) {
87 // Get the electrons
89
90 // Loop over electrons
91 for (const auto *el : *electrons) {
92 if (el->pt() < m_minptElectrons) {
93 continue;
94 }
95 size_t nel = el->nTrackParticles();
96 if (m_bestonlyElectrons && nel > 1) {
97 nel = 1;
98 }
99 for (size_t i = 0; i < nel; i++) {
100 const xAOD::TrackParticle* tp = el->trackParticle(i);
101 if (!tp || !tp->trackLink().isValid()) {
102 continue;
103 }
104 size_t index = tp->trackLink().index();
105 keptTracks[index] = true;
106 ++kept;
107 }
108 }
109 }
110
111 if (m_doPhotons) {
112 // Get the photons
114
115 // Loop over photons
116 for (const auto *ph : *photons) {
117 if (ph->pt() < m_minptPhotons) {
118 continue;
119 }
120 size_t nvx = ph->nVertices();
121 if (m_bestonlyPhotons && nvx > 1) {
122 nvx = 1;
123 }
124 for (size_t i = 0; i < nvx; i++) {
125 const xAOD::Vertex* vx = ph->vertex(i);
126 if (vx) {
127 size_t ntp = vx->nTrackParticles();
128 for (size_t j = 0; j < ntp; j++) {
129 const xAOD::TrackParticle* tp = vx->trackParticle(j);
130 if (!tp || !tp->trackLink().isValid()) {
131 continue;
132 }
133 size_t index = tp->trackLink().index();
134 keptTracks[index] = true;
135 ++kept;
136 }
137 }
138 }
139 }
140 }
141
142 ATH_MSG_DEBUG("keep " << kept << " out of " << keptTracks.size());
143 ATH_MSG_DEBUG("Do the Thinning");
144 trackPC.keep(keptTracks);
145 return StatusCode::SUCCESS;
146}
147
148StatusCode
149ThinTrkTrackAlg::doMuons(const EventContext& ctx) const
150{
151
152 // Prepare for the Thinning of Trk::Tracks
153 std::vector<bool> keptTracks;
155 ATH_MSG_DEBUG("Number of " << m_CombinedMuonsTracksKey.key() << " "
156 << trackPC->size());
157 if (keptTracks.size() < trackPC->size()) {
158 keptTracks.resize(trackPC->size(), false);
159 }
160
161 // Get the muons
163
164 // Loop over muons
165 size_t kept(0);
166 for (const auto *mu : *muons) {
167 if (mu->pt() < m_minptMuons) {
168 continue;
169 }
170 const static SG::AuxElement::Accessor<
172 acc("combinedTrackParticleLink");
173 if (!acc.isAvailable(*mu)) {
174 continue;
175 }
176 const ElementLink<xAOD::TrackParticleContainer>& link = acc(*mu);
177 if (!link.isValid()) {
178 continue;
179 }
180 const xAOD::TrackParticle* tp = (*link);
181 if (!tp || !tp->trackLink().isValid()) {
182 continue;
183 }
184 size_t index = tp->trackLink().index();
185 keptTracks[index] = true;
186 ++kept;
187 }
188
189 ATH_MSG_DEBUG("keep " << kept << " out of " << keptTracks.size());
190 ATH_MSG_DEBUG("Do the Thinning");
191 trackPC.keep(keptTracks);
192 return StatusCode::SUCCESS;
193}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Handle for requesting thinning for a data object.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
Gaudi::Property< bool > m_doMuons
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonsKey
Gaudi::Property< double > m_minptMuons
Gaudi::Property< bool > m_bestonlyPhotons
SG::ThinningHandleKey< TrackCollection > m_GSFTracksKey
StatusCode doEGamma(const EventContext &ctx) const
Inline method.
Gaudi::Property< bool > m_bestonlyElectrons
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
StringProperty m_streamName
StatusCode doMuons(const EventContext &ctx) const
Gaudi::Property< double > m_minptPhotons
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
Should the thinning run?
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
Gaudi::Property< double > m_minptElectrons
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsKey
Gaudi::Property< bool > m_doElectrons
Gaudi::Property< bool > m_doPhotons
SG::ThinningHandleKey< TrackCollection > m_CombinedMuonsTracksKey
Containers to thin.
const ElementLink< TrackCollection > & trackLink() const
Returns a link (which can be invalid) to the Trk::Track which was used to make this TrackParticle.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition index.py:1
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.