Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-07 22:41:51

0001 // -*- C++ -*-
0002 //
0003 // Package:    Utilities
0004 // Class:      SimpleJetFilter
0005 //
0006 /**\class SimpleJetFilter SimpleJetFilter.cc DPGAnalysis/Skims/src/SimpleJetFilter.cc
0007 
0008  Description: 
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Tue Oct 21 20:55:22 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 #include "FWCore/Framework/interface/ESHandle.h"
0030 #include "FWCore/Framework/interface/ESWatcher.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 
0034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0035 
0036 #include "FWCore/Utilities/interface/InputTag.h"
0037 
0038 #include "DataFormats/JetReco/interface/JetID.h"
0039 #include "DataFormats/JetReco/interface/CaloJet.h"
0040 
0041 #include "PhysicsTools/SelectorUtils/interface/JetIDSelectionFunctor.h"
0042 #include "PhysicsTools/SelectorUtils/interface/strbitset.h"
0043 
0044 //
0045 // class declaration
0046 //
0047 
0048 class SimpleJetFilter : public edm::stream::EDFilter<> {
0049 public:
0050   explicit SimpleJetFilter(const edm::ParameterSet&);
0051   ~SimpleJetFilter() override;
0052 
0053 private:
0054   bool filter(edm::Event&, const edm::EventSetup&) override;
0055 
0056   // ----------member data ---------------------------
0057 
0058   edm::InputTag m_jetCollection;
0059   edm::InputTag m_jetIDMap;
0060   const double m_ptcut;
0061   const double m_etamaxcut;
0062   const double m_njetmin;
0063   JetIDSelectionFunctor m_jetIDfunc;
0064 };
0065 
0066 //
0067 // constructors and destructor
0068 //
0069 SimpleJetFilter::SimpleJetFilter(const edm::ParameterSet& iConfig)
0070     : m_jetCollection(iConfig.getParameter<edm::InputTag>("jetCollection")),
0071       m_jetIDMap(iConfig.getParameter<edm::InputTag>("jetIDMap")),
0072       m_ptcut(iConfig.getParameter<double>("ptCut")),
0073       m_etamaxcut(iConfig.getParameter<double>("maxRapidityCut")),
0074       m_njetmin(iConfig.getParameter<unsigned int>("nJetMin")),
0075       m_jetIDfunc(JetIDSelectionFunctor::PURE09, JetIDSelectionFunctor::LOOSE) {
0076   //now do what ever initialization is needed
0077 }
0078 
0079 SimpleJetFilter::~SimpleJetFilter() {
0080   // do anything here that needs to be done at desctruction time
0081   // (e.g. close files, deallocate resources etc.)
0082 }
0083 
0084 //
0085 // member functions
0086 //
0087 
0088 // ------------ method called on each new Event  ------------
0089 bool SimpleJetFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0090   using namespace edm;
0091 
0092   bool selected = false;
0093 
0094   Handle<reco::CaloJetCollection> jetcoll;
0095   iEvent.getByLabel(m_jetCollection, jetcoll);
0096 
0097   Handle<reco::JetIDValueMap> jetIDmap;
0098   iEvent.getByLabel(m_jetIDMap, jetIDmap);
0099 
0100   unsigned int goodjets = 0;
0101 
0102   for (unsigned int ijet = 0; ijet < jetcoll->size(); ++ijet) {
0103     const reco::CaloJetRef jet(jetcoll, ijet);
0104 
0105     LogDebug("JetUnderTest") << "Jet with eta = " << jet->eta() << " and pt = " << jet->pt() << " under test";
0106 
0107     if (!(std::abs(jet->eta()) < m_etamaxcut && jet->pt() > m_ptcut))
0108       continue;
0109 
0110     LogDebug("JetUnderTest") << "kincut passed";
0111 
0112     if (jetIDmap->contains(jet.id())) {
0113       const reco::JetID& jetid = (*jetIDmap)[jet];
0114       pat::strbitset ret = m_jetIDfunc.getBitTemplate();
0115       ret.set(false);
0116       bool goodjet = m_jetIDfunc((*jetcoll)[ijet], jetid, ret);
0117       if (goodjet) {
0118         ++goodjets;
0119         LogDebug("JetUnderTest") << "JetID passed";
0120       }
0121       if (goodjets >= m_njetmin)
0122         return true;
0123 
0124     } else {
0125       edm::LogWarning("JetIDNotFound") << "JetID not found ";
0126     }
0127   }
0128 
0129   return selected;
0130 }
0131 
0132 //define this as a plug-in
0133 DEFINE_FWK_MODULE(SimpleJetFilter);