Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-18 02:30:15

0001 // -*- C++ -*-
0002 //
0003 // Package:    TauHadronDecayFilter
0004 // Class:      TauHadronDecayFilter
0005 //
0006 /**\class TauHadronDecayFilter 
0007 
0008  Description: filters single tau events with a tau decaying hadronically
0009 */
0010 //
0011 // Original Author:  Colin BERNET
0012 //         Created:  Mon Nov 13 11:06:39 CET 2006
0013 //
0014 //
0015 
0016 #include "FWCore/Framework/interface/one/EDFilter.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FastSimulation/Event/interface/FSimEvent.h"
0025 #include "FastSimulation/Event/interface/FSimTrack.h"
0026 #include "FastSimulation/Event/interface/FSimVertex.h"
0027 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0028 
0029 #include <iostream>
0030 #include <memory>
0031 
0032 class TauHadronDecayFilter : public edm::one::EDFilter<edm::one::WatchRuns> {
0033 public:
0034   explicit TauHadronDecayFilter(const edm::ParameterSet&);
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 private:
0039   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0040   void endRun(const edm::Run&, const edm::EventSetup&) override{};
0041   bool filter(edm::Event&, const edm::EventSetup&) override;
0042 
0043   // ----------member data ---------------------------
0044   const edm::ESGetToken<HepPDT::ParticleDataTable, PDTRecord> tokPdt_;
0045   const edm::EDGetTokenT<std::vector<SimTrack>> simtracksToken_;
0046   const edm::EDGetTokenT<std::vector<SimVertex>> simvertexToken_;
0047   edm::ParameterSet particleFilter_;
0048   std::unique_ptr<FSimEvent> mySimEvent;
0049 };
0050 
0051 #include "FWCore/Framework/interface/MakerMacros.h"
0052 DEFINE_FWK_MODULE(TauHadronDecayFilter);
0053 
0054 void TauHadronDecayFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055   // tauHadronDecayFilter
0056   edm::ParameterSetDescription desc;
0057   desc.add<edm::InputTag>("particles", edm::InputTag("particleFlowBlock"));
0058   {
0059     edm::ParameterSetDescription psd0;
0060     psd0.add<double>("etaMax", 10.0);
0061     psd0.add<double>("pTMin", 0.0);
0062     psd0.add<double>("EMin", 0.0);
0063     desc.add<edm::ParameterSetDescription>("ParticleFilter", psd0);
0064   }
0065   descriptions.add("tauHadronDecayFilter", desc);
0066 }
0067 
0068 TauHadronDecayFilter::TauHadronDecayFilter(const edm::ParameterSet& iConfig)
0069     : tokPdt_(esConsumes<edm::Transition::BeginRun>()),
0070       simtracksToken_(consumes<std::vector<SimTrack>>(edm::InputTag("g4SimHits"))),
0071       simvertexToken_(consumes<std::vector<SimVertex>>(edm::InputTag("g4SimHits"))) {
0072   particleFilter_ = iConfig.getParameter<edm::ParameterSet>("ParticleFilter");
0073 
0074   mySimEvent = std::make_unique<FSimEvent>(particleFilter_);
0075 }
0076 
0077 bool TauHadronDecayFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0078   mySimEvent->fill(iEvent.get(simtracksToken_), iEvent.get(simvertexToken_));
0079 
0080   if (mySimEvent->nTracks() >= 2) {
0081     FSimTrack& gene = mySimEvent->track(0);
0082     if (std::abs(gene.type()) != 15) {
0083       // first particle is not a tau.
0084       // -> do not filter
0085       return true;
0086     }
0087 
0088     FSimTrack& decayproduct = mySimEvent->track(1);
0089     switch (std::abs(decayproduct.type())) {
0090       case 11:  // electrons
0091       case 13:  // muons
0092         edm::LogWarning("PFProducer") << "TauHadronDecayFilter: selecting single tau events with hadronic decay.";
0093         // mySimEvent->print();
0094         return false;
0095       default:
0096         return true;
0097     }
0098   }
0099 
0100   // more than 2 particles
0101   return true;
0102 }
0103 
0104 void TauHadronDecayFilter::beginRun(const edm::Run& run, const edm::EventSetup& es) {
0105   // initialize Particle data table (from Pythia)
0106   mySimEvent->initializePdt(&es.getData(tokPdt_));
0107 }