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