ATLAS Offline Software
Loading...
Searching...
No Matches
LArCelldeadOTXAlg.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#include "LArCelldeadOTXAlg.h"
6
8#include "CaloDetDescr/CaloDetDescrElement.h"
13
15
16 ATH_CHECK(m_deadOTXFromSCKey.initialize());
17 ATH_CHECK(m_SCKey.initialize());
18 ATH_CHECK(m_MFKey.initialize());
19 ATH_CHECK(m_badSCKey.initialize());
20 ATH_CHECK(m_cablingKey.initialize());
21 ATH_CHECK(m_cablingSCKey.initialize());
22 ATH_CHECK(m_caloMgrKey.initialize());
23
24 ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
25 ATH_CHECK(detStore()->retrieve(m_onlineSCID, "LArOnline_SuperCellID"));
26 ATH_CHECK(detStore()->retrieve(m_calo_id, "CaloCell_ID"));
27
28 ATH_CHECK(m_scidtool.retrieve());
29
30 return StatusCode::SUCCESS;
31}
32
33StatusCode LArCelldeadOTXAlg::execute(const EventContext& ctx) const {
34
35 ATH_MSG_VERBOSE(" in execute...");
36
37 StatusCode sc = StatusCode::SUCCESS;
38 std::call_once(m_onceFlag, &LArCelldeadOTXAlg::buildMap, this, ctx, sc);
39
40 if (sc.isFailure()) {
41 ATH_MSG_ERROR("Call to LArCelldeadOTXAlg::buidMap returned an error");
42 return StatusCode::FAILURE;
43 }
44
46 std::unique_ptr<LArDeadOTXFromSC> deadHandle = std::make_unique<LArDeadOTXFromSC>();
47
48 // get SuperCellContainer
50 if (!scHdl.isValid()) {
51 ATH_MSG_WARNING("Do not have SuperCell container no patching !!!!");
52 return StatusCode::SUCCESS;
53 }
54
55 const unsigned int bcid = ctx.eventID().bunch_crossing_id();
56
57 // get the SC, container is unordered, so have to loop
58 const LArRawSCContainer* scells = scHdl.cptr();
59 std::vector<float> vecEnergies;
60 vecEnergies.reserve(m_onlineSCID->channelHashMax());
61 vecEnergies.resize(m_onlineSCID->channelHashMax(),0.0);
62 //will be used below; avoid recreating in tight loop
63 std::vector<float> cellEnergies(128, 0.f);
64 //
65 for (const auto* supercell : *scells) {
66 if (!supercell)
67 continue;
68 const HWIdentifier scHwid = supercell->hardwareID();
69 uint32_t scIDHash = (m_onlineSCID->channel_Hash(scHwid)).value();
70
71 const std::vector<unsigned short>& bcids = supercell->bcids();
72 const std::vector<int>& energies = supercell->energies();
73 const std::vector<bool>& satur = supercell->satur();
74
75 // Look for bcid:
76 float scEne = 0;
77 const size_t nBCIDs = bcids.size();
78 size_t i = 0;
79 for (i = 0; i < nBCIDs && bcids[i] != bcid; i++)
80 ;
81
82 if (ATH_LIKELY(!satur[i]))
83 scEne = energies[i];
84 if (scEne < m_scCut) {
85 ATH_MSG_VERBOSE("SC value " << scEne << " below threshold, ignoring");
86 continue;
87 }
88 vecEnergies[scIDHash]=scEne;
89 } // End loop over SuperCell container
90
91 for(size_t i=0;i<m_channels.size();i++){
92 std::vector<uint32_t>& chans = m_channels[i];
93 std::vector<float>& mults = m_multipliers.at(i);
94 //set vector to zero
95 std::fill(cellEnergies.begin(), cellEnergies.end(),0.f);
96 for(size_t j=0; j<chans.size(); j++) {
97 if ( chans[j] < 0xfffffffe ) cellEnergies[j] = mults[j]*vecEnergies[chans[j]];
98 }
99 deadHandle->addFEB(m_febs[i],cellEnergies);
100 }
101 ATH_CHECK(deadHdl.record(std::move(deadHandle)) );
102
104 //cell->setProvenance(cell->provenance() | LArProv::PATCHED);
105
106 return StatusCode::SUCCESS;
107}
108
109void LArCelldeadOTXAlg::buildMap(const EventContext& ctx, StatusCode& sc) const {
110
111 sc = StatusCode::FAILURE;
112
114 if (!cablingHdl.isValid()) {
115 ATH_MSG_ERROR("Do not have Onl-Ofl cabling map !!!!");
116 return;
117 }
118 const LArOnOffIdMapping* oflCabling = cablingHdl.cptr();
119
121 if (!cablingSCHdl.isValid()) {
122 ATH_MSG_ERROR("Do not have Onl-Ofl cabling map for SuperCells !!!!");
123 return;
124 }
125
126 const LArOnOffIdMapping* scCabling = cablingSCHdl.cptr();
127
129 if (!mfHdl.isValid()) {
130 ATH_MSG_ERROR("Do not have Missing FEBs container !!!!");
131 return;
132 }
133
135 if (!caloMgrHandle.isValid()) {
136 ATH_MSG_ERROR("Do not have CaloDetDescManager !!!");
137 return;
138 }
139
140 const CaloDetDescrManager* caloDDM = *caloMgrHandle;
141
143 if (!bcSCHdl.isValid()) {
144 ATH_MSG_ERROR("Do not have BadSCContainer !!!!");
145 return;
146 }
147 const LArBadChannelCont* bcSCCont = *bcSCHdl;
148
149 const std::vector<std::pair<unsigned int, LArBadFeb> >& badFebs = mfHdl->fullCont();
150
151 for (const auto& idBF : badFebs) {
152 if (idBF.second.deadReadout()) {
153 const HWIdentifier febid(idBF.first);
154 m_febs.push_back(febid);
155 ATH_MSG_INFO("FEB " << m_onlineID->channel_name(febid) << " labelled as dead");
156 std::vector<float> vector_of_multipliers;
157 std::vector<uint32_t> vector_of_chans;
158 const int nChans = m_onlineID->channelInSlotMax(febid);//may return -999
159 if (ATH_UNLIKELY(nChans < 0)) {
160 ATH_MSG_WARNING("LArCelldeadOTXAlg::buildMap : nChans<0");
161 continue;
162 }
163 vector_of_multipliers.resize(nChans,0.0);
164 vector_of_chans.resize(nChans,0xffffffff);
165 for (int ch = 0; ch < nChans; ++ch) {
166 const HWIdentifier chid = m_onlineID->channel_Id(febid, ch);
167 const Identifier id = oflCabling->cnvToIdentifier(chid);
168 const IdentifierHash hashId = m_calo_id->calo_cell_hash(id);
169 const Identifier scID = m_scidtool->offlineToSuperCellID(id);
170 const HWIdentifier scHwid = scCabling->createSignalChannelID(scID);
171 const IdentifierHash hashidSC = m_onlineSCID->channel_Hash(scHwid);
172 if (!bcSCCont->status(scHwid).good()) {
173 ATH_MSG_DEBUG("SuperCell with id 0x" << std::hex << scHwid.get_identifier32().get_compact() << std::dec
174 << " is ignored b/c of it's bad-channel word. Connected to deadFEB channel " << m_onlineID->channel_name(chid));
175 continue;
176 }
177 const unsigned nCell = (m_scidtool->superCellToOfflineID(scID)).size();
178 const CaloDetDescrElement* dde = caloDDM->get_element(hashId);
179 if (ATH_UNLIKELY(!dde)) {
180 ATH_MSG_INFO("No DetDescElement for cell hash : " << hashId);
181 } else {
182 // 12.5: Convert SC ADC to MeV (Et), et ->e, scale by the number of regular cells connected to this super-cell
183 const float convFactor = 12.5 * (1.0 / nCell) * (1.0 / dde->sinTh());
184 vector_of_multipliers[ch]=convFactor;
185 vector_of_chans[ch]=hashidSC.value();
186 }
187 } // end loop over channels of one dead FEB
188 m_multipliers.push_back(std::move(vector_of_multipliers));
189 m_channels.push_back(std::move(vector_of_chans));
190 } // end if feb is deadAll
191 } // end loop over dead febs
192
193 sc = StatusCode::SUCCESS;
194 return;
195}
196
#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)
#define ATH_LIKELY(x)
#define ATH_UNLIKELY(x)
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t sc
Handle class for recording to StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
This class groups all DetDescr information related to a CaloCell.
float sinTh() const
for algorithm working in transverse Energy
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
value_type value() const
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
bool good() const
Returns true if no problems at all (all bits at zero)
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
const LArOnline_SuperCellID * m_onlineSCID
ToolHandle< ICaloSuperCellIDTool > m_scidtool
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
const LArOnlineID * m_onlineID
SG::ReadCondHandleKey< LArBadChannelCont > m_badSCKey
virtual StatusCode initialize() override final
virtual StatusCode execute(const EventContext &ctx) const override final
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Gaudi::Property< int > m_scCut
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingSCKey
SG::ReadHandleKey< LArRawSCContainer > m_SCKey
void buildMap(const EventContext &ctx, StatusCode &sc) const
SG::WriteHandleKey< LArDeadOTXFromSC > m_deadOTXFromSCKey
SG::ReadCondHandleKey< LArBadFebCont > m_MFKey
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Container class for LArRawSC.
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.