ATLAS Offline Software
Loading...
Searching...
No Matches
ThinNegativeEnergyNeutralPFOsAlg.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// 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
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)
41{
42}
43
44// Athena Algorithm's Hooks
46StatusCode
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()));
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
80StatusCode
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
91StatusCode
92ThinNegativeEnergyNeutralPFOsAlg::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
#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?
ThinNegativeEnergyNeutralPFOsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode finalize() override final
Athena algorithm's finalize hook.
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's execute hook.
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_LCNeutralPFOsKey
virtual StatusCode initialize() override final
Athena algorithm's initalize hook.
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_neutralPFOsKey
Names of the containers to thin.
std::atomic< unsigned long > m_nNeutralPFOsProcessed
std::atomic< unsigned long > m_nEventsProcessed
Counters.
virtual double pt() const override
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16