ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCaloClusterMonitor.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3//
4// Dear emacs, this is -*- c++ -*-
5//
6
7/********************************************************************
8 *
9 * NAME: TrigCaloClusterMonitor
10 * PACKAGE: Trigger/TrigAlgorithms/TrigCaloRec
11 *
12 * AUTHOR: Nuno Fernandes
13 * CREATED: September 2024
14 *
15 * Stores the relevant information for monitoring topological clustering
16 * through monitored variables, separately from the actual algorithm.
17 *********************************************************************/
18
20
26#include "GaudiKernel/StatusCode.h"
27
28
30// CONSTRUCTOR:
32//
33TrigCaloClusterMonitor::TrigCaloClusterMonitor(const std::string & name, ISvcLocator * pSvcLocator)
34 : AthReentrantAlgorithm(name, pSvcLocator)
35{
36}
37
39{
40 if (!m_moniTool.empty()) {
41 ATH_CHECK(m_moniTool.retrieve());
42 }
43 ATH_CHECK(m_clustersKey.initialize());
44
45 ATH_CHECK(m_avgMuKey.initialize());
46
49
50 return StatusCode::SUCCESS;
51}
52
53
54StatusCode TrigCaloClusterMonitor::execute(const EventContext & ctx) const
55{
56 const auto monitoring_number = ctx.eventID().event_number();
57
58 if (monitoring_number % m_monitorInterval != 0)
59 {
60 return StatusCode::SUCCESS;
61 }
62
63 const bool really_monitor_cells = m_monitorCells && (monitoring_number % (m_monitorInterval * m_monitorCellsInterval) == 0);
64
65
67
68 const xAOD::CaloClusterContainer * cluster_collection_ptr = cluster_collection.ptr();
69
70 if (!cluster_collection.isValid())
71 {
72 ATH_MSG_ERROR("Cannot retrieve CaloClusterContainer: " << m_clustersKey.key());
73 return StatusCode::FAILURE;
74 }
75
76 std::vector<double> clus_phi;
77 std::vector<double> clus_eta;
78 std::vector<double> clus_n_bad_cells;
79 std::vector<double> clus_eng_frac_max;
80 std::vector<unsigned int> size_vec;
81 clus_phi.reserve(1024);
82 clus_eta.reserve(1024);
83 clus_n_bad_cells.reserve(1024);
84 clus_eng_frac_max.reserve(1024);
85 size_vec.reserve(1024);
86
87 auto mon_clusEt = Monitored::Collection("Et", *cluster_collection_ptr, &xAOD::CaloCluster::et);
88 auto mon_clusSignalState = Monitored::Collection("signalState", *cluster_collection_ptr, &xAOD::CaloCluster::signalState);
89 auto mon_clusSize = Monitored::Collection("clusterSize", *cluster_collection_ptr, &xAOD::CaloCluster::clusterSize);
90 auto mon_clusPhi = Monitored::Collection("Phi", clus_phi);
91 auto mon_clusEta = Monitored::Collection("Eta", clus_eta);
92 auto mon_badCells = Monitored::Collection("N_BAD_CELLS", clus_n_bad_cells);
93 auto mon_engFrac = Monitored::Collection("ENG_FRAC_MAX", clus_eng_frac_max);
94 auto mon_size = Monitored::Collection("size", size_vec);
95 auto monmu = Monitored::Scalar("mu", -999.0);
96 auto mon_container_size = Monitored::Scalar("container_size", 0);
97 auto mon_container_size_by_mu = Monitored::Scalar("container_size_by_mu", 0.);
98
99 mon_container_size = cluster_collection_ptr->size();
100
101 for (const xAOD::CaloCluster * cl : *cluster_collection_ptr)
102 {
103 const CaloClusterCellLink * num_cell_links = cl->getCellLinks();
104 if (!num_cell_links)
105 {
106 size_vec.push_back(0);
107 }
108 else
109 {
110 size_vec.push_back(num_cell_links->size());
111 }
112 clus_phi.push_back(cl->phi());
113 clus_eta.push_back(cl->eta());
114 clus_n_bad_cells.push_back(cl->getMomentValue(xAOD::CaloCluster::N_BAD_CELLS));
115 clus_eng_frac_max.push_back(cl->getMomentValue(xAOD::CaloCluster::ENG_FRAC_MAX));
116 }
117
118 float read_mu = 0;
119
121 if (eventInfoDecor.isPresent())
122 {
123 read_mu = eventInfoDecor(0);
124 monmu = read_mu;
125 }
126 else
127 {
128 ATH_MSG_WARNING("EventInfo decoration not present: " << m_avgMuKey.key());
129 }
130
131 int count_1thrsigma = 0, count_2thrsigma = 0;
132
133 if (really_monitor_cells)
134 {
135 SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
136 if ( !cell_collection.isValid() )
137 {
138 ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
139 return StatusCode::FAILURE;
140 }
141
143 const CaloNoise * noisep = *noiseHdl;
144 for (const auto cell : *cell_collection)
145 {
146 const CaloDetDescrElement * cdde = cell->caloDDE();
147
148 const bool is_tile = cdde->is_tile();
149
150 if (m_excludeTile && is_tile)
151 {
152 continue;
153 }
154
155 const float cell_energy = cell->energy();
156
157 if (cell_energy < 0)
158 {
159 continue;
160 }
161
162 const float thr = ( is_tile && m_useTwoGaussianNoise ?
163 noisep->getEffectiveSigma(cdde->identifyHash(), cell->gain(), cell_energy) :
164 noisep->getNoise(cdde->identifyHash(), cell->gain())
165 );
166
167 if (cell_energy > m_monitoring1thr * thr)
168 {
169 count_1thrsigma += 1;
170 if (cell_energy > m_monitoring2thr * thr)
171 {
172 count_2thrsigma += 1;
173 }
174 }
175 }
176 }
177
178
179 if (really_monitor_cells)
180 {
181
182 auto moncount_1thrsigma = Monitored::Scalar("count_1thrsigma", -999.0);
183 auto moncount_2thrsigma = Monitored::Scalar("count_2thrsigma", -999.0);
184 auto moncount_1thrsigma_by_mu2 = Monitored::Scalar("count_1thrsigma_by_mu2", -999.0);
185 auto moncount_2thrsigma_by_mu2 = Monitored::Scalar("count_2thrsigma_by_mu2", -999.0);
186
187
188 if (read_mu > 5)
189 {
190 const float rev_mu = 1.f / read_mu;
191 mon_container_size_by_mu = rev_mu * cluster_collection_ptr->size();
192 const float sqr_rev_mu = rev_mu * rev_mu;
193 moncount_1thrsigma_by_mu2 = sqr_rev_mu * count_1thrsigma;
194 moncount_2thrsigma_by_mu2 = sqr_rev_mu * count_2thrsigma;
195 }
196
197 moncount_1thrsigma = count_1thrsigma;
198 moncount_2thrsigma = count_2thrsigma;
199
200 auto monitorIt = Monitored::Group( m_moniTool, mon_container_size, mon_clusEt, mon_clusPhi, mon_clusEta,
201 mon_clusSignalState, mon_clusSize, mon_badCells, mon_engFrac, mon_size,
202 monmu, mon_container_size_by_mu, moncount_1thrsigma, moncount_2thrsigma,
203 moncount_1thrsigma_by_mu2, moncount_2thrsigma_by_mu2 );
204 }
205 else
206 {
207 if (read_mu > 5)
208 {
209 mon_container_size_by_mu = cluster_collection_ptr->size() / read_mu;
210 }
211 auto monitorIt = Monitored::Group( m_moniTool, mon_container_size, mon_clusEt, mon_clusPhi, mon_clusEta,
212 mon_clusSignalState, mon_clusSize, mon_badCells, mon_engFrac, mon_size,
213 monmu, mon_container_size_by_mu);
214 }
215
216 return StatusCode::SUCCESS;
217}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
Handle class for reading a decoration on an object.
An algorithm that can be simultaneously executed in multiple threads.
This class groups all DetDescr information related to a CaloCell.
IdentifierHash identifyHash() const override final
cell subcalo hash same as subcalo_hash(), but kept for backward compatibility
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition CaloNoise.h:34
float getEffectiveSigma(const Identifier id, const int gain, const float energy) const
Definition CaloNoise.h:55
size_type size() const noexcept
Returns the number of elements in the collection.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
Handle class for reading a decoration on an object.
bool isPresent() const
Is the referenced container present in SG?
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & name() const
Return the StoreGate ID for the referenced object.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_avgMuKey
Event input: To get <mu> from Event Info.
Gaudi::Property< bool > m_excludeTile
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
TrigCaloClusterMonitor(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersKey
The name of the key in StoreGate for the CaloClusterContainer we want to monitor.
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
Gaudi::Property< unsigned int > m_monitorCellsInterval
Gaudi::Property< float > m_monitoring2thr
Gaudi::Property< float > m_monitoring1thr
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Gaudi::Property< bool > m_monitorCells
Gaudi::Property< bool > m_useTwoGaussianNoise
Gaudi::Property< unsigned int > m_monitorInterval
ToolHandle< GenericMonitoringTool > m_moniTool
Monitoring tool.
ClusterSize clusterSize() const
Get cluster size.
State signalState() const
Get the current signal state.
@ N_BAD_CELLS
number of bad cells
@ ENG_FRAC_MAX
Energy fraction of hottest cell.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.