CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/PhysicsTools/IsolationAlgos/src/EventDependentAbsVetos.cc

Go to the documentation of this file.
00001 
00002 #include "PhysicsTools/IsolationAlgos/interface/EventDependentAbsVetos.h"
00003 #include "DataFormats/Common/interface/View.h"
00004 #include "DataFormats/Candidate/interface/Candidate.h"
00005 #include "DataFormats/JetReco/interface/PFJet.h"
00006 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00007 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00008 #include "DataFormats/Common/interface/AssociationMap.h"
00009 #include "DataFormats/Math/interface/deltaR.h"
00010 
00011 bool 
00012 reco::isodeposit::OtherCandidatesDeltaRVeto::veto(double eta, double phi, float value) const 
00013 {
00014     for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
00015         if (::deltaR2(it->eta(), it->phi(), eta, phi) < deltaR2_) return true;
00016     }
00017     return false;
00018 }
00019 
00020 void
00021 reco::isodeposit::OtherCandidatesDeltaRVeto::setEvent(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
00022     items_.clear();
00023     edm::Handle<edm::View<reco::Candidate> > candidates;
00024     iEvent.getByLabel(src_, candidates);
00025     for (edm::View<reco::Candidate>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
00026         items_.push_back(Direction(it->eta(), it->phi()));
00027     }
00028 }
00029 
00030 bool 
00031 reco::isodeposit::OtherCandVeto::veto(double eta, double phi, float value) const 
00032 {
00033     for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
00034         veto_->centerOn(it->eta(), it->phi());
00035         if ( veto_->veto(eta,phi,value) ) return true;
00036     }
00037     return false;
00038 }
00039 
00040 void
00041 reco::isodeposit::OtherCandVeto::setEvent(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
00042     items_.clear();
00043     edm::Handle<edm::View<reco::Candidate> > candidates;
00044     iEvent.getByLabel(src_, candidates);
00045     for (edm::View<reco::Candidate>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
00046         items_.push_back(Direction(it->eta(), it->phi()));
00047     }
00048 }
00049 
00050 bool 
00051 reco::isodeposit::OtherJetConstituentsDeltaRVeto::veto(double eta, double phi, float value) const 
00052 {
00053     for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
00054         if (::deltaR2(it->eta(), it->phi(), eta, phi) < dR2constituent_) return true;
00055     }
00056     return false;
00057 }
00058 
00059 void
00060 reco::isodeposit::OtherJetConstituentsDeltaRVeto::setEvent(const edm::Event& evt, const edm::EventSetup& es) 
00061 {
00062     //std::cout << "<OtherJetConstituentsDeltaRVeto::setEvent>:" << std::endl;
00063     evt_ = &evt;
00064 }
00065 void
00066 reco::isodeposit::OtherJetConstituentsDeltaRVeto::initialize()
00067 {
00068     //std::cout << "<OtherJetConstituentsDeltaRVeto::initialize>:" << std::endl;
00069     //std::cout << " vetoDir: eta = " << vetoDir_.eta() << ", phi = " << vetoDir_.phi() << std::endl;
00070     assert(evt_);
00071     items_.clear();
00072     edm::Handle<reco::PFJetCollection> jets;
00073     evt_->getByLabel(srcJets_, jets);
00074     typedef edm::AssociationMap<edm::OneToMany<std::vector<reco::PFJet>, std::vector<reco::PFCandidate>, unsigned int> > JetToPFCandidateAssociation;
00075     edm::Handle<JetToPFCandidateAssociation> jetToPFCandMap;
00076     evt_->getByLabel(srcPFCandAssocMap_, jetToPFCandMap);
00077     double dR2min = dR2jet_;
00078     reco::PFJetRef matchedJet;
00079     size_t numJets = jets->size();
00080     for ( size_t jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
00081       reco::PFJetRef jet(jets, jetIndex);
00082       double dR2 = ::deltaR2(vetoDir_.eta(), vetoDir_.phi(), jet->eta(), jet->phi());
00083       //std::cout << "jet #" << jetIndex << ": Pt = " << jet->pt() << ", eta = " << jet->eta() << ", phi = " << jet->phi() << " (dR = " << sqrt(dR2) << ")" << std::endl;
00084       if ( dR2 < dR2min ) {
00085         matchedJet = jet;
00086         dR2min = dR2;
00087       }
00088     }
00089     if ( matchedJet.isNonnull() ) {
00090       edm::RefVector<reco::PFCandidateCollection> pfCandsMappedToJet = (*jetToPFCandMap)[matchedJet];
00091       int idx = 0;
00092       for ( edm::RefVector<reco::PFCandidateCollection>::const_iterator pfCand = pfCandsMappedToJet.begin();
00093             pfCand != pfCandsMappedToJet.end(); ++pfCand ) {
00094         //std::cout << "pfCand #" << idx << ": Pt = " << (*pfCand)->pt() << ", eta = " << (*pfCand)->eta() << ", phi = " << (*pfCand)->phi() << std::endl;
00095         items_.push_back(Direction((*pfCand)->eta(), (*pfCand)->phi()));
00096         ++idx;
00097       }
00098     }
00099 }
00100 
00101 void 
00102 reco::isodeposit::OtherJetConstituentsDeltaRVeto::centerOn(double eta, double phi) 
00103 { 
00104     //std::cout << "<OtherJetConstituentsDeltaRVeto::centerOn>:" << std::endl;
00105     //std::cout << " eta = " << eta << std::endl;
00106     //std::cout << " phi = " << phi << std::endl;
00107     vetoDir_ = Direction(eta,phi); 
00108     initialize();
00109 }