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
23#include "GaudiKernel/ThreadLocalContext.h"
25
27// Public methods:
29
30// Constructors
33 const std::string& name,
34 ISvcLocator* pSvcLocator)
35 : AthReentrantAlgorithm(name, pSvcLocator)
39{}
40
41// Athena Algorithm's Hooks
43StatusCode
45{
46 ATH_MSG_DEBUG("Initializing " << name() << "...");
47
48 // Print out the used configuration
49 ATH_MSG_DEBUG(" using = " << m_streamName);
50
51 // Is truth thinning required?
52 if (!m_doThinning) {
53 ATH_MSG_INFO("Negative energy CaloClusters thinning not required");
54 } else {
55 ATH_MSG_INFO("Negative energy CaloClusters will be thinned");
56 }
57
58 if (m_doThinning && m_streamName.empty()) {
59 ATH_MSG_ERROR("StreamName property has not been initialized.");
60 return StatusCode::FAILURE;
61 }
63
64 // Initialize the counters to zero
68
69 ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
70
71 return StatusCode::SUCCESS;
72}
73
74StatusCode
76{
77 ATH_MSG_DEBUG("Finalizing " << name() << "...");
78 ATH_MSG_INFO("Processed " << m_nEventsProcessed << " events containing "
79 << m_nCaloClustersProcessed << " CaloClusters");
81 << " negative energy CaloClusters ");
82 return StatusCode::SUCCESS;
83}
84
85StatusCode
86ThinNegativeEnergyCaloClustersAlg::execute(const EventContext& ctx) const
87{
88 // Increase the event counter
89 m_nEventsProcessed.fetch_add(1, std::memory_order_relaxed);
90
91 // Is thinning required?
92 if (!m_doThinning) {
93 return StatusCode::SUCCESS;
94 }
95
96 // Retrieve truth and vertex containers
98 ctx);
99
100 // Set up masks
101 std::vector<bool> mask;
102 int nCaloClusters = caloClusters->size();
103 m_nCaloClustersProcessed.fetch_add(nCaloClusters, std::memory_order_relaxed);
104 mask.assign(nCaloClusters, false);
105
106 // Loop over CaloClusters and update mask
107 unsigned long int nCaloClustersThinned = 0;
108 for (int i = 0; i < nCaloClusters; ++i) {
109 const xAOD::CaloCluster* caloCluster = (*caloClusters)[i];
110 // Retain postive energy clusters
111 if (caloCluster->rawE() > 0.0) {
112 mask[i] = true;
113 } else {
114 ++nCaloClustersThinned;
115 }
116 }
117 m_nCaloClustersThinned.fetch_add(nCaloClustersThinned,
118 std::memory_order_relaxed);
119
120 // Apply masks to thinning service
121 caloClusters.keep(mask);
122
123 return StatusCode::SUCCESS;
124}
125
#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.