Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:39

0001 // -*- C++ -*-
0002 //
0003 // Package:    FourLepFilter
0004 // Class:      FourLepFilter
0005 //
0006 /**\class FourLepFilter FourLepFilter.cc psi2s1s/FourLepFilter/src/FourLepFilter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  bian jianguo
0015 //         Created:  Tue Nov 22 20:39:54 CST 2011
0016 //
0017 //
0018 
0019 // user include files
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDFilter.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0028 #include "FWCore/Utilities/interface/EDGetToken.h"
0029 #include "FWCore/Utilities/interface/InputTag.h"
0030 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0031 
0032 #include <cmath>
0033 #include <cstdlib>
0034 #include <string>
0035 
0036 //
0037 // class declaration
0038 //
0039 
0040 class FourLepFilter : public edm::global::EDFilter<> {
0041 public:
0042   explicit FourLepFilter(const edm::ParameterSet&);
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions&);
0045 
0046 private:
0047   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0048 
0049   // ----------member data ---------------------------
0050 
0051   const edm::EDGetToken token_;
0052   const double minPt;
0053   const double maxEta;
0054   const double maxPt;
0055   const double minEta;
0056   const int particleID;
0057 };
0058 
0059 FourLepFilter::FourLepFilter(const edm::ParameterSet& iConfig)
0060     : token_(consumes<edm::HepMCProduct>(
0061           edm::InputTag(iConfig.getUntrackedParameter("moduleLabel", std::string("generator")), "unsmeared"))),
0062       minPt(iConfig.getUntrackedParameter("MinPt", 0.)),
0063       maxEta(iConfig.getUntrackedParameter("MaxEta", 10.)),
0064       maxPt(iConfig.getUntrackedParameter("MaxPt", 1000.)),
0065       minEta(iConfig.getUntrackedParameter("MinEta", 0.)),
0066       particleID(iConfig.getUntrackedParameter("ParticleID", 0)) {}
0067 
0068 // ------------ method called on each new Event  ------------
0069 bool FourLepFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0070   bool accepted = false;
0071   int nLeptons = 0;
0072 
0073   edm::Handle<edm::HepMCProduct> evt;
0074   iEvent.getByToken(token_, evt);
0075   const HepMC::GenEvent* myGenEvent = evt->GetEvent();
0076 
0077   for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
0078        ++p) {
0079     if ((*p)->status() != 1)
0080       continue;
0081     if ((*p)->momentum().perp() > minPt && std::fabs((*p)->momentum().eta()) < maxEta &&
0082         (*p)->momentum().perp() < maxPt && std::fabs((*p)->momentum().eta()) > minEta) {
0083       if (std::abs((*p)->pdg_id()) == particleID)
0084         nLeptons++;
0085     }
0086     if (nLeptons >= 4) {
0087       accepted = true;
0088       break;
0089     }
0090   }
0091   return accepted;
0092 }
0093 
0094 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0095 void FourLepFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0096   //The following says we do not know what parameters are allowed so do no validation
0097   // Please change this to state exactly what you do use, even if it is no parameters
0098   edm::ParameterSetDescription desc;
0099   desc.setUnknown();
0100   descriptions.addDefault(desc);
0101 }
0102 //define this as a plug-in
0103 DEFINE_FWK_MODULE(FourLepFilter);