ATLAS Offline Software
Loading...
Searching...
No Matches
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"
11
13namespace
14{
15 const static SG::AuxElement::ConstAccessor<char> accPVMatched("matchedToPV");
16}
17
18namespace 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 }
50 return StatusCode::SUCCESS;
51 }
52
53 StatusCode PFOPrepAlg::execute(const EventContext &ctx) const
54 {
55 auto charged = SG::makeHandle(m_inputChargedKey, ctx);
56 if (!charged.isValid())
57 {
58 ATH_MSG_ERROR("Failed to retrieve " << m_inputChargedKey);
59 return StatusCode::FAILURE;
60 }
61 auto neutral = SG::makeHandle(m_inputNeutralKey, ctx);
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
#define ATH_MSG_ERROR(x)
DataVector adapter that acts like it holds const pointers.
#define CHECK(...)
Evaluate an expression and check for errors.
Some common helper functions used by decoration handles.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::VertexContainer > m_inputVertexKey
The input vertex container.
Definition PFOPrepAlg.h:67
bool m_manualTVA
Whether to perform track -> vertex matching manually.
Definition PFOPrepAlg.h:95
virtual StatusCode initialize() override
SG::WriteHandleKey< xAOD::PFOContainer > m_outputKey
The output combined container.
Definition PFOPrepAlg.h:71
SG::WriteDecorHandleKey< xAOD::PFOContainer > m_outputCategoryKey
The output classification.
Definition PFOPrepAlg.h:74
PFOPrepAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandle< CP::ITrackVertexAssociationTool > m_tvaTool
Track -> vertex association.
Definition PFOPrepAlg.h:77
SG::ReadHandleKey< xAOD::PFOContainer > m_inputChargedKey
The input charged container.
Definition PFOPrepAlg.h:64
SG::ReadHandleKey< xAOD::PFOContainer > m_inputNeutralKey
The input neutral container.
Definition PFOPrepAlg.h:61
deferred_t< SG::AuxElement::Decorator< int > > m_decCategory
Definition PFOPrepAlg.h:98
Gaudi::Property< bool > m_useCompatible
Choose between the unique (many-to-one) track->vertex association and just checking compatibility wit...
Definition PFOPrepAlg.h:89
virtual StatusCode execute(const EventContext &context) const override
Run the algorithm.
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelTool
Track selection tool.
Definition PFOPrepAlg.h:82
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
VxType::VertexType vertexType() const
The type of the vertex.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
std::string decorKeyFromKey(const std::string &key, const std::string &deflt)
Extract the decoration part of key.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ PriVtx
Primary vertex.
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.