Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef EcalSimAlgos_EcalTDigitizer_icc
0002 #define EcalSimAlgos_EcalTDigitizer_icc
0003 
0004 #include "SimCalorimetry/EcalSimAlgos/interface/EcalTDigitizer.h"
0005 #include "SimCalorimetry/EcalSimAlgos/interface/EcalHitResponse.h"
0006 #include "SimCalorimetry/EcalSimAlgos/interface/EcalBaseSignalGenerator.h"
0007 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
0008 
0009 template <class Traits>
0010 EcalTDigitizer<Traits>::EcalTDigitizer(EcalHitResponse* hitResponse, ElectronicsSim* electronicsSim, bool addNoise)
0011     : m_hitResponse(hitResponse),
0012       m_electronicsSim(electronicsSim),
0013       m_addNoise(addNoise),
0014       theNoiseSignalGenerator(nullptr) {}
0015 
0016 template <class Traits>
0017 EcalTDigitizer<Traits>::~EcalTDigitizer() {}
0018 
0019 template <class Traits>
0020 void EcalTDigitizer<Traits>::add(const std::vector<PCaloHit>& hits, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
0021   if (m_hitResponse->withinBunchRange(bunchCrossing)) {
0022     for (std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
0023       m_hitResponse->add(*it, engine);
0024     }
0025   }
0026 }
0027 
0028 template <class Traits>
0029 void EcalTDigitizer<Traits>::initializeHits() {
0030   m_hitResponse->initializeHits();
0031 }
0032 
0033 template <class Traits>
0034 void EcalTDigitizer<Traits>::setNoiseSignalGenerator(EcalBaseSignalGenerator* noiseSignalGenerator) {
0035   theNoiseSignalGenerator = noiseSignalGenerator;
0036 }
0037 
0038 template <class Traits>
0039 void EcalTDigitizer<Traits>::run(DigiCollection& output, CLHEP::HepRandomEngine* engine) {
0040   m_hitResponse->finalizeHits();
0041 
0042   if (theNoiseSignalGenerator != nullptr) {
0043     addNoiseSignals();
0044   }
0045 
0046   m_electronicsSim->newEvent();
0047 
0048   const unsigned int ssize(m_hitResponse->samplesSize());
0049   output.reserve(ssize);
0050 
0051   for (unsigned int i(0); i != ssize; ++i) {
0052     EcalSamples& analogSignal(*static_cast<EcalSamples*>((*m_hitResponse)[i]));
0053     if (m_addNoise ||  // digitize if real or adding noise
0054         !analogSignal.zero()) {
0055       output.push_back(analogSignal.id().rawId());
0056       Digi digi(output.back());  // why does this work without &
0057       m_electronicsSim->analogToDigital(engine, analogSignal, digi);
0058       Traits::fix(digi, output.back());
0059     }
0060   }
0061 }
0062 
0063 template <class Traits>
0064 void EcalTDigitizer<Traits>::addNoiseSignals() {
0065   std::vector<CaloSamples> noiseSignals;
0066   // noise signals need to be in units of photoelectrons.  Fractional is OK
0067   theNoiseSignalGenerator->fillEvent();
0068   theNoiseSignalGenerator->getNoiseSignals(noiseSignals);
0069   for (typename std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
0070                                                          signalEnd = noiseSignals.end();
0071        signalItr != signalEnd;
0072        ++signalItr) {
0073     m_hitResponse->add(*signalItr);
0074   }
0075 }
0076 
0077 template <class Traits>
0078 bool EcalTDigitizer<Traits>::addNoise() const {
0079   return m_addNoise;
0080 }
0081 
0082 template <class Traits>
0083 const EcalHitResponse* EcalTDigitizer<Traits>::hitResponse() const {
0084   return m_hitResponse;
0085 }
0086 
0087 template <class Traits>
0088 const typename Traits::ElectronicsSim* EcalTDigitizer<Traits>::elecSim() const {
0089   return m_electronicsSim;
0090 }
0091 
0092 #endif