File indexing completed on 2024-06-22 02:24:03
0001 #include "FWCore/Framework/interface/one/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0007
0008 #include "HepMC/GenEvent.h"
0009
0010 class HepMCCopy : public edm::one::EDProducer<> {
0011 public:
0012 explicit HepMCCopy(edm::ParameterSet const& p);
0013 ~HepMCCopy() override = default;
0014 void produce(edm::Event& e, const edm::EventSetup& c) override;
0015 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0016
0017 private:
0018 const edm::EDGetTokenT<edm::HepMCProduct> hepMCToken_;
0019 };
0020
0021 void HepMCCopy::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0022 edm::ParameterSetDescription desc;
0023 desc.add<edm::InputTag>("src", {"generatorSmeared"});
0024 descriptions.addWithDefaultLabel(desc);
0025 }
0026
0027 HepMCCopy::HepMCCopy(edm::ParameterSet const& p)
0028 : hepMCToken_(consumes<edm::HepMCProduct>(p.getParameter<edm::InputTag>("src"))) {
0029
0030 produces<edm::HepMCProduct>();
0031 }
0032
0033 void HepMCCopy::produce(edm::Event& iEvent, const edm::EventSetup& es) {
0034 const auto& theHepMCProduct = iEvent.getHandle(hepMCToken_);
0035 if (theHepMCProduct.isValid()) {
0036 auto pu_product = std::make_unique<edm::HepMCProduct>();
0037 iEvent.put(std::move(pu_product));
0038 } else {
0039 auto pu_product = std::make_unique<edm::HepMCProduct>(*theHepMCProduct);
0040 iEvent.put(std::move(pu_product));
0041 }
0042 }
0043
0044 #include "FWCore/Framework/interface/MakerMacros.h"
0045 DEFINE_FWK_MODULE(HepMCCopy);