CMS 3D CMS Logo

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:
35  explicit DuplicatedElectronCleaner(const edm::ParameterSet& iConfig);
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 
Remove duplicates from the list of electrons.
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
T try_(Func f, Response r)
DuplicatedElectronCleaner(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const final
fixed size matrix
HLT enums.
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > electronSrcToken_
def move(src, dest)
Definition: eostools.py:511
const pat::DuplicatedElectronRemover duplicateRemover_