CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/PhysicsTools/PatAlgos/src/OverlapTest.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/PatAlgos/interface/OverlapTest.h"
00002 
00003 #include <algorithm>
00004 #include "DataFormats/Math/interface/deltaR.h"
00005 #include "DataFormats/Candidate/interface/OverlapChecker.h"
00006 
00007 using namespace pat::helper;
00008 
00009 void
00010 BasicOverlapTest::readInput(const edm::Event & iEvent, const edm::EventSetup &iSetup) 
00011 {
00012     iEvent.getByLabel(src_, candidates_);
00013     isPreselected_.resize(candidates_->size());
00014     size_t idx = 0;
00015     for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
00016         isPreselected_[idx] = presel_(*it);
00017     }
00018     // Yes, I could use std::transform. But would people like it?
00019     // https://www.sgi.com/tech/stl/transform.html
00020 }
00021 
00022 bool
00023 BasicOverlapTest::fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const 
00024 {
00025     size_t idx = 0;
00026     std::vector<std::pair<float,size_t> > matches;
00027     for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
00028         if (!isPreselected_[idx]) continue;
00029         double dr = reco::deltaR(item, *it);
00030         if (dr < deltaR_) {
00031             if (checkRecoComponents_) {
00032                 OverlapChecker overlaps;
00033                 if (!overlaps(item, *it)) continue;
00034             }
00035             if (!pairCut_(pat::DiObjectProxy(item,*it))) continue;
00036             matches.push_back(std::make_pair(dr, idx));
00037         }
00038     }
00039     // see if we matched anything
00040     if (matches.empty()) return false;
00041 
00042     // sort matches
00043     std::sort(matches.begin(), matches.end());
00044     // fill ptr vector
00045     for (std::vector<std::pair<float,size_t> >::const_iterator it = matches.begin(); it != matches.end(); ++it) {
00046         overlapsToFill.push_back(candidates_->ptrAt(it->second));
00047     }
00048     return true;
00049 }
00050 
00051 bool
00052 OverlapBySuperClusterSeed::fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const
00053 {
00054     const reco::RecoCandidate * input = dynamic_cast<const reco::RecoCandidate *>(&item);
00055     if (input == 0) throw cms::Exception("Type Error") << "Input to OverlapBySuperClusterSeed is not a RecoCandidate. " 
00056                                                        << "It's a " << typeid(item).name() << "\n";
00057     reco::SuperClusterRef mySC = input->superCluster();
00058     if (mySC.isNull() || !mySC.isAvailable()) {
00059         throw cms::Exception("Bad Reference") << "Input to OverlapBySuperClusterSeed has a null or dangling superCluster reference\n";
00060     }
00061     const reco::CaloClusterPtr & mySeed = mySC->seed();
00062     if (mySeed.isNull()) {
00063         throw cms::Exception("Bad Reference") << "Input to OverlapBySuperClusterSeed has a null superCluster seed reference\n";
00064     }
00065     bool hasOverlaps = false;
00066     size_t idx = 0;
00067     for (edm::View<reco::RecoCandidate>::const_iterator it = others_->begin(); it != others_->end(); ++it, ++idx) {
00068         reco::SuperClusterRef otherSc = it->superCluster();
00069         if (otherSc.isNull() || !otherSc.isAvailable()) {
00070             throw cms::Exception("Bad Reference") << "One item in the OverlapBySuperClusterSeed input list has a null or dangling superCluster reference\n";
00071         }
00072         if (mySeed == otherSc->seed()) {
00073             overlapsToFill.push_back(others_->ptrAt(idx));
00074             hasOverlaps = true;
00075         }
00076     }
00077     return hasOverlaps;
00078 }