Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSim.h"
0002 #include "DataFormats/EcalDigi/interface/ESSample.h"
0003 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0004 
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0007 #include "CLHEP/Random/RandGaussQ.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include <iostream>
0010 
0011 ESElectronicsSim::ESElectronicsSim(bool addNoise) : addNoise_(addNoise), peds_(nullptr), mips_(nullptr) {
0012   // Preshower Electronics Simulation
0013   // gain = 1 : low gain for data taking
0014   // gain = 2 : high gain for calibration and low energy runs
0015   // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
0016 }
0017 
0018 ESElectronicsSim::~ESElectronicsSim() {}
0019 
0020 void ESElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, const CaloSamples& cs, ESDataFrame& df) const {
0021   std::vector<ESSample> essamples = encode(cs, engine);
0022 
0023   df.setSize(cs.size());
0024   for (int i = 0; i < df.size(); i++) {
0025     df.setSample(i, essamples[i]);
0026   }
0027 }
0028 
0029 void ESElectronicsSim::digitalToAnalog(const ESDataFrame& df, CaloSamples& cs) const {
0030   for (int i = 0; i < df.size(); i++) {
0031     cs[i] = decode(df[i], df.id());
0032   }
0033 }
0034 
0035 std::vector<ESSample> ESElectronicsSim::encode(const CaloSamples& timeframe, CLHEP::HepRandomEngine* engine) const {
0036   edm::Service<edm::RandomNumberGenerator> rng;
0037   if (!rng.isAvailable()) {
0038     throw cms::Exception("Configuration")
0039         << "ESElectroncSim requires the RandomNumberGeneratorService\n"
0040            "which is not present in the configuration file.  You must add the service\n"
0041            "in the configuration file or remove the modules that require it.";
0042   }
0043 
0044   std::vector<ESSample> results;
0045   results.reserve(timeframe.size());
0046 
0047   ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
0048   ESIntercalibConstantMap::const_iterator it_mip = mips_->getMap().find(timeframe.id());
0049   int baseline_ = (int)it_ped->getMean();
0050   double sigma_ = (double)it_ped->getRms();
0051   double MIPADC_ = (double)(*it_mip);
0052 
0053   int adc = 0;
0054   double ADCGeV = MIPADC_ / MIPToGeV_;
0055 
0056   for (int i = 0; i < timeframe.size(); i++) {
0057     double noi = 0;
0058     double signal = 0;
0059 
0060     if (addNoise_) {
0061       noi = CLHEP::RandGaussQ::shoot(engine, 0., sigma_);
0062     }
0063 
0064     signal = timeframe[i] * ADCGeV + noi + baseline_;
0065 
0066     if (signal > 0)
0067       signal += 0.5;
0068     else if (signal < 0)
0069       signal -= 0.5;
0070 
0071     adc = int(signal);
0072 
0073     if (adc > MAXADC)
0074       adc = MAXADC;
0075     if (adc < MINADC)
0076       adc = MINADC;
0077 
0078     results.emplace_back(adc);
0079   }
0080 
0081   return results;
0082 }
0083 
0084 double ESElectronicsSim::decode(const ESSample& sample, const DetId& id) const { return 0.; }