File indexing completed on 2024-04-06 12:23:31
0001 #include "DataFormats/Candidate/interface/Candidate.h"
0002 #include "DataFormats/Common/interface/Handle.h"
0003 #include "DataFormats/Math/interface/deltaR.h"
0004 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0005 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
0006 #include "DataFormats/TauReco/interface/PFTau.h"
0007 #include "DataFormats/TrackReco/interface/Track.h"
0008 #include "FWCore/Framework/interface/ConsumesCollector.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0015
0016 class PFTauExtractor : public reco::isodeposit::IsoDepositExtractor {
0017 public:
0018 explicit PFTauExtractor(const edm::ParameterSet&, edm::ConsumesCollector&& iC);
0019 ~PFTauExtractor() override {}
0020
0021
0022 void fillVetos(const edm::Event&, const edm::EventSetup&, const reco::TrackCollection&) override {}
0023 reco::IsoDeposit deposit(const edm::Event& evt, const edm::EventSetup& es, const reco::Track& track) const override {
0024 return depositFromObject(evt, es, track);
0025 }
0026 reco::IsoDeposit deposit(const edm::Event& evt,
0027 const edm::EventSetup& es,
0028 const reco::Candidate& candidate) const override {
0029 return depositFromObject(evt, es, candidate);
0030 }
0031
0032 private:
0033
0034 edm::EDGetTokenT<reco::PFTauCollection> tauSourceToken_;
0035 edm::EDGetTokenT<edm::View<reco::Candidate> > candidateSourceToken_;
0036 double maxDxyTrack_;
0037 double maxDzTrack_;
0038 double dRmatchPFTau_;
0039 double dRVetoCone_;
0040 double dRIsoCone_;
0041 double dRvetoPFTauSignalConeConstituents_;
0042
0043
0044
0045 template <typename T>
0046 reco::IsoDeposit depositFromObject(const edm::Event&, const edm::EventSetup&, const T&) const;
0047 };
0048
0049 PFTauExtractor::PFTauExtractor(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC) {
0050 tauSourceToken_ = iC.consumes<reco::PFTauCollection>(cfg.getParameter<edm::InputTag>("tauSource"));
0051 candidateSourceToken_ =
0052 iC.mayConsume<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("candidateSource"));
0053 maxDxyTrack_ = cfg.getParameter<double>("Diff_r");
0054 maxDzTrack_ = cfg.getParameter<double>("Diff_z");
0055 dRmatchPFTau_ = cfg.getParameter<double>("dRmatchPFTau");
0056 dRVetoCone_ = cfg.getParameter<double>("DR_Veto");
0057 dRIsoCone_ = cfg.getParameter<double>("DR_Max");
0058 dRvetoPFTauSignalConeConstituents_ = cfg.getParameter<double>("dRvetoPFTauSignalConeConstituents");
0059 }
0060
0061 template <typename T>
0062 reco::IsoDeposit PFTauExtractor::depositFromObject(const edm::Event& evt,
0063 const edm::EventSetup& es,
0064 const T& tauCandidate) const {
0065
0066
0067 reco::isodeposit::Direction tauCandidateDirection(tauCandidate.eta(), tauCandidate.phi());
0068 reco::IsoDeposit isoDeposit(tauCandidateDirection);
0069 isoDeposit.addCandEnergy(tauCandidate.pt());
0070
0071
0072 edm::Handle<reco::PFTauCollection> pfTaus;
0073 evt.getByToken(tauSourceToken_, pfTaus);
0074
0075 double dR_min = -1.;
0076 const reco::PFTau* pfTau_matched = nullptr;
0077 for (reco::PFTauCollection::const_iterator pfTau = pfTaus->begin(); pfTau != pfTaus->end(); ++pfTau) {
0078 double dR = deltaR(pfTau->eta(), pfTau->phi(), tauCandidate.eta(), tauCandidate.phi());
0079 if (pfTau_matched == nullptr || dR < dR_min) {
0080 dR_min = dR;
0081 pfTau_matched = &(*pfTau);
0082 }
0083 }
0084
0085
0086 if (pfTau_matched != nullptr && dR_min < dRmatchPFTau_) {
0087 edm::Handle<edm::View<reco::Candidate> > candidates;
0088 evt.getByToken(candidateSourceToken_, candidates);
0089
0090 const reco::Particle::Point& tauVertex = pfTau_matched->vertex();
0091 double dRsignalCone_max = 0.;
0092 for (edm::View<reco::Candidate>::const_iterator candidate = candidates->begin(); candidate != candidates->end();
0093 ++candidate) {
0094 double dR = deltaR(candidate->momentum(), pfTau_matched->momentum());
0095
0096
0097
0098 if (dR > dRVetoCone_ && dR < dRIsoCone_ && (candidate->vertex() - tauVertex).Rho() < maxDxyTrack_ &&
0099 fabs(candidate->vertex().z() - tauVertex.z()) < maxDzTrack_) {
0100
0101
0102 bool isSignalCone = false;
0103 for (std::vector<reco::CandidatePtr>::const_iterator tauSignalConeConstituent =
0104 pfTau_matched->signalCands().begin();
0105 tauSignalConeConstituent != pfTau_matched->signalCands().end();
0106 ++tauSignalConeConstituent) {
0107 double dR = deltaR(candidate->momentum(), (*tauSignalConeConstituent)->momentum());
0108 if (dR <= dRvetoPFTauSignalConeConstituents_)
0109 isSignalCone = true;
0110 }
0111
0112 if (!isSignalCone) {
0113 reco::isodeposit::Direction candidateDirection(candidate->eta(), candidate->phi());
0114 isoDeposit.addDeposit(candidateDirection, candidate->pt());
0115 }
0116 }
0117 }
0118
0119
0120
0121
0122
0123 reco::IsoDeposit::Veto isoDepositVeto;
0124 isoDepositVeto.vetoDir = tauCandidateDirection;
0125 isoDepositVeto.dR = dRsignalCone_max + 1.e-3;
0126 isoDeposit.setVeto(isoDepositVeto);
0127 } else {
0128 edm::LogWarning("PFTauExtractor::depositFromObject")
0129 << " Failed to match PFTau to tauCandidate direction given by"
0130 << " eta = " << tauCandidate.eta() << ", phi = " << tauCandidate.phi()
0131 << " --> skipping computation of IsoDeposit !!";
0132 }
0133
0134 return isoDeposit;
0135 }
0136
0137 #include "FWCore/Framework/interface/MakerMacros.h"
0138
0139 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
0140
0141 DEFINE_EDM_PLUGIN(IsoDepositExtractorFactory, PFTauExtractor, "PFTauExtractor");