Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:11

0001 /**
0002   Take as input:
0003      - the electron and photon collections
0004      - the electron and photon pf maps (edm::ValueMap<std::vector<reco::PFCandidateRef>>) pointing to old PF candidates
0005   Produce as output:
0006      - the electron and photon collections as VertexCompositePtrCandidates
0007 */
0008 
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/global/EDProducer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "DataFormats/Common/interface/ValueMap.h"
0016 #include "DataFormats/Common/interface/PtrVector.h"
0017 #include "DataFormats/PatCandidates/interface/Photon.h"
0018 #include "DataFormats/PatCandidates/interface/Electron.h"
0019 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0020 #include "DataFormats/Common/interface/RefToPtr.h"
0021 #include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
0022 
0023 class PFEGammaToCandidate : public edm::global::EDProducer<> {
0024 public:
0025   explicit PFEGammaToCandidate(const edm::ParameterSet &iConfig);
0026   ~PFEGammaToCandidate() override = default;
0027 
0028   void produce(edm::StreamID iID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
0029   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0030 
0031 private:
0032   const edm::EDGetTokenT<edm::View<pat::Photon>> photons_;
0033   const edm::EDGetTokenT<edm::View<pat::Electron>> electrons_;
0034   const edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef>>> photon2pf_, electron2pf_;
0035 
0036   template <typename T>
0037   void run(edm::Event &iEvent,
0038            const edm::EDGetTokenT<edm::View<T>> &colltoken,
0039            const edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef>>> &oldmaptoken,
0040            const std::string &name) const {
0041     auto const &coll = iEvent.get(colltoken);
0042 
0043     edm::Handle<edm::ValueMap<std::vector<reco::PFCandidateRef>>> oldmap;
0044     iEvent.getByToken(oldmaptoken, oldmap);
0045 
0046     auto result = std::make_unique<std::vector<reco::VertexCompositePtrCandidate>>();
0047     for (auto const &obj : coll) {
0048       result->push_back(reco::VertexCompositePtrCandidate(obj));
0049       for (const reco::PFCandidateRef &pfRef : (*oldmap)[obj.originalObjectRef()])
0050         result->back().addDaughter(refToPtr(pfRef));
0051     }
0052     iEvent.put(std::move(result), name);
0053   }
0054 };
0055 
0056 PFEGammaToCandidate::PFEGammaToCandidate(const edm::ParameterSet &iConfig)
0057     : photons_(consumes<edm::View<pat::Photon>>(iConfig.getParameter<edm::InputTag>("photons"))),
0058       electrons_(consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("electrons"))),
0059       photon2pf_(
0060           consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(iConfig.getParameter<edm::InputTag>("photon2pf"))),
0061       electron2pf_(consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
0062           iConfig.getParameter<edm::InputTag>("electron2pf"))) {
0063   produces<std::vector<reco::VertexCompositePtrCandidate>>("photons");
0064   produces<std::vector<reco::VertexCompositePtrCandidate>>("electrons");
0065 }
0066 
0067 void PFEGammaToCandidate::produce(edm::StreamID iID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0068   run<pat::Photon>(iEvent, photons_, photon2pf_, "photons");
0069   run<pat::Electron>(iEvent, electrons_, electron2pf_, "electrons");
0070 }
0071 
0072 void PFEGammaToCandidate::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0073   edm::ParameterSetDescription desc;
0074   desc.add<edm::InputTag>("photons", edm::InputTag("selectedPatPhotons"));
0075   desc.add<edm::InputTag>("electrons", edm::InputTag("selectedPatElectrons"));
0076   desc.add<edm::InputTag>("photon2pf", edm::InputTag("particleBasedIsolation", "gedPhotons"));
0077   desc.add<edm::InputTag>("electron2pf", edm::InputTag("particleBasedIsolation", "gedGsfElectrons"));
0078   descriptions.addWithDefaultLabel(desc);
0079 }
0080 
0081 #include "FWCore/Framework/interface/MakerMacros.h"
0082 DEFINE_FWK_MODULE(PFEGammaToCandidate);