00001
00002
00003
00004
00016 #include "FWCore/Framework/interface/EDProducer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/ParameterSet/interface/InputTag.h"
00020
00021 #include "PhysicsTools/Utilities/interface/StringObjectFunction.h"
00022 #include "PhysicsTools/Utilities/interface/StringCutObjectSelector.h"
00023
00024 #include "DataFormats/PatCandidates/interface/Electron.h"
00025 #include "DataFormats/PatCandidates/interface/Muon.h"
00026 #include "DataFormats/PatCandidates/interface/Tau.h"
00027 #include "DataFormats/PatCandidates/interface/Photon.h"
00028 #include "DataFormats/PatCandidates/interface/Jet.h"
00029 #include "DataFormats/PatCandidates/interface/MET.h"
00030 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00031 #include "DataFormats/PatCandidates/interface/PFParticle.h"
00032
00033 #include "PhysicsTools/PatAlgos/interface/OverlapTest.h"
00034 #include <boost/ptr_container/ptr_vector.hpp>
00035
00036 namespace pat {
00037
00038 template<class PATObjType>
00039 class PATCleaner : public edm::EDProducer {
00040 public:
00041 explicit PATCleaner(const edm::ParameterSet & iConfig);
00042 virtual ~PATCleaner() {}
00043
00044 virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
00045
00046 private:
00047 typedef StringCutObjectSelector<PATObjType> Selector;
00048
00049 edm::InputTag src_;
00050 bool doPreselection_, doFinalCut_;
00051 Selector preselectionCut_;
00052 Selector finalCut_;
00053
00054 typedef pat::helper::OverlapTest OverlapTest;
00055
00056 boost::ptr_vector<OverlapTest> overlapTests_;
00057 };
00058
00059 }
00060
00061 template <class PATObjType>
00062 pat::PATCleaner<PATObjType>::PATCleaner(const edm::ParameterSet & iConfig) :
00063 src_(iConfig.getParameter<edm::InputTag>("src")),
00064 preselectionCut_(iConfig.getParameter<std::string>("preselection")),
00065 finalCut_(iConfig.getParameter<std::string>("finalCut"))
00066 {
00067
00068 edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
00069
00070 std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
00071
00072 for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
00073
00074 edm::ParameterSet cfg = overlapPSet.getParameter<edm::ParameterSet>(*itn);
00075
00076 if (cfg.empty()) continue;
00077
00078 std::string algorithm = cfg.getParameter<std::string>("algorithm");
00079
00080 if (algorithm == "byDeltaR") {
00081 overlapTests_.push_back(new pat::helper::BasicOverlapTest(*itn, cfg));
00082 } else if (algorithm == "bySuperClusterSeed") {
00083 overlapTests_.push_back(new pat::helper::OverlapBySuperClusterSeed(*itn, cfg));
00084 } else {
00085 throw cms::Exception("Configuration") << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
00086 }
00087 }
00088
00089
00090 produces<std::vector<PATObjType> >();
00091 }
00092
00093 template <class PATObjType>
00094 void
00095 pat::PATCleaner<PATObjType>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00096 using namespace edm;
00097
00098
00099 Handle<View<PATObjType> > candidates;
00100 iEvent.getByLabel(src_, candidates);
00101
00102
00103 std::auto_ptr< std::vector<PATObjType> > output(new std::vector<PATObjType>());
00104
00105
00106 for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
00107 itov->readInput(iEvent,iSetup);
00108 }
00109
00110 for (typename View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
00111
00112 if (!preselectionCut_(*it)) continue;
00113
00114
00115
00116 output->push_back(*it);
00117 PATObjType &obj = output->back();
00118
00119
00120 bool badForOverlap = false;
00121 for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
00122 reco::CandidatePtrVector overlaps;
00123 bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
00124 if (hasOverlap && itov->requireNoOvelaps()) {
00125 badForOverlap = true;
00126 break;
00127 }
00128 obj.setOverlaps(itov->name(), overlaps);
00129 }
00130 if (badForOverlap) { output->pop_back(); continue; }
00131
00132
00133 if (!finalCut_(obj)) output->pop_back();
00134 }
00135
00136 iEvent.put(output);
00137 }
00138
00139
00140 #include "FWCore/Framework/interface/MakerMacros.h"
00141 namespace pat {
00142 typedef pat::PATCleaner<pat::Electron> PATElectronCleaner;
00143 typedef pat::PATCleaner<pat::Muon> PATMuonCleaner;
00144 typedef pat::PATCleaner<pat::Tau> PATTauCleaner;
00145 typedef pat::PATCleaner<pat::Photon> PATPhotonCleaner;
00146 typedef pat::PATCleaner<pat::Jet> PATJetCleaner;
00147 typedef pat::PATCleaner<pat::MET> PATMETCleaner;
00148 typedef pat::PATCleaner<pat::GenericParticle> PATGenericParticleCleaner;
00149
00150
00151 }
00152 using namespace pat;
00153 DEFINE_FWK_MODULE(PATElectronCleaner);
00154 DEFINE_FWK_MODULE(PATMuonCleaner);
00155 DEFINE_FWK_MODULE(PATTauCleaner);
00156 DEFINE_FWK_MODULE(PATPhotonCleaner);
00157 DEFINE_FWK_MODULE(PATJetCleaner);
00158 DEFINE_FWK_MODULE(PATMETCleaner);
00159 DEFINE_FWK_MODULE(PATGenericParticleCleaner);
00160