ATLAS Offline Software
Loading...
Searching...
No Matches
BJetCalibrationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
14//
15// method implementations
16//
17
18namespace CP
19{
20
21 StatusCode BJetCalibrationAlg ::
22 initialize ()
23 {
30
32
33 if(!m_muonSelectionTool.empty()){
34 ANA_CHECK (m_muonSelectionTool.retrieve());
35 if(!m_muonPreselection.empty()){
36 ATH_MSG_ERROR ("muonSelectionTool and muonPreselection should not be configured simultaneously");
37 return StatusCode::FAILURE;
38 }
39 }
40
41 ANA_CHECK (m_muonInJetTool.retrieve());
42 if(!m_bJetTool.empty()) ANA_CHECK (m_bJetTool.retrieve());
43
44 ANA_CHECK (m_systematicsList.initialize());
45 return StatusCode::SUCCESS;
46 }
47
48 StatusCode BJetCalibrationAlg ::
49 execute (const EventContext& ctx)
50 {
51 for (const auto& sys : m_systematicsList.systematicsVector())
52 {
53 xAOD::JetContainer *jets = nullptr;
54 ANA_CHECK (m_jetHandle.getCopy (jets, sys, ctx));
55
56 const xAOD::MuonContainer *muons = nullptr;
57 ANA_CHECK (m_muonHandle.retrieve (muons, sys, ctx));
58
59 std::vector<const xAOD::Muon*> muons_for_correction;
60 muons_for_correction.reserve(muons->size());
61 for(const xAOD::Muon* muon : *muons)
62 {
63 if (// For analysis frameworks
64 (m_muonSelectionTool.empty() && m_muonPreselection.getBool(*muon, sys)) ||
65 // For other frameworks
66 (!m_muonSelectionTool.empty() && m_muonSelectionTool->accept(*muon)))
67 {
68 muons_for_correction.emplace_back(muon);
69 }
70 }
71
72 for (xAOD::Jet* jet : *jets)
73 {
74 jet->setJetP4("NoBJetCalibMomentum", jet->jetP4());
75 jet->setJetP4("MuonCorrMomentum", jet->jetP4());
76 if (!m_bJetTool.empty())
77 {
78 jet->setJetP4("BJetCalibMomentum", jet->jetP4());
79 }
80
81 int nmuons = 0;
82 if (m_jetPreselection.getBool(*jet, sys))
83 {
84 ANA_CHECK (m_muonInJetTool->applyMuonInJetCorrection(*jet, muons_for_correction, nmuons));
85 jet->setJetP4("MuonCorrMomentum", jet->jetP4());
86 if (!m_bJetTool.empty())
87 {
88 ANA_CHECK (m_bJetTool->applyBJetCorrection(*jet, nmuons>0));
89 jet->setJetP4("BJetCalibMomentum", jet->jetP4());
90 }
91
93 {
94 // Reset the jet 4-vector to the original one
95 jet->setJetP4(jet->jetP4("NoBJetCalibMomentum"));
96 }
97 }
98
99 m_nmuons.set(*jet, nmuons, sys);
100 }
101 }
102
103 return StatusCode::SUCCESS;
104 }
105}
#define ATH_MSG_ERROR(x)
#define ANA_CHECK(EXP)
check whether the given expression was successful
ToolHandle< IBJetCorrectionTool > m_bJetTool
the b-jet pt correction tool
SysReadSelectionHandle m_jetPreselection
SysCopyHandle< xAOD::JetContainer > m_jetHandle
SysReadSelectionHandle m_muonPreselection
ToolHandle< CP::IMuonSelectionTool > m_muonSelectionTool
the muon-in-jet selection tool, unused if muonPreselection set
Gaudi::Property< bool > m_onlyDecorate
SysReadHandle< xAOD::MuonContainer > m_muonHandle
ToolHandle< IMuonInJetCorrectionTool > m_muonInJetTool
the muon-in-jet correction tool
SysWriteDecorHandle< int > m_nmuons
size_type size() const noexcept
Returns the number of elements in the collection.
Select isolated Photons, Electrons and Muons.
Jet_v1 Jet
Definition of the current "jet version".
Muon_v1 Muon
Reference the current persistent version:
JetContainer_v1 JetContainer
Definition of the current "jet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".