ATLAS Offline Software
EGSelectionToolWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  : AthAlgTool(t, n, p)
24 {
25  declareInterface<DerivationFramework::IAugmentationTool>(this);
26 }
27 
30 {
31  if (m_sgName.empty()) {
33  "No SG name provided for the output of EGElectronLikelihoodToolWrapper!");
34  return StatusCode::FAILURE;
35  }
36  ATH_CHECK(m_tool.retrieve());
37 
38  if (!(m_fudgeMCTool.name().empty())) {
39  ATH_CHECK(m_fudgeMCTool.retrieve());
40  } else {
41  m_fudgeMCTool.disable();
42  }
43 
44  ATH_CHECK(m_ContainerName.initialize());
45  //
47  m_decoratorIsEM = m_ContainerName.key() + "." + m_sgName + "IsEMValue";
48  ATH_CHECK(m_decoratorPass.initialize());
49  ATH_CHECK(m_decoratorIsEM.initialize());
50 
51  return StatusCode::SUCCESS;
52 }
53 
56 {
57  // retrieve container
58  const EventContext& ctx = Gaudi::Hive::currentContext();
60 
61  // Decorators
63  m_decoratorPass, ctx
64  };
66  m_decoratorIsEM, ctx
67  };
68 
69  bool applyFF = (!m_fudgeMCTool.empty());
70  // Write mask for each element and record to SG for subsequent selection
71  for (const xAOD::Egamma* par : *particles) {
72  const xAOD::Egamma* pCopy = par;
73  if (applyFF) {
76  if (type == xAOD::Type::Electron) {
77  const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
78  xAOD::Electron* el = nullptr;
79  correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
80  pCopy = el;
81  } else {
82  const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
83  xAOD::Photon* ph = nullptr;
84  correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
85  pCopy = ph;
86  }
87  if (correctionCode == CP::CorrectionCode::Ok) {
88  // all OK
89  } else if (correctionCode == CP::CorrectionCode::Error) {
90  Error("addBranches()",
91  "Error applying fudge factors to current photon");
92  } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
93  Warning(
94  "addBranches()",
95  "Current photon has no valid fudge factors due to out-of-range");
96  } else {
97  Warning(
98  "addBranches()",
99  "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
100  (int)correctionCode);
101  }
102  }
103  // compute the output of the selector
104  asg::AcceptData theAccept(m_tool->accept(ctx, pCopy));
105  unsigned int isEM = (unsigned int)theAccept.getCutResultInvertedBitSet()
106  .to_ulong(); // this should work for both the
107  // cut-based and the LH selectors
108 
109  // decorate the original object
110  if (m_cut == "") {
111  bool pass_selection = (bool)theAccept;
112  if (pass_selection) {
113  decoratorPass(*par) = 1;
114  } else {
115  decoratorPass(*par) = 0;
116  }
117  decoratorIsEM(*par) = isEM;
118  } else {
119  if (theAccept.getCutResult(m_cut)) {
120  decoratorPass(*par) = 1;
121  } else {
122  decoratorPass(*par) = 0;
123  }
124  decoratorIsEM(*par) = isEM;
125  }
126 
127  // delete the particle copy
128  if (applyFF) {
129  delete pCopy;
130  }
131  }
132 
133  return StatusCode::SUCCESS;
134 }
135 }
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ParticleTest.eg
eg
Definition: ParticleTest.py:29
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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:70
DerivationFramework::EGSelectionToolWrapper::m_decoratorIsEM
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorIsEM
Definition: EGSelectionToolWrapper.h:63
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:61
DerivationFramework::EGSelectionToolWrapper::m_tool
ToolHandle< IAsgEGammaIsEMSelector > m_tool
Definition: EGSelectionToolWrapper.h:43
DerivationFramework::EGSelectionToolWrapper::initialize
virtual StatusCode initialize() override final
Definition: EGSelectionToolWrapper.cxx:29
EgammaContainer.h
DerivationFramework::EGSelectionToolWrapper::m_cut
Gaudi::Property< std::string > m_cut
Definition: EGSelectionToolWrapper.h:64
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::EGSelectionToolWrapper::m_sgName
Gaudi::Property< std::string > m_sgName
Definition: EGSelectionToolWrapper.h:66
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
IParticleContainer.h
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
AcceptData.h
DerivationFramework::EGSelectionToolWrapper::m_ContainerName
SG::ReadHandleKey< xAOD::EgammaContainer > m_ContainerName
Definition: EGSelectionToolWrapper.h:52
DerivationFramework::EGSelectionToolWrapper::addBranches
virtual StatusCode addBranches() const override final
Pass the thinning service
Definition: EGSelectionToolWrapper.cxx:55
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:50
AthAlgTool
Definition: AthAlgTool.h:26
asg::AcceptData
Definition: AcceptData.h:30
EGSelectionToolWrapper.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60