ATLAS Offline Software
MuonJetDrTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Finds the nearest jet and adds its info to the muon.
7 
10 // Constructor
11 DerivationFramework::MuonJetDrTool::MuonJetDrTool(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t, n, p) {
12  declareInterface<DerivationFramework::IAugmentationTool>(this);
13 }
15  ATH_CHECK(m_muonSGKey.initialize());
16  ATH_CHECK(m_jetSGKey.initialize());
17  m_jetDR_SGKey = m_muonSGKey.key() + "." + m_jetDR_SGKey.key();
18  ATH_CHECK(m_jetDR_SGKey.initialize());
19  return StatusCode::SUCCESS;
20 }
22  const EventContext& ctx = Gaudi::Hive::currentContext();
23 
24  // Retrieve main muonicle collection
25  SG::ReadHandle<xAOD::MuonContainer> muons{m_muonSGKey, ctx};
26  if (!muons.isValid()) {
27  ATH_MSG_FATAL("Failed to retrive container " << m_muonSGKey.fullKey());
28  return StatusCode::FAILURE;
29  }
31  if (!jets.isValid()) {
32  ATH_MSG_FATAL("Failed to retrieve " << m_jetSGKey.fullKey());
33  return StatusCode::FAILURE;
34  }
35  SG::WriteDecorHandle<xAOD::MuonContainer, float> decorator_jetdR{m_jetDR_SGKey, ctx};
36 
37  for (auto muon : *muons) {
38  double new_jetdR = FLT_MAX;
39  bool found{false};
40  for (auto jet : *jets) {
41  if (jet->pt() <= m_jetMinPt) continue;
42  new_jetdR = std::min(xAOD::P4Helpers::deltaR(jet, muon), new_jetdR);
43  found = true;
44  }
45  decorator_jetdR(*muon) = found ? new_jetdR : -1;
46  }
47  return StatusCode::SUCCESS;
48 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
DerivationFramework::MuonJetDrTool::initialize
virtual StatusCode initialize() override
Definition: MuonJetDrTool.cxx:14
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DerivationFramework::MuonJetDrTool::MuonJetDrTool
MuonJetDrTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: MuonJetDrTool.cxx:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::MuonJetDrTool::addBranches
virtual StatusCode addBranches() const override
Pass the thinning service
Definition: MuonJetDrTool.cxx:21
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
min
#define min(a, b)
Definition: cfImp.cxx:40
MuonJetDrTool.h
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
AthAlgTool
Definition: AthAlgTool.h:26