Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-05 23:51:42

0001 #ifndef ELECTRONIDSELECTOR
0002 #define ELECTRONIDSELECTOR
0003 
0004 #include <memory>
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 
0012 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0013 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0014 
0015 template <class algo>
0016 struct ElectronIDSelector {
0017 public:
0018   explicit ElectronIDSelector(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC)
0019       : select_(iConfig, iC), threshold_(iConfig.getParameter<double>("threshold")) {}
0020 
0021   virtual ~ElectronIDSelector() {}
0022 
0023   // Collections to be selected
0024   typedef reco::GsfElectronCollection collection;
0025   typedef std::vector<reco::GsfElectronRef> container;
0026   //typedef std::vector<reco::GsfElectron> container ;
0027   typedef container::const_iterator const_iterator;
0028 
0029   //define iterators with above typedef
0030   const_iterator begin() const { return selected_.begin(); }
0031   const_iterator end() const { return selected_.end(); }
0032 
0033   void select(const edm::Handle<reco::GsfElectronCollection>& _electrons,
0034               const edm::Event& iEvent,
0035               const edm::EventSetup& iEs) {
0036     const edm::Handle<reco::GsfElectronCollection>& electrons = _electrons;
0037     selected_.clear();
0038     select_.newEvent(iEvent, iEs);
0039     // Loop over electrons
0040     unsigned int i = 0;
0041     for (reco::GsfElectronCollection::const_iterator eleIt = electrons->begin(); eleIt != electrons->end(); ++eleIt) {
0042       edm::Ref<reco::GsfElectronCollection> electronRef(electrons, i);
0043       if (select_((*eleIt), iEvent, iEs) > threshold_)
0044         selected_.push_back(electronRef);
0045       //selected_.push_back ( & * eleIt) ;
0046       ++i;
0047     }
0048   }
0049 
0050   static void fillPSetDescription(edm::ParameterSetDescription& desc) {
0051     desc.add<double>("threshold", -1.0);
0052     algo::fillPSetDescription(desc);
0053   }
0054 
0055 private:
0056   container selected_;
0057   algo select_;
0058   double threshold_;
0059 };
0060 
0061 #endif