ATLAS Offline Software
Loading...
Searching...
No Matches
TrkMHTFex.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4
5/******************************************************************************
6 * @package Trigger/TrigAlgorithms/TrigEFMissingET
7 * @file TrkMHTFex.cxx
8 *
9 * Implementation of trkmht fex class
10 * @author Jon Burr
11 *****************************************************************************/
12
13#include "TrkMHTFex.h"
17#include "AthLinks/ElementLink.h"
19#include <unordered_set>
20#include <numeric>
21
22namespace {
23 bool isCentral(const xAOD::Jet* ijet) {
24 return fabs(ijet->eta() ) < 2.4;
25 }
26}
27
28namespace HLT { namespace MET {
29 TrkMHTFex::TrkMHTFex(const std::string& name, ISvcLocator* pSvcLocator):
30 FexBase(name, pSvcLocator)
31 {}
32
34 {
35 CHECK( m_jetKey.initialize() );
36 CHECK( m_trackKey.initialize() );
37 CHECK( m_vertexKey.initialize() );
38 CHECK( m_tvaKey.initialize() );
39 CHECK( m_trackSelTool.retrieve() );
40
41 // Update the decor keys if necessary
42 if (m_jvtKey.key().find(".") == std::string::npos)
43 m_jvtKey = m_jetKey.key() + "." + m_jvtKey.key();
44 else if (SG::contKeyFromKey(m_jvtKey.key()) != m_jetKey.key())
45 {
46 ATH_MSG_ERROR("JVT container key does not match jet key!");
47 return StatusCode::FAILURE;
48 }
49 CHECK(m_jvtKey.initialize());
50 m_trackGA.emplace(m_trackGAName);
51
52 return initializeBase(
53 {"JETB1", "JETB2", "JETE1", "JETE2", "TrackSoftTerm"});
54 }
55
58 const EventContext& context,
59 MonGroupBuilder&) const
60 {
61 // Retrieve the inputs
62 auto jets = SG::makeHandle(m_jetKey, context);
63 if (!jets.isValid())
64 {
65 ATH_MSG_ERROR("Failed to retrieve " << m_jetKey);
66 return StatusCode::FAILURE;
67 }
68 auto tracks = SG::makeHandle(m_trackKey, context);
69 if (!tracks.isValid())
70 {
71 ATH_MSG_ERROR("Failed to retrieve " << m_trackKey);
72 return StatusCode::FAILURE;
73 }
74 auto vertices = SG::makeHandle(m_vertexKey, context);
75 if (!vertices.isValid())
76 {
77 ATH_MSG_ERROR("Failed to retrieve " << m_vertexKey);
78 return StatusCode::FAILURE;
79 }
80 auto tva = SG::makeHandle(m_tvaKey, context);
81 auto jvtAcc = SG::makeHandle<float>(m_jvtKey, context);
82 auto& trackLinksAcc = *m_trackGA;
83
84 // Work out which is the primary vertex
85 // I do not know if there is a way to see which vertex was counted as
86 // primary by the JVT calculation but I see no reason to suspect that it
87 // would be anything other than the one found by this method
88 const xAOD::Vertex* priVtx = nullptr;
89 for (const xAOD::Vertex* vtx : *vertices)
90 if (vtx->vertexType() == xAOD::VxType::PriVtx) {
91 priVtx = vtx;
92 break;
93 }
94
95 // Prepare the output values
96 std::array<METComponent, 4> mhtSums;
97 METComponent tstSum;
98
99 // If no primary vertex is identified, the algorithm will return 0
100 if (priVtx) {
101 // Prepare a list of primary vertex tracks
102 std::vector<const xAOD::TrackParticle*> tstTracks;
103 tstTracks.reserve(tracks->size() );
104 for (const xAOD::TrackParticle* itrk : *tracks)
105 if (tva->associatedVertex(itrk) == priVtx &&
106 itrk->pt() < m_tstPtCeil &&
107 m_trackSelTool->accept(*itrk, priVtx) )
108 tstTracks.push_back(itrk);
109 // Keep indices of tracks associated to hard-scatter jets
110 std::unordered_set<std::size_t> jetTrackIndices;
111 // Iterate over the jets
112 for (const xAOD::Jet* ijet : *jets) {
113 if (isCentral(ijet) ) {
114 if (ijet->pt() < m_minJvtJetPt)
115 // Skip central jets below the JVT pT threshold
116 continue;
117 if (ijet->pt() < m_maxJvtJetPt && jvtAcc(*ijet) < m_jvtSelection)
118 // Skip central jets below the maximum JVT pT threshold and with JVT
119 // below threshold
120 continue;
121 } // end if isCentral(ijet)
122 else {
123 if (ijet->pt() < m_forwardJetPt)
124 // Skip forward jets below the forward jet pT threshold
125 continue;
126 }
127 // The index of the mht METComponent
128 std::size_t componentIdx = 0;
129 if (ijet->eta() < 0)
130 ++componentIdx;
131 if (!isCentral(ijet) )
132 componentIdx += 2;
133 // Add the jet into the correct component
134 mhtSums.at(componentIdx) += ijet->p4();
135 // Iterate over the ghost-associated tracks
136 for (const auto& link : trackLinksAcc(*ijet) ) {
137 if (link.getDataPtr() != tracks.ptr() ) {
138 ATH_MSG_ERROR("Tracks linked with key '" << m_trackGAName
139 << "' do not match tracks retrieved with '"
140 << m_trackKey << "'!");
141 return StatusCode::FAILURE;
142 }
143 jetTrackIndices.insert(link.index() );
144 }
145 }
146 // Build up the track soft term
147 for (const xAOD::TrackParticle* itrk : tstTracks)
148 if (jetTrackIndices.count(itrk->index() ) == 0)
149 // Only include tracks that weren't associated to a hard-scatter jet
150 tstSum += itrk->p4();
151 } //> end if priVtx
152 // Save the sum over components
153 std::accumulate(mhtSums.begin(), mhtSums.end(), tstSum).fillMET(met);
154 // Save each component
155 for (std::size_t ii = 0; ii < 4; ++ii)
156 mhtSums.at(ii).fillMETComponent(ii, met);
157 // Save the tst
158 tstSum.fillMETComponent(4, met);
159
160 // Debugging information
161 ATH_MSG_DEBUG("Jets: "
162 << std::accumulate(mhtSums.begin(), mhtSums.end(), METComponent{}) );
163
164 return StatusCode::SUCCESS;
165 }
166
167} } //> end namespace HLT::MET
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Some common helper functions used by decoration handles.
Handle class for reading a decoration on an object.
FexBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition FexBase.cxx:43
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition FexBase.cxx:48
Helper struct to build up MET values before moving them into the EDM.
void fillMETComponent(std::size_t idx, xAOD::TrigMissingET &met) const
Fill a component of the MET with this.
void fillMET(xAOD::TrigMissingET &met) const
Fill the main component of the MET with this.
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelTool
The track selection tool.
Definition TrkMHTFex.h:87
TrkMHTFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition TrkMHTFex.cxx:29
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
Definition TrkMHTFex.cxx:56
Gaudi::Property< float > m_tstPtCeil
The maximum pT for tracks in the soft term.
Definition TrkMHTFex.h:92
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jvtKey
The Jvt selection name.
Definition TrkMHTFex.h:67
SG::ReadHandleKey< jet::TrackVertexAssociation > m_tvaKey
The track-vertex assocation name.
Definition TrkMHTFex.h:63
SG::ReadHandleKey< xAOD::JetContainer > m_jetKey
Input jets and jvt.
Definition TrkMHTFex.h:53
deferred_t< SG::AuxElement::ConstAccessor< std::vector< ElementLink< xAOD::IParticleContainer > > > > m_trackGA
Definition TrkMHTFex.h:113
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackKey
Input tracks.
Definition TrkMHTFex.h:56
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
Input vertices.
Definition TrkMHTFex.h:60
virtual StatusCode initialize() override
Initialise the fex.
Definition TrkMHTFex.cxx:33
Gaudi::Property< std::string > m_trackGAName
The ghost-association aux element name.
Definition TrkMHTFex.h:70
Gaudi::Property< float > m_minJvtJetPt
Minimum pt selection for JVT on central jets.
Definition TrkMHTFex.h:76
Gaudi::Property< float > m_forwardJetPt
Pt selection on forward jets.
Definition TrkMHTFex.h:73
Gaudi::Property< float > m_maxJvtJetPt
Maximum pt selection for JVT on central jets.
Definition TrkMHTFex.h:80
Gaudi::Property< float > m_jvtSelection
The JVT selection.
Definition TrkMHTFex.h:84
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition Jet_v1.cxx:49
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.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrigMissingET_v1 TrigMissingET
Define the most recent version of the TrigMissingET class.