CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoTauTag/RecoTau/src/RecoTauBinnedIsolationPlugin.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h"
00002 #include <boost/foreach.hpp>
00003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00005 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00006 #include "DataFormats/VertexReco/interface/Vertex.h"
00007 
00008 namespace reco { namespace tau {
00009 
00010 namespace {
00011 template<typename C>
00012 bool is_sorted(const C& collection) {
00013   for(size_t i = 0; i < collection.size()-1; i++) {
00014     if (collection[i] > collection[i+1])
00015       return false;
00016   }
00017   return true;
00018 }
00019 }
00020 
00021 RecoTauDiscriminationBinnedIsolation::RecoTauDiscriminationBinnedIsolation(
00022     const edm::ParameterSet& pset):RecoTauDiscriminantPlugin(pset) {
00023   puVtxSrc_ = pset.getParameter<edm::InputTag>("vtxSource");
00024   // Configure the binning
00025   typedef std::vector<edm::ParameterSet> VPSet;
00026   VPSet binning = pset.getParameter<VPSet>("binning");
00027   BOOST_FOREACH(const edm::ParameterSet& bincfg, binning) {
00028     std::vector<double> bins = bincfg.getParameter<std::vector<double> >(
00029         "binLowEdges");
00030     int nVtx = bincfg.getParameter<int>("nPUVtx");
00031     // Sanity checks
00032     // No double entries
00033     if (binning_.count(nVtx)) {
00034       throw cms::Exception("BadIsoBinVtxConfig") << "Multiple configuraions for"
00035         << " vertex multiplicity: " << nVtx << " have been entered!";
00036     }
00037     // Bins are sorted
00038     if (!is_sorted(bins)) {
00039       throw cms::Exception("BadIsoBinConfig") << "The binning for vertex: "
00040         << nVtx << " is not in ascending order!";
00041     }
00042     binning_[nVtx] = bins;
00043   }
00044   defaultBinning_ = pset.getParameter<std::vector<double> >("defaultBinning");
00045 }
00046 
00047 // Load the vertices at the beginning of each event
00048 void RecoTauDiscriminationBinnedIsolation::beginEvent() {
00049   edm::Handle<reco::VertexCollection> vertices_;
00050   evt()->getByLabel(puVtxSrc_, vertices_);
00051   nVertices_ = vertices_->size();
00052 }
00053 
00054 // Compute the result of the function
00055 std::vector<double> RecoTauDiscriminationBinnedIsolation::operator()(
00056     const reco::PFTauRef& tau) const {
00057   // Get the binning for this event
00058   std::map<int, std::vector<double> >::const_iterator binningIter =
00059     binning_.find(nVertices_);
00060 
00061   const std::vector<double>* bins = NULL;
00062   if (binningIter != binning_.end()) {
00063     bins = &(binningIter->second);
00064   } else {
00065     bins = &defaultBinning_;
00066   }
00067 
00068   if (!bins) {
00069     throw cms::Exception("NullBinning")
00070       << "The binning for nVtx: " << nVertices_ << " is null!";
00071   }
00072 
00073   // Create our output spectrum
00074   std::vector<double> output(bins->size(), 0.0);
00075   // Get the desired isolation objects
00076   reco::PFCandidateRefVector isoObjects = extractIsoObjects(tau);
00077   // Loop over each and histogram their pt
00078   BOOST_FOREACH(const reco::PFCandidateRef& cand, isoObjects) {
00079     int highestBinLessThan = -1;
00080     for (size_t ibin = 0; ibin < bins->size(); ++ibin) {
00081       if (cand->pt() > bins->at(ibin)) {
00082         highestBinLessThan = ibin;
00083       }
00084     }
00085     if (highestBinLessThan >= 0)
00086       output[highestBinLessThan] += 1;
00087   }
00088   return output;
00089 }
00090 
00091 
00092 }} // end namespace reco::tau