ATLAS Offline Software
Loading...
Searching...
No Matches
LArBadChannelHunter.cxx File Reference

Go to the source code of this file.

Functions

StatusCode LArBadChannelHunter::stop ATLAS_NOT_THREAD_SAFE ()
 Install fatal handler with default options.

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

StatusCode LArBadChannelHunter::stop ATLAS_NOT_THREAD_SAFE ( void )
inline

Install fatal handler with default options.

This is meant to be easy to call from python via ctypes.

Install fatal handler with default options.

getLorentzAngle() Read LorentzAngle from HIST and write out into local DB

getBSErrors() Read BSErrors from Monitoring HIST and write out into local DB

getEfficiency() Read Efficiency from Monitoring HIST and write out into local DB

getRawOccupancy() Read RawOccupancy from Monitoring HIST and write out into local DB

getNoiseOccupancy() Read NoiseOccupancy from HIST and write out into local DB

getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats

beginning of the loop of channels

bad bit newly found

known bad bit

for low noisy cells

for high noisy cells

0.01 is used to scale "PER" to the same order of magnitude to "SIG"

smaller deviation: distorted

checking TmaxAmp, Not mixed with MaxAmp and Width

channel information output

Only dead or distorted, or short known BCs are considered below.

index of bc

Definition at line 117 of file LArBadChannelHunter.cxx.

