ATLAS Offline Software
ThinNegativeEnergyCaloClustersAlg.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 // 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)
36  , m_nEventsProcessed(0)
37  , m_nCaloClustersProcessed(0)
38  , m_nCaloClustersThinned(0)
39 {}
40 
41 // Athena Algorithm's Hooks
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 
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 
86 ThinNegativeEnergyCaloClustersAlg::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 
ThinNegativeEnergyCaloClustersAlg::m_doThinning
BooleanProperty m_doThinning
Should the thinning run?
Definition: ThinNegativeEnergyCaloClustersAlg.h:53
ThinNegativeEnergyCaloClustersAlg::finalize
virtual StatusCode finalize() override final
Athena algorithm's finalize hook.
Definition: ThinNegativeEnergyCaloClustersAlg.cxx:75
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ThinningHandle.h
Handle for requesting thinning for a data object.
ThinNegativeEnergyCaloClustersAlg.h
ThinNegativeEnergyCaloClustersAlg::ThinNegativeEnergyCaloClustersAlg
ThinNegativeEnergyCaloClustersAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: ThinNegativeEnergyCaloClustersAlg.cxx:32
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
ThinNegativeEnergyCaloClustersAlg::m_nEventsProcessed
std::atomic< unsigned long > m_nEventsProcessed
Counters.
Definition: ThinNegativeEnergyCaloClustersAlg.h:69
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ThinNegativeEnergyCaloClustersAlg::m_nCaloClustersThinned
std::atomic< unsigned long > m_nCaloClustersThinned
Definition: ThinNegativeEnergyCaloClustersAlg.h:71
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
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ThinNegativeEnergyCaloClustersAlg::initialize
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
Definition: ThinNegativeEnergyCaloClustersAlg.cxx:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ThinNegativeEnergyCaloClustersAlg::m_caloClustersKey
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
Names of the containers to thin.
Definition: ThinNegativeEnergyCaloClustersAlg.h:61
CaloClusterContainer.h
ThinNegativeEnergyCaloClustersAlg::m_streamName
StringProperty m_streamName
Definition: ThinNegativeEnergyCaloClustersAlg.h:45
ThinNegativeEnergyCaloClustersAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
Definition: ThinNegativeEnergyCaloClustersAlg.cxx:86
ThinNegativeEnergyCaloClustersAlg::m_nCaloClustersProcessed
std::atomic< unsigned long > m_nCaloClustersProcessed
Definition: ThinNegativeEnergyCaloClustersAlg.h:70