6#include "CLHEP/Random/RandGaussZiggurat.h"
16#include "CLHEP/Random/RandomEngine.h"
17#include <CLHEP/Random/Randomize.h>
21using CLHEP::RandGaussZiggurat;
29 return StatusCode::FAILURE;
52 StatusCode
sc =
detStore()->retrieve(caloIdMgr);
54 ATH_MSG_ERROR(
" Unable to retrieve CaloIdManager from DetectoreStore");
55 return StatusCode::FAILURE;
63 ATH_MSG_ERROR(
" Unable to retrieve LArOnlineId from DetectoreStore");
64 return StatusCode::FAILURE;
75 return StatusCode::SUCCESS;
87 return StatusCode::FAILURE;
93 const LArHitEMap* hitmapPtr_DigiHSTruth =
nullptr;
96 hitmapPtr_DigiHSTruth = hitmap_DigitHSTruth.
cptr();
107 DigitContainer->reserve(it_end);
113 std::unique_ptr<LArDigitContainer> DigitContainer_DigiHSTruth =
nullptr;
115 DigitContainer_DigiHSTruth = std::make_unique<LArDigitContainer>();
116 DigitContainer_DigiHSTruth->reserve(it_end);
119 const std::vector<std::pair<float,float> >* TimeE;
120 const std::vector<std::pair<float,float> >* TimeE_DigiHSTruth =
nullptr;
123 CLHEP::HepRandomEngine * engine = rngWrapper->
getEngine(context);
127 for( ; it!=it_end;++it)
134 const auto& hitlist_DigiHSTruth=hitmapPtr_DigiHSTruth->
GetCell(it);
135 TimeE_DigiHSTruth = &(hitlist_DigiHSTruth.getData());
142 bool missing=!(badFebs->
status(febId).good());
150 LArDigit* Digit_DigiHSTruth =
nullptr;
153 Digit_DigiHSTruth, TimeE, digit, engine,
155 DigitContainer->push_back(Digit);
156 if (DigitContainer_DigiHSTruth){
157 DigitContainer_DigiHSTruth->push_back(Digit_DigiHSTruth);
166 ATH_MSG_DEBUG(
" number of created digits = " << DigitContainer->size());
170 if ( DigitContainer_DigiHSTruth ){
172 ATH_CHECK(DigitContainer_DigiHSTruthHandle.
record( std::move(DigitContainer_DigiHSTruth) ) );
176 return StatusCode::SUCCESS;
180 const EventContext& ctx,
186 const std::vector<std::pair<float, float>>* TimeE,
188 CLHEP::HepRandomEngine* engine,
189 const std::vector<std::pair<float, float>>* TimeE_DigiHSTruth)
const {
190 bool createDigit_DigiHSTruth =
true;
192 int sampleGainChoice{2};
197 short Adc_DigiHSTruth;
201 std::vector<short> AdcSample_DigiHSTruth(
m_NSamples);
228 autoCorrNoise=*autoCorrNoiseHdl;
272 ATH_MSG_DEBUG(
" number of hit for this cell " << TimeE->size());
278 bool isDead =
m_bcMask.cellShouldBeMasked(bcCont,ch_id);
282 if( this->
ConvertHits2Samples(ctx, cellId,ch_id,initialGain,TimeE, Samples).isFailure() ) {
283 return StatusCode::SUCCESS;
286 if( this->
ConvertHits2Samples(ctx, cellId,ch_id,initialGain,TimeE_DigiHSTruth, Samples_DigiHSTruth).isFailure() ) {
287 return StatusCode::SUCCESS;
299 rndmGain= rndmEvtDigit->
gain();
300 auto polynom_adc2mev =adc2MeVs->
ADC2MEV(cellId,rndmEvtDigit->
gain());
301 if (polynom_adc2mev.size() > 1) {
302 float adc2energy = SF * polynom_adc2mev[1];
303 const std::vector<short> & rndm_digit_samples = rndmEvtDigit->
samples() ;
304 float Pedestal = pedestal->
pedestal(ch_id,rndmEvtDigit->
gain());
306 ATH_MSG_WARNING(
" Pedestal not found in database for this channel offID " << cellId <<
" Use sample 0 for random");
307 Pedestal = rndm_digit_samples[0];
309 ATH_MSG_DEBUG(
" Params for inverting LAr Digitization: pedestal " << Pedestal <<
" adc2energy " << adc2energy);
316 if (larOFC.
cptr() !=
nullptr) {
319 if (ofc_a.size()>0) {
320 for (
unsigned int j=0;j<ofc_a.size();j++) sumOfc += ofc_a.
at(j);
322 if (sumOfc>0) adc0 = polynom_adc2mev[0] * SF /sumOfc;
327 if ((
int)(rndm_digit_samples.size()) <
m_NSamples) {
329 "Less digit Samples than requested in digitization for cell "
330 << ch_id.
get_compact() <<
" Digit has " << rndm_digit_samples.size()
331 <<
" samples. Digitization request " <<
m_NSamples);
332 nmax = rndm_digit_samples.size();
334 for(i=0 ; i<
nmax ; i++)
336 rAdc = (rndm_digit_samples[i] - Pedestal ) * adc2energy + adc0;
337 rndm_energy_samples[i] = rAdc ;
354 float samp2=Samples[sampleGainChoice-ihecshift]*MeV2GeV;
358 float Samp2_DigiHSTruth=Samples_DigiHSTruth[sampleGainChoice-ihecshift]*MeV2GeV;
359 if ( Samp2_DigiHSTruth <=
m_EnergyThresh ) createDigit_DigiHSTruth =
false;
372 ATH_MSG_DEBUG(
" Pedestal not found for medium gain ,cellID " << cellId <<
" assume 1000 ");
376 if ( polynom_adc2mev.size() < 2) {
377 ATH_MSG_WARNING(
" No medium gain ramp found for cell " <<
m_larem_id->show_to_string(cellId) <<
" no digit produced...");
378 return StatusCode::SUCCESS;
380 pseudoADC3 = Samples[sampleGainChoice-ihecshift]/(polynom_adc2mev[1])/SF + Pedestal ;
399 if (igain != initialGain ){
403 else Samples[i] = 0.;
407 if( this->
ConvertHits2Samples(ctx, cellId,ch_id,igain,TimeE, Samples) == StatusCode::FAILURE ) {
408 return StatusCode::SUCCESS;
411 if( this->
ConvertHits2Samples(ctx, cellId,ch_id,igain,TimeE_DigiHSTruth, Samples_DigiHSTruth) == StatusCode::FAILURE ) {
412 return StatusCode::SUCCESS;
426 bool addedNoise=
false;
434 SigmaNoise = noise->noise(ch_id, igain);
443 const std::vector<float>& CorGen =
449 return StatusCode::FAILURE;
452 RandGaussZiggurat::shootArray(engine,
m_NSamples, Rndm, 0., 1.);
457 for (
int j = 0; j <= i; j++) {
459 Noise[i] += Rndm[j] * CorGen[
index];
461 Noise[i] = Noise[i] * SigmaNoise;
474 if (igain > rndmEvtDigit->
gain()) {
475 double SigmaNoiseZB = 0.;
476 double SigmaNoise = 0.;
477 double SigmaExtraNoise = 0.;
479 SigmaNoiseZB = noise->noise(ch_id, rndmEvtDigit->
gain());
480 SigmaNoise = noise->noise(ch_id, igain);
484 SigmaNoiseZB = noise;
494 auto polynom_adc2mevZB =
496 auto polynom_adc2mev = adc2MeVs->
ADC2MEV(cellId, igain);
497 if (polynom_adc2mevZB.size() > 1 && polynom_adc2mev.size() > 1) {
498 if (polynom_adc2mev[1] > 0.) {
499 SigmaNoiseZB = SigmaNoiseZB * (polynom_adc2mevZB[1]) /
500 (polynom_adc2mev[1]);
501 if (SigmaNoise > SigmaNoiseZB)
502 SigmaExtraNoise = sqrt(SigmaNoise * SigmaNoise -
503 SigmaNoiseZB * SigmaNoiseZB);
506 RandGaussZiggurat::shootArray(engine,
m_NSamples, Rndm, 0.,
509 Noise[i] = SigmaExtraNoise * Rndm[i];
518 Pedestal = pedestal->
pedestal(ch_id,igain);
520 ATH_MSG_WARNING(
" pedestal not found for cellId " << cellId <<
" assume 1000" );
523 polynom_adc2mev = adc2MeVs->
ADC2MEV(cellId,igain);
524 if (polynom_adc2mev.size() < 2) {
525 ATH_MSG_WARNING(
" No ramp found for requested gain " << igain <<
" for cell " <<
m_larem_id->show_to_string(cellId) <<
" no digit made...");
526 return StatusCode::SUCCESS;
529 energy2adc=1./(polynom_adc2mev[1])/SF;
536 if (larOFC.
cptr() !=
nullptr) {
539 if (ofc_a.size()>0) {
540 for (
unsigned int j=0;j<ofc_a.size();j++) sumOfc+= ofc_a.
at(j);
542 if ((polynom_adc2mev[1])>0 && sumOfc>0) Pedestal = Pedestal - (polynom_adc2mev[0])/(polynom_adc2mev[1])/sumOfc;
543 ATH_MSG_DEBUG(
" Params for final LAr Digitization gain: " << igain <<
" pedestal: " << Pedestal <<
" energy2adc: " << energy2adc);
549 double xAdc_DigiHSTruth = 0;
552 xAdc = Samples[i]*energy2adc + Noise[i] + Pedestal + 0.5;
554 xAdc_DigiHSTruth = Samples_DigiHSTruth[i]*energy2adc + Noise[i] + Pedestal + 0.5;
560 float flatRndm = RandFlat::shoot(engine);
561 xAdc = Samples[i]*energy2adc + Pedestal + flatRndm;
563 xAdc_DigiHSTruth = Samples_DigiHSTruth[i]*energy2adc + Pedestal + flatRndm;
568 xAdc = Samples[i]*energy2adc + Pedestal + 0.5;
570 xAdc_DigiHSTruth = Samples_DigiHSTruth[i]*energy2adc + Pedestal + 0.5;
582 else Adc = (short) xAdc;
587 if (xAdc_DigiHSTruth <0) Adc_DigiHSTruth=0;
589 else Adc_DigiHSTruth = (short) xAdc_DigiHSTruth;
590 AdcSample_DigiHSTruth[i] = Adc_DigiHSTruth;
594 ATH_MSG_DEBUG(
" Sample " << i <<
" Energy= " << Samples[i] <<
" Adc=" << Adc);
603 (*Digit)=
LArDigit(ch_id,igain,std::move(AdcSample));
606 createDigit_DigiHSTruth =
false;
607 Digit_DigiHSTruth =
nullptr;
610 if (Samples_DigiHSTruth[i] != 0)
611 createDigit_DigiHSTruth =
true;
615 new LArDigit(ch_id, igain, std::move(AdcSample_DigiHSTruth));
618 return StatusCode::SUCCESS;
625 const std::vector<std::pair<float,float> > *TimeE,
staticVecDouble_t &sampleList)
const
646 nsamples = Shape.size();
647 nsamples_der = ShapeDer.size();
651 return StatusCode::FAILURE;
656 for (i=0;i<nsamples;i++)
662 std::vector<std::pair<float,float> >
::const_iterator first = TimeE->begin();
665 while (first != last)
667 energy = (*first).first;
668 time = (*first).second;
686 int ishift=(int)(rint(time*(1./25.)));
687 double dtime=time-25.*((double)(ishift));
694 if (j >=0 && j < nsamples ) {
695 if (j<nsamples_der && std::abs(ShapeDer[j])<10. )
696 sampleList[i] += (Shape[j]- ShapeDer[j]*dtime)*energy ;
697 else sampleList[i] += Shape[j]*energy ;
707 float timeBinWidth = 25./24.*3.;
715 int ishift = (int)(time*(1./25.));
718 tbin = (int)(fmod(time,25)/timeBinWidth);
724 tbin = (int)(fmod(-time,25)/timeBinWidth);
727 double dtime = time - ( 25.*((float)(ishift)) - timeBinWidth*tbin);
729 Shape = shape->
Shape(ch_id,igain,tbin);
730 ShapeDer = shape->
ShapeDer(ch_id,igain,tbin);
732 nsamples = Shape.size();
733 nsamples_der = ShapeDer.size();
742 if (j >=0 && j < nsamples ) {
743 if (j<nsamples_der && std::abs(ShapeDer[j])<10. )
744 sampleList[i] += (Shape[j]- ShapeDer[j]*dtime)*energy ;
745 else sampleList[i] += Shape[j]*energy ;
754 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Definition of CaloDetDescrManager.
interface to a tool that returns the time offset of the current trigger.
LArBadXCont< LArBadFeb > LArBadFebCont
LArBadXCont< LArBadChannel > LArBadChannelCont
A wrapper class for event-slot-local random engines.
SeedingOptionType
Options for seeding option=0 is setSeed as in MC20 option=1 is setSeedLegacy as in MC16 option=2 is s...
void setSeedLegacy(const std::string &algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset, SeedingOptionType seeding, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
const ServiceHandle< StoreGateSvc > & detStore() const
const_iterator end() const
This class initializes the Calo (LAr and Tile) offline identifiers.
const LArHEC_ID * getHEC_ID(void) const
const LArFCAL_ID * getFCAL_ID(void) const
const LArEM_ID * getEM_ID(void) const
a typed memory pool that saves time spent allocation small object.
void reserve(unsigned int size)
Set the desired capacity.
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
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
virtual const float & FSAMPL(const HWIdentifier &id) const =0
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
const LArVectorProxy ADC2MEV(const HWIdentifier &id, int gain) const
const std::vector< float > & autoCorrSqrt(const HWIdentifier &id, int gain) const
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
Liquid Argon digit base class.
CaloGain::CaloGain gain() const
const std::vector< short > & samples() const
Gaudi::Property< bool > m_usePhase
Gaudi::Property< double > m_EnergyThresh
Gaudi::Property< bool > m_isMcOverlay
const LArHEC_ID * m_larhec_id
Gaudi::Property< std::vector< std::string > > m_problemsToMask
static constexpr int s_MaxNSamples
Gaudi::Property< bool > m_NoiseInEMEC
Gaudi::Property< bool > m_doDigiTruth
SG::ReadHandleKey< LArHitEMap > m_hitMapKey
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
const CaloCell_ID * m_calocell_id
Gaudi::Property< bool > m_pedestalNoise
Gaudi::Property< bool > m_roundingNoNoise
SG::ReadHandleKey< LArHitEMap > m_hitMapKey_DigiHSTruth
StatusCode MakeDigit(const EventContext &ctx, const Identifier &cellId, const HWIdentifier &ch_id, LArDigit *&Digit, DataPool< LArDigit > &dataItemsPool, LArDigit *&Digit_DigiHSTruth, const std::vector< std::pair< float, float > > *TimeE, const LArDigit *rndm_digit, CLHEP::HepRandomEngine *engine, const std::vector< std::pair< float, float > > *TimeE_DigiHSTruth=nullptr) const
virtual StatusCode execute(const EventContext &context) const
Gaudi::Property< uint32_t > m_randomSeedOffset
Gaudi::Property< bool > m_NoiseInEMB
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Gaudi::Property< int > m_firstSample
SG::WriteHandleKey< LArDigitContainer > m_DigitContainerName_DigiHSTruth
const LArOnlineID * m_laronline_id
Gaudi::Property< bool > m_NoiseInHEC
boost::container::static_vector< double, s_MaxNSamples > staticVecDouble_t
Gaudi::Property< bool > m_useLegacyRandomSeeds
const LArFCAL_ID * m_larfcal_id
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::array< Gaudi::Property< double >, 4 > m_LowGainThresh
virtual StatusCode initialize()
SG::ReadCondHandleKey< ILArPedestal > m_pedestalKey
const LArEM_ID * m_larem_id
SG::ReadCondHandleKey< ILArNoise > m_noiseKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Gaudi::Property< bool > m_Windows
StatusCode ConvertHits2Samples(const EventContext &ctx, const Identifier &cellId, HWIdentifier ch_id, CaloGain::CaloGain igain, const std::vector< std::pair< float, float > > *TimeE, staticVecDouble_t &sampleList) const
LArBadChannelMask m_bcMask
Gaudi::Property< bool > m_NoiseOnOff
std::array< Gaudi::Property< double >, 4 > m_HighGainThresh
boost::container::static_vector< float, s_MaxNSamples > staticVecFloat_t
Gaudi::Property< bool > m_RndmEvtOverlay
Gaudi::Property< int > m_NSamples
SG::ReadCondHandleKey< ILArOFC > m_OFCKey
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
SG::ReadCondHandleKey< LArAutoCorrNoise > m_autoCorrNoiseKey
const T * pointerFromKey(const EventContext &context, const SG::ReadCondHandleKey< T > &key) const
Gaudi::Property< bool > m_NoiseInFCAL
SG::ReadCondHandleKey< LArBadFebCont > m_badFebKey
SG::ReadCondHandleKey< ILArfSampl > m_fSamplKey
Gaudi::Property< unsigned > m_maxADC
SG::WriteHandleKey< LArDigitContainer > m_DigitContainerName
SG::ReadCondHandleKey< ILArShape > m_shapeKey
Gaudi::Property< std::string > m_randomStreamName
const LArHitList & GetCell(const unsigned int index) const
const LArDigit * GetDigit(unsigned int index) const
int GetNbCells(void) const
const LARLIST & getData() const
value_type at(size_t i) const
Vector indexing with bounds check.
const_pointer_type cptr()
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts