Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:00

0001 // -*- C++ -*-
0002 //
0003 // Package:    MuPFIsoEmbedder
0004 // Class:      MuPFIsoEmbedder
0005 //
0006 /**\class MuPFIsoEmbedder MuPFIsoEmbedder.cc RecoMuon/MuPFIsoEmbedder/src/MuPFIsoEmbedder.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Michail Bachtis,32 3-B16,+41227675567,
0015 //         Created:  Thu Jun  9 01:36:17 CEST 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "RecoMuon/MuonIsolation/interface/MuPFIsoHelper.h"
0031 #include "DataFormats/MuonReco/interface/Muon.h"
0032 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0033 #include "FWCore/Framework/interface/ConsumesCollector.h"
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 class MuPFIsoEmbedder : public edm::EDProducer {
0040 public:
0041   explicit MuPFIsoEmbedder(const edm::ParameterSet&);
0042   ~MuPFIsoEmbedder() override;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void produce(edm::Event&, const edm::EventSetup&) override;
0048 
0049   // ----------member data ---------------------------
0050   edm::InputTag muons_;
0051   edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0052   MuPFIsoHelper* helper_;
0053 };
0054 
0055 //
0056 MuPFIsoEmbedder::MuPFIsoEmbedder(const edm::ParameterSet& iConfig)
0057     : muons_(iConfig.getParameter<edm::InputTag>("src")) {
0058   //decide what to read
0059   //Define a map between the isolation and the PSet for the PFHelper
0060   std::map<std::string, edm::ParameterSet> psetMap;
0061 
0062   //First declare what isolation you are going to read
0063   std::vector<std::string> isolationLabels;
0064   isolationLabels.push_back("pfIsolationR03");
0065   isolationLabels.push_back("pfIsoMeanDRProfileR03");
0066   isolationLabels.push_back("pfIsoSumDRProfileR03");
0067   isolationLabels.push_back("pfIsolationR04");
0068   isolationLabels.push_back("pfIsoMeanDRProfileR04");
0069   isolationLabels.push_back("pfIsoSumDRProfileR04");
0070 
0071   //Fill the label,pet map and initialize MuPFIsoHelper
0072   for (std::vector<std::string>::const_iterator label = isolationLabels.begin(); label != isolationLabels.end();
0073        ++label)
0074     psetMap[*label] = iConfig.getParameter<edm::ParameterSet>(*label);
0075   helper_ = new MuPFIsoHelper(psetMap, consumesCollector());
0076   muonToken_ = consumes<reco::MuonCollection>(muons_);
0077   produces<reco::MuonCollection>();
0078 }
0079 
0080 MuPFIsoEmbedder::~MuPFIsoEmbedder() {
0081   // do anything here that needs to be done at desctruction time
0082   // (e.g. close files, deallocate resources etc.)
0083 }
0084 
0085 //
0086 // member functions
0087 //
0088 
0089 // ------------ method called to produce the data  ------------
0090 void MuPFIsoEmbedder::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0091   using namespace edm;
0092   using namespace reco;
0093 
0094   helper_->beginEvent(iEvent);
0095 
0096   edm::Handle<reco::MuonCollection> muons;
0097   iEvent.getByToken(muonToken_, muons);
0098 
0099   auto out = std::make_unique<MuonCollection>();
0100 
0101   for (unsigned int i = 0; i < muons->size(); ++i) {
0102     MuonRef muonRef(muons, i);
0103     Muon muon = muons->at(i);
0104     helper_->embedPFIsolation(muon, muonRef);
0105     out->push_back(muon);
0106   }
0107 
0108   iEvent.put(std::move(out));
0109 }
0110 
0111 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0112 void MuPFIsoEmbedder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0113   //The following says we do not know what parameters are allowed so do no validation
0114   // Please change this to state exactly what you do use, even if it is no parameters
0115   edm::ParameterSetDescription desc;
0116   desc.setUnknown();
0117   descriptions.addDefault(desc);
0118 }
0119 
0120 //define this as a plug-in
0121 DEFINE_FWK_MODULE(MuPFIsoEmbedder);