CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/EcalSimAlgos/src/ESElectronicsSimFast.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSimFast.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/RandFlat.h"
00008 #include "CLHEP/Random/RandGaussQ.h"
00009 #include "CLHEP/Random/RandGeneral.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include <iostream>
00012 
00013 ESElectronicsSimFast::ESElectronicsSimFast (bool addNoise) :
00014   addNoise_(addNoise), peds_(0), mips_(0)
00015 {
00016   // Preshower "Fast" Electronics Simulation
00017   // gain = 1 : low gain for data taking 
00018   // gain = 2 : high gain for calibration and low energy runs
00019   // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
00020 }
00021 
00022 void ESElectronicsSimFast::analogToDigital(const CaloSamples& cs, ESDataFrame& df, bool wasEmpty, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const 
00023 {
00024   std::vector<ESSample> essamples;
00025   if (!wasEmpty) essamples = standEncode(cs);
00026   if ( wasEmpty) essamples = fastEncode(cs, histoDistribution, hInf, hSup, hBin);
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 void ESElectronicsSimFast::digitalToAnalog(const ESDataFrame& df, CaloSamples& cs) const 
00035 {
00036   for(int i = 0; i < df.size(); i++) {
00037     cs[i] = decode(df[i], df.id());
00038   } 
00039 }
00040 
00041 std::vector<ESSample>
00042 ESElectronicsSimFast::standEncode(const CaloSamples& timeframe) const
00043 {
00044   edm::Service<edm::RandomNumberGenerator> rng;
00045   if ( ! rng.isAvailable()) {
00046     throw cms::Exception("Configuration")
00047       << "ESElectroncSimFast 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   std::vector<ESSample> results;
00053   results.reserve(timeframe.size());
00054   
00055   ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
00056   ESIntercalibConstantMap::const_iterator it_mip = mips_->getMap().find(timeframe.id());
00057   int baseline_  = (int) it_ped->getMean();
00058   double sigma_  = (double) it_ped->getRms();
00059   double MIPADC_ = (double) (*it_mip);
00060 
00061   int adc = 0; 
00062   double ADCGeV = MIPADC_/MIPToGeV_;
00063   for (int i=0; i<timeframe.size(); i++) {
00064     
00065     double noi = 0;
00066     double signal = 0;    
00067     
00068     if (addNoise_) {
00069       CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0, sigma_);
00070       noi = gaussQDistribution.fire();
00071     }
00072     
00073     signal = timeframe[i]*ADCGeV + noi + baseline_;
00074     
00075     if (signal>0) 
00076       signal += 0.5;
00077     else if (signal<0)
00078       signal -= 0.5;
00079     
00080     adc = int(signal);
00081 
00082     if (adc>MAXADC) adc = MAXADC;
00083     if (adc<MINADC) adc = MINADC;
00084 
00085     results.push_back(ESSample(adc));
00086   }
00087   
00088   return results;
00089 }
00090 
00091 
00092 std::vector<ESSample>
00093 ESElectronicsSimFast::fastEncode(const CaloSamples& timeframe, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
00094 {
00095   std::vector<ESSample> results;
00096   results.reserve(timeframe.size());
00097 
00098   int bin[3]; 
00099   double hBin2 = hBin*hBin;
00100   double hBin3 = hBin*hBin*hBin;
00101   double width = (hSup - hInf)/hBin;  
00102 
00103   double thisRnd  = histoDistribution->fire();  
00104   int thisRndCell = (int)((hBin3)*(thisRnd)/width);  
00105   bin[2] = (int)(thisRndCell/hBin2);                              // sample2 - bin [0,N-1]
00106   bin[1] = (int)((thisRndCell - hBin2*bin[2])/hBin);              // sample1
00107   bin[0] = (int)(thisRndCell - hBin*(bin[1] + hBin*bin[2]));      // sample0
00108 
00109   ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
00110   int baseline_  = (int) it_ped->getMean();
00111 
00112   int adc[3];
00113   double noi[3];
00114   for(int ii=0; ii<3; ii++){
00115 
00116     noi[ii] = hInf + bin[ii]*width; 
00117     if (noi[ii]>0)      noi[ii] += 0.5;
00118     else if (noi[ii]<0) noi[ii] -= 0.5;
00119     
00120     adc[ii] = int(noi[ii]) - 1000 + baseline_;      
00121 
00122     if (adc[ii]>MAXADC) adc[ii] = MAXADC;
00123     if (adc[ii]<MINADC) adc[ii] = MINADC;
00124     
00125     results.push_back(ESSample(adc[ii]));
00126   }
00127   
00128   return results;
00129 }
00130 
00131 double ESElectronicsSimFast::decode(const ESSample & sample, const DetId & id) const
00132 {
00133   return 0. ;
00134 }
00135 
00136 
00137