File indexing completed on 2024-04-06 12:33:18
0001 #include "FWCore/PluginManager/interface/ModuleDef.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003
0004
0005 #include <memory>
0006
0007
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/global/EDFilter.h"
0010
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015
0016 #include "DataFormats/Common/interface/RefVector.h"
0017
0018 #include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
0019 #include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
0020 #include "CommonTools/UtilAlgos/interface/SingleElementCollectionSelector.h"
0021 #include "CommonTools/UtilAlgos/interface/ObjectCountFilter.h"
0022
0023 #include "DataFormats/JetReco/interface/PFJet.h"
0024 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0025
0026 #include "DataFormats/JetReco/interface/Jet.h"
0027 #include "DataFormats/JetReco/interface/JetCollection.h"
0028
0029 #include "DataFormats/MuonReco/interface/Muon.h"
0030 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0031
0032 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0033 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0034
0035 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0036 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0037
0038 #include <vector>
0039 #include <iostream>
0040
0041 typedef SingleObjectSelector<std::vector<reco::Jet>, StringCutObjectSelector<reco::Jet> > TauValJetSelector;
0042 typedef SingleObjectSelector<reco::MuonCollection, StringCutObjectSelector<reco::Muon> > TauValMuonSelector;
0043 typedef SingleObjectSelector<reco::GenParticleCollection, StringCutObjectSelector<reco::GenParticle> >
0044 TauValGenPSelector;
0045 typedef SingleObjectSelector<reco::GenParticleRefVector, StringCutObjectSelector<reco::GenParticleRef> >
0046 TauValGenPRefSelector;
0047 typedef SingleObjectSelector<reco::PFJetCollection, StringCutObjectSelector<reco::PFJet> > TauValPFJetSelector;
0048 typedef SingleObjectSelector<edm::View<reco::GsfElectron>,
0049 StringCutObjectSelector<reco::GsfElectron>,
0050 reco::GsfElectronCollection>
0051 TauValElectronSelector;
0052
0053 DEFINE_FWK_MODULE(TauValPFJetSelector);
0054 DEFINE_FWK_MODULE(TauValJetSelector);
0055 DEFINE_FWK_MODULE(TauValMuonSelector);
0056 DEFINE_FWK_MODULE(TauValElectronSelector);
0057 DEFINE_FWK_MODULE(TauValGenPSelector);
0058 DEFINE_FWK_MODULE(TauValGenPRefSelector);
0059
0060 class ElectronIdFilter : public edm::global::EDFilter<> {
0061 public:
0062 explicit ElectronIdFilter(const edm::ParameterSet&);
0063
0064 private:
0065 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0066
0067 edm::EDGetTokenT<reco::GsfElectronCollection> recoGsfElectronCollectionToken_;
0068 edm::EDGetTokenT<edm::ValueMap<float> > edmValueMapFloatToken_;
0069 int eid_;
0070
0071 };
0072
0073 ElectronIdFilter::ElectronIdFilter(const edm::ParameterSet& iConfig)
0074 : recoGsfElectronCollectionToken_(
0075 consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0076 edmValueMapFloatToken_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("eidsrc"))),
0077 eid_(iConfig.getParameter<int>("eid")) {
0078 produces<reco::GsfElectronCollection>();
0079 }
0080
0081
0082
0083 bool ElectronIdFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0084
0085
0086 edm::Handle<reco::GsfElectronCollection> electrons;
0087 iEvent.getByToken(recoGsfElectronCollectionToken_, electrons);
0088
0089 edm::Handle<edm::ValueMap<float> > eIDValueMap;
0090 iEvent.getByToken(edmValueMapFloatToken_, eIDValueMap);
0091 const edm::ValueMap<float>& eIDmap = *eIDValueMap;
0092 reco::GsfElectronCollection* product = new reco::GsfElectronCollection();
0093
0094
0095 for (unsigned int i = 0; i < electrons->size(); i++) {
0096 edm::Ref<reco::GsfElectronCollection> electronRef(electrons, i);
0097 if ((eIDmap[electronRef]) == eid_)
0098 product->push_back((*electrons)[i]);
0099 }
0100
0101
0102 std::unique_ptr<reco::GsfElectronCollection> collection(product);
0103 iEvent.put(std::move(collection));
0104 return true;
0105 }
0106
0107 DEFINE_FWK_MODULE(ElectronIdFilter);