270 {
271
272 bool createDigit_DigiHSTruth = true;
273
274
276 short Adc;
277 short Adc_DigiHSTruth;
278
280 std::vector<short> AdcSample_DigiHSTruth(
m_NSamples);
281
283 float SigmaNoise;
285
291 else if (
m_larem_id->is_em_endcap_inner(cellId))
293
296
297
298
300
301
302
303
304#ifndef NDEBUG
307#endif
308
315
316
317
318
319
320#ifndef NDEBUG
321 ATH_MSG_DEBUG(
" number of hit for this cell " << TimeE->size());
322#endif
323
324
325
326
327 bool isDead =
m_bcMask.cellShouldBeMasked(bcCont,ch_id);
328
329
330 if (!isDead) {
331 if( this->
ConvertHits2Samples(cellId,ch_id,initialGain,TimeE, Samples, shape).isFailure() ) {
332 return StatusCode::SUCCESS;
333 }
335 if( this->
ConvertHits2Samples(cellId,ch_id,initialGain,TimeE_DigiHSTruth, Samples_DigiHSTruth, shape).isFailure() ) {
336 return StatusCode::SUCCESS;
337 }
338 }
339 }
340
341
342
343
344 float energy2adc ;
345 float rAdc ;
347 {
348 rndmGain= rndmEvtDigit->gain();
349 auto polynom_adc2mev =adc2MeVs->
ADC2MEV(ch_id,rndmEvtDigit->gain());
350 if (polynom_adc2mev.size() > 1) {
351 float adc2energy =
SF * polynom_adc2mev[1];
352 const std::vector<short> & rndm_digit_samples = rndmEvtDigit->samples() ;
353 float Pedestal = pedestal->
pedestal(ch_id,rndmEvtDigit->gain());
355 ATH_MSG_WARNING(
" Pedestal not found in database for this channel offID " << cellId <<
" Use sample 0 for random");
356 Pedestal = rndm_digit_samples[0];
357 }
358 ATH_MSG_DEBUG(
" Params for inverting LAr Digitization: pedestal " << Pedestal <<
" adc2energy " << adc2energy);
359
360
361
362 float adc0=0.;
364 SG::ReadCondHandle<ILArOFC> larOFC(
m_OFCKey, ctx);
365 if (larOFC.cptr() != nullptr) {
367 float sumOfc=0.;
368 if (ofc_a.size()>0) {
369 for (
unsigned int j=0;
j<ofc_a.size();
j++) sumOfc += ofc_a.
at(j);
370 }
371 if (sumOfc>0) adc0 = polynom_adc2mev[0] *
SF /sumOfc;
372 }
373 }
374
376 if ((
int)(rndm_digit_samples.size()) <
m_NSamples) {
378 "Less digit Samples than requested in digitization for cell "
379 << ch_id.
get_compact() <<
" Digit has " << rndm_digit_samples.size()
380 <<
" samples. Digitization request " <<
m_NSamples);
381 nmax = rndm_digit_samples.size();
382 }
384 {
385 rAdc = (rndm_digit_samples[
i] - Pedestal ) * adc2energy + adc0;
386 rndm_energy_samples[
i] = rAdc ;
388 }
389 }
390 else {
391 ATH_MSG_ERROR(
" No ramp found for this random cell " <<
m_larem_id->show_to_string(cellId) <<
" for gain " << rndmEvtDigit->gain());
392 if (adc2MeVs->
nGains()<=(
int)rndmEvtDigit->gain()) {
393 ATH_MSG_ERROR(
"Found ramp for only " << adc2MeVs->
nGains() <<
" gains. Are you trying to overlay of Run 3 random with run 4 signal?");
394 }
395 return StatusCode::FAILURE;
396 }
397 }
398
399
402 return StatusCode::FAILURE;
403 }
404
405
406 igain=std::max(rndmGain,igain);
407
408
409
410
411 if (igain != initialGain ){
415 else Samples[
i] = 0.;
416 }
417
418 if (!isDead) {
419 if( this->
ConvertHits2Samples(cellId,ch_id,igain,TimeE, Samples, shape) == StatusCode::FAILURE ) {
420 return StatusCode::SUCCESS;
421 }
423 if( this->
ConvertHits2Samples(cellId,ch_id,igain,TimeE_DigiHSTruth, Samples_DigiHSTruth, shape) == StatusCode::FAILURE ) {
424 return StatusCode::SUCCESS;
425 }
426 }
427 }
428 }
429
430
431
432
433
434 double Rndm[32]{};
435 int BvsEC=0;
437
438 bool addedNoise=false;
442
443 {
446 SigmaNoise =
noise->noise(ch_id, igain);
447 } else {
448 float thisNoise = pedestal->
pedestalRMS(ch_id, igain);
450 SigmaNoise = thisNoise;
451 else
452 SigmaNoise = 0.;
453 }
454
455 const std::vector<float>& CorGen =
461 return StatusCode::FAILURE;
462 }
463
464 RandGaussZiggurat::shootArray(engine,
m_NSamples, Rndm, 0., 1.);
465
469 for (
int j = 0;
j <=
i;
j++) {
471 Noise[
i] += Rndm[
j] * CorGen[
index];
472 }
473 Noise[
i] = Noise[
i] * SigmaNoise;
474 }
475 addedNoise = true;
476 } else {
477
479 Noise[i] = 0.;
480
481
482
483
484 if (rndmEvtDigit) {
485
486 if (igain > rndmEvtDigit->gain()) {
487 double SigmaNoiseZB = 0.;
488 double SigmaNoise = 0.;
489 double SigmaExtraNoise = 0.;
491 SigmaNoiseZB =
noise->noise(ch_id, rndmEvtDigit->gain());
492 SigmaNoise =
noise->noise(ch_id, igain);
493 } else {
494 float thisNoise = pedestal->
pedestalRMS(ch_id, rndmEvtDigit->gain());
496 SigmaNoiseZB = thisNoise;
497 else
498 SigmaNoiseZB = 0.;
501 SigmaNoise = thisNoise;
502 else
503 SigmaNoise = 0.;
504 }
505
506 auto polynom_adc2mevZB =
507 adc2MeVs->
ADC2MEV(cellId, rndmEvtDigit->gain());
508 auto polynom_adc2mev = adc2MeVs->
ADC2MEV(cellId, igain);
509 if (polynom_adc2mevZB.size() > 1 && polynom_adc2mev.size() > 1) {
510 if (polynom_adc2mev[1] > 0.) {
511 SigmaNoiseZB = SigmaNoiseZB * (polynom_adc2mevZB[1]) /
512 (polynom_adc2mev[1]);
513 if (SigmaNoise > SigmaNoiseZB)
514 SigmaExtraNoise = sqrt(SigmaNoise * SigmaNoise -
515 SigmaNoiseZB * SigmaNoiseZB);
516 }
517 }
518 RandGaussZiggurat::shootArray(engine,
m_NSamples, Rndm, 0.,
519 1.);
521 Noise[i] = SigmaExtraNoise * Rndm[i];
522 addedNoise = true;
523 }
524 }
525 }
526 }
527
528
529
530 float Pedestal = pedestal->
pedestal(ch_id,igain);
532 ATH_MSG_WARNING(
" pedestal not found for cellId " << cellId <<
" assume 1000" );
533 Pedestal=1000.;
534 }
535 const auto polynom_adc2mev = adc2MeVs->
ADC2MEV(cellId,igain);
536 if (polynom_adc2mev.size() < 2) {
537 ATH_MSG_WARNING(
" No ramp found for requested gain " << igain <<
" for cell " <<
m_larem_id->show_to_string(cellId) <<
" no digit made...");
538 return StatusCode::SUCCESS;
539 }
540
541 energy2adc=1./(polynom_adc2mev[1])/SF;
542
543
544
546 {
547 SG::ReadCondHandle<ILArOFC> larOFC(
m_OFCKey, ctx);
548 if (larOFC.cptr() != nullptr) {
549 float sumOfc=0.;
551 if (ofc_a.size()>0) {
552 for (
unsigned int j=0;
j<ofc_a.size();
j++) sumOfc+= ofc_a.
at(j);
553 }
554 if ((polynom_adc2mev[1])>0 && sumOfc>0) Pedestal = Pedestal - (polynom_adc2mev[0])/(polynom_adc2mev[1])/sumOfc;
555 ATH_MSG_DEBUG(
" Params for final LAr Digitization gain: " << igain <<
" pedestal: " << Pedestal <<
" energy2adc: " << energy2adc);
556 }
557 }
559 {
560 double xAdc;
561 double xAdc_DigiHSTruth = 0;
562
563 if ( addedNoise ){
564 xAdc = Samples[
i]*energy2adc + Noise[
i] + Pedestal + 0.5;
566 xAdc_DigiHSTruth = Samples_DigiHSTruth[
i]*energy2adc + Noise[
i] + Pedestal + 0.5;
567 }
568 }
569
570 else {
572 float flatRndm = RandFlat::shoot(engine);
573 xAdc = Samples[
i]*energy2adc + Pedestal + flatRndm;
575 xAdc_DigiHSTruth = Samples_DigiHSTruth[
i]*energy2adc + Pedestal + flatRndm;
576 }
577
578 }
579 else{
580 xAdc = Samples[
i]*energy2adc + Pedestal + 0.5;
582 xAdc_DigiHSTruth = Samples_DigiHSTruth[
i]*energy2adc + Pedestal + 0.5;
583 }
584 }
585
586 }
587
588
589
590
591
592 if (xAdc <0) {
594 Adc=0;
595 }
598 ", energy2adc=" << energy2adc << ", E[0]= " << (TimeE->size()>0 ? std::format("{}",TimeE->at(0).first) : "No value"));
600 }
601 else
603
605
607 if (xAdc_DigiHSTruth <0) Adc_DigiHSTruth=0;
609 else Adc_DigiHSTruth = (
short) xAdc_DigiHSTruth;
610 AdcSample_DigiHSTruth[
i] = Adc_DigiHSTruth;
611 }
612
613#ifndef NDEBUG
614 ATH_MSG_DEBUG(
" Sample " << i <<
" Energy= " << Samples[i] <<
" Adc=" << Adc);
615#endif
616
617 }
618
619
620
621
623 (*Digit)=LArDigit(ch_id,igain,std::move(AdcSample));
624
626 createDigit_DigiHSTruth = false;
627 Digit_DigiHSTruth = nullptr;
628
630 if (Samples_DigiHSTruth[i] != 0)
631 createDigit_DigiHSTruth = true;
632 }
633
634 Digit_DigiHSTruth =
635 new LArDigit(ch_id, igain, std::move(AdcSample_DigiHSTruth));
636 }
637
638 return StatusCode::SUCCESS;
639}
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
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
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
virtual const float & FSAMPL(const HWIdentifier &id) const =0
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.
const LArVectorProxy ADC2MEV(const HWIdentifier &id, int gain) const
const std::vector< float > & autoCorrSqrt(const HWIdentifier &id, int gain) const
Gaudi::Property< bool > m_NoiseInEMEC
StatusCode ConvertHits2Samples(const Identifier &cellId, HWIdentifier ch_id, CaloGain::CaloGain igain, const std::vector< std::pair< float, float > > *TimeE, staticVecDouble_t &sampleList, const ILArShape *shape) const
Gaudi::Property< bool > m_roundingNoNoise
Gaudi::Property< bool > m_NoiseInEMB
Gaudi::Property< bool > m_NoiseInHEC
boost::container::static_vector< double, s_MaxNSamples > staticVecDouble_t
CaloGain::CaloGain chooseGain(const staticVecDouble_t &samples, const HWIdentifier id, const CaloNum iCalo, const ILArPedestal *ped, const LArADC2MeV *ramp, const float SF) const
boost::container::static_vector< float, s_MaxNSamples > staticVecFloat_t
Gaudi::Property< bool > m_NoiseInFCAL
value_type at(size_t i) const
Vector indexing with bounds check.
const float SF[NF]
Cross sections for Fluor.