ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/plugins/PATCleaner.cc
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: ANA
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
version CMSSW_2_2_10

File Contents

# Content
1 //
2 // $Id: PATCleaner.cc,v 1.1.2.1 2009/01/14 17:27:56 gpetrucc Exp $
3 //
4
5 /**
6 \class pat::PATCleaner PATCleaner.h "PhysicsTools/PatAlgos/interface/PATCleaner.h"
7 \brief PAT Cleaner module for PAT Objects
8
9 The same module is used for all collections.
10
11 \author Giovanni Petrucciani
12 \version $Id: PATCleaner.cc,v 1.1.2.1 2009/01/14 17:27:56 gpetrucc Exp $
13 */
14
15
16 #include "FWCore/Framework/interface/EDProducer.h"
17 #include "FWCore/Framework/interface/Event.h"
18 #include "FWCore/ParameterSet/interface/ParameterSet.h"
19 #include "FWCore/ParameterSet/interface/InputTag.h"
20
21 #include "PhysicsTools/Utilities/interface/StringObjectFunction.h"
22 #include "PhysicsTools/Utilities/interface/StringCutObjectSelector.h"
23
24 #include "DataFormats/PatCandidates/interface/Electron.h"
25 #include "DataFormats/PatCandidates/interface/Muon.h"
26 #include "DataFormats/PatCandidates/interface/Tau.h"
27 #include "DataFormats/PatCandidates/interface/Photon.h"
28 #include "DataFormats/PatCandidates/interface/Jet.h"
29 #include "DataFormats/PatCandidates/interface/MET.h"
30 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
31 #include "DataFormats/PatCandidates/interface/PFParticle.h"
32
33 #include "PhysicsTools/PatAlgos/interface/OverlapTest.h"
34 #include <boost/ptr_container/ptr_vector.hpp>
35
36 namespace pat {
37
38 template<class PATObjType>
39 class PATCleaner : public edm::EDProducer {
40 public:
41 explicit PATCleaner(const edm::ParameterSet & iConfig);
42 virtual ~PATCleaner() {}
43
44 virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
45
46 private:
47 typedef StringCutObjectSelector<PATObjType> Selector;
48
49 edm::InputTag src_;
50 bool doPreselection_, doFinalCut_;
51 Selector preselectionCut_;
52 Selector finalCut_;
53
54 typedef pat::helper::OverlapTest OverlapTest;
55 // make a list of overlap tests (ptr_vector instead of std::vector because they're polymorphic)
56 boost::ptr_vector<OverlapTest> overlapTests_;
57 };
58
59 } // namespace
60
61 template <class PATObjType>
62 pat::PATCleaner<PATObjType>::PATCleaner(const edm::ParameterSet & iConfig) :
63 src_(iConfig.getParameter<edm::InputTag>("src")),
64 preselectionCut_(iConfig.getParameter<std::string>("preselection")),
65 finalCut_(iConfig.getParameter<std::string>("finalCut"))
66 {
67 // pick parameter set for overlaps
68 edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
69 // get all the names of the tests (all nested PSets in this PSet)
70 std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
71 // loop on them
72 for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
73 // retrieve configuration
74 edm::ParameterSet cfg = overlapPSet.getParameter<edm::ParameterSet>(*itn);
75 // skip empty parameter sets
76 if (cfg.empty()) continue;
77 // get the name of the algorithm to use
78 std::string algorithm = cfg.getParameter<std::string>("algorithm");
79 // create the appropriate OverlapTest
80 if (algorithm == "byDeltaR") {
81 overlapTests_.push_back(new pat::helper::BasicOverlapTest(*itn, cfg));
82 } else if (algorithm == "bySuperClusterSeed") {
83 overlapTests_.push_back(new pat::helper::OverlapBySuperClusterSeed(*itn, cfg));
84 } else {
85 throw cms::Exception("Configuration") << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
86 }
87 }
88
89
90 produces<std::vector<PATObjType> >();
91 }
92
93 template <class PATObjType>
94 void
95 pat::PATCleaner<PATObjType>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
96 using namespace edm;
97
98 // Read the input. We use View<> in case the input happes to be something different than a std::vector<>
99 Handle<View<PATObjType> > candidates;
100 iEvent.getByLabel(src_, candidates);
101
102 // Prepare a collection for the output
103 std::auto_ptr< std::vector<PATObjType> > output(new std::vector<PATObjType>());
104
105 // initialize the overlap tests
106 for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
107 itov->readInput(iEvent,iSetup);
108 }
109
110 for (typename View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
111 // Apply a preselection to the inputs and copy them in the output
112 if (!preselectionCut_(*it)) continue;
113
114 // Add it to the list and take a reference to it, so it can be modified (e.g. to set the overlaps)
115 // If at some point I'll decide to drop this item, I'll use pop_back to remove it
116 output->push_back(*it);
117 PATObjType &obj = output->back();
118
119 // Look for overlaps
120 bool badForOverlap = false;
121 for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
122 reco::CandidatePtrVector overlaps;
123 bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
124 if (hasOverlap && itov->requireNoOvelaps()) {
125 badForOverlap = true; // mark for discarding
126 break; // no point in checking the others, as this item will be discarded
127 }
128 obj.setOverlaps(itov->name(), overlaps);
129 }
130 if (badForOverlap) { output->pop_back(); continue; }
131
132 // Apply one final selection cut
133 if (!finalCut_(obj)) output->pop_back();
134 }
135
136 iEvent.put(output);
137 }
138
139
140 #include "FWCore/Framework/interface/MakerMacros.h"
141 namespace pat {
142 typedef pat::PATCleaner<pat::Electron> PATElectronCleaner;
143 typedef pat::PATCleaner<pat::Muon> PATMuonCleaner;
144 typedef pat::PATCleaner<pat::Tau> PATTauCleaner;
145 typedef pat::PATCleaner<pat::Photon> PATPhotonCleaner;
146 typedef pat::PATCleaner<pat::Jet> PATJetCleaner;
147 typedef pat::PATCleaner<pat::MET> PATMETCleaner;
148 typedef pat::PATCleaner<pat::GenericParticle> PATGenericParticleCleaner;
149 //typedef pat::PATCleaner<pat::PFParticle> PATPFParticleCleaner; // I don't think the PF folks need/want this
150 // but technically it can work
151 }
152 using namespace pat;
153 DEFINE_FWK_MODULE(PATElectronCleaner);
154 DEFINE_FWK_MODULE(PATMuonCleaner);
155 DEFINE_FWK_MODULE(PATTauCleaner);
156 DEFINE_FWK_MODULE(PATPhotonCleaner);
157 DEFINE_FWK_MODULE(PATJetCleaner);
158 DEFINE_FWK_MODULE(PATMETCleaner);
159 DEFINE_FWK_MODULE(PATGenericParticleCleaner);
160 //DEFINE_FWK_MODULE(PATPFParticleCleaner);