Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:57

0001 // -*- C++ -*-
0002 //
0003 // Package:   NJetsMC
0004 // Class:     NJetsMC
0005 //
0006 /**\class NJetsMC NJetsMC.cc
0007 
0008  Description: Filter for DPS MC generation.
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  "Nathaniel Odell"
0015 //         Created:  Thu Aug 12 09:24:46 CDT 2010
0016 // then moved to more general N-jets purpose in GeneratorInterface/GenFilters
0017 //
0018 
0019 #include "DataFormats/Common/interface/Handle.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDFilter.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/EDGetToken.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027 
0028 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0029 #include "DataFormats/JetReco/interface/GenJet.h"
0030 
0031 #include <cstdint>
0032 
0033 class NJetsMC : public edm::global::EDFilter<> {
0034 public:
0035   explicit NJetsMC(const edm::ParameterSet&);
0036 
0037 private:
0038   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0039 
0040   // ----------member data ---------------------------
0041 
0042   const edm::EDGetTokenT<reco::GenJetCollection> genToken_;
0043   const int njets_;
0044   const double minpt_;
0045 };
0046 
0047 NJetsMC::NJetsMC(const edm::ParameterSet& iConfig)
0048     : genToken_(consumes<reco::GenJetCollection>(iConfig.getUntrackedParameter<edm::InputTag>("GenTag"))),
0049       njets_(iConfig.getParameter<int32_t>("Njets")),
0050       minpt_(iConfig.getParameter<double>("MinPt")) {}
0051 
0052 bool NJetsMC::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0053   edm::Handle<reco::GenJetCollection> genJets;
0054   iEvent.getByToken(genToken_, genJets);
0055 
0056   int count = 0;
0057   bool result = false;
0058 
0059   for (reco::GenJetCollection::const_iterator iJet = genJets->begin(); iJet != genJets->end(); ++iJet) {
0060     reco::GenJet myJet = reco::GenJet(*iJet);
0061 
0062     if (myJet.pt() > minpt_)
0063       ++count;
0064   }
0065 
0066   if (count >= njets_)
0067     result = true;
0068 
0069   return result;
0070 }
0071 //define this as a plug-in
0072 DEFINE_FWK_MODULE(NJetsMC);