ATLAS Offline Software
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 
11 namespace {
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 
30 namespace 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");
56  return CorrectionCode::Error;
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");
75  return CorrectionCode::Error;
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 
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
CP::JvtEfficiencyToolBase::getIneffImpl
CorrectionCode getIneffImpl(float x, float y, float &sf) const
Definition: JvtEfficiencyToolBase.cxx:137
CP::JvtEfficiencyToolBase::m_appliedSysSigma
int m_appliedSysSigma
Definition: JvtEfficiencyToolBase.h:61
CP::JvtEfficiencyToolBase::m_jetEtaName
Gaudi::Property< std::string > m_jetEtaName
Definition: JvtEfficiencyToolBase.h:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::JvtEfficiencyToolBase::m_doTruthRequirement
Gaudi::Property< bool > m_doTruthRequirement
Definition: JvtEfficiencyToolBase.h:37
CP::JvtEfficiencyToolBase::initHists
StatusCode initHists(const std::string &file, const std::string &wp)
Read the input histograms. Passing an empty 'file' string uses dummy SFs.
Definition: JvtEfficiencyToolBase.cxx:85
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
CP::JvtEfficiencyToolBase::getEfficiencyScaleFactor
virtual CorrectionCode getEfficiencyScaleFactor(const xAOD::Jet &jet, float &sf) const override
Calculate the efficiency scale factor for the provided jet.
Definition: JvtEfficiencyToolBase.cxx:48
bin
Definition: BinsDiffFromStripMedian.h:43
getBin
int getBin(double x, double min, double step, int clamp_max)
Definition: FPGATrackSimSectorSlice.cxx:209
athena.value
value
Definition: athena.py:124
SG::ConstAccessor< float >
x
#define x
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::JvtEfficiencyToolBase::m_jvtHist
std::unique_ptr< TH2 > m_jvtHist
Definition: JvtEfficiencyToolBase.h:55
CP::JvtEfficiencyToolBase::m_effHist
std::unique_ptr< TH2 > m_effHist
Definition: JvtEfficiencyToolBase.h:56
grepfile.content
string content
Definition: grepfile.py:56
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::JvtEfficiencyToolBase::m_maxEta
Gaudi::Property< float > m_maxEta
Definition: JvtEfficiencyToolBase.h:44
CP::JvtEfficiencyToolBase::m_dummySFError
Gaudi::Property< float > m_dummySFError
Definition: JvtEfficiencyToolBase.h:50
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::JvtEfficiencyToolBase::getInefficiencyScaleFactor
virtual CorrectionCode getInefficiencyScaleFactor(const xAOD::Jet &jet, float &sf) const override
Calculate the inefficiency scale factor for the provided jet.
Definition: JvtEfficiencyToolBase.cxx:67
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JvtEfficiencyToolBase.h
PlotSFuncertainty.wp
wp
Definition: PlotSFuncertainty.py:112
CP::JvtEfficiencyToolBase::m_etaAcc
SG::ConstAccessor< float > m_etaAcc
Definition: JvtEfficiencyToolBase.h:59
CP::JvtEfficiencyToolBase::isInRange
bool isInRange(const xAOD::Jet &jet) const
Definition: JvtEfficiencyToolBase.cxx:155
PathResolver.h
CP::JvtEfficiencyToolBase::getEffImpl
CorrectionCode getEffImpl(float x, float y, float &sf) const
Definition: JvtEfficiencyToolBase.cxx:124
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CP::JvtEfficiencyToolBase::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JvtEfficiencyToolBase.cxx:31
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
CP::JvtEfficiencyToolBase::m_minPtForJvt
Gaudi::Property< float > m_minPtForJvt
Definition: JvtEfficiencyToolBase.h:46
y
#define y
h
CP::JvtEfficiencyToolBase::m_useDummySFs
bool m_useDummySFs
Definition: JvtEfficiencyToolBase.h:57
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::JvtEfficiencyToolBase::m_jetContainer
Gaudi::Property< std::string > m_jetContainer
Definition: JvtEfficiencyToolBase.h:34
CP::JvtEfficiencyToolBase::m_minEta
Gaudi::Property< float > m_minEta
Definition: JvtEfficiencyToolBase.h:42
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
ReadDecorHandle.h
Handle class for reading a decoration on an object.
CP::JvtEfficiencyToolBase::m_truthHSLabel
SG::ReadDecorHandleKey< xAOD::JetContainer > m_truthHSLabel
Definition: JvtEfficiencyToolBase.h:40
error
Definition: IImpactPoint3dEstimator.h:70
MooRTT_summarizeCPU.fIn
fIn
Definition: MooRTT_summarizeCPU.py:11
CP::JvtEfficiencyToolBase::m_maxPtForJvt
Gaudi::Property< float > m_maxPtForJvt
Definition: JvtEfficiencyToolBase.h:48
CP::JvtEfficiencyToolBase::m_accIsHS
std::optional< SG::AuxElement::ConstAccessor< char > > m_accIsHS
Definition: JvtEfficiencyToolBase.h:63