ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10CaloClusterMLCalibAlgLite::CaloClusterMLCalibAlgLite(const std::string &name, ISvcLocator *pSvcLocator)
11 : AthReentrantAlgorithm(name, pSvcLocator)
12{
13}
14
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());
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
33{
34 ATH_MSG_INFO("Finalizing " << name() << "...");
35 return StatusCode::SUCCESS;
36}
37
38StatusCode CaloClusterMLCalibAlgLite::execute(const EventContext &ctx) const
39{
40 ATH_MSG_DEBUG("Executing " << name() << "...");
41
44
45 // -- get the input
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
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
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}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
CaloClusterMLCalibAlgLite(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_clusterMLCalibEnergyUncDecorKey
Gaudi::Property< double > m_minClusterEnergy
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_clusterMLCalibEnergyDecorKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Gaudi::Property< std::vector< float > > m_rapidityRange
StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
ToolHandle< ICaloClusterMLCalibToolLite > m_calibTool
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
@ PileUp
Pile-up vertex.
@ PriVtx
Primary vertex.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.