CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00007 #include "DataFormats/TauReco/interface/PFTau.h"
00008 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00009 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00010 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00011 
00012 #include "DataFormats/Math/interface/deltaR.h"
00013 
00014 PFTauExtractor::PFTauExtractor(const edm::ParameterSet& cfg)
00015 {
00016   tauSource_ = cfg.getParameter<edm::InputTag>("tauSource");
00017   candidateSource_ = cfg.getParameter<edm::InputTag>("candidateSource");
00018   maxDxyTrack_ = cfg.getParameter<double>("Diff_r");
00019   maxDzTrack_ = cfg.getParameter<double>("Diff_z");
00020   dRmatchPFTau_ = cfg.getParameter<double>("dRmatchPFTau");
00021   dRVetoCone_ = cfg.getParameter<double>("DR_Veto");
00022   dRIsoCone_ = cfg.getParameter<double>("DR_Max");
00023   dRvetoPFTauSignalConeConstituents_ = cfg.getParameter<double>("dRvetoPFTauSignalConeConstituents");
00024 }
00025 
00026 template<typename T>
00027 reco::IsoDeposit PFTauExtractor::depositFromObject(const edm::Event& evt, const edm::EventSetup& es, const T& tauCandidate) const
00028 {
00029 //--- create IsoDeposit to be returned;
00030 //    set "direction" of IsoDeposit cone to jet-axis of tauCandidate
00031   reco::isodeposit::Direction tauCandidateDirection(tauCandidate.eta(), tauCandidate.phi());
00032   reco::IsoDeposit isoDeposit(tauCandidateDirection);
00033   isoDeposit.addCandEnergy(tauCandidate.pt());
00034 
00035 //--- find PFTau closest to tauDirection
00036   edm::Handle<reco::PFTauCollection> pfTaus;
00037   evt.getByLabel(tauSource_, pfTaus);
00038 
00039   double dR_min = -1.;
00040   const reco::PFTau* pfTau_matched = 0;
00041   for ( reco::PFTauCollection::const_iterator pfTau = pfTaus->begin();
00042         pfTau != pfTaus->end(); ++pfTau ) {
00043     double dR = deltaR(pfTau->eta(), pfTau->phi(), tauCandidate.eta(), tauCandidate.phi());
00044     if ( pfTau_matched == 0 || dR < dR_min ) {
00045       dR_min = dR;
00046       pfTau_matched = &(*pfTau);
00047     }
00048   }
00049 
00050 //--- compute IsoDeposit for matched PFTau
00051   if ( pfTau_matched != 0 && dR_min < dRmatchPFTau_ ) {
00052     edm::Handle<edm::View<reco::Candidate> > candidates;
00053     evt.getByLabel(candidateSource_, candidates);
00054 
00055     const reco::Particle::Point& tauVertex = pfTau_matched->vertex();
00056     double dRsignalCone_max = 0.;
00057     for ( edm::View<reco::Candidate>::const_iterator candidate = candidates->begin();
00058           candidate != candidates->end(); ++candidate ) {
00059       double dR = deltaR(candidate->momentum(), pfTau_matched->momentum());
00060 
00061 //--- check that candidate is inbetween veto and isolation cone,
00062 //    and is compatible with originating from the same primary event vertex as the PFTau
00063       if ( dR > dRVetoCone_ && dR < dRIsoCone_ &&
00064            (candidate->vertex() - tauVertex).Rho() < maxDxyTrack_ &&
00065            fabs(candidate->vertex().z() - tauVertex.z()) < maxDzTrack_ ) {
00066 
00067 //--- check that the candidate is not associated to one of the tau decay products
00068 //    within the signal cone of the PFTau
00069         bool isSignalCone = false;
00070         for ( reco::PFCandidateRefVector::const_iterator tauSignalConeConstituent = pfTau_matched->signalPFCands().begin();
00071               tauSignalConeConstituent != pfTau_matched->signalPFCands().end(); ++tauSignalConeConstituent ) {
00072           double dR = deltaR(candidate->momentum(), (*tauSignalConeConstituent)->momentum());
00073           if ( dR <= dRvetoPFTauSignalConeConstituents_ ) isSignalCone = true;
00074         }
00075         
00076         if ( !isSignalCone ) {
00077           reco::isodeposit::Direction candidateDirection(candidate->eta(), candidate->phi());
00078           isoDeposit.addDeposit(candidateDirection, candidate->pt());
00079         }
00080       }
00081     }
00082 
00083 //--- set size of veto cone of IsoDeposit to largest distance 
00084 //    of any tau decay product within the signal cone of the PFTau
00085 //    (add a small positive number in order to avoid issues 
00086 //     with rounding errors and "<" versus "<=" comparisson)
00087     reco::IsoDeposit::Veto isoDepositVeto;
00088     isoDepositVeto.vetoDir = tauCandidateDirection;
00089     isoDepositVeto.dR = dRsignalCone_max + 1.e-3;
00090     isoDeposit.setVeto(isoDepositVeto);
00091   } else {
00092     edm::LogWarning ("PFTauExtractor::depositFromObject") << " Failed to match PFTau to tauCandidate direction given by" 
00093                                                           << " eta = " << tauCandidate.eta() << ", phi = " << tauCandidate.phi()
00094                                                           << " --> skipping computation of IsoDeposit !!";
00095   }
00096 
00097   return isoDeposit;
00098 }
00099 
00100 #include "FWCore/Framework/interface/MakerMacros.h"
00101 
00102 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
00103 
00104 DEFINE_EDM_PLUGIN(IsoDepositExtractorFactory, PFTauExtractor, "PFTauExtractor");