ATLAS Offline Software
JetScaleFactorCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Id: JetScaleFactorCalculator.cxx 794672 2017-01-31 00:41:04Z tpelzer $
8 #include "TopEvent/EventTools.h"
9 
10 #include "xAODJet/JetContainer.h"
11 
12 
13 namespace top {
15  asg::AsgTool(name),
16  m_config(nullptr),
17 
18  m_systNominal(CP::SystematicSet()),
19  m_systUP(CP::SystematicSet()),
20  m_systDOWN(CP::SystematicSet()),
21  m_jvt_tool("JetJvtEfficiencyTool"),
22  m_fjvt_tool("JetForwardJvtEfficiencyTool") {
23  declareProperty("config", m_config);
24  }
25 
27  ATH_MSG_INFO("top::JetScaleFactorCalculator initialize");
28 
29  top::check(m_jvt_tool.retrieve(), "Failed to retrieve JVT tool");
30 
31  m_systUP.insert(CP::SystematicVariation(CP::NNJvtEfficiencyUp));
32  m_systDOWN.insert(CP::SystematicVariation(CP::NNJvtEfficiencyDown));
33 
34  // fJVT Efficiency tool is only set up if user requests it
35  if (m_config->getfJVTWP() != "None") {
36  top::check(m_fjvt_tool.retrieve(), "Failed to retrieve fJVT tool");
37 
38  m_systUP.insert(CP::SystematicVariation(CP::fJvtEfficiencyUp));
39  m_systDOWN.insert(CP::SystematicVariation(CP::fJvtEfficiencyDown));
40  }
41 
42  return StatusCode::SUCCESS;
43  }
44 
47 
48  for (auto currentSystematic : *m_config->systSgKeyMapJets(false)) {
49  const xAOD::JetContainer* jets(nullptr);
50  top::check(evtStore()->retrieve(jets, currentSystematic.second), "failed to retrieve jets in JetScaleFactorCalculator::execute()");
51  top::check(this->decorateJets(jets,currentSystematic.first == m_config->nominalHashValue()),"failed to decorate jets in JetScaleFactorCalculator::execute()");
52  }
53 
54  if(m_config->doLooseEvents() && m_config->applyElectronInJetSubtraction())
55  {
56  for (auto currentSystematic : *m_config->systSgKeyMapJets(true)) {
57  const xAOD::JetContainer* jets(nullptr);
58  top::check(evtStore()->retrieve(jets, currentSystematic.second), "failed to retrieve loose jets in JetScaleFactorCalculator::execute()");
59  top::check(this->decorateJets(jets,currentSystematic.first == m_config->nominalHashValue()),"failed to decorate loose jets in JetScaleFactorCalculator::execute()");
60  }
61  }
62 
63  return StatusCode::SUCCESS;
64  }
65 
67 
69  for (const xAOD::Jet *jetPtr : *jets) {
71  // WARNING: this doesn't include the JVT cut anymore
72  bool passSelection(false);
73  if (jetPtr->isAvailable<char>("passPreORSelection")) {
74  if (jetPtr->auxdataConst<char>("passPreORSelection") == 1) {
75  passSelection = true;
76  }
77  }
78  if (jetPtr->isAvailable<char>("passPreORSelectionLoose")) {
79  if (jetPtr->auxdataConst<char>("passPreORSelectionLoose") == 1) {
80  passSelection = true;
81  }
82  }
83 
84  if (passSelection) {
86  // Set to nominal first...
87  top::check(m_jvt_tool->applySystematicVariation(m_systNominal),
88  "Failed to set JVT nominal SF");
89 
90  float jvtSF(1.);
91 
92  if (!jetPtr->isAvailable<char>("passJVT")) {
93  ATH_MSG_ERROR(" Can't find jet decoration \"passJVT\" - we need it to calculate the jet scale-factors!");
94  return StatusCode::FAILURE;
95  }
96 
97  int passes_jvt = jetPtr->auxdataConst< char >("passJVT");
98  if (passes_jvt < 0) continue;
99 
100  if (passes_jvt) top::check(m_jvt_tool->getEfficiencyScaleFactor(*jetPtr, jvtSF),
101  "Failed to getEfficiencyScaleFactor for JVT");
102  else {
103  top::check(m_jvt_tool->getInefficiencyScaleFactor(*jetPtr, jvtSF),
104  "Failed to getInefficiencyScaleFactor for JVT");
105  }
106 
107  jetPtr->auxdecor<float>("JET_SF_jvt") = jvtSF;
108 
110  if (isNominal) {
111  float jvtSF_up(1.), jvtSF_down(1.); // made up values
112 
113  if (passes_jvt) {
114  top::check(m_jvt_tool->applySystematicVariation(m_systUP),
115  "Failed to applySystematicVariation up for JVT");
116  top::check(m_jvt_tool->getEfficiencyScaleFactor(*jetPtr, jvtSF_up),
117  "Failed to get JVT SF (systematic up)");
118  top::check(m_jvt_tool->applySystematicVariation(m_systDOWN),
119  "Failed to applySystematicVariation down for JVT");
120  top::check(m_jvt_tool->getEfficiencyScaleFactor(*jetPtr, jvtSF_down),
121  "Failed to get JVT SF (systematic down)");
122  } else {
123  top::check(m_jvt_tool->applySystematicVariation(m_systUP),
124  "Failed to applySystematicVariation up for JVT");
125  top::check(m_jvt_tool->getInefficiencyScaleFactor(*jetPtr, jvtSF_up),
126  "Failed to get JVT SF (systematic up)");
127  top::check(m_jvt_tool->applySystematicVariation(m_systDOWN),
128  "Failed to applySystematicVariation down for JVT");
129  top::check(m_jvt_tool->getInefficiencyScaleFactor(*jetPtr, jvtSF_down),
130  "Failed to get JVT SF (systematic down)");
131  }
132 
134  jetPtr->auxdecor<float>("JET_SF_jvt_UP") = jvtSF_up;
135  jetPtr->auxdecor<float>("JET_SF_jvt_DOWN") = jvtSF_down;
136 
137  } // Calibration systematic is nominal, so calculate SF systematics
138 
140  if (m_config->getfJVTWP() != "None") {
141  top::check(m_fjvt_tool->applySystematicVariation(m_systNominal),
142  "Failed to set fJVT nominal SF");
143  float fjvtSF(1.);
144 
145  if (!jetPtr->isAvailable<char>("AnalysisTop_fJVTdecision")) {
146  ATH_MSG_ERROR(" Can't find jet decoration \"AnalysisTop_fJVTdecision\" - we need it to calculate the jet fJVT scale-factors!");
147  return StatusCode::FAILURE;
148  }
149  int passes_fjvt = jetPtr->auxdataConst< char >("AnalysisTop_fJVTdecision");
150  if (passes_fjvt < 0) continue;
151  if (passes_fjvt) top::check(m_fjvt_tool->getEfficiencyScaleFactor(*jetPtr, fjvtSF),
152  "Failed to getEfficiencyScaleFactor for fJVT");
153  else {
154  top::check(m_fjvt_tool->getInefficiencyScaleFactor(*jetPtr, fjvtSF),
155  "Failed to getInefficiencyScaleFactor for fJVT");
156  }
157  jetPtr->auxdecor<float>("JET_SF_fjvt") = fjvtSF;
158 
159  if (isNominal) {
160  float fjvtSF_up(1.), fjvtSF_down(1.); // made up values
161  if (passes_fjvt) {
162  top::check(m_fjvt_tool->applySystematicVariation(m_systUP),
163  "Failed to applySystematicVariation up for fJVT");
164  top::check(m_fjvt_tool->getEfficiencyScaleFactor(*jetPtr, fjvtSF_up),
165  "Failed to get fJVT SF (systematic up)");
166  top::check(m_fjvt_tool->applySystematicVariation(m_systDOWN),
167  "Failed to applySystematicVariation down for fJVT");
168  top::check(m_fjvt_tool->getEfficiencyScaleFactor(*jetPtr, fjvtSF_down),
169  "Failed to get fJVT SF (systematic down)");
170  } else {
171  top::check(m_fjvt_tool->applySystematicVariation(m_systUP),
172  "Failed to applySystematicVariation up for fJVT");
173  top::check(m_fjvt_tool->getInefficiencyScaleFactor(*jetPtr, fjvtSF_up),
174  "Failed to get fJVT SF (systematic up)");
175  top::check(m_fjvt_tool->applySystematicVariation(m_systDOWN),
176  "Failed to applySystematicVariation down for fJVT");
177  top::check(m_fjvt_tool->getInefficiencyScaleFactor(*jetPtr, fjvtSF_down),
178  "Failed to get fJVT SF (systematic down)");
179  }
181  jetPtr->auxdecor<float>("JET_SF_fjvt_UP") = fjvtSF_up;
182  jetPtr->auxdecor<float>("JET_SF_fjvt_DOWN") = fjvtSF_down;
183 
184  } // Calibration systematic is nominal, so calculate SF systematics
185  }
186  }
187  }
188  return StatusCode::SUCCESS;
189  }
190 } // namespace top
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg
Definition: DataHandleTestTool.h:28
top::JetScaleFactorCalculator::JetScaleFactorCalculator
JetScaleFactorCalculator(const std::string &name)
Definition: JetScaleFactorCalculator.cxx:14
CP::SystematicVariation
Definition: SystematicVariation.h:47
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::JetScaleFactorCalculator::m_systDOWN
CP::SystematicSet m_systDOWN
Definition: JetScaleFactorCalculator.h:61
JetScaleFactorCalculator.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
top::JetScaleFactorCalculator::m_systNominal
CP::SystematicSet m_systNominal
Definition: JetScaleFactorCalculator.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
top::JetScaleFactorCalculator::decorateJets
StatusCode decorateJets(const xAOD::JetContainer *jets, bool isNominal)
Definition: JetScaleFactorCalculator.cxx:66
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
top::JetScaleFactorCalculator::m_jvt_tool
ToolHandle< CP::IJetJvtEfficiency > m_jvt_tool
Definition: JetScaleFactorCalculator.h:63
TopConfig.h
top::JetScaleFactorCalculator::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: JetScaleFactorCalculator.h:57
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetContainer.h
top::JetScaleFactorCalculator::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetScaleFactorCalculator.cxx:26
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
top::JetScaleFactorCalculator::execute
StatusCode execute()
Definition: JetScaleFactorCalculator.cxx:45
top::JetScaleFactorCalculator::m_systUP
CP::SystematicSet m_systUP
Definition: JetScaleFactorCalculator.h:60
top::JetScaleFactorCalculator::m_fjvt_tool
ToolHandle< CP::IJetJvtEfficiency > m_fjvt_tool
Definition: JetScaleFactorCalculator.h:64