ATLAS Offline Software
Loading...
Searching...
No Matches
L1CaloMonitoringCaloTool.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// ********************************************************************
6//
7// NAME: L1CaloMonitoringCaloTool.cxx
8// PACKAGE: TrigT1CaloCalibTools
9//
10// AUTHOR: Peter Faulkner
11//
12// ********************************************************************
13
14#include <cmath>
15
16#include "GaudiKernel/IInterface.h"
17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/StatusCode.h"
19
20#include "CaloEvent/CaloCell.h"
22#include "CaloDetDescr/CaloDetDescrElement.h"
24
25#include "TileEvent/TileCell.h"
26
27#include "Identifier/Identifier.h"
29
31
33
34namespace LVL1 {
35
39
40
41/*---------------------------------------------------------*/
43 asg::AsgTool( name ),
44 m_lvl1Helper(nullptr),
46 m_events(0),
47 m_lastRun(0),
48 m_lastEvent(0),
49 m_sideOffset(0),
54/*---------------------------------------------------*/
55{
56 declareProperty("CaloCellContainer", m_caloCellContainerName = "AllCalo");
57 declareProperty("MappingVectorSize", m_maxCells = 188080);
58}
59
60/*---------------------------------------------------------*/
62/*---------------------------------------------------------*/
63{
64 ATH_MSG_INFO("Initializing " << name());
65
66 ATH_CHECK( m_cellMatch.retrieve() );
67
68 StatusCode sc;
69
70 // Get LVL1 idhelper from detector store
71 const CaloLVL1_ID* lvl1_id = 0;
72 sc = detStore()->retrieve(lvl1_id, "CaloLVL1_ID");
73 if (sc.isFailure() || !lvl1_id) {
74 ATH_MSG_ERROR("Could not get CaloLVL1_ID helper !");
75 return sc;
76 }
77 else {
78 m_lvl1Helper = static_cast<const CaloLVL1_ID*> (lvl1_id);
79 }
80
81 // Set up cell to tt mapping arrays
82 const unsigned int maxCaloCells = 188080;
83 if (m_maxCells > maxCaloCells) m_maxCells = maxCaloCells;
84 if (m_maxCells > 0) {
85 m_cellIds.reserve(m_maxCells);
86 m_cellIds.assign(m_maxCells, 0);
87 m_ttIdx.reserve(m_maxCells);
88 m_ttIdx.assign(m_maxCells, 0);
89 }
91 m_quality.reserve(s_maxTowers);
92 m_denom.reserve(s_maxTowers);
93
94 // Set up arrays for indexing and sinTh
95 int binsEta[s_nregions] = { 25, 3, 1, 4 };
96 int binsPhi[s_nregions] = { 64, 32, 32, 16 };
97 double grans[s_nregions] = { 0.1, 0.2, 0.1, 0.425 };
98 double etaOffset[s_nregions] = { 0., 2.5, 3.1, 3.2 };
99 int bin = 0;
100 for (int r = 0; r < s_nregions; ++r) {
101 if (r == 0) {
102 m_binOffset[r] = 0;
103 m_indexOffset[r] = 0;
104 } else {
105 m_binOffset[r] = binsEta[r-1] + m_binOffset[r-1];
106 m_indexOffset[r] = binsEta[r-1]*binsPhi[r-1] + m_indexOffset[r-1];
107 }
108 m_etaShift[r] = 0;
109 int shift = binsPhi[r] - 1;
110 while (shift) {
111 m_etaShift[r]++;
112 shift>>=1;
113 }
114 for (int i = 0; i < binsEta[r]; ++i) {
115 double eta = etaOffset[r] + (i+0.5)*grans[r];
116 m_sinTh[bin++] = 1./(1000.*std::cosh(eta)); // include MeV->GeV conversion
117 }
118 }
119 m_sideOffset = binsEta[s_nregions-1]*binsPhi[s_nregions-1] + m_indexOffset[s_nregions-1];
121
122 ATH_CHECK( m_cablingKey.initialize() );
123
124 return StatusCode::SUCCESS;
125
126}
127
128/*---------------------------------------------------------*/
130/*---------------------------------------------------------*/
131{
132 return StatusCode::SUCCESS;
133}
134
135/*---------------------------------------------------------*/
137/*---------------------------------------------------------*/
138{
139 const bool debug = msgLvl(MSG::DEBUG);
140 if (debug) {
141 ATH_MSG_DEBUG("in loadCaloCells()");
142 }
143
144 StatusCode sc;
145
146 // Don't run more than once per event
147
148 const EventContext& ctx = Gaudi::Hive::currentContext();
149 int eventNumber = ctx.eventID().event_number();
150 int runNumber = ctx.eventID().run_number();
151 if (eventNumber == m_lastEvent && runNumber == m_lastRun) {
152 return StatusCode::SUCCESS;
153 }
154 m_lastEvent = eventNumber;
155 m_lastRun = runNumber;
156
157 // Retreive Calo Cell collection from SG
158
159 const CaloCellContainer* caloCellContainer = 0;
160 sc = evtStore()->retrieve(caloCellContainer, m_caloCellContainerName);
161 if(!sc.isSuccess() || !caloCellContainer) {
162 ATH_MSG_WARNING("No CaloCellContainer found at AllCalo");
163 return StatusCode::SUCCESS;
164 }
165 ++m_events;
166
167 // Get Et and CaloQuality corresponding to TTs
168
169 CaloCellContainer::const_iterator CaloCellIterator = caloCellContainer->begin();
170 CaloCellContainer::const_iterator CaloCellIteratorEnd = caloCellContainer->end();
171 m_energySums.assign(s_maxTowers, 0.0);
172 m_quality.assign(s_maxTowers, 0.0);
173 m_denom.assign(s_maxTowers, 0.0);
174 unsigned int cellIdsIndex = 0;
175
177
178 for (; CaloCellIterator != CaloCellIteratorEnd; ++CaloCellIterator) {
179
180 const CaloCell* caloCell(*CaloCellIterator);
181 const Identifier cellId(caloCell->ID());
182 const Identifier invalidId(0);
183 Identifier ttId1(0);
184 Identifier ttId2(0);
185
186 // Use cell ordering to avoid unnecessary calls to mapping tools
187
188 int index1 = s_maxTowers;
189 int index2 = s_maxTowers;
190 const unsigned int cellId32 = cellId.get_identifier32().get_compact();
191 if (m_events == 1) {
192 m_cellMatch->matchCell2Tower(**cabling, caloCell, ttId1, ttId2);
193 if (ttId1 != invalidId) index1 = towerIndex(ttId1);
194 if (ttId2 != invalidId) index2 = towerIndex(ttId2);
195 if (cellIdsIndex < m_maxCells-1) {
196 m_cellIds[cellIdsIndex] = cellId32;
197 m_ttIdx[cellIdsIndex++] = index1;
198 if (ttId2 != invalidId) {
199 m_cellIds[cellIdsIndex] = cellId32;
200 m_ttIdx[cellIdsIndex++] = index2;
201 }
202 }
203 } else {
204 if ((cellIdsIndex < m_maxCells-1) && (m_cellIds[cellIdsIndex] == cellId32)) {
205 index1 = m_ttIdx[cellIdsIndex++];
206 if (m_cellIds[cellIdsIndex] == cellId32) index2 = m_ttIdx[cellIdsIndex++];
207 } else {
208 m_cellMatch->matchCell2Tower(**cabling, caloCell, ttId1, ttId2);
209 if (ttId1 != invalidId) index1 = towerIndex(ttId1);
210 if (ttId2 != invalidId) index2 = towerIndex(ttId2);
211 }
212 }
213
214 // Get Et/Energy and CaloQuality
215
216 if (index1 < s_maxTowers) {
217 const float energy = caloCell->energy();
218 const CaloDetDescrElement* caloDDE = caloCell->caloDDE();
219 if (index2 < s_maxTowers) { // Tile D cells
220 const float energy2 = energy*0.5;
221 m_energySums[index1] += energy2;
222 m_energySums[index2] += energy2;
223 const TileCell* tileCell = dynamic_cast<const TileCell*>(caloCell);
224 if (tileCell && (tileCell->provenance() & 0x8080)) {
225 const float qual = energy2 * std::max(tileCell->qual1(), tileCell->qual2());
226 m_quality[index1] += qual;
227 m_quality[index2] += qual;
228 m_denom[index1] += energy2;
229 m_denom[index2] += energy2;
230 }
231 } else {
232 if (caloDDE->is_lar_fcal()) {
233 m_energySums[index1] += energy*caloDDE->sinTh();
234 } else m_energySums[index1] += energy;
235 if (caloDDE->is_tile()) {
236 const TileCell* tileCell = dynamic_cast<const TileCell*>(caloCell);
237 if (tileCell && (tileCell->provenance() & 0x8080)) {
238 m_quality[index1] += energy * std::max(tileCell->qual1(), tileCell->qual2());
239 m_denom[index1] += energy;
240 }
241 } else {
242 if (caloCell->provenance() & 0x2000) {
243 m_quality[index1] += (energy * caloCell->quality());
244 m_denom[index1] += energy;
245 }
246 }
247 }
248 }
249 }
250
251 // Compute final quantities
252
253 for (int index = 0; index < s_maxTowers; ++index) {
254 if (region(index) == 3) { // FCAL
255 m_energySums[index] *= 1e-3;
256 } else {
257 const int bin = etaBin(index);
259 }
260 if ( m_denom[index] != 0.) {
262 } else {
263 m_quality[index] = -1e6; // error value
264 }
265 }
266
267 return StatusCode::SUCCESS;
268}
269
270// Return Et
271
273{
274 float e = 0.;
275 const int index = towerIndex(ttId);
277 return e;
278}
279
280// Return Calo Quality
281
283{
284 float q = -1e6;
285 const int index = towerIndex(ttId);
286 if (index < s_maxTowers) q = m_quality[index];
287 return q;
288}
289
290// Return index to TT-Calo energy sum vector
291
293{
294 const int side = m_lvl1Helper->pos_neg_z(ttId);
295 const int layer = m_lvl1Helper->sampling(ttId);
296 const int region = m_lvl1Helper->region(ttId);
297 const int ieta = m_lvl1Helper->eta(ttId);
298 const int iphi = m_lvl1Helper->phi(ttId);
299 int index = 0;
300 index = m_indexOffset[region] + (ieta<<(m_etaShift[region])) + iphi;
301 if (side < 0) index += m_sideOffset;
302 if (layer > 0) index += m_layerOffset;
303 return index;
304}
305
306// Return the region corresponding to index
307
309{
310 int rg = 0;
311 int ix = index;
312 if (ix >= m_layerOffset) ix -= m_layerOffset;
313 if (ix >= m_sideOffset) ix -= m_sideOffset;
314 for (int r = s_nregions-1; r >= 0; --r) {
315 if (ix >= m_indexOffset[r]) {
316 rg = r;
317 break;
318 }
319 }
320 return rg;
321}
322
323// Return the eta bin corresponding to index
324
326{
327 int bin = 0;
328 int ix = index;
329 if (ix >= m_layerOffset) ix -= m_layerOffset;
330 if (ix >= m_sideOffset) ix -= m_sideOffset;
331 for (int r = s_nregions-1; r >= 0; --r) {
332 if (ix >= m_indexOffset[r]) {
333 const int ieta = (ix - m_indexOffset[r])>>(m_etaShift[r]);
334 bin = m_binOffset[r] + ieta;
335 break;
336 }
337 }
338 return bin;
339}
340
341} // end namespace
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_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const ITkStripOnlineId invalidId
static Double_t sc
const bool debug
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
uint16_t provenance() const
get provenance (data member)
Definition CaloCell.h:354
uint16_t quality() const
get quality (data member)
Definition CaloCell.h:348
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
This class groups all DetDescr information related to a CaloCell.
float sinTh() const
for algorithm working in transverse Energy
bool is_lar_fcal() const
cell belongs to FCAL
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
L1CaloMonitoringCaloTool()=delete
delete the big 4
ToolHandle< LVL1::IL1CaloMatchCell2Tower > m_cellMatch
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
StatusCode loadCaloCells()
Declare the interface that the class provides.
float et(const Identifier &ttid) const
std::vector< unsigned int > m_cellIds
float caloQuality(const Identifier &ttid) const
int towerIndex(const Identifier &ttId) const
uint8_t qual1(void) const
get quality of first PMT (data member)
Definition TileCell.h:197
uint8_t qual2(void) const
get quality of second PMT (data member)
Definition TileCell.h:200
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
int r
Definition globals.cxx:22
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition index.py:1