ATLAS Offline Software
EGPhotonCleaningWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Author: Giovanni Marchiori (giovanni.marchiori@cern.ch)
6 
8 #include "xAODEgamma/Photon.h"
10 
11 namespace DerivationFramework {
12 
15 {
16  if (!m_fudgeMCTool.name().empty()) {
17  CHECK(m_fudgeMCTool.retrieve());
18  }
19  ATH_CHECK(m_containerName.initialize());
20  ATH_CHECK(m_decoratorPass.initialize());
21  ATH_CHECK(m_decoratorPassDelayed.initialize());
22 
23  return StatusCode::SUCCESS;
24 }
25 
27 EGPhotonCleaningWrapper::addBranches(const EventContext& ctx) const
28 {
29 
31 
32  // If we're applying corrections, the correction tools will give us
33  // copies that we need to keep track of. (We want to do all the copies
34  // before we start writing decorations, to avoid warnings about having
35  // unlocked decorations in a copy).
36  // The copies we get back from the tool will have standalone aux stores.
37  // We'll put them in a DataVector to get them deleted, but we don't
38  // need to copy the aux data to the container, so construct it with
39  // @c NEVER_TRACK_INDICES.
41  if (!m_fudgeMCTool.empty()) {
42  pCopies.reserve (photons->size());
43  for (const xAOD::Photon* photon : *photons) {
44  // apply the shower shape corrections
46  xAOD::Photon* ph = nullptr;
47  correctionCode = m_fudgeMCTool->correctedCopy(*photon, ph);
48  if (correctionCode == CP::CorrectionCode::Ok) {
49  } else if (correctionCode == CP::CorrectionCode::Error) {
50  Error("addBranches()",
51  "Error applying fudge factors to current photon");
52  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
53  Warning(
54  "addBranches()",
55  "Current photon has no valid fudge factors due to out-of-range");
56  } else {
57  Warning("addBranches()",
58  "Unknown correction code %d from "
59  "ElectronPhotonShowerShapeFudgeTool",
60  (int)correctionCode);
61  }
62  pCopies.push_back (ph);
63  }
64  }
65  else {
66  pCopies.resize (photons->size());
67  }
68 
70  m_decoratorPass, ctx
71  };
74  };
75 
76  // Write mask for each element and record to SG for subsequent selection
77  for (size_t ipar = 0; const xAOD::Photon* photon : *photons) {
78 
79  const xAOD::Photon* pCopy = pCopies[ipar++];
80  if (!pCopy) pCopy = photon;
81 
82  // decorate the original object
83  decoratorPass(*photon) = static_cast<int> (PhotonHelpers::passOQquality(*pCopy));
84  decoratorPassDelayed(*photon) = static_cast<int> (PhotonHelpers::passOQqualityDelayed(*pCopy));
85  }
86  return StatusCode::SUCCESS;
87 }
88 } // 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:33
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:46
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
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:14
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:48
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::m_containerName
SG::ReadHandleKey< xAOD::PhotonContainer > m_containerName
Definition: EGPhotonCleaningWrapper.h:39
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:27