Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:45

0001 
0002 #include <memory>
0003 #include "FWCore/Framework/interface/global/EDFilter.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/Common/interface/View.h"
0007 #include "DataFormats/PatCandidates/interface/Jet.h"
0008 #include "DataFormats/PatCandidates/interface/MET.h"
0009 
0010 class JetIDFailureFilter : public edm::global::EDFilter<> {
0011 public:
0012   explicit JetIDFailureFilter(const edm::ParameterSet& iConfig);
0013 
0014 private:
0015   bool filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0016 
0017   edm::EDGetTokenT<edm::View<pat::Jet> > theJetToken_;
0018   const double minJetPt_, maxJetEta_, maxNeutHadF_, maxNeutEmF_;
0019   const bool debug_;
0020   const bool taggingMode_;
0021 };
0022 
0023 JetIDFailureFilter::JetIDFailureFilter(const edm::ParameterSet& iConfig)
0024     : theJetToken_(consumes<edm::View<pat::Jet> >(iConfig.getParameter<edm::InputTag>("JetSource"))),
0025       minJetPt_(iConfig.getParameter<double>("MinJetPt")),
0026       maxJetEta_(iConfig.getParameter<double>("MaxJetEta")),
0027       maxNeutHadF_(iConfig.getParameter<double>("MaxNeutralHadFrac")),
0028       maxNeutEmF_(iConfig.getParameter<double>("MaxNeutralEMFrac")),
0029       debug_(iConfig.getParameter<bool>("debug")),
0030       taggingMode_(iConfig.getParameter<bool>("taggingMode")) {
0031   produces<bool>();
0032 }
0033 
0034 bool JetIDFailureFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0035   // read in the objects
0036   edm::Handle<edm::View<pat::Jet> > jets;
0037   iEvent.getByToken(theJetToken_, jets);
0038 
0039   bool goodJetID = true;
0040 
0041   int jetIdx = -1;
0042 
0043   for (edm::View<pat::Jet>::const_iterator j = jets->begin(); j != jets->end(); ++j) {
0044     if (j->isCaloJet()) {
0045       std::cout << "No JetId is applied to CaloJets for time being !!! " << std::endl;
0046     } else if (j->isPFJet()) {
0047       if (j->pt() > minJetPt_ && fabs(j->eta()) < maxJetEta_) {
0048         jetIdx++;
0049 
0050         // neutral hadron fraction already calculated on uncorrected jet energy
0051         double nhf = j->neutralHadronEnergyFraction();
0052 
0053         // charged hadron fraction, uncorrected jet energy
0054         double nem = j->photonEnergyFraction() / j->jecFactor(0);
0055 
0056         if (debug_) {
0057           printf("DEBUG ... idx : %3d  pt : %8.3f  eta : % 6.3f  phi : % 6.3f  nhf : %5.3f  nem : %5.3f\n",
0058                  jetIdx,
0059                  j->pt(),
0060                  j->eta(),
0061                  j->phi(),
0062                  nhf,
0063                  nem);
0064         }
0065 
0066         if (nhf > maxNeutHadF_ || nem > maxNeutEmF_) {
0067           goodJetID = false;
0068         }
0069       }
0070     }
0071   }
0072 
0073   iEvent.put(std::make_unique<bool>(goodJetID));
0074 
0075   return taggingMode_ || goodJetID;
0076 }
0077 
0078 #include "FWCore/Framework/interface/MakerMacros.h"
0079 
0080 DEFINE_FWK_MODULE(JetIDFailureFilter);