CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h"
00002 #include "DataFormats/VertexReco/interface/Vertex.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include <boost/bind.hpp>
00006 
00007 namespace reco { namespace tau {
00008 
00009 // Quality cut implementations
00010 namespace qcuts {
00011 
00012 bool ptMin(const PFCandidate& cand, double cut) {
00013   return cand.pt() > cut;
00014 }
00015 
00016 bool etMin(const PFCandidate& cand, double cut) {
00017   return cand.et() > cut;
00018 }
00019 
00020 bool trkPixelHits(const PFCandidate& cand, int cut) {
00021   // For some reason, the number of hits is signed
00022   TrackRef trk = cand.trackRef();
00023   if (!trk) return false;
00024   return trk->hitPattern().numberOfValidPixelHits() >= cut;
00025 }
00026 
00027 bool trkTrackerHits(const PFCandidate& cand, int cut) {
00028   TrackRef trk = cand.trackRef();
00029   if (!trk) return false;
00030   return trk->hitPattern().numberOfValidHits() >= cut;
00031 }
00032 
00033 bool trkTransverseImpactParameter(const PFCandidate& cand,
00034                                   const reco::VertexRef* pv,
00035                                   double cut) {
00036   if (pv->isNull()) {
00037     edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " <<
00038         "RecoTauQualityCuts is invalid. - trkTransverseImpactParameter";
00039     return false;
00040   }
00041   TrackRef trk = cand.trackRef();
00042   if (!trk) return false;
00043   return std::abs(trk->dxy((*pv)->position())) <= cut;
00044 }
00045 
00046 bool trkLongitudinalImpactParameter(const PFCandidate& cand,
00047                                     const reco::VertexRef* pv,
00048                                     double cut) {
00049   if (pv->isNull()) {
00050     edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " <<
00051         "RecoTauQualityCuts is invalid. - trkLongitudinalImpactParameter";
00052     return false;
00053   }
00054   TrackRef trk = cand.trackRef();
00055   if (!trk) return false;
00056   return std::abs(trk->dz((*pv)->position())) <= cut;
00057 }
00058 
00059 bool trkChi2(const PFCandidate& cand, double cut) {
00060   TrackRef trk = cand.trackRef();
00061   if (!trk) return false;
00062   return trk->normalizedChi2() <= cut;
00063 }
00064 
00065 // And a set of qcuts
00066 bool AND(const PFCandidate& cand,
00067          const RecoTauQualityCuts::QCutFuncCollection& cuts) {
00068   BOOST_FOREACH(const RecoTauQualityCuts::QCutFunc& func, cuts) {
00069     if (!func(cand))
00070       return false;
00071   }
00072   return true;
00073 }
00074 
00075 // Get the set of Q cuts for a given type (i.e. gamma)
00076 bool mapAndCutByType(const PFCandidate& cand,
00077                      const RecoTauQualityCuts::QCutFuncMap& funcMap) {
00078   // Find the cuts that for this particle type
00079   RecoTauQualityCuts::QCutFuncMap::const_iterator cuts =
00080       funcMap.find(cand.particleId());
00081   // Return false if we dont' know how to deal w/ this particle type
00082   if (cuts == funcMap.end())
00083     return false;
00084   else
00085     // Otherwise AND all the cuts
00086     return AND(cand, cuts->second);
00087 }
00088 
00089 }  // end qcuts implementation namespace
00090 
00091 RecoTauQualityCuts::RecoTauQualityCuts(const edm::ParameterSet &qcuts) {
00092   // Setup all of our predicates
00093   QCutFuncCollection chargedHadronCuts;
00094   QCutFuncCollection gammaCuts;
00095   QCutFuncCollection neutralHadronCuts;
00096 
00097   // Build all the QCuts for tracks
00098   if (qcuts.exists("minTrackPt"))
00099     chargedHadronCuts.push_back(
00100         boost::bind(qcuts::ptMin, _1,
00101                     qcuts.getParameter<double>("minTrackPt")));
00102 
00103   if (qcuts.exists("maxTrackChi2"))
00104     chargedHadronCuts.push_back(
00105         boost::bind(qcuts::trkChi2, _1,
00106                     qcuts.getParameter<double>("maxTrackChi2")));
00107 
00108   if (qcuts.exists("minTrackPixelHits"))
00109     chargedHadronCuts.push_back(boost::bind(
00110             qcuts::trkPixelHits, _1,
00111             qcuts.getParameter<uint32_t>("minTrackPixelHits")));
00112 
00113   if (qcuts.exists("minTrackHits"))
00114     chargedHadronCuts.push_back(boost::bind(
00115             qcuts::trkTrackerHits, _1,
00116             qcuts.getParameter<uint32_t>("minTrackHits")));
00117 
00118   // The impact parameter functions are bound to our member PV, since they
00119   // need it to compute the discriminant value.
00120   if (qcuts.exists("maxTransverseImpactParameter"))
00121     chargedHadronCuts.push_back(boost::bind(
00122             qcuts::trkTransverseImpactParameter, _1, &pv_,
00123             qcuts.getParameter<double>("maxTransverseImpactParameter")));
00124 
00125   if (qcuts.exists("maxDeltaZ"))
00126     chargedHadronCuts.push_back(boost::bind(
00127             qcuts::trkLongitudinalImpactParameter, _1, &pv_,
00128             qcuts.getParameter<double>("maxDeltaZ")));
00129 
00130   // Build the QCuts for gammas
00131   if (qcuts.exists("minGammaEt"))
00132     gammaCuts.push_back(boost::bind(
00133             qcuts::etMin, _1, qcuts.getParameter<double>("minGammaEt")));
00134 
00135   // Build QCuts for netural hadrons
00136   if (qcuts.exists("minNeutralHadronEt"))
00137     neutralHadronCuts.push_back(boost::bind(
00138             qcuts::etMin, _1,
00139             qcuts.getParameter<double>("minNeutralHadronEt")));
00140 
00141   // Map our QCut collections to the particle Ids they are associated to.
00142   qcuts_[PFCandidate::h] = chargedHadronCuts;
00143   qcuts_[PFCandidate::gamma] = gammaCuts;
00144   qcuts_[PFCandidate::h0] = neutralHadronCuts;
00145   // We use the same qcuts for muons/electrons and charged hadrons.
00146   qcuts_[PFCandidate::e] = chargedHadronCuts;
00147   qcuts_[PFCandidate::mu] = chargedHadronCuts;
00148 
00149   // Build a final level predicate that works on any PFCand
00150   predicate_ = boost::bind(qcuts::mapAndCutByType, _1, boost::cref(qcuts_));
00151 }
00152 
00153 }}  // end namespace reco::tau