File indexing completed on 2024-04-06 12:23:58
0001 #include "PhysicsTools/PatAlgos/interface/OverlapTest.h"
0002
0003 #include <algorithm>
0004 #include "DataFormats/Math/interface/deltaR.h"
0005 #include "DataFormats/Candidate/interface/OverlapChecker.h"
0006
0007 using namespace pat::helper;
0008
0009 void BasicOverlapTest::readInput(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0010 iEvent.getByToken(srcToken_, candidates_);
0011 isPreselected_.resize(candidates_->size());
0012 size_t idx = 0;
0013 for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
0014 isPreselected_[idx] = presel_(*it);
0015 }
0016
0017
0018 }
0019
0020 bool BasicOverlapTest::fillOverlapsForItem(const reco::Candidate &item,
0021 reco::CandidatePtrVector &overlapsToFill) const {
0022 size_t idx = 0;
0023 std::vector<std::pair<float, size_t> > matches;
0024 for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
0025 if (!isPreselected_[idx])
0026 continue;
0027 double dr = reco::deltaR(item, *it);
0028 if (dr < deltaR_) {
0029 if (checkRecoComponents_) {
0030 OverlapChecker overlaps;
0031 if (!overlaps(item, *it))
0032 continue;
0033 }
0034 if (!pairCut_(pat::DiObjectProxy(item, *it)))
0035 continue;
0036 matches.push_back(std::make_pair(dr, idx));
0037 }
0038 }
0039
0040 if (matches.empty())
0041 return false;
0042
0043
0044 std::sort(matches.begin(), matches.end());
0045
0046 for (std::vector<std::pair<float, size_t> >::const_iterator it = matches.begin(); it != matches.end(); ++it) {
0047 overlapsToFill.push_back(candidates_->ptrAt(it->second));
0048 }
0049 return true;
0050 }
0051
0052 bool OverlapBySuperClusterSeed::fillOverlapsForItem(const reco::Candidate &item,
0053 reco::CandidatePtrVector &overlapsToFill) const {
0054 const reco::RecoCandidate *input = dynamic_cast<const reco::RecoCandidate *>(&item);
0055 if (input == nullptr)
0056 throw cms::Exception("Type Error") << "Input to OverlapBySuperClusterSeed is not a RecoCandidate. "
0057 << "It's a " << typeid(item).name() << "\n";
0058 reco::SuperClusterRef mySC = input->superCluster();
0059 if (mySC.isNull() || !mySC.isAvailable()) {
0060 throw cms::Exception("Bad Reference")
0061 << "Input to OverlapBySuperClusterSeed has a null or dangling superCluster reference\n";
0062 }
0063 const reco::CaloClusterPtr &mySeed = mySC->seed();
0064 if (mySeed.isNull()) {
0065 throw cms::Exception("Bad Reference")
0066 << "Input to OverlapBySuperClusterSeed has a null superCluster seed reference\n";
0067 }
0068 bool hasOverlaps = false;
0069 size_t idx = 0;
0070
0071 for (reco::CandidateView::const_iterator it = others_->begin(); it != others_->end(); ++it, ++idx) {
0072 const reco::RecoCandidate *other = dynamic_cast<const reco::RecoCandidate *>(&*it);
0073 reco::SuperClusterRef otherSc = other->superCluster();
0074 if (otherSc.isNull() || !otherSc.isAvailable()) {
0075 throw cms::Exception("Bad Reference")
0076 << "One item in the OverlapBySuperClusterSeed input list has a null or dangling superCluster reference\n";
0077 }
0078 if (mySeed == otherSc->seed()) {
0079 overlapsToFill.push_back(others_->ptrAt(idx));
0080 hasOverlaps = true;
0081 }
0082 }
0083 return hasOverlaps;
0084 }