00001 #include "PhysicsTools/PatUtils/plugins/ShiftedPFCandidateProducerForPFMEtMVA.h" 00002 00003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" 00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" 00005 #include "DataFormats/Common/interface/Handle.h" 00006 #include "DataFormats/Common/interface/View.h" 00007 #include "DataFormats/Math/interface/deltaR.h" 00008 00009 ShiftedPFCandidateProducerForPFMEtMVA::ShiftedPFCandidateProducerForPFMEtMVA(const edm::ParameterSet& cfg) 00010 : moduleLabel_(cfg.getParameter<std::string>("@module_label")) 00011 { 00012 srcPFCandidates_ = cfg.getParameter<edm::InputTag>("srcPFCandidates"); 00013 srcUnshiftedObjects_ = cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"); 00014 srcShiftedObjects_ = cfg.getParameter<edm::InputTag>("srcShiftedObjects"); 00015 00016 dRmatch_PFCandidate_ = cfg.getParameter<double>("dRmatch_PFCandidate"); 00017 dRmatch_Object_ = cfg.exists("dRmatch_Object") ? 00018 cfg.getParameter<double>("dRmatch_Object") : 0.1; 00019 00020 produces<reco::PFCandidateCollection>(); 00021 } 00022 00023 ShiftedPFCandidateProducerForPFMEtMVA::~ShiftedPFCandidateProducerForPFMEtMVA() 00024 { 00025 // nothing to be done yet... 00026 } 00027 00028 void ShiftedPFCandidateProducerForPFMEtMVA::produce(edm::Event& evt, const edm::EventSetup& es) 00029 { 00030 edm::Handle<reco::PFCandidateCollection> originalPFCandidates; 00031 evt.getByLabel(srcPFCandidates_, originalPFCandidates); 00032 00033 typedef edm::View<reco::Candidate> CandidateView; 00034 00035 edm::Handle<CandidateView> unshiftedObjects; 00036 evt.getByLabel(srcUnshiftedObjects_, unshiftedObjects); 00037 00038 edm::Handle<CandidateView> shiftedObjects; 00039 evt.getByLabel(srcShiftedObjects_, shiftedObjects); 00040 00041 objects_.clear(); 00042 00043 for ( CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin(); 00044 unshiftedObject != unshiftedObjects->end(); ++unshiftedObject ) { 00045 bool isMatched_Object = false; 00046 double dRbestMatch_Object = 1.e+3; 00047 reco::Candidate::LorentzVector shiftedObjectP4_matched; 00048 for ( CandidateView::const_iterator shiftedObject = shiftedObjects->begin(); 00049 shiftedObject != shiftedObjects->end(); ++shiftedObject ) { 00050 double dR = deltaR(unshiftedObject->p4(), shiftedObject->p4()); 00051 if ( dR < dRmatch_Object_ && dR < dRbestMatch_Object ) { 00052 shiftedObjectP4_matched = shiftedObject->p4(); 00053 isMatched_Object = true; 00054 dRbestMatch_Object = dR; 00055 } 00056 } 00057 if ( isMatched_Object ) { 00058 objects_.push_back(objectEntryType(shiftedObjectP4_matched, unshiftedObject->p4(), dRbestMatch_Object)); 00059 } 00060 } 00061 00062 std::auto_ptr<reco::PFCandidateCollection> shiftedPFCandidates(new reco::PFCandidateCollection); 00063 00064 for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin(); 00065 originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) { 00066 00067 double shift = 0.; 00068 bool applyShift = false; 00069 double dRbestMatch_PFCandidate = 1.e+3; 00070 for ( std::vector<objectEntryType>::const_iterator object = objects_.begin(); 00071 object != objects_.end(); ++object ) { 00072 if ( !object->isValidMatch_ ) continue; 00073 double dR = deltaR(originalPFCandidate->p4(), object->unshiftedObjectP4_); 00074 if ( dR < dRmatch_PFCandidate_ && dR < dRbestMatch_PFCandidate ) { 00075 shift = object->shift_; 00076 applyShift = true; 00077 dRbestMatch_PFCandidate = dR; 00078 } 00079 } 00080 00081 reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4(); 00082 if ( applyShift ) shiftedPFCandidateP4 *= (1. + shift); 00083 00084 reco::PFCandidate shiftedPFCandidate(*originalPFCandidate); 00085 shiftedPFCandidate.setP4(shiftedPFCandidateP4); 00086 00087 shiftedPFCandidates->push_back(shiftedPFCandidate); 00088 } 00089 00090 evt.put(shiftedPFCandidates); 00091 } 00092 00093 #include "FWCore/Framework/interface/MakerMacros.h" 00094 00095 DEFINE_FWK_MODULE(ShiftedPFCandidateProducerForPFMEtMVA); 00096 00097 00098