1 |
dgele |
1.1 |
//
|
2 |
|
|
// $Id: DuplicatedElectronCleaner.cc,v 1.1.2.2.2.1 2009/01/12 22:08:06 gpetrucc Exp $
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
/**
|
6 |
|
|
\class pat::DuplicatedElectronCleaner DuplicatedElectronCleaner.h "PhysicsTools/PatAlgos/interface/DuplicatedElectronCleaner.h"
|
7 |
|
|
\brief Remove duplicates from the list of electrons
|
8 |
|
|
|
9 |
|
|
The DuplicatedElectronCleaner removes duplicates from the input collection.
|
10 |
|
|
Two electrons are considered duplicate if they share the same gsfTrack or the same superCluster.
|
11 |
|
|
Among the two, the one with |E/P| nearest to 1 is kept.
|
12 |
|
|
This is performed by the DuplicatedElectronRemover in PhysicsTools/PatUtils
|
13 |
|
|
|
14 |
|
|
The output is an edm::RefVector<reco:::GsfElectron>,
|
15 |
|
|
which can be read through edm::View<reco::GsfElectron>
|
16 |
|
|
|
17 |
|
|
\author Giovanni Petrucciani
|
18 |
|
|
\version $Id: DuplicatedElectronCleaner.cc,v 1.1.2.2.2.1 2009/01/12 22:08:06 gpetrucc Exp $
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
23 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
24 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
25 |
|
|
#include "FWCore/ParameterSet/interface/InputTag.h"
|
26 |
|
|
|
27 |
|
|
//#include "DataFormats/Common/interface/RefVector.h"
|
28 |
|
|
#include "DataFormats/Common/interface/RefToBaseVector.h"
|
29 |
|
|
//#include "DataFormats/Common/interface/PtrVector.h"
|
30 |
|
|
|
31 |
|
|
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
|
32 |
|
|
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
|
33 |
|
|
|
34 |
|
|
#include "PhysicsTools/PatUtils/interface/DuplicatedElectronRemover.h"
|
35 |
|
|
|
36 |
|
|
namespace pat {
|
37 |
|
|
|
38 |
|
|
class DuplicatedElectronCleaner : public edm::EDProducer {
|
39 |
|
|
public:
|
40 |
|
|
explicit DuplicatedElectronCleaner(const edm::ParameterSet & iConfig);
|
41 |
|
|
~DuplicatedElectronCleaner();
|
42 |
|
|
|
43 |
|
|
virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
|
44 |
|
|
virtual void endJob();
|
45 |
|
|
|
46 |
|
|
private:
|
47 |
|
|
edm::InputTag electronSrc_;
|
48 |
|
|
pat::DuplicatedElectronRemover duplicateRemover_;
|
49 |
|
|
uint64_t try_, pass_;
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
} // namespace
|
53 |
|
|
|
54 |
|
|
pat::DuplicatedElectronCleaner::DuplicatedElectronCleaner(const edm::ParameterSet & iConfig) :
|
55 |
|
|
electronSrc_(iConfig.getParameter<edm::InputTag>("electronSource")),
|
56 |
|
|
try_(0), pass_(0)
|
57 |
|
|
{
|
58 |
|
|
//produces<edm::RefVector<reco::GsfElectronCollection> >();
|
59 |
|
|
produces<edm::RefToBaseVector<reco::GsfElectron> >();
|
60 |
|
|
//produces<edm::PtrVector<reco::GsfElectron> >();
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
pat::DuplicatedElectronCleaner::~DuplicatedElectronCleaner() {
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
void
|
67 |
|
|
pat::DuplicatedElectronCleaner::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
|
68 |
|
|
using namespace edm;
|
69 |
|
|
Handle<View<reco::GsfElectron> > electrons;
|
70 |
|
|
iEvent.getByLabel(electronSrc_, electrons);
|
71 |
|
|
try_ += electrons->size();
|
72 |
|
|
|
73 |
|
|
//std::auto_ptr<RefVector<reco::GsfElectronCollection> > result(new RefVector<reco::GsfElectronCollection>());
|
74 |
|
|
std::auto_ptr<RefToBaseVector<reco::GsfElectron> > result(new RefToBaseVector<reco::GsfElectron>());
|
75 |
|
|
//std::auto_ptr<PtrVector<reco::GsfElectron> > result(new PtrVector<reco::GsfElectron>());
|
76 |
|
|
|
77 |
|
|
std::auto_ptr< std::vector<size_t> > duplicates = duplicateRemover_.duplicatesToRemove(*electrons);
|
78 |
|
|
|
79 |
|
|
std::vector<size_t>::const_iterator itdup = duplicates->begin(), enddup = duplicates->end();
|
80 |
|
|
for (size_t i = 0, n = electrons->size(); i < n; ++i) {
|
81 |
|
|
while ((itdup != enddup) && (*itdup < i)) { ++itdup; }
|
82 |
|
|
if ((itdup != enddup) && (*itdup == i)) continue;
|
83 |
|
|
//result->push_back(electrons->refAt(i).castTo<edm::Ref<reco::GsfElectronCollection> >());
|
84 |
|
|
result->push_back(electrons->refAt(i));
|
85 |
|
|
//result->push_back(electrons->ptrAt(i));
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
pass_ += result->size();
|
89 |
|
|
iEvent.put(result);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
void
|
94 |
|
|
pat::DuplicatedElectronCleaner::endJob() {
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
98 |
|
|
using pat::DuplicatedElectronCleaner;
|
99 |
|
|
DEFINE_FWK_MODULE(DuplicatedElectronCleaner);
|