File indexing completed on 2024-12-01 23:40:21
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 "SimDataFormats/GeneratorProducts/interface/HepMC3Product.h"
0009 #include "FWCore/Framework/interface/global/EDProducer.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012
0013 #include <memory>
0014
0015 namespace edm {
0016 class ParameterSet;
0017 class ConfigurationDescriptions;
0018 class Event;
0019 class EventSetup;
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 const edm::EDGetTokenT<edm::HepMC3Product> Token3_;
0033 };
0034
0035 GeneratorSmearedProducer::GeneratorSmearedProducer(edm::ParameterSet const& ps)
0036 : newToken_(consumes<edm::HepMCProduct>(ps.getUntrackedParameter<edm::InputTag>("currentTag"))),
0037 oldToken_(consumes<edm::HepMCProduct>(ps.getUntrackedParameter<edm::InputTag>("previousTag"))),
0038 Token3_(consumes<edm::HepMC3Product>(ps.getUntrackedParameter<edm::InputTag>("currentTag"))) {
0039
0040
0041
0042
0043 produces<edm::HepMCProduct>();
0044 produces<edm::HepMC3Product>();
0045 }
0046
0047 void GeneratorSmearedProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& es) const {
0048 edm::Handle<edm::HepMCProduct> theHepMCProduct;
0049 bool found = iEvent.getByToken(newToken_, theHepMCProduct);
0050 if (!found) {
0051 found = iEvent.getByToken(oldToken_, theHepMCProduct);
0052 }
0053 if (found) {
0054 std::unique_ptr<edm::HepMCProduct> theCopy(new edm::HepMCProduct(*theHepMCProduct));
0055 iEvent.put(std::move(theCopy));
0056 }
0057
0058 edm::Handle<edm::HepMC3Product> theHepMC3Product;
0059 found = iEvent.getByToken(Token3_, theHepMC3Product);
0060 if (found) {
0061 std::unique_ptr<edm::HepMC3Product> theCopy3(new edm::HepMC3Product(*theHepMC3Product));
0062 iEvent.put(std::move(theCopy3));
0063 }
0064 }
0065
0066 void GeneratorSmearedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0067 edm::ParameterSetDescription desc;
0068 desc.addUntracked<edm::InputTag>("currentTag", edm::InputTag("VtxSmeared"));
0069 desc.addUntracked<edm::InputTag>("previousTag", edm::InputTag("generator"));
0070 descriptions.add("generatorSmeared", desc);
0071 }
0072
0073 DEFINE_FWK_MODULE(GeneratorSmearedProducer);