Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:26

0001 #ifndef RecoEgamma_ElectronIdentification_ElectronIDExternalProducer_h
0002 #define RecoEgamma_ElectronIdentification_ElectronIDExternalProducer_h
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/Framework/interface/stream/EDProducer.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.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 #include "DataFormats/Common/interface/ValueMap.h"
0016 
0017 template <class algo>
0018 class ElectronIDExternalProducer : public edm::stream::EDProducer<> {
0019 public:
0020   explicit ElectronIDExternalProducer(const edm::ParameterSet& iConfig)
0021       : srcToken_(consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0022         select_(iConfig, consumesCollector()) {
0023     produces<edm::ValueMap<float>>();
0024   }
0025 
0026   ~ElectronIDExternalProducer() override {}
0027 
0028   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0029 
0030 private:
0031   edm::EDGetTokenT<reco::GsfElectronCollection> srcToken_;
0032   algo select_;
0033 };
0034 
0035 template <typename algo>
0036 void ElectronIDExternalProducer<algo>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0037   // read input collection
0038   edm::Handle<reco::GsfElectronCollection> electrons;
0039   iEvent.getByToken(srcToken_, electrons);
0040 
0041   // initialize common selector
0042   select_.newEvent(iEvent, iSetup);
0043 
0044   // prepare room for output
0045   std::vector<float> values;
0046   values.reserve(electrons->size());
0047   for (reco::GsfElectronCollection::const_iterator eleIt = electrons->begin(); eleIt != electrons->end(); ++eleIt) {
0048     values.push_back(float(select_((*eleIt), iEvent, iSetup)));
0049   }
0050 
0051   // fill in the ValueMap
0052   auto out = std::make_unique<edm::ValueMap<float>>();
0053   edm::ValueMap<float>::Filler filler(*out);
0054   filler.insert(electrons, values.begin(), values.end());
0055   filler.fill();
0056   // and put it into the event
0057   iEvent.put(std::move(out));
0058 }
0059 #endif