ATLAS Offline Software
EGSelectionToolWrapper.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 //
7 
9 #include "PATCore/AcceptData.h"
12 #include "xAODEgamma/Electron.h"
13 #include "xAODEgamma/Photon.h"
14 
15 namespace DerivationFramework {
16 
19 {
20  ATH_CHECK(m_tool.retrieve());
21 
22  if (!(m_fudgeMCTool.name().empty())) {
23  ATH_CHECK(m_fudgeMCTool.retrieve());
24  } else {
25  m_fudgeMCTool.disable();
26  }
27 
28  ATH_CHECK(m_ContainerName.initialize());
29  ATH_CHECK(m_decoratorPass.initialize());
30  ATH_CHECK(m_decoratorIsEM.initialize());
31 
32  return StatusCode::SUCCESS;
33 }
34 
36 EGSelectionToolWrapper::addBranches(const EventContext& ctx) const
37 {
38  // retrieve container
40 
41  // Decorators
43  m_decoratorPass, ctx
44  };
46  m_decoratorIsEM, ctx
47  };
48 
49  // If we're applying corrections, the correction tools will give us
50  // copies that we need to keep track of. (We want to do all the copies
51  // before we start writing decorations, to avoid warnings about having
52  // unlocked decorations in a copy).
53  // The copies we get back from the tool will have standalone aux stores.
54  // We'll put them in a DataVector to get them deleted, but we don't
55  // need to copy the aux data to the container, so construct it with
56  // @c NEVER_TRACK_INDICES.
58  if (!m_fudgeMCTool.empty()) {
59  pCopies.reserve (particles->size());
60  for (const xAOD::Egamma* par : *particles) {
62  // apply the shower shape corrections
64  xAOD::Egamma* pCopy = nullptr;
65  if (type == xAOD::Type::Electron) {
66  const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
67  xAOD::Electron* el = nullptr;
68  correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
69  pCopy = el;
70  } else {
71  const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
72  xAOD::Photon* ph = nullptr;
73  correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
74  pCopy = ph;
75  }
76  if (correctionCode == CP::CorrectionCode::Ok) {
77  // all OK
78  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
79  Warning(
80  "addBranches()",
81  "Current photon has no valid fudge factors due to out-of-range");
82  } else {
83  Warning(
84  "addBranches()",
85  "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
86  (int)correctionCode);
87  }
88  pCopies.push_back (pCopy);
89  }
90  }
91  else {
92  pCopies.resize (particles->size());
93  }
94 
95  // Write mask for each element and record to SG for subsequent selection
96  for (size_t ipar = 0; const xAOD::Egamma* par : *particles) {
97  const xAOD::Egamma* pCopy = pCopies[ipar++];
98  if (!pCopy) pCopy = par;
99 
100  // compute the output of the selector
101  asg::AcceptData theAccept(m_tool->accept(ctx, pCopy));
102  unsigned int isEM = (unsigned int)theAccept.getCutResultInvertedBitSet()
103  .to_ulong(); // this should work for both the
104  // cut-based and the LH selectors
105 
106  // decorate the original object
107  if (m_cut == "") {
108  bool pass_selection = (bool)theAccept;
109  if (pass_selection) {
110  decoratorPass(*par) = 1;
111  } else {
112  decoratorPass(*par) = 0;
113  }
114  decoratorIsEM(*par) = isEM;
115  } else {
116  if (theAccept.getCutResult(m_cut)) {
117  decoratorPass(*par) = 1;
118  } else {
119  decoratorPass(*par) = 0;
120  }
121  decoratorIsEM(*par) = isEM;
122  }
123  }
124 
125  return StatusCode::SUCCESS;
126 }
127 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
asg::AcceptData::getCutResultInvertedBitSet
std::bitset< NBITS > getCutResultInvertedBitSet() const
Get an inverted bitset of the cut result.
Definition: AcceptData.h:119
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
ParticleTest.eg
eg
Definition: ParticleTest.py:29
ObjectType
ObjectType
Definition: BaseObject.h:11
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::EGSelectionToolWrapper::m_decoratorIsEM
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorIsEM
Definition: EGSelectionToolWrapper.h:52
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
DerivationFramework::EGSelectionToolWrapper::m_decoratorPass
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorPass
Definition: EGSelectionToolWrapper.h:50
DerivationFramework::EGSelectionToolWrapper::m_tool
ToolHandle< IAsgEGammaIsEMSelector > m_tool
Definition: EGSelectionToolWrapper.h:36
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
DerivationFramework::EGSelectionToolWrapper::initialize
virtual StatusCode initialize() override final
Definition: EGSelectionToolWrapper.cxx:18
EgammaContainer.h
DerivationFramework::EGSelectionToolWrapper::m_cut
Gaudi::Property< std::string > m_cut
Definition: EGSelectionToolWrapper.h:54
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
Photon.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IParticleContainer.h
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
python.getProblemFolderFromLogs.el
dictionary el
Definition: getProblemFolderFromLogs.py:54
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
AcceptData.h
DerivationFramework::EGSelectionToolWrapper::m_ContainerName
SG::ReadHandleKey< xAOD::EgammaContainer > m_ContainerName
Definition: EGSelectionToolWrapper.h:45
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
DerivationFramework::EGSelectionToolWrapper::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: EGSelectionToolWrapper.cxx:36
xAOD::Photon_v1
Definition: Photon_v1.h:37
asg::AcceptData::getCutResult
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:98
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
Electron.h
DerivationFramework::EGSelectionToolWrapper::m_fudgeMCTool
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
Definition: EGSelectionToolWrapper.h:43
asg::AcceptData
Definition: AcceptData.h:30
EGSelectionToolWrapper.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60