CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMuon/MuonIsolation/plugins/MuPFIsoEmbedder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuPFIsoEmbedder
00004 // Class:      MuPFIsoEmbedder
00005 // 
00013 //
00014 // Original Author:  Michail Bachtis,32 3-B16,+41227675567,
00015 //         Created:  Thu Jun  9 01:36:17 CEST 2011
00016 // $Id: MuPFIsoEmbedder.cc,v 1.3 2013/02/25 21:46:26 chrjones Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "RecoMuon/MuonIsolation/interface/MuPFIsoHelper.h"
00033 #include "DataFormats/MuonReco/interface/Muon.h"
00034 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00035 
00036 //
00037 // class declaration
00038 //
00039 
00040 class MuPFIsoEmbedder : public edm::EDProducer {
00041    public:
00042       explicit MuPFIsoEmbedder(const edm::ParameterSet&);
00043       ~MuPFIsoEmbedder();
00044 
00045       static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00046 
00047    private:
00048       virtual void produce(edm::Event&, const edm::EventSetup&);
00049       
00050 
00051       // ----------member data ---------------------------
00052   edm::InputTag muons_;
00053 
00054   MuPFIsoHelper *helper_;
00055 
00056 };
00057 
00058 
00059 
00060 
00061 //
00062 MuPFIsoEmbedder::MuPFIsoEmbedder(const edm::ParameterSet& iConfig):
00063   muons_(iConfig.getParameter<edm::InputTag>("src"))
00064 {
00065 
00066   //decide what to read
00067     //Define a map between the isolation and the PSet for the PFHelper
00068     std::map<std::string,edm::ParameterSet> psetMap;
00069 
00070     //First declare what isolation you are going to read
00071     std::vector<std::string> isolationLabels;
00072     isolationLabels.push_back("pfIsolationR03");
00073     isolationLabels.push_back("pfIsoMeanDRProfileR03");
00074     isolationLabels.push_back("pfIsoSumDRProfileR03");
00075     isolationLabels.push_back("pfIsolationR04");
00076     isolationLabels.push_back("pfIsoMeanDRProfileR04");
00077     isolationLabels.push_back("pfIsoSumDRProfileR04");
00078 
00079     //Fill the label,pet map and initialize MuPFIsoHelper
00080     for( std::vector<std::string>::const_iterator label = isolationLabels.begin();label != isolationLabels.end();++label)
00081       psetMap[*label] =iConfig.getParameter<edm::ParameterSet >(*label); 
00082 
00083     helper_ = new MuPFIsoHelper(psetMap);
00084 
00085   produces<reco::MuonCollection>();
00086 }
00087 
00088 
00089 MuPFIsoEmbedder::~MuPFIsoEmbedder()
00090 {
00091  
00092    // do anything here that needs to be done at desctruction time
00093    // (e.g. close files, deallocate resources etc.)
00094 
00095 }
00096 
00097 
00098 //
00099 // member functions
00100 //
00101 
00102 // ------------ method called to produce the data  ------------
00103 void
00104 MuPFIsoEmbedder::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00105 {
00106    using namespace edm;
00107    using namespace reco;
00108 
00109 
00110    helper_->beginEvent(iEvent);
00111   
00112    edm::Handle<reco::MuonCollection > muons;
00113    iEvent.getByLabel(muons_,muons);
00114 
00115 
00116    std::auto_ptr<MuonCollection> out(new MuonCollection);
00117 
00118    for(unsigned int i=0;i<muons->size();++i) {
00119      MuonRef muonRef(muons,i);
00120      Muon muon = muons->at(i);
00121      helper_->embedPFIsolation(muon,muonRef);
00122      out->push_back(muon);
00123    }
00124 
00125    iEvent.put(out);
00126 }
00127 
00128 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00129 void
00130 MuPFIsoEmbedder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00131   //The following says we do not know what parameters are allowed so do no validation
00132   // Please change this to state exactly what you do use, even if it is no parameters
00133   edm::ParameterSetDescription desc;
00134   desc.setUnknown();
00135   descriptions.addDefault(desc);
00136 }
00137 
00138 //define this as a plug-in
00139 DEFINE_FWK_MODULE(MuPFIsoEmbedder);