ATLAS Offline Software
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 
22 namespace {
23  bool isCentral(const xAOD::Jet* ijet) {
24  return fabs(ijet->eta() ) < 2.4;
25  }
26 }
27 
28 namespace HLT { namespace MET {
29  TrkMHTFex::TrkMHTFex(const std::string& name, ISvcLocator* pSvcLocator):
30  FexBase(name, pSvcLocator)
31  {}
32 
34  {
35  CHECK( m_jetKey.initialize() );
37  CHECK( m_vertexKey.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
METComponent.h
SG::contKeyFromKey
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
Definition: DecorKeyHelpers.cxx:26
HLT::MET::TrkMHTFex::initialize
virtual StatusCode initialize() override
Initialise the fex.
Definition: TrkMHTFex.cxx:33
HLT::MET::TrkMHTFex::m_maxJvtJetPt
Gaudi::Property< float > m_maxJvtJetPt
Maximum pt selection for JVT on central jets.
Definition: TrkMHTFex.h:107
HLT::MET::TrkMHTFex::m_jvtKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jvtKey
The Jvt selection name.
Definition: TrkMHTFex.h:94
HLT::MET::TrkMHTFex::m_forwardJetPt
Gaudi::Property< float > m_forwardJetPt
Pt selection on forward jets.
Definition: TrkMHTFex.h:100
HLT::MET::TrkMHTFex::TrkMHTFex
TrkMHTFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: TrkMHTFex.cxx:29
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
TrkMHTFex.h
HLT::MET::TrkMHTFex::m_trackKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackKey
Input tracks.
Definition: TrkMHTFex.h:83
HLT::MET::FexBase
Definition: FexBase.h:47
HLT::MET::TrkMHTFex::m_jetKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetKey
Input jets and jvt.
Definition: TrkMHTFex.h:80
DecorKeyHelpers.h
Some common helper functions used by decoration handles.
HLT::MET::TrkMHTFex::m_trackGAName
Gaudi::Property< std::string > m_trackGAName
The ghost-association aux element name.
Definition: TrkMHTFex.h:97
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLT::MET::TrkMHTFex::fillMET
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
Definition: TrkMHTFex.cxx:56
HLT::MET::TrkMHTFex::m_vertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
Input vertices.
Definition: TrkMHTFex.h:87
met
Definition: IMETSignificance.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HLT::MET::TrkMHTFex::m_trackSelTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelTool
The track selection tool.
Definition: TrkMHTFex.h:114
IParticleContainer.h
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
HLT::MET::METComponent::fillMETComponent
void fillMETComponent(std::size_t idx, xAOD::TrigMissingET &met) const
Fill a component of the MET with this.
Definition: METComponent.cxx:101
HLT::MET::FexBase::initializeBase
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition: FexBase.cxx:48
xAOD::Jet_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: Jet_v1.cxx:49
HLT::MET::METComponent
Helper struct to build up MET values before moving them into the EDM.
Definition: METComponent.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MET
Definition: MET.py:1
HLT::MET::TrkMHTFex::m_jvtSelection
Gaudi::Property< float > m_jvtSelection
The JVT selection.
Definition: TrkMHTFex.h:111
HLT::MET::MonGroupBuilder
Definition: MonGroupBuilder.h:45
HLT::MET::TrkMHTFex::m_tstPtCeil
Gaudi::Property< float > m_tstPtCeil
The maximum pT for tracks in the soft term.
Definition: TrkMHTFex.h:119
HLT::MET::TrkMHTFex::m_trackGA
deferred_t< SG::AuxElement::ConstAccessor< std::vector< ElementLink< xAOD::IParticleContainer > > > > m_trackGA
Definition: TrkMHTFex.h:140
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
HLT::MET::TrkMHTFex::m_tvaKey
SG::ReadHandleKey< jet::TrackVertexAssociation > m_tvaKey
The track-vertex assocation name.
Definition: TrkMHTFex.h:90
xAOD::TrigMissingET_v1
Class holding the Missing ET trigger fex results.
Definition: TrigMissingET_v1.h:32
ReadDecorHandle.h
Handle class for reading a decoration on an object.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
HLT::MET::TrkMHTFex::m_minJvtJetPt
Gaudi::Property< float > m_minJvtJetPt
Minimum pt selection for JVT on central jets.
Definition: TrkMHTFex.h:103