CMS 3D CMS Logo

OverlapTest.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
6 
7 using namespace pat::helper;
8 
10  iEvent.getByToken(srcToken_, candidates_);
11  isPreselected_.resize(candidates_->size());
12  size_t idx = 0;
13  for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
14  isPreselected_[idx] = presel_(*it);
15  }
16  // Yes, I could use std::transform. But would people like it?
17  // http://www.sgi.com/tech/stl/transform.html
18 }
19 
21  reco::CandidatePtrVector &overlapsToFill) const {
22  size_t idx = 0;
23  std::vector<std::pair<float, size_t> > matches;
24  for (reco::CandidateView::const_iterator it = candidates_->begin(); it != candidates_->end(); ++it, ++idx) {
25  if (!isPreselected_[idx])
26  continue;
27  double dr = reco::deltaR(item, *it);
28  if (dr < deltaR_) {
31  if (!overlaps(item, *it))
32  continue;
33  }
34  if (!pairCut_(pat::DiObjectProxy(item, *it)))
35  continue;
36  matches.push_back(std::make_pair(dr, idx));
37  }
38  }
39  // see if we matched anything
40  if (matches.empty())
41  return false;
42 
43  // sort matches
44  std::sort(matches.begin(), matches.end());
45  // fill ptr vector
46  for (std::vector<std::pair<float, size_t> >::const_iterator it = matches.begin(); it != matches.end(); ++it) {
47  overlapsToFill.push_back(candidates_->ptrAt(it->second));
48  }
49  return true;
50 }
51 
53  reco::CandidatePtrVector &overlapsToFill) const {
54  const reco::RecoCandidate *input = dynamic_cast<const reco::RecoCandidate *>(&item);
55  if (input == nullptr)
56  throw cms::Exception("Type Error") << "Input to OverlapBySuperClusterSeed is not a RecoCandidate. "
57  << "It's a " << typeid(item).name() << "\n";
58  reco::SuperClusterRef mySC = input->superCluster();
59  if (mySC.isNull() || !mySC.isAvailable()) {
60  throw cms::Exception("Bad Reference")
61  << "Input to OverlapBySuperClusterSeed has a null or dangling superCluster reference\n";
62  }
63  const reco::CaloClusterPtr &mySeed = mySC->seed();
64  if (mySeed.isNull()) {
65  throw cms::Exception("Bad Reference")
66  << "Input to OverlapBySuperClusterSeed has a null superCluster seed reference\n";
67  }
68  bool hasOverlaps = false;
69  size_t idx = 0;
70  // for (edm::View<reco::RecoCandidate>::const_iterator it = others_->begin(); it != others_->end(); ++it, ++idx) {
71  for (reco::CandidateView::const_iterator it = others_->begin(); it != others_->end(); ++it, ++idx) {
72  const reco::RecoCandidate *other = dynamic_cast<const reco::RecoCandidate *>(&*it);
73  reco::SuperClusterRef otherSc = other->superCluster();
74  if (otherSc.isNull() || !otherSc.isAvailable()) {
75  throw cms::Exception("Bad Reference")
76  << "One item in the OverlapBySuperClusterSeed input list has a null or dangling superCluster reference\n";
77  }
78  if (mySeed == otherSc->seed()) {
79  overlapsToFill.push_back(others_->ptrAt(idx));
80  hasOverlaps = true;
81  }
82  }
83  return hasOverlaps;
84 }
bool fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const override
Check for overlaps.
Definition: OverlapTest.cc:20
edm::EDGetTokenT< reco::CandidateView > srcToken_
Definition: OverlapTest.h:41
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
bool fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const override
Check for overlaps.
Definition: OverlapTest.cc:52
static std::string const input
Definition: EdmProvDump.cc:50
int iEvent
Definition: GenABIO.cc:224
PATStringCutObjectSelector presel_
A generic preselection cut that can work on any Candidate, but has access also to methods of PAT spec...
Definition: OverlapTest.h:63
bool isAvailable() const
Definition: Ref.h:537
edm::Handle< reco::CandidateView > candidates_
The collection to check overlaps against.
Definition: OverlapTest.h:72
std::vector< bool > isPreselected_
Flag saying if each element has passed the preselection or not.
Definition: OverlapTest.h:74
bool isNull() const
Checks for null.
Definition: Ref.h:235
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
void readInput(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Read input, apply preselection cut.
Definition: OverlapTest.cc:9
double deltaR_
Delta R for the match.
Definition: OverlapTest.h:65
bool checkRecoComponents_
Check the overlapping by RECO components.
Definition: OverlapTest.h:67
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::Handle< reco::CandidateView > others_
Definition: OverlapTest.h:91
StringCutObjectSelector< pat::DiObjectProxy > pairCut_
Cut on the pair of objects together.
Definition: OverlapTest.h:69
const std::string & name() const
Definition: OverlapTest.h:37