ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
Muon
L1MuonNSW
src
NSWEncoding.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef L1MUONNSW_NSWENCODING_H
6
#define L1MUONNSW_NSWENCODING_H
7
8
#include "
xAODTrigL1Muon/NSWTPBits.h
"
9
10
#include <algorithm>
11
#include <cmath>
12
#include <cstdint>
13
#include <numbers>
14
24
namespace
L1Muon::NSWEncoding
{
25
26
constexpr
double
kTwoPi
= 2. * std::numbers::pi;
27
29
inline
double
wrapTwoPi
(
double
phi
) {
30
phi
= std::fmod(
phi
,
kTwoPi
);
31
return
(
phi
< 0.) ?
phi
+
kTwoPi
:
phi
;
32
}
33
34
// ---------------------------------------------------------------------------------------
35
// eta: 14 bits over [ETA_MIN, ETA_MAX]; nearest bin. Same scale as L1NSWCandData_v1::segEta().
36
// The NSW covers 1.3 < |eta| < 2.7, so inRange is false only for a broken input.
37
// ---------------------------------------------------------------------------------------
38
inline
uint16_t
etaIndex
(
double
eta
,
bool
&
inRange
) {
39
using namespace
L1Muon::NSWTPBits
;
40
const
double
x
= (
eta
-
ETA_MIN
) / (
ETA_MAX
-
ETA_MIN
) *
ETA_MAX_RAW
;
41
inRange
= (
x
>= -0.5 &&
x
<=
ETA_MAX_RAW
+ 0.5);
42
return
static_cast<
uint16_t
>
(std::clamp(std::round(
x
), 0.,
static_cast<
double
>
(
ETA_MAX_RAW
)));
43
}
44
inline
double
etaValue
(uint16_t idx) {
45
using namespace
L1Muon::NSWTPBits
;
46
return
ETA_MIN
+ (idx /
static_cast<
double
>
(
ETA_MAX_RAW
)) * (
ETA_MAX
-
ETA_MIN
);
47
}
48
49
// ---------------------------------------------------------------------------------------
50
// phi: 10 bits over [0, 2pi]; nearest bin. Same scale as L1NSWCandData_v1::segPhi().
51
// PHI_MAX_RAW = 1023, so index 1023 decodes to 2pi, the same direction as index 0. Whether the
52
// hardware divides 2pi in 1023 or 1024 steps is to be confirmed with the NSW-TP firmware.
53
// Never out of range: the angle is wrapped first.
54
// ---------------------------------------------------------------------------------------
55
inline
uint16_t
phiIndex
(
double
phi
) {
56
using namespace
L1Muon::NSWTPBits
;
57
const
double
x
=
wrapTwoPi
(
phi
) /
PHI_MAX
*
PHI_MAX_RAW
;
58
return
static_cast<
uint16_t
>
(std::clamp(std::round(
x
), 0.,
static_cast<
double
>
(
PHI_MAX_RAW
)));
59
}
60
inline
double
phiValue
(uint16_t idx) {
61
using namespace
L1Muon::NSWTPBits
;
62
return
(idx /
static_cast<
double
>
(
PHI_MAX_RAW
)) *
PHI_MAX
;
63
}
64
65
// ---------------------------------------------------------------------------------------
66
// Delta theta: 5 bits, sign-magnitude. [4] sign (0:+, 1:-), [3:0] |value| in steps of `step`.
67
// '+0' is used for 0, '-0' is never produced (interface document, Figure 13).
68
// With step = 1 mrad the 4 magnitude bits cover |dtheta| <= 15 mrad, the Run 3 range.
69
// Out of range (|dtheta| > range): the segment is KEPT and the magnitude saturates at 15,
70
// keeping the sign. (Run 3 encoded out-of-range values as index 0, i.e. -15 mrad, and also
71
// kept the segment.) inRange reports it, so it can be counted.
72
// ---------------------------------------------------------------------------------------
73
constexpr
unsigned
kDthMagMax
= 15;
74
constexpr
uint8_t
kDthSignBit
= 0x10;
75
76
inline
uint8_t
dthetaIndex
(
double
dtheta,
double
step,
double
range,
bool
&
inRange
) {
77
inRange
= std::abs(dtheta) <= range;
78
const
double
mag
= std::min(std::round(std::abs(dtheta) / step),
static_cast<
double
>
(
kDthMagMax
));
79
const
uint8_t
sign
= (dtheta < 0. &&
mag
> 0.) ?
kDthSignBit
: 0;
80
return
sign
|
static_cast<
uint8_t
>
(
mag
);
81
}
82
inline
double
dthetaValue
(uint8_t idx,
double
step) {
83
const
double
mag
= (idx & 0xF) * step;
84
return
(idx &
kDthSignBit
) ? -
mag
:
mag
;
85
}
86
87
// ---------------------------------------------------------------------------------------
88
// Quality flag (3 bits): 0 invalid/no segment, 1 sTGC pad, 2 sTGC strip, 3 MM, 4 combination
89
// ---------------------------------------------------------------------------------------
90
constexpr
uint8_t
kQualityMM
= 3;
91
92
// ---------------------------------------------------------------------------------------
93
// Board ID (7 bits). Provisional mapping, until the assignment of the NSW-TP boards to the
94
// sectors is defined (interface document, Section 4.2): one board per NSW sector and side,
95
// boardID = 16*side + (sector-1), side 0 = A, 1 = C -> 0..31.
96
// The Run 4 frame has no side field, so the side has to be carried here.
97
// (Run 3 NSW_TrigRawData: sectorId = sector-1, side as a separate char.)
98
// ---------------------------------------------------------------------------------------
99
inline
uint16_t
boardID
(
int
sectorPhi,
bool
isSideC) {
100
return
static_cast<
uint16_t
>
((isSideC ? 16 : 0) + (sectorPhi - 1));
101
}
102
103
}
// namespace L1Muon::NSWEncoding
104
105
#endif
// L1MUONNSW_NSWENCODING_H
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
mag
Scalar mag() const
mag method
Definition
AmgMatrixBasePlugin.h:26
inRange
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
Definition
LArSCIdVsIdTest.cxx:5
NSWTPBits.h
sign
int sign(int a)
Definition
TRT_StrawNeighbourSvc.h:108
x
#define x
L1Muon::NSWEncoding
Quantisation of NSW segment quantities into the Run 4 NSW-TP -> TGC-SL segment word (L1Muon interface...
Definition
NSWEncoding.h:24
L1Muon::NSWEncoding::dthetaValue
double dthetaValue(uint8_t idx, double step)
Definition
NSWEncoding.h:82
L1Muon::NSWEncoding::etaValue
double etaValue(uint16_t idx)
Definition
NSWEncoding.h:44
L1Muon::NSWEncoding::phiIndex
uint16_t phiIndex(double phi)
Definition
NSWEncoding.h:55
L1Muon::NSWEncoding::etaIndex
uint16_t etaIndex(double eta, bool &inRange)
Definition
NSWEncoding.h:38
L1Muon::NSWEncoding::boardID
uint16_t boardID(int sectorPhi, bool isSideC)
Definition
NSWEncoding.h:99
L1Muon::NSWEncoding::phiValue
double phiValue(uint16_t idx)
Definition
NSWEncoding.h:60
L1Muon::NSWEncoding::kDthMagMax
constexpr unsigned kDthMagMax
Definition
NSWEncoding.h:73
L1Muon::NSWEncoding::dthetaIndex
uint8_t dthetaIndex(double dtheta, double step, double range, bool &inRange)
Definition
NSWEncoding.h:76
L1Muon::NSWEncoding::kDthSignBit
constexpr uint8_t kDthSignBit
Definition
NSWEncoding.h:74
L1Muon::NSWEncoding::wrapTwoPi
double wrapTwoPi(double phi)
Map any angle to [0, 2pi).
Definition
NSWEncoding.h:29
L1Muon::NSWEncoding::kQualityMM
constexpr uint8_t kQualityMM
Definition
NSWEncoding.h:90
L1Muon::NSWEncoding::kTwoPi
constexpr double kTwoPi
Definition
NSWEncoding.h:26
L1Muon::NSWTPBits
Definition
NSWTPBits.h:8
L1Muon::NSWTPBits::PHI_MAX
constexpr float PHI_MAX
Definition
NSWTPBits.h:24
L1Muon::NSWTPBits::ETA_MAX
constexpr float ETA_MAX
Definition
NSWTPBits.h:17
L1Muon::NSWTPBits::ETA_MIN
constexpr float ETA_MIN
Definition
NSWTPBits.h:16
L1Muon::NSWTPBits::PHI_MAX_RAW
constexpr float PHI_MAX_RAW
Definition
NSWTPBits.h:23
L1Muon::NSWTPBits::ETA_MAX_RAW
constexpr float ETA_MAX_RAW
Definition
NSWTPBits.h:15
Generated on
for ATLAS Offline Software by
1.17.0