ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagInference
src
FoldDecoratorAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
FoldDecoratorAlg.h
"
6
7
#include "
StoreGate/ReadDecorHandle.h
"
8
#include "
StoreGate/WriteDecorHandle.h
"
9
10
#include <nlohmann/json.hpp>
11
12
#include <random>
13
14
namespace
FlavorTagInference
{
15
16
FoldDecoratorAlg::FoldDecoratorAlg
(
17
const
std::string& name, ISvcLocator* svcloc):
18
AthReentrantAlgorithm
(name, svcloc)
19
{
20
}
21
22
StatusCode
FoldDecoratorAlg::initialize
()
23
{
24
ATH_CHECK
(
m_mcEventNumberKey
.initialize());
25
// event info is usually not decorated, renounce the dependency
26
renounce
(
m_mcEventNumberKey
);
27
if
(
m_jetCollection
.empty()) {
28
ATH_MSG_ERROR
(
"jet collection not specified"
);
29
return
StatusCode::FAILURE;
30
}
31
m_hashKey
=
m_jetCollection
+
"."
+
m_hashKey
.key();
32
ATH_CHECK
(
m_hashKey
.initialize());
33
34
// other entropy sources, mostly counts
35
for
(
auto
& key:
m_jetAssociations
) {
36
key =
m_jetCollection
+
"."
+ key.key();
37
}
38
ATH_CHECK
(
m_jetAssociations
.initialize());
39
// most the associations also aren't decorated, renounce these
40
// dependencies too
41
renounceArray
(
m_jetAssociations
);
42
for
(
auto
& key:
m_jetInts
) {
43
key =
m_jetCollection
+
"."
+ key.key();
44
}
45
ATH_CHECK
(
m_jetInts
.initialize());
46
// same with jetInts: usually not decorated
47
renounceArray
(
m_jetInts
);
48
49
// set up some salts for other sources of entropy
50
std::map<std::string, uint32_t> fullSeeds;
51
for
(
const
auto
& [k, v]:
m_jetVarSeeds
) {
52
fullSeeds[
m_jetCollection
+
"."
+ k] = v;
53
}
54
auto
addHashKeys = [
this
, &fullSeeds](
auto
keys) {
55
for
(
auto
& key: keys) {
56
uint32_t salt =
m_salt
;
57
if
(
auto
h
= fullSeeds.extract(key.key())) {
58
salt = std::mt19937(
h
.mapped())();
59
}
60
this->
m_hashedKeys
[key.key()] = salt;
61
}
62
};
63
addHashKeys(
m_jetAssociations
);
64
addHashKeys(
m_jetInts
);
65
if
(!fullSeeds.empty()) {
66
for
(
const
auto
& [k, v]: fullSeeds) {
67
ATH_MSG_ERROR
(
"unused salt for jet variable "
<< k);
68
}
69
return
StatusCode::FAILURE;
70
}
71
72
// more sources from constituents
73
std::set<std::string> associations;
74
for
(
const
auto
& key:
m_jetAssociations
) associations.insert(key.key());
75
using
charmap_t = std::map<std::string,std::vector<std::string>>;
76
auto
chars = nlohmann::json::parse(
m_constituentChars
);
77
for
(
const
auto
& [k, vlist]: chars.get<charmap_t>()) {
78
uint32_t salt =
m_salt
;
79
std::string key =
m_jetCollection
+
"."
+ k;
80
if
(!associations.count(key)) {
81
ATH_MSG_ERROR
(
"Constituent "
<< key <<
" is not read from the jet"
);
82
return
StatusCode::FAILURE;
83
}
84
for
(
const
auto
& v: vlist) {
85
if
(
auto
h
=
m_constituentSeeds
.value().extract(v)) {
86
salt = std::mt19937(
h
.mapped())();
87
}
88
m_chars
[key].emplace_back(salt,v);
89
}
90
}
91
if
(!
m_constituentSeeds
.empty()) {
92
for
(
const
auto
& [k, v]:
m_constituentSeeds
) {
93
ATH_MSG_ERROR
(
"unused salt for constituent variable "
<< k);
94
}
95
return
StatusCode::FAILURE;
96
}
97
98
return
StatusCode::SUCCESS;
99
}
100
101
StatusCode
FoldDecoratorAlg::execute
(
const
EventContext& cxt)
const
{
102
SG::ReadDecorHandle<xAOD::EventInfo, uint64_t>
hnumber(
103
m_mcEventNumberKey
, cxt);
104
SG::WriteDecorHandle<xAOD::JetContainer, uint32_t>
hhash(
105
m_hashKey
, cxt);
106
auto
hjetassoc =
m_jetAssociations
.makeHandles(cxt);
107
auto
hjetint =
m_jetInts
.makeHandles(cxt);
108
uint32_t
number
= hnumber(*hnumber);
109
auto
event_hash = std::mt19937(
number
^
m_salt
)();
110
111
// get more entropy from jet variables
112
auto
getSalt = [
this
, event_hash](
const
auto
& handle) {
113
return
this->
m_hashedKeys
.at(handle.decorKey()) ^ event_hash;
114
};
115
for
(
const
auto
*
jet
: *hhash) {
116
uint32_t jet_hash = 0;
117
for
(
const
auto
& assoc: hjetassoc) {
118
const
auto
& iplc = assoc(*
jet
);
119
jet_hash ^= std::mt19937( iplc.size() ^ getSalt(assoc))();
120
if
(
m_chars
.count(assoc.decorKey())) {
121
for
(
const
auto
& [salt, acc]:
m_chars
.at(assoc.decorKey())) {
122
unsigned
int
count
= 0;
123
for
(
const
auto
& lnk: iplc)
count
+= acc(**lnk);
124
jet_hash ^= std::mt19937(
count
^ salt ^ event_hash)();
125
}
126
}
127
}
128
for
(
const
auto
& hint: hjetint) {
129
jet_hash ^= std::mt19937( hint(*
jet
) ^ getSalt(hint))();
130
}
131
hhash(*
jet
) = event_hash ^ jet_hash;
132
}
133
return
StatusCode::SUCCESS;
134
}
135
136
}
// end namespace FlavorTagInference
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
FoldDecoratorAlg.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthCommonAlgorithm< Gaudi::Algorithm >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition
AthCommonDataStore.h:380
AthCommonAlgorithm< Gaudi::Algorithm >::renounceArray
void renounceArray(SG::VarHandleKeyArray &handlesArray)
Definition
AthCommonDataStore.h:364
h
Header file for AthHistogramAlgorithm.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagInference::FoldDecoratorAlg::m_jetVarSeeds
Gaudi::Property< std::map< std::string, uint32_t > > m_jetVarSeeds
Definition
FoldDecoratorAlg.h:47
FlavorTagInference::FoldDecoratorAlg::FoldDecoratorAlg
FoldDecoratorAlg(const std::string &name, ISvcLocator *svcloc)
Definition
FoldDecoratorAlg.cxx:16
FlavorTagInference::FoldDecoratorAlg::m_jetCollection
Gaudi::Property< std::string > m_jetCollection
Definition
FoldDecoratorAlg.h:35
FlavorTagInference::FoldDecoratorAlg::m_mcEventNumberKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_mcEventNumberKey
Definition
FoldDecoratorAlg.h:29
FlavorTagInference::FoldDecoratorAlg::m_jetInts
SG::ReadDecorHandleKeyArray< JC, int > m_jetInts
Definition
FoldDecoratorAlg.h:41
FlavorTagInference::FoldDecoratorAlg::m_salt
Gaudi::Property< uint32_t > m_salt
Definition
FoldDecoratorAlg.h:32
FlavorTagInference::FoldDecoratorAlg::m_chars
std::unordered_map< std::string, std::vector< SaltedCReader > > m_chars
Definition
FoldDecoratorAlg.h:62
FlavorTagInference::FoldDecoratorAlg::m_jetAssociations
SG::ReadDecorHandleKeyArray< JC, IPLV > m_jetAssociations
Definition
FoldDecoratorAlg.h:38
FlavorTagInference::FoldDecoratorAlg::m_constituentSeeds
Gaudi::Property< std::map< std::string, uint32_t > > m_constituentSeeds
Definition
FoldDecoratorAlg.h:53
FlavorTagInference::FoldDecoratorAlg::m_constituentChars
Gaudi::Property< std::string > m_constituentChars
Definition
FoldDecoratorAlg.h:50
FlavorTagInference::FoldDecoratorAlg::m_hashedKeys
std::unordered_map< std::string, uint32_t > m_hashedKeys
Definition
FoldDecoratorAlg.h:58
FlavorTagInference::FoldDecoratorAlg::m_hashKey
SG::WriteDecorHandleKey< JC > m_hashKey
Definition
FoldDecoratorAlg.h:44
FlavorTagInference::FoldDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
FoldDecoratorAlg.cxx:22
FlavorTagInference::FoldDecoratorAlg::execute
virtual StatusCode execute(const EventContext &cxt) const override
Definition
FoldDecoratorAlg.cxx:101
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
FlavorTagInference
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition
CaloClusterLoader.h:27
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
number
std::string number(const double &d, const std::string &s)
Definition
utils.cxx:186
Generated on
for ATLAS Offline Software by
1.17.0