ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigCost
RatesAnalysis
src
JZCombineWeight.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
JZCombineWeight.h
"
6
7
#include "
AthenaKernel/Units.h
"
8
#include "
xAODEventInfo/EventInfo.h
"
9
#include "
xAODJet/JetContainer.h
"
10
11
#include <fstream>
12
#include <sstream>
13
14
using
Athena::Units::GeV;
15
19
20
StatusCode
JZCombineWeight::initialize
() {
21
std::ifstream
fs
(
m_weightsFile
);
22
try
{
23
m_weightsMap
= nlohmann::json::parse(
fs
);
24
}
catch
(
const
std::exception&) {
25
ATH_MSG_ERROR
(
"Failed to parse input "
<<
m_weightsFile
);
26
return
StatusCode::FAILURE;
27
}
28
return
StatusCode::SUCCESS;
29
}
30
31
StatusCode
JZCombineWeight::getValue
(
double
& value)
const
{
32
const
xAOD::EventInfo
* evt {
nullptr
};
33
ATH_CHECK
(evtStore()->retrieve(evt,
"EventInfo"
));
34
35
// Truth jets are only valid for MC
36
bool
isMC = evt->eventTypeBitmask() &
xAOD::EventInfo::IS_SIMULATION
;
37
if
(!isMC) {
return
StatusCode::SUCCESS; }
38
39
auto
mu_actual =
static_cast<
std::size_t
>
(std::ceil(evt->actualInteractionsPerCrossing()));
40
41
42
// categories
43
std::vector<std::size_t> categories(
m_binning
.size() - 1, 0);
44
45
// HS jets
46
double
pt_j0_AK4HS {5.0};
47
std::size_t idx_HS {0};
48
const
xAOD::JetContainer
* hs_jets {
nullptr
};
49
ATH_CHECK
(evtStore()->retrieve(hs_jets,
m_jetCollectionHS
));
50
if
(hs_jets->
size
()) {
51
auto
iter_jet = std::max_element(hs_jets->
begin
(), hs_jets->
end
(),
52
[](
const
xAOD::Jet
* j0,
const
xAOD::Jet
* j1){ return j0->pt() < j1->pt(); });
53
pt_j0_AK4HS = (*iter_jet)->pt() /
GeV
;
54
idx_HS =
getIndex
(pt_j0_AK4HS);
55
}
56
57
++categories[idx_HS];
58
59
// PU jets
60
std::vector<double> pt_j0_AK4PU;
61
const
xAOD::JetContainer
* pu_jets {
nullptr
};
62
ATH_CHECK
(evtStore()->retrieve(pu_jets,
m_jetCollectionPU
));
63
std::unordered_map<int, double> leading_pts;
64
if
(pu_jets->
size
()) {
65
for
(
const
xAOD::Jet
* pu_jet : *pu_jets) {
66
SG::ConstAccessor<int>
pu_enum_acc(
"pileupEventNumber"
);
67
const
uint32_t pu_enum =
static_cast<
uint32_t
>
(pu_enum_acc.
withDefault
(*pu_jet, 0));
68
double
pu_jet_pt = pu_jet->pt() /
GeV
;
69
if
(!leading_pts.contains(pu_enum) || leading_pts.at(pu_enum) < pu_jet_pt) {
70
leading_pts[pu_enum] = pu_jet_pt;
71
}
72
}
73
}
74
auto
n_pileup_records = leading_pts.size();
75
76
for
(
const
auto
&
pair
: leading_pts) {
77
double
pt =
pair
.second;
78
pt_j0_AK4PU.push_back(pt);
79
std::size_t idx_PU =
getIndex
(pt);
80
++categories[idx_PU];
81
}
82
83
// Remining low pT pileups
84
categories[0] += mu_actual - n_pileup_records - 1;
85
86
// Convert to string
87
std::stringstream key_ss;
88
std::string delim {
"_"
};
89
for
(std::size_t i = 0; i < categories.size(); ++i) {
90
if
(i != 0) key_ss << delim;
91
key_ss << categories.at(i);
92
}
93
key_ss <<
","
<< idx_HS;
94
95
const
std::string& key = key_ss.str();
96
97
// categories that are not included in the weight mapping will be skipped
98
if
(
m_weightsMap
.find(key) ==
m_weightsMap
.end()) {
99
value = 0.0;
100
return
StatusCode::SUCCESS;
101
}
102
103
for
(
const
auto
& weightName :
m_weightsName
) {
104
try
{
105
auto
wt =
m_weightsMap
.at(key).at(weightName).get<
double
>();
106
value *= wt;
107
}
catch
(
const
std::exception&) {
108
ATH_MSG_ERROR
(
"Failed to get weight ["
<< weightName <<
"] in ["
<< key <<
"]!"
);
109
return
StatusCode::FAILURE;
110
}
111
}
112
113
return
StatusCode::SUCCESS;
114
}
115
116
std::size_t
JZCombineWeight::getIndex
(
double
value)
const
{
117
auto
it = std::upper_bound(
m_binning
.begin(),
m_binning
.end(), value);
118
return
std::distance(
m_binning
.begin(), it) - 1;
119
}
120
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
JZCombineWeight.h
JetContainer.h
fs
static Double_t fs
Definition
LArPhysWaveHECTool.cxx:37
GeV
#define GeV
Definition
PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
Units.h
Wrapper to avoid constant divisions when using units.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
JZCombineWeight::m_weightsFile
Gaudi::Property< std::string > m_weightsFile
Definition
JZCombineWeight.h:34
JZCombineWeight::getValue
virtual StatusCode getValue(double &value) const override
Definition
JZCombineWeight.cxx:31
JZCombineWeight::m_binning
Gaudi::Property< std::vector< double > > m_binning
Definition
JZCombineWeight.h:36
JZCombineWeight::m_weightsName
Gaudi::Property< std::vector< std::string > > m_weightsName
Definition
JZCombineWeight.h:38
JZCombineWeight::m_jetCollectionHS
Gaudi::Property< std::string > m_jetCollectionHS
Definition
JZCombineWeight.h:30
JZCombineWeight::getIndex
std::size_t getIndex(double value) const
Definition
JZCombineWeight.cxx:116
JZCombineWeight::initialize
virtual StatusCode initialize() override
This class provides the weight used to combine JZ sliced samples by querying JSON.
Definition
JZCombineWeight.cxx:20
JZCombineWeight::m_weightsMap
nlohmann::json m_weightsMap
Definition
JZCombineWeight.h:41
JZCombineWeight::m_jetCollectionPU
Gaudi::Property< std::string > m_jetCollectionPU
Definition
JZCombineWeight.h:32
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
SG::ConstAccessor::withDefault
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
pair
STL class.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition
EventInfo_v1.h:151
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition
JetContainer.h:17
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0