Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:33

0001 
0002 #include "PhysicsTools/IsolationAlgos/interface/EventDependentAbsVetos.h"
0003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0005 #include "DataFormats/Math/interface/deltaR.h"
0006 
0007 bool reco::isodeposit::OtherCandidatesDeltaRVeto::veto(double eta, double phi, float value) const {
0008   for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
0009     if (::deltaR2(it->eta(), it->phi(), eta, phi) < deltaR2_)
0010       return true;
0011   }
0012   return false;
0013 }
0014 
0015 void reco::isodeposit::OtherCandidatesDeltaRVeto::setEvent(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0016   items_.clear();
0017   edm::Handle<edm::View<reco::Candidate> > candidates;
0018   iEvent.getByToken(src_, candidates);
0019   for (edm::View<reco::Candidate>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
0020     items_.push_back(Direction(it->eta(), it->phi()));
0021   }
0022 }
0023 
0024 bool reco::isodeposit::OtherCandVeto::veto(double eta, double phi, float value) const {
0025   for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
0026     veto_->centerOn(it->eta(), it->phi());
0027     if (veto_->veto(eta, phi, value))
0028       return true;
0029   }
0030   return false;
0031 }
0032 
0033 void reco::isodeposit::OtherCandVeto::setEvent(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0034   items_.clear();
0035   edm::Handle<edm::View<reco::Candidate> > candidates;
0036   iEvent.getByToken(src_, candidates);
0037   for (edm::View<reco::Candidate>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
0038     items_.push_back(Direction(it->eta(), it->phi()));
0039   }
0040 }
0041 
0042 bool reco::isodeposit::OtherJetConstituentsDeltaRVeto::veto(double eta, double phi, float value) const {
0043   for (std::vector<Direction>::const_iterator it = items_.begin(), ed = items_.end(); it != ed; ++it) {
0044     if (::deltaR2(it->eta(), it->phi(), eta, phi) < dR2constituent_)
0045       return true;
0046   }
0047   return false;
0048 }
0049 
0050 void reco::isodeposit::OtherJetConstituentsDeltaRVeto::setEvent(const edm::Event &evt, const edm::EventSetup &es) {
0051   //std::cout << "<OtherJetConstituentsDeltaRVeto::setEvent>:" << std::endl;
0052   evt_ = &evt;
0053 }
0054 void reco::isodeposit::OtherJetConstituentsDeltaRVeto::initialize() {
0055   //std::cout << "<OtherJetConstituentsDeltaRVeto::initialize>:" << std::endl;
0056   //std::cout << " vetoDir: eta = " << vetoDir_.eta() << ", phi = " << vetoDir_.phi() << std::endl;
0057   assert(evt_);
0058   items_.clear();
0059   edm::Handle<reco::PFJetCollection> jets;
0060   evt_->getByToken(srcJets_, jets);
0061   edm::Handle<JetToPFCandidateAssociation> jetToPFCandMap;
0062   evt_->getByToken(srcPFCandAssocMap_, jetToPFCandMap);
0063   double dR2min = dR2jet_;
0064   reco::PFJetRef matchedJet;
0065   size_t numJets = jets->size();
0066   for (size_t jetIndex = 0; jetIndex < numJets; ++jetIndex) {
0067     reco::PFJetRef jet(jets, jetIndex);
0068     double dR2 = ::deltaR2(vetoDir_.eta(), vetoDir_.phi(), jet->eta(), jet->phi());
0069     //std::cout << "jet #" << jetIndex << ": Pt = " << jet->pt() << ", eta = " << jet->eta() << ", phi = " << jet->phi() << " (dR = " << sqrt(dR2) << ")" << std::endl;
0070     if (dR2 < dR2min) {
0071       matchedJet = jet;
0072       dR2min = dR2;
0073     }
0074   }
0075   if (matchedJet.isNonnull()) {
0076     edm::RefVector<reco::PFCandidateCollection> pfCandsMappedToJet = (*jetToPFCandMap)[matchedJet];
0077     int idx = 0;
0078     for (edm::RefVector<reco::PFCandidateCollection>::const_iterator pfCand = pfCandsMappedToJet.begin();
0079          pfCand != pfCandsMappedToJet.end();
0080          ++pfCand) {
0081       //std::cout << "pfCand #" << idx << ": Pt = " << (*pfCand)->pt() << ", eta = " << (*pfCand)->eta() << ", phi = " << (*pfCand)->phi() << std::endl;
0082       items_.push_back(Direction((*pfCand)->eta(), (*pfCand)->phi()));
0083       ++idx;
0084     }
0085   }
0086 }
0087 
0088 void reco::isodeposit::OtherJetConstituentsDeltaRVeto::centerOn(double eta, double phi) {
0089   //std::cout << "<OtherJetConstituentsDeltaRVeto::centerOn>:" << std::endl;
0090   //std::cout << " eta = " << eta << std::endl;
0091   //std::cout << " phi = " << phi << std::endl;
0092   vetoDir_ = Direction(eta, phi);
0093   initialize();
0094 }