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