Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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;
37  if (m_skipDisconnected) {
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 ){
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;
171  if (m_skipDisconnected)
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 
245 void 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 
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
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:407
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:15
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:245
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:141
LArBadChannel::offOFCs
bool offOFCs() const
Definition: LArBadChannel.h:100
LArBadChannel2Ascii::execute
virtual StatusCode execute() final
Definition: LArBadChannel2Ascii.cxx:29
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
runIDAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runIDAlign.py:63
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