ATLAS Offline Software
Loading...
Searching...
No Matches
MuonScaleFactorTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5// Local include(s):
10#include <cmath>
11
12namespace{
13 constexpr double MeVtoGeV = 1.e-3;
14}
15
16namespace CP {
17 MuonScaleFactorTestAlg::MuonScaleFactorTestAlg(const std::string& name, ISvcLocator* svcLoc) :
19 // force strict checking of return codes
21 }
22
24 ATH_CHECK(m_eventInfo.initialize());
25 ATH_CHECK(m_sgKey.initialize());
26 ATH_CHECK(m_prw_Tool.retrieve());
27 ATH_CHECK(m_sel_tool.retrieve());
28
29 ATH_MSG_DEBUG("PileupReweightingTool = " << m_prw_Tool);
30 ATH_CHECK(m_effiTools.retrieve());
31 ATH_CHECK(m_comparisonTools.retrieve());
32 for (auto& tool : m_effiTools) {
33 auto sfBranch = std::make_shared<TestMuonSF::MuonSFBranches>(m_tree,tool,
34 m_comparisonTools.empty() ? "" : m_defaultRelease.value());
35
36 m_sfBranches.push_back(sfBranch);
37 m_tree.addBranch(sfBranch);
38
39 auto replicaBranch = std::make_shared<TestMuonSF::MuonReplicaBranches>(m_tree, tool,
40 m_comparisonTools.empty() ? "" : m_defaultRelease.value());
41
42 m_sfBranches.push_back(replicaBranch);
43 m_tree.addBranch(replicaBranch);
44 }
45 for (auto& tool : m_comparisonTools) {
46 auto sfBranch = std::make_shared<TestMuonSF::MuonSFBranches>(m_tree, tool, m_validRelease);
47 m_sfBranches.push_back(sfBranch);
48 m_tree.addBranch(sfBranch);
49
50 auto replicaBranch = std::make_shared<TestMuonSF::MuonReplicaBranches>(m_tree,tool, m_validRelease);
51 m_sfBranches.push_back(replicaBranch);
52 m_tree.addBranch(replicaBranch);
53 }
54 m_tree.addBranch(std::make_shared<MuonVal::EventInfoBranch>(m_tree, 0));
55 ATH_CHECK(m_tree.init(this));
56 return StatusCode::SUCCESS;
57 }
59 ATH_CHECK(m_tree.write());
60 return StatusCode::SUCCESS;
61 }
62
64 const EventContext& ctx{Gaudi::Hive::currentContext()};
65 // Retrieve the muons:
67 // Retrieve the EventInfo:
69
70 ATH_MSG_DEBUG("Start to run over event "<<ei->eventNumber()<<" in run" <<ei->runNumber());
71
72 //Apply the prwTool first before calling the efficiency correction methods
73 ATH_CHECK(m_prw_Tool->apply(*ei));
74
75 for (const xAOD::Muon* mu : *muons) {
76 if (mu->pt() < m_pt_cut || (m_eta_cut > 0 && std::abs(mu->eta()) >= m_eta_cut)) continue;
77 // reject all loose muons
78 if (m_sel_tool->getQuality(*mu) > m_muon_quality) continue;
79
80 m_muonPt = mu->pt() * MeVtoGeV;
81 m_muonEta = mu->eta();
82 m_muonPhi = mu->phi();
83 m_muonQ = mu->charge();
84 for (auto& br : m_sfBranches) {
85 br->setMuon(*mu);
86 }
87 ATH_CHECK(m_tree.fill(ctx));
88 }
89 ATH_MSG_DEBUG("Done with processing the event");
90 // Return gracefully:
91 return StatusCode::SUCCESS;
92 }
93
94} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
AthHistogramAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
static void enableFailure() noexcept
MuonVal::ScalarBranch< float > & m_muonPt
ToolHandle< IPileupReweightingTool > m_prw_Tool
Scale factor tool.
ToolHandleArray< IMuonEfficiencyScaleFactors > m_effiTools
StatusCode finalize() override
Function finalizing the algortihm.
SG::ReadHandleKey< xAOD::MuonContainer > m_sgKey
muon container
Gaudi::Property< std::string > m_validRelease
ToolHandle< IMuonSelectionTool > m_sel_tool
MuonVal::MuonTesterTree m_tree
std::vector< std::shared_ptr< TestMuonSF::MuonEffiBranch > > m_sfBranches
Gaudi::Property< float > m_eta_cut
MuonVal::ScalarBranch< float > & m_muonPhi
ToolHandleArray< IMuonEfficiencyScaleFactors > m_comparisonTools
StatusCode execute() override
Function executing the algorithm.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Gaudi::Property< std::string > m_defaultRelease
MuonScaleFactorTestAlg(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Gaudi::Property< int > m_muon_quality
Gaudi::Property< float > m_pt_cut
MuonVal::ScalarBranch< int > & m_muonQ
StatusCode initialize() override
Function initialising the algorithm.
MuonVal::ScalarBranch< float > & m_muonEta
Select isolated Photons, Electrons and Muons.
constexpr float MeVtoGeV
Muon_v1 Muon
Reference the current persistent version: