00001 /* 00002 * Produce a RefVector of PFTaus that pass a given selection on 00003 * the input discriminator collection. 00004 * 00005 * Parameters: 00006 * InputTag src = View of PFTaus 00007 * InputTag disc = discriinator 00008 * double cut 00009 * 00010 * Author: Evan K. Friis (UC Davis) 00011 * 00012 */ 00013 00014 #include <boost/foreach.hpp> 00015 #include <memory> 00016 00017 #include "FWCore/Framework/interface/EDFilter.h" 00018 #include "FWCore/Framework/interface/EventSetup.h" 00019 #include "FWCore/Framework/interface/ESHandle.h" 00020 #include "FWCore/Framework/interface/Event.h" 00021 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00022 #include "DataFormats/TauReco/interface/PFTauFwd.h" 00023 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h" 00024 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h" 00025 00026 class ConcreteTauBuilder { 00027 public: 00028 typedef std::vector<reco::PFTau> OutputType; 00029 static OutputType::value_type make(const reco::PFTauRef& ref) { 00030 return *ref; 00031 } 00032 }; 00033 00034 class RefToBaseBuilder { 00035 public: 00036 typedef edm::RefToBaseVector<reco::PFTau> OutputType; 00037 static OutputType::value_type make(const reco::PFTauRef& ref) { 00038 return edm::RefToBase<reco::PFTau>(ref); 00039 } 00040 }; 00041 00042 class RefVectorBuilder { 00043 public: 00044 typedef reco::PFTauRefVector OutputType; 00045 static OutputType::value_type make(const reco::PFTauRef& ref) { 00046 return ref; 00047 } 00048 }; 00049 00050 00051 template<typename T> 00052 class RecoTauDiscriminatorRefSelectorImpl : public edm::EDFilter { 00053 public: 00054 explicit RecoTauDiscriminatorRefSelectorImpl(const edm::ParameterSet &pset); 00055 ~RecoTauDiscriminatorRefSelectorImpl() {} 00056 bool filter(edm::Event &evt, const edm::EventSetup &es); 00057 private: 00058 typedef typename T::OutputType OutputType; 00059 edm::InputTag src_; 00060 edm::InputTag discriminatorSrc_; 00061 double cut_; 00062 bool filter_; 00063 }; 00064 00065 template<typename T> 00066 RecoTauDiscriminatorRefSelectorImpl<T>::RecoTauDiscriminatorRefSelectorImpl( 00067 const edm::ParameterSet &pset) { 00068 src_ = pset.getParameter<edm::InputTag>("src"); 00069 discriminatorSrc_ = pset.getParameter<edm::InputTag>("discriminator"); 00070 cut_ = pset.getParameter<double>("cut"); 00071 filter_ = pset.getParameter<bool>("filter"); 00072 //produces<reco::PFTauRefVector>(); 00073 produces<OutputType>(); 00074 } 00075 00076 00077 template<typename T> 00078 bool RecoTauDiscriminatorRefSelectorImpl<T>::filter(edm::Event& evt, 00079 const edm::EventSetup &es) { 00080 edm::Handle<reco::CandidateView> input; 00081 evt.getByLabel(src_, input); 00082 reco::PFTauRefVector inputRefs = 00083 reco::tau::castView<reco::PFTauRefVector>(input); 00084 00085 edm::Handle<reco::PFTauDiscriminator> disc; 00086 evt.getByLabel(discriminatorSrc_, disc); 00087 00088 // std::auto_ptr<reco::PFTauRefVector> output( 00089 // new reco::PFTauRefVector(inputRefs.id())); 00090 //std::auto_ptr<OutputType> output( 00091 // new OutputType(inputRefs.id())); 00092 std::auto_ptr<OutputType> output(new OutputType); 00093 00094 BOOST_FOREACH(reco::PFTauRef ref, inputRefs) { 00095 if ( (*disc)[ref] > cut_ ) 00096 output->push_back(T::make(ref)); 00097 } 00098 size_t selected = output->size(); 00099 evt.put(output); 00100 return (!filter_ || selected); 00101 } 00102 00103 typedef RecoTauDiscriminatorRefSelectorImpl<RefVectorBuilder> RecoTauDiscriminatorRefSelector; 00104 typedef RecoTauDiscriminatorRefSelectorImpl<ConcreteTauBuilder> RecoTauDiscriminatorSelector; 00105 00106 #include "FWCore/Framework/interface/MakerMacros.h" 00107 DEFINE_FWK_MODULE(RecoTauDiscriminatorRefSelector); 00108 DEFINE_FWK_MODULE(RecoTauDiscriminatorSelector);