CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/EgammaAnalysis/ElectronTools/plugins/ElectronIsolatorFromEffectiveArea.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Frameworkfwd.h"
00002 #include "FWCore/Framework/interface/EDFilter.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 
00007 #include "DataFormats/Common/interface/ValueMap.h"
00008 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00009 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00010 
00011 #include "EgammaAnalysis/ElectronTools/interface/ElectronEffectiveArea.h"
00012 
00013 class ElectronIsolatorFromEffectiveArea : public edm::EDFilter {
00014 
00015  public:
00016   typedef edm::ValueMap<double> CandDoubleMap;
00017   typedef ElectronEffectiveArea EEA;
00018   explicit ElectronIsolatorFromEffectiveArea(const edm::ParameterSet&);
00019 
00020  private:
00021   virtual bool filter(edm::Event&, const edm::EventSetup&);
00022   const edm::InputTag gsfElectronTag, pfElectronTag, rhoIsoTag;
00023   const EEA::ElectronEffectiveAreaType modeEEA;
00024   const EEA::ElectronEffectiveAreaTarget targetEEA;
00025   static std::map<std::string,EEA::ElectronEffectiveAreaType> EEA_type();
00026   static std::map<std::string,EEA::ElectronEffectiveAreaTarget> EEA_target();
00027 };
00028 
00029 
00030 
00031 ElectronIsolatorFromEffectiveArea::
00032 ElectronIsolatorFromEffectiveArea(const edm::ParameterSet& config)
00033   : gsfElectronTag( config.getParameter<edm::InputTag>("gsfElectrons") )
00034   , pfElectronTag( config.getParameter<edm::InputTag>("pfElectrons") )
00035   , rhoIsoTag( config.getParameter<edm::InputTag>("rhoIso") )
00036   , modeEEA( EEA_type()[ config.getParameter<std::string>("EffectiveAreaType") ] )
00037   , targetEEA( EEA_target()[ config.getParameter<std::string>("EffectiveAreaTarget") ] )
00038 {  produces<CandDoubleMap>(); }
00039 
00040 
00041 
00042 bool ElectronIsolatorFromEffectiveArea::
00043 filter(edm::Event& event, const edm::EventSetup& )
00044 {
00045   std::auto_ptr<CandDoubleMap> product(new CandDoubleMap());
00046   CandDoubleMap::Filler filler(*product);
00047 
00048   edm::Handle<double> rho;                               event.getByLabel(rhoIsoTag, rho);
00049   edm::Handle<reco::GsfElectronCollection> gsfElectrons; event.getByLabel(gsfElectronTag,gsfElectrons);
00050   edm::Handle<reco::PFCandidateCollection>  pfElectrons; event.getByLabel( pfElectronTag, pfElectrons);
00051   std::vector<double> gsfCorrectionsEA,pfCorrectionsEA;
00052 
00053   if(gsfElectrons.isValid()) {
00054     for ( reco::GsfElectronCollection::const_iterator it = gsfElectrons->begin(); it != gsfElectrons->end(); ++it)
00055       gsfCorrectionsEA.push_back( (*rho) * EEA::GetElectronEffectiveArea( modeEEA, it->superCluster()->eta(), targetEEA ) );
00056     filler.insert(gsfElectrons, gsfCorrectionsEA.begin(), gsfCorrectionsEA.end() );
00057   }
00058 
00059   if(pfElectrons.isValid()) {
00060     for ( reco::PFCandidateCollection::const_iterator it = pfElectrons->begin(); it != pfElectrons->end(); ++it)
00061       pfCorrectionsEA.push_back( (*rho) * EEA::GetElectronEffectiveArea( modeEEA, it->gsfElectronRef()->superCluster()->eta(), targetEEA ) );
00062     filler.insert( pfElectrons,  pfCorrectionsEA.begin(),  pfCorrectionsEA.end() );
00063   }
00064 
00065   filler.fill();
00066   event.put(product);
00067   return true;
00068 }
00069 
00070 
00071 
00072 
00073 // These maps should really be static const members of interface/ElectronEffectiveArea.h
00074 // Here mapping strings to only a subset of the enum
00075 std::map<std::string,ElectronEffectiveArea::ElectronEffectiveAreaType>
00076 ElectronIsolatorFromEffectiveArea::EEA_type()
00077 {
00078   std::map<std::string,EEA::ElectronEffectiveAreaType> m;
00079   m["kEleGammaAndNeutralHadronIso03"] = EEA::kEleGammaAndNeutralHadronIso03;
00080   m["kEleGammaAndNeutralHadronIso04"] = EEA::kEleGammaAndNeutralHadronIso04;
00081   return m;
00082 }
00083 
00084 std::map<std::string,ElectronEffectiveArea::ElectronEffectiveAreaTarget>
00085 ElectronIsolatorFromEffectiveArea::EEA_target()
00086 {
00087   std::map<std::string,EEA::ElectronEffectiveAreaTarget > m;
00088   m["kEleEANoCorr"]     = EEA::kEleEANoCorr;
00089   m["kEleEAData2011"]   = EEA::kEleEAData2011;
00090   m["kEleEASummer11MC"] = EEA::kEleEASummer11MC;
00091   m["kEleEAFall11MC"]   = EEA::kEleEAFall11MC;
00092   m["kEleEAData2012"]   = EEA::kEleEAData2012;
00093   return m;
00094 }
00095 
00096 DEFINE_FWK_MODULE(ElectronIsolatorFromEffectiveArea);