150 return StatusCode::FAILURE;
156 return StatusCode::FAILURE;
164 msg() << MSG::INFO <<
"Check on ADC saturation: " ;
172 msg() << MSG::INFO <<
"Check on mimimum DAC value: " ;
181 ATH_MSG_INFO (
"Master Waveforms will NOT be normalized" );
184 ATH_MSG_INFO (
"Master Waveforms will be shifted to the origin" );
186 ATH_MSG_INFO (
"Master Waveforms will NOT be shifted to the origin" );
189 ATH_MSG_INFO (
"Build MWs even with only one usable DAC" );
191 ATH_MSG_INFO (
"Don't build MWs if only one usable DAC" );
194 ATH_MSG_INFO (
"For linearity check, normalize to peak " );
196 ATH_MSG_INFO (
"For linearity check, normalize to DAC " );
204 if ( caliWaveContainer ==
nullptr ) {
206 return StatusCode::FAILURE;
212 auto mwContainer = std::make_unique<LArCaliWaveContainer>();
218 std::vector< std::map<HWIdentifier, std::vector<int> > > badDACs ;
221 unsigned nMasterWaves = 0 ;
225 ATH_MSG_DEBUG (
"Evaluating master wavefroms for gain " << gain_it );
228 unsigned gainFactor = (unsigned)(
pow(10,2-gain_it)) ;
231 std::vector<int> minDAC , maxDAC ;
241 ATH_MSG_INFO (
"Minimum DAC allowed for layers 0,1,2,3 and gain " << gain_it );
243 ATH_MSG_INFO (
"Maximum DAC allowed for layers 0,1,2,3 and gain " << gain_it );
252 if ( cell_it == cell_it_e ) {
259 for ( ; cell_it!=cell_it_e ; ++cell_it ) {
263 if ( wave_it == wave_it_e ) {
271 double dt = vCaliWaves[0].getDt() ;
272 unsigned nDACs = vCaliWaves.size() ;
275 <<
" in gain " << gain_it );
276 msg() << MSG::DEBUG <<
"DAC list: " ;
277 for (
unsigned i=0 ; i<nDACs ; i++ )
278 msg() << vCaliWaves[i].getDAC() <<
" " ;
285 Identifier id = cabling->cnvToIdentifier(chID);
287 region = emId->
region(
id) ;
295 if ( region==0 && layer>=0 && layer<=3 ) {
296 DACMin = minDAC[layer] ;
297 DACMax = maxDAC[layer] ;
300 std::vector<double> vDACs ;
301 std::vector<const LArWave*> vWaves ;
302 std::vector<bool> usable ;
303 std::vector<int> thisDAC ;
304 std::vector<double> thisPeak ;
305 usable.resize(nDACs) ;
306 thisDAC.resize(nDACs) ;
307 thisPeak.resize(nDACs) ;
310 for (
unsigned i=0 ; i<nDACs ; i++ ) {
311 thisDAC[i] = vCaliWaves[i].getDAC() ;
312 thisPeak[i] = vCaliWaves[i].getSample(
m_waveHelper->getMax(vCaliWaves[i])) ;
316 <<
"DAC below threshold... skip!" );
324 <<
" absolute ADC saturation... skip!" );
330 <<
" relative ADC saturation... skip!" );
336 if ( fabs( thisPeak[i]/thisDAC[i] ) < gainFactor*0.0001 ) {
346 double minOverallDiff = 9.e+99 ;
347 for (
unsigned i=0 ; i<nDACs ; i++ ) {
348 if ( ! usable[i] ) continue ;
349 if ( thisDAC[i]<DACMin || thisDAC[i]>DACMax ) continue ;
350 double thisOverallDiff = 0 ;
351 for (
unsigned k=0 ; k<nDACs ; k++ ) {
352 if ( ! usable[k] ) continue ;
353 if ( k == i ) continue ;
355 if ( theDiff>0 ) thisOverallDiff += theDiff ;
357 if ( thisOverallDiff < minOverallDiff ) {
359 minOverallDiff = thisOverallDiff ;
363 if ( refIndex >=0 ) {
364 int refDAC = thisDAC[refIndex] ;
365 ATH_MSG_DEBUG (
"Check non-linearity against DAC " << refDAC );
366 for (
unsigned i=0 ; i<nDACs ; i++ ) {
367 if ( ! usable[i] ) continue ;
373 <<
" non-linearity detected, rel.resid= " << relDiff
374 <<
" at t= " << tbin*vCaliWaves[i].getDt() <<
" tbin= " << tbin
377 }
else if ( relDiff < 0 ) {
379 <<
" could not check linearity... skip!" );
383 <<
" linear within " << relDiff );
387 ATH_MSG_DEBUG (
"Could not find reference DAC, just reject all waves not in DAC ["
388 << DACMin <<
"," << DACMax <<
"]" );
389 for (
unsigned i=0 ; i<nDACs ; i++ ) {
390 if ( thisDAC[i]<DACMin || thisDAC[i]>DACMax ) usable[i] = false ;
394 for (
unsigned i=0 ; i<nDACs ; i++ ) {
396 vDACs.push_back( (
double)( thisDAC[i] ) ) ;
397 const LArWave* wave = &vCaliWaves[i];
398 vWaves.push_back(wave);
400 if ( (
unsigned int)thisDAC[i] > 1000/gainFactor )
401 ( badDACs[(unsigned)gain_it][chID] ).push_back(thisDAC[i]) ;
404 unsigned nGoodDACs = vDACs.size() ;
405 ATH_MSG_DEBUG ( nGoodDACs <<
" DAC's selected for MW evaluation, channel 0x"
409 std::vector<LArWave> fitWave ;
410 if ( nGoodDACs >= 2 ) {
411 fitWave =
m_waveHelper->linearMasterWave(vWaves,vDACs) ;
412 if ( fitWave.empty() ) {
413 ATH_MSG_ERROR (
"Master waveform linear fit failed! Channel 0x"
414 << MSG::hex << chID.
get_compact() << MSG::dec <<
", gain = " << gain_it );
417 }
else if (
m_buildMWoneDAC && nGoodDACs==1 && vDACs[0]>=DACMin && vDACs[0]<=DACMax ) {
419 <<
" just divide caliwave by DAC! Channel 0x"
420 << MSG::hex << chID.
get_compact() << MSG::dec <<
", gain = " << gain_it );
422 fitWave[1] = (*vWaves[0])*(1./vDACs[0]) ;
426 ATH_MSG_ERROR (
"No DACs available, cannot build MW! Channel 0x"
427 << MSG::hex << chID.
get_compact() << MSG::dec <<
", gain = " << gain_it );
431 ATH_MSG_DEBUG (
"master waveform evaluation succeeded for channel 0x"
432 << MSG::hex << chID.
get_compact() << MSG::dec <<
", gain = " << gain_it );
433 ATH_MSG_DEBUG (
" ... with " << nGoodDACs <<
" DAC values: " << vDACs );
437 fitWave[1] =
m_waveHelper->translate(fitWave[1],-tStart,0) ;
438 fitWave[0] =
m_waveHelper->translate(fitWave[0],-tStart,0) ;
442 double peak = fitWave[1].getSample(
m_waveHelper->getMax(fitWave[1]) ) ;
444 fitWave[1] = fitWave[1] * (1/peak) ;
455 dacWaves.push_back( masterWave );
456 dacWaves.push_back( dac0Wave );
459 ATH_MSG_DEBUG (
"MW and DAC0 evaluated and written in container, channel 0x"
464 ATH_MSG_INFO ( nMasterWaves <<
" master wfs generated for gain " << gain_it );
476 std::map<HWIdentifier, std::vector<int> > & badDACsGain = badDACs[gain_it] ;
478 for (
const auto& p : badDACsGain) {
480 const std::vector<int> & DACs = p.second ;
484 Identifier id = cabling->cnvToIdentifier(chId);
485 int region = emId->
region(
id);
489 const std::vector<HWIdentifier>& calibLineV=clCont->
calibSlotLine(chId);
490 std::vector<HWIdentifier>::const_iterator calibLineIt=calibLineV.begin();
492 if ( !calibLineV.empty() )
493 calibLine = onlineHelper->
channel(*calibLineIt);
494 int channel = onlineHelper->
channel(chId) ;
495 int slot = onlineHelper->
slot(chId) ;
497 const char gainName[3][3] = {
"HG" ,
"MG" ,
"LG" } ;
500 sprintf( formOut,
"%2s 0x%8x [%1d;%1d;%3d;%2d] [%2d;%3d;%3d;%3d]",
501 gainName[gain_it], ich, region, layer,
eta,
phi,
502 FT, slot, channel, calibLine ) ;
503 ATH_MSG_INFO (
"*** " << std::string(formOut) <<
" : " << DACs );
506 ATH_MSG_ERROR (
"LArID_Exception: channel 0x" << MSG::hex << chId << MSG::dec <<
" not registered " );
513 return StatusCode::SUCCESS;