Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:46

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/FTLDigi/interface/PMTDSimAccumulator.h"
0014 #include "SimFastTiming/FastTimingCommon/interface/MTDDigitizerBase.h"
0015 
0016 #include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
0017 #include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"
0018 
0019 class PreMixingMTDWorker : public PreMixingWorker {
0020 public:
0021   PreMixingMTDWorker(const edm::ParameterSet& ps, edm::ProducesCollector, edm::ConsumesCollector&& iC);
0022   ~PreMixingMTDWorker() override = default;
0023 
0024   PreMixingMTDWorker(const PreMixingMTDWorker&) = delete;
0025   PreMixingMTDWorker& operator=(const PreMixingMTDWorker&) = 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   edm::EDGetTokenT<PMTDSimAccumulator> signalToken_;
0034 
0035   edm::InputTag pileInputTag_;
0036 
0037   std::unique_ptr<MTDDigitizerBase> digitizer_;
0038 };
0039 
0040 PreMixingMTDWorker::PreMixingMTDWorker(const edm::ParameterSet& ps,
0041                                        edm::ProducesCollector producesCollector,
0042                                        edm::ConsumesCollector&& iC)
0043     : signalToken_(iC.consumes<PMTDSimAccumulator>(ps.getParameter<edm::InputTag>("digiTagSig"))),
0044       pileInputTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
0045       digitizer_(MTDDigitizerFactory::get()->create(
0046           ps.getParameter<std::string>("digitizerName"), ps, producesCollector, iC)) {}
0047 
0048 void PreMixingMTDWorker::initializeEvent(const edm::Event& e, const edm::EventSetup& ES) {
0049   digitizer_->initializeEvent(e, ES);
0050 }
0051 
0052 void PreMixingMTDWorker::addSignals(const edm::Event& e, const edm::EventSetup& ES) {
0053   edm::Handle<PMTDSimAccumulator> handle;
0054   e.getByToken(signalToken_, handle);
0055   if (handle.isValid())
0056     digitizer_->accumulate(*handle);
0057   else
0058     edm::LogWarning("MtdMix") << "PreMixingMTDWorker::Cannot find Signal collection";
0059 }
0060 
0061 void PreMixingMTDWorker::addPileups(const PileUpEventPrincipal& pep, const edm::EventSetup& ES) {
0062   edm::Handle<PMTDSimAccumulator> handle;
0063   pep.getByLabel(pileInputTag_, handle);
0064   if (handle.isValid())
0065     digitizer_->accumulate(*handle);
0066   else
0067     edm::LogWarning("MtdMix") << "PreMixingMTDWorker::Cannot find PileUp collection";
0068 }
0069 
0070 void PreMixingMTDWorker::put(edm::Event& e,
0071                              const edm::EventSetup& ES,
0072                              std::vector<PileupSummaryInfo> const& ps,
0073                              int bs) {
0074   edm::Service<edm::RandomNumberGenerator> rng;
0075   digitizer_->finalizeEvent(e, ES, &rng->getEngine(e.streamID()));
0076 }
0077 
0078 DEFINE_PREMIXING_WORKER(PreMixingMTDWorker);