1 #ifndef EcalSimAlgos_ESFastTDigitizer_h
2 #define EcalSimAlgos_ESFastTDigitizer_h
16 #include "CLHEP/Random/RandGeneral.h"
17 #include "CLHEP/Random/RandPoissonQ.h"
18 #include "CLHEP/Random/RandFlat.h"
19 #include <gsl/gsl_sf_erf.h>
20 #include <gsl/gsl_sf_result.h>
56 refFile_ =
"SimCalorimetry/EcalSimProducers/data/esRefHistosFile_LG.txt";
59 refFile_ =
"SimCalorimetry/EcalSimProducers/data/esRefHistosFile_HG.txt";
74 <<
"Reference histos file not opened" ;
81 while( thisLine==0 ) {
83 if (!strstr(buffer,
"#") && !(strspn(buffer,
" ") == strlen(buffer))){
85 sscanf(buffer,
"%f",&histoBin);
97 if (!strstr(buffer,
"#") && !(strspn(buffer,
" ") == strlen(buffer))){
98 if(thisBin==-2){
float histoInf; sscanf(buffer,
"%f",&histoInf);
histoInf_ = (double)histoInf; }
99 if(thisBin==-1){
float histoSup; sscanf(buffer,
"%f",&histoSup);
histoSup_ = (double)histoSup; }
103 sscanf(buffer,
"%f",&refBin);
114 <<
"ESFastTDigitizer requires the RandomNumberGeneratorService\n"
115 "which is not present in the configuration file. You must add the service\n"
116 "in the configuration file or remove the modules that require it.";
118 CLHEP::HepRandomEngine& engine = rng->
getEngine();
131 <<
"ESFastTDigitizer requires the RandomNumberGeneratorService\n"
132 "which is not present in the configuration file. You must add the service\n"
133 "in the configuration file or remove the modules that require it.";
135 CLHEP::RandPoissonQ poissonDistribution_(rng->
getEngine());
136 CLHEP::RandFlat flatDistribution_(rng->
getEngine());
140 if (status != 0)
std::cerr<<
"ESFastTDigitizer::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
141 double probabilityLeft = result.val;
142 double meanNumberOfNoisyChannels = probabilityLeft *
numESdetId_;
143 int numberOfNoisyChannels = poissonDistribution_.fire(meanNumberOfNoisyChannels);
144 abThreshCh.reserve(numberOfNoisyChannels);
145 for (
int i = 0;
i < numberOfNoisyChannels;
i++) {
146 std::vector<int>::iterator theChannel;
147 int theChannelNumber = 0;
149 theChannelNumber = (int)flatDistribution_.fire(numESdetId_);
150 theChannel =
find(abThreshCh.begin(), abThreshCh.end(), theChannelNumber);
152 while ( theChannel!=abThreshCh.end() );
154 abThreshCh.push_back(theChannelNumber);
180 output.
reserve(nDigisExpected);
183 std::vector<int> abThreshCh;
188 for(std::vector<DetId>::const_iterator idItr =
theDetIds->begin();
189 idItr !=
theDetIds->end(); ++idItr,++idxDetId) {
191 bool needToDeleteSignal =
false;
195 bool wasEmpty =
false;
201 std::vector<int>::iterator thisChannel;
202 thisChannel =
find( abThreshCh.begin(), abThreshCh.end(), idxDetId);
203 if( thisChannel != abThreshCh.end() ) {
205 needToDeleteSignal =
true;
210 if (analogSignal != 0){
216 if (needToDeleteSignal)
delete analogSignal;
226 std::vector<PCaloHit> noiseHits;
228 for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
229 hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr) {
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
ESFastTDigitizer(CaloHitResponse *hitResponse, ESElectronicsSimFast *electronicsSim, bool addNoise, int numESdetId)
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
void createNoisyList(std::vector< int > &abThreshCh)
preparing the list of channels where the noise has to be generated
void push_back(T const &t)
virtual void getNoiseHits(std::vector< PCaloHit > &noiseHits)=0
void run(MixCollection< PCaloHit > &input, ESDigiCollection &output)
turns hits into digis
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
ESElectronicsSimFast * theElectronicsSim
Creates electronics signals from hits.
virtual void analogToDigital(const CaloSamples &cs, ESDataFrame &df, bool wasEmpty, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
CaloVNoiseHitGenerator * theNoiseHitGenerator
virtual void add(const PCaloHit &hit)
process a single SimHit
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
const std::vector< DetId > * theDetIds
virtual void run(MixCollection< PCaloHit > &hits)
Complete cell digitization.
void setDetIds(const std::vector< DetId > &detIds)
tell the digitizer which cells exist
void setGain(const int gain)
set ES Gain
CaloHitResponse * theHitResponse
void readHistosFromFile()
taking reference histos
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
void clear()
frees up memory
CLHEP::RandGeneral * histoDistribution_
void reserve(size_type n)
void newEvent()
anything that needs to be done once per event
int nSignals() const
number of signals in the current cache