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 
48 {
49 
50  const EventContext& ctx = Gaudi::Hive::currentContext();
52 
53  // If we're applying corrections, the correction tools will give us
54  // copies that we need to keep track of. (We want to do all the copies
55  // before we start writing decorations, to avoid warnings about having
56  // unlocked decorations in a copy).
57  // The copies we get back from the tool will have standalone aux stores.
58  // We'll put them in a DataVector to get them deleted, but we don't
59  // need to copy the aux data to the container, so construct it with
60  // @c NEVER_TRACK_INDICES.
62  if (!m_fudgeMCTool.empty()) {
63  pCopies.reserve (photons->size());
64  for (const xAOD::Photon* photon : *photons) {
65  // apply the shower shape corrections
67  xAOD::Photon* ph = nullptr;
68  correctionCode = m_fudgeMCTool->correctedCopy(*photon, ph);
69  if (correctionCode == CP::CorrectionCode::Ok) {
70  } else if (correctionCode == CP::CorrectionCode::Error) {
71  Error("addBranches()",
72  "Error applying fudge factors to current photon");
73  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
74  Warning(
75  "addBranches()",
76  "Current photon has no valid fudge factors due to out-of-range");
77  } else {
78  Warning("addBranches()",
79  "Unknown correction code %d from "
80  "ElectronPhotonShowerShapeFudgeTool",
81  (int)correctionCode);
82  }
83  pCopies.push_back (ph);
84  }
85  }
86  else {
87  pCopies.resize (photons->size());
88  }
89 
91  m_decoratorPass, ctx
92  };
95  };
96 
97  // Write mask for each element and record to SG for subsequent selection
98  for (size_t ipar = 0; const xAOD::Photon* photon : *photons) {
99 
100  const xAOD::Photon* pCopy = pCopies[ipar++];
101  if (!pCopy) pCopy = photon;
102 
103  // decorate the original object
104  decoratorPass(*photon) = static_cast<int> (PhotonHelpers::passOQquality(*pCopy));
105  decoratorPassDelayed(*photon) = static_cast<int> (PhotonHelpers::passOQqualityDelayed(*pCopy));
106  }
107  return StatusCode::SUCCESS;
108 }
109 } // 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:729
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
DerivationFramework::EGPhotonCleaningWrapper::addBranches
virtual StatusCode addBranches() const override final
Definition: EGPhotonCleaningWrapper.cxx:47
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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::m_sgName
std::string m_sgName
Definition: EGPhotonCleaningWrapper.h:54