Execute method.
181{
182
183
184 int noEnergy = 0;
185 int BadTiming = 0;
186 int noTime = 0;
187 int noShape = 0;
188 int noShapeDer = 0;
189 int highE = 0;
190 int saturation = 0;
191
192 const ILArHVScaleCorr *oflHVCorr=nullptr;
195 oflHVCorr = *oflHVCorrHdl;
196 if(!oflHVCorr) {
198 return StatusCode::FAILURE;
199 }
200 }
201 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{
m_cablingKey, ctx};
202 const LArOnOffIdMapping*
cabling{*cablingHdl};
203 if(!cabling) {
205 return StatusCode::FAILURE;
206 }
207
208
209 const LArDigitContainer* digitContainer=NULL;
210
211 float PhaseTime=0;
212 float globalTimeOffset=0;
213
214 const ILArFEBTimeOffset* larFebTimeOffset=NULL;
215 const ILArShape* larShape=NULL;
216
217
219
220
221 const ILArPedestal* larPedestal=nullptr;
223
227 if (
sc.isFailure()) {
228 ATH_MSG_WARNING (
"Can't retrieve LArShape from Conditions Store" << std::endl
229 << "Quality factor will not be caluclated." );
230 larShape=NULL;
231 }
232 }
233
235 SG::ReadCondHandle<ILArOFC> larOFC (
m_ofcKey, ctx);
236
237 const LArADC2MeV* adc2mev = nullptr;
239 SG::ReadCondHandle<LArADC2MeV> adc2mevH (
m_adc2mevKey, ctx);
240 adc2mev = *adc2mevH;
241 }
242
243
245 const TBPhase* theTBPhase = nullptr;
246 const ILArGlobalTimeOffset* larGlobalTimeOffset = nullptr;
248
250
253
254
255
257 if (
sc.isSuccess()) globalTimeOffset = larGlobalTimeOffset->
TimeOffset();
258
259
261 if (
sc.isFailure()) larFebTimeOffset=NULL;
262 }
263
264
266 larRawChannelContainer->reserve(digitContainer->
size());
269 ATH_MSG_ERROR (
"Can't record LArRawChannelContainer in StoreGate" );
270 }
271
272
275
278
279
280 int ntot_raw=0;
281
282 for (const LArDigit* digit : *(digitContainer)) {
283
284
287 float quality=0;
288
289 int OFCTimeBin=0;
291
292
293 const std::vector<short>& samples=
digit->samples();
294 const unsigned nSamples=samples.size();
295 const HWIdentifier chid=
digit->channelID();
297
298
302 int region = -99999 ;
303 if (
msgLvl(MSG::DEBUG) ) {
305 try {
306 id =
cabling->cnvToIdentifier(chid);
307 } catch ( LArID_Exception & except ) {
308 ATH_MSG_DEBUG (
"A Cabling exception was caught for channel 0x!"
310 continue ;
311 }
315 region =
m_emId->region(
id);
317 <<
" [ Layer = " << layer <<
" - Eta = " <<
eta
318 <<
" - Phi = " <<
phi <<
" - Region = " << region <<
" ] " );
319 }
320
321
322 int nSatur=-1 ;
323 for (unsigned iSample=0;iSample<samples.size();iSample++) {
325 nSatur++;
326 break ;
327 }
328 }
329 if ( nSatur>-1 ) {
330 msg() << MSG::DEBUG <<
"Saturation on channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec ;
331 saturation++;
332 }
334 msg() <<
". Skipping channel." <<
endmsg;
335 continue;
336 } else if ( nSatur>-1 ) {
338 }
339
340
341
342
343 float pedestal=larPedestal->
pedestal(chid,gain);
344
345 float pedestalAverage;
349 <<
" Gain " << gain <<
". Using time sample " <<
m_iPedestal );
351 } else {
353 <<
" [ Layer = " << layer <<
" - Eta = " <<
eta <<
" - Phi = " <<
phi <<
" - Region = " << region <<
" ]"
354 << " Gain = " << gain << ". Skipping channel." );
355 noEnergy++;
356 continue;
357 }
358 } else {
363 << MSG::dec <<
" Gain=" << gain <<
". Using time sample " <<
m_iPedestal );
365 } else {
366 pedestalAverage=pedestal;
367 }
368 }
369
370
373 {
374 float febTimeOffset=0;
376 if (larFebTimeOffset)
377 febTimeOffset=larFebTimeOffset->
TimeOffset(febid);
378 double timeShift=PhaseTime+globalTimeOffset+febTimeOffset;
379 if (debugPrint)
380 msg() << MSG::VERBOSE <<
"Channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec
381 << " phase=" << PhaseTime << " Feb=" << febTimeOffset
382 << " Global=" << globalTimeOffset;
383
385 const double ofcTimeOffset=larOFC->timeOffset(chid,gain);
386 timeShift+=ofcTimeOffset;
387 if (debugPrint)
msg() << MSG::VERBOSE <<
" OFC=" << ofcTimeOffset;
388 }
389
390 if (debugPrint)
msg() << MSG::VERBOSE <<
" Total=" << timeShift <<
endmsg;
391
394 timeSampleShift -= 1;
395
397 }
400 timeSampleShift += 1;
401
403 }
404
406 BadTiming++;
407 noEnergy++;
408 ATH_MSG_ERROR ( noEnergy <<
". Time offset out of range for channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec
410 continue;
411 }
412
414 BadTiming++;
415 noEnergy++;
416 ATH_MSG_ERROR ( noEnergy <<
". Negative time sample (" << timeSampleShift <<
") shift for channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec
417 << " Found. Skipping channel." );
418 continue;
419 }
420
422
425
426
427
428
429 if (debugPrint)
ATH_MSG_VERBOSE (
"OFC bin width = " <<
m_OFCTimeBin <<
" - OFCBin = " << OFCTimeBin <<
" - timeShift = " << timeShift );
430
431 if ( OFCTimeBin < 0 ) {
432 ATH_MSG_ERROR (
"Channel " << MSG::hex << chid.
get_compact() << MSG::dec <<
" asks for OFC bin = " << OFCTimeBin <<
". Set to 0." );
433 OFCTimeBin=0;
437 }
438
439 ofc_a=larOFC->OFC_a(chid,gain,OFCTimeBin);
440
441 }
442
443
444 if (ofc_a.size()==0) {
445 noEnergy++;
447 <<
" [ Layer = " << layer <<
" - Eta = " <<
eta <<
" - Phi = " <<
phi <<
" - Region = " << region <<
" ]"
448 << " Time bin = " << OFCTimeBin << ", Gain = " << gain << ". Skipping channel." );
449 continue;
450 }
451 if (ofc_a.size()+timeSampleShift>nSamples) {
452 BadTiming++;
453 noEnergy++;
454 if (timeSampleShift==0)
455 ATH_MSG_DEBUG (
"Found LArDigit with " << nSamples <<
" samples, but OFCs for "
456 << ofc_a.size() << " samples. Skipping Channel ");
457 else
458 ATH_MSG_DEBUG (
"After time sample shift of " << timeSampleShift <<
", " << nSamples-timeSampleShift
459 << " samples left, but have OFCs for " << ofc_a.size() << " samples. Skipping Channel ");
460 continue;
461 }
462
463
464 float ADCPeak=0;
465 for (
unsigned i=0;
i<(ofc_a.size());
i++)
466 ADCPeak+=(samples[i+timeSampleShift]-pedestalAverage)*ofc_a.
at(i);
467
468 if (debugPrint)
ATH_MSG_VERBOSE (
"ADC Height calculated " << ADCPeak <<
" TimeBin=" << OFCTimeBin );
469
471
472 LArVectorProxy ramp = adc2mev->
ADC2MEV(chid,gain);
473
474 if (ramp.size()==0) {
475 noEnergy++;
477 <<
" [ Layer = " << layer <<
" - Eta = " <<
eta <<
" - Phi = " <<
phi <<
" - Region = " << region <<
" ]"
478 << " Gain = " << gain << ". Skipping channel." );
479 continue;
480 }
481
482
484 noEnergy++;
485 ATH_MSG_DEBUG (
"Bad ramp for channel " << chid <<
" (ramp[1] = " << ramp[1] <<
"): skip this channel" );
486 continue;
487 }
488
489 float ADCPeakPower=ADCPeak;
490
493
494 for (
unsigned i=1;
i<ramp.size();
i++)
496 ADCPeakPower*=ADCPeak;
497 }
498 } else {
502 Identifier
id =
cabling->cnvToIdentifier(chid);
505 }
506
507
508
510
511 float hvCorr = oflHVCorr-> HVScaleCorr(chid);
513 }
514
515
517 highE++;
518 ofc_b=larOFC->OFC_b(chid,gain,OFCTimeBin);
519 if (ofc_b.size() != ofc_a.size()) {
520 if (ofc_b.size()==0)
522 << " Gain "<< gain << " found. Time not calculated." );
523 else
525 << " not equal to OFC for energy size " << ofc_a.size()
526 << " Time not calculated " );
527 noTime++;
528 }else{
529 for (
unsigned i=0;
i<(ofc_b.size());
i++)
530 time+=(samples[i+timeSampleShift]-pedestalAverage)*ofc_b.
at(i);
532
533
534 }
535 if (debugPrint)
ATH_MSG_VERBOSE (
"Time calculated " << time <<
" TimeBin=" << OFCTimeBin );
536
537
538 if (larShape) {
539
540
541
542
543
546
547
548
549 if (shape.size() < ofc_a.size()) {
550 if (shape.size()==0)
552 << " Gain "<< gain << ". Quality factor not calculated." );
553 else
555 << "smaller than OFC size " << ofc_a.size()
556 <<
"for channel 0x" << MSG::hex << chid.
get_compact()
557 << MSG::dec << ". Quality factor not calculated." );
558 quality=0;
559 noShape++;
560 }
561 else {
562 if (time!=0 && shapeDer.size()!=shape.size()) {
563
564 ATH_MSG_DEBUG (
"Shape-Derivative has different size than Shape for channel 0x" << MSG::hex << chid.
get_compact() << MSG::dec
565 << ". Derivative not taken into accout for quality factor." );
566 noShapeDer++;
567 }
568 if (time==0 || shapeDer.size()!=shape.size() ) {
569 for (
unsigned i=0;
i<(ofc_a.size());
i++)
570 quality+=((samples[i+timeSampleShift]-pedestalAverage)-shape[i]*ADCPeak)*
571 ((samples[
i+timeSampleShift]-pedestalAverage)-shape[
i]*ADCPeak);
572 }
573 else {
574 for (
unsigned i=0;
i<(ofc_a.size());
i++)
575 quality+=((samples[i+timeSampleShift]-pedestalAverage)-((shape[i]-shapeDer[i]*time)*ADCPeak))*
576 ((samples[
i+timeSampleShift]-pedestalAverage)-((shape[
i]-shapeDer[
i]*
time)*ADCPeak));
577 }
578 }
579 }
580 else {
581 quality=0;
582 noShape++;
583 }
584
585
586 }
587 else
588 quality=-1;
589
591
592
595 if (quality>=0) {
596 iquality = ((
int)(quality) ) & 0xFFFF;
597 iprovenance=iprovenance | 0x2000;
598 }
599
600
601 LArRawChannel larRawChannel(chid,(int)energy,(int)time,iquality,iprovenance, gain);
602 larRawChannelContainer->push_back(larRawChannel);
603 ntot_raw++;
604 if (debugPrint)
606 << " e=" << energy << " t=" << time << " Q=" << quality );
607 }
608
609 ATH_MSG_DEBUG ( ntot_raw <<
" channels successfully processed, (" << highE <<
" with high energy)" );
610
611
612 if(BadTiming>=128){
613 ATH_MSG_ERROR (
"Too many channels (" <<BadTiming<<
" !) have a bad timing !!" );
614 ATH_MSG_ERROR (
"OFC time constants should be revisited !!!" );
616 larRawChannelContainer->clear();
617
618 }
619
620
622 ATH_MSG_ERROR ( saturation <<
" saturating channels were found. Event is skipped." );
623 larRawChannelContainer->clear();
624 }
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
653
659
664 || saturation>0 )
665 || (
msgSvc()->
outputLevel(
name()) <= MSG::DEBUG && ( noEnergy || noTime || noShape || noShapeDer || saturation ) )
666 ) {
667
672
673
674 MSG::Level msglvl;
675 if (noEnergy)
676 msglvl=MSG::ERROR;
677 else
678 msglvl=MSG::WARNING;
679 msg() << msglvl <<
" *** Error & Warning summary for this event *** " << std::endl;
680
681 if ( noEnergy ) {
682 msg() << msglvl <<
" " << noEnergy <<
" out of "
683 << digitContainer->
size() <<
" channel(s) skipped due to a lack of basic calibration constants."
684 << std::endl;
685 }
686 if ( noTime ) {
687 msg() << msglvl <<
" " << noTime <<
" out of "
688 << highE << " high-enegy channel(s) have no time-info due to a lack of Optimal Filtering Coefficients."
689 << std::endl;
690 }
691 if ( noShape ) {
692 msg() << msglvl <<
" " << noShape <<
" out of "
693 << highE << " high-enegy channel(s) have no quality factor due to a lack of shape."
694 << std::endl;
695 }
696 if ( noShapeDer ) {
697 msg() << msglvl <<
" " << noShapeDer <<
" out of "
698 << highE << " high-enegy channel(s) lack the derivative of the shape. Not taken into accout for Quality factor."
699 << std::endl;
700 }
701 if ( saturation ) {
703 msg() << MSG::ERROR <<
" " << saturation <<
" out of "
704 << digitContainer->
size() <<
" channel(s) showed saturations. The complete event was skipped." << std::endl;
706 msg() << MSG::ERROR <<
" " << saturation <<
" out of "
707 << digitContainer->
size() <<
" channel(s) showed saturations and were skipped." << std::endl;
708 else
709 msg() << MSG::WARNING <<
" " << saturation <<
" out of "
710 << digitContainer->
size() <<
" channel(s) showed saturations." << std::endl;
711 }
713 }
714
715
717
718 return StatusCode::SUCCESS;
719}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Old LArRawChannelContainer
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
size_type size() const noexcept
Returns the number of elements in the collection.
virtual float TimeOffset(const HWIdentifier fId) const =0
virtual float TimeOffset() const =0
LArVectorProxy OFCRef_t
This class defines the interface for accessing Optimal Filtering coefficients for each channel provid...
virtual float pedestal(const HWIdentifier &id, int gain) const =0
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
value_type get_compact() const
Get the compact id.
const LArVectorProxy ADC2MEV(const HWIdentifier &id, int gain) const
value_type at(size_t i) const
Vector indexing with bounds check.
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_offlineHVScaleCorrKey
SG::ReadCondHandleKey< ILArOFC > m_ofcKey
Property: OFC coefficients (conditions input).
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
time(flags, cells_name, *args, **kw)
void setConst()
Set the const flag for this expression.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::string debugPrint(const IDC_Container *container, unsigned numprint=25)
Diagnostic output of Identifiable Containers.