Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-04 22:27:54

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/Framework/interface/ProducesCollector.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0008 
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0011 
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "DataFormats/HGCalDigi/interface/PHGCSimAccumulator.h"
0014 #include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizer.h"
0015 
0016 #include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
0017 #include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"
0018 
0019 class PreMixingHGCalWorker : public PreMixingWorker {
0020 public:
0021   PreMixingHGCalWorker(const edm::ParameterSet& ps, edm::ProducesCollector, edm::ConsumesCollector&& iC);
0022   ~PreMixingHGCalWorker() override = default;
0023 
0024   PreMixingHGCalWorker(const PreMixingHGCalWorker&) = delete;
0025   PreMixingHGCalWorker& operator=(const PreMixingHGCalWorker&) = delete;
0026 
0027   void initializeEvent(const edm::Event& e, const edm::EventSetup& ES) override;
0028   void addSignals(const edm::Event& e, const edm::EventSetup& ES) override;
0029   void addPileups(const PileUpEventPrincipal&, const edm::EventSetup& ES) override;
0030   void put(edm::Event& e, const edm::EventSetup& ES, std::vector<PileupSummaryInfo> const& ps, int bs) override;
0031 
0032 private:
0033   const edm::EDGetTokenT<PHGCSimAccumulator> signalToken_;
0034   const edm::InputTag pileupInputTag_;
0035 
0036   HGCDigitizer digitizer_;
0037 };
0038 
0039 PreMixingHGCalWorker::PreMixingHGCalWorker(const edm::ParameterSet& ps,
0040                                            edm::ProducesCollector producesCollector,
0041                                            edm::ConsumesCollector&& iC)
0042     : signalToken_(iC.consumes<PHGCSimAccumulator>(ps.getParameter<edm::InputTag>("digiTagSig"))),
0043       pileupInputTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
0044       digitizer_(ps, iC) {
0045   producesCollector.produces<HGCalDigiCollection>(digitizer_.digiCollection());
0046 }
0047 
0048 void PreMixingHGCalWorker::initializeEvent(const edm::Event& e, const edm::EventSetup& ES) {
0049   digitizer_.initializeEvent(e, ES);
0050 }
0051 
0052 void PreMixingHGCalWorker::addSignals(const edm::Event& e, const edm::EventSetup& ES) {
0053   const edm::Handle<PHGCSimAccumulator>& handle = e.getHandle(signalToken_);
0054   digitizer_.accumulate_forPreMix(*handle, false);
0055 }
0056 
0057 void PreMixingHGCalWorker::addPileups(const PileUpEventPrincipal& pep, const edm::EventSetup& ES) {
0058   edm::Handle<PHGCSimAccumulator> handle;
0059   pep.getByLabel(pileupInputTag_, handle);
0060   digitizer_.accumulate_forPreMix(*handle, true);
0061 }
0062 
0063 void PreMixingHGCalWorker::put(edm::Event& e,
0064                                const edm::EventSetup& ES,
0065                                std::vector<PileupSummaryInfo> const& ps,
0066                                int bs) {
0067   edm::Service<edm::RandomNumberGenerator> rng;
0068   digitizer_.finalizeEvent(e, ES, &rng->getEngine(e.streamID()));
0069 }
0070 
0071 DEFINE_PREMIXING_WORKER(PreMixingHGCalWorker);