ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
src
CleanHitDecoratorAlg.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 "
FlavorTagDiscriminants/CleanHitDecoratorAlg.h
"
6
7
#include "
StoreGate/ReadHandle.h
"
8
#include "
StoreGate/ReadDecorHandle.h
"
9
#include "
StoreGate/WriteDecorHandle.h
"
10
11
#include "
AthContainers/AuxElement.h
"
12
13
#include <algorithm>
14
#include <cmath>
15
#include <limits>
16
#include <optional>
17
18
namespace
{
19
20
struct
HitPos {
21
float
z;
22
float
phi;
23
unsigned
long
deid;
24
int
layer;
25
};
26
27
inline
float
deltaPhi
(
const
HitPos&
a
,
const
HitPos& b) {
28
float
d
=
b
.phi -
a
.phi;
29
if
(d >
M_PI
)
d
-= 2*
M_PI
;
30
else
if
(d <= -
M_PI
)
d
+= 2*
M_PI
;
31
return
d
;
32
}
33
34
inline
bool
isGoodHit
(
35
const
xAOD::TrackMeasurementValidation
*
h
,
36
const
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, char>
& isFakeHandle,
37
const
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>
& hasBSErrHandle,
38
const
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>
& DCSStateHandle) {
39
if
(isFakeHandle(*
h
))
return
false
;
40
if
(hasBSErrHandle(*
h
))
return
false
;
41
if
(DCSStateHandle(*
h
))
return
false
;
42
return
true
;
43
}
44
45
}
46
47
namespace
FlavorTagDiscriminants
{
48
49
CleanHitDecoratorAlg::CleanHitDecoratorAlg
(
const
std::string& name, ISvcLocator* svcLoc)
50
:
AthReentrantAlgorithm
(name, svcLoc) {}
51
52
StatusCode
CleanHitDecoratorAlg::initialize
() {
53
ATH_MSG_DEBUG
(
"Initializing "
<< name());
54
55
ATH_CHECK
(
m_hitContainer
.initialize());
56
57
ATH_CHECK
(
m_cleanHitKey
.initialize());
58
59
// The goodness decorations exist only on pixel hits
60
ATH_CHECK
(
m_isFakeKey
.initialize(!
m_isSCT
));
61
ATH_CHECK
(
m_hasBSErrKey
.initialize(!
m_isSCT
));
62
ATH_CHECK
(
m_DCSStateKey
.initialize(!
m_isSCT
));
63
64
// The geometry decorations are read only by the overlap removal
65
ATH_CHECK
(
m_becKey
.initialize(
m_doOverlapRemoval
));
66
ATH_CHECK
(
m_deidKey
.initialize(
m_doOverlapRemoval
));
67
ATH_CHECK
(
m_layerKey
.initialize(
m_doOverlapRemoval
));
68
69
return
StatusCode::SUCCESS;
70
}
71
72
StatusCode
CleanHitDecoratorAlg::execute
(
const
EventContext& ctx)
const
{
73
// Read hits
74
SG::ReadHandle<xAOD::TrackMeasurementValidationContainer>
hits(
m_hitContainer
, ctx);
75
if
(!hits.isValid()) {
76
ATH_MSG_ERROR
(
"Failed to retrieve "
<<
m_hitContainer
.key());
77
return
StatusCode::FAILURE;
78
}
79
80
// Decoration handle
81
SG::WriteDecorHandle<xAOD::TrackMeasurementValidationContainer, int>
82
cleanDeco(
m_cleanHitKey
, ctx);
83
84
std::optional<SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, char>>
85
isFakeHandle;
86
std::optional<SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>>
87
hasBSErrHandle;
88
std::optional<SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>>
89
DCSStateHandle;
90
if
(!
m_isSCT
) {
91
isFakeHandle.emplace(
m_isFakeKey
, ctx);
92
hasBSErrHandle.emplace(
m_hasBSErrKey
, ctx);
93
DCSStateHandle.emplace(
m_DCSStateKey
, ctx);
94
}
95
96
// Without overlap removal the flag depends only on the hit itself, so neither
97
// the geometry nor the ordering is needed
98
if
(!
m_doOverlapRemoval
) {
99
for
(
const
xAOD::TrackMeasurementValidation
*
hit
: *hits) {
100
cleanDeco(*
hit
) =
101
(
m_isSCT
|| isGoodHit(
hit
, *isFakeHandle, *hasBSErrHandle, *DCSStateHandle)) ? 1 : 0;
102
}
103
return
StatusCode::SUCCESS;
104
}
105
106
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>
107
becHandle(
m_becKey
, ctx);
108
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, unsigned long>
109
deidHandle(
m_deidKey
, ctx);
110
SG::ReadDecorHandle<xAOD::TrackMeasurementValidationContainer, int>
111
layerHandle(
m_layerKey
, ctx);
112
113
std::vector<std::pair<float, const xAOD::TrackMeasurementValidation*>> hits_sorted;
114
hits_sorted.reserve(hits->size());
115
116
for
(
const
xAOD::TrackMeasurementValidation
*
hit
: *hits) {
117
hits_sorted.emplace_back(
hit
->localX(),
hit
);
118
}
119
120
std::ranges::sort(hits_sorted);
121
122
std::vector<std::vector<HitPos>> savedHits;
123
124
for
(
const
auto
& [localX,
hit
] : hits_sorted) {
125
126
int
cleanFlag = 1;
127
128
// Extract geometry
129
HitPos hp;
130
hp.z =
hit
->globalZ();
131
hp.phi = std::atan2(
hit
->globalY(),
hit
->globalX());
132
hp.deid = deidHandle(*
hit
);
133
hp.layer = layerHandle(*
hit
);
134
135
const
bool
isBarrel = (becHandle(*
hit
) == 0);
136
137
// Overlap evaluation
138
const
float
dZcut = 20.f;
139
const
float
dPhicut = isBarrel ? 0.004f : std::numeric_limits<float>::max();
140
141
if
(
static_cast<
size_t
>
(hp.layer) >= savedHits.size()) {
142
savedHits.resize(hp.layer + 1);
143
}
144
145
auto
& layerHits = savedHits[hp.layer];
146
147
for
(
const
HitPos& prev : layerHits) {
148
149
// Skip hits from the same module
150
if
(prev.deid == hp.deid)
151
continue
;
152
153
const
float
dphi = std::abs(
deltaPhi
(prev, hp));
154
const
float
dz = std::abs(prev.z - hp.z);
155
156
if
(dphi < dPhicut && dz < dZcut) {
157
cleanFlag = 0;
158
break
;
159
}
160
}
161
162
// Mark bad hits
163
if
(!
m_isSCT
&& !isGoodHit(
hit
, *isFakeHandle, *hasBSErrHandle, *DCSStateHandle)) {
164
cleanFlag = 0;
165
}
166
167
// Write decoration
168
cleanDeco(*
hit
) = cleanFlag;
169
170
// Save for next comparisons
171
layerHits.push_back(hp);
172
}
173
174
return
StatusCode::SUCCESS;
175
}
176
177
}
M_PI
#define M_PI
Definition
ActiveFraction.h:14
deltaPhi
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:112
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
AuxElement.h
Base class for elements of a container that can have aux data.
CleanHitDecoratorAlg.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
ReadDecorHandle.h
Handle class for reading a decoration on an object.
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
h
Header file for AthHistogramAlgorithm.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagDiscriminants::CleanHitDecoratorAlg::CleanHitDecoratorAlg
CleanHitDecoratorAlg(const std::string &name, ISvcLocator *svcLoc)
Definition
CleanHitDecoratorAlg.cxx:49
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_deidKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_deidKey
Definition
CleanHitDecoratorAlg.h:53
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_doOverlapRemoval
Gaudi::Property< bool > m_doOverlapRemoval
Definition
CleanHitDecoratorAlg.h:67
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_hasBSErrKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_hasBSErrKey
Definition
CleanHitDecoratorAlg.h:47
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_DCSStateKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_DCSStateKey
Definition
CleanHitDecoratorAlg.h:50
FlavorTagDiscriminants::CleanHitDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
CleanHitDecoratorAlg.cxx:52
FlavorTagDiscriminants::CleanHitDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
CleanHitDecoratorAlg.cxx:72
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_hitContainer
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_hitContainer
Definition
CleanHitDecoratorAlg.h:37
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_isSCT
Gaudi::Property< bool > m_isSCT
Definition
CleanHitDecoratorAlg.h:64
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_becKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_becKey
Definition
CleanHitDecoratorAlg.h:41
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_layerKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_layerKey
Definition
CleanHitDecoratorAlg.h:56
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_isFakeKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_isFakeKey
Definition
CleanHitDecoratorAlg.h:44
FlavorTagDiscriminants::CleanHitDecoratorAlg::m_cleanHitKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_cleanHitKey
Definition
CleanHitDecoratorAlg.h:60
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
FlavorTagDiscriminants
Definition
CaloChargedFlowDecoratorAlg.h:15
MuonR4::isGoodHit
bool isGoodHit(const CalibratedSpacePoint &hit)
Returns whether the calibrated spacepoint is valid and therefore suitable to be used in the segment f...
Definition
SpacePointHelpers.cxx:16
hist_file_dump.d
d
Definition
hist_file_dump.py:142
plotBeamSpotMon.b
b
Definition
plotBeamSpotMon.py:76
xAOD::TrackMeasurementValidation
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Definition
TrackMeasurementValidation.h:13
Generated on
for ATLAS Offline Software by
1.17.0