CMS 3D CMS Logo

RecoTauBinnedIsolationPlugin.cc
Go to the documentation of this file.
6 
7 namespace reco::tau {
8 
9 namespace {
10 template<typename C>
11 bool is_sorted(const C& collection) {
12  for(size_t i = 0; i < collection.size()-1; i++) {
13  if (collection[i] > collection[i+1])
14  return false;
15  }
16  return true;
17 }
18 }
19 
22  puVtxSrc_ = pset.getParameter<edm::InputTag>("vtxSource");
23  // Configure the binning
24  typedef std::vector<edm::ParameterSet> VPSet;
25  VPSet binning = pset.getParameter<VPSet>("binning");
26  for(auto const& bincfg : binning) {
27  std::vector<double> bins = bincfg.getParameter<std::vector<double> >(
28  "binLowEdges");
29  int nVtx = bincfg.getParameter<int>("nPUVtx");
30  // Sanity checks
31  // No double entries
32  if (binning_.count(nVtx)) {
33  throw cms::Exception("BadIsoBinVtxConfig") << "Multiple configuraions for"
34  << " vertex multiplicity: " << nVtx << " have been entered!";
35  }
36  // Bins are sorted
37  if (!is_sorted(bins)) {
38  throw cms::Exception("BadIsoBinConfig") << "The binning for vertex: "
39  << nVtx << " is not in ascending order!";
40  }
41  binning_[nVtx] = bins;
42  }
43  defaultBinning_ = pset.getParameter<std::vector<double> >("defaultBinning");
44 }
45 
46 // Load the vertices at the beginning of each event
49  evt()->getByLabel(puVtxSrc_, vertices_);
50  nVertices_ = vertices_->size();
51 }
52 
53 // Compute the result of the function
55  const reco::PFTauRef& tau) const {
56  // Get the binning for this event
57  std::map<int, std::vector<double> >::const_iterator binningIter =
58  binning_.find(nVertices_);
59 
60  const std::vector<double>* bins = nullptr;
61  if (binningIter != binning_.end()) {
62  bins = &(binningIter->second);
63  } else {
64  bins = &defaultBinning_;
65  }
66 
67  if (!bins) {
68  throw cms::Exception("NullBinning")
69  << "The binning for nVtx: " << nVertices_ << " is null!";
70  }
71 
72  // Create our output spectrum
73  std::vector<double> output(bins->size(), 0.0);
74  // Get the desired isolation objects
75  std::vector<reco::PFCandidatePtr> isoObjects = extractIsoObjects(tau);
76  // Loop over each and histogram their pt
77  for(auto const& cand : isoObjects) {
78  int highestBinLessThan = -1;
79  for (size_t ibin = 0; ibin < bins->size(); ++ibin) {
80  if (cand->pt() > bins->at(ibin)) {
81  highestBinLessThan = ibin;
82  }
83  }
84  if (highestBinLessThan >= 0)
85  output[highestBinLessThan] += 1;
86  }
87  return output;
88 }
89 
90 
91 } // end namespace reco::tau
T getParameter(std::string const &) const
std::vector< double > operator()(const reco::PFTauRef &tau) const override
virtual std::vector< reco::PFCandidatePtr > extractIsoObjects(const reco::PFTauRef &tau) const =0
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535