ATLAS Offline Software
Loading...
Searching...
No Matches
ThinNegativeEnergyCaloClustersAlg.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// ThinNegativeEnergyCaloClustersAlg.cxx
8// Author: James Catmore <James.Catmore@cern.ch>
9// based on similar code by Karsten Koeneke <karsten.koeneke@cern.ch>
10// Uses thinning service to remove CaloClusters with negative energy
11// Intended for use in ESD->AOD in reconstruction - use other tools
12// for analysis (Expression evaluation is not used here)
14
15// EventUtils includes
18
19// STL includes
20#include <algorithm>
21
22// FrameWork includes
24
26// Public methods:
28
29// Constructors
32 const std::string& name,
33 ISvcLocator* pSvcLocator)
34 : AthReentrantAlgorithm(name, pSvcLocator)
38{}
39
40// Athena Algorithm's Hooks
42StatusCode
44{
45 ATH_MSG_DEBUG("Initializing " << name() << "...");
46
47 // Print out the used configuration
48 ATH_MSG_DEBUG(" using = " << m_streamName);
49
50 // Is truth thinning required?
51 if (!m_doThinning) {
52 ATH_MSG_INFO("Negative energy CaloClusters thinning not required");
53 } else {
54 ATH_MSG_INFO("Negative energy CaloClusters will be thinned");
55 }
56
57 if (m_doThinning && m_streamName.empty()) {
58 ATH_MSG_ERROR("StreamName property has not been initialized.");
59 return StatusCode::FAILURE;
60 }
62
63 // Initialize the counters to zero
67
68 ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
69
70 return StatusCode::SUCCESS;
71}
72
73StatusCode
75{
76 ATH_MSG_DEBUG("Finalizing " << name() << "...");
77 ATH_MSG_INFO("Processed " << m_nEventsProcessed << " events containing "
78 << m_nCaloClustersProcessed << " CaloClusters");
80 << " negative energy CaloClusters ");
81 return StatusCode::SUCCESS;
82}
83
84StatusCode
85ThinNegativeEnergyCaloClustersAlg::execute(const EventContext& ctx) const
86{
87 // Increase the event counter
88 m_nEventsProcessed.fetch_add(1, std::memory_order_relaxed);
89
90 // Is thinning required?
91 if (!m_doThinning) {
92 return StatusCode::SUCCESS;
93 }
94
95 // Retrieve truth and vertex containers
97 ctx);
98
99 // Set up masks
100 std::vector<bool> mask;
101 int nCaloClusters = caloClusters->size();
102 m_nCaloClustersProcessed.fetch_add(nCaloClusters, std::memory_order_relaxed);
103 mask.assign(nCaloClusters, false);
104
105 // Loop over CaloClusters and update mask
106 unsigned long int nCaloClustersThinned = 0;
107 for (int i = 0; i < nCaloClusters; ++i) {
108 const xAOD::CaloCluster* caloCluster = (*caloClusters)[i];
109 // Retain postive energy clusters
110 if (caloCluster->rawE() > 0.0) {
111 mask[i] = true;
112 } else {
113 ++nCaloClustersThinned;
114 }
115 }
116 m_nCaloClustersThinned.fetch_add(nCaloClustersThinned,
117 std::memory_order_relaxed);
118
119 // Apply masks to thinning service
120 caloClusters.keep(mask);
121
122 return StatusCode::SUCCESS;
123}
124
#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 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.
BooleanProperty m_doThinning
Should the thinning run?
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
ThinNegativeEnergyCaloClustersAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode finalize() override final
Athena algorithm's finalize hook.
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
Names of the containers to thin.
StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
std::atomic< unsigned long > m_nEventsProcessed
Counters.
flt_t rawE() const
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.