CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/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 ESElectronicsSim::~ESElectronicsSim ()
00021 {}
00022 
00023 void ESElectronicsSim::analogToDigital(const CaloSamples& cs, ESDataFrame& df) const 
00024 {
00025 
00026   std::vector<ESSample> essamples = encode(cs);
00027 
00028   df.setSize(cs.size());
00029   for(int i=0; i<df.size(); i++) {
00030     df.setSample(i, essamples[i]);
00031   }
00032 
00033 }
00034 
00035 void ESElectronicsSim::digitalToAnalog(const ESDataFrame& df, CaloSamples& cs) const 
00036 {
00037 
00038   for(int i = 0; i < df.size(); i++) {
00039     cs[i] = decode(df[i], df.id());
00040   }
00041 
00042 }
00043 
00044 std::vector<ESSample>
00045 ESElectronicsSim::encode(const CaloSamples& timeframe) const
00046 {
00047   edm::Service<edm::RandomNumberGenerator> rng;
00048   if ( ! rng.isAvailable()) {
00049     throw cms::Exception("Configuration")
00050       << "ESElectroncSim requires the RandomNumberGeneratorService\n"
00051       "which is not present in the configuration file.  You must add the service\n"
00052       "in the configuration file or remove the modules that require it.";
00053   }
00054 
00055 
00056   std::vector<ESSample> results;
00057   results.reserve(timeframe.size());
00058 
00059   ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
00060   ESIntercalibConstantMap::const_iterator it_mip = mips_->getMap().find(timeframe.id());
00061   int baseline_  = (int) it_ped->getMean();
00062   double sigma_  = (double) it_ped->getRms();
00063   double MIPADC_ = (double) (*it_mip);
00064 
00065   int adc = 0; 
00066   double ADCGeV = MIPADC_/MIPToGeV_;
00067 
00068   for (int i=0; i<timeframe.size(); i++) {
00069 
00070     double noi = 0;
00071     double signal = 0;    
00072 
00073     if (addNoise_) {
00074       CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0., sigma_);
00075       noi = gaussQDistribution.fire();
00076     }
00077 
00078     signal = timeframe[i]*ADCGeV + noi + baseline_;
00079     
00080     if (signal>0) 
00081       signal += 0.5;
00082     else if (signal<0)
00083       signal -= 0.5;
00084     
00085     adc = int(signal);
00086 
00087     if (adc>MAXADC) adc = MAXADC;
00088     if (adc<MINADC) adc = MINADC;
00089 
00090     results.push_back(ESSample(adc));
00091   }
00092 
00093   return results;
00094 }
00095 
00096 double ESElectronicsSim::decode(const ESSample & sample, const DetId & id) const
00097 {
00098   return 0. ;
00099 }
00100 
00101 
00102