Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-25 05:52:08

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/stream/EDFilter.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 
0005 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0006 
0007 /**
0008    \class   StringCutObjectEvtFilter StringCutObjectEvtFilter.h "TopQuarkAnalysis/TopEventProducers/interface/StringCutObjectEvtFilter.h"
0009 
0010    \brief   Event filter based on the StringCutObjectSelector
0011 
0012    Template class to filter events based on member functions of a given object in the event
0013    and cuts that are parsed by the StringCutObjectSelector.
0014 
0015 */
0016 
0017 template <typename T>
0018 class StringCutObjectEvtFilter : public edm::stream::EDFilter<> {
0019 public:
0020   /// default constructor
0021   explicit StringCutObjectEvtFilter(const edm::ParameterSet&);
0022 
0023 private:
0024   /// filter function
0025   bool filter(edm::Event&, const edm::EventSetup&) override;
0026 
0027 private:
0028   /// input object
0029   edm::EDGetTokenT<T> srcToken_;
0030   /// cut string for event selection
0031   StringCutObjectSelector<T> cut_;
0032 };
0033 
0034 template <typename T>
0035 StringCutObjectEvtFilter<T>::StringCutObjectEvtFilter(const edm::ParameterSet& cfg)
0036     : srcToken_(consumes<T>(cfg.getParameter<edm::InputTag>("src"))), cut_(cfg.getParameter<std::string>("cut")) {}
0037 
0038 template <typename T>
0039 bool StringCutObjectEvtFilter<T>::filter(edm::Event& evt, const edm::EventSetup& setup) {
0040   return cut_(evt.get(srcToken_));
0041 }
0042 
0043 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
0044 #include "AnalysisDataFormats/TopObjects/interface/TtFullHadronicEvent.h"
0045 #include "AnalysisDataFormats/TopObjects/interface/TtSemiLeptonicEvent.h"
0046 #include "AnalysisDataFormats/TopObjects/interface/TtFullLeptonicEvent.h"
0047 
0048 using TtGenEvtFilter = StringCutObjectEvtFilter<TtGenEvent>;
0049 using TtFullHadEvtFilter = StringCutObjectEvtFilter<TtFullHadronicEvent>;
0050 using TtFullLepEvtFilter = StringCutObjectEvtFilter<TtFullLeptonicEvent>;
0051 using TtSemiLepEvtFilter = StringCutObjectEvtFilter<TtSemiLeptonicEvent>;
0052 
0053 #include "FWCore/Framework/interface/MakerMacros.h"
0054 DEFINE_FWK_MODULE(TtGenEvtFilter);
0055 DEFINE_FWK_MODULE(TtFullHadEvtFilter);
0056 DEFINE_FWK_MODULE(TtFullLepEvtFilter);
0057 DEFINE_FWK_MODULE(TtSemiLepEvtFilter);