CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ElectronMatchedCandidateProducer.cc
Go to the documentation of this file.
7 
8 #include <memory>
9 
11 public:
13 
14 private:
15  void beginJob() override;
16  void produce(edm::Event &, const edm::EventSetup &) override;
17  void endJob() override;
18 
19  // ----------member data ---------------------------
20 
24 };
25 
27  const edm::InputTag allelectrons("gsfElectrons");
28  electronCollectionToken_ = consumes<edm::View<reco::GsfElectron>>(
29  params.getUntrackedParameter<edm::InputTag>("ReferenceElectronCollection", allelectrons));
30  scCollectionToken_ = consumes<edm::View<reco::Candidate>>(params.getParameter<edm::InputTag>("src"));
31 
32  delRMatchingCut_ = params.getUntrackedParameter<double>("deltaR", 0.30);
33 
34  produces<edm::PtrVector<reco::Candidate>>();
35  produces<edm::RefToBaseVector<reco::Candidate>>();
36 }
37 
38 //
39 // member functions
40 //
41 
42 // ------------ method called to produce the data ------------
43 
45  // Create the output collection
46  auto outColRef = std::make_unique<edm::RefToBaseVector<reco::Candidate>>();
47  auto outColPtr = std::make_unique<edm::PtrVector<reco::Candidate>>();
48 
49  // Read electrons
51  event.getByToken(electronCollectionToken_, electrons);
52 
53  //Read candidates
55  event.getByToken(scCollectionToken_, recoCandColl);
56 
57  unsigned int counter = 0;
58 
59  // Loop over candidates
60  for (edm::View<reco::Candidate>::const_iterator scIt = recoCandColl->begin(); scIt != recoCandColl->end();
61  ++scIt, ++counter) {
62  // Now loop over electrons
63  for (edm::View<reco::GsfElectron>::const_iterator elec = electrons->begin(); elec != electrons->end(); ++elec) {
64  reco::SuperClusterRef eSC = elec->superCluster();
65 
66  double dRval = reco::deltaR((float)eSC->eta(), (float)eSC->phi(), scIt->eta(), scIt->phi());
67 
68  if (dRval < delRMatchingCut_) {
69  //outCol->push_back( *scIt );
70  outColRef->push_back(recoCandColl->refAt(counter));
71  outColPtr->push_back(recoCandColl->ptrAt(counter));
72  } // end if loop
73  } // end electron loop
74 
75  } // end candidate loop
76 
77  event.put(std::move(outColRef));
78  event.put(std::move(outColPtr));
79 }
80 
81 // ------ method called once each job just before starting event loop ---
82 
84 
86 
87 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
def move
Definition: eostools.py:511
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::EDGetTokenT< edm::View< reco::Candidate > > scCollectionToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ElectronMatchedCandidateProducer(const edm::ParameterSet &)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
static std::atomic< unsigned int > counter
edm::EDGetTokenT< edm::View< reco::GsfElectron > > electronCollectionToken_