CMS 3D CMS Logo

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