CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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.2 2012/07/21 00:33:38 bachtis 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 beginJob() ;
00049       virtual void produce(edm::Event&, const edm::EventSetup&);
00050       virtual void endJob() ;
00051       
00052       virtual void beginRun(edm::Run&, edm::EventSetup const&);
00053       virtual void endRun(edm::Run&, edm::EventSetup const&);
00054       virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
00055       virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
00056 
00057 
00058       // ----------member data ---------------------------
00059   edm::InputTag muons_;
00060 
00061   MuPFIsoHelper *helper_;
00062 
00063 };
00064 
00065 
00066 
00067 
00068 //
00069 MuPFIsoEmbedder::MuPFIsoEmbedder(const edm::ParameterSet& iConfig):
00070   muons_(iConfig.getParameter<edm::InputTag>("src"))
00071 {
00072 
00073   //decide what to read
00074     //Define a map between the isolation and the PSet for the PFHelper
00075     std::map<std::string,edm::ParameterSet> psetMap;
00076 
00077     //First declare what isolation you are going to read
00078     std::vector<std::string> isolationLabels;
00079     isolationLabels.push_back("pfIsolationR03");
00080     isolationLabels.push_back("pfIsoMeanDRProfileR03");
00081     isolationLabels.push_back("pfIsoSumDRProfileR03");
00082     isolationLabels.push_back("pfIsolationR04");
00083     isolationLabels.push_back("pfIsoMeanDRProfileR04");
00084     isolationLabels.push_back("pfIsoSumDRProfileR04");
00085 
00086     //Fill the label,pet map and initialize MuPFIsoHelper
00087     for( std::vector<std::string>::const_iterator label = isolationLabels.begin();label != isolationLabels.end();++label)
00088       psetMap[*label] =iConfig.getParameter<edm::ParameterSet >(*label); 
00089 
00090     helper_ = new MuPFIsoHelper(psetMap);
00091 
00092   produces<reco::MuonCollection>();
00093 }
00094 
00095 
00096 MuPFIsoEmbedder::~MuPFIsoEmbedder()
00097 {
00098  
00099    // do anything here that needs to be done at desctruction time
00100    // (e.g. close files, deallocate resources etc.)
00101 
00102 }
00103 
00104 
00105 //
00106 // member functions
00107 //
00108 
00109 // ------------ method called to produce the data  ------------
00110 void
00111 MuPFIsoEmbedder::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00112 {
00113    using namespace edm;
00114    using namespace reco;
00115 
00116 
00117    helper_->beginEvent(iEvent);
00118   
00119    edm::Handle<reco::MuonCollection > muons;
00120    iEvent.getByLabel(muons_,muons);
00121 
00122 
00123    std::auto_ptr<MuonCollection> out(new MuonCollection);
00124 
00125    for(unsigned int i=0;i<muons->size();++i) {
00126      MuonRef muonRef(muons,i);
00127      Muon muon = muons->at(i);
00128      helper_->embedPFIsolation(muon,muonRef);
00129      out->push_back(muon);
00130    }
00131 
00132    iEvent.put(out);
00133 }
00134 
00135 // ------------ method called once each job just before starting event loop  ------------
00136 void 
00137 MuPFIsoEmbedder::beginJob()
00138 {
00139 }
00140 
00141 // ------------ method called once each job just after ending the event loop  ------------
00142 void 
00143 MuPFIsoEmbedder::endJob() {
00144 }
00145 
00146 // ------------ method called when starting to processes a run  ------------
00147 void 
00148 MuPFIsoEmbedder::beginRun(edm::Run&, edm::EventSetup const&)
00149 {
00150 }
00151 
00152 // ------------ method called when ending the processing of a run  ------------
00153 void 
00154 MuPFIsoEmbedder::endRun(edm::Run&, edm::EventSetup const&)
00155 {
00156 }
00157 
00158 // ------------ method called when starting to processes a luminosity block  ------------
00159 void 
00160 MuPFIsoEmbedder::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
00161 {
00162 }
00163 
00164 // ------------ method called when ending the processing of a luminosity block  ------------
00165 void 
00166 MuPFIsoEmbedder::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
00167 {
00168 }
00169 
00170 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00171 void
00172 MuPFIsoEmbedder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00173   //The following says we do not know what parameters are allowed so do no validation
00174   // Please change this to state exactly what you do use, even if it is no parameters
00175   edm::ParameterSetDescription desc;
00176   desc.setUnknown();
00177   descriptions.addDefault(desc);
00178 }
00179 
00180 //define this as a plug-in
00181 DEFINE_FWK_MODULE(MuPFIsoEmbedder);