Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:05

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/stream/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::stream::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   delete helper_;
0084 }
0085 
0086 //
0087 // member functions
0088 //
0089 
0090 // ------------ method called to produce the data  ------------
0091 void MuPFIsoEmbedder::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0092   using namespace edm;
0093   using namespace reco;
0094 
0095   helper_->beginEvent(iEvent);
0096 
0097   edm::Handle<reco::MuonCollection> muons;
0098   iEvent.getByToken(muonToken_, muons);
0099 
0100   auto out = std::make_unique<MuonCollection>();
0101 
0102   for (unsigned int i = 0; i < muons->size(); ++i) {
0103     MuonRef muonRef(muons, i);
0104     Muon muon = muons->at(i);
0105     helper_->embedPFIsolation(muon, muonRef);
0106     out->push_back(muon);
0107   }
0108 
0109   iEvent.put(std::move(out));
0110 }
0111 
0112 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0113 void MuPFIsoEmbedder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0114   //The following says we do not know what parameters are allowed so do no validation
0115   // Please change this to state exactly what you do use, even if it is no parameters
0116   edm::ParameterSetDescription desc;
0117   desc.setUnknown();
0118   descriptions.addDefault(desc);
0119 }
0120 
0121 //define this as a plug-in
0122 DEFINE_FWK_MODULE(MuPFIsoEmbedder);