CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducer.h

Go to the documentation of this file.
00001 #ifndef RecoEgamma_ElectronIdentification_ElectronIDExternalProducer_h
00002 #define RecoEgamma_ElectronIdentification_ElectronIDExternalProducer_h
00003 
00004 #include <memory>
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/EDProducer.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Utilities/interface/InputTag.h"
00010 
00011 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00013 
00014 #include "DataFormats/Common/interface/ValueMap.h"
00015 
00016 template<class algo>
00017 class ElectronIDExternalProducer : public edm::EDProducer {
00018  public:
00019    explicit ElectronIDExternalProducer(const edm::ParameterSet& iConfig) :
00020             src_(iConfig.getParameter<edm::InputTag>("src")),
00021             select_(iConfig)
00022    {
00023         produces<edm::ValueMap<float> >();
00024    }
00025 
00026    virtual ~ElectronIDExternalProducer() {}
00027 
00028    void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) ;
00029         
00030  private:       
00031    edm::InputTag src_ ;
00032    algo select_ ;
00033   
00034 };
00035 
00036 template<typename algo>
00037 void ElectronIDExternalProducer<algo>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00038      // read input collection
00039      edm::Handle<reco::GsfElectronCollection> electrons;
00040      iEvent.getByLabel(src_, electrons);
00041 
00042      // initialize common selector
00043      select_.newEvent(iEvent, iSetup);
00044 
00045      // prepare room for output
00046      std::vector<float> values; values.reserve(electrons->size());
00047      for ( reco::GsfElectronCollection::const_iterator eleIt = electrons->begin () ;
00048              eleIt != electrons->end () ;
00049              ++eleIt ) {
00050          values.push_back( float( select_((*eleIt),iEvent,iSetup) ) );
00051      }
00052 
00053      // fill in the ValueMap
00054      std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>());
00055      edm::ValueMap<float>::Filler filler(*out);
00056      filler.insert(electrons, values.begin(), values.end());
00057      filler.fill();
00058      // and put it into the event
00059      iEvent.put(out);
00060 
00061 }
00062 #endif