File indexing completed on 2023-03-17 11:04:11
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006
0007 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011
0012 #include <memory>
0013
0014 namespace edm {
0015 class ParameterSet;
0016 class ConfigurationDescriptions;
0017 class Event;
0018 class EventSetup;
0019 class HepMCProduct;
0020 }
0021
0022 class GeneratorSmearedProducer : public edm::global::EDProducer<> {
0023 public:
0024 explicit GeneratorSmearedProducer(edm::ParameterSet const& p);
0025
0026 void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
0027 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028
0029 private:
0030 const edm::EDGetTokenT<edm::HepMCProduct> newToken_;
0031 const edm::EDGetTokenT<edm::HepMCProduct> oldToken_;
0032 };
0033
0034 GeneratorSmearedProducer::GeneratorSmearedProducer(edm::ParameterSet const& ps)
0035 : newToken_(consumes<edm::HepMCProduct>(ps.getUntrackedParameter<edm::InputTag>("currentTag"))),
0036 oldToken_(consumes<edm::HepMCProduct>(ps.getUntrackedParameter<edm::InputTag>("previousTag"))) {
0037
0038
0039 produces<edm::HepMCProduct>();
0040 }
0041
0042 void GeneratorSmearedProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& es) const {
0043 edm::Handle<edm::HepMCProduct> theHepMCProduct;
0044 bool found = iEvent.getByToken(newToken_, theHepMCProduct);
0045 if (!found) {
0046 found = iEvent.getByToken(oldToken_, theHepMCProduct);
0047 }
0048 if (found) {
0049 std::unique_ptr<edm::HepMCProduct> theCopy(new edm::HepMCProduct(*theHepMCProduct));
0050 iEvent.put(std::move(theCopy));
0051 }
0052 }
0053
0054 void GeneratorSmearedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055 edm::ParameterSetDescription desc;
0056 desc.addUntracked<edm::InputTag>("currentTag", edm::InputTag("VtxSmeared"));
0057 desc.addUntracked<edm::InputTag>("previousTag", edm::InputTag("generator"));
0058 descriptions.add("generatorSmeared", desc);
0059 }
0060
0061 DEFINE_FWK_MODULE(GeneratorSmearedProducer);