Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:33

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