File indexing completed on 2024-04-06 12:30:40
0001 #ifndef SimGeneral_PreMixingModule_PreMixingMuonWorker_h
0002 #define SimGeneral_PreMixingModule_PreMixingMuonWorker_h
0003
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/Framework/interface/ProducesCollector.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0010
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
0013
0014 template <typename DigiCollection>
0015 class PreMixingMuonWorker : public PreMixingWorker {
0016 public:
0017 PreMixingMuonWorker(const edm::ParameterSet& ps,
0018 edm::ProducesCollector producesCollector,
0019 edm::ConsumesCollector&& iC)
0020 : PreMixingMuonWorker(ps, producesCollector, iC) {}
0021 PreMixingMuonWorker(const edm::ParameterSet& ps, edm::ProducesCollector, edm::ConsumesCollector& iC);
0022 ~PreMixingMuonWorker() override = default;
0023
0024 void initializeEvent(edm::Event const& iEvent, edm::EventSetup const& iSetup) override {}
0025 void addSignals(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0026 void addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& iSetup) override;
0027 void put(edm::Event& iEvent,
0028 edm::EventSetup const& iSetup,
0029 std::vector<PileupSummaryInfo> const& ps,
0030 int bunchSpacing) override {
0031 put(iEvent);
0032 }
0033
0034 void put(edm::Event& iEvent);
0035
0036 private:
0037 edm::EDGetTokenT<DigiCollection> signalToken_;
0038 edm::InputTag pileupTag_;
0039 std::string collectionDM_;
0040
0041 std::unique_ptr<DigiCollection> accumulated_;
0042 };
0043
0044 template <typename DigiCollection>
0045 PreMixingMuonWorker<DigiCollection>::PreMixingMuonWorker(const edm::ParameterSet& ps,
0046 edm::ProducesCollector producesCollector,
0047 edm::ConsumesCollector& iC)
0048 : signalToken_(iC.consumes<DigiCollection>(ps.getParameter<edm::InputTag>("digiTagSig"))),
0049 pileupTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
0050 collectionDM_(ps.getParameter<std::string>("collectionDM")) {
0051 producesCollector.produces<DigiCollection>(collectionDM_);
0052 }
0053
0054 template <typename DigiCollection>
0055 void PreMixingMuonWorker<DigiCollection>::addSignals(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0056 edm::Handle<DigiCollection> digis;
0057 iEvent.getByToken(signalToken_, digis);
0058
0059 accumulated_ = std::make_unique<DigiCollection>(*digis);
0060 }
0061
0062 template <typename DigiCollection>
0063 void PreMixingMuonWorker<DigiCollection>::addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& iSetup) {
0064 edm::Handle<DigiCollection> digis;
0065 pep.getByLabel(pileupTag_, digis);
0066 for (const auto& elem : *digis) {
0067 accumulated_->put(elem.second, elem.first);
0068 }
0069 }
0070
0071 template <typename DigiCollection>
0072 void PreMixingMuonWorker<DigiCollection>::put(edm::Event& iEvent) {
0073 iEvent.put(std::move(accumulated_), collectionDM_);
0074 }
0075
0076 #endif