ATLAS Offline Software
ThinInDetForwardTrackParticlesAlg.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 // ThinInDetForwardTrackParticlesAlg.cxx
8 // Author: James Catmore <James.Catmore@cern.ch>
9 // Uses thinning service to remove unwanted all InDetForwardTrackParticles
10 // that are not associated with Muons.
11 // Unlike some other algs in this package, no tool is used to select the
12 // objects for thinning - everything is done in this one class.
13 
14 // Expression evaluation is also not used.
16 
17 // EventUtils includes
19 #include "xAODMuon/MuonContainer.h"
21 
22 // STL includes
23 #include <algorithm>
24 
25 // FrameWork includes
26 #include "Gaudi/Property.h"
27 #include "GaudiKernel/ThreadLocalContext.h"
28 #include "StoreGate/ReadHandle.h"
30 
32 // Public methods:
34 
35 // Constructors
38  const std::string& name,
39  ISvcLocator* pSvcLocator)
40  : AthReentrantAlgorithm(name, pSvcLocator)
41 {
42 }
43 
44 // Athena Algorithm's Hooks
48 {
49  ATH_MSG_DEBUG("Initializing " << name() << "...");
50 
51  // Print out the used configuration
52  ATH_MSG_DEBUG(" using = " << m_streamName);
53 
54  // Is truth thinning required?
55  if (!m_doThinning) {
56  ATH_MSG_INFO("InDetForwardTrackParticles thinning not required");
57  } else {
58  ATH_MSG_INFO("InDetForwardTrackParticles will be thinned");
59  }
60 
61  if (m_doThinning && m_streamName.empty()) {
62  ATH_MSG_ERROR("StreamName property was not initialized.");
63  return StatusCode::FAILURE;
64  }
66  ATH_CHECK(m_muonsKey.initialize(m_doThinning && !m_muonsKey.empty()));
67  ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
68 
69  return StatusCode::SUCCESS;
70 }
71 
74 {
75  ATH_MSG_DEBUG("Finalizing " << name() << "...");
76  ATH_MSG_INFO("Processed " << m_nEventsProcessed << " events containing: ");
77  ATH_MSG_INFO(" " << m_nTracksProcessed << " InDetForwardTrackParticles");
78  ATH_MSG_INFO(" " << m_nMuons << " muons of which " << m_nSiFwdMuons
79  << " were SiliconAssociatedForward muons");
81  << " of the SiliconAssociatedForward muons were "
82  "associated with InDetForwardTrackParticles");
83  ATH_MSG_INFO("Removed " << m_nTracksThinned << " InDetForwardTrackParticles");
84  return StatusCode::SUCCESS;
85 }
86 
88 ThinInDetForwardTrackParticlesAlg::execute(const EventContext& ctx) const
89 {
90  // Increase the event counter
91  m_nEventsProcessed.fetch_add(1, std::memory_order_relaxed);
92 
93  // Is truth thinning required?
94  if (!m_doThinning) {
95  return StatusCode::SUCCESS;
96  }
97 
98  // Retrieve InDetForwardTrackParticles container
100 
101  // Set up mask and set the main counters
102  std::vector<bool> trackMask;
103  unsigned int nTracks = tracks->size();
104  m_nTracksProcessed.fetch_add(nTracks, std::memory_order_relaxed);
105  trackMask.assign(nTracks, false);
106 
107  unsigned int nSiFwdAssoc = 0;
108  unsigned int nSiFwdMuons = 0;
109 
110  // Loop over the muons. Identify which are SiliconAssociatedForwardMuon.
111  // Get their associated inner detector track. Find that track in the
112  // InDetForwardTrackParticles. Set the mask element.
113  // Only if muons are provided as inputs
114 
115  if(!m_muonsKey.empty()){
117  m_nMuons.fetch_add(muons->size(), std::memory_order_relaxed);
118 
119  for (const auto* muon : *muons) {
120  if (muon->muonType() == xAOD::Muon::SiliconAssociatedForwardMuon) {
121  ++nSiFwdMuons;
122  const xAOD::TrackParticle* muTrk(nullptr);
123  if (muon->inDetTrackParticleLink().isValid())
124  muTrk = *(muon->inDetTrackParticleLink());
125  if (muTrk != nullptr) {
126  auto search = std::find(tracks->begin(), tracks->end(), muTrk);
127  if (search != tracks->end()) {
128  ++nSiFwdAssoc;
129  trackMask[(*search)->index()] = true;
130  }
131  }
132  }
133  }
134  }
135 
136  m_nSiFwdAssoc.fetch_add(nSiFwdAssoc, std::memory_order_relaxed);
137  m_nSiFwdMuons.fetch_add(nSiFwdMuons, std::memory_order_relaxed);
138 
139  // Increment counters
140  unsigned int nTracksThinned = 0;
141  for (unsigned int i = 0; i < nTracks; ++i) {
142  if (!trackMask[i])
143  ++nTracksThinned;
144  }
145  m_nTracksThinned.fetch_add(nTracksThinned, std::memory_order_relaxed);
146  // Apply masks to thinning service
147  tracks.keep(trackMask);
148 
149  return StatusCode::SUCCESS;
150 }
151 
ThinInDetForwardTrackParticlesAlg::m_nSiFwdMuons
std::atomic< unsigned long > m_nSiFwdMuons
Definition: ThinInDetForwardTrackParticlesAlg.h:75
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ThinInDetForwardTrackParticlesAlg::initialize
virtual StatusCode initialize() override
Athena algorithm's initalize hook.
Definition: ThinInDetForwardTrackParticlesAlg.cxx:47
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ThinInDetForwardTrackParticlesAlg::m_streamName
StringProperty m_streamName
Definition: ThinInDetForwardTrackParticlesAlg.h:47
ThinInDetForwardTrackParticlesAlg::m_nMuons
std::atomic< unsigned long > m_nMuons
Definition: ThinInDetForwardTrackParticlesAlg.h:74
ThinInDetForwardTrackParticlesAlg::m_nTracksProcessed
std::atomic< unsigned long > m_nTracksProcessed
Definition: ThinInDetForwardTrackParticlesAlg.h:72
search
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition: hcg.cxx:738
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
ThinInDetForwardTrackParticlesAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ThinInDetForwardTrackParticlesAlg::m_nSiFwdAssoc
std::atomic< unsigned long > m_nSiFwdAssoc
Definition: ThinInDetForwardTrackParticlesAlg.h:76
ThinInDetForwardTrackParticlesAlg::m_muonsKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
Definition: ThinInDetForwardTrackParticlesAlg.h:60
ThinInDetForwardTrackParticlesAlg::m_nTracksThinned
std::atomic< unsigned long > m_nTracksThinned
Definition: ThinInDetForwardTrackParticlesAlg.h:73
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonContainer.h
ThinInDetForwardTrackParticlesAlg::m_tracksKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_tracksKey
Definition: ThinInDetForwardTrackParticlesAlg.h:52
ThinInDetForwardTrackParticlesAlg::ThinInDetForwardTrackParticlesAlg
ThinInDetForwardTrackParticlesAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: ThinInDetForwardTrackParticlesAlg.cxx:37
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ReadHandle.h
Handle class for reading from StoreGate.
ThinInDetForwardTrackParticlesAlg::finalize
virtual StatusCode finalize() override
Athena algorithm's finalize hook.
Definition: ThinInDetForwardTrackParticlesAlg.cxx:73
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ThinInDetForwardTrackParticlesAlg::m_nEventsProcessed
std::atomic< unsigned long > m_nEventsProcessed
Counters.
Definition: ThinInDetForwardTrackParticlesAlg.h:71
TrackParticleContainer.h
ThinInDetForwardTrackParticlesAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Athena algorithm's execute hook.
Definition: ThinInDetForwardTrackParticlesAlg.cxx:88
ThinInDetForwardTrackParticlesAlg::m_doThinning
BooleanProperty m_doThinning
Should the thinning run?
Definition: ThinInDetForwardTrackParticlesAlg.h:63