ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloRec
src
CaloClusterMLCalibAlgLite.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 "
CaloClusterMLCalibAlgLite.h
"
6
#include "
StoreGate/ReadHandle.h
"
7
#include "
StoreGate/WriteDecorHandle.h
"
8
#include "
AthContainers/ConstDataVector.h
"
9
10
CaloClusterMLCalibAlgLite::CaloClusterMLCalibAlgLite
(
const
std::string &name, ISvcLocator *pSvcLocator)
11
:
AthReentrantAlgorithm
(name, pSvcLocator)
12
{
13
}
14
15
StatusCode
CaloClusterMLCalibAlgLite::initialize
()
16
{
17
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
18
19
ATH_CHECK
(
m_calibTool
.retrieve());
20
ATH_CHECK
(
m_eventInfoKey
.initialize());
21
ATH_CHECK
(
m_verticesKey
.initialize());
22
ATH_CHECK
(
m_clusterContainerKey
.initialize());
23
ATH_CHECK
(
m_clusterMLCalibEnergyDecorKey
.initialize());
24
ATH_CHECK
(
m_clusterMLCalibEnergyUncDecorKey
.initialize());
25
26
ATH_MSG_INFO
(
"ML calibration will be applied for clusters within ["
<<
m_rapidityRange
[0] <<
","
<<
m_rapidityRange
[1] <<
"]"
);
27
ATH_MSG_INFO
(
"ML calibration will be applied for clusters with energy >= "
<<
m_minClusterEnergy
<<
" MeV"
);
28
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
CaloClusterMLCalibAlgLite::finalize
()
33
{
34
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
35
return
StatusCode::SUCCESS;
36
}
37
38
StatusCode
CaloClusterMLCalibAlgLite::execute
(
const
EventContext &ctx)
const
39
{
40
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
41
42
SG::WriteDecorHandle<xAOD::CaloClusterContainer, double>
clusterMLCalibEnergyDecor(
m_clusterMLCalibEnergyDecorKey
, ctx);
43
SG::WriteDecorHandle<xAOD::CaloClusterContainer, double>
clusterMLCalibEnergyUncDecor(
m_clusterMLCalibEnergyUncDecorKey
, ctx);
44
45
// -- get the input
46
SG::ReadHandle<xAOD::CaloClusterContainer>
clusterReadHandle(
m_clusterContainerKey
, ctx);
47
if
(!clusterReadHandle.
isValid
())
48
{
49
ATH_MSG_ERROR
(
"cannot allocate the input cluster container with key <"
<<
m_clusterContainerKey
.key() <<
">"
);
50
return
StatusCode::FAILURE;
51
}
52
53
SG::ReadHandle<xAOD::EventInfo>
eventInfo(
m_eventInfoKey
, ctx);
54
SG::ReadHandle<xAOD::VertexContainer>
vertices(
m_verticesKey
, ctx);
55
56
float
avgMu = eventInfo->actualInteractionsPerCrossing();
57
int
nPrimVtx = 0;
58
for
(
auto
vtx : *vertices)
59
{
60
if
(vtx->vertexType() ==
xAOD::VxType::PriVtx
|| vtx->vertexType() ==
xAOD::VxType::PileUp
)
61
++nPrimVtx;
62
}
63
64
// only run inference for clusters passing cuts
65
ConstDataVector<xAOD::CaloClusterContainer>
selectedClusters(
SG::VIEW_ELEMENTS
);
66
std::vector<bool> clusterMask(clusterReadHandle->size(),
false
);
67
for
(
const
xAOD::CaloCluster
*cluster : *clusterReadHandle) {
68
if
(
m_rapidityRange
.size() == 2) {
69
const
double
eta
= cluster->eta(
xAOD::CaloCluster::UNCALIBRATED
);
70
if
(
eta
<
m_rapidityRange
[0] ||
eta
>
m_rapidityRange
[1])
continue
;
71
}
72
// minimum cluster energy cut; in MeV
73
const
double
energy = cluster->rawE();
74
if
(energy <
m_minClusterEnergy
)
continue
;
75
76
selectedClusters.
push_back
(cluster);
77
clusterMask.at(cluster->index()) =
true
;
78
}
79
80
std::vector<double> clusterE_ML_vec;
81
std::vector<double> clusterE_ML_Unc_vec;
82
83
ATH_CHECK
(
m_calibTool
->inference(*selectedClusters.
asDataVector
(), nPrimVtx, avgMu, clusterE_ML_vec, clusterE_ML_Unc_vec));
84
85
size_t
i = 0;
86
for
(
const
xAOD::CaloCluster
*cluster : *clusterReadHandle)
87
{
88
if
(clusterMask.at(cluster->index()))
89
{
90
clusterMLCalibEnergyDecor(*cluster) = clusterE_ML_vec[i];
91
clusterMLCalibEnergyUncDecor(*cluster) = clusterE_ML_Unc_vec[i];
92
++i;
93
}
94
else
95
{
96
clusterMLCalibEnergyDecor(*cluster) = cluster->rawE();
97
clusterMLCalibEnergyUncDecor(*cluster) = 0.0;
98
}
99
}
100
101
return
StatusCode::SUCCESS;
102
}
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
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:32
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:30
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:28
CaloClusterMLCalibAlgLite.h
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
CaloClusterMLCalibAlgLite::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
CaloClusterMLCalibAlgLite.h:40
CaloClusterMLCalibAlgLite::finalize
StatusCode finalize() override
Definition
CaloClusterMLCalibAlgLite.cxx:32
CaloClusterMLCalibAlgLite::CaloClusterMLCalibAlgLite
CaloClusterMLCalibAlgLite(const std::string &name, ISvcLocator *pSvcLocator)
Definition
CaloClusterMLCalibAlgLite.cxx:10
CaloClusterMLCalibAlgLite::m_clusterMLCalibEnergyUncDecorKey
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_clusterMLCalibEnergyUncDecorKey
Definition
CaloClusterMLCalibAlgLite.h:45
CaloClusterMLCalibAlgLite::m_minClusterEnergy
Gaudi::Property< double > m_minClusterEnergy
Definition
CaloClusterMLCalibAlgLite.h:49
CaloClusterMLCalibAlgLite::m_clusterMLCalibEnergyDecorKey
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_clusterMLCalibEnergyDecorKey
Definition
CaloClusterMLCalibAlgLite.h:44
CaloClusterMLCalibAlgLite::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition
CaloClusterMLCalibAlgLite.h:41
CaloClusterMLCalibAlgLite::initialize
StatusCode initialize() override
Definition
CaloClusterMLCalibAlgLite.cxx:15
CaloClusterMLCalibAlgLite::m_rapidityRange
Gaudi::Property< std::vector< float > > m_rapidityRange
Definition
CaloClusterMLCalibAlgLite.h:47
CaloClusterMLCalibAlgLite::execute
StatusCode execute(const EventContext &ctx) const override
Definition
CaloClusterMLCalibAlgLite.cxx:38
CaloClusterMLCalibAlgLite::m_clusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Definition
CaloClusterMLCalibAlgLite.h:42
CaloClusterMLCalibAlgLite::m_calibTool
ToolHandle< ICaloClusterMLCalibToolLite > m_calibTool
Definition
CaloClusterMLCalibAlgLite.h:35
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition
ConstDataVector.h:76
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::CaloCluster_v1::UNCALIBRATED
@ UNCALIBRATED
Definition
CaloCluster_v1.h:309
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition
OwnershipPolicy.h:18
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition
TrackingPrimitives.h:592
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition
TrackingPrimitives.h:590
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition
Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
Generated on
for ATLAS Offline Software by
1.17.0