Go to the documentation of this file.00001 #ifndef PhysicsTools_PFCandProducer_IsolatedPFCandidateSelectorDefinition
00002 #define PhysicsTools_PFCandProducer_IsolatedPFCandidateSelectorDefinition
00003
00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00006 #include "PhysicsTools/PFCandProducer/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 isolationValueMapLabels_(cfg.getParameter< std::vector<edm::InputTag> >("isolationValueMaps") ),
00019 isRelative_(cfg.getParameter<bool>("isRelative")),
00020 isCombined_(cfg.getParameter<bool>("isCombined")),
00021 isolationCuts_(cfg.getParameter< std::vector<double> >("isolationCuts")),
00022 combinedIsolationCut_(cfg.getParameter<double>("combinedIsolationCut")) {
00023
00024
00025 if( isolationCuts_.size() != isolationValueMapLabels_.size() )
00026 throw cms::Exception("BadConfiguration")<<"the vector of isolation ValueMaps and the vector of the corresponding cuts must have the same size."<<std::endl;
00027 }
00028
00029 void select( const HandleToCollection & hc,
00030 const edm::EventBase & e,
00031 const edm::EventSetup& s) {
00032 selected_.clear();
00033
00034
00035
00036
00037 std::vector< edm::Handle<IsoMap> >
00038 isoMaps(isolationValueMapLabels_.size());
00039 for(unsigned iMap = 0; iMap<isolationValueMapLabels_.size(); ++iMap) {
00040 e.getByLabel(isolationValueMapLabels_[iMap], isoMaps[iMap]);
00041 }
00042
00043 unsigned key=0;
00044
00045 for( collection::const_iterator pfc = hc->begin();
00046 pfc != hc->end(); ++pfc, ++key) {
00047 reco::PFCandidateRef candidate(hc,key);
00048
00049 bool passed = true;
00050 double isoSum=0.0;
00051 for(unsigned iMap = 0; iMap<isoMaps.size(); ++iMap) {
00052
00053 const IsoMap & isoMap = *(isoMaps[iMap]);
00054
00055 double val = isoMap[candidate];
00056 double cut = isolationCuts_[iMap];
00057 if(isRelative_ && candidate->pt()>0.0) val/=candidate->pt();
00058 isoSum+=val;
00059
00060
00061 if ( !isCombined_ && val>cut ) {
00062 passed = false;
00063 break;
00064 }
00065 }
00066
00067 if ( isCombined_ && isoSum>combinedIsolationCut_ )
00068 {
00069 passed = false;
00070 }
00071
00072 if(passed) {
00073
00074 selected_.push_back( reco::PFCandidate(*pfc) );
00075 reco::PFCandidatePtr ptrToMother( hc, key );
00076 selected_.back().setSourceCandidatePtr( ptrToMother );
00077 }
00078 }
00079 }
00080
00081 private:
00082 std::vector<edm::InputTag> isolationValueMapLabels_;
00083 bool isRelative_, isCombined_;
00084 std::vector<double> isolationCuts_;
00085 double combinedIsolationCut_;
00086 };
00087
00088 }
00089
00090 #endif