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  : AthAlgTool(t, n, p)
21  , m_sgName("DFCommonPhotonsCleaning")
22 {
23  declareInterface<DerivationFramework::IAugmentationTool>(this);
24  declareProperty("StoreGateEntryName", m_sgName);
25 }
26 
29 {
30  if (m_sgName.empty()) {
32  "No SG name provided for the output of EGPhotonCleaningWrapper");
33  return StatusCode::FAILURE;
34  }
35  if (!m_fudgeMCTool.name().empty()) {
36  CHECK(m_fudgeMCTool.retrieve());
37  }
38  ATH_CHECK(m_containerName.initialize());
40  m_decoratorPassDelayed = m_containerName.key() + "." + m_sgName + "NoTime";
41  ATH_CHECK(m_decoratorPass.initialize());
42  ATH_CHECK(m_decoratorPassDelayed.initialize());
43 
44  return StatusCode::SUCCESS;
45 }
46 
49 {
50 
51  const EventContext& ctx = Gaudi::Hive::currentContext();
53 
54  // If we're applying corrections, the correction tools will give us
55  // copies that we need to keep track of. (We want to do all the copies
56  // before we start writing decorations, to avoid warnings about having
57  // unlocked decorations in a copy).
58  // The copies we get back from the tool will have standalone aux stores.
59  // We'll put them in a DataVector to get them deleted, but we don't
60  // need to copy the aux data to the container, so construct it with
61  // @c NEVER_TRACK_INDICES.
63  if (!m_fudgeMCTool.empty()) {
64  pCopies.reserve (photons->size());
65  for (const xAOD::Photon* photon : *photons) {
66  // apply the shower shape corrections
68  xAOD::Photon* ph = nullptr;
69  correctionCode = m_fudgeMCTool->correctedCopy(*photon, ph);
70  if (correctionCode == CP::CorrectionCode::Ok) {
71  } else if (correctionCode == CP::CorrectionCode::Error) {
72  Error("addBranches()",
73  "Error applying fudge factors to current photon");
74  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
75  Warning(
76  "addBranches()",
77  "Current photon has no valid fudge factors due to out-of-range");
78  } else {
79  Warning("addBranches()",
80  "Unknown correction code %d from "
81  "ElectronPhotonShowerShapeFudgeTool",
82  (int)correctionCode);
83  }
84  pCopies.push_back (ph);
85  }
86  }
87  else {
88  pCopies.resize (photons->size());
89  }
90 
92  m_decoratorPass, ctx
93  };
96  };
97 
98  // Write mask for each element and record to SG for subsequent selection
99  for (size_t ipar = 0; const xAOD::Photon* photon : *photons) {
100 
101  const xAOD::Photon* pCopy = pCopies[ipar++];
102  if (!pCopy) pCopy = photon;
103 
104  // decorate the original object
105  decoratorPass(*photon) = static_cast<int> (PhotonHelpers::passOQquality(*pCopy));
106  decoratorPassDelayed(*photon) = static_cast<int> (PhotonHelpers::passOQqualityDelayed(*pCopy));
107  }
108  return StatusCode::SUCCESS;
109 }
110 } // 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:40
PhotonHelpers.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:53
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:210
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:28
beamspotman.n
n
Definition: beamspotman.py:731
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
Pass the thinning service
Definition: EGPhotonCleaningWrapper.cxx:48
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:55
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:199
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:46
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
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::EGPhotonCleaningWrapper::m_sgName
std::string m_sgName
Definition: EGPhotonCleaningWrapper.h:56