ATLAS Offline Software
EGSelectionToolWrapper.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 // EGSelectionToolWrapper.cxx, (c) ATLAS Detector software
8 // Author: Giovanni Marchiori (giovanni.marchiori@cern.ch)
9 //
10 
12 #include "PATCore/AcceptData.h"
15 #include "xAODEgamma/Electron.h"
16 #include "xAODEgamma/Photon.h"
17 
18 namespace DerivationFramework {
19 
21  const std::string& n,
22  const IInterface* p)
23  : base_class(t, n, p)
24 {
25 }
26 
29 {
30  if (m_sgName.empty()) {
32  "No SG name provided for the output of EGElectronLikelihoodToolWrapper!");
33  return StatusCode::FAILURE;
34  }
35  ATH_CHECK(m_tool.retrieve());
36 
37  if (!(m_fudgeMCTool.name().empty())) {
38  ATH_CHECK(m_fudgeMCTool.retrieve());
39  } else {
40  m_fudgeMCTool.disable();
41  }
42 
43  ATH_CHECK(m_ContainerName.initialize());
44  //
46  m_decoratorIsEM = m_ContainerName.key() + "." + m_sgName + "IsEMValue";
47  ATH_CHECK(m_decoratorPass.initialize());
48  ATH_CHECK(m_decoratorIsEM.initialize());
49 
50  return StatusCode::SUCCESS;
51 }
52 
54 EGSelectionToolWrapper::addBranches(const EventContext& ctx) const
55 {
56  // retrieve container
58 
59  // Decorators
61  m_decoratorPass, ctx
62  };
64  m_decoratorIsEM, ctx
65  };
66 
67  // If we're applying corrections, the correction tools will give us
68  // copies that we need to keep track of. (We want to do all the copies
69  // before we start writing decorations, to avoid warnings about having
70  // unlocked decorations in a copy).
71  // The copies we get back from the tool will have standalone aux stores.
72  // We'll put them in a DataVector to get them deleted, but we don't
73  // need to copy the aux data to the container, so construct it with
74  // @c NEVER_TRACK_INDICES.
76  if (!m_fudgeMCTool.empty()) {
77  pCopies.reserve (particles->size());
78  for (const xAOD::Egamma* par : *particles) {
80  // apply the shower shape corrections
82  xAOD::Egamma* pCopy = nullptr;
83  if (type == xAOD::Type::Electron) {
84  const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
85  xAOD::Electron* el = nullptr;
86  correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
87  pCopy = el;
88  } else {
89  const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
90  xAOD::Photon* ph = nullptr;
91  correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
92  pCopy = ph;
93  }
94  if (correctionCode == CP::CorrectionCode::Ok) {
95  // all OK
96  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
97  Warning(
98  "addBranches()",
99  "Current photon has no valid fudge factors due to out-of-range");
100  } else {
101  Warning(
102  "addBranches()",
103  "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
104  (int)correctionCode);
105  }
106  pCopies.push_back (pCopy);
107  }
108  }
109  else {
110  pCopies.resize (particles->size());
111  }
112 
113  // Write mask for each element and record to SG for subsequent selection
114  for (size_t ipar = 0; const xAOD::Egamma* par : *particles) {
115  const xAOD::Egamma* pCopy = pCopies[ipar++];
116  if (!pCopy) pCopy = par;
117 
118  // compute the output of the selector
119  asg::AcceptData theAccept(m_tool->accept(ctx, pCopy));
120  unsigned int isEM = (unsigned int)theAccept.getCutResultInvertedBitSet()
121  .to_ulong(); // this should work for both the
122  // cut-based and the LH selectors
123 
124  // decorate the original object
125  if (m_cut == "") {
126  bool pass_selection = (bool)theAccept;
127  if (pass_selection) {
128  decoratorPass(*par) = 1;
129  } else {
130  decoratorPass(*par) = 0;
131  }
132  decoratorIsEM(*par) = isEM;
133  } else {
134  if (theAccept.getCutResult(m_cut)) {
135  decoratorPass(*par) = 1;
136  } else {
137  decoratorPass(*par) = 0;
138  }
139  decoratorIsEM(*par) = isEM;
140  }
141  }
142 
143  return StatusCode::SUCCESS;
144 }
145 }
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
DerivationFramework::EGSelectionToolWrapper::EGSelectionToolWrapper
EGSelectionToolWrapper(const std::string &t, const std::string &n, const IInterface *p)
Definition: EGSelectionToolWrapper.cxx:20
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:61
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::EGSelectionToolWrapper::m_decoratorPass
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorPass
Definition: EGSelectionToolWrapper.h:59
DerivationFramework::EGSelectionToolWrapper::m_tool
ToolHandle< IAsgEGammaIsEMSelector > m_tool
Definition: EGSelectionToolWrapper.h:41
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
DerivationFramework::EGSelectionToolWrapper::initialize
virtual StatusCode initialize() override final
Definition: EGSelectionToolWrapper.cxx:28
EgammaContainer.h
DerivationFramework::EGSelectionToolWrapper::m_cut
Gaudi::Property< std::string > m_cut
Definition: EGSelectionToolWrapper.h:62
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
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::EGSelectionToolWrapper::m_sgName
Gaudi::Property< std::string > m_sgName
Definition: EGSelectionToolWrapper.h:64
beamspotman.n
n
Definition: beamspotman.py:727
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:48
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:50
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:54
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:48
asg::AcceptData
Definition: AcceptData.h:30
EGSelectionToolWrapper.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60