CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc

Go to the documentation of this file.
00001 #include <functional>
00002 #include <boost/foreach.hpp>
00003 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
00004 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00005 #include "RecoTauTag/TauTagTools/interface/PFTauQualityCutWrapper.h"
00006 #include "RecoTauTag/RecoTau/interface/ConeTools.h"
00007 
00008 /* class PFRecoTauDiscriminationByIsolation
00009  * created : Jul 23 2007,
00010  * revised : Thu Aug 13 14:44:40 PDT 2009
00011  * contributors : Ludovic Houchu (Ludovic.Houchu@cern.ch ; IPHC, Strasbourg),
00012  * Christian Veelken (veelken@fnal.gov ; UC Davis),
00013  *                Evan K. Friis (friis@physics.ucdavis.edu ; UC Davis)
00014  */
00015 
00016 using namespace reco;
00017 using namespace std;
00018 
00019 class PFRecoTauDiscriminationByIsolation :
00020   public PFTauDiscriminationProducerBase  {
00021   public:
00022     explicit PFRecoTauDiscriminationByIsolation(
00023         const edm::ParameterSet& pset):
00024       PFTauDiscriminationProducerBase(pset),
00025       qualityCuts_(pset.getParameter<edm::ParameterSet>("qualityCuts"))  {
00026         includeTracks_ = pset.getParameter<bool>(
00027             "ApplyDiscriminationByTrackerIsolation");
00028         includeGammas_ = pset.getParameter<bool>(
00029             "ApplyDiscriminationByECALIsolation");
00030 
00031         applyOccupancyCut_ = pset.getParameter<bool>("applyOccupancyCut");
00032         maximumOccupancy_ = pset.getParameter<uint32_t>("maximumOccupancy");
00033 
00034         applySumPtCut_ = pset.getParameter<bool>("applySumPtCut");
00035         maximumSumPt_ = pset.getParameter<double>("maximumSumPtCut");
00036 
00037         applyRelativeSumPtCut_ = pset.getParameter<bool>(
00038             "applyRelativeSumPtCut");
00039         maximumRelativeSumPt_ = pset.getParameter<double>(
00040             "relativeSumPtCut");
00041 
00042         pvProducer_ = pset.getParameter<edm::InputTag>("PVProducer");
00043 
00044         if (pset.exists("customOuterCone")) {
00045           customIsoCone_ = pset.getParameter<double>("customOuterCone");
00046         } else {
00047           customIsoCone_ = -1;
00048         }
00049       }
00050 
00051     ~PFRecoTauDiscriminationByIsolation(){}
00052 
00053     void beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup);
00054     double discriminate(const PFTauRef& pfTau);
00055 
00056   private:
00057     PFTauQualityCutWrapper qualityCuts_;
00058 
00059     bool includeTracks_;
00060     bool includeGammas_;
00061 
00062     bool applyOccupancyCut_;
00063     uint32_t maximumOccupancy_;
00064 
00065     bool applySumPtCut_;
00066     double maximumSumPt_;
00067 
00068     bool applyRelativeSumPtCut_;
00069     double maximumRelativeSumPt_;
00070 
00071     double customIsoCone_;
00072 
00073     edm::InputTag pvProducer_;
00074 
00075     Vertex currentPV_;
00076 };
00077 
00078 void PFRecoTauDiscriminationByIsolation::beginEvent(const edm::Event& event,
00079     const edm::EventSetup& eventSetup) {
00080 
00081   // NB: The use of the PV in this context is necessitated by its use in
00082   // applying quality cuts to the different objects in the isolation cone
00083 
00084   // get the PV for this event
00085   edm::Handle<VertexCollection> primaryVertices;
00086   event.getByLabel(pvProducer_, primaryVertices);
00087 
00088   // take the highest pt primary vertex in the event
00089   if( primaryVertices->size() ) {
00090     currentPV_ = *(primaryVertices->begin());
00091   } else {
00092     const double smearedPVsigmaY = 0.0015;
00093     const double smearedPVsigmaX = 0.0015;
00094     const double smearedPVsigmaZ = 0.005;
00095     Vertex::Error SimPVError;
00096     SimPVError(0,0) = smearedPVsigmaX*smearedPVsigmaX;
00097     SimPVError(1,1) = smearedPVsigmaY*smearedPVsigmaY;
00098     SimPVError(2,2) = smearedPVsigmaZ*smearedPVsigmaZ;
00099     Vertex::Point blankVertex(0, 0, 0);
00100 
00101     // note that the PFTau has its vertex set as the associated PV.  So if it
00102     // doesn't exist, a fake vertex has already been created (about 0, 0, 0) w/
00103     // the above width (gaussian)
00104     currentPV_ = Vertex(blankVertex, SimPVError,1,1,1);
00105   }
00106 }
00107 
00108 double PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) {
00109   // collect the objects we are working with (ie tracks, tracks+gammas, etc)
00110   std::vector<LeafCandidate> isoObjects;
00111 
00112   if (includeTracks_) {
00113     qualityCuts_.isolationChargedObjects(*pfTau, currentPV_, isoObjects);
00114   }
00115 
00116   if (includeGammas_) {
00117     qualityCuts_.isolationGammaObjects(*pfTau, isoObjects);
00118   }
00119 
00120   typedef reco::tau::cone::DeltaRFilter<LeafCandidate> DRFilter;
00121 
00122   // Check if we want a custom iso cone
00123   if (customIsoCone_ >= 0.) {
00124     DRFilter filter(pfTau->p4(), 0, customIsoCone_);
00125     // Remove all the objects not in our iso cone
00126     std::remove_if(isoObjects.begin(), isoObjects.end(), std::not1(filter));
00127   }
00128 
00129   bool failsOccupancyCut     = false;
00130   bool failsSumPtCut         = false;
00131   bool failsRelativeSumPtCut = false;
00132 
00133   //--- nObjects requirement
00134   failsOccupancyCut = ( isoObjects.size() > maximumOccupancy_ );
00135 
00136   //--- Sum PT requirement
00137   if( applySumPtCut_ || applyRelativeSumPtCut_ ) {
00138     reco::Particle::LorentzVector totalP4;
00139     BOOST_FOREACH(const LeafCandidate& isoObject, isoObjects) {
00140       totalP4 += isoObject.p4();
00141     }
00142 
00143     failsSumPtCut = (totalP4.pt() > maximumSumPt_);
00144 
00145     //--- Relative Sum PT requirement
00146     failsRelativeSumPtCut = (
00147         (pfTau->pt() > 0 ? totalP4.pt()/pfTau->pt() : 0 )
00148         > maximumRelativeSumPt_ );
00149   }
00150 
00151   bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
00152     (applySumPtCut_ && failsSumPtCut) ||
00153     (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ;
00154 
00155   return (fails ? 0. : 1.);
00156 }
00157 
00158 DEFINE_FWK_MODULE(PFRecoTauDiscriminationByIsolation);