Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    PythiaFilterTTBar
0004 // Class:      PythiaFilterTTBar
0005 //
0006 /**\class PythiaFilterTTBar PythiaFilterTTBar.cc GeneratorInterface/GenFilter/src/PythiaFilterTTBar.cc
0007 
0008  Description: edmFilter to select a TTBar decay channel
0009 
0010  Implementation:
0011     decayType: 1 + leptonFlavour: 0 -> Semi-leptonic
0012                    leptonFlavour: 1 -> Semi-e
0013            leptonFlavour: 2 -> Semi-mu
0014            leptonFlavour: 3 -> Semi-tau
0015     decayType: 2 -> di-leptonic (no seperate channels implemented yet)
0016 
0017     decayType: 3 -> fully-hadronic
0018 
0019 */
0020 //
0021 // Original Author:  Michael Maes
0022 //         Created:  Wed Dec  3 12:07:13 CET 2009
0023 //
0024 //
0025 
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/global/EDFilter.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/EDGetToken.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0035 
0036 #include <cmath>
0037 #include <cstdlib>
0038 #include <string>
0039 
0040 class PythiaFilterTTBar : public edm::global::EDFilter<> {
0041 public:
0042   explicit PythiaFilterTTBar(const edm::ParameterSet&);
0043 
0044   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0045 
0046 private:
0047   const edm::EDGetTokenT<edm::HepMCProduct> token_;
0048   const unsigned int decayType_;
0049   const unsigned int leptonFlavour_;
0050 };
0051 
0052 PythiaFilterTTBar::PythiaFilterTTBar(const edm::ParameterSet& iConfig)
0053     : token_(consumes<edm::HepMCProduct>(
0054           edm::InputTag(iConfig.getUntrackedParameter("moduleLabel", std::string("generator")), "unsmeared"))),
0055       decayType_(iConfig.getUntrackedParameter("decayType", 1)),
0056       leptonFlavour_(iConfig.getUntrackedParameter("leptonFlavour", 0)) {}
0057 
0058 bool PythiaFilterTTBar::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0059   bool accept = false;
0060   edm::Handle<edm::HepMCProduct> evt;
0061   iEvent.getByToken(token_, evt);
0062 
0063   const HepMC::GenEvent* myGenEvent = evt->GetEvent();
0064 
0065   unsigned int iE = 0, iMu = 0, iTau = 0;
0066 
0067   unsigned int iNuE = 0, iNuMu = 0, iNuTau = 0;
0068 
0069   unsigned int iLep = 0, iNu = 0;
0070 
0071   for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
0072        ++p) {
0073     int pdgID = (*p)->pdg_id();
0074 
0075     int status = (*p)->status();
0076 
0077     if (status == 3) {
0078       // count the final state leptons
0079 
0080       if (std::abs(pdgID) == 11)
0081         iE++;
0082 
0083       if (std::abs(pdgID) == 13)
0084         iMu++;
0085 
0086       if (std::abs(pdgID) == 15)
0087         iTau++;
0088 
0089       // count the final state neutrinos
0090 
0091       if (std::abs(pdgID) == 12)
0092         iNuE++;
0093 
0094       if (std::abs(pdgID) == 14)
0095         iNuMu++;
0096 
0097       if (std::abs(pdgID) == 16)
0098         iNuTau++;
0099     }
0100   }
0101 
0102   iLep = (iE + iMu + iTau);
0103   iNu = (iNuE + iNuMu + iNuTau);
0104 
0105   if (decayType_ == 1) {  // semi-leptonic decay
0106 
0107     // l = e,mu,tau
0108 
0109     if (leptonFlavour_ == 0 && iLep == 1 && iNu == 1)
0110       accept = true;
0111 
0112     // l = e
0113 
0114     else if (leptonFlavour_ == 1 && iE == 1 && iNuE == 1 && iLep == 1 && iNu == 1)
0115       accept = true;
0116 
0117     // l = mu
0118 
0119     else if (leptonFlavour_ == 2 && iMu == 1 && iNuMu == 1 && iLep == 1 && iNu == 1)
0120       accept = true;
0121 
0122     // l = tau
0123 
0124     else if (leptonFlavour_ == 3 && iTau == 1 && iNuTau == 1 && iLep == 1 && iNu == 1)
0125       accept = true;
0126 
0127   }
0128 
0129   else if (decayType_ == 2) {  // di-leptonic decay (inclusive)
0130 
0131     if (iLep == 2 && iNu == 2)
0132       accept = true;
0133 
0134   }
0135 
0136   else if (decayType_ == 3) {  // fully-hadronic decay
0137 
0138     if (iLep == 0 && iNu == 0)
0139       accept = true;
0140   }
0141 
0142   else
0143     accept = false;
0144 
0145   return accept;
0146 }
0147 
0148 DEFINE_FWK_MODULE(PythiaFilterTTBar);