ATLAS Offline Software
Loading...
Searching...
No Matches
ThinInDetForwardTrackParticlesAlg.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// 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
21
22// STL includes
23#include <algorithm>
24
25// FrameWork includes
26#include "Gaudi/Property.h"
27#include "GaudiKernel/ThreadLocalContext.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
46StatusCode
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
72StatusCode
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
87StatusCode
88ThinInDetForwardTrackParticlesAlg::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
#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)
Handle class for reading from StoreGate.
Handle for requesting thinning for a data object.
An algorithm that can be simultaneously executed in multiple threads.
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.
std::atomic< unsigned long > m_nEventsProcessed
Counters.
ThinInDetForwardTrackParticlesAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode initialize() override
Athena algorithm's initalize hook.
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_tracksKey
virtual StatusCode execute(const EventContext &ctx) const override
Athena algorithm's execute hook.
virtual StatusCode finalize() override
Athena algorithm's finalize hook.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
BooleanProperty m_doThinning
Should the thinning run?
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:739
TrackParticle_v1 TrackParticle
Reference the current persistent version: