00001 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSim.h"
00002 #include "DataFormats/EcalDigi/interface/ESSample.h"
00003 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00004
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00007 #include "CLHEP/Random/RandGaussQ.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009
00010 using namespace std;
00011
00012 ESElectronicsSim::ESElectronicsSim (bool addNoise, double sigma, int gain, int baseline, double MIPADC, double MIPkeV):
00013 addNoise_(addNoise), sigma_ (sigma), gain_ (gain), baseline_(baseline), MIPADC_(MIPADC), MIPkeV_(MIPkeV)
00014 {
00015
00016
00017
00018
00019
00020
00021
00022 }
00023
00024 void ESElectronicsSim::setNoiseSigma (const double sigma)
00025 {
00026 sigma_ = sigma ;
00027 return ;
00028 }
00029
00030 void ESElectronicsSim::setGain (const int gain)
00031 {
00032 gain_ = gain ;
00033 return ;
00034 }
00035
00036 void ESElectronicsSim::setBaseline (const int baseline)
00037 {
00038 baseline_ = baseline ;
00039 return ;
00040 }
00041
00042 void ESElectronicsSim::setMIPADC (const double MIPADC)
00043 {
00044 MIPADC_ = MIPADC ;
00045 return ;
00046 }
00047
00048 void ESElectronicsSim::setMIPkeV (const double MIPkeV)
00049 {
00050 MIPkeV_ = MIPkeV ;
00051 return ;
00052 }
00053
00054 void ESElectronicsSim::analogToDigital(const CaloSamples& cs, ESDataFrame& df) const
00055 {
00056
00057 std::vector<ESSample> essamples = encode(cs);
00058
00059 df.setSize(cs.size());
00060 for(int i=0; i<df.size(); i++) {
00061 df.setSample(i, essamples[i]);
00062 }
00063
00064 }
00065
00066 void ESElectronicsSim::digitalToAnalog(const ESDataFrame& df, CaloSamples& cs) const
00067 {
00068
00069 for(int i = 0; i < df.size(); i++) {
00070 cs[i] = decode(df[i], df.id());
00071 }
00072
00073 }
00074
00075 std::vector<ESSample>
00076 ESElectronicsSim::encode(const CaloSamples& timeframe) const
00077 {
00078 edm::Service<edm::RandomNumberGenerator> rng;
00079 if ( ! rng.isAvailable()) {
00080 throw cms::Exception("Configuration")
00081 << "ESElectroncSim requires the RandomNumberGeneratorService\n"
00082 "which is not present in the configuration file. You must add the service\n"
00083 "in the configuration file or remove the modules that require it.";
00084 }
00085
00086
00087 std::vector<ESSample> results;
00088 results.reserve(timeframe.size());
00089
00090 int adc = 0;
00091 double ADCkeV = MIPADC_/MIPkeV_;
00092
00093 for (int i=0; i<timeframe.size(); i++) {
00094
00095 double noi = 0;
00096 double signal = 0;
00097
00098 if (addNoise_) {
00099 CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0., sigma_);
00100 noi = gaussQDistribution.fire();
00101 }
00102
00103 if (gain_ == 0) {
00104 signal = timeframe[i]*1000000. + noi + baseline_;
00105
00106 if (signal>0)
00107 signal += 0.5;
00108 else if (signal<0)
00109 signal -= 0.5;
00110
00111 adc = int(signal);
00112 }
00113 else if (gain_ == 1 || gain_ == 2) {
00114 signal = timeframe[i]*1000000.*ADCkeV + noi + baseline_;
00115
00116 if (signal>0)
00117 signal += 0.5;
00118 else if (signal<0)
00119 signal -= 0.5;
00120
00121 adc = int(signal);
00122 }
00123
00124 if (adc>MAXADC) adc = MAXADC;
00125 if (adc<MINADC) adc = MINADC;
00126
00127 results.push_back(ESSample(adc));
00128 }
00129
00130 return results;
00131 }
00132
00133 double ESElectronicsSim::decode(const ESSample & sample, const DetId & id) const
00134 {
00135 return 0. ;
00136 }
00137
00138
00139