ATLAS Offline Software
TrigCaloClusterMonitor.cxx
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2024 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 
19 #include "GaudiKernel/StatusCode.h"
20 
22 
23 #include "TrigCaloClusterMonitor.h"
24 
25 
27 // CONSTRUCTOR:
29 //
30 TrigCaloClusterMonitor::TrigCaloClusterMonitor(const std::string & name, ISvcLocator * pSvcLocator)
31  : AthReentrantAlgorithm(name, pSvcLocator)
32 {
33 }
34 
36 {
37  CHECK(m_moniTool.retrieve());
39 
40  ATH_CHECK(m_avgMuKey.initialize());
41 
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 
49 StatusCode TrigCaloClusterMonitor::execute(const EventContext & ctx) const
50 {
51  const auto monitoring_number = ctx.eventID().event_number();
52 
53  if (monitoring_number % m_monitorInterval != 0)
54  {
55  return StatusCode::SUCCESS;
56  }
57 
58  const bool really_monitor_cells = m_monitorCells && (monitoring_number % (m_monitorInterval * m_monitorCellsInterval) == 0);
59 
60 
62 
63  const xAOD::CaloClusterContainer * cluster_collection_ptr = cluster_collection.ptr();
64 
65  if (!cluster_collection.isValid())
66  {
67  ATH_MSG_ERROR("Cannot retrieve CaloClusterContainer: " << m_clustersKey.key());
68  return StatusCode::FAILURE;
69  }
70 
71 
72  auto time_tot = Monitored::Timer("TIME_execute");
73  auto time_clusMaker = Monitored::Timer("TIME_ClustMaker");
74  auto time_clusCorr = Monitored::Timer("TIME_ClustCorr");
75 
76  time_tot.start();
77  time_clusMaker.start();
78  time_clusCorr.start();
79  time_clusMaker.stop();
80  time_clusCorr.stop();
81  time_tot.stop();
82 
83  //Dummy values: We will need to find a better way to monitor the times
84  // (maybe leveraging whatever cost monitoring does?)
85  //
86  //We could add also some monitoring to cluster making itself,
87  //as that would probably be the only good way to get the time
88  //for the actual clustering and the corrections separately,
89  //but this would mean further modifications to the offline algorithm,
90  //which we likely want to avoid, also because it might be more of a mess
91  //to get the histograms in the right places?
92 
93  std::vector<double> clus_phi;
94  std::vector<double> clus_eta;
95  std::vector<double> clus_n_bad_cells;
96  std::vector<double> clus_eng_frac_max;
97  std::vector<unsigned int> size_vec;
98  clus_phi.reserve(1024);
99  clus_eta.reserve(1024);
100  clus_n_bad_cells.reserve(1024);
101  clus_eng_frac_max.reserve(1024);
102  size_vec.reserve(1024);
103 
104  auto mon_clusEt = Monitored::Collection("Et", *cluster_collection_ptr, &xAOD::CaloCluster::et);
105  auto mon_clusSignalState = Monitored::Collection("signalState", *cluster_collection_ptr, &xAOD::CaloCluster::signalState);
106  auto mon_clusSize = Monitored::Collection("clusterSize", *cluster_collection_ptr, &xAOD::CaloCluster::clusterSize);
107  auto mon_clusPhi = Monitored::Collection("Phi", clus_phi);
108  auto mon_clusEta = Monitored::Collection("Eta", clus_eta);
109  auto mon_badCells = Monitored::Collection("N_BAD_CELLS", clus_n_bad_cells);
110  auto mon_engFrac = Monitored::Collection("ENG_FRAC_MAX", clus_eng_frac_max);
111  auto mon_size = Monitored::Collection("size", size_vec);
112  auto monmu = Monitored::Scalar("mu", -999.0);
113  auto mon_container_size = Monitored::Scalar("container_size", 0);
114  auto mon_container_size_by_mu = Monitored::Scalar("container_size_by_mu", 0.);
115 
116  mon_container_size = cluster_collection_ptr->size();
117 
118  for (const xAOD::CaloCluster * cl : *cluster_collection_ptr)
119  {
120  const CaloClusterCellLink * num_cell_links = cl->getCellLinks();
121  if (!num_cell_links)
122  {
123  size_vec.push_back(0);
124  }
125  else
126  {
127  size_vec.push_back(num_cell_links->size());
128  }
129  clus_phi.push_back(cl->phi());
130  clus_eta.push_back(cl->eta());
131  clus_n_bad_cells.push_back(cl->getMomentValue(xAOD::CaloCluster::N_BAD_CELLS));
132  clus_eng_frac_max.push_back(cl->getMomentValue(xAOD::CaloCluster::ENG_FRAC_MAX));
133  }
134 
135  float read_mu = 0;
136 
138  if (eventInfoDecor.isPresent())
139  {
140  read_mu = eventInfoDecor(0);
141  monmu = read_mu;
142  }
143  else
144  {
145  ATH_MSG_WARNING("EventInfo decoration not present: " << m_avgMuKey.key());
146  }
147 
148  int count_1thrsigma = 0, count_2thrsigma = 0;
149 
150  if (really_monitor_cells)
151  {
152  SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
153  if ( !cell_collection.isValid() )
154  {
155  ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
156  return StatusCode::FAILURE;
157  }
158 
160  const CaloNoise * noisep = *noiseHdl;
161  for (const auto & cell : *cell_collection)
162  {
163  const CaloDetDescrElement * cdde = cell->caloDDE();
164 
165  const bool is_tile = cdde->is_tile();
166 
167  if (m_excludeTile && is_tile)
168  {
169  continue;
170  }
171 
172  const float cell_energy = cell->energy();
173 
174  if (cell_energy < 0)
175  {
176  continue;
177  }
178 
179  const float thr = ( is_tile && m_useTwoGaussianNoise ?
180  noisep->getEffectiveSigma(cdde->identifyHash(), cell->gain(), cell_energy) :
181  noisep->getNoise(cdde->identifyHash(), cell->gain())
182  );
183 
184  if (cell_energy > m_monitoring1thr * thr)
185  {
186  count_1thrsigma += 1;
187  if (cell_energy > m_monitoring2thr * thr)
188  {
189  count_2thrsigma += 1;
190  }
191  }
192  }
193  }
194 
195 
196  if (really_monitor_cells)
197  {
198 
199  auto moncount_1thrsigma = Monitored::Scalar("count_1thrsigma", -999.0);
200  auto moncount_2thrsigma = Monitored::Scalar("count_2thrsigma", -999.0);
201  auto moncount_1thrsigma_by_mu2 = Monitored::Scalar("count_1thrsigma_by_mu2", -999.0);
202  auto moncount_2thrsigma_by_mu2 = Monitored::Scalar("count_2thrsigma_by_mu2", -999.0);
203 
204 
205  if (read_mu > 5)
206  {
207  const float rev_mu = 1.f / read_mu;
208  mon_container_size_by_mu = rev_mu * cluster_collection_ptr->size();
209  const float sqr_rev_mu = rev_mu * rev_mu;
210  moncount_1thrsigma_by_mu2 = sqr_rev_mu * count_1thrsigma;
211  moncount_2thrsigma_by_mu2 = sqr_rev_mu * count_2thrsigma;
212  }
213 
214  moncount_1thrsigma = count_1thrsigma;
215  moncount_2thrsigma = count_2thrsigma;
216 
217  auto monitorIt = Monitored::Group( m_moniTool, time_tot, time_clusMaker, time_clusCorr, mon_container_size,
218  mon_clusEt, mon_clusPhi, mon_clusEta, mon_clusSignalState, mon_clusSize,
219  mon_badCells, mon_engFrac, mon_size, monmu, mon_container_size_by_mu,
220  moncount_1thrsigma, moncount_2thrsigma, moncount_1thrsigma_by_mu2, moncount_2thrsigma_by_mu2 );
221  }
222  else
223  {
224  if (read_mu > 5)
225  {
226  mon_container_size_by_mu = cluster_collection_ptr->size() / read_mu;
227  }
228  auto monitorIt = Monitored::Group( m_moniTool, time_tot, time_clusMaker, time_clusCorr, mon_container_size,
229  mon_clusEt, mon_clusPhi, mon_clusEta, mon_clusSignalState, mon_clusSize,
230  mon_badCells, mon_engFrac, mon_size, monmu, mon_container_size_by_mu);
231  }
232 
233  return StatusCode::SUCCESS;
234 }
TrigCaloClusterMonitor::m_monitoring1thr
Gaudi::Property< float > m_monitoring1thr
Definition: TrigCaloClusterMonitor.h:60
CaloNoise::getEffectiveSigma
float getEffectiveSigma(const Identifier id, const int gain, const float energy) const
Definition: CaloNoise.h:55
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
TrigCaloClusterMonitor::m_cellsKey
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Definition: TrigCaloClusterMonitor.h:80
SG::ReadDecorHandle::isPresent
bool isPresent() const
Is the referenced container present in SG?
xAOD::CaloCluster_v1::et
double et() const
Definition: CaloCluster_v1.h:856
xAOD::CaloCluster_v1::signalState
State signalState() const
Get the current signal state.
Definition: CaloCluster_v1.h:633
TrigCaloClusterMonitor::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Definition: TrigCaloClusterMonitor.h:68
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TrigCaloClusterMonitor::m_monitorInterval
Gaudi::Property< unsigned int > m_monitorInterval
Definition: TrigCaloClusterMonitor.h:64
xAOD::CaloCluster_v1::ENG_FRAC_MAX
@ ENG_FRAC_MAX
Energy fraction of hottest cell.
Definition: CaloCluster_v1.h:140
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
TrigCaloClusterMonitor::TrigCaloClusterMonitor
TrigCaloClusterMonitor(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigCaloClusterMonitor.cxx:30
TrigCaloClusterMonitor::m_monitorCellsInterval
Gaudi::Property< unsigned int > m_monitorCellsInterval
Definition: TrigCaloClusterMonitor.h:66
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigCaloClusterMonitor.h
xAOD::CaloCluster_v1::clusterSize
ClusterSize clusterSize() const
Get cluster size.
Definition: CaloCluster_v1.cxx:364
TrigCaloClusterMonitor::m_avgMuKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_avgMuKey
Event input: To get <mu> from Event Info.
Definition: TrigCaloClusterMonitor.h:75
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
TrigCaloClusterMonitor::m_useTwoGaussianNoise
Gaudi::Property< bool > m_useTwoGaussianNoise
Definition: TrigCaloClusterMonitor.h:57
TrigCaloClusterMonitor::m_monitoring2thr
Gaudi::Property< float > m_monitoring2thr
Definition: TrigCaloClusterMonitor.h:61
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigCaloClusterMonitor::m_moniTool
ToolHandle< GenericMonitoringTool > m_moniTool
Monitoring tool.
Definition: TrigCaloClusterMonitor.h:72
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
CaloNoise
Definition: CaloNoise.h:16
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloDetDescrElement::identifyHash
IdentifierHash identifyHash() const override final
cell subcalo hash same as subcalo_hash(), but kept for backward compatibility
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:424
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TrigCaloClusterMonitor::m_clustersKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersKey
The name of the key in StoreGate for the CaloClusterContainer we want to monitor.
Definition: TrigCaloClusterMonitor.h:83
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
TrigCaloClusterMonitor::m_monitorCells
Gaudi::Property< bool > m_monitorCells
Definition: TrigCaloClusterMonitor.h:54
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigCaloClusterMonitor::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigCaloClusterMonitor.cxx:49
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigCaloClusterMonitor::m_excludeTile
Gaudi::Property< bool > m_excludeTile
Definition: TrigCaloClusterMonitor.h:56
TrigCaloClusterMonitor::initialize
virtual StatusCode initialize() override
Definition: TrigCaloClusterMonitor.cxx:35
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::CaloCluster_v1::N_BAD_CELLS
@ N_BAD_CELLS
number of bad cells
Definition: CaloCluster_v1.h:149
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32