Go to the documentation of this file.00001 #ifndef CommonTools_ParticleFlow_IsolatedPFCandidateSelectorDefinition
00002 #define CommonTools_ParticleFlow_IsolatedPFCandidateSelectorDefinition
00003
00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00006 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
00007 #include "DataFormats/Common/interface/ValueMap.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009
00010 namespace pf2pat {
00011
00012 class IsolatedPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
00013
00014 public:
00015 typedef edm::ValueMap<double> IsoMap;
00016
00017 IsolatedPFCandidateSelectorDefinition ( const edm::ParameterSet & cfg ) :
00018 isolationValueMapChargedLabels_(cfg.getParameter< std::vector<edm::InputTag> >("isolationValueMapsCharged") ),
00019 isolationValueMapNeutralLabels_(cfg.getParameter< std::vector<edm::InputTag> >("isolationValueMapsNeutral") ),
00020 doDeltaBetaCorrection_(cfg.getParameter<bool>("doDeltaBetaCorrection")),
00021 deltaBetaIsolationValueMap_(cfg.getParameter< edm::InputTag >("deltaBetaIsolationValueMap") ),
00022 deltaBetaFactor_(cfg.getParameter<double>("deltaBetaFactor")),
00023 isRelative_(cfg.getParameter<bool>("isRelative")),
00024 isolationCut_(cfg.getParameter<double>("isolationCut")) {}
00025
00026
00027
00028 void select( const HandleToCollection & hc,
00029 const edm::EventBase & e,
00030 const edm::EventSetup& s) {
00031 selected_.clear();
00032
00033
00034
00035 std::vector< edm::Handle<IsoMap> >
00036 isoMapsCharged(isolationValueMapChargedLabels_.size());
00037 for(unsigned iMap = 0; iMap<isolationValueMapChargedLabels_.size(); ++iMap) {
00038 e.getByLabel(isolationValueMapChargedLabels_[iMap], isoMapsCharged[iMap]);
00039 }
00040
00041
00042
00043 std::vector< edm::Handle<IsoMap> >
00044 isoMapsNeutral(isolationValueMapNeutralLabels_.size());
00045 for(unsigned iMap = 0; iMap<isolationValueMapNeutralLabels_.size(); ++iMap) {
00046 e.getByLabel(isolationValueMapNeutralLabels_[iMap], isoMapsNeutral[iMap]);
00047 }
00048
00049 edm::Handle<IsoMap> dBetaH;
00050 if(doDeltaBetaCorrection_) {
00051 e.getByLabel(deltaBetaIsolationValueMap_, dBetaH);
00052 }
00053
00054 unsigned key=0;
00055 for( collection::const_iterator pfc = hc->begin();
00056 pfc != hc->end(); ++pfc, ++key) {
00057 reco::PFCandidateRef candidate(hc,key);
00058
00059 bool passed = true;
00060 double isoSumCharged=0.0;
00061 double isoSumNeutral=0.0;
00062
00063 for(unsigned iMap = 0; iMap<isoMapsCharged.size(); ++iMap) {
00064 const IsoMap & isoMap = *(isoMapsCharged[iMap]);
00065 double val = isoMap[candidate];
00066 isoSumCharged+=val;
00067 }
00068
00069 for(unsigned iMap = 0; iMap<isoMapsNeutral.size(); ++iMap) {
00070 const IsoMap & isoMap = *(isoMapsNeutral[iMap]);
00071 double val = isoMap[candidate];
00072 isoSumNeutral+=val;
00073 }
00074
00075
00076 if ( doDeltaBetaCorrection_ ) {
00077 const IsoMap& isoMap = *dBetaH;
00078 double dBetaVal = isoMap[candidate];
00079 double dBetaCorIsoSumNeutral = isoSumNeutral + deltaBetaFactor_*dBetaVal;
00080 isoSumNeutral = dBetaCorIsoSumNeutral>0 ? dBetaCorIsoSumNeutral : isoSumNeutral;
00081 }
00082
00083 double isoSum=isoSumCharged+isoSumNeutral;
00084
00085 if( isRelative_ ) {
00086 isoSum /= candidate->pt();
00087 }
00088
00089 if ( isoSum>isolationCut_ ) {
00090 passed = false;
00091 }
00092
00093 if(passed) {
00094
00095 selected_.push_back( reco::PFCandidate(*pfc) );
00096 reco::PFCandidatePtr ptrToMother( hc, key );
00097 selected_.back().setSourceCandidatePtr( ptrToMother );
00098 }
00099 }
00100 }
00101
00102
00103 private:
00104 std::vector<edm::InputTag> isolationValueMapChargedLabels_;
00105 std::vector<edm::InputTag> isolationValueMapNeutralLabels_;
00106 bool doDeltaBetaCorrection_;
00107 edm::InputTag deltaBetaIsolationValueMap_;
00108 double deltaBetaFactor_;
00109 bool isRelative_;
00110 double isolationCut_;
00111 };
00112
00113 }
00114
00115 #endif