ATLAS Offline Software
MuonScaleFactorTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // Local include(s):
7 #include "StoreGate/ReadHandle.h"
10 #include <cmath>
11 
12 namespace{
13  constexpr double MeVtoGeV = 1.e-3;
14 }
15 
16 namespace CP {
17  MuonScaleFactorTestAlg::MuonScaleFactorTestAlg(const std::string& name, ISvcLocator* svcLoc) :
18  AthHistogramAlgorithm(name, svcLoc) {
19  // force strict checking of return codes
21  }
22 
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);
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);
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  }
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
CP::MuonScaleFactorTestAlg::m_validRelease
Gaudi::Property< std::string > m_validRelease
Definition: MuonScaleFactorTestAlg.h:57
MuonScaleFactorTestAlg.h
CP::MuonScaleFactorTestAlg::m_sgKey
SG::ReadHandleKey< xAOD::MuonContainer > m_sgKey
muon container
Definition: MuonScaleFactorTestAlg.h:44
CP::MuonScaleFactorTestAlg::execute
StatusCode execute() override
Function executing the algorithm.
Definition: MuonScaleFactorTestAlg.cxx:63
MuonVal::MuonTesterTree::init
StatusCode init(OWNER *instance)
Initialize method.
CP::MuonScaleFactorTestAlg::m_muonPt
MuonVal::ScalarBranch< float > & m_muonPt
Definition: MuonScaleFactorTestAlg.h:65
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::CorrectionCode::enableFailure
static void enableFailure() noexcept
Definition: CorrectionCode.h:64
CP::MeVtoGeV
constexpr float MeVtoGeV
Definition: IsolationCloseByCorrectionTool.cxx:33
CP::MuonScaleFactorTestAlg::m_tree
MuonVal::MuonTesterTree m_tree
Definition: MuonScaleFactorTestAlg.h:63
EventInfoBranch.h
CP::MuonScaleFactorTestAlg::initialize
StatusCode initialize() override
Function initialising the algorithm.
Definition: MuonScaleFactorTestAlg.cxx:23
CP::MuonScaleFactorTestAlg::m_comparisonTools
ToolHandleArray< IMuonEfficiencyScaleFactors > m_comparisonTools
Definition: MuonScaleFactorTestAlg.h:47
CP::MuonScaleFactorTestAlg::m_muon_quality
Gaudi::Property< int > m_muon_quality
Definition: MuonScaleFactorTestAlg.h:61
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::MuonScaleFactorTestAlg::MuonScaleFactorTestAlg
MuonScaleFactorTestAlg(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: MuonScaleFactorTestAlg.cxx:17
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::MuonScaleFactorTestAlg::m_muonEta
MuonVal::ScalarBranch< float > & m_muonEta
Definition: MuonScaleFactorTestAlg.h:66
CP::MuonScaleFactorTestAlg::m_eta_cut
Gaudi::Property< float > m_eta_cut
Definition: MuonScaleFactorTestAlg.h:60
CP::MuonScaleFactorTestAlg::m_defaultRelease
Gaudi::Property< std::string > m_defaultRelease
Definition: MuonScaleFactorTestAlg.h:56
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
AthHistogramAlgorithm
Definition: AthHistogramAlgorithm.h:32
SystematicsTool.h
CP::MuonScaleFactorTestAlg::finalize
StatusCode finalize() override
Function finalizing the algortihm.
Definition: MuonScaleFactorTestAlg.cxx:58
CP::MuonScaleFactorTestAlg::m_prw_Tool
ToolHandle< IPileupReweightingTool > m_prw_Tool
Scale factor tool.
Definition: MuonScaleFactorTestAlg.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
CP::MuonScaleFactorTestAlg::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: MuonScaleFactorTestAlg.h:42
CP::MuonScaleFactorTestAlg::m_effiTools
ToolHandleArray< IMuonEfficiencyScaleFactors > m_effiTools
Definition: MuonScaleFactorTestAlg.h:46
CP::MuonScaleFactorTestAlg::m_sfBranches
std::vector< std::shared_ptr< TestMuonSF::MuonEffiBranch > > m_sfBranches
Definition: MuonScaleFactorTestAlg.h:70
MuonVal::MuonTesterTree::fill
bool fill(const EventContext &ctx)
Fills the tree per call.
Definition: MuonTesterTree.cxx:89
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
CP::MuonScaleFactorTestAlg::m_pt_cut
Gaudi::Property< float > m_pt_cut
Definition: MuonScaleFactorTestAlg.h:59
CP::MuonScaleFactorTestAlg::m_sel_tool
ToolHandle< IMuonSelectionTool > m_sel_tool
Definition: MuonScaleFactorTestAlg.h:51
ReadHandle.h
Handle class for reading from StoreGate.
CP::MuonScaleFactorTestAlg::m_muonQ
MuonVal::ScalarBranch< int > & m_muonQ
Definition: MuonScaleFactorTestAlg.h:68
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::MuonScaleFactorTestAlg::m_muonPhi
MuonVal::ScalarBranch< float > & m_muonPhi
Definition: MuonScaleFactorTestAlg.h:67
MuonVal::MuonTesterTree::addBranch
bool addBranch(std::shared_ptr< IMuonTesterBranch > branch)
Branch is added to the tree without transferring the ownership.
Definition: MuonTesterTree.cxx:61
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355