Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "SimCalorimetry/EcalSimAlgos/interface/EcalTimeMapDigitizer.h"
0003 #include "SimCalorimetry/EcalSimProducers/interface/EcalTimeDigiProducer.h"
0004 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
0005 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0006 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0013 
0014 //#define EDM_ML_DEBUG
0015 
0016 EcalTimeDigiProducer::EcalTimeDigiProducer(const edm::ParameterSet &params,
0017                                            edm::ProducesCollector producesCollector,
0018                                            edm::ConsumesCollector &sumes)
0019     : DigiAccumulatorMixMod(),
0020       m_EBdigiCollection(params.getParameter<std::string>("EBtimeDigiCollection")),
0021       m_hitsProducerTagEB(params.getParameter<edm::InputTag>("hitsProducerEB")),
0022       m_hitsProducerTokenEB(sumes.consumes<std::vector<PCaloHit>>(m_hitsProducerTagEB)),
0023       m_geometryToken(sumes.esConsumes()),
0024       m_timeLayerEB(params.getParameter<int>("timeLayerBarrel")),
0025       m_Geometry(nullptr) {
0026   producesCollector.produces<EcalTimeDigiCollection>(m_EBdigiCollection);
0027 
0028   m_BarrelDigitizer = new EcalTimeMapDigitizer(EcalBarrel);
0029 
0030 #ifdef EDM_ML_DEBUG
0031   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::Create EB " << m_EBdigiCollection
0032                                    << "  collection and digitizer";
0033 #endif
0034 
0035   m_BarrelDigitizer->setTimeLayerId(m_timeLayerEB);
0036 }
0037 
0038 EcalTimeDigiProducer::~EcalTimeDigiProducer() {}
0039 
0040 void EcalTimeDigiProducer::initializeEvent(edm::Event const &event, edm::EventSetup const &eventSetup) {
0041   checkGeometry(eventSetup);
0042   //    checkCalibrations( event, eventSetup );
0043   // here the methods to clean the maps
0044   m_BarrelDigitizer->initializeMap();
0045 }
0046 
0047 void EcalTimeDigiProducer::accumulateCaloHits(HitsHandle const &ebHandle, int bunchCrossing) {
0048   // accumulate the simHits and do the averages in a given layer per bunch
0049   // crossing
0050   if (ebHandle.isValid()) {
0051     m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing);
0052   }
0053 }
0054 
0055 void EcalTimeDigiProducer::accumulate(edm::Event const &e, edm::EventSetup const &eventSetup) {
0056   // Step A: Get Inputs
0057   const edm::Handle<std::vector<PCaloHit>> &ebHandle = e.getHandle(m_hitsProducerTokenEB);
0058 
0059 #ifdef EDM_ML_DEBUG
0060   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::Accumulate Hits HS  event";
0061 #endif
0062 
0063   accumulateCaloHits(ebHandle, 0);
0064 }
0065 
0066 void EcalTimeDigiProducer::accumulate(PileUpEventPrincipal const &e,
0067                                       edm::EventSetup const &eventSetup,
0068                                       edm::StreamID const &) {
0069   edm::Handle<std::vector<PCaloHit>> ebHandle;
0070   e.getByLabel(m_hitsProducerTagEB, ebHandle);
0071 
0072 #ifdef EDM_ML_DEBUG
0073   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::Accumulate Hits for BC " << e.bunchCrossing();
0074 #endif
0075   accumulateCaloHits(ebHandle, e.bunchCrossing());
0076 }
0077 
0078 void EcalTimeDigiProducer::finalizeEvent(edm::Event &event, edm::EventSetup const &eventSetup) {
0079   std::unique_ptr<EcalTimeDigiCollection> barrelResult = std::make_unique<EcalTimeDigiCollection>();
0080 
0081 #ifdef EDM_ML_DEBUG
0082   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::finalizeEvent";
0083 #endif
0084 
0085   // here basically just put everything in the final collections
0086   m_BarrelDigitizer->run(*barrelResult);
0087 
0088 #ifdef EDM_ML_DEBUG
0089   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::EB Digi size " << barrelResult->size();
0090 #endif
0091 
0092   edm::LogInfo("TimeDigiInfo") << "EB time Digis: " << barrelResult->size();
0093 
0094 #ifdef EDM_ML_DEBUG
0095   edm::LogVerbatim("TimeDigiInfo") << "[EcalTimeDigiProducer]::putting EcalTimeDigiCollection into the event ";
0096 #endif
0097 
0098   event.put(std::move(barrelResult), m_EBdigiCollection);
0099 }
0100 
0101 void EcalTimeDigiProducer::checkGeometry(const edm::EventSetup &eventSetup) {
0102   if (m_geometryWatcher.check(eventSetup)) {
0103     m_Geometry = &eventSetup.getData(m_geometryToken);
0104     updateGeometry();
0105   }
0106 }
0107 
0108 void EcalTimeDigiProducer::updateGeometry() {
0109   m_BarrelDigitizer->setGeometry(m_Geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel));
0110 }