Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-16 00:33:15

0001 // -*- C++ -*-
0002 //
0003 // Package:    HFFilter
0004 // Class:      HFFilter
0005 //
0006 /**\class HFFilter HFFilter.cc PhysicsTools/HFFilter/src/HFFilter.cc
0007 
0008  Description: Filter to see if there are heavy flavor GenJets in this event
0009 
0010  Implementation:
0011      The implementation is simple, it loops over the GenJets and checks if any constituents
0012      have a pdg ID that matches a list. It also has a switch to count objects from a gluon parent,
0013      so the user can turn off counting gluon splitting.
0014 */
0015 //
0016 // Original Author:  "Salvatore Rappoccio"
0017 //         Created:  Tue Apr  8 16:19:45 CDT 2008
0018 //
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <string>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/global/EDFilter.h"
0028 
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 
0034 #include "DataFormats/JetReco/interface/GenJet.h"
0035 
0036 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
0037 
0038 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0039 
0040 //
0041 // class declaration
0042 //
0043 
0044 class HFFilter : public edm::global::EDFilter<> {
0045 public:
0046   explicit HFFilter(const edm::ParameterSet&);
0047 
0048   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0049 
0050   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051 
0052 private:
0053   // ----------member data ---------------------------
0054   edm::EDGetTokenT<std::vector<reco::GenJet>> genJetsCollToken_;  // Input GenJetsCollection
0055   double ptMin_;                                                  // Min pt
0056   double etaMax_;                                                 // Max abs(eta)
0057 };
0058 using namespace std;
0059 
0060 //
0061 // constructors and destructor
0062 //
0063 HFFilter::HFFilter(const edm::ParameterSet& iConfig) {
0064   genJetsCollToken_ = consumes<vector<reco::GenJet>>(iConfig.getParameter<edm::InputTag>("genJetsCollName"));
0065   ptMin_ = iConfig.getParameter<double>("ptMin");
0066   etaMax_ = iConfig.getParameter<double>("etaMax");
0067 }
0068 
0069 void HFFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0070   edm::ParameterSetDescription desc;
0071   desc.add<edm::InputTag>("genJetsCollName");
0072   desc.add<double>("ptMin");
0073   desc.add<double>("etaMax");
0074 
0075   descriptions.addDefault(desc);
0076 }
0077 
0078 //
0079 // member functions
0080 //
0081 
0082 // Filter event based on whether there are heavy flavor GenJets in it that satisfy
0083 // pt and eta cuts
0084 bool HFFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0085   // Get the GenJetCollection
0086   using namespace edm;
0087   using namespace reco;
0088   Handle<std::vector<GenJet>> hGenJets;
0089   iEvent.getByToken(genJetsCollToken_, hGenJets);
0090 
0091   // Loop over the GenJetCollection
0092   vector<GenJet>::const_iterator ijet = hGenJets->begin();
0093   vector<GenJet>::const_iterator end = hGenJets->end();
0094   for (; ijet != end; ++ijet) {
0095     // Check to make sure the GenJet satisfies kinematic cuts. Ignore those that don't.
0096     if (ijet->pt() < ptMin_ || fabs(ijet->eta()) > etaMax_)
0097       continue;
0098 
0099     // Get the constituent particles
0100     vector<const GenParticle*> particles = ijet->getGenConstituents();
0101 
0102     // Loop over the constituent particles
0103     vector<const GenParticle*>::const_iterator genit = particles.begin();
0104     vector<const GenParticle*>::const_iterator genend = particles.end();
0105     for (; genit != genend; ++genit) {
0106       // See if any of them come from B or C hadrons
0107       const GenParticle& genitref = **genit;
0108       if (JetMCTagUtils::decayFromBHadron(genitref) || JetMCTagUtils::decayFromCHadron(genitref)) {
0109         return true;
0110       }
0111     }  // end loop over constituents
0112   }    // end loop over jets
0113 
0114   return false;
0115 }
0116 
0117 //define this as a plug-in
0118 DEFINE_FWK_MODULE(HFFilter);