CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/SimCalorimetry/EcalSimAlgos/src/ESElectronicsSim.cc

Go to the documentation of this file.
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 #include <iostream>
00010 
00011 ESElectronicsSim::ESElectronicsSim (bool addNoise):
00012   addNoise_(addNoise), peds_(0), mips_(0)
00013 {
00014   // Preshower Electronics Simulation
00015   // gain = 1 : low gain for data taking 
00016   // gain = 2 : high gain for calibration and low energy runs
00017   // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
00018 }
00019 
00020 void ESElectronicsSim::analogToDigital(const CaloSamples& cs, ESDataFrame& df) const 
00021 {
00022 
00023   std::vector<ESSample> essamples = encode(cs);
00024 
00025   df.setSize(cs.size());
00026   for(int i=0; i<df.size(); i++) {
00027     df.setSample(i, essamples[i]);
00028   }
00029 
00030 }
00031 
00032 void ESElectronicsSim::digitalToAnalog(const ESDataFrame& df, CaloSamples& cs) const 
00033 {
00034 
00035   for(int i = 0; i < df.size(); i++) {
00036     cs[i] = decode(df[i], df.id());
00037   }
00038 
00039 }
00040 
00041 std::vector<ESSample>
00042 ESElectronicsSim::encode(const CaloSamples& timeframe) const
00043 {
00044   edm::Service<edm::RandomNumberGenerator> rng;
00045   if ( ! rng.isAvailable()) {
00046     throw cms::Exception("Configuration")
00047       << "ESElectroncSim requires the RandomNumberGeneratorService\n"
00048       "which is not present in the configuration file.  You must add the service\n"
00049       "in the configuration file or remove the modules that require it.";
00050   }
00051 
00052 
00053   std::vector<ESSample> results;
00054   results.reserve(timeframe.size());
00055 
00056   ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
00057   ESIntercalibConstantMap::const_iterator it_mip = mips_->getMap().find(timeframe.id());
00058   int baseline_  = (int) it_ped->getMean();
00059   double sigma_  = (double) it_ped->getRms();
00060   double MIPADC_ = (double) (*it_mip);
00061 
00062   int adc = 0; 
00063   double ADCGeV = MIPADC_/MIPToGeV_;
00064 
00065   for (int i=0; i<timeframe.size(); i++) {
00066 
00067     double noi = 0;
00068     double signal = 0;    
00069 
00070     if (addNoise_) {
00071       CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0., sigma_);
00072       noi = gaussQDistribution.fire();
00073     }
00074 
00075     signal = timeframe[i]*ADCGeV + noi + baseline_;
00076     
00077     if (signal>0) 
00078       signal += 0.5;
00079     else if (signal<0)
00080       signal -= 0.5;
00081     
00082     adc = int(signal);
00083 
00084     if (adc>MAXADC) adc = MAXADC;
00085     if (adc<MINADC) adc = MINADC;
00086 
00087     results.push_back(ESSample(adc));
00088   }
00089 
00090   return results;
00091 }
00092 
00093 double ESElectronicsSim::decode(const ESSample & sample, const DetId & id) const
00094 {
00095   return 0. ;
00096 }
00097 
00098 
00099