CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/GeneratorInterface/GenFilters/src/NJetsMC.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:   NJetsMC
00004 // Class:     NJetsMC
00005 // 
00013 //
00014 // Original Author:  "Nathaniel Odell"
00015 //         Created:  Thu Aug 12 09:24:46 CDT 2010
00016 // $Id: NJetsMC.cc,v 1.1 2011/03/23 14:46:46 mucib Exp $
00017 // then moved to more general N-jets purpose in GeneratorInterface/GenFilters
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 
00032 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00033 #include "DataFormats/JetReco/interface/GenJet.h"
00034 
00035 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00036 
00037 #include "TROOT.h"
00038 #include "TH1F.h"
00039 #include "TFile.h"
00040 #include "TSystem.h"
00041 #include <iostream>
00042 
00043 using namespace edm;
00044 using namespace std;
00045 using namespace reco;
00046 
00047 //
00048 // class declaration
00049 //
00050 
00051 class NJetsMC : public edm::EDFilter 
00052 {
00053 public:
00054   explicit NJetsMC(const edm::ParameterSet&);
00055   ~NJetsMC();
00056   
00057 private:
00058   virtual void beginJob() ;
00059   virtual bool filter(edm::Event&, const edm::EventSetup&);
00060   virtual void endJob() ;
00061   
00062   // ----------member data ---------------------------
00063   
00064   edm::InputTag GenHandle_;
00065   Int_t  njets_;
00066   double minpt_;
00067 
00068 };
00069 
00070 NJetsMC::NJetsMC(const edm::ParameterSet& iConfig):
00071   GenHandle_(iConfig.getUntrackedParameter<InputTag>("GenTag")),
00072   njets_(iConfig.getParameter<int32_t>("Njets")),
00073   minpt_(iConfig.getParameter<double>("MinPt"))
00074 {
00075 }
00076 
00077 
00078 NJetsMC::~NJetsMC()
00079 {
00080 }
00081 
00082 bool NJetsMC::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00083 {
00084    using namespace edm;
00085    
00086    Handle<reco::GenJetCollection> GenJets;
00087    iEvent.getByLabel(GenHandle_, GenJets);
00088 
00089    Int_t count = 0;
00090    bool result = false;
00091 
00092    for(GenJetCollection::const_iterator iJet = GenJets->begin(); iJet != GenJets->end(); ++iJet)
00093      {
00094        reco::GenJet myJet = reco::GenJet(*iJet);
00095 
00096        if(myJet.pt() > minpt_) ++count;
00097      }
00098 
00099    if( count >= njets_ )
00100       result = true;
00101 
00102    return result;
00103 }
00104 
00105 void NJetsMC::beginJob()
00106 {
00107 }
00108 
00109 void NJetsMC::endJob()
00110 {
00111 }
00112 
00113 //define this as a plug-in
00114 DEFINE_FWK_MODULE(NJetsMC);