ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
L1Topo
L1TopoAlgorithms
Root
KalmanMETCorrection.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
* KalmanMETCorrection.cpp
6
* Created by Joerg Stelzer on 11/16/12.
7
* Re-written by Ralf Gugel on 04/19/24.
8
*
9
* @brief algorithm calculates the KF correction per jet , get new XE and apply cut
10
*
11
* @param NumberLeading
12
**********************************/
13
14
15
16
#include "
L1TopoAlgorithms/KalmanMETCorrection.h
"
17
#include "
L1TopoCommon/Exception.h
"
18
#include "
L1TopoInterfaces/Decision.h
"
19
#include "
L1TopoSimulationUtils/KFLUT.h
"
20
#include "
L1TopoSimulationUtils/Kinematics.h
"
21
// Bitwise implementation utils
22
#include "
L1TopoSimulationUtils/L1TopoDataTypes.h
"
23
#include "
L1TopoSimulationUtils/Trigo.h
"
24
#include "
L1TopoSimulationUtils/Conversions.h
"
25
//
26
#include <cmath>
27
#include <string>
28
29
30
REGISTER_ALG_TCS
(KalmanMETCorrection)
31
32
TCS
::
KalmanMETCorrection
::
KalmanMETCorrection
(
const
std
::
string
&
name
) :
DecisionAlg
(
name
)
33
{
34
defineParameter
(
"InputWidth"
, 9);
35
defineParameter
(
"NumResultBits"
, 6);
36
for
(
size_t
weightIndex = 0; weightIndex <
TCS::KFMET::nWeightWords
; weightIndex++) {
37
defineParameter
(
"weights"
+std::to_string(weightIndex), 0);
38
}
39
defineParameter
(
"MinET"
, 0);
40
defineParameter
(
"KFXE"
,0,0);
41
defineParameter
(
"KFXE"
,0,1);
42
defineParameter
(
"KFXE"
,0,2);
43
defineParameter
(
"KFXE"
,0,3);
44
defineParameter
(
"KFXE"
,0,4);
45
defineParameter
(
"KFXE"
,0,5);
46
setNumberOutputBits
(6);
47
}
48
49
TCS::KalmanMETCorrection::~KalmanMETCorrection
(){}
50
51
52
TCS::StatusCode
53
TCS::KalmanMETCorrection::initialize
() {
54
55
p_NumberLeading2
=
parameter
(
"InputWidth"
).value();
56
57
p_MinEt
=
parameter
(
"MinET"
).value();
58
59
for
(
unsigned
int
i=0; i<
numberOutputBits
(); ++i) {
60
p_XE
[i] =
parameter
(
"KFXE"
,i).value();
61
62
}
63
TRG_MSG_INFO
(
"NumberLeading2 : "
<<
p_NumberLeading2
);
64
for
(
unsigned
int
i=0; i<
numberOutputBits
(); ++i) {
65
TRG_MSG_INFO
(
"KFXE : "
<<
p_XE
[i]);
66
}
67
TRG_MSG_INFO
(
"MinET : "
<<
p_MinEt
);
68
69
TRG_MSG_INFO
(
"number output : "
<<
numberOutputBits
());
70
71
//retrieve all weight words (in compacted representation)
72
std::vector<unsigned> weightWords(
TCS::KFMET::nWeightWords
);
73
for
(
size_t
weightIndex = 0; weightIndex <
TCS::KFMET::nWeightWords
; weightIndex++) {
74
weightWords[weightIndex] =
parameter
(
"weights"
+std::to_string(weightIndex)).value();
75
}
76
//unpack and convert individual weights
77
for
(
size_t
iET=0; iET <
TCS::KFMET::nLogEtBins
; ++iET) {
78
for
(
size_t
jEta=0; jEta <
TCS::KFMET::nEtaBins
; ++jEta) {
79
if
(jEta ==
TCS::KFMET::nEtaBins
-1) {
80
p_correctionLut
[jEta][iET] = 0;
//eta fallback bin
81
continue
;
82
}
83
//assuming here that weights are max. 32 bits each to simplify unpacking logic
84
size_t
startBit = (iET + jEta *
TCS::KFMET::nLogEtBins
) *
TCS::KFMET::correctionBitWidth
;
85
constexpr
unsigned
weightMask = (1 <<
TCS::KFMET::correctionBitWidth
)-1;
86
unsigned
rawValue = ( weightWords[startBit/32] >> (startBit%32) ) & weightMask;
87
int
nOverflowBits = (startBit%32) +
TCS::KFMET::correctionBitWidth
- 32;
88
if
(nOverflowBits > 0) {
89
//overflow into next word
90
// ( next word & bit mask for parts of 2nd word ) << bits already taken from previus word
91
rawValue |= (weightWords[startBit/32 + 1] & ( (1 << nOverflowBits) - 1 ) ) << (
TCS::KFMET::correctionBitWidth
- nOverflowBits);
92
}
93
//convert raw value to suitable signed integer (assuming 2's complement)
94
p_correctionLut
[jEta][iET] =
TSU::toSigned
(rawValue,
TCS::KFMET::correctionBitWidth
);
95
/*
96
if (rawValue >> (TCS::KFMET::correctionBitWidth-1) == 0) { //sign bit is not set
97
p_correctionLut[jEta][iET] = rawValue;
98
} else {
99
constexpr int twosComplementOffset = 1 << TCS::KFMET::correctionBitWidth; // 2^bitwidth
100
p_correctionLut[jEta][iET] = rawValue - twosComplementOffset;
101
}
102
*/
103
}
104
}
105
106
return
StatusCode::SUCCESS
;
107
}
108
109
110
111
TCS::StatusCode
112
TCS::KalmanMETCorrection::processBitCorrect
(
const
std::vector<TCS::TOBArray const *> & input,
113
const
std::vector<TCS::TOBArray *> &
/*output*/
,
114
Decision
& decision )
115
116
{
117
118
if
(
isLegacyTopo
()){
119
//KFMET was never fully commissioned on legacy L1Topo, hence, simply ignore
120
return
TCS::StatusCode::SUCCESS
;
121
}
122
123
if
(input.size()!=2) {
124
TCS_EXCEPTION
(
"KalmanMETCorrection alg must have exactly two input list (jets and MET list), but got "
<< input.size());
125
}
126
127
const
TCS::GenericTOB
&
met
= (*input[0])[0];
128
int64_t metXY[2] {
met
.Ex(),
met
.Ey()};
129
int64_t jetSumXY[2] {0, 0};
130
for
(
TOBArray::const_iterator
tob = input[1]->begin();
131
tob != input[1]->end() && distance( input[1]->begin(), tob) <
p_NumberLeading2
;
132
++tob) {
133
if
( (*tob)->Et() <=
p_MinEt
)
continue
;
// E_T cut
134
unsigned
tobEta = abs((*tob)->eta());
135
size_t
etaBin =
TCS::KFMET::lookupEtaBin
.count(tobEta) ?
TCS::KFMET::lookupEtaBin
.at(tobEta) :
TCS::KFMET::lookupEtaBinFallback
;
136
137
//ignore given number of least significant bits right away
138
unsigned
tobET = (*tob)->Et() >>
TCS::KFMET::jetEtBinOffset
;
139
unsigned
etBin = 0;
140
//KFMET LUT is binned in log2(ET) with ET in Topo's internal granularity
141
//-> determining the bin index reduces to determining the position of the higest non-zero bit
142
// highest log2(ET) bin also acts as overflow bin
143
while
(tobET > 1 && etBin <
TCS::KFMET::nLogEtBins
-1) {
144
etBin++;
145
tobET >>= 1;
146
}
147
int
scaledEt = (*tob)->Et() *
p_correctionLut
[etaBin][etBin];
148
unsigned
tobPhi = (*tob)->phi();
149
jetSumXY[0] +=
static_cast<
int64_t
>
(scaledEt) *
TSU::Trigo::CosInt
.at(tobPhi);
150
jetSumXY[1] +=
static_cast<
int64_t
>
(scaledEt) *
TSU::Trigo::SinInt
.at(tobPhi);
151
152
}
153
154
//compute "corrected" MET values
155
int64_t kfmetXY[2] {
156
metXY[0] + ( jetSumXY[0] >> (
TCS::KFMET::correctionDecimalBitWidth
+ 10
/*cos/sin decimal bits*/
) ),
157
metXY[1] + ( jetSumXY[1] >> (
TCS::KFMET::correctionDecimalBitWidth
+ 10
/*cos/sin decimal bits*/
) )
158
};
159
160
uint64_t kfmetSq = kfmetXY[0] * kfmetXY[0] + kfmetXY[1] * kfmetXY[1];
161
162
for
(
unsigned
int
i=0; i<
numberOutputBits
(); ++i) {
163
const
auto
XE64 =
static_cast<
uint64_t
>
(
p_XE
[i]);
164
decision.
setBit
( i, kfmetSq > XE64 * XE64 );
165
}
166
167
return
TCS::StatusCode::SUCCESS
;
168
169
}
170
171
TCS::StatusCode
172
TCS::KalmanMETCorrection::process
(
const
std::vector<TCS::TOBArray const *> & input,
173
const
std::vector<TCS::TOBArray *> & output,
174
Decision
& decision )
175
176
{
177
//we have a bitwise correct implementation, so use it
178
return
this->
processBitCorrect
(input, output, decision);
179
}
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition
AlgFactory.h:62
Conversions.h
Decision.h
KFLUT.h
KalmanMETCorrection.h
Kinematics.h
L1TopoDataTypes.h
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
Exception.h
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition
Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:15
Trigo.h
TCS::ConfigurableAlg::isLegacyTopo
bool isLegacyTopo() const
Definition
ConfigurableAlg.h:67
TCS::ConfigurableAlg::name
const std::string & name() const
Definition
ConfigurableAlg.h:49
TCS::ConfigurableAlg::parameter
const Parameter & parameter(std::string_view parameterName) const
Definition
ConfigurableAlg.cxx:245
TCS::ConfigurableAlg::defineParameter
void defineParameter(std::string_view name, TCS::parType_t value)
Definition
ConfigurableAlg.cxx:203
TCS::DataArrayImpl< GenericTOB >::const_iterator
data_t::const_iterator const_iterator
Definition
DataArrayImpl.h:18
TCS::DecisionAlg::setNumberOutputBits
void setNumberOutputBits(unsigned int numberOutputBits)
Definition
DecisionAlg.h:39
TCS::DecisionAlg::DecisionAlg
DecisionAlg(const std::string &name)
Definition
DecisionAlg.h:24
TCS::DecisionAlg::numberOutputBits
unsigned int numberOutputBits() const
Definition
DecisionAlg.h:38
TCS::Decision
Definition
Decision.h:19
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition
Decision.cxx:12
TCS::GenericTOB
Definition
GenericTOB.h:35
TCS::KalmanMETCorrection::KalmanMETCorrection
KalmanMETCorrection(const std::string &name)
Definition
KalmanMETCorrection.cxx:32
TCS::KalmanMETCorrection::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition
KalmanMETCorrection.cxx:172
TCS::KalmanMETCorrection::p_MinEt
parType_t p_MinEt
Definition
KalmanMETCorrection.h:38
TCS::KalmanMETCorrection::~KalmanMETCorrection
virtual ~KalmanMETCorrection()
Definition
KalmanMETCorrection.cxx:49
TCS::KalmanMETCorrection::p_XE
parType_t p_XE[6]
Definition
KalmanMETCorrection.h:37
TCS::KalmanMETCorrection::p_correctionLut
int p_correctionLut[KFMET::nEtaBins][KFMET::nLogEtBins]
Definition
KalmanMETCorrection.h:34
TCS::KalmanMETCorrection::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition
KalmanMETCorrection.cxx:112
TCS::KalmanMETCorrection::p_NumberLeading2
parType_t p_NumberLeading2
Definition
KalmanMETCorrection.h:36
TCS::KalmanMETCorrection::initialize
virtual StatusCode initialize()
Definition
KalmanMETCorrection.cxx:53
TCS::StatusCode
Definition
Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition
Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
const
TCS::KFMET::lookupEtaBinFallback
constexpr size_t lookupEtaBinFallback
Definition
KalmanMETCorrectionConstants.h:28
TCS::KFMET::lookupEtaBin
const std::map< unsigned, size_t > lookupEtaBin
Definition
KalmanMETCorrectionConstants.h:29
TCS::KFMET::nEtaBins
constexpr unsigned nEtaBins
Definition
KalmanMETCorrectionConstants.h:18
TCS::KFMET::correctionBitWidth
constexpr unsigned correctionBitWidth
Definition
KalmanMETCorrectionConstants.h:23
TCS::KFMET::jetEtBinOffset
constexpr int jetEtBinOffset
Definition
KalmanMETCorrectionConstants.h:25
TCS::KFMET::nLogEtBins
constexpr unsigned nLogEtBins
Definition
KalmanMETCorrectionConstants.h:20
TCS::KFMET::correctionDecimalBitWidth
constexpr unsigned correctionDecimalBitWidth
Definition
KalmanMETCorrectionConstants.h:22
TCS::KFMET::nWeightWords
constexpr size_t nWeightWords
Definition
KalmanMETCorrectionConstants.h:16
TCS
Definition
AnomalyDetectionBDT.h:18
TSU::toSigned
int toSigned(unsigned bits, unsigned length)
Definition
Conversions.cxx:32
met
Definition
IMETSignificance.h:24
std
STL namespace.
TSU::Trigo::CosInt
static const std::vector< int > CosInt
Definition
Trigo.h:28
TSU::Trigo::SinInt
static const std::vector< int > SinInt
Definition
Trigo.h:29
Generated on
for ATLAS Offline Software by
1.17.0