117 {
118 ATH_CHECK( detStore()->retrieve(m_onlineId, "LArOnlineID") );
119 ATH_CHECK( detStore()->retrieve(m_caloId, "CaloCell_ID") );
120
121 const ILArPedestal* pedestal = nullptr;
122 ATH_CHECK( detStore()->retrieve(pedestal,m_pedKey) );
123
124 const LArCaliWaveContainer* caliwave = nullptr;
125 ATH_CHECK( detStore()->retrieve(caliwave,m_caliWaveKey) );
126
127 if (m_undoCorr) {
128 LArCaliWaveContainer* caliwavecomplete= const_cast<LArCaliWaveContainer*>(caliwave);
129 ATH_MSG_INFO ( "Undo caliwave corrections now." ) ;
130 ATH_CHECK( caliwavecomplete->undoCorrections() );
131 }
132
133 SG::ReadCondHandle<LArBadChannelCont> readHandle{m_BCKey};
134 const LArBadChannelCont *bcCont {*readHandle};
135 if(!bcCont) {
136 ATH_MSG_ERROR( "Do not have Bad chan container " << m_BCKey.key() );
137 return StatusCode::FAILURE;
138 }
140 const LArCalibLineMapping *clCont {*clHdl};
141 if(!clCont) {
142 ATH_MSG_ERROR( "Do not have calib line mapping !!!" );
143 return StatusCode::FAILURE;
144 }
145 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
146 const LArOnOffIdMapping* cabling=*cablingHdl;
147 if(!cabling) {
148 ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping" );
149 return StatusCode::FAILURE;
150 }
151
153 LArWaveHelper waveHelper;
154
155 //HWIdentifier lastfeb=HWIdentifier(0);
156 //Map of Averages per region (defined by getSymId)
157 std::map<unsigned,Average> averageMap;
158 //List of all individual values
159 std::vector<CellData> cellData;
160
161 std::vector<HWIdentifier>::const_iterator itOnId = m_onlineId->channel_begin();
162 std::vector<HWIdentifier>::const_iterator itOnIdEnd = m_onlineId->channel_end();
163
164 for(; itOnId!=itOnIdEnd;++itOnId){
165 const HWIdentifier chid = *itOnId;
166 if (!cabling->isOnlineConnected(chid)) continue;
167 //const HWIdentifier febid= m_onlineId->feb_Id(chid);
168 float ped=pedestal->pedestalRMS(chid,0);
169 const LArCaliWaveVec& cwv=caliwave->get(chid,0);
170 if (cwv.size()==0 || ped <=(1.0+LArElecCalib::ERRORCODE)) continue; //Want at least high-gain ped and wave
171 const float ampl=waveHelper.getMaxAmp(cwv[0]);
172 const float wid =waveHelper.getWidth(cwv[0])*cwv[0].getDt();
173 const float tmax=waveHelper.getMax(cwv[0])*cwv[0].getDt();
174
175 CellData thisCellData;
176 thisCellData.m_chid=chid;
177 thisCellData.m_ampl=ampl;
178 thisCellData.m_wid =wid;
179 thisCellData.m_tmax=tmax;
180
181 const unsigned regId=getSymId(chid, cabling);
182 Average& avreg=averageMap[regId];
183
184 for(unsigned igain=CaloGain::LARHIGHGAIN; igain<CaloGain::LARNGAIN; igain++) {
185 //get Pedestal RMS
186 float ped=pedestal->pedestalRMS(chid,igain);
187 if (ped >= (1.0+LArElecCalib::ERRORCODE)) {
188 avreg.m_avPedRMS[igain]+=ped;
189 avreg.m_avPedRMSSD[igain]+=(ped*ped);
190 avreg.m_nPed[igain]++;
191 avreg.m_vmedPedRMS[igain].push_back(ped);
192 thisCellData.m_pedRMS[igain]=ped;
193 }
194 }//end loop over gains
195
196 avreg.m_avAmpl[0]+=ampl;
197 avreg.m_avAmplSD[0]+=ampl*ampl;
198 avreg.m_nAmpls[0]++;
199 avreg.m_vmedAmpl[0].push_back(ampl);
200
201 avreg.m_avWid[0]+=wid;
202 avreg.m_avWidSD[0]+=wid*wid;
203 avreg.m_nWids[0]++;
204 avreg.m_vmedWid[0].push_back(wid);
205
206 avreg.m_avTmax[0]+=tmax;
207 avreg.m_avTmaxSD[0]+=tmax*tmax;
208 avreg.m_nTmaxs[0]++;
209 avreg.m_vmedTmax[0].push_back(tmax);
210
211 cellData.push_back(thisCellData);
212 }//End loop over cells
213
215 for(auto &[i, average]:averageMap) {
216 average.finish(m_recalcPer);
217 }
218
219
221 //Keep track to bad cells ...
223 typedef std::vector<std::pair<HWIdentifier,LArBadChannel> > BCV_t;
224
225 BCV_t badChanVec;
226 LArBadChanBitPacking packing;
227 PROB_t lownoiseProb[CaloGain::LARNGAIN], highnoiseProb[CaloGain::LARNGAIN];
231
235
236 typedef std::pair<unsigned,std::vector<size_t> > goodAndBad_t;
237 typedef std::map<HWIdentifier,goodAndBad_t> goodAndBadMap_t; //the key is the calibLineID
238
239 goodAndBadMap_t calibLineMap;
240
241 //Second loop: Find bad channels:
242 std::vector<CellData>::const_iterator itcells=cellData.begin();
243 std::vector<CellData>::const_iterator itcells_e=cellData.end();
244
245 for (;itcells!=itcells_e;++itcells) {
246 const CellData& thisCellData=*itcells;
247 const HWIdentifier chid = thisCellData.m_chid;
248
249 unsigned regId=getSymId(chid, cabling);
250 ATH_MSG_VERBOSE ( "Checking " << channelDescription(chid, cabling) ) ;
251 std::map<unsigned,Average>::const_iterator febit=averageMap.find(regId);
252 if (febit==averageMap.end()) continue;
253 const Average& avreg=febit->second;
254
255 LArBadChannel problem(0);
256 LArBadChannel bc = bcCont->status(chid);
257
258 for(unsigned igain=CaloGain::LARHIGHGAIN; igain<CaloGain::LARNGAIN; igain++) {
259 if (avreg.m_nPed[igain]>2) {//Check if have average ped-rms for this cell & gain
260 const float rms=thisCellData.m_pedRMS[igain];
261 float lowCut_rms=0.;
262 float higCut_rms=0.;
263 if ( m_cutType=="SIG" ) {
264 lowCut_rms=m_lowNoiseTh[igain]*avreg.m_avPedRMSSD[igain];
265 higCut_rms=m_highNoiseTh[igain]*avreg.m_avPedRMSSD[igain];
266 }
267 else if ( m_cutType=="PER") {
268 lowCut_rms=m_lowNoiseTh[igain]*avreg.m_avPedRMS[igain]*0.01;
269 higCut_rms=m_highNoiseTh[igain]*avreg.m_avPedRMS[igain]*0.01;
270 }
271
272 if (rms==-1)
273 ATH_MSG_ERROR ( "No Pedestal found for " << channelDescription(chid,cabling, igain) ) ;
274 else {
275 ATH_MSG_VERBOSE ( "PedRMS, gain: " << igain << ":" << rms << " Average: "
276 << avreg.m_avPedRMS[igain] << " Median: " << avreg.m_medPedRMS ) ;
278 if ( (rms-avreg.m_avPedRMS[igain]) > higCut_rms ) {
279 packing.setBit(highnoiseProb[igain],problem);
280 }
281 else if ( (rms-avreg.m_avPedRMS[igain]) > lowCut_rms ) {
282 packing.setBit(lownoiseProb[igain],problem);
283 }
285 if (fabs(rms-avreg.m_avPedRMS[igain]) > lowCut_rms || (bc.lowNoiseHG()||bc.highNoiseHG()) ) {
286 std::string my_status;
287 if (fabs(rms-avreg.m_avPedRMS[igain]) < lowCut_rms && (bc.lowNoiseHG()||bc.highNoiseHG()))
288 my_status="BCN ";
289 else
290 my_status=(bc.lowNoiseHG()||bc.highNoiseHG()) ? "BC " : "NEW ";
291
292 ATH_MSG_INFO( my_status << channelDescription(chid,cabling,igain)
293 << " RMS: " << rms << " ( " << avreg.m_avPedRMS[igain] << " , "
294 << float(int(10000*(rms-avreg.m_avPedRMS[igain])/avreg.m_avPedRMS[igain]))/100 <<" %) " << ", #Sig: "
295 << float(int(100*(rms-avreg.m_avPedRMS[igain])/avreg.m_avPedRMSSD[igain]))/100
296 << " ( " << avreg.m_avPedRMSSD[igain] << " ) " ) ;
297 }// end bad channels information output
298 } //end if(rms==-1)
299 }//end if have ped rms for this cell & gain
300 }//end loop over gains
301
303 if (avreg.m_nAmpls[0]>2 && avreg.m_nWids[0]>2 && avreg.m_nTmaxs[0]>2) {//Check if we have average ampls for this cell & gain
304 const float ampl=thisCellData.m_ampl;
305 const float wid=thisCellData.m_wid;
306 const float tmax=thisCellData.m_tmax;
307
308 float lowCut_amp=0.;
309 float higCut_amp=0.;
310 float lowCut_wid=0.;
311 float higCut_wid=0.;
312 float Cut_tmax=0.;
313
314 if ( m_cutType=="SIG" ) {
315 lowCut_amp=m_distampTh[0]*avreg.m_avAmplSD[0];
316 higCut_amp=m_amplTh[0]*avreg.m_avAmplSD[0];
317 lowCut_wid=m_distwidTh[0]*avreg.m_avWidSD[0];
318 higCut_wid=m_widTh[0]*avreg.m_avWidSD[0];
319 Cut_tmax=m_tmaxampTh[0]*avreg.m_avTmaxSD[0];
320 }
321 else if ( m_cutType=="PER") {
322 lowCut_amp=m_distampTh[0]*avreg.m_avAmpl[0]*0.01;
323 higCut_amp=m_amplTh[0]*avreg.m_avAmpl[0]*0.01;
324 lowCut_wid=m_distwidTh[0]*avreg.m_avWid[0]*0.01;
325 higCut_wid=m_widTh[0]*avreg.m_avWid[0]*0.01;
326 Cut_tmax=m_tmaxampTh[0]*avreg.m_avTmax[0]*0.01;
327 } // end if loop
328
329
330 if (ampl==-1 || wid==-1) {
331 ATH_MSG_INFO ( "No Amplitude or Width found for " << channelDescription(chid,cabling,0) ) ;
333 }
334 else {
335 ATH_MSG_VERBOSE ( "Ampl gain: "<< 0<< ":"<< ampl<< " Average: " << avreg.m_avAmpl[0]) ;
337 if (fabs(ampl-avreg.m_avAmpl[0])>higCut_amp || fabs(wid-avreg.m_avWid[0])>higCut_wid) {
339 }
341 else if (fabs(ampl-avreg.m_avAmpl[0])>lowCut_amp || fabs(wid-avreg.m_avWid[0])>lowCut_wid){
343 }
345 else if (fabs(tmax-avreg.m_avTmax[0])>Cut_tmax) {
347// std::string my_status=(bc.good()) ? "NEW " : "BC ";
348// log << MSG::INFO << my_status << channelDescription(chid,cabling,0) << " Tmax: " << tmax << " ( " << avreg.m_avTmax[0] << " , "
349// << float(int(10000*(tmax-avreg.m_avTmax[0])/avreg.m_avTmax[0]))/100 << " %) "
350// << " #Sig:" << float(int(100*(tmax-avreg.m_avTmax[0])/avreg.m_avTmaxSD[0]))/100
351// << " ( " << avreg.m_avTmaxSD[0] << " ) " << endmsg;
352 }
354// if (fabs(ampl-avreg.m_avAmpl[0])>lowCut_amp || fabs(wid-avreg.m_avWid[0])>lowCut_wid) {
356 if ( problem.deadReadout()||problem.distorted() || bc.deadReadout()||bc.deadCalib()||bc.deadPhys()||bc.distorted()||bc.shortProblem() ){
357 std::string my_status;
358 if ( !(problem.deadReadout()||problem.distorted())
359 &&(bc.deadReadout()||bc.deadCalib()||bc.deadPhys()||bc.distorted()||bc.shortProblem()) )
360 my_status="BCN ";
361 else
362 my_status=(bc.deadReadout()||bc.deadCalib()||bc.deadPhys()||bc.distorted()||bc.shortProblem()) ? "BC " : "NEW ";
363
364 ATH_MSG_INFO ( my_status << channelDescription(chid,cabling,0)
365 << " Amp: " << ampl << " ( " << avreg.m_avAmpl[0] << " , "
366 << float(int(10000*(ampl-avreg.m_avAmpl[0])/avreg.m_avAmpl[0]))/100 << " %) " << " #Sig: "
367 << float(int(100*(ampl-avreg.m_avAmpl[0])/avreg.m_avAmplSD[0]))/100 << " ( " << avreg.m_avAmplSD[0] <<" ) "
368 << " FWHM: " << wid << " ( " << avreg.m_avWid[0] << " , "
369 << float(int(10000*(wid-avreg.m_avWid[0])/avreg.m_avWid[0]))/100 << " %) " << " #Sig: "
370 << float(int(100*(wid-avreg.m_avWid[0])/avreg.m_avWidSD[0]))/100
371 << " ( " << avreg.m_avWidSD[0] << " ) "
372 << " Tmax: " << tmax << " ( " << avreg.m_avTmax[0] << " , "
373 << float(int(10000*(tmax-avreg.m_avTmax[0])/avreg.m_avTmax[0]))/100 << " %) " << " #Sig:"
374 << float(int(100*(tmax-avreg.m_avTmax[0])/avreg.m_avTmaxSD[0]))/100
375 ) ;
376 }
377 }
378 }//end if have amplitude for this cell
379
380
381 const std::vector<HWIdentifier>& cLids=clCont->calibSlotLine(chid);
382 for (const HWIdentifier& hwid : cLids) {
383 goodAndBad_t& gb=calibLineMap[hwid];
384 if (problem.deadReadout()||problem.distorted())
385 gb.second.push_back(badChanVec.size());
386 else
387 ++gb.first;
388 }
389 if (!problem.good()) badChanVec.push_back(std::make_pair(chid,problem));
390
391 }//end loop over channels
392
393
394 for(const auto & kv: calibLineMap) {
395 const goodAndBad_t& gb=kv.second;
396 for (unsigned i=0;i<gb.second.size();i++) {
397 if (gb.first==0) {
398 ATH_MSG_INFO ( "All channels belonging to calibLine " << channelDescription(badChanVec[gb.second[i]].first, cabling)
399 << " don't respond to pulses. Assume bad calib line." ) ;
400 packing.setBit(LArBadChannel::LArBadChannelEnum::deadReadoutBit,badChanVec[gb.second[i]].second,false);
401 packing.setBit(LArBadChannel::LArBadChannelEnum::distortedBit,badChanVec[gb.second[i]].second,false);
402 packing.setBit(LArBadChannel::LArBadChannelEnum::deadCalibBit,badChanVec[gb.second[i]].second,true);
403 }//end loop over all channels belonging to this calibline
404 }
405 }//end loop over calibline vector
406
407 if (m_outFileName.size()) {
408 std::ofstream outfile(m_outFileName.c_str());
409 if (!outfile.is_open()) {
410 ATH_MSG_ERROR ( "Failed to open output file " << m_outFileName << ". No output will be written." ) ;
411 }
412 else {
413 BCV_t::const_iterator bcvit=badChanVec.begin();
414 BCV_t::const_iterator bcvit_e=badChanVec.end();
415 for(;bcvit!=bcvit_e;++bcvit) {
416 const HWIdentifier chid=bcvit->first;
417 const LArBadChannel bc=bcvit->second;
418 const HWIdentifier cLid=clCont->calibSlotLine(chid)[0];
419 const LArBadChannel bc2=bcCont->status(chid);
420 std::string my_ps=(bc2.good())? "NEW " : "BC ";
421 if (!bc2.good()&&m_outOnlyNew) continue; // just new
422 outfile << m_onlineId->barrel_ec(chid) << " "
423 << m_onlineId->pos_neg(chid) << " "
424 << m_onlineId->feedthrough(chid) << " "
425 << m_onlineId->slot(chid) << " "
426 << m_onlineId->channel(chid) << " "
427 << m_onlineId->channel(cLid) << " "
428 << packing.stringStatus(bc) << " "
429 << my_ps << std::endl;
430// << packing.stringStatus(bc) << std::endl;
431 }
432 outfile.close();
433 } //end if out file open
434 } // end if have out file name
435 return StatusCode::SUCCESS;
436}
#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)
LArBadXCont< LArBadChannel > LArBadChannelCont
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
bool shortProblem() const
bool lowNoiseHG() const
bool deadReadout() const
bool highNoiseHG() const
bool deadCalib() const
bool deadPhys() const
bool good() const
Returns true if no problems at all (all bits at zero)
bool distorted() const
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
Liquid Argon Cumulative Wave Container.
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
StatusCode undoCorrections()
undo corrections that have been already applied
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
double getMaxAmp(const LArWave &theWave) const
double getWidth(const LArWave &theWave) const
unsigned int getMax(const LArWave &theWave) const
return index of maximum sample
void setBit(typename T::ProblemType pb, LArBadChannel::BitWord &word, bool value=true) const
std::string stringStatus(const LArBadChannel &bc) const
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18
retrieve(aClass, aKey=None)
Definition PyKernel.py:110