ATLAS Offline Software
Loading...
Searching...
No Matches
LArDigitRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArDigitRetriever.h"
6
7#include "CLHEP/Units/SystemOfUnits.h"
8
10
11#include "CaloDetDescr/CaloDetDescrElement.h"
19#include "GaudiKernel/ThreadLocalContext.h"
20#include <memory>
21#include <array>
22
23using CLHEP::GeV;
24
25namespace JiveXML {
26
30
32
33 ATH_MSG_DEBUG( "Initialising Tool" );
34 ATH_CHECK( detStore()->retrieve (m_calocell_id, "CaloCell_ID") );
35 ATH_CHECK( m_adc2mevKey.initialize() );
36
37 ATH_CHECK( m_sgKey.initialize() );
38 ATH_CHECK( m_sgKeyLArDigit_raw.initialize() );
39 ATH_CHECK( m_sgKeyLArDigit_esd.initialize() );
40 ATH_CHECK( m_cablingKey.initialize() );
41
42 return StatusCode::SUCCESS;
43 }
44
48 StatusCode LArDigitRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
49
50 ATH_MSG_DEBUG( "in retrieve()" );
51
53 m_doDigit = true;
54 }
55
57 if (!cellContainer.isValid()){
58 ATH_MSG_WARNING( "Could not retrieve Calorimeter Cells " );
59 }
60 else{
61
62 if(m_fcal){
63 DataMap data = getLArDigitData(&(*cellContainer),"FCAL",CaloCell_ID::LARFCAL);
64 ATH_CHECK( FormatTool->AddToEvent("FCAL", m_sgKey.key(), &data) );
65 ATH_MSG_DEBUG( "FCAL retrieved" );
66 }
67
68 if(m_lar){
69 DataMap data = getLArDigitData(&(*cellContainer),"LAr",CaloCell_ID::LAREM);
70 ATH_CHECK( FormatTool->AddToEvent("LAr", m_sgKey.key(), &data) );
71 ATH_MSG_DEBUG( "LAr retrieved" );
72 }
73
74 if(m_hec){
75 DataMap data = getLArDigitData(&(*cellContainer),"HEC",CaloCell_ID::LARHEC);
76 ATH_CHECK( FormatTool->AddToEvent("HEC", m_sgKey.key(), &data) );
77 ATH_MSG_DEBUG( "HEC retrieved" );
78 }
79 }
80
81 //Tile cells retrieved okay
82 return StatusCode::SUCCESS;
83 }
84
85
91 const std::string& datatype,
92 CaloCell_ID::SUBCALO calotype)
93 {
94
95 //be verbose
96 ATH_MSG_DEBUG( "getLArDigitData()" );
97 const EventContext& ctx = Gaudi::Hive::currentContext();
98
99 char rndStr[30];
101
102 DataVect phi; phi.reserve(cellContainer->size());
103 DataVect eta; eta.reserve(cellContainer->size());
104 DataVect x; x.reserve(cellContainer->size());
105 DataVect y; y.reserve(cellContainer->size());
106 DataVect dx; dx.reserve(cellContainer->size());
107 DataVect dy; dy.reserve(cellContainer->size());
108
109 DataVect energy; energy.reserve(cellContainer->size());
110 DataVect idVec; idVec.reserve(cellContainer->size());
111 DataVect channel; channel.reserve(cellContainer->size());
112 DataVect feedThrough; feedThrough.reserve(cellContainer->size());
113 DataVect slotVec; slotVec.reserve(cellContainer->size());
114
115 DataVect cellTimeVec; cellTimeVec.reserve(cellContainer->size());
116 DataVect cellGain; cellGain.reserve(cellContainer->size());
117 DataVect cellPedestal; cellPedestal.reserve(cellContainer->size());
118 DataVect adc2Mev; adc2Mev.reserve(cellContainer->size());
119
120// m_sub; m_sub.reserve(cellContainer->size());
121 m_sub.clear(); // need to clear before each event, otherwise appended
122
123 DataVect LArSampleIndexVec; LArSampleIndexVec.reserve(cellContainer->size());
124
125 std::string LArSampleIndexStr="adcCounts multiple=\"0\"";
126
129 const LArDigitContainer* LArDigitCnt = nullptr;
130 if (LArDigitCnt_raw_handle.isValid()) {
131 LArDigitCnt = &(*LArDigitCnt_raw_handle);
132 }
133 else if (LArDigitCnt_esd_handle.isValid()) {
134 LArDigitCnt = &(*LArDigitCnt_esd_handle);
135 m_inputdpd = true;
136 }
137 else {
138 ATH_MSG_WARNING( "Could not retrieve LArDigits" );
139 }
140
141 const ILArPedestal* larPedestal = nullptr;
142 if ( detStore()->retrieve(larPedestal).isFailure()){
143 ATH_MSG_ERROR( "in getLArDigitData(), Could not retrieve LAr Pedestal" );
144 }
145
146 const LArOnlineID* onlineId = nullptr;
147 if ( detStore()->retrieve(onlineId, "LArOnlineID").isFailure()) {
148 ATH_MSG_ERROR( "in getLArDigitData(),Could not get LArOnlineID!" );
149 }
150
152
153//------------------------------------------------------
154//Loop over the digits and find Cell (LAr,HEC, FCAL)
155//------------------------------------------------------
156
158 const LArOnOffIdMapping* cabling{*cablingHdl};
159 if(!cabling) {
160 ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKey.key() );
161 return DataMap;
162 }
163
164
165 if (LArDigitCnt && m_doDigit==true) {
166
167 auto pCellIndex = std::make_unique<std::array<int, 200000>>();
168 pCellIndex->fill(0);
169 int nLArSamples = 0;
170 HWIdentifier LArHardwareId;
171 Identifier LArId;
172
173 double energyGeV,cellTime;
174
175 for (const LArDigit* digit : *LArDigitCnt) {
176
177 LArHardwareId = digit->hardwareID();
178 if (!cabling->isOnlineConnected(LArHardwareId))continue;
179
180 LArId = cabling->cnvToIdentifier(LArHardwareId); //converter
181 const IdentifierHash cellhash=m_calocell_id->calo_cell_hash(LArId); //fast method to find cell
182
183 int Index = cellContainer->findIndex(cellhash); //find Cell Index
184 if (Index >= 0)
185 (*pCellIndex)[Index] = Index;
186
187 nLArSamples = digit->nsamples();
188 std::vector<short> LArSamples = digit->samples();
189 int largain = digit->gain();
190 int FT = onlineId->feedthrough(LArHardwareId);
191 int slot = onlineId->slot(LArHardwareId);
192 int larchan = onlineId->channel(LArHardwareId);
193 float pedestal=larPedestal->pedestal(LArHardwareId,largain);
194 float pedvalue=0;
195 if (pedestal >= (1.0+LArElecCalib::ERRORCODE)) pedvalue = pedestal;
196 else pedvalue = LArSamples[0];
197
198 LArVectorProxy polynom_adc2mev = adc2mev->ADC2MEV(LArId,largain);
199
200 if ( Index >= 0 ){ // can be -1
201 if ( (*cellContainer)[Index]->energy() >m_cellThreshold) {
202
203 if (((((*cellContainer)[Index]->provenance())&0xFF)!=0xA5)&&m_cellConditionCut) continue; // check full conition for LAr Cells
204
205 //ignore LAr, HEC, and/or FCAL cells that are to be masked
207 bool maskChannel = false;
208 for (size_t i = 0; i < m_LArChannelsToIgnoreM5.size(); i++){
209 if ( (*cellContainer)[Index]->ID().get_compact() == m_LArChannelsToIgnoreM5[i]){
210 maskChannel = true;
211 break; // exit loop over bad channels
212 }
213 }
214 if (maskChannel) continue; // continue loop over all channels
215 }
216
217
218 if (datatype == "LAr" && m_calocell_id->is_em(LArId)) {
219
220 calcEMLayerSub(LArId);
221
222 energyGeV = (*cellContainer)[Index]->energy() * (1./GeV);
223 energy.push_back(DataType( gcvt( energyGeV, m_cellEnergyPrec, rndStr) ));
224 idVec.push_back(DataType((*cellContainer)[Index]->ID().get_compact() ));
225 phi.push_back(DataType((*cellContainer)[Index]->phi()));
226 eta.push_back(DataType((*cellContainer)[Index]->eta()));
227
228 cellTime = (*cellContainer)[Index]->time();
229 cellTimeVec.push_back(DataType( gcvt( cellTime, m_cellTimePrec, rndStr) ) );
230 cellPedestal.push_back(DataType(pedvalue));
231 cellGain.push_back(DataType(largain));
232 channel.push_back(DataType(larchan));
233 feedThrough.push_back(DataType(FT));
234 slotVec.push_back(DataType(slot));
235 if (polynom_adc2mev.size()==0){
236 adc2Mev.push_back(DataType(-1));
237 }else{
238 adc2Mev.push_back(DataType(polynom_adc2mev[1]));
239 }
240 if ( m_doLArDigit ) {
241 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
242 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(LArSamples[i]));
243 }
244 } //match datatype LAr
245
246 else if(datatype == "HEC" && m_calocell_id->is_hec(LArId)) {
247
248 calcHECLayerSub(LArId);
249 energyGeV = (*cellContainer)[Index]->energy() * (1./GeV);
250 energy.push_back(DataType( gcvt( energyGeV, m_cellEnergyPrec, rndStr) ));
251 idVec.push_back(DataType((*cellContainer)[Index]->ID().get_compact() ));
252 phi.push_back(DataType((*cellContainer)[Index]->phi()));
253 eta.push_back(DataType((*cellContainer)[Index]->eta()));
254
255
256 cellTime = (*cellContainer)[Index]->time();
257 cellTimeVec.push_back(DataType( gcvt( cellTime, m_cellTimePrec, rndStr) ) );
258 cellPedestal.push_back(DataType(pedvalue));
259 cellGain.push_back(DataType(largain));
260 channel.push_back(DataType(larchan));
261 feedThrough.push_back(DataType(FT));
262 slotVec.push_back(DataType(slot));
263 if (polynom_adc2mev.size()==0)
264 adc2Mev.push_back(DataType(-1));
265 else
266 adc2Mev.push_back(DataType(polynom_adc2mev[1]));
267 if (m_doHECDigit){
268 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
269 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(LArSamples[i]));
270 }
271 }//match datatype HEC
272
273 else if(datatype == "FCAL" && m_calocell_id->is_fcal(LArId)) {
274
275 energyGeV = (*cellContainer)[Index]->energy() * (1./GeV);
276 energy.push_back(DataType( gcvt( energyGeV, m_cellEnergyPrec, rndStr) ));
277 idVec.push_back(DataType((*cellContainer)[Index]->ID().get_compact() ));
278 x.push_back(DataType((*cellContainer)[Index]->x() *0.1));
279 y.push_back(DataType((*cellContainer)[Index]->y() *0.1));
280
281 const CaloDetDescrElement* elt = (*cellContainer)[Index]->caloDDE();
282
283 dx.push_back(DataType(elt->dx()*0.1));
284 dy.push_back(DataType(elt->dy()*0.1));
285
286 if (m_calocell_id->pos_neg(LArId)==2) m_sub.push_back(DataType(1));
287 else m_sub.push_back(DataType(0));
288
289
290 cellTime = (*cellContainer)[Index]->time();
291 cellTimeVec.push_back(DataType( gcvt( cellTime, m_cellTimePrec, rndStr) ) );
292 cellPedestal.push_back(DataType(pedvalue));
293 cellGain.push_back(DataType(largain));
294 channel.push_back(DataType(larchan));
295 feedThrough.push_back(DataType(FT));
296 slotVec.push_back(DataType(slot));
297 if (polynom_adc2mev.size()==0)
298 adc2Mev.push_back(DataType(-1));
299 else
300 adc2Mev.push_back(DataType(polynom_adc2mev[1]));
301 if (m_doFCalDigit){
302 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
303 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(LArSamples[i]));
304 }
305 }//match datatype FCAL
306 } //if cellThreshold
307 } // if Index >0
308 } //digit
309
310
311// If the digits are retrieved from DPD, retrieve the other cells which do not have the digits available
312
313 if (m_inputdpd) {
314
315 CaloCellContainer::const_iterator it1 = cellContainer->beginConstCalo(calotype);
316 CaloCellContainer::const_iterator it2 = cellContainer->endConstCalo(calotype);
317
318
319 for (;it1!=it2;++it1) {
320 //---------------------------------------------
321
322 if ( (*it1)->energy() < m_cellThreshold ) continue;
323
324 Identifier cellid = (*it1)->ID();
325
326 const IdentifierHash cellhash=m_calocell_id->calo_cell_hash(cellid); //fast method to find cell
327 int Index = cellContainer->findIndex(cellhash); //find Cell Index
328 if (Index >= 0 && (*pCellIndex)[Index] == Index)
329 continue; //test whether this cell was already retrieved
330
331 HWIdentifier LArhwid = cabling->createSignalChannelIDFromHash((*it1)->caloDDE()->calo_hash());
332
333 if (m_calocell_id->is_tile(cellid) ) continue;
334 if (((((*it1)->provenance())&0xFF)!=0xA5)&&m_cellConditionCut) continue; // check full condition for LAr cells
335
336 //ignore LAr, HEC, and/or FCAL cells that are to be masked
338 bool maskChannel = false;
339 for (size_t i = 0; i < m_LArChannelsToIgnoreM5.size(); i++){
340 if (cellid == m_LArChannelsToIgnoreM5[i]){
341 maskChannel = true;
342 break; // exit loop over bad channels
343 }
344 }
345 if (maskChannel) continue; // continue loop over all channels
346 }
347
348 energyGeV = (*it1)->energy()*(1./GeV);
349 energy.push_back(DataType( gcvt( energyGeV, m_cellEnergyPrec, rndStr) ));
350 idVec.push_back(DataType((*it1)->ID().get_compact() ));
351 channel.push_back(DataType(onlineId->channel(LArhwid)));
352 feedThrough.push_back(DataType(onlineId->feedthrough(LArhwid)));
353 slotVec.push_back(DataType(onlineId->slot(LArhwid)));
354
355 cellTime = (*it1)->time();
356 cellTimeVec.push_back(DataType( gcvt( cellTime, m_cellTimePrec, rndStr) ) );
357 cellGain.push_back(DataType((*it1)->gain()));
358 int largain = (*it1)->gain();
359 float pedvalue=0;
360 float pedestal=larPedestal->pedestal(LArhwid,largain);
361 if (pedestal >= (1.0+LArElecCalib::ERRORCODE)) pedvalue = pedestal;
362 else pedvalue = 0;
363 cellPedestal.push_back(DataType(pedvalue));
364
365 LArVectorProxy polynom_adc2mev = adc2mev->ADC2MEV(cellid,largain);
366 if (polynom_adc2mev.size()==0){
367 adc2Mev.push_back(DataType(-1));
368 }else{
369 adc2Mev.push_back(DataType(polynom_adc2mev[1]));
370 }
371
372
373 if (datatype == "LAr") {
374 calcEMLayerSub(cellid);
375 phi.push_back(DataType((*it1)->phi()));
376 eta.push_back(DataType((*it1)->eta()));
377 if ( m_doLArDigit ) {
378 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
379 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(0)); }
380 }
381
382 else if (datatype == "HEC") {
383 calcHECLayerSub(cellid);
384 phi.push_back(DataType((*it1)->phi()));
385 eta.push_back(DataType((*it1)->eta()));
386 if (m_doHECDigit){
387 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
388 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(0)); }
389 }
390
391 else if (datatype == "FCAL") {
392
393 x.push_back(DataType( (*it1)->x()*0.1 ));
394 y.push_back(DataType( (*it1)->y()*0.1 ));
395
396 const CaloDetDescrElement* elt = (*it1)->caloDDE();
397 dx.push_back(DataType( elt->dx()*0.1 ));
398 dy.push_back(DataType( elt->dy()*0.1 ));
399
400 if (m_calocell_id->pos_neg(cellid)==2) m_sub.push_back(DataType(1));
401 else m_sub.push_back(DataType(0));
402 if (m_doFCalDigit){
403 LArSampleIndexStr="adcCounts multiple=\""+DataType(nLArSamples).toString()+"\"";
404 for(int i=0; i<nLArSamples; i++) LArSampleIndexVec.push_back(DataType(0));
405 }
406 }
407
408 }//for(;it1!=it2;it1++)
409 }// if (m_inputdpd)
410 }
411
412//----------------above lines are trying to get the LAr,HEC and FCAL tags --------------
413
414 // write values into DataMap
415 const auto nEntries = phi.size();
416 if(!(datatype=="FCAL")){
417 DataMap["phi"] = std::move(phi);
418 DataMap["eta"] = std::move(eta);
419 } else {
420 DataMap["x"] = std::move(x);
421 DataMap["y"] = std::move(y);
422 DataMap["dx"] = std::move(dx);
423 DataMap["dy"] = std::move(dy);
424 }
425
426 DataMap["energy"] = std::move(energy);
427 DataMap["id"] = std::move(idVec);
428 DataMap["channel"] = std::move(channel);
429 DataMap["feedThrough"] = std::move(feedThrough);
430 DataMap["slot"] = std::move(slotVec);
431
432 // adc counts
433 DataMap["cellTime"] = std::move(cellTimeVec);
434 DataMap["cellGain"] = std::move(cellGain);
435 DataMap["cellPedestal"] = std::move(cellPedestal);
436 DataMap["adc2Mev"] = std::move(adc2Mev);
437
438 DataMap[LArSampleIndexStr] = std::move(LArSampleIndexVec); // adcCounts
439
440 //Be verbose
441 ATH_MSG_DEBUG( dataTypeName() << " retrieved with " << nEntries<< " entries" );
442
443 //All collections retrieved okay
444 return DataMap;
445
446 } // getTileData
447
448
449 //--------------------------------------------------------------------------
450
452 {
453 const auto posNeg = std::abs(m_calocell_id->pos_neg(cellid));
454 if (posNeg<1 or posNeg>3) return;
455 static constexpr std::array<int,3> datatypes{2,3,0};
456 m_sub.emplace_back(datatypes[posNeg-1]);
457 }
458
459 //--------------------------------------------------------------------------
460
462 {
463 if(m_calocell_id->pos_neg(cellid)==2)
464 m_sub.emplace_back(1);
465 else
466 m_sub.emplace_back(0);
467 }
468
469
470 //--------------------------------------------------------------------------
471
472} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
IndexedConstituentUserInfo::Index Index
#define y
#define x
Container class for CaloCell.
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
int findIndex(const IdentifierHash theHash) const
Return index of the cell with a given hash.
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
This class groups all DetDescr information related to a CaloCell.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
size_type size() const noexcept
Returns the number of elements in the collection.
virtual float pedestal(const HWIdentifier &id, int gain) const =0
This is a "hash" representation of an Identifier.
Templated class to convert any object that is streamable in a ostringstream in a string.
Definition DataType.h:21
Gaudi::Property< bool > m_cellConditionCut
Gaudi::Property< bool > m_lar
Gaudi::Property< bool > m_doLArDigit
Gaudi::Property< double > m_cellThreshold
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
const CaloCell_ID * m_calocell_id
virtual StatusCode initialize() override
Default AthAlgTool methods.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
virtual std::string dataTypeName() const override
Return the name of the data type.
Gaudi::Property< bool > m_doHECDigit
Gaudi::Property< bool > m_hec
Gaudi::Property< bool > m_fcal
const DataMap getLArDigitData(const CaloCellContainer *cellContainer, const std::string &datatype, CaloCell_ID::SUBCALO calotype)
Retrieve Tile cell location and details.
Gaudi::Property< bool > m_doFCalDigit
SG::ReadHandleKey< CaloCellContainer > m_sgKey
Gaudi::Property< bool > m_doMaskLArChannelsM5
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool) override
Retrieve all the data.
Gaudi::Property< int > m_cellTimePrec
Gaudi::Property< std::vector< Identifier::value_type > > m_LArChannelsToIgnoreM5
Gaudi::Property< int > m_cellEnergyPrec
SG::ReadHandleKey< LArDigitContainer > m_sgKeyLArDigit_esd
SG::ReadHandleKey< LArDigitContainer > m_sgKeyLArDigit_raw
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Proxy for accessing a range of float values like a vector.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58