ATLAS Offline Software
Loading...
Searching...
No Matches
LArBadChannel2Ascii.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#include <format>
12#include <fstream>
13#include <algorithm>
14
16
17 ATH_MSG_INFO ( "initialize()" );
18
19 ATH_CHECK(m_BCKey.initialize());
20
21 ATH_CHECK(m_BFKey.initialize(!m_executiveSummaryFile.empty()));
22
24
25 return StatusCode::SUCCESS;
26}
27
28
30
31 const bool doExecSummary=(!m_executiveSummaryFile.empty());
32
34 const LArBadChannelCont* badChannelCont{*bch};
35
36 const LArOnOffIdMapping* cabling=nullptr;
39 cabling=(*cablingHdl);
40 }
41
42 const LArBadFebCont* badFebCont=nullptr;
43 if (doExecSummary && !m_isSC) {
45 badFebCont=(*badFebHdl);
46 }
47
48 const LArOnlineID_Base* larOnlineID;
49 if ( m_isSC ){
50 const LArOnline_SuperCellID* ll;
51 StatusCode sc = detStore()->retrieve(ll, "LArOnline_SuperCellID");
52 if (sc.isFailure()) {
53 ATH_MSG_ERROR( "Could not get LArOnlineID helper !" );
54 return StatusCode::FAILURE;
55 } else {
56 larOnlineID = ll;
57 ATH_MSG_DEBUG("Found the LArOnlineID helper");
58 }
59 } else { // m_isSC
60 const LArOnlineID* ll;
61 StatusCode sc = detStore()->retrieve(ll, "LArOnlineID");
62 if (sc.isFailure()) {
63 ATH_MSG_ERROR( "Could not get LArOnlineID helper !");
64 return StatusCode::FAILURE;
65 } else {
66 larOnlineID = ll;
67 ATH_MSG_DEBUG(" Found the LArOnlineID helper. ");
68 }
69 }
70
71 std::ostream *out = &(std::cout);
72 std::ofstream outfile;
73 if (!m_fileName.empty()) {
74 outfile.open(m_fileName.value().c_str(),std::ios::out);
75 if (outfile.is_open()) {
76 ATH_MSG_INFO ( "Writing to file " << m_fileName );
77 out = &outfile;
78 }
79 else
80 ATH_MSG_ERROR ( "Failed to open file " << m_fileName );
81 }
82
83 const LArBadChanBitPacking packing;
84 const LArBadChanSCBitPacking SCpacking;
85
86 std::vector<std::vector<unsigned> > problemMatrix(nProblemTypes, std::vector<unsigned>(nParts));
87
88 std::vector<HWIdentifier>::const_iterator it = larOnlineID->channel_begin();
89 std::vector<HWIdentifier>::const_iterator it_e = larOnlineID->channel_end();
90 unsigned count = 0, nConnected = 0;
91 std::vector<unsigned> nPerPart(nParts);
92
93 for (; it != it_e; ++it) {
94 const HWIdentifier chid = *it;
95 if (cabling && !cabling->isOnlineConnected(chid))
96 continue;
97 ++nConnected;
98
99 DetPart dp = EMB;
100 if (larOnlineID->isHECchannel(chid))
101 dp = HEC;
102 else if (larOnlineID->isEMECchannel(chid))
103 dp = EMEC;
104 else if (larOnlineID->isFCALchannel(chid))
105 dp = FCAL;
106
107 ++nPerPart[dp];
108
109 LArBadChannel bc = badChannelCont->status(chid);
110
111 if (!bc.good()) {
112 ++count;
113 (*out) << std::format("{} {} {} {} {} 0 ",larOnlineID->barrel_ec(chid),larOnlineID->pos_neg(chid),larOnlineID->feedthrough(chid),larOnlineID->slot(chid),larOnlineID->channel(chid));
114 // Dummy 0 for calib-line
115 if (m_isSC) {
116 (*out) << SCpacking.stringStatus(bc);
117 } else {
118 (*out) << packing.stringStatus(bc);
119 }
120
121 (*out) << std::format(" # {:#x}", chid.get_identifier32().get_compact());
122 if (cabling) {
123 Identifier offid = cabling->cnvToIdentifier(chid);
124 (*out) << std::format(" -> {:#x}",offid.get_identifier32().get_compact());
125 }
126 (*out) << std::endl;
127 } // End if channel is not good (regular printout)
128
129 if (doExecSummary) {
130 HWIdentifier fid = larOnlineID->feb_Id(chid);
131 LArBadFeb bf;
132 if (!m_isSC) bf= badFebCont->status(fid);
133
134 if (bc.deadReadout() || bc.maskedOSUM())
135 ++problemMatrix[DeadReadout][dp];
136 if (bc.deadPhys())
137 ++problemMatrix[DeadPhys][dp];
138 if (bc.deadCalib())
139 ++problemMatrix[DeadCalib][dp];
140 if (bc.reallyNoisy())
141 ++problemMatrix[Noisy][dp];
142 if (bc.sporadicBurstNoise())
143 ++problemMatrix[Sporadic][dp];
144
145 if (bc.distorted() || bc.deformedTail() || bc.deformedPulse())
146 ++problemMatrix[Distorted][dp];
147
148 if (bc.ADCJump() || bc.nonLinearRamp() || bc.SCAProblem() || bc.offOFCs() || bc.offAmplitude() || bc.offScale()) {
149 ++problemMatrix[PeakReco][dp];
150 }
151
152 if (bc.lowLightFibre() || bc.transmissionErrorFibre()) {
153 ++problemMatrix[Fibre][dp];
154 }
155
156 if (!m_isSC) { //problematic febs apply only to regular cells
157 if (bf.deadAll() || bf.deadReadout() || bf.deactivatedInOKS())
158 ++problemMatrix[DeadFEB][dp];
159 if (bf.deadAll() || bf.deadReadout() || bf.deactivatedInOKS() || bc.deadReadout() || bc.deadPhys() || bc.reallyNoisy())
160 ++problemMatrix[GrandTotalDead][dp];
161 }
162 else {
163 if(bc.maskedOSUM() || bc.deadReadout() || bc.deadPhys() || bc.reallyNoisy())
164 ++problemMatrix[GrandTotalDead][dp];
165 }
166
167
168 } // end if executive Summary
169
170 } // end loop over channels;
172 ATH_MSG_INFO ( "Found " << count << " entries in the bad-channel database. (Number of connected cells: " << nConnected << ")" );
173 else
174 ATH_MSG_INFO ( "Found " << count << " entries in the bad-channel database. (Number of cells: " << nConnected << ")");
175 if (m_wMissing)
176 ATH_MSG_INFO ( "Including missing FEBs" );
177 else
178 ATH_MSG_INFO ( "Without missing FEBs" );
179 if (outfile.is_open())
180 outfile.close();
181
182
183 if (doExecSummary) {
184 std::ofstream exeSum;
185 exeSum.open(m_executiveSummaryFile.value().c_str(),std::ios::out);
186 if (!exeSum.is_open()) {
187 ATH_MSG_ERROR ( "Failed to open file " << m_executiveSummaryFile );
188 return StatusCode::FAILURE;
189 }
190
191 ATH_MSG_INFO ( "Writing Executive Summary to file " << m_executiveSummaryFile );
192
193 if (m_isSC) {
194 exeSum << "LAr SuperCells dead readout (incl masked OSUM)" << std::endl;
195 writeSum(exeSum,problemMatrix[DeadReadout],nPerPart);
196
197 exeSum << "LAr SuperCells suffering from high noise:" << std::endl;
198 writeSum(exeSum,problemMatrix[Noisy],nPerPart);
199
200 exeSum << "LAr SuperCells w/o calibration (constants from phi average of eta neighbours):" << std::endl;
201 writeSum(exeSum,problemMatrix[DeadCalib],nPerPart);
202
203 exeSum << "LAr SuperCells with distorted pulse shape:" << std::endl;
204 writeSum(exeSum,problemMatrix[Distorted],nPerPart);
205
206 exeSum << "LAr SuperCells having problems with the peak reco:" << std::endl;
207 writeSum(exeSum,problemMatrix[PeakReco],nPerPart);
208
209 exeSum << "LAr SuperCells having problems with the optical transmission:" << std::endl;
210 writeSum(exeSum,problemMatrix[Fibre],nPerPart);
211
212 exeSum << "LAr SuperCells not usable:" << std::endl;
213 writeSum(exeSum,problemMatrix[GrandTotalDead],nPerPart);
214 }
215 else {
216 exeSum << "LAr dead readout channels:" << std::endl;
217 writeSum(exeSum,problemMatrix[DeadReadout],nPerPart);
218
219 exeSum << "LAr permanently dead channels inside detector:" << std::endl;
220 writeSum(exeSum,problemMatrix[DeadPhys],nPerPart);
221
222 exeSum << "LAr noisy readout channels (more than 10 sigma above phi average or unstable):" << std::endl;
223 writeSum(exeSum,problemMatrix[Noisy],nPerPart);
224
225 exeSum << "LAr readout channels showing sporadic noise bursts:" << std::endl;
226 writeSum(exeSum,problemMatrix[Sporadic],nPerPart);
227
228 exeSum << "LAr readout channels w/o calibration (constants from phi average of eta neighbours):" << std::endl;
229 writeSum(exeSum,problemMatrix[DeadCalib],nPerPart);
230
231 exeSum << "LAr readout channels connected to inactive Front End Boards:" << std::endl;
232 writeSum(exeSum,problemMatrix[DeadFEB],nPerPart);
233
234 exeSum << "LAr readout channels not usable:" << std::endl;
235 writeSum(exeSum,problemMatrix[GrandTotalDead],nPerPart);
236 }
237
238 exeSum.close();
239 }
240
241 return StatusCode::SUCCESS;
242}
243
244
245void LArBadChannel2Ascii::writeSum(std::ofstream& exeFile, const std::vector<unsigned>& probs, const std::vector<unsigned>& nChans) const {
246
247 const unsigned nTot=std::accumulate(nChans.begin(),nChans.end(),0);
248 const unsigned nTotProb=std::accumulate(probs.begin(),probs.end(),0);
249
250 constexpr const char* fmt="{:>7}: {:>5} of {} ({:.3f}%)\n";
251 //avoid divide by zero, return 0. instead
252 auto f = [](unsigned den)->double{
253 if (den > 0) return 100./den;
254 return 0.;
255 };
256 exeFile << std::format(fmt, "EMB",probs[EMB], nChans[EMB], probs[EMB]*f(nChans[EMB]));
257 exeFile << std::format(fmt, "EMEC",probs[EMEC], nChans[EMEC], probs[EMEC]*f(nChans[EMEC]));
258 exeFile << std::format(fmt, "EM tot",probs[EMEC]+probs[EMB],nChans[EMB]+nChans[EMEC],(probs[EMEC]+probs[EMB])*f(nChans[EMEC]+nChans[EMB]));
259 exeFile << std::format(fmt, "EMEC",probs[HEC], nChans[HEC], probs[HEC]*f(nChans[HEC]));
260 exeFile << std::format(fmt, "EMEC",probs[FCAL], nChans[FCAL], probs[FCAL]*f(nChans[FCAL]));
261 exeFile << std::format(fmt, "Total",nTotProb,nTot,nTotProb*f(nTot));
262
263 exeFile << std::endl;
264
265}
266
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
LArBadXCont< LArBadFeb > LArBadFebCont
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t sc
const char *const fmt
const ServiceHandle< StoreGateSvc > & detStore() const
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
SG::ReadCondHandleKey< LArBadChannelCont > m_BCKey
SG::ReadCondHandleKey< LArBadFebCont > m_BFKey
virtual StatusCode initialize() final
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Gaudi::Property< std::string > m_fileName
void writeSum(std::ofstream &exeFile, const std::vector< unsigned > &probs, const std::vector< unsigned > &nChans) const
Gaudi::Property< std::string > m_executiveSummaryFile
Gaudi::Property< bool > m_isSC
Gaudi::Property< bool > m_skipDisconnected
Gaudi::Property< bool > m_wMissing
virtual StatusCode execute() final
bool deadReadout() const
bool offAmplitude() const
bool transmissionErrorFibre() const
bool lowLightFibre() const
bool deformedPulse() const
bool offOFCs() const
bool offScale() const
bool reallyNoisy() const
bool ADCJump() const
bool deadCalib() const
bool nonLinearRamp() const
bool deformedTail() const
bool sporadicBurstNoise() const
bool SCAProblem() const
bool deadPhys() const
bool maskedOSUM() const
bool good() const
Returns true if no problems at all (all bits at zero)
bool distorted() const
bool deadAll() const
FEB is completely missing, e.g. powered off.
Definition LArBadFeb.h:30
bool deactivatedInOKS() const
Deactivated in OKS.
Definition LArBadFeb.h:39
bool deadReadout() const
FEB is not sending readout data, but the L1 trigger path is working.
Definition LArBadFeb.h:33
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
Helper for the Liquid Argon Calorimeter cell identifiers.
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
virtual bool isEMECchannel(const HWIdentifier id) const =0
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 barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
id_iterator channel_end() const
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
id_iterator channel_begin() const
Returns an iterator pointing to a channel identifier collection.
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
bool isFCALchannel(const HWIdentifier id) const
virtual bool isHECchannel(const HWIdentifier id) const =0
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
std::string stringStatus(const LArBadChannel &bc) const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146