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"
13#include "GaudiKernel/ThreadLocalContext.h"
18
19// STL includes
20#include <algorithm>
21
22StatusCode
24{
25 ATH_MSG_DEBUG("Initializing " << name() << "...");
26
27 // Print out the used configuration
28 ATH_MSG_DEBUG(" using = " << m_streamName);
29
30 // Is truth thinning required?
31 if (m_doElectrons) {
32 ATH_MSG_INFO("Will thin " << m_electronsKey
33 << " Trk::Tracks with key (electrons) "
35 }
36 if (m_doPhotons) {
37 ATH_MSG_INFO("Will thin " << m_photonsKey
38 << " Trk::Tracks with key (photons) "
40 }
41 if (m_doMuons) {
42 ATH_MSG_INFO("Will thin " << m_muonsKey << " Trk::Tracks with key "
44 }
45
46 if (m_streamName.empty()) {
47 ATH_MSG_ERROR("StreamName property was not initialized");
48 return StatusCode::FAILURE;
49 }
54 ATH_CHECK(m_muonsKey.initialize(m_doMuons));
55
56 ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
57 return StatusCode::SUCCESS;
58}
59
60StatusCode
61ThinTrkTrackAlg::execute(const EventContext& ctx) const
62{
63
65 CHECK(doEGamma(ctx));
66 }
67 if (m_doMuons) {
68 CHECK(doMuons(ctx));
69 }
70 return StatusCode::SUCCESS;
71}
72
73StatusCode
74ThinTrkTrackAlg::doEGamma(const EventContext& ctx) const
75{
76
77 // Prepare for the Thinning of Trk::Tracks
78 std::vector<bool> keptTracks;
80 ATH_MSG_DEBUG("Number of " << m_GSFTracksKey.key() << " " << trackPC->size());
81 if (keptTracks.size() < trackPC->size()) {
82 keptTracks.resize(trackPC->size(), false);
83 }
84
85 size_t kept(0);
86
87 if (m_doElectrons) {
88 // Get the electrons
90
91 // Loop over electrons
92 for (const auto *el : *electrons) {
93 if (el->pt() < m_minptElectrons) {
94 continue;
95 }
96 size_t nel = el->nTrackParticles();
97 if (m_bestonlyElectrons && nel > 1) {
98 nel = 1;
99 }
100 for (size_t i = 0; i < nel; i++) {
101 const xAOD::TrackParticle* tp = el->trackParticle(i);
102 if (!tp || !tp->trackLink().isValid()) {
103 continue;
104 }
105 size_t index = tp->trackLink().index();
106 keptTracks[index] = true;
107 ++kept;
108 }
109 }
110 }
111
112 if (m_doPhotons) {
113 // Get the photons
115
116 // Loop over photons
117 for (const auto *ph : *photons) {
118 if (ph->pt() < m_minptPhotons) {
119 continue;
120 }
121 size_t nvx = ph->nVertices();
122 if (m_bestonlyPhotons && nvx > 1) {
123 nvx = 1;
124 }
125 for (size_t i = 0; i < nvx; i++) {
126 const xAOD::Vertex* vx = ph->vertex(i);
127 if (vx) {
128 size_t ntp = vx->nTrackParticles();
129 for (size_t j = 0; j < ntp; j++) {
130 const xAOD::TrackParticle* tp = vx->trackParticle(j);
131 if (!tp || !tp->trackLink().isValid()) {
132 continue;
133 }
134 size_t index = tp->trackLink().index();
135 keptTracks[index] = true;
136 ++kept;
137 }
138 }
139 }
140 }
141 }
142
143 ATH_MSG_DEBUG("keep " << kept << " out of " << keptTracks.size());
144 ATH_MSG_DEBUG("Do the Thinning");
145 trackPC.keep(keptTracks);
146 return StatusCode::SUCCESS;
147}
148
149StatusCode
150ThinTrkTrackAlg::doMuons(const EventContext& ctx) const
151{
152
153 // Prepare for the Thinning of Trk::Tracks
154 std::vector<bool> keptTracks;
156 ATH_MSG_DEBUG("Number of " << m_CombinedMuonsTracksKey.key() << " "
157 << trackPC->size());
158 if (keptTracks.size() < trackPC->size()) {
159 keptTracks.resize(trackPC->size(), false);
160 }
161
162 // Get the muons
164
165 // Loop over muons
166 size_t kept(0);
167 for (const auto *mu : *muons) {
168 if (mu->pt() < m_minptMuons) {
169 continue;
170 }
171 const static SG::AuxElement::Accessor<
173 acc("combinedTrackParticleLink");
174 if (!acc.isAvailable(*mu)) {
175 continue;
176 }
177 const ElementLink<xAOD::TrackParticleContainer>& link = acc(*mu);
178 if (!link.isValid()) {
179 continue;
180 }
181 const xAOD::TrackParticle* tp = (*link);
182 if (!tp || !tp->trackLink().isValid()) {
183 continue;
184 }
185 size_t index = tp->trackLink().index();
186 keptTracks[index] = true;
187 ++kept;
188 }
189
190 ATH_MSG_DEBUG("keep " << kept << " out of " << keptTracks.size());
191 ATH_MSG_DEBUG("Do the Thinning");
192 trackPC.keep(keptTracks);
193 return StatusCode::SUCCESS;
194}
#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.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
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.
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.
Definition index.py:1
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.