File indexing completed on 2024-04-06 12:30:40
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventPrincipal.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/Framework/interface/ProducesCollector.h"
0006 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0007
0008 #include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
0009 #include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"
0010
0011 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
0012 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
0013
0014 namespace edm {
0015 template <typename T>
0016 class PreMixingCrossingFrameWorker : public PreMixingWorker {
0017 public:
0018 PreMixingCrossingFrameWorker(const edm::ParameterSet& ps, edm::ProducesCollector, edm::ConsumesCollector&& iC);
0019 ~PreMixingCrossingFrameWorker() override = default;
0020
0021 void initializeEvent(edm::Event const& iEvent, edm::EventSetup const& iSetup) override {}
0022 void addSignals(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0023 void addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& iSetup) override;
0024 void put(edm::Event& iEvent,
0025 edm::EventSetup const& iSetup,
0026 std::vector<PileupSummaryInfo> const& ps,
0027 int bunchSpacing) override;
0028
0029 private:
0030 edm::EDGetTokenT<CrossingFrame<T> > signalToken_;
0031 edm::InputTag pileupTag_;
0032 std::string collectionDM_;
0033
0034 std::unique_ptr<PCrossingFrame<T> > merged_;
0035 };
0036
0037 template <typename T>
0038 PreMixingCrossingFrameWorker<T>::PreMixingCrossingFrameWorker(const edm::ParameterSet& ps,
0039 edm::ProducesCollector producesCollector,
0040 edm::ConsumesCollector&& iC)
0041 : signalToken_(iC.consumes<CrossingFrame<T> >(ps.getParameter<edm::InputTag>("labelSig"))),
0042 pileupTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
0043 collectionDM_(ps.getParameter<std::string>("collectionDM")) {
0044 producesCollector.produces<PCrossingFrame<T> >(
0045 collectionDM_);
0046 producesCollector.produces<CrossingFrame<T> >(collectionDM_);
0047 }
0048
0049 template <typename T>
0050 void PreMixingCrossingFrameWorker<T>::addSignals(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0051 edm::Handle<CrossingFrame<T> > hcf;
0052 iEvent.getByToken(signalToken_, hcf);
0053
0054 const auto& cf = *hcf;
0055 if (!cf.getPileups().empty()) {
0056 throw cms::Exception("LogicError") << "Got CrossingFrame from signal with pileup content?";
0057 }
0058
0059 merged_ = std::make_unique<PCrossingFrame<T> >(cf);
0060 }
0061
0062 template <typename T>
0063 void PreMixingCrossingFrameWorker<T>::addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& iSetup) {
0064 edm::Handle<PCrossingFrame<T> > hcf;
0065 pep.getByLabel(pileupTag_, hcf);
0066
0067 const auto& cf = *hcf;
0068 if (!cf.getSignals().empty()) {
0069 throw cms::Exception("LogicError") << "Got PCrossingFrame from pileup with signal content?";
0070 }
0071
0072 merged_->setAllExceptSignalFrom(cf);
0073 }
0074
0075 template <typename T>
0076 void PreMixingCrossingFrameWorker<T>::put(edm::Event& iEvent,
0077 edm::EventSetup const& iSetup,
0078 std::vector<PileupSummaryInfo> const& ps,
0079 int bunchSpacing) {
0080 auto orphanHandle = iEvent.put(std::move(merged_), collectionDM_);
0081 const auto& pcf = *orphanHandle;
0082
0083 const auto bx = pcf.getBunchRange();
0084 auto cf = std::make_unique<CrossingFrame<T> >(
0085 bx.first, bx.second, pcf.getBunchSpace(), pcf.getSubDet(), pcf.getMaxNbSources());
0086 cf->addSignals(&(pcf.getSignals()), pcf.getEventID());
0087 cf->setPileups(pcf.getPileups());
0088 iEvent.put(std::move(cf), collectionDM_);
0089 }
0090 }
0091
0092 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0093 using PreMixingCrossingFramePSimHitWorker = edm::PreMixingCrossingFrameWorker<PSimHit>;
0094
0095 DEFINE_PREMIXING_WORKER(PreMixingCrossingFramePSimHitWorker);