ATLAS Offline Software
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 
5 #include "TileCellContainerCnv.h"
8 
9 #include "GaudiKernel/StatusCode.h"
10 
11 
13  : TileCellContainerCnvBase::T_AthenaPoolCustomCnv(svcloc, "TileCellContainerCnv"),
14  m_storeGate("StoreGateSvc", "TileCellContainerCnv")
15 {
16 }
17 
19 {
20 }
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) {
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) {
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 
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 }
TileCell
Definition: TileCell.h:57
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Identifier32
Definition: Identifier32.h:25
TileTBID::channel_id
Identifier channel_id(int type, int module, int channel) const
identifer for one channel of a Tile testbeam detector
Definition: TileTBID.cxx:197
TileCellContainerCnv::m_gainIndex
int m_gainIndex[17]
Definition: TileCellContainerCnv.h:51
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
TileCellContainerCnv::NPHI
static const int NPHI
Definition: TileCellContainerCnv.h:42
TileTBID::is_tiletb
bool is_tiletb(const Identifier &id) const
Test ID if it is TileTBID.
Definition: TileTBID.cxx:87
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TileCellContainerCnv::round16
int round16(double x)
Definition: TileCellContainerCnv.h:60
TileCellContainerCnv::m_gain
int m_gain[8]
Definition: TileCellContainerCnv.h:52
TileCellContainerCnv::initialize
virtual StatusCode initialize() override
initialization
Definition: TileCellContainerCnv.cxx:22
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
skel.it
it
Definition: skel.GENtoEVGEN.py:396
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TileCellContainerCnv::NETA
static const int NETA
Definition: TileCellContainerCnv.h:43
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
TileCellContainerCnv::TileCellContainerCnv
TileCellContainerCnv(ISvcLocator *svcloc)
Definition: TileCellContainerCnv.cxx:12
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition: CaloGain.h:12
TileCellContainerCnv::m_version
int m_version
Definition: TileCellContainerCnv.h:39
TileCellContainerCnv::m_storeGate
ServiceHandle< StoreGateSvc > m_storeGate
Definition: TileCellContainerCnv.h:34
AthenaPoolConverter::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: AthenaPoolConverter.cxx:27
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
TileCellContainerCnv::m_tileTBID
const TileTBID * m_tileTBID
Definition: TileCellContainerCnv.h:36
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MbtsDetDescrManager.h
TRT::Hit::side
@ side
Definition: HitInfo.h:83
CaloGain::TILEHIGHHIGH
@ TILEHIGHHIGH
Definition: CaloGain.h:15
TileCellContainerCnv::m_id
Identifier m_id[NCELLMBTS]
Definition: TileCellContainerCnv.h:49
TileCellContainerCnv::NSIDE
static const int NSIDE
Definition: TileCellContainerCnv.h:41
CaloGain::INVALIDGAIN
@ INVALIDGAIN
Definition: CaloGain.h:18
python.LArBadChannelDBAlg.x7FFFFFFF
x7FFFFFFF
Definition: LArBadChannelDBAlg.py:72
TileCellContainerCnv::m_mbtsMgr
const MbtsDetDescrManager * m_mbtsMgr
Definition: TileCellContainerCnv.h:37
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
TileTBID.h
TileCellContainerCnv::createPersistent
virtual TileCellVec * createPersistent(TileCellContainer *cont) override
Definition: TileCellContainerCnv.cxx:94
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
TileCellContainerCnv::createTransient
virtual TileCellContainer * createTransient() override
Definition: TileCellContainerCnv.cxx:251
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
T_AthenaPoolCustomCnv
Compatibility for old converter classes that don't get passed the key.
Definition: T_AthenaPoolCustomCnv.h:132
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloGain::TILEONELOW
@ TILEONELOW
Definition: CaloGain.h:16
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileCellContainerCnv::cell_index
int cell_index(int side, int phi, int eta) const
Definition: TileCellContainerCnv.h:46
TileCellVec
Definition: TileContainer.h:73
TileCell::MASK_CMPC
@ MASK_CMPC
Definition: TileCell.h:66
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MbtsDetDescrManager::get_element
CaloDetDescrElement * get_element(const Identifier &elementId) const
Definition: MbtsDetDescrManager.cxx:22
AthenaPoolConverter::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Handle to DetectorStore.
Definition: AthenaPoolConverter.h:69
CaloGain::TILEHIGHLOW
@ TILEHIGHLOW
Definition: CaloGain.h:14
TileCellContainerCnv::round32
int round32(double x)
Definition: TileCellContainerCnv.h:54
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
TileTBID::channel
int channel(const Identifier &id) const
extract channel field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:154
CaloGain::TILELOWHIGH
@ TILELOWHIGH
Definition: CaloGain.h:13
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
TileCellContainerCnv.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
TileCellContainerCnv::m_dde
CaloDetDescrElement * m_dde[NCELLMBTS]
Definition: TileCellContainerCnv.h:50
TileCellContainerCnv::~TileCellContainerCnv
virtual ~TileCellContainerCnv()
Definition: TileCellContainerCnv.cxx:18
get_generator_info.version
version
Definition: get_generator_info.py:33
TileCell::MASK_TIME
@ MASK_TIME
Definition: TileCell.h:67
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
beamspotman.qual
qual
Definition: beamspotman.py:481
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TileCellContainerCnv::NCELLMBTS
static const int NCELLMBTS
Definition: TileCellContainerCnv.h:44
TileContainer
Definition: TileContainer.h:38
CaloGain::TILEONEHIGH
@ TILEONEHIGH
Definition: CaloGain.h:17
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
TileCellContainerCnv::initIdToIndex
void initIdToIndex()
Definition: TileCellContainerCnv.cxx:83
Identifier
Definition: IdentifierFieldParser.cxx:14