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"
29
31// Public methods:
33
34// Constructors
37 const std::string& name,
38 ISvcLocator* pSvcLocator)
39 : AthReentrantAlgorithm(name, pSvcLocator)
40{
41}
42
43// Athena Algorithm's Hooks
45StatusCode
47{
48 ATH_MSG_DEBUG("Initializing " << name() << "...");
49
50 // Print out the used configuration
51 ATH_MSG_DEBUG(" using = " << m_streamName);
52
53 // Is truth thinning required?
54 if (!m_doThinning) {
55 ATH_MSG_INFO("InDetForwardTrackParticles thinning not required");
56 } else {
57 ATH_MSG_INFO("InDetForwardTrackParticles will be thinned");
58 }
59
60 if (m_doThinning && m_streamName.empty()) {
61 ATH_MSG_ERROR("StreamName property was not initialized.");
62 return StatusCode::FAILURE;
63 }
65 ATH_CHECK(m_muonsKey.initialize(m_doThinning && !m_muonsKey.empty()));
66 ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
67
68 return StatusCode::SUCCESS;
69}
70
71StatusCode
73{
74 ATH_MSG_DEBUG("Finalizing " << name() << "...");
75 ATH_MSG_INFO("Processed " << m_nEventsProcessed << " events containing: ");
76 ATH_MSG_INFO(" " << m_nTracksProcessed << " InDetForwardTrackParticles");
77 ATH_MSG_INFO(" " << m_nMuons << " muons of which " << m_nSiFwdMuons
78 << " were SiliconAssociatedForward muons");
80 << " of the SiliconAssociatedForward muons were "
81 "associated with InDetForwardTrackParticles");
82 ATH_MSG_INFO("Removed " << m_nTracksThinned << " InDetForwardTrackParticles");
83 return StatusCode::SUCCESS;
84}
85
86StatusCode
87ThinInDetForwardTrackParticlesAlg::execute(const EventContext& ctx) const
88{
89 // Increase the event counter
90 m_nEventsProcessed.fetch_add(1, std::memory_order_relaxed);
91
92 // Is truth thinning required?
93 if (!m_doThinning) {
94 return StatusCode::SUCCESS;
95 }
96
97 // Retrieve InDetForwardTrackParticles container
99
100 // Set up mask and set the main counters
101 std::vector<bool> trackMask;
102 unsigned int nTracks = tracks->size();
103 m_nTracksProcessed.fetch_add(nTracks, std::memory_order_relaxed);
104 trackMask.assign(nTracks, false);
105
106 unsigned int nSiFwdAssoc = 0;
107 unsigned int nSiFwdMuons = 0;
108
109 // Loop over the muons. Identify which are SiliconAssociatedForwardMuon.
110 // Get their associated inner detector track. Find that track in the
111 // InDetForwardTrackParticles. Set the mask element.
112 // Only if muons are provided as inputs
113
114 if(!m_muonsKey.empty()){
116 m_nMuons.fetch_add(muons->size(), std::memory_order_relaxed);
117
118 for (const auto* muon : *muons) {
119 if (muon->muonType() == xAOD::Muon::MuonType::SiliconAssociatedForwardMuon) {
120 ++nSiFwdMuons;
121 const xAOD::TrackParticle* muTrk = muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
122
123 if (muTrk != nullptr) {
124 auto search = std::find(tracks->begin(), tracks->end(), muTrk);
125 if (search != tracks->end()) {
126 ++nSiFwdAssoc;
127 trackMask[(*search)->index()] = true;
128 }
129 }
130 }
131 }
132 }
133
134 m_nSiFwdAssoc.fetch_add(nSiFwdAssoc, std::memory_order_relaxed);
135 m_nSiFwdMuons.fetch_add(nSiFwdMuons, std::memory_order_relaxed);
136
137 // Increment counters
138 unsigned int nTracksThinned = 0;
139 for (unsigned int i = 0; i < nTracks; ++i) {
140 if (!trackMask[i])
141 ++nTracksThinned;
142 }
143 m_nTracksThinned.fetch_add(nTracksThinned, std::memory_order_relaxed);
144 // Apply masks to thinning service
145 tracks.keep(trackMask);
146
147 return StatusCode::SUCCESS;
148}
149
#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:743
TrackParticle_v1 TrackParticle
Reference the current persistent version: