Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:44

0001 #include <memory>
0002 #include <vector>
0003 
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 
0013 #include "DataFormats/Common/interface/View.h"
0014 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0015 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0016 
0017 class HiSignalGenJetProducer : public edm::global::EDProducer<> {
0018 public:
0019   explicit HiSignalGenJetProducer(const edm::ParameterSet&);
0020   ~HiSignalGenJetProducer() override = default;
0021 
0022   static void fillDescriptions(edm::ConfigurationDescriptions&);
0023 
0024 private:
0025   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0026 
0027   edm::EDGetTokenT<edm::View<reco::GenJet> > jetSrc_;
0028 };
0029 
0030 HiSignalGenJetProducer::HiSignalGenJetProducer(const edm::ParameterSet& iConfig)
0031     : jetSrc_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))) {
0032   std::string alias = (iConfig.getParameter<edm::InputTag>("src")).label();
0033   produces<reco::GenJetCollection>().setBranchAlias(alias);
0034 }
0035 
0036 void HiSignalGenJetProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0037   auto jets = std::make_unique<reco::GenJetCollection>();
0038 
0039   edm::Handle<edm::View<reco::GenJet> > genjets;
0040   iEvent.getByToken(jetSrc_, genjets);
0041 
0042   for (const reco::GenJet& jet1 : *genjets) {
0043     const reco::GenParticle* gencon = jet1.getGenConstituent(0);
0044 
0045     if (gencon == nullptr)
0046       throw cms::Exception("GenConstituent", "GenJet is missing its constituents");
0047     else if (gencon->collisionId() == 0) {
0048       jets->push_back(jet1);
0049     }
0050   }
0051 
0052   iEvent.put(std::move(jets));
0053 }
0054 
0055 void HiSignalGenJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0056   edm::ParameterSetDescription desc;
0057   desc.setComment("Selects genJets from collision id = 0");
0058   desc.add<edm::InputTag>("src", edm::InputTag("akHiGenJets"));
0059   descriptions.addWithDefaultLabel(desc);
0060 }
0061 
0062 DEFINE_FWK_MODULE(HiSignalGenJetProducer);