ATLAS Offline Software
PFOPrepAlg.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 "PFOPrepAlg.h"
6 #include "StoreGate/ReadHandle.h"
11 
13 namespace
14 {
15  const static SG::AuxElement::ConstAccessor<char> accPVMatched("matchedToPV");
16 }
17 
18 namespace HLT
19 {
20  namespace MET
21  {
22  PFOPrepAlg::PFOPrepAlg(const std::string &name, ISvcLocator *pSvcLocator)
23  : AthReentrantAlgorithm(name, pSvcLocator)
24  {
25  }
26 
28  {
29  m_manualTVA = !m_tvaTool.empty();
30  CHECK(m_inputNeutralKey.initialize());
31  CHECK(m_inputChargedKey.initialize());
32  CHECK(m_outputKey.initialize());
33  if (m_outputCategoryKey.key().find(".") == std::string::npos)
35  else if (SG::contKeyFromKey(m_outputCategoryKey.key()) != m_outputKey.key())
36  {
37  ATH_MSG_ERROR("Category key does not match output container key!");
38  return StatusCode::FAILURE;
39  }
40  CHECK(m_outputCategoryKey.initialize());
42 
43  if (m_manualTVA)
44  {
45  CHECK(m_tvaTool.retrieve());
46  if (!m_trackSelTool.empty())
47  CHECK(m_trackSelTool.retrieve());
48  }
49  CHECK(m_inputVertexKey.initialize(m_manualTVA));
50  return StatusCode::SUCCESS;
51  }
52 
53  StatusCode PFOPrepAlg::execute(const EventContext &ctx) const
54  {
56  if (!charged.isValid())
57  {
58  ATH_MSG_ERROR("Failed to retrieve " << m_inputChargedKey);
59  return StatusCode::FAILURE;
60  }
62  if (!neutral.isValid())
63  {
64  ATH_MSG_ERROR("Failed to retrieve " << m_inputNeutralKey);
65  return StatusCode::FAILURE;
66  }
67  const xAOD::Vertex *priVtx = nullptr;
68  std::vector<const xAOD::Vertex *> vertices;
69  if (m_manualTVA)
70  {
71  auto vertexHandle = SG::makeHandle(m_inputVertexKey, ctx);
72  if (!vertexHandle.isValid())
73  {
74  ATH_MSG_ERROR("Failed to retrieve " << m_inputVertexKey);
75  return StatusCode::FAILURE;
76  }
77  // Find the primary vertex and build up the vector for the TVA tool
78  vertices.reserve(vertexHandle->size());
79  for (const xAOD::Vertex *ivtx : *vertexHandle)
80  {
81  if (!priVtx && ivtx->vertexType() == xAOD::VxType::PriVtx)
82  priVtx = ivtx;
83  vertices.push_back(ivtx);
84  }
85  }
86  auto outputHandle = SG::makeHandle(m_outputKey, ctx);
87  auto &decCategory = *m_decCategory;
88 
89  auto combined = std::make_unique<ConstDataVector<xAOD::PFOContainer>>(SG::VIEW_ELEMENTS);
90  combined->reserve(charged->size() + neutral->size());
91 
92  for (const xAOD::PFO *ipfo : *charged)
93  {
94  combined->push_back(ipfo);
95  if (m_manualTVA)
96  {
97  if (!priVtx)
98  // If we could not identify a primary vertex, classify as neutral
99  // Note that this means in order to distinguish cPFOs from nPFOs the 'isCharged'
100  // function should still be used
101  decCategory(*ipfo) = PUClassification::NeutralForward;
102  else
103  {
104  const xAOD::TrackParticle *itrk = ipfo->track(0);
105  if (itrk && (m_trackSelTool.empty() || m_trackSelTool->accept(*itrk)))
106  {
107  bool isPVMatched;
108  if (m_useCompatible)
109  isPVMatched = m_tvaTool->isCompatible(*itrk, *priVtx);
110  else
111  isPVMatched = m_tvaTool->getUniqueMatchVertex(*itrk, vertices) == priVtx;
112  if (isPVMatched)
113  decCategory(*ipfo) = PUClassification::ChargedHS;
114  else
115  decCategory(*ipfo) = PUClassification::ChargedPU;
116  }
117  }
118  }
119  else
120  {
121  if (accPVMatched(*ipfo))
122  decCategory(*ipfo) = PUClassification::ChargedHS;
123  else
124  decCategory(*ipfo) = PUClassification::ChargedPU;
125  }
126  }
127  for (const xAOD::PFO *ipfo : *neutral)
128  {
129  combined->push_back(ipfo);
130  decCategory(*ipfo) = PUClassification::NeutralForward;
131  }
132 
133  CHECK(outputHandle.put(ctx, std::move(combined)) != nullptr);
134  return StatusCode::SUCCESS;
135  }
136  } // namespace MET
137 } // namespace HLT
SG::contKeyFromKey
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
Definition: DecorKeyHelpers.cxx:26
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::decorKeyFromKey
std::string decorKeyFromKey(const std::string &key)
Extract the decoration part of key.
Definition: DecorKeyHelpers.cxx:41
HLT::MET::PFOPrepAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Run the algorithm.
Definition: PFOPrepAlg.cxx:53
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
HLT::MET::PFOPrepAlg::m_tvaTool
ToolHandle< CP::ITrackVertexAssociationTool > m_tvaTool
Track -> vertex association.
Definition: PFOPrepAlg.h:108
HLT::MET::PFOPrepAlg::m_outputKey
SG::WriteHandleKey< xAOD::PFOContainer > m_outputKey
The output combined container.
Definition: PFOPrepAlg.h:102
HLT::MET::PFOPrepAlg::m_useCompatible
Gaudi::Property< bool > m_useCompatible
Choose between the unique (many-to-one) track->vertex association and just checking compatibility wit...
Definition: PFOPrepAlg.h:120
DecorKeyHelpers.h
Some common helper functions used by decoration handles.
xAOD::Vertex_v1::vertexType
VxType::VertexType vertexType() const
The type of the vertex.
HLT::MET::PFOPrepAlg::m_inputChargedKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inputChargedKey
The input charged container.
Definition: PFOPrepAlg.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PFOPrepAlg.h
HLT::MET::PFOPrepAlg::initialize
virtual StatusCode initialize() override
Definition: PFOPrepAlg.cxx:27
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HLT::MET::PUClassification::ChargedHS
@ ChargedHS
Definition: PUClassification.h:20
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
TCS::MET
@ MET
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:16
HLT::MET::PFOPrepAlg::m_trackSelTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelTool
Track selection tool.
Definition: PFOPrepAlg.h:113
HLT::MET::PFOPrepAlg::m_manualTVA
bool m_manualTVA
Whether to perform track -> vertex matching manually.
Definition: PFOPrepAlg.h:126
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::MET::PFOPrepAlg::m_inputNeutralKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inputNeutralKey
The input neutral container.
Definition: PFOPrepAlg.h:92
HLT::MET::PFOPrepAlg::m_inputVertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_inputVertexKey
The input vertex container.
Definition: PFOPrepAlg.h:98
CP::neutral
@ neutral
Definition: Reconstruction/PFlow/PFlowUtils/PFlowUtils/PFODefs.h:11
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
HLT::MET::PFOPrepAlg::PFOPrepAlg
PFOPrepAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: PFOPrepAlg.cxx:22
HLT::MET::PUClassification::ChargedPU
@ ChargedPU
Definition: PUClassification.h:19
HLT::MET::PFOPrepAlg::m_outputCategoryKey
SG::WriteDecorHandleKey< xAOD::PFOContainer > m_outputCategoryKey
The output classification.
Definition: PFOPrepAlg.h:105
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
PUClassification.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::TrackParticle_v1::track
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
Definition: TrackParticle_v1.cxx:805
ReadHandle.h
Handle class for reading from StoreGate.
HLT::MET::PFOPrepAlg::m_decCategory
deferred_t< SG::AuxElement::Decorator< int > > m_decCategory
Definition: PFOPrepAlg.h:129
CP::charged
@ charged
Definition: Reconstruction/PFlow/PFlowUtils/PFlowUtils/PFODefs.h:11
HLT::MET::PUClassification::NeutralForward
@ NeutralForward
Definition: PUClassification.h:18