ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetMomentTools
Root
NNJvtBinning.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
JetMomentTools/NNJvtBinning.h
"
5
#include "nlohmann/json.hpp"
6
#include "
xAODBase/IParticle.h
"
7
8
#include <algorithm>
9
#include <map>
10
#include <regex>
11
#include <stdexcept>
12
#include <string>
13
14
namespace
{
15
static
constexpr
float
GeV
= 1
e3
;
// AnalysisBase has no SystemOfUnits.h
16
}
17
18
namespace
JetPileupTag
{
19
20
void
to_json
(nlohmann::json &j,
const
NNJvtBinning
&binning) {
21
j = nlohmann::json{{
"ptbin_edges"
, binning.ptEdges}, {
"etabin_edges"
, binning.etaEdges}};
22
}
23
24
void
from_json
(
const
nlohmann::json &j,
NNJvtBinning
&binning) {
25
j.at(
"ptbin_edges"
).get_to(binning.ptEdges);
26
j.at(
"etabin_edges"
).get_to(binning.etaEdges);
27
// pT values are stored in GeV but we should use CLHEP values wherever possible
28
for
(
float
&value : binning.ptEdges)
29
value *=
GeV
;
30
}
31
32
void
to_json
(nlohmann::json &j,
const
NNJvtCutMap
&cutMap) {
33
to_json
(j, cutMap.
edges
);
34
std::map<std::string, float> cuts;
35
for
(std::size_t ptIdx = 0; ptIdx < cutMap.
cutMap
.size(); ++ptIdx)
36
for
(std::size_t etaIdx = 0; etaIdx < cutMap.
cutMap
.at(ptIdx).
size
(); ++etaIdx)
37
cuts[
"("
+ std::to_string(ptIdx) +
", "
+ std::to_string(etaIdx) +
")"
] =
38
cutMap.
cutMap
.at(ptIdx).at(etaIdx);
39
j[
"cuts"
] = cutMap;
40
}
41
42
void
from_json
(
const
nlohmann::json &j,
NNJvtCutMap
&cutMap) {
43
j.get_to(cutMap.
edges
);
44
cutMap.
cutMap
.resize(cutMap.
edges
.
ptEdges
.size() - 1);
45
for
(
auto
&v : cutMap.
cutMap
)
46
v.resize(cutMap.
edges
.
etaEdges
.size() - 1);
47
std::regex expr(R
"(\((\d+),\s*(\d+)\))");
48
for
(
const
auto
&[
bin
, cut] : j[
"cuts"
].
get
<std::map<std::string, float>>()) {
49
std::smatch sm;
50
if
(!std::regex_match(
bin
, sm, expr))
51
throw
std::invalid_argument(
"Invalid bin descriptor: "
+
bin
);
52
cutMap.
cutMap
.at(std::stoi(sm[1])).at(std::stoi(sm[2])) = cut;
53
}
54
}
55
56
NNJvtBinning
NNJvtBinning::fromJSON
(std::istream &is) {
57
nlohmann::json j;
58
is >> j;
59
return
j.get<
NNJvtBinning
>();
60
}
61
62
std::string
NNJvtBinning::toJSON
()
const
{
63
return
nlohmann::json(*this).dump();
64
}
65
66
bool
67
NNJvtBinning::operator()
(
float
pt,
float
eta
, std::size_t &ptBin, std::size_t &etaBin)
const
{
68
ptBin = std::distance(
69
ptEdges
.begin(), std::lower_bound(
ptEdges
.begin(),
ptEdges
.end(), pt));
70
etaBin = std::distance(
71
etaEdges
.begin(), std::lower_bound(
etaEdges
.begin(),
etaEdges
.end(),
eta
));
72
// 0 => below the lowest bin edge, size() => above the highest bin edge
73
// Use lowest pt bin for any jets with lower pt
74
if
(ptBin == 0)
75
ptBin = 1;
76
if
(ptBin ==
ptEdges
.size())
77
ptBin = SIZE_MAX;
78
else
79
ptBin -= 1;
80
if
(etaBin == 0 || etaBin ==
etaEdges
.size())
81
etaBin = SIZE_MAX;
82
else
83
etaBin -= 1;
84
85
return
ptBin != SIZE_MAX && etaBin != SIZE_MAX;
86
}
87
88
bool
NNJvtBinning::operator()
(
89
const
xAOD::IParticle
&particle, std::size_t &ptBin, std::size_t &etaBin)
const
{
90
return
this->
operator()
(particle.
pt
(), particle.eta(), ptBin, etaBin);
91
}
92
93
NNJvtCutMap
NNJvtCutMap::fromJSON
(std::istream &is) {
94
nlohmann::json j;
95
is >> j;
96
return
j.get<
NNJvtCutMap
>();
97
}
98
99
std::string
NNJvtCutMap::toJSON
()
const
{
100
return
nlohmann::json(*this).dump();
101
}
102
103
float
NNJvtCutMap::operator()
(
float
pt,
float
eta
)
const
{
104
std::size_t ptBin, etaBin;
105
if
(!
edges
(pt,
eta
, ptBin, etaBin))
106
return
-1;
107
return
this->
operator()
(ptBin, etaBin);
108
}
109
110
float
NNJvtCutMap::operator()
(
const
xAOD::IParticle
&particle)
const
{
111
std::size_t ptBin, etaBin;
112
if
(!
edges
(particle, ptBin, etaBin))
113
return
-1;
114
return
this->
operator()
(ptBin, etaBin);
115
}
116
117
float
NNJvtCutMap::operator()
(std::size_t ptBin, std::size_t etaBin)
const
{
118
return
cutMap
.at(ptBin).at(etaBin);
119
}
120
}
// namespace JetPileupTag
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
IParticle.h
NNJvtBinning.h
Helpers for reading NN Jvt network binnings and results from an input file.
GeV
#define GeV
Definition
PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
size
size_t size() const
Number of registered mappings.
bin
Definition
BinsDiffFromStripMedian.h:43
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::IParticle::pt
virtual double pt() const =0
The transverse momentum ( ) of the particle.
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition
hcg.cxx:132
CheckAppliedSFs.e3
e3
Definition
CheckAppliedSFs.py:264
JetPileupTag
Definition
JetVertexNNTagger.h:41
JetPileupTag::to_json
void to_json(nlohmann::json &j, const NNJvtBinning &binning)
Definition
NNJvtBinning.cxx:20
JetPileupTag::GeV
constexpr float GeV
Definition
JetVertexNNTagger.h:44
JetPileupTag::from_json
void from_json(const nlohmann::json &j, NNJvtBinning &binning)
Definition
NNJvtBinning.cxx:24
JetPileupTag::NNJvtBinning
Helper struct to hold the bin edges for the NN Jvt cut maps.
Definition
NNJvtBinning.h:23
JetPileupTag::NNJvtBinning::ptEdges
std::vector< float > ptEdges
Definition
NNJvtBinning.h:24
JetPileupTag::NNJvtBinning::operator()
bool operator()(float pt, float eta, std::size_t &ptBin, std::size_t &etaBin) const
Get the correct bin for the provided pt/eta values.
Definition
NNJvtBinning.cxx:67
JetPileupTag::NNJvtBinning::etaEdges
std::vector< float > etaEdges
Definition
NNJvtBinning.h:25
JetPileupTag::NNJvtBinning::toJSON
std::string toJSON() const
Definition
NNJvtBinning.cxx:62
JetPileupTag::NNJvtBinning::fromJSON
static NNJvtBinning fromJSON(std::istream &is)
Definition
NNJvtBinning.cxx:56
JetPileupTag::NNJvtCutMap
The NNJvt cut maps.
Definition
NNJvtBinning.h:50
JetPileupTag::NNJvtCutMap::toJSON
std::string toJSON() const
Definition
NNJvtBinning.cxx:99
JetPileupTag::NNJvtCutMap::fromJSON
static NNJvtCutMap fromJSON(std::istream &is)
Definition
NNJvtBinning.cxx:93
JetPileupTag::NNJvtCutMap::operator()
float operator()(float pt, float eta) const
Get the correct cut value for the provided pt/eta.
Definition
NNJvtBinning.cxx:103
JetPileupTag::NNJvtCutMap::edges
NNJvtBinning edges
Definition
NNJvtBinning.h:51
JetPileupTag::NNJvtCutMap::cutMap
std::vector< std::vector< float > > cutMap
Definition
NNJvtBinning.h:52
Generated on
for ATLAS Offline Software by
1.17.0