ATLAS Offline Software
Loading...
Searching...
No Matches
JvtEfficiencyToolBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <TFile.h>
10
11namespace {
12 bool getBin(const TAxis &axis, float value, int &bin) {
13 bin = axis.FindBin(value);
14 return (bin != 0 && bin != axis.GetNbins()+1);
15 }
16 bool getBinContentAndError(const TH2 &h, float x, float y, float &content, float &error) {
17 int xBin{}, yBin{};
18 if (!getBin(*h.GetXaxis(), x, xBin) || !getBin(*h.GetYaxis(), y, yBin)) {
19
20 content = -1;
21 error = -1;
22 return false;
23 }
24 content = h.GetBinContent(xBin, yBin);
25 error = h.GetBinError(xBin, yBin);
26 return true;
27 }
28} // namespace
29
30namespace CP {
34 ATH_MSG_WARNING("No truth requirement will be performed, which is not recommended.");
35 m_accIsHS.emplace(m_truthHSLabel.key());
36 if (m_jetContainer.empty()) {
37 ATH_MSG_WARNING("No JetContainer set. This behaviour is deprecated");
38 ATH_CHECK(m_truthHSLabel.initialize(false));
39 }
40 else {
43 }
44 return StatusCode::SUCCESS;
45 }
46
49 if (!isInRange(jet)) {
50 sf = -1;
52 }
54 if (!m_accIsHS->isAvailable(jet)) {
55 ATH_MSG_ERROR("Truth tagging required but not available");
57 }
58 if (!(*m_accIsHS)(jet)) {
59 sf = 1;
60 return CorrectionCode::Ok;
61 }
62 }
63 return getEffImpl(jet.pt(), m_etaAcc(jet), sf);
64 }
65
68 if (!isInRange(jet)) {
69 sf = -1;
71 }
73 if (!m_accIsHS->isAvailable(jet)) {
74 ATH_MSG_ERROR("Truth tagging required but not available");
76 }
77 if (!(*m_accIsHS)(jet)) {
78 sf = 1;
79 return CorrectionCode::Ok;
80 }
81 }
82 return getIneffImpl(jet.pt(), m_etaAcc(jet), sf);
83 }
84
85 StatusCode JvtEfficiencyToolBase::initHists(const std::string &file, const std::string &wp) {
86 if (file.empty()) {
87 m_useDummySFs = true;
88 ATH_MSG_INFO("No SF file provided, running with dummy SFs of 1 +/- " << m_dummySFError);
89 return StatusCode::SUCCESS;
90 }
91 std::string resolved = PathResolverFindCalibFile(file);
92 if (resolved.empty()) {
93 ATH_MSG_ERROR("Could not locate file " << file);
94 return StatusCode::FAILURE;
95 }
96 std::unique_ptr<TFile> fIn(TFile::Open(resolved.c_str(), "READ"));
97 if (!fIn) {
98 ATH_MSG_ERROR("Failed to open file " << resolved);
99 return StatusCode::FAILURE;
100 }
101
102 std::string jvtName = "Jvt" + wp;
103 m_jvtHist.reset(fIn->Get<TH2>(jvtName.c_str()));
104 if (!m_jvtHist) {
106 "Could not open SF histogram "
107 << jvtName << ". Please check the supported working points.");
108 return StatusCode::FAILURE;
109 }
110 m_jvtHist->SetDirectory(nullptr);
111 std::string effName = "Eff" + wp;
112 m_effHist.reset(fIn->Get<TH2>(effName.c_str()));
113 if (!m_effHist) {
115 "Could not open efficiency histogram "
116 << jvtName << ". Please check the supported working points.");
117 return StatusCode::FAILURE;
118 }
119 m_effHist->SetDirectory(nullptr);
120
121 return StatusCode::SUCCESS;
122 }
123
124 CorrectionCode JvtEfficiencyToolBase::getEffImpl(float x, float y, float &sf) const {
125 float baseFactor = 1;
126 float errorTerm = m_dummySFError;
127 if (!m_useDummySFs) {
128 if (!getBinContentAndError(*m_jvtHist, x, y, baseFactor, errorTerm)) {
129 sf = -1;
131 }
132 }
133 sf = baseFactor + m_appliedSysSigma * errorTerm;
134 return CorrectionCode::Ok;
135 }
136
137 CorrectionCode JvtEfficiencyToolBase::getIneffImpl(float x, float y, float &sf) const {
138 if (m_useDummySFs) {
140 return CorrectionCode::Ok;
141 }
142 float baseFactor, errorTerm, effFactor, errorEffTerm;
143 if (!getBinContentAndError(*m_jvtHist, x, y, baseFactor, errorTerm) ||
144 !getBinContentAndError(*m_effHist, x, y, effFactor, errorEffTerm)) {
145 sf = -1;
147 }
148 baseFactor += errorTerm * m_appliedSysSigma;
149 effFactor += errorEffTerm * m_appliedSysSigma;
150
151 sf = (1 - baseFactor * effFactor) / (1 - effFactor);
152 return CorrectionCode::Ok;
153 }
154
156 if (jet.pt() < m_minPtForJvt || jet.pt() > m_maxPtForJvt)
157 return false;
158 float eta = m_etaAcc(jet);
159 return std::abs(eta) >= m_minEta && std::abs(eta) <= m_maxEta;
160 }
161} // namespace CP
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Handle class for reading a decoration on an object.
int getBin(double x, double min, double step, int clamp_max)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
#define y
#define x
Header file for AthHistogramAlgorithm.
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
Gaudi::Property< float > m_minEta
StatusCode initHists(const std::string &file, const std::string &wp)
Read the input histograms. Passing an empty 'file' string uses dummy SFs.
Gaudi::Property< float > m_minPtForJvt
Gaudi::Property< float > m_maxEta
CorrectionCode getIneffImpl(float x, float y, float &sf) const
std::unique_ptr< TH2 > m_jvtHist
SG::ConstAccessor< float > m_etaAcc
std::unique_ptr< TH2 > m_effHist
SG::ReadDecorHandleKey< xAOD::JetContainer > m_truthHSLabel
Gaudi::Property< bool > m_doTruthRequirement
virtual CorrectionCode getInefficiencyScaleFactor(const xAOD::Jet &jet, float &sf) const override
Calculate the inefficiency scale factor for the provided jet.
CorrectionCode getEffImpl(float x, float y, float &sf) const
virtual CorrectionCode getEfficiencyScaleFactor(const xAOD::Jet &jet, float &sf) const override
Calculate the efficiency scale factor for the provided jet.
Gaudi::Property< std::string > m_jetContainer
std::optional< SG::AuxElement::ConstAccessor< char > > m_accIsHS
Gaudi::Property< float > m_maxPtForJvt
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
bool isInRange(const xAOD::Jet &jet) const
Gaudi::Property< float > m_dummySFError
Gaudi::Property< std::string > m_jetEtaName
Helper class to provide constant type-safe access to aux data.
Select isolated Photons, Electrons and Muons.
str content
Definition grepfile.py:56
Jet_v1 Jet
Definition of the current "jet version".
TFile * file