ATLAS Offline Software
ThinTrkTrackAlg.cxx
Go to the documentation of this file.
1 
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 
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) "
34  << m_GSFTracksKey);
35  }
36  if (m_doPhotons) {
37  ATH_MSG_INFO("Will thin " << m_photonsKey
38  << " Trk::Tracks with key (photons) "
39  << m_GSFTracksKey);
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  }
53  ATH_CHECK(m_photonsKey.initialize(m_doPhotons));
54  ATH_CHECK(m_muonsKey.initialize(m_doMuons));
55 
56  ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
57  return StatusCode::SUCCESS;
58 }
59 
61 ThinTrkTrackAlg::execute(const EventContext& ctx) const
62 {
63 
64  if (m_doElectrons || m_doPhotons) {
65  CHECK(doEGamma(ctx));
66  }
67  if (m_doMuons) {
68  CHECK(doMuons(ctx));
69  }
70  return StatusCode::SUCCESS;
71 }
72 
74 ThinTrkTrackAlg::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 
150 ThinTrkTrackAlg::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  }
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 }
ThinTrkTrackAlg::m_GSFTracksKey
SG::ThinningHandleKey< TrackCollection > m_GSFTracksKey
Definition: ThinTrkTrackAlg.h:80
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
ThinTrkTrackAlg::m_photonsKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonsKey
Definition: ThinTrkTrackAlg.h:65
ThinTrkTrackAlg::doEGamma
StatusCode doEGamma(const EventContext &ctx) const
Inline method.
Definition: ThinTrkTrackAlg.cxx:74
ThinTrkTrackAlg::m_minptMuons
Gaudi::Property< double > m_minptMuons
Definition: ThinTrkTrackAlg.h:94
ElectronxAODHelpers.h
ThinTrkTrackAlg::m_CombinedMuonsTracksKey
SG::ThinningHandleKey< TrackCollection > m_CombinedMuonsTracksKey
Containers to thin.
Definition: ThinTrkTrackAlg.h:73
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ThinTrkTrackAlg::doMuons
StatusCode doMuons(const EventContext &ctx) const
Definition: ThinTrkTrackAlg.cxx:150
ThinTrkTrackAlg::m_electronsKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsKey
Definition: ThinTrkTrackAlg.h:58
ThinTrkTrackAlg::m_bestonlyElectrons
Gaudi::Property< bool > m_bestonlyElectrons
Definition: ThinTrkTrackAlg.h:90
ThinTrkTrackAlg::m_minptElectrons
Gaudi::Property< double > m_minptElectrons
Definition: ThinTrkTrackAlg.h:92
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
ThinTrkTrackAlg::m_bestonlyPhotons
Gaudi::Property< bool > m_bestonlyPhotons
Definition: ThinTrkTrackAlg.h:91
ThinTrkTrackAlg::m_doPhotons
Gaudi::Property< bool > m_doPhotons
Definition: ThinTrkTrackAlg.h:88
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:68
ThinTrkTrackAlg::m_doMuons
Gaudi::Property< bool > m_doMuons
Definition: ThinTrkTrackAlg.h:89
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
TrackCollection.h
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
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
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
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
ThinTrkTrackAlg::m_muonsKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
Should the thinning run? The containers of Objects of interest Electron/Muon.
Definition: ThinTrkTrackAlg.h:51
ThinTrkTrackAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ThinTrkTrackAlg::m_doElectrons
Gaudi::Property< bool > m_doElectrons
Definition: ThinTrkTrackAlg.h:87
DeMoScan.index
string index
Definition: DeMoScan.py:364
ThinTrkTrackAlg::initialize
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
Definition: ThinTrkTrackAlg.cxx:23
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ThinTrkTrackAlg::m_minptPhotons
Gaudi::Property< double > m_minptPhotons
Definition: ThinTrkTrackAlg.h:93
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ThinTrkTrackAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
Definition: ThinTrkTrackAlg.cxx:61
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
TrackParticleContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
ThinTrkTrackAlg::m_streamName
StringProperty m_streamName
Definition: ThinTrkTrackAlg.h:44