ATLAS Offline Software
ThinNegativeEnergyNeutralPFOsAlg.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 // ThinNegativeEnergyNeutralPFOsAlg.cxx
8 // Author: Chris Young <christopher.young@cern.ch>
9 // based on similar code by Karsten Koeneke <karsten.koeneke@cern.ch>
10 // and James Catmore <James.Catmore@cern.ch>
11 // Uses thinning service to remove Neutral PFOs with negative energy
12 // Intended for use in ESD->AOD in reconstruction - use other tools
13 // for analysis (Expression evaluation is not used here)
15 
16 // EventUtils includes
18 #include "xAODPFlow/PFOContainer.h"
19 
20 // STL includes
21 #include <algorithm>
22 
23 // FrameWork includes
24 #include "Gaudi/Property.h"
25 #include "GaudiKernel/ThreadLocalContext.h"
27 
29 // Public methods:
31 
32 // Constructors
35  const std::string& name,
36  ISvcLocator* pSvcLocator)
37  : AthReentrantAlgorithm(name, pSvcLocator)
38  , m_nEventsProcessed(0)
39  , m_nNeutralPFOsProcessed(0)
40  , m_nNeutralPFOsThinned(0)
41 {
42 }
43 
44 // Athena Algorithm's Hooks
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("Negative energy NeutralPFO thinning not required");
57  } else {
58  ATH_MSG_INFO("Negative energy NeutralPFOs will be thinned");
59  }
60 
61  if (m_doThinning && m_streamName.empty()) {
62  ATH_MSG_ERROR("StreamName property has not been initialized.");
63  return StatusCode::FAILURE;
64  }
65  ATH_CHECK(m_neutralPFOsKey.initialize(
66  m_streamName, m_doThinning && !m_neutralPFOsKey.key().empty()));
67  ATH_CHECK(m_LCNeutralPFOsKey.initialize(
68  m_streamName, m_doThinning && !m_LCNeutralPFOsKey.key().empty()));
69 
70  // Initialize the counters to zero
74 
75  ATH_MSG_DEBUG("==> done with initialize " << name() << "...");
76 
77  return StatusCode::SUCCESS;
78 }
79 
82 {
83  ATH_MSG_DEBUG("Finalizing " << name() << "...");
84  ATH_MSG_INFO("Processed " << m_nEventsProcessed << " events containing "
85  << m_nNeutralPFOsProcessed << " NeutralPFOs");
87  << " negative energy NeutralPFOs ");
88  return StatusCode::SUCCESS;
89 }
90 
92 ThinNegativeEnergyNeutralPFOsAlg::execute(const EventContext& ctx) const
93 {
94  // Increase the event counter
95  m_nEventsProcessed.fetch_add(1, std::memory_order_relaxed);
96 
97  // Is truth thinning required?
98  if (!m_doThinning || m_neutralPFOsKey.key().empty()) {
99  return StatusCode::SUCCESS;
100  }
101 
103  ctx);
104  std::vector<bool> mask;
105  int nNeutralFEs = neutralFEs->size();
106  m_nNeutralPFOsProcessed.fetch_add(nNeutralFEs, std::memory_order_relaxed);
107  mask.assign(nNeutralFEs, false);
108 
109  unsigned long int nNeutralPFOsThinned = 0;
110  for (int i = 0; i < nNeutralFEs; i++) {
111  const xAOD::FlowElement* neutralFE = (*neutralFEs)[i];
112  if (neutralFE->pt() > 0.0)
113  mask[i] = true;
114  else {
115  ++nNeutralPFOsThinned;
116  }
117  }
118 
119  m_nNeutralPFOsThinned.fetch_add(nNeutralPFOsThinned,
120  std::memory_order_relaxed);
121  neutralFEs.keep(mask);
122 
123  if (!m_LCNeutralPFOsKey.key().empty()) {
125  m_LCNeutralPFOsKey, ctx);
126  // LC PFOs are thinned based on the energy of the (EM-scale) originals
127  LCNeutralFEs.keep(mask);
128  }
129  return StatusCode::SUCCESS;
130 }
131 
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ThinNegativeEnergyNeutralPFOsAlg.h
ThinNegativeEnergyNeutralPFOsAlg::m_nEventsProcessed
std::atomic< unsigned long > m_nEventsProcessed
Counters.
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:75
ThinningHandle.h
Handle for requesting thinning for a data object.
ThinNegativeEnergyNeutralPFOsAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
Definition: ThinNegativeEnergyNeutralPFOsAlg.cxx:92
PFOContainer.h
xAOD::FlowElement_v1::pt
virtual double pt() const override
ThinNegativeEnergyNeutralPFOsAlg::m_LCNeutralPFOsKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_LCNeutralPFOsKey
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:67
ThinNegativeEnergyNeutralPFOsAlg::finalize
virtual StatusCode finalize() override final
Athena algorithm's finalize hook.
Definition: ThinNegativeEnergyNeutralPFOsAlg.cxx:81
ThinNegativeEnergyNeutralPFOsAlg::ThinNegativeEnergyNeutralPFOsAlg
ThinNegativeEnergyNeutralPFOsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: ThinNegativeEnergyNeutralPFOsAlg.cxx:34
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
ThinNegativeEnergyNeutralPFOsAlg::m_streamName
StringProperty m_streamName
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:45
ThinNegativeEnergyNeutralPFOsAlg::m_neutralPFOsKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_neutralPFOsKey
Names of the containers to thin.
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:61
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
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
ThinNegativeEnergyNeutralPFOsAlg::m_nNeutralPFOsThinned
std::atomic< unsigned long > m_nNeutralPFOsThinned
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:77
ThinNegativeEnergyNeutralPFOsAlg::m_doThinning
BooleanProperty m_doThinning
Should the thinning run?
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:53
ThinNegativeEnergyNeutralPFOsAlg::m_nNeutralPFOsProcessed
std::atomic< unsigned long > m_nNeutralPFOsProcessed
Definition: ThinNegativeEnergyNeutralPFOsAlg.h:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ThinNegativeEnergyNeutralPFOsAlg::initialize
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
Definition: ThinNegativeEnergyNeutralPFOsAlg.cxx:47
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25