Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:05

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 
0006 #include "DataFormats/PatCandidates/interface/Electron.h"
0007 #include "DataFormats/Common/interface/ValueMap.h"
0008 
0009 class PatElectronEAIsoCorrectionProducer : public edm::stream::EDProducer<> {
0010 public:
0011   explicit PatElectronEAIsoCorrectionProducer(const edm::ParameterSet& iConfig);
0012   ~PatElectronEAIsoCorrectionProducer() override {}
0013   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0014 
0015 private:
0016   edm::EDGetTokenT<pat::ElectronCollection> patElectronsToken_;
0017   edm::EDGetTokenT<edm::ValueMap<double> > eaIsolatorToken_;
0018 };
0019 
0020 PatElectronEAIsoCorrectionProducer::PatElectronEAIsoCorrectionProducer(const edm::ParameterSet& iConfig)
0021     : patElectronsToken_(consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("patElectrons"))),
0022       eaIsolatorToken_(consumes<edm::ValueMap<double> >(iConfig.getParameter<edm::InputTag>("eaIsolator"))) {
0023   produces<pat::ElectronCollection>();
0024 }
0025 
0026 void PatElectronEAIsoCorrectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0027   edm::Handle<pat::ElectronCollection> patElectrons;
0028   iEvent.getByToken(patElectronsToken_, patElectrons);
0029   edm::Handle<edm::ValueMap<double> > eaIsolator;
0030   iEvent.getByToken(eaIsolatorToken_, eaIsolator);
0031 
0032   std::unique_ptr<pat::ElectronCollection> updatedPatElectrons(new pat::ElectronCollection);
0033 
0034   for (size_t iElectron = 0; iElectron < patElectrons->size(); ++iElectron) {
0035     pat::Electron* updatedPatElectron = patElectrons->at(iElectron).clone();
0036     pat::ElectronRef electronRef(patElectrons, iElectron);
0037     updatedPatElectron->setIsolation(pat::User1Iso, (*eaIsolator)[electronRef]);  // FIXME: hard-coded isolation key
0038     updatedPatElectrons->push_back(*updatedPatElectron);
0039   }
0040 
0041   iEvent.put(std::move(updatedPatElectrons));
0042 }
0043 
0044 #include "FWCore/Framework/interface/MakerMacros.h"
0045 DEFINE_FWK_MODULE(PatElectronEAIsoCorrectionProducer);