CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimCalorimetry/EcalSimAlgos/src/ESElectronicsSimFast.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSimFast.h"
00002 #include "DataFormats/DetId/interface/DetId.h"
00003 
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00006 #include "CLHEP/Random/RandGaussQ.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 
00009 #include <iostream>
00010 
00011 ESElectronicsSimFast::ESElectronicsSimFast( bool addNoise ) :
00012    m_addNoise ( addNoise ) ,
00013    m_MIPToGeV (        0 ) ,
00014    m_peds     (        0 ) ,
00015    m_mips     (        0 ) ,
00016    m_ranGau   (        0 )
00017 {
00018    // Preshower "Fast" Electronics Simulation
00019    // gain = 1 : low gain for data taking 
00020    // gain = 2 : high gain for calibration and low energy runs
00021    // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
00022 
00023    if( m_addNoise )
00024    {
00025       edm::Service<edm::RandomNumberGenerator> rng;
00026       if( !rng.isAvailable() ) 
00027       {
00028          throw cms::Exception("Configuration")
00029             << "ESElectroncSimFast requires the RandomNumberGeneratorService\n"
00030             "which is not present in the configuration file.  You must add the service\n"
00031             "in the configuration file or remove the modules that require it.";
00032       }
00033       m_ranGau = new CLHEP::RandGaussQ( rng->getEngine(), 0, 1 ) ;
00034    }
00035 }
00036 
00037 ESElectronicsSimFast::~ESElectronicsSimFast()
00038 {
00039    delete m_ranGau ;
00040 }
00041 
00042 void 
00043 ESElectronicsSimFast::setPedestals( const ESPedestals* peds ) 
00044 {
00045    m_peds = peds ;
00046 } 
00047 
00048 void 
00049 ESElectronicsSimFast::setMIPs( const ESIntercalibConstants* mips ) 
00050 {
00051    m_mips = mips ;
00052 }
00053 
00054 void 
00055 ESElectronicsSimFast::setMIPToGeV( double MIPToGeV )
00056 {
00057    m_MIPToGeV = MIPToGeV ;
00058 }
00059 
00060 void 
00061 ESElectronicsSimFast::analogToDigital( ESSamples&   cs, 
00062                                        ESDataFrame& df, 
00063                                        bool         isNoise ) const
00064 {
00065    assert( 0 != m_peds &&
00066            0 != m_mips &&
00067            0 < m_MIPToGeV ) ; // sanity check
00068 
00069    assert( ( !m_addNoise ) ||
00070            0 != m_ranGau ) ; // sanity check
00071 
00072    df.setSize( cs.size() ) ;
00073 
00074    const DetId id ( cs.id() ) ;
00075    ESPedestals::const_iterator it_ped ( m_peds->find( id ) ) ;
00076    ESIntercalibConstantMap::const_iterator it_mip (
00077       isNoise ? m_mips->getMap().end() : m_mips->getMap().find( id ) ) ;
00078 
00079    const double baseline ( (double) it_ped->getMean() ) ;
00080    const double sigma    ( isNoise ? 0. : (double) it_ped->getRms() ) ;
00081    const double MIPADC   ( isNoise ? 0. : (double) (*it_mip) ) ;
00082    const double ADCGeV   ( isNoise ? 1. : MIPADC/m_MIPToGeV ) ;
00083 
00084    int adc = 0 ;
00085 //   std::cout<<"   **Id="<<ESDetId(df.id())<<", size="<<df.size();
00086    for( unsigned int i ( 0 ) ; i != cs.size(); ++i ) 
00087    {
00088       const double noi ( isNoise || (!m_addNoise) ? 0 :
00089                          sigma*m_ranGau->fire() ) ;
00090     
00091       double signal = cs[i]*ADCGeV + noi + baseline ;
00092 
00093       if( 0 <= signal )
00094       { 
00095          signal += 0.5 ;
00096       }
00097       else
00098       {
00099          signal -= 0.5 ;
00100       }
00101     
00102       adc = int( signal ) ;
00103       assert( 0 < adc ) ;
00104 
00105       if( 0.5 < signal - adc ) ++adc ;
00106 
00107       if( MAXADC < adc )
00108       {
00109          adc = MAXADC ;
00110       }
00111       else
00112       {
00113          if( MINADC > adc ) adc = MINADC ;
00114       }
00115 
00116       df.setSample( i, ESSample( adc ) ) ;
00117 //      std::cout<<", "<<df[i];
00118    }
00119 //   std::cout<<std::endl ;
00120 }