6 #include "CLHEP/Random/RandGeneral.h"
7 #include "CLHEP/Random/RandPoissonQ.h"
8 #include "CLHEP/Random/RandFlat.h"
10 #include <gsl/gsl_sf_erf.h>
11 #include <gsl/gsl_sf_result.h>
62 double zsThresh ( 0. ) ;
68 refFile =
"SimCalorimetry/EcalSimProducers/data/esRefHistosFile_LG.txt";
73 refFile =
"SimCalorimetry/EcalSimProducers/data/esRefHistosFile_HG.txt";
77 int status = gsl_sf_erf_Q_e( zsThresh, &result ) ;
78 if( status != 0 )
std::cerr <<
"ESDigitizer::could not compute gaussian tail probability for the threshold chosen" << std::endl ;
80 const double probabilityLeft ( result.val ) ;
84 if( !histofile.good() )
87 <<
"Reference histos file not opened" ;
94 while( 0 == thisLine )
96 histofile.getline( buffer, 200 ) ;
97 if( !strstr(buffer,
"#") &&
98 !(strspn(buffer,
" ") == strlen(buffer) ) )
101 sscanf( buffer,
"%f" , &histoBin ) ;
106 const uint32_t histoBin1 ( (
int)
m_histoBin ) ;
107 const uint32_t histoBin2 ( histoBin1*histoBin1 ) ;
109 double t_histoSup ( 0 ) ;
111 std::vector<double> t_refHistos ;
112 t_refHistos.reserve( 2500 ) ;
115 while( !( histofile.eof() ) )
117 histofile.getline( buffer, 200 ) ;
118 if( !strstr( buffer,
"#" ) &&
119 !( strspn( buffer,
" " ) == strlen( buffer ) ) )
124 sscanf( buffer,
"%f" , &histoInf ) ;
130 sscanf( buffer,
"%f" , &histoSup ) ;
131 t_histoSup = (double) histoSup ;
136 sscanf( buffer,
"%f", &refBin ) ;
139 t_refHistos.push_back( (
double) refBin ) ;
140 const uint32_t i2 ( thisBin/histoBin2 ) ;
141 const uint32_t off ( i2*histoBin2 ) ;
142 const uint32_t i1 ( ( thisBin - off )/histoBin1 ) ;
143 const uint32_t i0 ( thisBin - off - i1*histoBin1 ) ;
144 m_trip.emplace_back(i0, i1, i2) ;
156 &t_refHistos.front() ,
180 std::vector<DetId> abThreshCh ;
184 for( std::vector<DetId>::const_iterator idItr ( abThreshCh.begin() ) ;
185 idItr != abThreshCh.end(); ++idItr )
191 if( myBin ==
m_trip.size() ) --myBin ;
199 analogToDigital( engine,
212 CLHEP::RandPoissonQ randPoissonQ(*engine,
m_meanNoisy);
213 const unsigned int nChan (randPoissonQ.fire());
214 abThreshCh.reserve( nChan ) ;
216 for(
unsigned int i ( 0 ) ;
i != nChan ; ++
i )
218 std::vector<DetId>::const_iterator idItr ( abThreshCh.end() ) ;
219 uint32_t iChan ( 0 ) ;
223 iChan = (uint32_t) CLHEP::RandFlat::shoot(engine,
m_detIds->size());
224 if( iChan ==
m_detIds->size() ) --iChan ;
226 id = (*m_detIds)[ iChan ] ;
227 idItr =
find( abThreshCh.begin() ,
231 while( idItr != abThreshCh.end() ) ;
void setDetIds(const std::vector< DetId > &detIds)
tell the digitizer which cells exist; cannot change during a run
std::vector< Triplet > m_trip
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const EcalSamples * findDetId(const DetId &detId) const
const ElectronicsSim * elecSim() const
CLHEP::RandGeneral * m_ranGeneral
void createNoisyList(std::vector< DetId > &abThreshCh, CLHEP::HepRandomEngine *)
void setGain(const int gain)
void reserve(size_t isize)
const std::vector< DetId > * m_detIds
void push_back(unsigned int i)
virtual void run(DigiCollection &output, CLHEP::HepRandomEngine *)
virtual void run(ESDigiCollection &output, CLHEP::HepRandomEngine *) override
turns hits into digis
const EcalHitResponse * hitResponse() const
ESDigitizer(EcalHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)