Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-05 01:48:37

0001 #include <memory>
0002 
0003 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitResponse.h"
0006 #include "SimCalorimetry/EcalSimAlgos/interface/APDSimParameters.h"
0007 #include "SimCalorimetry/EcalSimAlgos/interface/EBHitResponse.h"
0008 #include "SimCalorimetry/EcalSimAlgos/interface/EEHitResponse.h"
0009 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSim.h"
0010 #include "SimCalorimetry/EcalSimAlgos/interface/ESElectronicsSimFast.h"
0011 #include "SimCalorimetry/EcalSimAlgos/interface/ESHitResponse.h"
0012 #include "SimCalorimetry/EcalSimAlgos/interface/EcalCoder.h"
0013 #include "SimCalorimetry/EcalSimAlgos/interface/EcalElectronicsSim.h"
0014 #include "SimCalorimetry/EcalSimAlgos/interface/EcalSimParameterMap.h"
0015 #include "SimCalorimetry/EcalSimProducers/interface/EcalDigiProducer.h"
0016 //#include "SimCalorimetry/EcalSimAlgos/interface/ESFastTDigitizer.h"
0017 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "FWCore/Framework/interface/ConsumesCollector.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/LuminosityBlock.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0028 #include "FWCore/Utilities/interface/StreamID.h"
0029 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0030 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0031 #include "SimCalorimetry/EcalSimAlgos/interface/ESDigitizer.h"
0032 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0033 
0034 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0035 
0036 EcalDigiProducer::EcalDigiProducer(const edm::ParameterSet &params,
0037                                    edm::ProducesCollector producesCollector,
0038                                    edm::ConsumesCollector &iC)
0039     : EcalDigiProducer(params, iC) {
0040   if (m_apdSeparateDigi)
0041     producesCollector.produces<EBDigiCollection>(m_apdDigiTag);
0042 
0043   producesCollector.produces<EBDigiCollection>(m_EBdigiCollection);
0044   producesCollector.produces<EEDigiCollection>(m_EEdigiCollection);
0045   producesCollector.produces<ESDigiCollection>(m_ESdigiCollection);
0046 }
0047 
0048 // version for Pre-Mixing, for use outside of MixingModule
0049 EcalDigiProducer::EcalDigiProducer(const edm::ParameterSet &params, edm::ConsumesCollector &iC)
0050     : DigiAccumulatorMixMod(),
0051       m_APDShape(iC),
0052       m_EBShape(iC),
0053       m_EEShape(iC),
0054       m_ESShape(),
0055       m_EBdigiCollection(params.getParameter<std::string>("EBdigiCollection")),
0056       m_EEdigiCollection(params.getParameter<std::string>("EEdigiCollection")),
0057       m_ESdigiCollection(params.getParameter<std::string>("ESdigiCollection")),
0058       m_hitsProducerTag(params.getParameter<std::string>("hitsProducer")),
0059       m_HitsEBToken_(iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"))),
0060       m_HitsEEToken_(iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEE"))),
0061       m_HitsESToken_(iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsES"))),
0062       m_pedestalsToken(iC.esConsumes()),
0063       m_icalToken(iC.esConsumes()),
0064       m_laserToken(iC.esConsumes()),
0065       m_agcToken(iC.esConsumes()),
0066       m_grToken(iC.esConsumes()),
0067       m_geometryToken(iC.esConsumes()),
0068       m_useLCcorrection(params.getUntrackedParameter<bool>("UseLCcorrection")),
0069       m_apdSeparateDigi(params.getParameter<bool>("apdSeparateDigi")),
0070 
0071       m_EBs25notCont(params.getParameter<double>("EBs25notContainment")),
0072       m_EEs25notCont(params.getParameter<double>("EEs25notContainment")),
0073 
0074       m_readoutFrameSize(ecalPh1::sampleSize),
0075       m_ParameterMap(new EcalSimParameterMap(params.getParameter<double>("simHitToPhotoelectronsBarrel"),
0076                                              params.getParameter<double>("simHitToPhotoelectronsEndcap"),
0077                                              params.getParameter<double>("photoelectronsToAnalogBarrel"),
0078                                              params.getParameter<double>("photoelectronsToAnalogEndcap"),
0079                                              params.getParameter<double>("samplingFactor"),
0080                                              params.getParameter<double>("timePhase"),
0081                                              m_readoutFrameSize,
0082                                              params.getParameter<int>("binOfMaximum"),
0083                                              params.getParameter<bool>("doPhotostatistics"),
0084                                              params.getParameter<bool>("syncPhase"))),
0085 
0086       m_apdDigiTag(params.getParameter<std::string>("apdDigiTag")),
0087       m_apdParameters(new APDSimParameters(params.getParameter<bool>("apdAddToBarrel"),
0088                                            m_apdSeparateDigi,
0089                                            params.getParameter<double>("apdSimToPELow"),
0090                                            params.getParameter<double>("apdSimToPEHigh"),
0091                                            params.getParameter<double>("apdTimeOffset"),
0092                                            params.getParameter<double>("apdTimeOffWidth"),
0093                                            params.getParameter<bool>("apdDoPEStats"),
0094                                            m_apdDigiTag,
0095                                            params.getParameter<std::vector<double>>("apdNonlParms"))),
0096 
0097       m_APDResponse(
0098           !m_apdSeparateDigi
0099               ? nullptr
0100               : new EBHitResponse(m_ParameterMap.get(), &m_EBShape, true, m_apdParameters.get(), &m_APDShape)),
0101 
0102       m_EBResponse(new EBHitResponse(m_ParameterMap.get(),
0103                                      &m_EBShape,
0104                                      false,  // barrel
0105                                      m_apdParameters.get(),
0106                                      &m_APDShape)),
0107 
0108       m_EEResponse(new EEHitResponse(m_ParameterMap.get(), &m_EEShape)),
0109       m_ESResponse(new ESHitResponse(m_ParameterMap.get(), &m_ESShape)),
0110       m_ESOldResponse(new CaloHitResponse(m_ParameterMap.get(), &m_ESShape)),
0111 
0112       m_addESNoise(params.getParameter<bool>("doESNoise")),
0113       m_PreMix1(params.getParameter<bool>("EcalPreMixStage1")),
0114       m_PreMix2(params.getParameter<bool>("EcalPreMixStage2")),
0115 
0116       m_doFastES(params.getParameter<bool>("doFast")),
0117 
0118       m_doEB(params.getParameter<bool>("doEB")),
0119       m_doEE(params.getParameter<bool>("doEE")),
0120       m_doES(params.getParameter<bool>("doES")),
0121 
0122       m_ESElectronicsSim(m_doFastES ? nullptr : new ESElectronicsSim(m_addESNoise)),
0123 
0124       m_ESOldDigitizer(m_doFastES ? nullptr
0125                                   : new ESOldDigitizer(m_ESOldResponse.get(), m_ESElectronicsSim.get(), m_addESNoise)),
0126 
0127       m_ESElectronicsSimFast(!m_doFastES ? nullptr : new ESElectronicsSimFast(m_addESNoise, m_PreMix1)),
0128 
0129       m_ESDigitizer(!m_doFastES ? nullptr
0130                                 : new ESDigitizer(m_ESResponse.get(), m_ESElectronicsSimFast.get(), m_addESNoise)),
0131 
0132       m_APDDigitizer(nullptr),
0133       m_BarrelDigitizer(nullptr),
0134       m_EndcapDigitizer(nullptr),
0135       m_ElectronicsSim(nullptr),
0136       m_Coder(nullptr),
0137       m_APDElectronicsSim(nullptr),
0138       m_APDCoder(nullptr),
0139       m_Geometry(nullptr),
0140       m_EBCorrNoise({{nullptr, nullptr, nullptr}}),
0141       m_EECorrNoise({{nullptr, nullptr, nullptr}}) {
0142   // "produces" statements taken care of elsewhere.
0143   //   if(m_apdSeparateDigi) mixMod.produces<EBDigiCollection>(m_apdDigiTag);
0144   // mixMod.produces<EBDigiCollection>(m_EBdigiCollection);
0145   // mixMod.produces<EEDigiCollection>(m_EEdigiCollection);
0146   // mixMod.produces<ESDigiCollection>(m_ESdigiCollection);
0147   if (m_doEB)
0148     iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
0149   if (m_doEE)
0150     iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEE"));
0151   if (m_doES) {
0152     iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsES"));
0153     m_esGainToken = iC.esConsumes();
0154     m_esMIPToGeVToken = iC.esConsumes();
0155     m_esPedestalsToken = iC.esConsumes();
0156     m_esMIPsToken = iC.esConsumes();
0157   }
0158 
0159   const std::vector<double> ebCorMatG12 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG12");
0160   const std::vector<double> eeCorMatG12 = params.getParameter<std::vector<double>>("EECorrNoiseMatrixG12");
0161   const std::vector<double> ebCorMatG06 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG06");
0162   const std::vector<double> eeCorMatG06 = params.getParameter<std::vector<double>>("EECorrNoiseMatrixG06");
0163   const std::vector<double> ebCorMatG01 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG01");
0164   const std::vector<double> eeCorMatG01 = params.getParameter<std::vector<double>>("EECorrNoiseMatrixG01");
0165 
0166   const bool applyConstantTerm = params.getParameter<bool>("applyConstantTerm");
0167   const double rmsConstantTerm = params.getParameter<double>("ConstantTerm");
0168 
0169   const bool addNoise = params.getParameter<bool>("doENoise");
0170   const bool cosmicsPhase = params.getParameter<bool>("cosmicsPhase");
0171   const double cosmicsShift = params.getParameter<double>("cosmicsShift");
0172 
0173   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0174 
0175   // further phase for cosmics studies
0176   if (cosmicsPhase) {
0177     if (m_doEB)
0178       m_EBResponse->setPhaseShift(1. + cosmicsShift);
0179     if (m_doEE)
0180       m_EEResponse->setPhaseShift(1. + cosmicsShift);
0181   }
0182 
0183   EcalCorrMatrix ebMatrix[3];
0184   EcalCorrMatrix eeMatrix[3];
0185 
0186   assert(ebCorMatG12.size() == m_readoutFrameSize);
0187   assert(eeCorMatG12.size() == m_readoutFrameSize);
0188   assert(ebCorMatG06.size() == m_readoutFrameSize);
0189   assert(eeCorMatG06.size() == m_readoutFrameSize);
0190   assert(ebCorMatG01.size() == m_readoutFrameSize);
0191   assert(eeCorMatG01.size() == m_readoutFrameSize);
0192 
0193   assert(1.e-7 > fabs(ebCorMatG12[0] - 1.0));
0194   assert(1.e-7 > fabs(ebCorMatG06[0] - 1.0));
0195   assert(1.e-7 > fabs(ebCorMatG01[0] - 1.0));
0196   assert(1.e-7 > fabs(eeCorMatG12[0] - 1.0));
0197   assert(1.e-7 > fabs(eeCorMatG06[0] - 1.0));
0198   assert(1.e-7 > fabs(eeCorMatG01[0] - 1.0));
0199 
0200   for (unsigned int row(0); row != m_readoutFrameSize; ++row) {
0201     assert(0 == row || 1. >= ebCorMatG12[row]);
0202     assert(0 == row || 1. >= ebCorMatG06[row]);
0203     assert(0 == row || 1. >= ebCorMatG01[row]);
0204     assert(0 == row || 1. >= eeCorMatG12[row]);
0205     assert(0 == row || 1. >= eeCorMatG06[row]);
0206     assert(0 == row || 1. >= eeCorMatG01[row]);
0207     for (unsigned int column(0); column <= row; ++column) {
0208       const unsigned int index(row - column);
0209       ebMatrix[0](row, column) = ebCorMatG12[index];
0210       eeMatrix[0](row, column) = eeCorMatG12[index];
0211       ebMatrix[1](row, column) = ebCorMatG06[index];
0212       eeMatrix[1](row, column) = eeCorMatG06[index];
0213       ebMatrix[2](row, column) = ebCorMatG01[index];
0214       eeMatrix[2](row, column) = eeCorMatG01[index];
0215     }
0216   }
0217 
0218   m_EBCorrNoise[0] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(ebMatrix[0]);
0219   m_EECorrNoise[0] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(eeMatrix[0]);
0220   m_EBCorrNoise[1] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(ebMatrix[1]);
0221   m_EECorrNoise[1] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(eeMatrix[1]);
0222   m_EBCorrNoise[2] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(ebMatrix[2]);
0223   m_EECorrNoise[2] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix>>(eeMatrix[2]);
0224 
0225   m_Coder = std::make_unique<EcalCoder>(addNoise,
0226                                         m_PreMix1,
0227                                         m_EBCorrNoise[0].get(),
0228                                         m_EECorrNoise[0].get(),
0229                                         m_EBCorrNoise[1].get(),
0230                                         m_EECorrNoise[1].get(),
0231                                         m_EBCorrNoise[2].get(),
0232                                         m_EECorrNoise[2].get());
0233 
0234   m_ElectronicsSim =
0235       std::make_unique<EcalElectronicsSim_Ph1>(m_ParameterMap.get(), m_Coder.get(), applyConstantTerm, rmsConstantTerm);
0236 
0237   if (m_apdSeparateDigi) {
0238     m_APDCoder = std::make_unique<EcalCoder>(false,
0239                                              m_PreMix1,
0240                                              m_EBCorrNoise[0].get(),
0241                                              m_EECorrNoise[0].get(),
0242                                              m_EBCorrNoise[1].get(),
0243                                              m_EECorrNoise[1].get(),
0244                                              m_EBCorrNoise[2].get(),
0245                                              m_EECorrNoise[2].get());
0246 
0247     m_APDElectronicsSim = std::make_unique<EcalElectronicsSim_Ph1>(
0248         m_ParameterMap.get(), m_APDCoder.get(), applyConstantTerm, rmsConstantTerm);
0249 
0250     m_APDDigitizer = std::make_unique<EBDigitizer>(m_APDResponse.get(), m_APDElectronicsSim.get(), false);
0251   }
0252 
0253   if (m_doEB) {
0254     m_BarrelDigitizer = std::make_unique<EBDigitizer>(m_EBResponse.get(), m_ElectronicsSim.get(), addNoise);
0255   }
0256 
0257   if (m_doEE) {
0258     m_EndcapDigitizer = std::make_unique<EEDigitizer>(m_EEResponse.get(), m_ElectronicsSim.get(), addNoise);
0259   }
0260 }
0261 
0262 EcalDigiProducer::~EcalDigiProducer() {}
0263 
0264 void EcalDigiProducer::initializeEvent(edm::Event const &event, edm::EventSetup const &eventSetup) {
0265   edm::Service<edm::RandomNumberGenerator> rng;
0266   randomEngine_ = &rng->getEngine(event.streamID());
0267 
0268   checkGeometry(eventSetup);
0269   checkCalibrations(event, eventSetup);
0270   if (m_doEB) {
0271     m_BarrelDigitizer->initializeHits();
0272     if (m_apdSeparateDigi) {
0273       m_APDDigitizer->initializeHits();
0274     }
0275   }
0276   if (m_doEE) {
0277     m_EndcapDigitizer->initializeHits();
0278   }
0279   if (m_doES) {
0280     if (m_doFastES) {
0281       m_ESDigitizer->initializeHits();
0282     } else {
0283       m_ESOldDigitizer->initializeHits();
0284     }
0285   }
0286 }
0287 
0288 void EcalDigiProducer::accumulateCaloHits(HitsHandle const &ebHandle,
0289                                           HitsHandle const &eeHandle,
0290                                           HitsHandle const &esHandle,
0291                                           int bunchCrossing) {
0292   if (m_doEB && ebHandle.isValid()) {
0293     m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
0294 
0295     if (m_apdSeparateDigi) {
0296       m_APDDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
0297     }
0298   }
0299 
0300   if (m_doEE && eeHandle.isValid()) {
0301     m_EndcapDigitizer->add(*eeHandle.product(), bunchCrossing, randomEngine_);
0302   }
0303 
0304   if (m_doES && esHandle.isValid()) {
0305     if (m_doFastES) {
0306       m_ESDigitizer->add(*esHandle.product(), bunchCrossing, randomEngine_);
0307     } else {
0308       m_ESOldDigitizer->add(*esHandle.product(), bunchCrossing, randomEngine_);
0309     }
0310   }
0311 }
0312 
0313 void EcalDigiProducer::accumulate(edm::Event const &e, edm::EventSetup const &eventSetup) {
0314   // Step A: Get Inputs
0315   const edm::Handle<std::vector<PCaloHit>> &ebHandle = e.getHandle(m_HitsEBToken_);
0316   if (m_doEB) {
0317     m_EBShape.setEventSetup(eventSetup);
0318     m_APDShape.setEventSetup(eventSetup);
0319   }
0320 
0321   const edm::Handle<std::vector<PCaloHit>> &eeHandle = e.getHandle(m_HitsEEToken_);
0322   if (m_doEE) {
0323     m_EEShape.setEventSetup(eventSetup);
0324   }
0325 
0326   const edm::Handle<std::vector<PCaloHit>> &esHandle = e.getHandle(m_HitsESToken_);
0327 
0328   accumulateCaloHits(ebHandle, eeHandle, esHandle, 0);
0329 }
0330 
0331 void EcalDigiProducer::accumulate(PileUpEventPrincipal const &e,
0332                                   edm::EventSetup const &eventSetup,
0333                                   edm::StreamID const &streamID) {
0334   // Step A: Get Inputs
0335   edm::Handle<std::vector<PCaloHit>> ebHandle;
0336   if (m_doEB) {
0337     edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
0338     e.getByLabel(ebTag, ebHandle);
0339   }
0340 
0341   edm::Handle<std::vector<PCaloHit>> eeHandle;
0342   if (m_doEE) {
0343     edm::InputTag eeTag(m_hitsProducerTag, "EcalHitsEE");
0344     e.getByLabel(eeTag, eeHandle);
0345   }
0346 
0347   edm::Handle<std::vector<PCaloHit>> esHandle;
0348   if (m_doES) {
0349     edm::InputTag esTag(m_hitsProducerTag, "EcalHitsES");
0350     e.getByLabel(esTag, esHandle);
0351   }
0352 
0353   accumulateCaloHits(ebHandle, eeHandle, esHandle, e.bunchCrossing());
0354 }
0355 
0356 void EcalDigiProducer::finalizeEvent(edm::Event &event, edm::EventSetup const &eventSetup) {
0357   // Step B: Create empty output
0358   std::unique_ptr<EBDigiCollection> apdResult(!m_apdSeparateDigi || !m_doEB ? nullptr : new EBDigiCollection());
0359   std::unique_ptr<EBDigiCollection> barrelResult(new EBDigiCollection());
0360   std::unique_ptr<EEDigiCollection> endcapResult(new EEDigiCollection());
0361   std::unique_ptr<ESDigiCollection> preshowerResult(new ESDigiCollection());
0362 
0363   // run the algorithm
0364 
0365   if (m_doEB) {
0366     m_BarrelDigitizer->run(*barrelResult, randomEngine_);
0367     cacheEBDigis(&*barrelResult);
0368 
0369     edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size();
0370 
0371     if (m_apdSeparateDigi) {
0372       m_APDDigitizer->run(*apdResult, randomEngine_);
0373       edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size();
0374     }
0375   }
0376 
0377   if (m_doEE) {
0378     m_EndcapDigitizer->run(*endcapResult, randomEngine_);
0379     edm::LogInfo("EcalDigi") << "EE Digis: " << endcapResult->size();
0380     cacheEEDigis(&*endcapResult);
0381   }
0382   if (m_doES) {
0383     if (m_doFastES) {
0384       m_ESDigitizer->run(*preshowerResult, randomEngine_);
0385     } else {
0386       m_ESOldDigitizer->run(*preshowerResult, randomEngine_);
0387     }
0388     edm::LogInfo("EcalDigi") << "ES Digis: " << preshowerResult->size();
0389   }
0390 
0391   // Step D: Put outputs into event
0392   if (m_apdSeparateDigi) {
0393     // event.put(std::move(apdResult),    m_apdDigiTag         ) ;
0394   }
0395 
0396   event.put(std::move(barrelResult), m_EBdigiCollection);
0397   event.put(std::move(endcapResult), m_EEdigiCollection);
0398   event.put(std::move(preshowerResult), m_ESdigiCollection);
0399 
0400   randomEngine_ = nullptr;  // to prevent access outside event
0401 }
0402 
0403 void EcalDigiProducer::beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) {
0404   edm::Service<edm::RandomNumberGenerator> rng;
0405   if (!rng.isAvailable()) {
0406     throw cms::Exception("Configuration") << "RandomNumberGenerator service is not available.\n"
0407                                              "You must add the service in the configuration file\n"
0408                                              "or remove the module that requires it.";
0409   }
0410   CLHEP::HepRandomEngine *engine = &rng->getEngine(lumi.index());
0411 
0412   if (m_doEB) {
0413     if (nullptr != m_APDResponse)
0414       m_APDResponse->initialize(engine);
0415     m_EBResponse->initialize(engine);
0416   }
0417 }
0418 
0419 void EcalDigiProducer::checkCalibrations(const edm::Event &event, const edm::EventSetup &eventSetup) {
0420   // Pedestals from event setup
0421 
0422   const EcalPedestals *pedestals = &eventSetup.getData(m_pedestalsToken);
0423 
0424   m_Coder->setPedestals(pedestals);
0425   if (nullptr != m_APDCoder)
0426     m_APDCoder->setPedestals(pedestals);
0427 
0428   // Ecal Intercalibration Constants
0429   const EcalIntercalibConstantsMC *ical = &eventSetup.getData(m_icalToken);
0430 
0431   m_Coder->setIntercalibConstants(ical);
0432   if (nullptr != m_APDCoder)
0433     m_APDCoder->setIntercalibConstants(ical);
0434 
0435   m_EBResponse->setIntercal(ical);
0436   if (nullptr != m_APDResponse)
0437     m_APDResponse->setIntercal(ical);
0438 
0439   // Ecal LaserCorrection Constants
0440   const EcalLaserDbService *laser = &eventSetup.getData(m_laserToken);
0441   const edm::TimeValue_t eventTimeValue = event.time().value();
0442 
0443   m_EBResponse->setEventTime(eventTimeValue);
0444   m_EBResponse->setLaserConstants(laser, m_useLCcorrection);
0445 
0446   m_EEResponse->setEventTime(eventTimeValue);
0447   m_EEResponse->setLaserConstants(laser, m_useLCcorrection);
0448 
0449   // ADC -> GeV Scale
0450   const EcalADCToGeVConstant *agc = &eventSetup.getData(m_agcToken);
0451 
0452   // Gain Ratios
0453   const EcalGainRatios *gr = &eventSetup.getData(m_grToken);
0454 
0455   m_Coder->setGainRatios(gr);
0456   if (nullptr != m_APDCoder)
0457     m_APDCoder->setGainRatios(gr);
0458 
0459   EcalMGPAGainRatio *defaultRatios = new EcalMGPAGainRatio();
0460 
0461   double theGains[m_Coder->NGAINS + 1];
0462   theGains[0] = 0.;
0463   theGains[3] = 1.;
0464   theGains[2] = defaultRatios->gain6Over1();
0465   theGains[1] = theGains[2] * (defaultRatios->gain12Over6());
0466 
0467   LogDebug("EcalDigi") << " Gains: "
0468                        << "\n"
0469                        << " g1 = " << theGains[1] << "\n"
0470                        << " g2 = " << theGains[2] << "\n"
0471                        << " g3 = " << theGains[3];
0472 
0473   delete defaultRatios;
0474 
0475   const double EBscale((agc->getEBValue()) * theGains[1] * (m_Coder->MAXADC) * m_EBs25notCont);
0476 
0477   LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue() << "\n"
0478                        << " notCont = " << m_EBs25notCont << "\n"
0479                        << " saturation for EB = " << EBscale << ", " << m_EBs25notCont;
0480 
0481   const double EEscale((agc->getEEValue()) * theGains[1] * (m_Coder->MAXADC) * m_EEs25notCont);
0482 
0483   LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEEValue() << "\n"
0484                        << " notCont = " << m_EEs25notCont << "\n"
0485                        << " saturation for EB = " << EEscale << ", " << m_EEs25notCont;
0486 
0487   m_Coder->setFullScaleEnergy(EBscale, EEscale);
0488   if (nullptr != m_APDCoder)
0489     m_APDCoder->setFullScaleEnergy(EBscale, EEscale);
0490 
0491   if (m_doES) {
0492     // ES condition objects
0493     const ESGain *esgain = &eventSetup.getData(m_esGainToken);
0494     const ESPedestals *espeds = &eventSetup.getData(m_esPedestalsToken);
0495     const ESIntercalibConstants *esmips = &eventSetup.getData(m_esMIPsToken);
0496     const ESMIPToGeVConstant *esMipToGeV = &eventSetup.getData(m_esMIPToGeVToken);
0497     const int ESGain(1.1 > esgain->getESGain() ? 1 : 2);
0498     const double ESMIPToGeV((1 == ESGain) ? esMipToGeV->getESValueLow() : esMipToGeV->getESValueHigh());
0499 
0500     m_ESShape.setGain(ESGain);
0501     if (!m_doFastES) {
0502       m_ESElectronicsSim->setGain(ESGain);
0503       m_ESElectronicsSim->setPedestals(espeds);
0504       m_ESElectronicsSim->setMIPs(esmips);
0505       m_ESElectronicsSim->setMIPToGeV(ESMIPToGeV);
0506     } else {
0507       m_ESDigitizer->setGain(ESGain);
0508       m_ESElectronicsSimFast->setPedestals(espeds);
0509       m_ESElectronicsSimFast->setMIPs(esmips);
0510       m_ESElectronicsSimFast->setMIPToGeV(ESMIPToGeV);
0511     }
0512   }
0513 }
0514 
0515 void EcalDigiProducer::checkGeometry(const edm::EventSetup &eventSetup) {
0516   if (m_geometryWatcher.check(eventSetup)) {
0517     m_Geometry = &eventSetup.getData(m_geometryToken);
0518     updateGeometry();
0519   }
0520 }
0521 
0522 void EcalDigiProducer::updateGeometry() {
0523   if (m_doEB) {
0524     if (nullptr != m_APDResponse)
0525       m_APDResponse->setGeometry(m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel));
0526     m_EBResponse->setGeometry(m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel));
0527   }
0528   if (m_doEE) {
0529     m_EEResponse->setGeometry(m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap));
0530   }
0531   if (m_doES) {
0532     m_ESResponse->setGeometry(m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalPreshower));
0533     m_ESOldResponse->setGeometry(m_Geometry);
0534 
0535     const std::vector<DetId> *theESDets(
0536         nullptr != m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalPreshower)
0537             ? &m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalPreshower)->getValidDetIds()
0538             : nullptr);
0539 
0540     if (!m_doFastES) {
0541       if (nullptr != m_ESOldDigitizer && nullptr != theESDets)
0542         m_ESOldDigitizer->setDetIds(*theESDets);
0543     } else {
0544       if (nullptr != m_ESDigitizer && nullptr != theESDets)
0545         m_ESDigitizer->setDetIds(*theESDets);
0546     }
0547   }
0548 }
0549 
0550 void EcalDigiProducer::setEBNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator) {
0551   // noiseGenerator->setParameterMap(theParameterMap);
0552   if (nullptr != m_BarrelDigitizer)
0553     m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
0554 }
0555 
0556 void EcalDigiProducer::setEENoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator) {
0557   // noiseGenerator->setParameterMap(theParameterMap);
0558   if (nullptr != m_EndcapDigitizer)
0559     m_EndcapDigitizer->setNoiseSignalGenerator(noiseGenerator);
0560 }
0561 
0562 void EcalDigiProducer::setESNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator) {
0563   // noiseGenerator->setParameterMap(theParameterMap);
0564   if (nullptr != m_ESDigitizer)
0565     m_ESDigitizer->setNoiseSignalGenerator(noiseGenerator);
0566 }