ATLAS Offline Software
EGElectronLikelihoodToolWrapper.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 //
9 #include "PATCore/AcceptData.h"
10 #include "PATCore/AcceptInfo.h"
11 //
14 #include "xAODEgamma/Electron.h"
15 #include "xAODEgamma/Photon.h"
16 
17 namespace DerivationFramework {
18 
21  {
22  ATH_CHECK(m_tool.retrieve());
23 
24  if (!(m_fudgeMCTool.name().empty())) {
25  ATH_CHECK(m_fudgeMCTool.retrieve());
26  } else {
27  m_fudgeMCTool.disable();
28  }
29 
30  ATH_CHECK(m_ContainerName.initialize());
31  //
32  ATH_CHECK(m_decoratorPass.initialize());
33  ATH_CHECK(m_decoratorIsEM.initialize());
34  //
37  return StatusCode::SUCCESS;
38  }
39 
41  EGElectronLikelihoodToolWrapper::addBranches(const EventContext& ctx) const
42  {
43  // retrieve container
45 
46  // If we're applying corrections, the correction tools will give us
47  // copies that we need to keep track of. (We want to do all the copies
48  // before we start writing decorations, to avoid warnings about having
49  // unlocked decorations in a copy).
50  // The copies we get back from the tool will have standalone aux stores.
51  // We'll put them in a DataVector to get them deleted, but we don't
52  // need to copy the aux data to the container, so construct it with
53  // @c NEVER_TRACK_INDICES.
55  if (!m_fudgeMCTool.empty()) {
56  pCopies.reserve (particles->size());
57  for (const xAOD::Egamma* par : *particles) {
59  // apply the shower shape corrections
61  xAOD::Egamma* pCopy = nullptr;
62  if (type == xAOD::Type::Electron) {
63  const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
64  xAOD::Electron* el = nullptr;
65  correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
66  pCopy = el;
67  } else {
68  const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
69  xAOD::Photon* ph = nullptr;
70  correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
71  pCopy = ph;
72  }
73  if (correctionCode == CP::CorrectionCode::Ok) { // All OK
74  } else if (correctionCode == CP::CorrectionCode::Error) {
75  Error("addBranches()",
76  "Error applying fudge factors to current photon");
77  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
78  Warning(
79  "addBranches()",
80  "Current object has no valid fudge factors due to out-of-range");
81  } else {
82  Warning(
83  "addBranches()",
84  "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
85  (int)correctionCode);
86  }
87  pCopies.push_back (pCopy);
88  }
89  }
90  else {
91  pCopies.resize (particles->size());
92  }
93 
94  // Decorators
96  m_decoratorPass, ctx
97  };
99  m_decoratorIsEM, ctx
100  };
101 
102  std::unique_ptr<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
103  decoratorResult = nullptr;
104  if (m_storeTResult) {
105  decoratorResult =
106  std::make_unique<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>(
107  m_decoratorResult, ctx);
108  }
109  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decoratorMultipleOutputs{};
111  decoratorMultipleOutputs = m_decoratorMultipleOutputs.makeHandles(ctx);
112  }
113 
114  // Write mask for each element and record to SG for subsequent selection
115  for (size_t ipar = 0; const xAOD::Egamma* par : *particles) {
116  const xAOD::Egamma* pCopy = pCopies[ipar++];
117  if (!pCopy) pCopy = par;
118  // compute the output of the selector
119  asg::AcceptData theAccept(m_tool->accept(ctx, pCopy));
120  const unsigned int isEM =
121  (unsigned int)theAccept.getCutResultInvertedBitSet()
122  .to_ulong(); // this should work for both the
123  // cut-based and the LH selectors
124 
125  // decorate the original object
126  if (m_cut.empty()) {
127  const bool pass_selection = (bool)theAccept;
128  if (pass_selection) {
129  decoratorPass(*par) = 1;
130  } else {
131  decoratorPass(*par) = 0;
132  }
133  decoratorIsEM(*par) = isEM;
134  if (decoratorResult) {
135  (*decoratorResult)(*par) =
136  static_cast<float>(m_tool->calculate(ctx, pCopy));
137  }
139  // calculateMultipleOutputs only supports xAOD::Electron as input
140  const xAOD::Electron *eCopy = static_cast<const xAOD::Electron *>(pCopy);
141  std::vector<float> toolOutput = m_tool->calculateMultipleOutputs(ctx, eCopy);
142  for (size_t i = 0; i < toolOutput.size(); i++){
143  decoratorMultipleOutputs.at(i)(*par) = toolOutput.at(i);
144  }
145  }
146  } else {
147  if (theAccept.getCutResult(m_cut)) {
148  decoratorPass(*par) = 1;
149  } else {
150  decoratorPass(*par) = 0;
151  }
152  decoratorIsEM(*par) = isEM;
153  if (decoratorResult) {
154  (*decoratorResult)(*par) =
155  static_cast<float>(m_tool->calculate(ctx, pCopy));
156  }
158  // calculateMultipleOutputs only supports xAOD::Electron as input
159  const xAOD::Electron* eCopy = static_cast<const xAOD::Electron*>(pCopy);
160  std::vector<float> toolOutput = m_tool->calculateMultipleOutputs(ctx, eCopy);
161  for (size_t i = 0; i < toolOutput.size(); i++){
162  decoratorMultipleOutputs.at(i)(*par) = toolOutput.at(i);
163  }
164  }
165  }
166  }
167 
168  return StatusCode::SUCCESS;
169  }
170 }
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
DerivationFramework::EGElectronLikelihoodToolWrapper::m_fudgeMCTool
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
Definition: EGElectronLikelihoodToolWrapper.h:50
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::EGElectronLikelihoodToolWrapper::m_decoratorIsEM
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorIsEM
Definition: EGElectronLikelihoodToolWrapper.h:61
DerivationFramework::EGElectronLikelihoodToolWrapper::m_storeTResult
Gaudi::Property< bool > m_storeTResult
Definition: EGElectronLikelihoodToolWrapper.h:67
EGElectronLikelihoodToolWrapper.h
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
DerivationFramework::EGElectronLikelihoodToolWrapper::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: EGElectronLikelihoodToolWrapper.cxx:41
EgammaContainer.h
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
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
DerivationFramework::EGElectronLikelihoodToolWrapper::m_decoratorPass
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorPass
Definition: EGElectronLikelihoodToolWrapper.h:59
IParticleContainer.h
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::EGElectronLikelihoodToolWrapper::initialize
virtual StatusCode initialize() override final
Definition: EGElectronLikelihoodToolWrapper.cxx:20
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
DerivationFramework::EGElectronLikelihoodToolWrapper::m_ContainerName
SG::ReadHandleKey< xAOD::EgammaContainer > m_ContainerName
Definition: EGElectronLikelihoodToolWrapper.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
AcceptData.h
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.
DerivationFramework::EGElectronLikelihoodToolWrapper::m_decoratorResult
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorResult
Definition: EGElectronLikelihoodToolWrapper.h:63
xAOD::Electron_v1
Definition: Electron_v1.h:34
DerivationFramework::EGElectronLikelihoodToolWrapper::m_tool
ToolHandle< IAsgElectronLikelihoodTool > m_tool
Definition: EGElectronLikelihoodToolWrapper.h:43
AcceptInfo.h
DerivationFramework::EGElectronLikelihoodToolWrapper::m_decoratorMultipleOutputs
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer, float > m_decoratorMultipleOutputs
Definition: EGElectronLikelihoodToolWrapper.h:65
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
DerivationFramework::EGElectronLikelihoodToolWrapper::m_cut
Gaudi::Property< std::string > m_cut
Definition: EGElectronLikelihoodToolWrapper.h:66
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
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
DerivationFramework::EGElectronLikelihoodToolWrapper::m_storeMultipleOutputs
Gaudi::Property< bool > m_storeMultipleOutputs
Definition: EGElectronLikelihoodToolWrapper.h:68
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
Electron.h
asg::AcceptData
Definition: AcceptData.h:30
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60