ATLAS Offline Software
EGPhotonCleaningWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EGPhotonCleaningWrapper.cxx, (c) ATLAS Detector software
8 // Author: Giovanni Marchiori (giovanni.marchiori@cern.ch)
9 //
10 
12 #include "xAODEgamma/Photon.h"
14 
15 namespace DerivationFramework {
16 
18  const std::string& n,
19  const IInterface* p)
20  : base_class(t, n, p)
21  , m_sgName("DFCommonPhotonsCleaning")
22 {
23  declareProperty("StoreGateEntryName", m_sgName);
24 }
25 
28 {
29  if (m_sgName.empty()) {
31  "No SG name provided for the output of EGPhotonCleaningWrapper");
32  return StatusCode::FAILURE;
33  }
34  if (!m_fudgeMCTool.name().empty()) {
35  CHECK(m_fudgeMCTool.retrieve());
36  }
37  ATH_CHECK(m_containerName.initialize());
39  m_decoratorPassDelayed = m_containerName.key() + "." + m_sgName + "NoTime";
40  ATH_CHECK(m_decoratorPass.initialize());
41  ATH_CHECK(m_decoratorPassDelayed.initialize());
42 
43  return StatusCode::SUCCESS;
44 }
45 
47 EGPhotonCleaningWrapper::addBranches(const EventContext& ctx) const
48 {
49 
51 
52  // If we're applying corrections, the correction tools will give us
53  // copies that we need to keep track of. (We want to do all the copies
54  // before we start writing decorations, to avoid warnings about having
55  // unlocked decorations in a copy).
56  // The copies we get back from the tool will have standalone aux stores.
57  // We'll put them in a DataVector to get them deleted, but we don't
58  // need to copy the aux data to the container, so construct it with
59  // @c NEVER_TRACK_INDICES.
61  if (!m_fudgeMCTool.empty()) {
62  pCopies.reserve (photons->size());
63  for (const xAOD::Photon* photon : *photons) {
64  // apply the shower shape corrections
66  xAOD::Photon* ph = nullptr;
67  correctionCode = m_fudgeMCTool->correctedCopy(*photon, ph);
68  if (correctionCode == CP::CorrectionCode::Ok) {
69  } else if (correctionCode == CP::CorrectionCode::Error) {
70  Error("addBranches()",
71  "Error applying fudge factors to current photon");
72  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
73  Warning(
74  "addBranches()",
75  "Current photon has no valid fudge factors due to out-of-range");
76  } else {
77  Warning("addBranches()",
78  "Unknown correction code %d from "
79  "ElectronPhotonShowerShapeFudgeTool",
80  (int)correctionCode);
81  }
82  pCopies.push_back (ph);
83  }
84  }
85  else {
86  pCopies.resize (photons->size());
87  }
88 
90  m_decoratorPass, ctx
91  };
94  };
95 
96  // Write mask for each element and record to SG for subsequent selection
97  for (size_t ipar = 0; const xAOD::Photon* photon : *photons) {
98 
99  const xAOD::Photon* pCopy = pCopies[ipar++];
100  if (!pCopy) pCopy = photon;
101 
102  // decorate the original object
103  decoratorPass(*photon) = static_cast<int> (PhotonHelpers::passOQquality(*pCopy));
104  decoratorPassDelayed(*photon) = static_cast<int> (PhotonHelpers::passOQqualityDelayed(*pCopy));
105  }
106  return StatusCode::SUCCESS;
107 }
108 } // end namespace DerivationFramework
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
DerivationFramework::EGPhotonCleaningWrapper::m_fudgeMCTool
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
Definition: EGPhotonCleaningWrapper.h:38
PhotonHelpers.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
SG::NEVER_TRACK_INDICES
@ NEVER_TRACK_INDICES
Never track indices, regardless of the setting of the ownership policy.
Definition: IndexTrackingPolicy.h:46
DerivationFramework::EGPhotonCleaningWrapper::m_decoratorPass
SG::WriteDecorHandleKey< xAOD::PhotonContainer > m_decoratorPass
Definition: EGPhotonCleaningWrapper.h:51
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PhotonHelpers::passOQquality
bool passOQquality(const xAOD::Photon &ph)
Helper to ease the implemmantation of the pass Quality requirements.
Definition: PhotonHelpers.cxx:12
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
DerivationFramework::EGPhotonCleaningWrapper::initialize
virtual StatusCode initialize() override final
Definition: EGPhotonCleaningWrapper.cxx:27
beamspotman.n
n
Definition: beamspotman.py:727
Photon.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
DerivationFramework::EGPhotonCleaningWrapper::m_decoratorPassDelayed
SG::WriteDecorHandleKey< xAOD::PhotonContainer > m_decoratorPassDelayed
Definition: EGPhotonCleaningWrapper.h:53
EGPhotonCleaningWrapper.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
xAOD::Photon_v1
Definition: Photon_v1.h:37
DerivationFramework::EGPhotonCleaningWrapper::EGPhotonCleaningWrapper
EGPhotonCleaningWrapper(const std::string &t, const std::string &n, const IInterface *p)
Definition: EGPhotonCleaningWrapper.cxx:17
DerivationFramework::EGPhotonCleaningWrapper::m_containerName
SG::ReadHandleKey< xAOD::PhotonContainer > m_containerName
Definition: EGPhotonCleaningWrapper.h:44
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
PhotonHelpers::passOQqualityDelayed
bool passOQqualityDelayed(const xAOD::Photon &ph)
Helpers to ease the implementation of the pass Quality requirements.
Definition: PhotonHelpers.cxx:29
DerivationFramework::EGPhotonCleaningWrapper::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: EGPhotonCleaningWrapper.cxx:47
DerivationFramework::EGPhotonCleaningWrapper::m_sgName
std::string m_sgName
Definition: EGPhotonCleaningWrapper.h:54