118 ATH_CHECK( detStore()->retrieve(m_onlineId,
"LArOnlineID") );
119 ATH_CHECK( detStore()->retrieve(m_caloId,
"CaloCell_ID") );
122 ATH_CHECK( detStore()->retrieve(pedestal,m_pedKey) );
125 ATH_CHECK( detStore()->retrieve(caliwave,m_caliWaveKey) );
136 ATH_MSG_ERROR(
"Do not have Bad chan container " << m_BCKey.key() );
137 return StatusCode::FAILURE;
143 return StatusCode::FAILURE;
148 ATH_MSG_ERROR(
"Do not have cabling object LArOnOffIdMapping" );
149 return StatusCode::FAILURE;
157 std::map<unsigned,Average> averageMap;
159 std::vector<CellData> cellData;
161 std::vector<HWIdentifier>::const_iterator itOnId = m_onlineId->channel_begin();
162 std::vector<HWIdentifier>::const_iterator itOnIdEnd = m_onlineId->channel_end();
164 for(; itOnId!=itOnIdEnd;++itOnId){
166 if (!cabling->isOnlineConnected(chid))
continue;
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();
175 CellData thisCellData;
176 thisCellData.m_chid=chid;
177 thisCellData.m_ampl=ampl;
178 thisCellData.m_wid =wid;
179 thisCellData.m_tmax=tmax;
181 const unsigned regId=getSymId(chid, cabling);
182 Average& avreg=averageMap[regId];
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;
196 avreg.m_avAmpl[0]+=ampl;
197 avreg.m_avAmplSD[0]+=ampl*ampl;
199 avreg.m_vmedAmpl[0].push_back(ampl);
201 avreg.m_avWid[0]+=wid;
202 avreg.m_avWidSD[0]+=wid*wid;
204 avreg.m_vmedWid[0].push_back(wid);
206 avreg.m_avTmax[0]+=tmax;
207 avreg.m_avTmaxSD[0]+=tmax*tmax;
209 avreg.m_vmedTmax[0].push_back(tmax);
211 cellData.push_back(thisCellData);
215 for(
auto &[i, average]:averageMap) {
216 average.finish(m_recalcPer);
223 typedef std::vector<std::pair<HWIdentifier,LArBadChannel> > BCV_t;
236 typedef std::pair<unsigned,std::vector<size_t> > goodAndBad_t;
237 typedef std::map<HWIdentifier,goodAndBad_t> goodAndBadMap_t;
239 goodAndBadMap_t calibLineMap;
242 std::vector<CellData>::const_iterator itcells=cellData.begin();
243 std::vector<CellData>::const_iterator itcells_e=cellData.end();
245 for (;itcells!=itcells_e;++itcells) {
246 const CellData& thisCellData=*itcells;
249 unsigned regId=getSymId(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;
259 if (avreg.m_nPed[igain]>2) {
260 const float rms=thisCellData.m_pedRMS[igain];
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];
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;
273 ATH_MSG_ERROR (
"No Pedestal found for " << channelDescription(chid,cabling, igain) ) ;
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);
281 else if ( (rms-avreg.m_avPedRMS[igain]) > lowCut_rms ) {
282 packing.
setBit(lownoiseProb[igain],problem);
286 std::string my_status;
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] <<
" ) " ) ;
303 if (avreg.m_nAmpls[0]>2 && avreg.m_nWids[0]>2 && avreg.m_nTmaxs[0]>2) {
304 const float ampl=thisCellData.m_ampl;
305 const float wid=thisCellData.m_wid;
306 const float tmax=thisCellData.m_tmax;
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];
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;
330 if (ampl==-1 || wid==-1) {
331 ATH_MSG_INFO (
"No Amplitude or Width found for " << channelDescription(chid,cabling,0) ) ;
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) {
341 else if (fabs(ampl-avreg.m_avAmpl[0])>lowCut_amp || fabs(wid-avreg.m_avWid[0])>lowCut_wid){
345 else if (fabs(tmax-avreg.m_avTmax[0])>Cut_tmax) {
357 std::string my_status;
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
381 const std::vector<HWIdentifier>& cLids=clCont->
calibSlotLine(chid);
383 goodAndBad_t& gb=calibLineMap[hwid];
385 gb.second.push_back(badChanVec.size());
389 if (!problem.
good()) badChanVec.push_back(std::make_pair(chid,problem));
394 for(
const auto & kv: calibLineMap) {
395 const goodAndBad_t& gb=kv.second;
396 for (
unsigned i=0;i<gb.second.size();i++) {
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." ) ;
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." ) ;
413 BCV_t::const_iterator bcvit=badChanVec.begin();
414 BCV_t::const_iterator bcvit_e=badChanVec.end();
415 for(;bcvit!=bcvit_e;++bcvit) {
420 std::string my_ps=(bc2.
good())?
"NEW " :
"BC ";
421 if (!bc2.
good()&&m_outOnlyNew)
continue;
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) <<
" "
429 << my_ps << std::endl;
435 return StatusCode::SUCCESS;
559 if (my_recalcPer>=0.){
562 float re_avPed=0.;
float re_avPedSD=0.;
int re_nPed=0;
563 std::vector<float>::iterator p_loop =
m_vmedPedRMS[igain].begin();
564 std::vector<float>::iterator p_loop_e=
m_vmedPedRMS[igain].end();
565 for (;p_loop!=p_loop_e; ++p_loop){
568 re_avPedSD+=*p_loop*(*p_loop);
574 re_avPedSD=(re_avPedSD- re_nPed*re_avPed*re_avPed)/(re_nPed);
576 re_avPedSD=sqrt(re_avPedSD);
577 std::cout <<
" PedRMS mean && RMS are recalc: Orig (recalc) are: "<<
m_avPedRMS[igain]<<
" ( "<< re_avPed
578 <<
" ) and "<<
m_avPedRMSSD[igain]<<
" ( "<<re_avPedSD<<
" )"<<std::endl;
583 float re_avAmpl=0.;
float re_avAmplSD=0.;
int re_nAmpl=0;
584 std::vector<float>::iterator re_loop =
m_vmedAmpl[igain].begin();
585 std::vector<float>::iterator re_loop_e=
m_vmedAmpl[igain].end();
586 for (;re_loop!=re_loop_e; ++re_loop){
589 re_avAmplSD+=*re_loop*(*re_loop);
595 re_avAmplSD=(re_avAmplSD- re_nAmpl*re_avAmpl*re_avAmpl)/(re_nAmpl);
597 re_avAmplSD=sqrt(re_avAmplSD);
598 std::cout <<
" MaxAmp mean && RMS are recalc: Orig (recalc) are: "<<
m_avAmpl[igain]<<
" ( "<< re_avAmpl
599 <<
" ) and "<<
m_avAmplSD[igain]<<
" ( "<<re_avAmplSD<<
" )"<<std::endl;
604 float re_avWid=0.;
float re_avWidSD=0.;
int re_nWid=0;
605 std::vector<float>::iterator w_loop =
m_vmedWid[igain].begin();
606 std::vector<float>::iterator w_loop_e=
m_vmedWid[igain].end();
607 for (;w_loop!=w_loop_e; ++w_loop){
610 re_avWidSD+=*w_loop*(*w_loop);
616 re_avWidSD=(re_avWidSD- re_nWid*re_avWid*re_avWid)/(re_nWid);
618 re_avWidSD=sqrt(re_avWidSD);
619 std::cout <<
" FWHM mean && RMS are recalc: Orig (recalc) are: "<<
m_avWid[igain]<<
" ( "<< re_avWid
620 <<
" ) and "<<
m_avWidSD[igain]<<
" ( "<<re_avWidSD<<
" )"<<std::endl;
625 float re_avTmax=0.;
float re_avTmaxSD=0.;
int re_nTmax=0;
626 std::vector<float>::iterator t_loop =
m_vmedTmax[igain].begin();
627 std::vector<float>::iterator t_loop_e=
m_vmedTmax[igain].end();
628 for (;t_loop!=t_loop_e; ++t_loop){
631 re_avTmaxSD+=*t_loop*(*t_loop);
637 re_avTmaxSD=(re_avTmaxSD- re_nTmax*re_avTmax*re_avTmax)/(re_nTmax);
639 re_avTmaxSD=sqrt(re_avTmaxSD);
640 std::cout <<
"TmaxAmp mean && RMS are recalc: Orig (recalc) are: "<<
m_avTmax[igain]<<
" ( "<< re_avTmax
641 <<
" ) and "<<
m_avTmaxSD[igain]<<
" ( "<<re_avTmaxSD<<
" )"<<std::endl;