CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DuplicatedElectronCleaner.cc
Go to the documentation of this file.
1 //
2 //
3 
24 //#include "DataFormats/Common/interface/RefVector.h"
26 //#include "DataFormats/Common/interface/PtrVector.h"
27 
31 
32 namespace pat {
34  public:
36  ~DuplicatedElectronCleaner() override;
37 
38  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const final;
39 
40  private:
43  mutable std::atomic<uint64_t> try_, pass_;
44  };
45 } // namespace pat
46 
48  : electronSrcToken_(consumes<edm::View<reco::GsfElectron>>(iConfig.getParameter<edm::InputTag>("electronSource"))),
49  duplicateRemover_(),
50  try_(0),
51  pass_(0) {
52  //produces<edm::RefVector<reco::GsfElectronCollection> >();
53  produces<edm::RefToBaseVector<reco::GsfElectron>>();
54  //produces<edm::PtrVector<reco::GsfElectron> >();
55 }
56 
58 
60  using namespace edm;
62  iEvent.getByToken(electronSrcToken_, electrons);
63  try_ += electrons->size();
64 
65  //auto result = std::make_unique<RefVector<reco::GsfElectronCollection>>();
66  auto result = std::make_unique<RefToBaseVector<reco::GsfElectron>>();
67  //auto result = std::make_unique<PtrVector<reco::GsfElectron>>();
68  std::unique_ptr<std::vector<size_t>> duplicates = duplicateRemover_.duplicatesToRemove(*electrons);
69 
70  std::vector<size_t>::const_iterator itdup = duplicates->begin(), enddup = duplicates->end();
71  for (size_t i = 0, n = electrons->size(); i < n; ++i) {
72  while ((itdup != enddup) && (*itdup < i)) {
73  ++itdup;
74  }
75  if ((itdup != enddup) && (*itdup == i))
76  continue;
77  //result->push_back(electrons->refAt(i).castTo<edm::Ref<reco::GsfElectronCollection> >());
78  result->push_back(electrons->refAt(i));
79  //result->push_back(electrons->ptrAt(i));
80  }
81  pass_ += result->size();
82  iEvent.put(std::move(result));
83 }
84 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Remove duplicates from the list of electrons.
tuple result
Definition: mps_fire.py:311
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
DuplicatedElectronCleaner(const edm::ParameterSet &iConfig)
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const final
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > electronSrcToken_
const pat::DuplicatedElectronRemover duplicateRemover_