ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellContainerCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include "GaudiKernel/StatusCode.h"
10
11
13 : TileCellContainerCnvBase::T_AthenaPoolCustomCnv(svcloc, "TileCellContainerCnv"),
14 m_storeGate("StoreGateSvc", "TileCellContainerCnv")
15{
16}
17
21
23{
24 // Call base clase initialize
26
27 // version 2 by default
28 m_version = 2;
29
30 // Get the messaging service, print where you are
31 ATH_MSG_INFO("TileCellContainerCnv::initialize(), packing format version " << m_version);
32
33 // get StoreGate service
34 StatusCode sc = m_storeGate.retrieve();
35 if (sc.isFailure()) {
36 this->initIdToIndex();
37 ATH_MSG_ERROR("StoreGate service not found !");
38 }
39
40 sc = detStore()->retrieve(m_tileTBID);
41 if (sc.isFailure()) {
42 this->initIdToIndex();
43 ATH_MSG_ERROR("No TileTBID helper");
44 } else {
45 for (int side=0; side<NSIDE; ++side) {
46 for (int phi=0; phi<NPHI; ++phi) {
47 for (int eta=0; eta<NETA; ++eta) {
48 m_id[cell_index(side,phi,eta)] = m_tileTBID->channel_id((side>0)?1:-1,phi,eta);
49 }
50 }
51 }
52 }
53
54 sc = detStore()->retrieve(m_mbtsMgr);
55 if (sc.isFailure()) {
56 ATH_MSG_WARNING("Unable to retrieve MbtsDetDescrManager from DetectorStore");
57 memset(m_dde,0,sizeof(m_dde));
58 } else {
59 for (int side=0; side<NSIDE; ++side) {
60 for (int phi=0; phi<NPHI; ++phi) {
61 for (int eta=0; eta<NETA; ++eta) {
62 m_dde[cell_index(side,phi,eta)] = m_mbtsMgr->get_element(m_id[cell_index(side,phi,eta)]);
63 }
64 }
65 }
66 }
67
68
69 // set CaloGain <-> gain index mapping for all possible TileCal gains
70 for (int i=0; i<17; ++i) m_gainIndex[i] = 8;
71 m_gain[0] = -2; // put non-existing gain here
79
80 return StatusCode::SUCCESS;
81}
82
84{
85 for (int side=0; side<NSIDE; ++side) {
86 for (int phi=0; phi<NPHI; ++phi) {
87 for (int eta=0; eta<NETA; ++eta) {
89 }
90 }
91 }
92}
93
95{
96 // Convert every TileCell to 3 32-bit integers: ID,Ene, and (time,qual,qain)
97
98 std::string name = m_storeGate->proxy(cont)->name();
99 auto vecCell = std::make_unique<TileCellVec>();
100 vecCell->reserve(NCELLMBTS);
101
102 ATH_MSG_DEBUG("storing TileCells from " << name << " in POOL");
103
104 vecCell->push_back(m_version);
105 int nMBTSfound=0;
106
107 std::vector<const TileCell *> allCells;
108
109 switch (m_version) {
110
111 case 1: // 3 words per cell, energy scale factor is 1000, time scale factor is 100
112 for (const TileCell* cell : *cont) {
113 ATH_MSG_VERBOSE("ene=" << cell->energy()
114 << " time=" << cell->time()
115 << " qual=" << (int)cell->qual1()
116 << " gain=" << (int)cell->gain());
117 unsigned int id = cell->ID().get_identifier32().get_compact();
118 int ene = round32(cell->energy() * 1000.);
119 unsigned int tim = 0x8000 + round16(cell->time()*100.);
120 unsigned int qua = std::max(0, std::min(0xFF, (int)cell->qual1()));
121 unsigned int gai = std::max(0, std::min(0xFF, 0x80 + (int)(cell->gain())));
122 unsigned int tqg = (tim<<16) | (qua<<8) | gai;
123 vecCell->push_back(id);
124 vecCell->push_back((unsigned int)ene);
125 vecCell->push_back(tqg);
126 ATH_MSG_VERBOSE("packing cell in three words " << MSG::hex << id <<
127 " " << ene << " " << tqg << MSG::dec);
128 }
129 break;
130
131 case 2: // 1 or 2 words for MBTS cells, 3 words for others, energy scale factor is 1000, time scale factor is 100
132
133 // prepare vector with all cells first, expect at least 32 MBTS cells
134 allCells.resize(NCELLMBTS);
135 for (const TileCell* cell : *cont) {
136 Identifier id = cell->ID();
137 if (m_tileTBID->is_tiletb(id)) {
138 int side = std::max(0,m_tileTBID->type(id));
139 int phi = m_tileTBID->module(id);
140 int eta = m_tileTBID->channel(id);
141 int ind = cell_index(side,phi,eta);
142 if (eta<NETA && phi<NPHI && ind < NCELLMBTS) {
143 allCells[ind] = cell;
144 ++nMBTSfound;
145 } else {
146 allCells.push_back(cell);
147 }
148 } else {
149 allCells.push_back(cell);
150 }
151 }
152
153 if (nMBTSfound>0) {
154
155 // save first 32 cells (MBTS) without identifiers, 2 words per cell, put zeros for empty cells
156 // if MBTS energy is in pCb, then LSB corresponds to 1/12 ADC count of high gain
157 for (int ind=0; ind<NCELLMBTS; ++ind) {
158 int energy = 0;
159 int time = 0;
160 int quality= 0;
161 int gain = m_gain[0]; // non-existing gain in CaloGain - to mark non-existing cells
162 const TileCell* cell = allCells[ind];
163 if (cell) {
164 energy = round32(cell->energy() * 1000.);
165 time = round16(cell->time() * 100.);
166 quality= cell->qual1();
167 gain = cell->gain();
168
169 ATH_MSG_VERBOSE("ind=" << ind <<
170 " ene=" << cell->energy() <<
171 " time=" << cell->time() <<
172 " qual=" << (int)cell->qual1() <<
173 " gain=" << (int)cell->gain());
174 }
175 else {
176 ATH_MSG_VERBOSE("ind=" << ind << " create MBTS cell with zero energy");
177 }
178
179 // put correct MBTS cells in one word
180 if (time == 0 && // expect time to be equal to zero
181 -0x10000 < energy && energy < 0xEFFFF && // expect energy within (-65,980) pCb
182 -17 < gain && gain < 0 ) { // expext only gains in TileCal range
183
184 unsigned int ene = energy+0x10000; // shift by 65 pCb (65*10^3 because of scaling)
185 unsigned int qua = std::max(0, std::min(0xFF, quality)); // 8 bits for quality
186 unsigned int gai = m_gainIndex[-gain];
187 unsigned int gqe = (gai << 28) | (qua<<20) | ene; // upper most bit is always 1 here
188 vecCell->push_back(gqe);
189
190 ATH_MSG_VERBOSE("packing cell " << ind << " in one word " <<
191 MSG::hex << gqe << MSG::dec);
192
193 } else { // cells with time, use 2 words for channel
194 // but make sure that upper most bit in energy word is zero
195
196 unsigned int ene = std::max(0, std::min(0x7FFFFFFF, 0x40000000 + energy));
197 unsigned int tim = std::max(0, std::min(0xFFFF, 0x8000 + time));
198 unsigned int qua = std::max(0, std::min(0xFF, quality)); // 8 bits for quality
199 unsigned int gai = std::max(0, std::min(0xFF, 0x80 + gain));
200 unsigned int tqg = (tim<<16) | (qua<<8) | gai;
201 vecCell->push_back(ene);
202 vecCell->push_back(tqg);
203
204 ATH_MSG_VERBOSE("packing cell " << ind << " in two words " <<
205 MSG::hex << ene << " " << tqg << MSG::dec);
206 }
207 }
208
209 } else {
210
211 (*vecCell)[0] = 1; // no MBTS found - use version 1 for packing
212 }
213
214 // keep all other cells (if any) with identifiers, 3 words per cell
215 for (unsigned int ind=NCELLMBTS; ind<allCells.size(); ++ind) {
216
217 const TileCell* cell = allCells[ind];
218
219 ATH_MSG_VERBOSE("ind=" << ind <<
220 " ene=" << cell->energy() <<
221 " time=" << cell->time() <<
222 " qual=" << (int)cell->qual1() <<
223 " gain=" << (int)cell->gain());
224
225 unsigned int id = cell->ID().get_identifier32().get_compact();
226 int ene = round32(cell->energy() * 1000.);
227 unsigned int tim = 0x8000 + round16(cell->time()*100.);
228 unsigned int qua = std::max(0, std::min(0xFF, (int)cell->qual1()));
229 unsigned int gai = std::max(0, std::min(0xFF, 0x80 + (int)(cell->gain())));
230 unsigned int tqg = (tim<<16) | (qua<<8) | gai;
231 vecCell->push_back(id);
232 vecCell->push_back((unsigned int)ene);
233 vecCell->push_back(tqg);
234
235 ATH_MSG_VERBOSE("packing cell " << ind << " in three words " <<
236 MSG::hex << id << " " << ene << " " << tqg << MSG::dec);
237 }
238 break;
239
240 default:
241
242 ATH_MSG_ERROR("Unknown version of TileCellVec, ver="<<m_version);
243
244 }
245
246 ATH_MSG_DEBUG("Storing data vector of size " << vecCell->size() << " with version " << vecCell->front());
247
248 return vecCell.release();
249}
250
252{
253 // Fill TileCellContainer from vector, creating cells from 3 integers
254
255 std::unique_ptr<TileCellVec> vec(this->poolReadObject<TileCellVec>());
256
257 ATH_MSG_DEBUG("Read TileCell Vec, size " << vec->size());
258
259 // create the TileCellContainer
260 auto cont = std::make_unique<TileCellContainer>();
261
262 TileCellVec::const_iterator it = vec->begin();
263 TileCellVec::const_iterator last = vec->end();
264
265 unsigned int version = *it++;
266 int iCell = 0;
267
268 switch (version) {
269 case 1:
270
271 for (; it != last; ) {
272
273 Identifier id(Identifier32(*it++));
274 int ene = (int)(*it++);
275 unsigned int tqg = *it++;
276
277 float ener = ene*1e-3;
278 float time = ((int)(tqg>>16) - 0x8000 ) * 0.01;
279 uint16_t qual = ((tqg>>8) & 0xFF);
281 int gain = (int)(tqg & 0xFF) - 0x80;
282
283 ATH_MSG_VERBOSE("reading cell " << (iCell++) << " " <<
284 MSG::hex << id << MSG::dec << " " << ene << " " <<
285 MSG::hex << tqg << MSG::dec);
286
287 ATH_MSG_VERBOSE("ene=" << ener << " time=" << time <<
288 " qual=" << qual << " gain=" << gain);
289
290 TileCell * cell = new TileCell(NULL,id,ener,time,qual,qbit,(CaloGain::CaloGain)gain);
291 cont->push_back(cell);
292 }
293 break;
294
295 case 2:
296
297 for (; it != last; ) {
298
299 Identifier id;
300 CaloDetDescrElement * dde = NULL;
301 float ener = 0.0;
302 float time = 0.0;
303 uint16_t qual = 0;
305 int gain = m_gain[0]; // non-existing gain in CaloGain - to mark non-existing cells
306
307 if (msgLvl(MSG::VERBOSE))
308 msg() << MSG::VERBOSE << "reading cell " << iCell << " ";
309
310 if (iCell < NCELLMBTS) { // first 32 cells are MBTS cells without identifier
311
312 id = m_id[iCell]; // identifier is taken from array
313 dde = m_dde[iCell]; // mbtsDDE is taken from array
314
315 int ene = (int)(*it++); // first word is energy
316
317 if (msgLvl(MSG::VERBOSE))
318 msg() << MSG::hex << id << " " << ene << " " << MSG::dec;
319
320 if (ene < 0 ) { // upper most bit is set, it means that everything is packed in one word
321
322 if (msgLvl(MSG::VERBOSE))
323 msg() << endmsg;
324
325 time = 0.0; // time was zero and it was not saved
326 ener = ((ene & 0xFFFFF) - 0x10000) * 1e-3;
327 qual = ((ene>>20) & 0xFF);
328 gain = m_gain[((ene>>28) & 0x7)]; // gain is taken from array
329
330 } else { // two words packing
331
332 unsigned int tqg = *it++;
333 ATH_MSG_VERBOSE(MSG::hex << tqg << MSG::dec);
334
335 ener = (ene - 0x40000000) * 1e-3;
336 time = ((int)(tqg>>16) - 0x8000 ) * 0.01;
337 qual = ((tqg>>8) & 0xFF);
338 gain = (int)(tqg & 0xFF) - 0x80;
339 }
340
341 } else { // three words packing for remaining cells
342
343 id = Identifier(Identifier32(*it++));
344 int ene = (int)(*it++);
345 unsigned int tqg = *it++;
346
347 ATH_MSG_VERBOSE(MSG::hex << id << MSG::dec << " " << ene <<
348 " " << MSG::hex << tqg << MSG::dec);
349
350 ener = ene*1e-3;
351 time = ((int)(tqg>>16) - 0x8000 ) * 0.01;
352 qual = ((tqg>>8) & 0xFF);
353 gain = (int)(tqg & 0xFF) - 0x80;
354 }
355
356 ATH_MSG_VERBOSE("ene=" << ener << " time=" << time
357 << " qual=" << qual << " gain=" << gain);
358
359 if (gain != m_gain[0]) { // don't create cells with non-existing gain
360 TileCell * cell = new TileCell(dde,id,ener,time,qual,qbit,(CaloGain::CaloGain)gain);
361 cont->push_back(cell);
362 }
363 else {
364 ATH_MSG_VERBOSE("Don't create MBTS cell with invalid gain");
365 }
366 ++iCell;
367 }
368 break;
369
370 default:
371
372 ATH_MSG_ERROR("Unknown version of TileCellVec, ver="<<version);
373 }
374
375 return cont.release();
376}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
static Double_t sc
T_AthenaPoolCustomCnv< TileCellContainer, TileCellVec > TileCellContainerCnvBase
TileContainer< TileCell > TileCellContainer
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
const ServiceHandle< StoreGateSvc > & detStore() const
This class groups all DetDescr information related to a CaloCell.
Compatibility for old converter classes that don't get passed the key.
const TileTBID * m_tileTBID
ServiceHandle< StoreGateSvc > m_storeGate
virtual TileCellVec * createPersistent(TileCellContainer *cont) override
virtual StatusCode initialize() override
initialization
CaloDetDescrElement * m_dde[NCELLMBTS]
TileCellContainerCnv(ISvcLocator *svcloc)
const MbtsDetDescrManager * m_mbtsMgr
Identifier m_id[NCELLMBTS]
virtual TileCellContainer * createTransient() override
int cell_index(int side, int phi, int eta) const
@ MASK_TIME
Definition TileCell.h:67
@ MASK_CMPC
Definition TileCell.h:66
@ TILELOWLOW
Definition CaloGain.h:12
@ INVALIDGAIN
Definition CaloGain.h:18
@ TILEONEHIGH
Definition CaloGain.h:17
@ TILEONELOW
Definition CaloGain.h:16
@ TILELOWHIGH
Definition CaloGain.h:13
@ TILEHIGHLOW
Definition CaloGain.h:14
@ TILEHIGHHIGH
Definition CaloGain.h:15