ATLAS Offline Software
EMPIDBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "EMPIDBuilder.h"
7 #include "PATCore/AcceptData.h"
8 #include "xAODEgamma/Egamma.h"
9 
10 namespace {
11 const SG::AuxElement::Accessor<float> accLH("LHValue");
12 }
13 
14 EMPIDBuilder::EMPIDBuilder(const std::string& type,
15  const std::string& name,
16  const IInterface* parent)
18 {
19  // declare interface
20  declareInterface<IegammaBaseTool>(this);
21 }
22 
25 {
26  ATH_MSG_DEBUG(" Initializing EMPIDBuilder");
27 
29 
30  if (m_electronIsEMselectors.size() !=
32  ATH_MSG_ERROR("The number of selectors does not match the number of given "
33  "electronIsEMselector names");
34  return StatusCode::FAILURE;
35  }
36 
37  ATH_CHECK(m_electronLHselectors.retrieve());
38 
40  ATH_MSG_ERROR("The number of selectors does not match the number of given "
41  "electron LH selector names");
42  return StatusCode::FAILURE;
43  }
44 
46 
47  if (m_genericIsEMselectors.size() !=
49  ATH_MSG_ERROR("The number of selectors does not match the number of given "
50  "generic selector names");
51  return StatusCode::FAILURE;
52  }
53 
54  ATH_CHECK(m_photonIsEMselectors.retrieve());
55 
57  ATH_MSG_ERROR("The number of selectors does not match the number of given "
58  "photon selector names");
59  return StatusCode::FAILURE;
60  }
61 
63  if (m_lumiBlockMuTool.retrieve().isFailure()) {
64  ATH_MSG_FATAL("Unable to retrieve Luminosity Tool");
65  return StatusCode::FAILURE;
66  }
67  ATH_MSG_DEBUG("Successfully retrieved Luminosity Tool");
68  } else {
69  m_lumiBlockMuTool.disable();
70  }
71  return StatusCode::SUCCESS;
72 }
73 
75 EMPIDBuilder::execute(const EventContext& ctx, xAOD::Egamma* eg) const
76 {
77 
78  ATH_MSG_DEBUG("Executing EMPIDBuilder::execute");
79 
80  // Protection against bad pointers
81  if (eg == nullptr) {
82  ATH_MSG_WARNING("NULL egamma object given to execute function");
83  return StatusCode::SUCCESS;
84  }
85 
86  size_t size = m_electronIsEMselectors.size();
87 
88  for (size_t i = 0; i < size; ++i) {
90  // save the bool result
91  eg->setPassSelection(static_cast<bool>(accept),
93  // save the isem
94  unsigned int isEM = (~0);
95  if (m_electronIsEMselectors[i]->execute(ctx, eg, isEM).isFailure()) {
96  ATH_MSG_ERROR("problem to get isEM for "
98  return StatusCode::FAILURE;
99  }
100  eg->setSelectionisEM(isEM, "isEM" + m_electronIsEMselectorResultNames[i]);
101  }
102 
103  size_t sizePh = m_photonIsEMselectors.size();
104 
105  for (size_t i = 0; i < sizePh; ++i) {
107  // save the bool result
108  eg->setPassSelection(static_cast<bool>(accept),
110  // save the isem
111  unsigned int isEM = ~0;
112  if (m_photonIsEMselectors[i]->execute(ctx, eg, isEM).isFailure()) {
113  ATH_MSG_ERROR("problem to get isEM for "
115  return StatusCode::FAILURE;
116  }
117  eg->setSelectionisEM(isEM, "isEM" + m_photonIsEMselectorResultNames[i]);
118  }
119 
120  size_t sizeLH = m_electronLHselectors.size();
121 
122  // negative mu means the default behaviour --> retrieve the one in xAOD
123  double mu = -99.;
124  double avg_mu = -99.;
125  if (m_UselumiBlockMuTool) { //
126  mu = m_lumiBlockMuTool->actualInteractionsPerCrossing();
127  avg_mu = m_lumiBlockMuTool->averageInteractionsPerCrossing();
128  ATH_MSG_DEBUG("REGTEST: Retrieved Mu Value : " << mu);
129  ATH_MSG_DEBUG("REGTEST: Average Mu Value : " << avg_mu);
130  }
131 
132  for (size_t i = 0; i < sizeLH; ++i) {
133  asg::AcceptData accept = m_electronLHselectors[i]->accept(ctx, eg, avg_mu);
134  // save the bool result
135  eg->setPassSelection(static_cast<bool>(accept),
137  // save the isem
138  eg->setSelectionisEM(
139  static_cast<unsigned int>(accept.getCutResultInverted()),
141 
142  // save the LHValue only once
143  if (i == 0) {
144  accLH(*eg) = static_cast<float>(
145  m_electronLHselectors[i]->calculate(ctx, eg, avg_mu));
146  }
147  }
148 
149  size_t sizeGen = m_genericIsEMselectors.size();
150  for (size_t i = 0; i < sizeGen; ++i) {
152  // save the bool result
153  eg->setPassSelection(static_cast<bool>(accept),
155  // save the isem
156  eg->setSelectionisEM(
157  static_cast<unsigned int>(accept.getCutResultInverted()),
159  }
160 
161  return StatusCode::SUCCESS;
162 }
163 
EMPIDBuilder.h
EMPIDBuilder::m_electronIsEMselectorResultNames
Gaudi::Property< std::vector< std::string > > m_electronIsEMselectorResultNames
Definition: EMPIDBuilder.h:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
EMPIDBuilder::m_lumiBlockMuTool
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
Definition: EMPIDBuilder.h:100
EMPIDBuilder::m_genericIsEMselectorResultNames
Gaudi::Property< std::vector< std::string > > m_genericIsEMselectorResultNames
Definition: EMPIDBuilder.h:80
ParticleTest.eg
eg
Definition: ParticleTest.py:29
EMPIDBuilder::m_photonIsEMselectors
ToolHandleArray< IAsgPhotonIsEMSelector > m_photonIsEMselectors
Definition: EMPIDBuilder.h:87
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
EMPIDBuilder::execute
virtual StatusCode execute(const EventContext &ctx, xAOD::Egamma *) const override final
standard execute method
Definition: EMPIDBuilder.cxx:75
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
EMPIDBuilder::m_electronLHselectorResultNames
Gaudi::Property< std::vector< std::string > > m_electronLHselectorResultNames
Definition: EMPIDBuilder.h:66
EMPIDBuilder::m_electronIsEMselectors
ToolHandleArray< IAsgElectronIsEMSelector > m_electronIsEMselectors
Handle to the selectors.
Definition: EMPIDBuilder.h:47
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Egamma.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
egammaBaseTool
Definition: egammaBaseTool.h:28
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
EMPIDBuilder::EMPIDBuilder
EMPIDBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Default constructor.
Definition: EMPIDBuilder.cxx:14
EMPIDBuilder::initialize
virtual StatusCode initialize() override final
initialize method
Definition: EMPIDBuilder.cxx:24
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EMPIDBuilder::m_electronLHselectors
ToolHandleArray< IAsgElectronLikelihoodTool > m_electronLHselectors
Definition: EMPIDBuilder.h:60
AcceptData.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EMPIDBuilder::m_UselumiBlockMuTool
Gaudi::Property< bool > m_UselumiBlockMuTool
Definition: EMPIDBuilder.h:112
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
EMPIDBuilder::m_photonIsEMselectorResultNames
Gaudi::Property< std::vector< std::string > > m_photonIsEMselectorResultNames
Definition: EMPIDBuilder.h:93
EMPIDBuilder::m_genericIsEMselectors
ToolHandleArray< IAsgSelectionTool > m_genericIsEMselectors
Definition: EMPIDBuilder.h:73
asg::AcceptData
Definition: AcceptData.h:30
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53