57{
61
63 ATH_MSG_ERROR(
"Key list is empty! No containers to process!" );
64 return StatusCode::FAILURE;
65 }
66
67
69 unsigned nSaturation=0;
70
75 ATH_MSG_ERROR(
"Failed to retrieve FebErrorSummary object!" );
77 }
78 }
79 else
81 ATH_MSG_WARNING(
"No FebErrorSummaryObject found! Feb errors not checked!" );
82
83 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{
m_cablingKey};
84 const LArOnOffIdMapping*
cabling{*cablingHdl};
85 if(!cabling) {
86 ATH_MSG_ERROR(
"Do not have cabling object LArOnOffIdMapping");
87 return StatusCode::FAILURE;
88 }
89
90 SG::ReadCondHandle<LArBadChannelCont> bcHdl{
m_BCKey};
92
93 SG::ReadCondHandle<ILArPedestal> pedHdl{
m_pedKey};
94 const ILArPedestal* larPedestal=*pedHdl;
95
96
97 const LArAccumulatedCalibDigitContainer* larAccumulatedCalibDigitContainer;
98
99
100
101 for (
const std::string& key :
m_keylist) {
102
103 sc =
evtStore()->retrieve(larAccumulatedCalibDigitContainer,key);
105 ATH_MSG_WARNING(
"Cannot read LArAccumulatedCalibDigitContainer from StoreGate! key=" << key );
106 continue;
107 }
108
109
110 LArAccumulatedCalibDigit febErrorDummy;
111 LArAccumulatedCalibDigit inexistingDummy;
112
113
114 HWIdentifier lastFailedFEB(0);
115
116 if(larAccumulatedCalibDigitContainer->
empty()) {
117 ATH_MSG_DEBUG(
"LArAccumulatedCalibDigitContainer with key = " << key <<
" is empty " );
118
119 continue;
120 } else {
121 ATH_MSG_DEBUG(
"Processing LArAccumulatedCalibDigitContainer with key = " << key
122 <<
". Size: " << larAccumulatedCalibDigitContainer->
size() );
123 }
124
125
128 }
129
130
131
132 for (int bec : {0,1}) {
134 for (
unsigned iphi=0;iphi!=
m_MAXphi;++iphi) {
135 for (unsigned iside=0;iside<2;++iside) {
137 }
138 }
139 }
140 }
143
144 for (const LArAccumulatedCalibDigit* dig : *larAccumulatedCalibDigitContainer) {
145 const HWIdentifier chid=dig->hardwareID();
147 if (!
cabling->isOnlineConnected(chid))
continue;
148
149
150 const Identifier
id=
cabling->cnvToIdentifier(chid);
151 if (
m_emId->sampling(
id)!=1)
continue;
152
154 if (febErrSum) {
157 if (febid!=lastFailedFEB) {
158 lastFailedFEB=febid;
160 <<
" reports error(s):" << febErrSum->
error_to_string(febErrs) <<
". Data ignored." );
161 }
162 dig=&febErrorDummy;
163 }
164 }
165
166
173 << ieta <<
"(max " <<
m_MAXeta[bec] <<
")" );
174 return StatusCode::FAILURE;
175 }
177
178
179
182 const std::vector<uint64_t>& samples=dig->sampleSum();
183 const size_t& nS=samples.size();
185 for (
size_t i=0;
i<nS;++
i) {
189 << ", <ADC> = " << samples[i]/dig->nTriggers()
190 << ", DAC = " << dig->DAC()
191 <<
") for channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec
192 << ". Skipping.");
193 break;
194 }
195 }
196 }
197 if (saturated) {
198 ++nSaturation;
199 continue;
200 }
201
203
204 }
205
208
212 }
213 else
216
217
218
219
220
221
223 neighbours[0].
dist=-2;
224 neighbours[1].dist=-1;
225 neighbours[2].dist=1;
226 neighbours[3].dist=2;
227
228 for (unsigned bec : {0,1}) {
229 for (unsigned iside=0; iside<2; iside++) {
231 for (
unsigned iphi=0; iphi<
m_MAXphi; iphi++) {
232 const unsigned iphi2=iphi+
m_MAXphi*iside;
234 if (currDig==nullptr || currDig==&febErrorDummy) continue;
235
241 << iphi2 << ") should not be touched accoring to jobConfig");
242 continue;
243 }
244
245 const unsigned NtotSamples = currDig->
nsamples();
246 const unsigned NbTriggers = currDig->
nTriggers();
248
249
250 for (
unsigned i=0;
i<4;
i++) {
251
252 neighbours[
i].dig=
nullptr;
253 neighbours[
i].ped=0.;
254 const int neigbEtaItx=neighbours[
i].dist+(
int)ieta;
255
257 ATH_MSG_DEBUG(
"Neighbour " << neighbours[i].dist <<
" , ieta=" << neigbEtaItx
258 <<
" doesn't exist. (min="<<
m_MINeta[bec] <<
" ,max=" <<
m_MAXeta[bec] <<
")");
259 neighbours[
i].dig=&inexistingDummy;
260 continue;
261 }
262 const LArAccumulatedCalibDigit* neighDig=
m_stripsLookUp[
bec][iphi2][neigbEtaItx];
263
264 if (!neighDig) {
265
266
267 if (
msgLvl(MSG::WARNING)) {
269 ATH_MSG_DEBUG(
"FEB missing for neighbour " << neighbours[i].dist <<
" to be added to strip 0x"
270 <<
m_onlineHelper->channel_name(chid) <<
" (Eta = " << ieta <<
", Phi = " << iphi <<
")");
271 }
272 else {
273 ATH_MSG_WARNING(
"Cannot find neighbour " << neighbours[i].dist <<
" to be added to strip 0x"
274 <<
m_onlineHelper->channel_name(chid) <<
" (Eta = " << ieta <<
", Phi = " << iphi <<
")" );
275 }
276 }
277 continue;
278 }
279 if (neighDig==&febErrorDummy) {
281 << " (Eta = " << ieta << ", Phi = " << iphi <<"), has a FEB error. Ignored.");
282 continue;
283 }
284
285
288 <<
" (Eta = " << ieta <<
", Phi = " << iphi <<
", " <<
printMaxSample(neighDig)
289 << ") is pulsed. Not used for correction." );
290 continue;
291 }
292
293
296 << " (Eta = " << ieta << ", Phi = " << iphi
297 << ") is flagged by the LArBadChannelMaskingTool. Not used for correction.");
298 continue;
299 }
300
301
304 ATH_MSG_ERROR(
"No pedestal are available for neighbour " << neighbours[i].dist <<
" of strip "
305 <<
m_onlineHelper->channel_name(chid) <<
" (Eta = " << ieta <<
", Phi = " << iphi <<
"). Not used for correction!" );
306 continue;
307 }
308
309 neighbours[
i].dig=neighDig;
310 neighbours[
i].ped=pedestal;
311
312
313 neighbours[
i].weight=1.0;
314
315 const int nnEta=ieta+2*neighbours[
i].dist;
318 if (nnDig!=nullptr) {
319
322 << " has another pulsed cell in the neighborhood. Setting weight to 0.5");
323 neighbours[
i].weight=0.5;
324 }
325 }
326 }
327 }
328
329
330
331 std::vector<double> SampleSums(NtotSamples);
332 for (std::size_t SampleIndex=0;SampleIndex<NtotSamples; ++SampleIndex ) {
334 ATH_MSG_VERBOSE(
"SampleSum " << SampleIndex <<
" (" << SampleSums[SampleIndex] <<
" ADC counts / " << NbTriggers <<
" Ntriggers)");
335 }
336
337 for (
unsigned i=0;
i<4;
i++) {
338 if (neighbours[i].dig==&inexistingDummy) {
340 << " (Eta = " << ieta << ", Phi = " << iphi << ") does not exist.");
341
342 continue;
343 }
344
345 if (neighbours[i].dig) {
348 << " (Eta = " << ieta << ", Phi = " << iphi << ") is used for correction");
349 }
350 else {
353 << " cannot be used. Taking mirrored neighbour " << neighbours[j].dist << " instead." );
354 if (neighbours[j].dig!=nullptr && neighbours[j].dig!=&inexistingDummy){
357 << " (Eta = " << ieta << ", Phi = " << iphi << ") is used for correction");
358 }
359 else {
361 << " cannot be used too. No correction applied" );
362 }
363 }
364 }
365
366
367 std::vector<uint64_t> SampleSumInt(NtotSamples);
368 bool unresonable=false;
370 for (std::size_t SampleIndex=0;SampleIndex<NtotSamples; ++SampleIndex ) {
371 const double& thisSampleSum=SampleSums[SampleIndex];
373 if (thisSampleSum<0) {
374 unresonable=true;
376 << " (Eta = " << ieta << ", Phi = " << iphi << ") Resulting ADC sample " << SampleIndex <<" negative! "
377 << thisSampleSum << " instead of " << oldVal << " Not corrected." );
378 break;
379 }
380
381 if (SampleIndex==iPeak) {
382 const float dev=(thisSampleSum-oldVal)/oldVal;
385 unresonable=true;
387 <<
") DAC=" << currDig->
DAC() <<
": Resulting ADC sample " << SampleIndex <<
" looks unreasonable: "
388 << thisSampleSum << " instead of " << oldVal << " (off by " << dev*100 << "%)"
389 << " (=" << thisSampleSum/NbTriggers << " -> " << oldVal/NbTriggers <<", ped="
390 << larPedestal->
pedestal(chid,t_gain)
391 << " Not Corrected.");
392 break;
393 }
394 }
395 SampleSumInt[SampleIndex] = (
uint64_t)(thisSampleSum);
396 }
397
398
399 if (unresonable) {
402 }
403 else {
405 << currDig->
sampleSum()[2] <<
"->" << SampleSumInt[2]);
406
407 const_cast<LArAccumulatedCalibDigit*>(currDig)->setSampleSum(SampleSumInt);
408 }
409 }
410 }
411 }
412 }
413 }
414 }
415
416 if (nSaturation) {
417 ATH_MSG_INFO(
"Found " << nSaturation <<
" saturating digits in this event." );
418 }
419 return StatusCode::SUCCESS;
420}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define maxValue(current, test)
LArBadXCont< LArBadChannel > LArBadChannelCont
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
virtual float pedestal(const HWIdentifier &id, int gain) const =0
value_type get_compact() const
Get the compact id.
bool isPulsed() const
Tell if this channel was pulsed.
CaloGain::CaloGain gain() const
return gain value
const HWIdentifier & hardwareID() const
Return HWIdentifier.
const std::vector< uint64_t > & sampleSum() const
return a reference to a stl vector containing the sample-sums
int DAC() const
return the number of samples
unsigned nTriggers() const
return the number of triggers
size_t nsamples() const
return number of samples
static std::string error_to_string(uint16_t error)
interpret the error in string
uint16_t feb_error(HWIdentifier febid) const
get error for feb
void correctSamples(std::vector< double > &dest, const neighbour_t &neighbor) const
SG::ReadCondHandleKey< ILArPedestal > m_pedKey
std::set< HWIdentifier > m_uncorrectedIds
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
const LArOnlineID * m_onlineHelper
unsigned int m_event_counter
std::array< std::vector< std::bitset< 128 > >, 2 > m_knownMissingFebs
size_t getEtaIndex(const Identifier) const
SG::ReadCondHandleKey< LArBadChannelCont > m_BCKey
Gaudi::Property< float > m_acceptableDifference
StatusCode initKnownMissingFebs()
XtalkCorrHisto m_differences
uint16_t m_fatalFebErrorPattern
const unsigned int m_MAXphi
static std::string printMaxSample(const LArAccumulatedCalibDigit *thisDig)
size_t getPhiIndex(const Identifier) const
std::array< std::vector< std::vector< const LArAccumulatedCalibDigit * > >, 2 > m_stripsLookUp
Gaudi::Property< std::vector< std::string > > m_keylist
static constexpr auto m_MAXeta
LArBadChannelMask m_dontUseForCorrMask
LArBadChannelMask m_dontCorrMask
static constexpr auto m_MINeta
Gaudi::Property< unsigned int > m_ADCsatur
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
::StatusCode StatusCode
StatusCode definition for legacy code.
int nStrips(const MuonGM::TgcReadoutElement &readoutEle, int layer)
setScaleOne setStatusOne saturated