Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:06

0001 #include "FWCore/Utilities/interface/InputTag.h"
0002 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0003 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0004 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0005 #include "DataFormats/Candidate/interface/Candidate.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 
0008 #include "FWCore/Framework/interface/stream/EDFilter.h"
0009 #include "FWCore/Utilities/interface/StreamID.h"
0010 
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 class DYToMuMuGenFilter : public edm::stream::EDFilter<> {
0016 public:
0017   explicit DYToMuMuGenFilter(const edm::ParameterSet&);
0018   ~DYToMuMuGenFilter() override;
0019 
0020   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0021 
0022 private:
0023   void beginStream(edm::StreamID) override;
0024   bool filter(edm::Event&, const edm::EventSetup&) override;
0025   void endStream() override;
0026 
0027   edm::InputTag inputTag_;
0028   edm::EDGetTokenT<reco::GenParticleCollection> genParticleCollection_;
0029 
0030   edm::Handle<reco::GenParticleCollection> gen_handle;
0031 
0032   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0033   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0034   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0035   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0036 
0037   // ----------member data ---------------------------
0038 };
0039 
0040 DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet& iConfig) {
0041   inputTag_ = iConfig.getParameter<edm::InputTag>("inputTag");
0042   genParticleCollection_ = consumes<reco::GenParticleCollection>(inputTag_);
0043 }
0044 
0045 DYToMuMuGenFilter::~DYToMuMuGenFilter() {}
0046 
0047 bool DYToMuMuGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048   iEvent.getByToken(genParticleCollection_, gen_handle);
0049 
0050   for (unsigned int i = 0; i < gen_handle->size(); i++) {
0051     const reco::GenParticle gen_particle = (*gen_handle)[i];
0052     // Check if Z Boson decayed into two leptons
0053     if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) {
0054       //Debug output
0055       //std::cout << "pdgId" << gen_particle.pdgId() << std::endl;
0056       //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl;
0057       //std::cout << "Dau1" << gen_particle->daughters->at(0).pdgId() << std::endl;
0058       //std::cout << "Dau2" << gen_particle.numberOfDaughters() << std::endl;
0059       //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl;
0060       //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl;
0061       //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl;
0062 
0063       // Check if daugther particles are muons
0064       if (std::abs(gen_particle.daughter(0)->pdgId()) == 13 && std::abs(gen_particle.daughter(0)->eta()) < 2.6 &&
0065           std::abs(gen_particle.daughter(1)->eta()) < 2.6 && gen_particle.daughter(0)->pt() > 7 &&
0066           gen_particle.daughter(1)->pt() > 7) {
0067         //std::cout << "pdgId" << gen_particle.pdgId() << std::endl;
0068         //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl;
0069         //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl;
0070         //std::cout << "Dau1 pt " << gen_particle.daughter(0)->pt() << std::endl;
0071         //std::cout << "Dau1 pt " << gen_particle.daughter(0)->eta() << std::endl;
0072         //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl;
0073         //std::cout << "Dau2 pt " << gen_particle.daughter(1)->pt() << std::endl;
0074         //std::cout << "Dau2 pt " << gen_particle.daughter(1)->eta() << std::endl;
0075         //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl;
0076         return true;
0077       } else {
0078         return false;
0079       }
0080     }
0081   }
0082   return false;
0083 }
0084 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0085 void DYToMuMuGenFilter::beginStream(edm::StreamID) {}
0086 
0087 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0088 void DYToMuMuGenFilter::endStream() {}
0089 
0090 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0091 void DYToMuMuGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0092   //The following says we do not know what parameters are allowed so do no validation
0093   // Please change this to state exactly what you do use, even if it is no parameters
0094   edm::ParameterSetDescription desc;
0095   desc.setUnknown();
0096   descriptions.addDefault(desc);
0097 }
0098 
0099 DEFINE_FWK_MODULE(DYToMuMuGenFilter);