Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:11

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 
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021 private:
0022   bool filter(edm::Event&, const edm::EventSetup&) override;
0023 
0024   edm::InputTag inputTag_;
0025   edm::EDGetTokenT<reco::GenParticleCollection> genParticleCollection_;
0026 
0027   edm::Handle<reco::GenParticleCollection> gen_handle;
0028 
0029   // ----------member data ---------------------------
0030 };
0031 
0032 DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet& iConfig) {
0033   inputTag_ = iConfig.getParameter<edm::InputTag>("inputTag");
0034   genParticleCollection_ = consumes<reco::GenParticleCollection>(inputTag_);
0035 }
0036 
0037 bool DYToMuMuGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0038   iEvent.getByToken(genParticleCollection_, gen_handle);
0039 
0040   for (unsigned int i = 0; i < gen_handle->size(); i++) {
0041     const reco::GenParticle gen_particle = (*gen_handle)[i];
0042     // Check if Z Boson decayed into two leptons
0043     if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) {
0044       //Debug output
0045       //std::cout << "pdgId" << gen_particle.pdgId() << std::endl;
0046       //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl;
0047       //std::cout << "Dau1" << gen_particle->daughters->at(0).pdgId() << std::endl;
0048       //std::cout << "Dau2" << gen_particle.numberOfDaughters() << std::endl;
0049       //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl;
0050       //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl;
0051       //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl;
0052 
0053       // Check if daugther particles are muons
0054       if (std::abs(gen_particle.daughter(0)->pdgId()) == 13 && std::abs(gen_particle.daughter(0)->eta()) < 2.6 &&
0055           std::abs(gen_particle.daughter(1)->eta()) < 2.6 && gen_particle.daughter(0)->pt() > 7 &&
0056           gen_particle.daughter(1)->pt() > 7) {
0057         //std::cout << "pdgId" << gen_particle.pdgId() << std::endl;
0058         //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl;
0059         //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl;
0060         //std::cout << "Dau1 pt " << gen_particle.daughter(0)->pt() << std::endl;
0061         //std::cout << "Dau1 pt " << gen_particle.daughter(0)->eta() << std::endl;
0062         //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl;
0063         //std::cout << "Dau2 pt " << gen_particle.daughter(1)->pt() << std::endl;
0064         //std::cout << "Dau2 pt " << gen_particle.daughter(1)->eta() << std::endl;
0065         //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl;
0066         return true;
0067       } else {
0068         return false;
0069       }
0070     }
0071   }
0072   return false;
0073 }
0074 
0075 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0076 void DYToMuMuGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0077   //The following says we do not know what parameters are allowed so do no validation
0078   // Please change this to state exactly what you do use, even if it is no parameters
0079   edm::ParameterSetDescription desc;
0080   desc.setUnknown();
0081   descriptions.addDefault(desc);
0082 }
0083 
0084 DEFINE_FWK_MODULE(DYToMuMuGenFilter);