140{
142
143 const LArOnlineID* onlineHelper;
144 const LArEM_ID* emId;
145
146 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{
m_cablingKey};
147 const LArOnOffIdMapping*
cabling{*cablingHdl};
148 if(!cabling){
150 return StatusCode::FAILURE;
151 }
152 SG::ReadCondHandle<LArCalibLineMapping> clHdl{
m_CLKey};
153 const LArCalibLineMapping *clCont {*clHdl};
154 if(!clCont){
156 return StatusCode::FAILURE;
157 }
159
160 const CaloCell_ID* idHelper = nullptr;
163
164 msg() << MSG::INFO <<
"Check on ADC saturation: " ;
169 } else {
171 }
172 msg() << MSG::INFO <<
"Check on mimimum DAC value: " ;
175 } else {
177 }
180 } else {
181 ATH_MSG_INFO (
"Master Waveforms will NOT be normalized" );
182 }
184 ATH_MSG_INFO (
"Master Waveforms will be shifted to the origin" );
185 } else {
186 ATH_MSG_INFO (
"Master Waveforms will NOT be shifted to the origin" );
187 }
189 ATH_MSG_INFO (
"Build MWs even with only one usable DAC" );
190 } else {
191 ATH_MSG_INFO (
"Don't build MWs if only one usable DAC" );
192 }
194 ATH_MSG_INFO (
"For linearity check, normalize to peak " );
195 } else {
196 ATH_MSG_INFO (
"For linearity check, normalize to DAC " );
197 }
199
200
201 const LArCaliWaveContainer* caliWaveContainer = nullptr;
203
204 if ( caliWaveContainer == nullptr ) {
206 return StatusCode::FAILURE;
207 }
208
210
211
212 auto mwContainer = std::make_unique<LArCaliWaveContainer>();
213
216
217
218 std::vector< std::map<HWIdentifier, std::vector<int> > > badDACs ;
220
221 unsigned nMasterWaves = 0 ;
222
224
225 ATH_MSG_DEBUG (
"Evaluating master wavefroms for gain " << gain_it );
226
227
228 unsigned gainFactor = (
unsigned)(
pow(10,2-gain_it)) ;
229
230
231 std::vector<int> minDAC , maxDAC ;
240
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 );
245
246 int DACMin = 0 ;
247 int DACMax = 65000 ;
248
251
252 if ( cell_it == cell_it_e ) {
254 continue;
255 } else {
257 }
258
259 for ( ; cell_it!=cell_it_e ; ++cell_it ) {
260
263 if ( wave_it == wave_it_e ) {
265 continue;
266 }
267
269
270 HWIdentifier chID = cell_it.
channelId() ;
271 double dt = vCaliWaves[0].getDt() ;
272 unsigned nDACs = vCaliWaves.size() ;
273
275 << " in gain " << gain_it );
276 msg() << MSG::DEBUG <<
"DAC list: " ;
277 for (
unsigned i=0 ;
i<nDACs ;
i++ )
278 msg() << vCaliWaves[
i].getDAC() <<
" " ;
280
282 long region = -1;
283
284 try {
285 Identifier
id =
cabling->cnvToIdentifier(chID);
287 region = emId->
region(
id) ;
288 } catch ( LArID_Exception & except ) {
291 << ". Skipping." );
292 continue ;
293 }
294
295 if ( region==0 && layer>=0 && layer<=3 ) {
296 DACMin = minDAC[
layer] ;
297 DACMax = maxDAC[
layer] ;
298 }
299
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) ;
308
309
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])) ;
313
316 << "DAC below threshold... skip!" );
318 continue ;
319 }
320
324 << " absolute ADC saturation... skip!" );
326 continue ;
328
330 << " relative ADC saturation... skip!" );
332 continue ;
333 }
334 }
335
336 if ( fabs( thisPeak[i]/thisDAC[i] ) < gainFactor*0.0001 ) {
339 continue ;
340 }
342 }
343
344
345 int refIndex = -1 ;
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 ;
356 }
357 if ( thisOverallDiff < minOverallDiff ) {
359 minOverallDiff = thisOverallDiff ;
360 }
361 }
362
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 ;
368 int tbin ;
373 << " non-linearity detected, rel.resid= " << relDiff
374 << " at t= " << tbin*vCaliWaves[i].getDt() << " tbin= " << tbin
375 << " ... skip!" );
377 } else if ( relDiff < 0 ) {
379 << " could not check linearity... skip!" );
381 } else {
383 << " linear within " << relDiff );
384 }
385 }
386 } else {
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 ;
391 }
392 }
393
394 for (
unsigned i=0 ;
i<nDACs ;
i++ ) {
395 if ( usable[i] ) {
396 vDACs.push_back( (double)( thisDAC[i] ) ) ;
397 const LArWave* wave = &vCaliWaves[
i];
398 vWaves.push_back(wave);
399 } else {
400 if ( (unsigned int)thisDAC[i] > 1000/gainFactor )
401 ( badDACs[(
unsigned)gain_it][chID] ).push_back(thisDAC[i]) ;
402 }
403 }
404 unsigned nGoodDACs = vDACs.size() ;
405 ATH_MSG_DEBUG ( nGoodDACs <<
" DAC's selected for MW evaluation, channel 0x"
408
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 );
415 continue ;
416 }
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 );
421 fitWave.resize(2) ;
422 fitWave[1] = (*vWaves[0])*(1./vDACs[0]) ;
425 } else {
426 ATH_MSG_ERROR (
"No DACs available, cannot build MW! Channel 0x"
427 << MSG::hex << chID.
get_compact() << MSG::dec <<
", gain = " << gain_it );
428 continue ;
429 }
430
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 );
434
437 fitWave[1] =
m_waveHelper->translate(fitWave[1],-tStart,0) ;
438 fitWave[0] =
m_waveHelper->translate(fitWave[0],-tStart,0) ;
439 }
440
442 double peak = fitWave[1].getSample(
m_waveHelper->getMax(fitWave[1]) ) ;
443 if ( peak != 0 ) {
444 fitWave[1] = fitWave[1] * (1/peak) ;
445 } else {
447 }
448 }
449
451 LArCaliWave masterWave( fitWave[1].getWave(),
453 LArCaliWave dac0Wave ( fitWave[0].getWave(),
455 dacWaves.push_back( masterWave );
456 dacWaves.push_back( dac0Wave );
457 nMasterWaves ++ ;
458
459 ATH_MSG_DEBUG (
"MW and DAC0 evaluated and written in container, channel 0x"
461
462 }
463
464 ATH_MSG_INFO ( nMasterWaves <<
" master wfs generated for gain " << gain_it );
465
466 }
467
468
471
473
475
476 std::map<HWIdentifier, std::vector<int> > & badDACsGain = badDACs[gain_it] ;
477
478 for (const auto& p : badDACsGain) {
479 const HWIdentifier chId =
p.first ;
480 const std::vector<int> & DACs =
p.second ;
481
483 try {
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();
491 int calibLine = 0;
492 if ( !calibLineV.empty() )
493 calibLine = onlineHelper->
channel(*calibLineIt);
495 int slot = onlineHelper->
slot(chId) ;
497 const char gainName[3][3] = { "HG" , "MG" , "LG" } ;
498 char formOut[200] ;
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 );
504 }
505 catch( LArID_Exception & except ) {
506 ATH_MSG_ERROR (
"LArID_Exception: channel 0x" << MSG::hex << chId << MSG::dec <<
" not registered " );
507 }
508
509 }
510 }
511 }
512
513 return StatusCode::SUCCESS;
514}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
LArCaliWaveContainer::LArCaliWaves::const_iterator CaliWaveIt
LArCaliWaveContainer::ConstConditionsMapIterator CaliCellIt
std::string ChanDacGain(HWIdentifier ch, int DAC, int gain)
constexpr int pow(int base, int exp) noexcept
const ServiceHandle< StoreGateSvc > & detStore() const
const LArEM_ID * em_idHelper() const
access to EM idHelper
value_type get_compact() const
Get the compact id.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
LArCaliWaveVec LArCaliWaves
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
HWIdentifier channelId() const
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
int region(const Identifier id) const
return region according to :
int eta(const Identifier id) const
return eta according to :
int phi(const Identifier id) const
return phi according to :
int sampling(const Identifier id) const
return sampling according to :
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
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...
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
retrieve(aClass, aKey=None)