File indexing completed on 2024-04-06 12:31:24
0001 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/stream/EDFilter.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0007
0008 template <typename S>
0009 class TopDecayChannelFilter : public edm::stream::EDFilter<> {
0010 public:
0011 TopDecayChannelFilter(const edm::ParameterSet&);
0012
0013 private:
0014 bool filter(edm::Event&, const edm::EventSetup&) override;
0015 edm::InputTag src_;
0016 edm::EDGetTokenT<TtGenEvent> genEvt_;
0017 edm::EDGetTokenT<reco::GenParticleCollection> parts_;
0018 S sel_;
0019 bool checkedSrcType_;
0020 bool useTtGenEvent_;
0021 };
0022
0023 template <typename S>
0024 TopDecayChannelFilter<S>::TopDecayChannelFilter(const edm::ParameterSet& cfg)
0025 : src_(cfg.template getParameter<edm::InputTag>("src")),
0026 genEvt_(mayConsume<TtGenEvent>(src_)),
0027 parts_(mayConsume<reco::GenParticleCollection>(src_)),
0028 sel_(cfg),
0029 checkedSrcType_(false),
0030 useTtGenEvent_(false) {}
0031
0032 template <typename S>
0033 bool TopDecayChannelFilter<S>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0034 edm::Handle<TtGenEvent> genEvt;
0035
0036 if (!checkedSrcType_) {
0037 checkedSrcType_ = true;
0038 if (genEvt = iEvent.getHandle(genEvt_); genEvt.isValid()) {
0039 useTtGenEvent_ = true;
0040 return sel_(genEvt->particles(), src_.label());
0041 }
0042 } else {
0043 if (useTtGenEvent_) {
0044 genEvt = iEvent.getHandle(genEvt_);
0045 return sel_(genEvt->particles(), src_.label());
0046 }
0047 }
0048 const auto& parts = iEvent.get(parts_);
0049 return sel_(parts, src_.label());
0050 }