Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:33

0001 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSimFast.h"
0002 #include "DataFormats/DetId/interface/DetId.h"
0003 
0004 #include "CLHEP/Random/RandGaussQ.h"
0005 
0006 #include <iostream>
0007 
0008 ESElectronicsSimFast::ESElectronicsSimFast(bool addNoise, bool PreMix1)
0009     : m_addNoise(addNoise), m_PreMix1(PreMix1), m_MIPToGeV(0), m_peds(nullptr), m_mips(nullptr) {
0010   // Preshower "Fast" Electronics Simulation
0011   // gain = 1 : low gain for data taking
0012   // gain = 2 : high gain for calibration and low energy runs
0013   // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
0014 }
0015 
0016 ESElectronicsSimFast::~ESElectronicsSimFast() {}
0017 
0018 void ESElectronicsSimFast::setPedestals(const ESPedestals* peds) { m_peds = peds; }
0019 
0020 void ESElectronicsSimFast::setMIPs(const ESIntercalibConstants* mips) { m_mips = mips; }
0021 
0022 void ESElectronicsSimFast::setMIPToGeV(double MIPToGeV) { m_MIPToGeV = MIPToGeV; }
0023 
0024 void ESElectronicsSimFast::analogToDigital(CLHEP::HepRandomEngine* engine,
0025                                            ESSamples& cs,
0026                                            ESDataFrame& df,
0027                                            bool isNoise) const {
0028   assert(nullptr != m_peds && nullptr != m_mips && 0 < m_MIPToGeV);  // sanity check
0029 
0030   df.setSize(cs.size());
0031 
0032   const DetId id(cs.id());
0033   ESPedestals::const_iterator it_ped(m_peds->find(id));
0034   ESIntercalibConstantMap::const_iterator it_mip(isNoise ? m_mips->getMap().end() : m_mips->getMap().find(id));
0035 
0036   const double baseline((double)it_ped->getMean());
0037   const double sigma(isNoise ? 0. : (double)it_ped->getRms());
0038   const double MIPADC(isNoise ? 0. : (double)(*it_mip));
0039   const double ADCGeV(isNoise ? 1. : MIPADC / m_MIPToGeV);
0040 
0041   int adc = 0;
0042   //   std::cout<<"   **Id="<<ESDetId(df.id())<<", size="<<df.size();
0043   for (unsigned int i(0); i != cs.size(); ++i) {
0044     const double noi(isNoise || (!m_addNoise) ? 0 : sigma * CLHEP::RandGaussQ::shoot(engine, 0, 1));
0045     double signal;
0046 
0047     if (!m_PreMix1)
0048       signal = cs[i] * ADCGeV + noi + baseline;
0049     else
0050       signal = cs[i] * ADCGeV;
0051 
0052     if (0 <= signal) {
0053       signal += 0.5;
0054     } else {
0055       signal -= 0.5;
0056     }
0057 
0058     adc = int(signal);
0059 
0060     if (!m_PreMix1)
0061       assert(0 < adc);
0062 
0063     if (0.5 < signal - adc)
0064       ++adc;
0065 
0066     if (MAXADC < adc) {
0067       adc = MAXADC;
0068     } else {
0069       if (MINADC > adc)
0070         adc = MINADC;
0071     }
0072 
0073     df.setSample(i, ESSample(adc));
0074     //      std::cout<<", "<<df[i];
0075   }
0076   //   std::cout<<std::endl ;
0077 }