ATLAS Offline Software
Loading...
Searching...
No Matches
LArCellCont.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
7
15
16#include "GaudiKernel/IToolSvc.h"
17#include "GaudiKernel/EventContext.h"
18
19#include <limits>
20
21// For debugging only
22#ifdef TRIGLARCELLDEBUG
23#include <iostream>
24#define LOG_DEBUG(msg) do { std::cout << "LArCellCont DEBUG " << msg << std::endl; } while(0)
25#else
26#define LOG_DEBUG(msg) do {} while (0)
27#endif
28
29
30StatusCode
32 const LArOnOffIdMapping& onOffMap,
33 const LArMCSym& mcsym,
34 const LArFebRodMapping& febrod,
35 const LArBadChannelCont& badchannel,
36 const CaloDetDescrManager& man) {
37
38 LOG_DEBUG("in initialize");
39
40 ServiceHandle<IToolSvc> toolSvc("ToolSvc", "LArCellCont");
41 CHECK_WITH_CONTEXT( toolSvc.retrieve(), "LArCellCont");
42
43 ServiceHandle<StoreGateSvc> detStore("DetectorStore", "LArCellCont");
44 CHECK_WITH_CONTEXT( detStore.retrieve(), "LArCellCont");
45
46 const LArOnlineID* onlineId = nullptr;
47 CHECK_WITH_CONTEXT( detStore->retrieve(onlineId,"LArOnlineID"), "LArCellCont" );
48
49 CHECK_WITH_CONTEXT( m_conv.initialize(febrod), "LArCellCont" );
50 m_hash.initialize(0, febrod.getLArRoModIDvec() );
51
52 const HWIdentifier larrodid(0);
53 for(size_t i=0;i<m_hash.max();i++){
54 LOG_DEBUG(i << " " << std::hex << m_hash.identifier(i) << std::dec);
55
56 // A collection per ROD/ROB/HashId
57 LArCellCollection* mycoll = new LArCellCollection(larrodid);
58 mycoll->reserve(256);
59 this->push_back(mycoll);
60 m_second.emplace_back(0);
61 m_eventNumber.push_back(std::numeric_limits<unsigned int>::max());
62 } // end of for id
63
64 std::vector<const CaloCellCorrection*> LArCellCorrTools;
65
66 MakeLArCellFromRaw makeCell;
67 makeCell.setThreshold(-100);
68 makeCell.initialize( roiMap, onOffMap, man, &LArCellCorrTools, 0 );
69
70 const bool toolAvailable = toolSvc->retrieveTool("LArBadFebMasker", m_badFebMasker).isSuccess();
71
72 if(!toolAvailable) //not a critical error. LArCellCont can proceed as usual, without masking.
73 REPORT_MESSAGE_WITH_CONTEXT(MSG::INFO, "LArCellCont") <<
74 "Failed to retrieve LArBadFebMasker - no masking will be done." << endmsg;
75
76 std::vector<uint32_t> RobsFromMissingFeb;
77
78 size_t count = 0;
79 for( const HWIdentifier& id : onlineId->channel_range() ){
80 HWIdentifier hwid = mcsym.ZPhiSymOnl(id);
81 if ( m_indexset.try_emplace (hwid, count).second ) {
82 ++count;
83 }
84 } // end of loop over online IDs
85
86 const size_t indexsetmax = m_indexset.size();
87 // the extra indexsetmax is used for invalid cells
88 m_corrBCID.resize(indexsetmax+1,0.0);
89
90 m_hashSym.clear();
91 m_hashSym.resize(onlineId->febHashMax());
92
93 for (size_t iFeb=0; iFeb<onlineId->febHashMax(); ++iFeb) {
94 const HWIdentifier& febid=onlineId->feb_Id(IdentifierHash(iFeb));
95 if( (toolAvailable && (m_badFebMasker->febMissing(febid)) ) || !toolAvailable ){
96 RobsFromMissingFeb.push_back( m_conv.getRobID( m_conv.getRodID( febrod, febid ) ) );
97 }
98 if( (toolAvailable && !(m_badFebMasker->febMissing(febid)) ) || !toolAvailable ){
99 // get RodID associated with the collection
100 const HWIdentifier& rodId = febrod.getReadoutModuleID(febid);
101 const unsigned int rodId32 = m_conv.getRodIDFromROM(rodId);
102 // index in the collection vector
103 const size_t idx = m_hash(rodId32);
104
105 LOG_DEBUG(idx << " " << std::hex << m_hash.identifier(idx) << std::dec);
106
107 // get all channels for a FEB
108 std::map<LArRoIMap::TT_ID,std::vector<LArCell* > > collMap;
109 if ( (*this)[idx]->size() != 0 ) { // This is the second FEB
110 m_second[idx] = febid;
111 }
112 std::vector<int>& hashTab = m_hashSym[idx];
113 hashTab.reserve(256);
114 unsigned int febidcomp = febid.get_identifier32().get_compact();
115 for(int ch=0; ch<128; ch++){
116 LArRoIMap::TT_ID ttId;
117 LArCell* larcell = makeCell.getLArCell(febidcomp,ch,0,0,0,ttId);
118 if ( larcell ) { // if it is a good cell
119 // Fixes default value
121 (*this)[idx]->push_back(larcell);
122 LArBadChannel bc = badchannel.offlineStatus(larcell->ID());
123
124 const bool bad = !bc.good() &&
125 // cell has some specific problems
126 ( bc.deadReadout() ||
127 bc.deadPhys() ||
128 bc.highNoiseHG() ||
129 bc.highNoiseMG() ||
130 bc.highNoiseLG() ||
132
133 if ( !bad ) collMap[ttId].push_back(larcell); // cell masked if not know to be good
134
135 HWIdentifier hwsym = mcsym.ZPhiSymOnl(onlineId->channel_Id(febid,ch));
136
137 auto itr = m_indexset.find( hwsym );
138 if ( itr != m_indexset.end() ){
139 const int index = itr->second;
140 hashTab.push_back( index );
141 } else hashTab.push_back(indexsetmax);
142
143 LOG_DEBUG("Cell registered at Collection "
144 << std::hex << febid.get_identifier32().get_compact() << std::dec <<
145 " Channel " << ch << " TTId " << (unsigned int)ttId);
146 }
147 else {// add a dummy cell
148 LOG_DEBUG("Cell not existing");
149
150 LArCell* larcell = new LArCell();
151 (*this)[idx]->push_back(larcell);
152 hashTab.push_back( indexsetmax);
153 } // end of if bad cell
154 } // end of for ch loop
155
156 for (const auto& [ttid, cells] : collMap) {
157 // Ones needs to dump the mapped vector to an allocated vector
159 vec->reserve(cells.size());
160 for(LArCell* c : cells) {
161 vec->push_back(c);
162 }
163 (*this)[idx]->setTT(ttid,vec->begin(),vec->end());
164 m_vecs.push_back(vec);
165 }
166
167 } // End of check for missing FEB
168 } // end of FEB for
169
170 m_MissingROBs.clear();
171 for(size_t i = 0 ; i < RobsFromMissingFeb.size() ; i++)
172 for(size_t j = i+1 ; j < RobsFromMissingFeb.size() ; j++)
173 if ( RobsFromMissingFeb[i] == RobsFromMissingFeb[j] )
174 m_MissingROBs.push_back(RobsFromMissingFeb[i]);
175
176 return StatusCode::SUCCESS;
177}
178
180 for(size_t i=0; i<m_hash.max(); i++){
181 LArCellCollection* coll = (*this)[i];
182 for(size_t j=0; j<coll->size(); j++) {
183 delete (*coll)[j];
184 }
185 delete coll;
186 }
187 // Destroy also the vector of vectors to TT maps.
188 for(size_t i=0; i<m_vecs.size(); i++) delete m_vecs[i];
189
190 m_hashSym.clear();
191 return StatusCode::SUCCESS;
192}
193
194// This WILL NOT trigger BSCNV. This assumes BSCNV was done before
195const std::vector<LArCellCollection*>::const_iterator
196LArCellCont::find(const HWIdentifier& rodid) const{
197 const size_t idx = m_hash(m_conv.getRodIDFromROM (rodid));
198 return (this->begin()+idx);
199}
200
201// This WILL NOT trigger BSCNV. This assumes BSCNV was done before
202const std::vector<LArCellCollection*>::const_iterator
203LArCellCont::find(unsigned int rodid) {
204 const size_t idx = m_hash(rodid);
205 if ( m_eventNumber[idx] != m_event ) { // Decoding a new event
206 m_eventNumber[idx] = m_event;
207 return (this->begin()+idx);
208 // Keep track of last decoded number
209 } else { // Event already decoded. Return Null
210 return this->end();
211 }
212}
213
214void LArCellCont::applyBCIDCorrection(unsigned int rodid) {
215 const size_t idx = m_hash(rodid);
216 LArCellCollection* col = *(this->begin()+idx);
217 std::vector<int>& hashTab = m_hashSym[idx];
218 for(size_t i=0; i<col->size(); ++i){
219 LArCell* cell = (*col)[i];
220 const float cellenergy = cell->energy();
221 const float cor = m_corrBCID[ hashTab[i] ];
222 cell->setEnergyFast( cellenergy - cor );
223 LOG_DEBUG("LArCellId= " << cell->ID() << " Ecorr= " << cor << " MeV");
224 }
225 return;
226}
227
229LArCellCont::findsec(unsigned int rodid) const{
230 const size_t idx = m_hash(rodid);
231 return m_second[idx];
232}
233
234void LArCellCont::lumiBlock_BCID(const unsigned int lumi_block, const unsigned int BCID){
235 if ( m_bcid != BCID ) {
236
237 LOG_DEBUG("Update : CURRENT lumi_block, BCID = " << lumi_block << ", " << BCID <<
238 " <--> PREVIOUS lumi_block = " << m_lumi_block << ", " << m_bcid);
239
240 m_lumi_block = lumi_block;
241 m_bcid = BCID;
242 m_BCIDcache = false;
243 }
244}
245
247
248 for (const auto& [hwid, idx] : m_indexset) {
249 if ( idx < m_corrBCID.size() ){
250 Identifier id = onoff.cnvToIdentifier(hwid);
251 float corr = avg.average(id);
252 m_corrBCID[idx] = corr;
253 }
254 }
255}
256
257bool LArCellCont::lumiBCIDCheck( const EventContext& context ) {
258 const unsigned int bcid = context.eventID().bunch_crossing_id();
259 if ( bcid == m_bcid ) return false;
260
261 const EventIDBase::event_number_t evN = context.eventID().event_number();
262 if ( evN == m_bcidEvt ) return false;
263
264 m_bcid = bcid;
265 m_bcidEvt = evN;
266 return true;
267}
#define endmsg
Definition of CaloDetDescrManager.
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
LArBadXCont< LArBadChannel > LArBadChannelCont
#define LOG_DEBUG(msg)
Mapping between calorimeter trigger id to offline/online Identifier.
size_t size() const
Number of registered mappings.
void setGain(CaloGain::CaloGain gain=CaloGain::INVALIDGAIN)
set gain
Definition CaloCell.h:497
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
This class provides the client interface for accessing the detector description information common to...
Derived DataVector<T>.
Definition DataVector.h:795
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
size_type size() const noexcept
Returns the number of elements in the collection.
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
bool deadReadout() const
bool highNoiseHG() const
bool problematicForUnknownReason() const
bool highNoiseMG() const
bool highNoiseLG() const
bool deadPhys() const
bool good() const
Returns true if no problems at all (all bits at zero).
LArBC_t offlineStatus(const Identifier id) const
Query the status of a particular channel by offline ID This is the main client access method.
Container Class for LArCell in a ROB used by EF.
void applyBCIDCorrection(unsigned int rodid)
method to apply correction based on the luminosity to the energy
Hid2RESrcID m_conv
Hardware to Source ID conversion.
HWIdentifier findsec(unsigned int id) const
Each Collection contains data from 2 FEBs.
std::vector< std::vector< int > > m_hashSym
hash references to BCID
std::vector< DataVector< LArCell > * > m_vecs
One needs to destroy the TT vectors.
std::vector< uint32_t > m_MissingROBs
List of Missing ROBs to be disabled at the RS.
StatusCode initialize(const LArRoIMap &roiMap, const LArOnOffIdMapping &onOffMap, const LArMCSym &mcsym, const LArFebRodMapping &febrod, const LArBadChannelCont &badchannel, const CaloDetDescrManager &ddm)
initialize method.
std::vector< float > m_corrBCID
corrections for a given BCID
unsigned int m_bcid
const ILArBadFebMasker * m_badFebMasker
A tool to help mask cells.
LArRodIdHash m_hash
Hash ID Identifier mapping to collection index.
bool m_BCIDcache
flag to only update cache when trying to apply corrections
const std::vector< LArCellCollection * >::const_iterator find(const HWIdentifier &id) const
Finds a collection by its LArReadoutModuleID.
unsigned int m_lumi_block
current lumi_block
void lumiBlock_BCID(const unsigned int lumi_block, const unsigned int BCID)
sets LumiBlock and BCID
void updateBCID(const CaloBCIDAverage &, const LArOnOffIdMapping &)
update BCID dependent correction table for MT case
StatusCode finalize(void)
finalize method.
std::map< HWIdentifier, size_t > m_indexset
index table
EventIDBase::event_number_t m_bcidEvt
unsigned int m_event
this event number
std::vector< unsigned int > m_eventNumber
eventNumber of a given Collection
bool lumiBCIDCheck(const EventContext &context)
std::vector< HWIdentifier > m_second
FEB Hardware Identifier for second FEBs in a Collection.
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
const std::vector< HWIdentifier > & getLArRoModIDvec() const
"iterator" on LArReadoutModuleIDs
HWIdentifier getReadoutModuleID(const HWIdentifier &id) const
Helper class to handle z-phi symmetry of calibration constants in MC.
Definition LArMCSym.h:19
HWIdentifier ZPhiSymOnl(const HWIdentifier notSymOnlId) const
Find the symmetric HWID for an online channel identifier.
Definition LArMCSym.h:91
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
id_range channel_range() const
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
size_type febHashMax() const
define feb hash tables max size
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Mapping between calorimeter trigger id to offline/online Identifier.
Definition LArRoIMap.h:31
unsigned int TT_ID
Definition LArRoIMap.h:34
Building LArCell objects from LArRawChannel.
void initialize(const LArRoIMap &roiMap, const LArOnOffIdMapping &onOffMap, const CaloDetDescrManager &man, const std::vector< const CaloCellCorrection * > *pCorr, unsigned int poolMaxSize=190000)
initialize the internal map
LArCell * getLArCell(unsigned int feb, unsigned int chan, int e, int t, int q, CaloGain::CaloGain caloGain, unsigned int &ttId) const
access by Identifier
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
@ LARHIGHGAIN
Definition CaloGain.h:18
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition index.py:1